免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1410 | 回复: 0
打印 上一主题 下一主题

linux通过date命令设置硬件时钟 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-14 15:45 |只看该作者 |倒序浏览

                                                                                                                                                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP