[Linux]学习笔记系列 -- [arm][lib]

文章目录

  • arch/arm/lib/delay.c
    • [register_current_timer_delay 注册当前定时器延迟](#register_current_timer_delay 注册当前定时器延迟)
    • [read_current_timer 读取当前定时器](#read_current_timer 读取当前定时器)
  • drivers/clocksource/timer-stm32.c
    • [stm32_clocksource_init STM32 平台上初始化时钟源](#stm32_clocksource_init STM32 平台上初始化时钟源)

https://github.com/wdfk-prog/linux-study

arch/arm/lib/delay.c

register_current_timer_delay 注册当前定时器延迟

c 复制代码
void __init register_current_timer_delay(const struct delay_timer *timer)
{
	u32 new_mult, new_shift;
	u64 res;

	clocks_calc_mult_shift(&new_mult, &new_shift, timer->freq,
			       NSEC_PER_SEC, 3600);
	res = cyc_to_ns(1ULL, new_mult, new_shift);

	if (res > 1000) {
		pr_err("Ignoring delay timer %ps, which has insufficient resolution of %lluns\n",
			timer, res);
		return;
	}

	if (!delay_calibrated && (!delay_res || (res < delay_res))) {
		pr_info("Switching to timer-based delay loop, resolution %lluns\n", res);
		delay_timer			= timer;
		lpj_fine			= timer->freq / HZ;
		delay_res			= res;

		/* cpufreq 可能会loops_per_jiffy扩展,因此请保留一个私有副本 */
		arm_delay_ops.ticks_per_jiffy	= lpj_fine;
		arm_delay_ops.delay		= __timer_delay;
		arm_delay_ops.const_udelay	= __timer_const_udelay;
		arm_delay_ops.udelay		= __timer_udelay;
	} else {
		pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
	}
}

read_current_timer 读取当前定时器

c 复制代码
int read_current_timer(unsigned long *timer_val)
{
	if (!delay_timer)
		return -ENXIO;

	*timer_val = delay_timer->read_current_timer();
	return 0;
}
EXPORT_SYMBOL_GPL(read_current_timer);

drivers/clocksource/timer-stm32.c

stm32_clocksource_init STM32 平台上初始化时钟源

c 复制代码
static unsigned long stm32_read_delay(void)
{
	return readl_relaxed(stm32_timer_cnt);
}

static int __init stm32_clocksource_init(struct timer_of *to)
{
	u32 bits = stm32_timer_of_bits_get(to);
	const char *name = to->np->full_name;

	/*
	 * 此驱动程序允许注册多个计时器,并依赖于通用时间框架来选择正确的计时器。
	 * 但是,不允许对 sched_clock 执行相同的作。
	 * 我们对 16 位定时器的 sched_clock 不感兴趣,而只对 32 位定时器感兴趣,
	 * 因此如果尚未注册 32 位定时器,我们选择这个 32 位定时器作为sched_clock。
	 */
	if (bits == 32 && !stm32_timer_cnt) {

		/*
		 * 立即启动计数器,因为我们将在之后立即使用它。
		 */
		stm32_timer_start(to);
		/* 获取计数器寄存器地址 */
		stm32_timer_cnt = timer_of_base(to) + TIM_CNT;
		sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to));
		pr_info("%s: STM32 sched_clock registered\n", name);

		stm32_timer_delay.read_current_timer = stm32_read_delay;
		stm32_timer_delay.freq = timer_of_rate(to);
		register_current_timer_delay(&stm32_timer_delay);
		pr_info("%s: STM32 delay timer registered\n", name);
	}

	return clocksource_mmio_init(timer_of_base(to) + TIM_CNT, name,
				     timer_of_rate(to), bits == 32 ? 250 : 100,
				     bits, clocksource_mmio_readl_up);
}
相关推荐
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号2 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行4 天前
Linux和window共享文件夹
linux
木心月转码ing4 天前
WSL+Cpp开发环境配置
linux
蝎子莱莱爱打怪5 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes