[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);
}
相关推荐
d111111111d几秒前
什么是内存对齐?在STM32上面如何通过编辑器指令来实现内存对齐。
笔记·stm32·单片机·嵌入式硬件·学习·编辑器
JiMoKuangXiangQu2 分钟前
Linux 内存管理:页表管理简析
linux·mmu·内存管理·页表管理
WG_172 分钟前
Linux:缓冲区_glibc封装
linux·运维·服务器
番知了5 分钟前
Ubuntu 22.04 常用命令清单
linux·运维·ubuntu
旺仔Sec7 分钟前
2026年河北省职业院校技能大赛“网络系统管理”(高职组)网络构建样题
运维·服务器·网络
FF-Studio27 分钟前
Ubuntu 24.04 磁盘爆满“灵异“事件:Btrfs, Snapper 与删不掉的空间
linux·运维·人工智能·ubuntu
爱尔兰极光28 分钟前
计算机网络--网络层
运维·服务器·计算机网络
蒙奇D索大32 分钟前
【数据结构】考研408 | 伪随机探测与双重散列精讲:散列的艺术与均衡之道
数据结构·笔记·学习·考研
Neolnfra35 分钟前
Xshell SSH 连接故障排查
运维·服务器·网络·ssh·xshell·运程连接
极地星光40 分钟前
Ubuntu 16.10 启动时 networking.service 缓慢问题
linux·ubuntu