[En-Nut-Discussion] NutGetMillis is a _very expensive_ function on Ethernut3

duane ellis ethernut at duaneellis.com
Wed Aug 20 03:05:09 CEST 2008


This is a simple solution that I used for clock frequency calculations 
in the past.

(1) create a small structure with a few "uint32_t" in it - one for each 
frequency, sort of a cache.
(2) create some access routines, that work like this:

uint32_t
GetSomeClockFreq(void)
{
    // If frequency is ZERO... it has not been re-calculated.
       if( clock_cache.some_freq== 0 ){
                ReCalc_SomeFreq();
       }

    /* remove bit 31 */
       return (0x7fffffff & clock_cache.some_freq);
}

--
The idea is this - do *LAZY* calculations.

a)   If you do something that changes the clock frequency - ZERO the 
clock cache structure.

b) DO NOT recalculate the frequency! Just zero the structure.

c) When -and if- a frequency is needed, the cached value will be zero.

d) Being "lazy" - calculate it only once and remember the value.
      Some linkers resolve links in DLLs in a "lazy way" on first 
request to that symbol.

e)  If the frequency is truly "ZERO" - and to avoid constant 
recalculation -
      set the ZERO value to 0x800000000 (set the high bit) - and mask as 
above.
     Most chips NUT runs on operate at slightly less then 2billion hertz.

-Duane.




   

   



More information about the En-Nut-Discussion mailing list