时钟问题

发现反复读取系统时间(频繁调用time()),会使系统时间变快。后来频繁执行date也会是时间变快。
看来core下代码,应该是由于_syspage_time()引起的。_syspage_time()返回的是qtime的nsec值。

请问诸位大侠,这些操作为什么会影响系统时间呢?

at91sam9x的bsp。没有人遇到该问题?

操作过程大概如下:
while(1) {
time_of_day = time( NULL );
printf("%s\n",ctime( &time_of_day ));
delay(100);
}
运行一段时间后,用date命令看,系统时间明显加快。

应该at91sam bsp的bug

问题解决了。
对比了at91sam9260和9263的bsp,timer call out都有点问题。系统定时使用了pit(Periodic Interval Timer)。pit与debug串口等外设共享System Controller Interrupt。debug的callout中进行中断源的判断,而timer callout中没有进行判断。如果debug产生中断也会引起timer call的调用。
因此,频繁的printf打印也导致timer callout的频繁执行,所以系统时间越来越快。

修改如下:
timer calout中断调用时,应先判断是否是pit中断。

CALLOUT_START(timer_reload_at91sam9260, 0, patch_timer)
/*

  • Get the address of the timer registers (patched)
    /
    mov ip, #0x000000ff
    orr ip, ip, #0x0000ff00
    orr ip, ip, #0x00ff0000
    orr ip, ip, #0xff000000
    // add below code
    //--------------------------------------------------
    ldr r0, [ip, #AT91SAM9260_PIT_SR]
    tst r0, #1 //PITS
    beq 0b
    //--------------------------------------------------
    /
    Read PIVR register to the clear interrupt */
    ldr r0, [ip, #AT91SAM9260_PIT_PIVR]

/* Reload and enable PIT */
mov r0, #3
mov r0, r0, lsl #24
ldr r1, [r1, #QT_TIMER_LOAD]
add r0, r0, r1
str r0, [ip, #AT91SAM9260_PIT_MR]
0:
mov pc, lr
CALLOUT_END(timer_reload_at91sam9260)

这个BSP的设计很不好.
系统时钟不应该跟任何设备共享中断.
SAM9260有三个TC,选一个作系统时钟吧,具体例子可参照at91rm9200ek BSP.

qnx开放代码是对的。呵呵 大家一起找bug。
说到bug,network中的at91sam9xx的网络驱动也有bug,只认dm9161 phy,其它厂家的phy还不认识,另外mdc时钟也有太快,需要降下来。
这些都修改完后,网络性能也比较差。还不如以前9263 bsp中网络驱动性能好。
原以为devnp的驱动性能应该比devn的好。估计这个devnp的驱动中还有别的bug。