Skip to contentSkip to conversation

nds32: ag101/ag102: Inconsistent timer3 counter unit?

U-Boot Axel Lin 2 participants 2 messages Jul 3, 2013 – Jul 8, 2013

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

Hi Macpaul,

For the case CONFIG_FTTMR010_EXT_CLK is not defined:

In reset_timer_masked():
lastdec = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2);

In get_timer_masked():
ulong now = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2 / 1024);

The code looks strange.
(Why one needs to be divided by 1024 and the other one does not?) I'm not sure which one is correct.

Regards,
Axel

#1 lore raw

Hi Axel,

2013/7/3 Axel Lin <[email protected]>:

Quoted 14 lines

Hi Macpaul,

For the case CONFIG_FTTMR010_EXT_CLK is not defined:

In reset_timer_masked():
lastdec = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2);

In get_timer_masked():
ulong now = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2 / 1024);

The code looks strange.
(Why one needs to be divided by 1024 and the other one does not?) I'm not sure which one is correct.

Quoted 7 lines

Regards,
Axel

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

The unit of "readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2)" is second. However, there is a definition CONFIG_SYS_HZ = 1000 in include/configs/adp-ag101p.h ,
this means the accuracy of "lastdec" and "now" should be in millisecond, I think divided by 1024 is just for this purpose, but use CONFIG_SYS_HZ to replace 1024 would be better.

so the correct should be:
lastdec = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2 / CONFIG_SYS_HZ);
ulong now = readl(&tmr->timer3_counter) / (CONFIG_SYS_CLK_FREQ / 2 / CONFIG_SYS_HZ);

Best Regards,
Kuan-Yu Kuo