[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);
}
相关推荐
全栈工程师修炼指南35 分钟前
DBA | SQL 结构化查询语言介绍与学习环境准备
数据库·sql·学习·dba
m0_7382065436 分钟前
嵌入式学习的第四十八天-中断+OCP原则
学习
华纳云IDC服务商1 小时前
通过限制网络访问来降低服务器被攻击风险的方法
运维·服务器·网络
amazinging1 小时前
北京-4年功能测试2年空窗-报培训班学测开-第七十三天-投递简历-[特殊字符][特殊字符]
python·学习
ue星空1 小时前
UE地裂制作学习
学习
艾莉丝努力练剑2 小时前
深入详解C语言的循环结构:while循环、do-while循环、for循环,结合实例,讲透C语言的循环结构
c语言·开发语言·c++·学习
boy快快长大2 小时前
【Linux】常用命令(三)
linux·运维·服务器
晨非辰3 小时前
#C语言——学习攻略:自定义类型路线--结构体--结构体类型,结构体变量的创建和初始化,结构体内存对齐,结构体传参,结构体实现位段
c语言·开发语言·经验分享·学习·其他·学习方法·visual studio
ayaya_mana4 小时前
Notepad--:国产跨平台文本编辑器,Notepad++ 的理想替代方案
linux·windows·macos·编辑器·notepad·notepad--