X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Fplatforms%2Ftelosb%2Fmac%2Ftkn154%2Ftimer%2FAlarm32khzTo62500hzTransformC.nc;h=e601285549487f9288a26f2e8b1e9e98afa16bd2;hp=20f0822d49e1d7863038d7f834e28b9ad3770734;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc index 20f0822d..e6012855 100644 --- a/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc @@ -40,12 +40,17 @@ module Alarm32khzTo62500hzTransformC } implementation { -/** - * This is the place where we cheat: since we don't have a clock source - * running at 62500 Hz, we cast 2 symbols to 1 tick of the 32768 - * clock, which introduces a small (5%) error. -*/ -#warning "Warning: MAC timing is not standard compliant (the symbol clock is based on the 32768 Hz oscillator)!" + + /** + * TelosB lacks a clock that satisfies the precision and accuracy + * requirements of the IEEE 802.15.4 standard (62500 Hz, +-40 ppm). + * As a workaround, we cast one tick of the 32768 Hz clock to two + * IEEE 802.15.4 symbols, which introduces a small (5%) error. + * As a consequence the timing of the beacon interval and slotted + * CSMA-CA algorithm is not standard-compliant anymore. + */ + +#warning "Warning: MAC timing is not standard compliant!" async command void Alarm.start[ uint8_t num ](uint32_t dt){ call AlarmFrom.start[num](dt >> 1);} async command void Alarm.stop[ uint8_t num ](){ call AlarmFrom.stop[num]();} @@ -61,15 +66,17 @@ implementation async command void Alarm.startAt[ uint8_t num ](uint32_t t0, uint32_t dt){ // t0 occured before "now" - uint32_t now = call Alarm.getNow[num](), elapsed; - if (t0 <= now) - elapsed = now - t0; - else - elapsed = ~(t0 - now) + 1; - if (elapsed > dt) - elapsed = dt; - dt -= elapsed; - call AlarmFrom.start[num](dt >> 1); + atomic { + uint32_t now = call Alarm.getNow[num](), elapsed; + if (t0 < now) + elapsed = now - t0; + else + elapsed = ~(t0 - now) + 1; + if (elapsed > dt) + dt = elapsed; + dt -= elapsed; + call Alarm.start[num](dt); + } } /******************** Defaults ****************************/