[U-Boot] Timer implementations

Reinhard Meyer u-boot at emk-elektronik.de
Tue Oct 26 20:36:56 CEST 2010


On 26.10.2010 18:26, Wolfgang Denk wrote:
> Dear Nishanth Menon,
>
> In message<4CC6F23A.2040608 at ti.com>  you wrote:
>>
>>> No. This code is always wrong. Please fix it as described.
>> Apologies on being a dudhead, I suppose you mean the following:
>>
>> ulong start;
>> start = get_timer(0);
>> while (!(readl(&mmc_base->stat)&  CC_MASK)) {
>>           if (get_timer(start)>  usec2ticks(MAX_RETRY_US)) {
>>                   printf("%s: timedout waiting for cc2!\n", __func__);
>>                   return;
>>           }
>> }
>>
>> would this be better?
>
> No, not at all, as get_timer() returns milliseconds, not ticks.
>
> You probably want something like:
>
> 	ulong start = get_timer(0);
>
> 	while (!(readl(&mmc_base->stat)&  CC_MASK)) {
> 		if (get_timer(0) - start>= MAX_RETRY_US/1000) {
> 			printf(...);
> 			return;
> 		}
> 		udelay(100);
> 	}

This will work, of course, but the original semantics of get_timer()
seems to be:

ulong start = get_timer(0);

loop {
	if (get_timer(start) >= timeout_in_ms)
		we_have_timeout();
}

--> get_timer(x) returns (time - x)

the subtraction is done internally.

Reinhard


More information about the U-Boot mailing list