- 论坛徽章:
- 0
|
linux系统一般用date命令设置系统时钟,用hwclock命令来修改硬件时钟,但是公司买的开发板的linux系统却是用date命令来修改硬件时钟,为此我分析了一下内核里时钟相关的源码。
时钟芯片是RTC4513。
arch/arm/mach-pxa/time.c
时钟中断处理函数
static irqreturn_t
pxa_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
int next_match;
do {
timer_tick(regs);
OSSR = OSSR_M0; /* Clear match on timer 0 */
next_match = (OSMR0 += LATCH);
} while( (signed long)(next_match - OSCR)
void timer_tick(struct pt_regs *regs)
{
profile_tick(CPU_PROFILING, regs);
do_leds();
do_set_rtc();
do_timer(regs);
}
->
static inline void do_set_rtc(void)
{
if (time_status & STA_UNSYNC || set_rtc == NULL)
return;
if (next_rtc_update &&
time_before((unsigned long)xtime.tv_sec, next_rtc_update))
return;
if (xtime.tv_nsec > 1) &&
xtime.tv_nsec >= 500000000 + ((unsigned) tick_nsec >> 1))
return;
if (set_rtc())
/*
* rtc update failed. Try again in 60s
*/
next_rtc_update = xtime.tv_sec + 60;
else
next_rtc_update = xtime.tv_sec + 660;
}
可以看出最终调用set_rtc()设置时钟,而set_rtc是一个函数指针,在函数pxa_init_time(void)中初始化:
void __init pxa_init_time(void)
{
struct timespec tv;
gettimeoffset = pxa_gettimeoffset;
set_rtc = set_rtc4513_time; //pxa_set_rtc;
//tv.tv_nsec = 0;
//tv.tv_sec =pxa_get_rtc_time();
//do_settimeofday(&tv);//kilody
OSMR0 = 0; /* set initial match at 0 */
OSSR = 0xf; /* clear status on all timers */
setup_irq(IRQ_OST0, &pxa_timer_irq);
OIER |= OIER_E0; /* enable match on timer 0 to cause interrupts */
OSCR = 0; /* initialize free-running timer, force first match */
}
set_rtc4513_time就是RTC4513芯片驱动中设置时钟的函数。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72751/showart_1130806.html |
|