Changeset 2837

Show
Ignore:
Timestamp:
11/09/09 11:19:18 (7 weeks ago)
Author:
stevedh
Message:
  • more nits
Location:
code/tinyos-2.x/tos/chips/cc2420_hotmac
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • code/tinyos-2.x/tos/chips/cc2420_hotmac/HotmacC.nc

    r2836 r2837  
    1616  components new StateC(); 
    1717  components NeighborTableC; 
     18  components RandomC; 
    1819 
    1920  SplitControl = HotmacReceiveP; 
     
    3839  HotmacReceiveP.CC2420PacketBody -> CC2420PacketC; 
    3940  HotmacReceiveP.Packet -> CC2420PacketC; 
    40 /*   HotmacReceiveP.MessagePool -> PoolC; */ 
    4141  HotmacReceiveP.SubReceive -> CC2420ReceiveC; 
    4242  HotmacReceiveP.ReceiveIndicator -> CC2420ReceiveC; 
     
    4444  HotmacReceiveP.CC2420Config -> CC2420ControlC; 
    4545  HotmacReceiveP.CC2420Receive -> CC2420ReceiveC; 
    46   // HotmacReceiveP.TransmitTransfer -> HotmacTransmitP.TransmitTransfer; 
    4746  HotmacReceiveP.PacketTimeStamp -> CC2420PacketC.PacketTimeStamp32khz; 
     47  HotmacReceiveP.PowerCycleInfo -> CC2420PowerC; 
     48  HotmacReceiveP.Random -> RandomC; 
    4849 
    4950  // Transmit wiring 
    5051  components new Alarm32khz32C() as SendAlarmC; 
    51   // components new Alarm32khz32C() as ShutdownAlarmC; 
     52  components new Alarm32khz32C() as ShutdownAlarmC; 
    5253  components new TimerMilliC() as ShutdownTimerC; 
    53   components RandomC; 
    5454  MainC.SoftwareInit -> HotmacTransmitP.Init; 
    5555  HotmacTransmitP.CC2420PacketBody -> CC2420PacketC; 
     
    6666  HotmacTransmitP.PacketAcknowledgements -> CC2420PacketC; 
    6767 
     68 
    6869  components NoLedsC as LedsC; 
    6970  HotmacReceiveP.Leds -> LedsC; 
    7071  HotmacTransmitP.Leds -> LedsC; 
     72 
     73  //components new Alarm32khz32C(); 
    7174}  
    7275 
  • code/tinyos-2.x/tos/chips/cc2420_hotmac/hotmac.h

    r2836 r2837  
    5353 
    5454  // jiffies 
    55   HOTMAC_DEFAULT_CHECK_PERIOD = 64L << 5, 
     55  HOTMAC_DEFAULT_CHECK_PERIOD = 1024L << 5, 
    5656 
    5757  // how long to wait for a beacon each time we wake up.  this is 
  • code/tinyos-2.x/tos/chips/cc2420_hotmac/receive/HotmacReceiveP.nc

    r2836 r2837  
    2929    interface CC2420Receive; 
    3030    interface PacketTimeStamp<T32khz, uint32_t>; 
    31  
     31    interface Random; 
     32 
     33    interface PowerCycleInfo; 
    3234    interface Leds; 
    3335  } 
     
    3537 
    3638  // phase in the 32khz time  
    37   uint32_t probe_phase = 0; 
     39  uint32_t probe_phase; 
    3840  // how many 32khz tics between probes 
    3941  uint32_t probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; 
     
    5355  command error_t Init.init() { 
    5456    printfUART_init(); 
    55     probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; // T_HOTMAC_PERIOD(HOTMAC_DEFAULT_CHECK_PERIOD); 
     57    probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; 
    5658    probe_phase    = 0; 
    5759    current_probe = &probe; 
    5860    return SUCCESS; 
    59     // call HotmacState.forceState(S_OFF); 
    6061  } 
    6162 
     
    8889        } 
    8990 
    90         // call Leds.led0Toggle(); 
    9191        // reset the contention window used by senders 
    9292        cwl = 1; 
     
    9595        // we turned and scheduled the probe for NOW 
    9696        call Leds.led1Toggle(); 
    97         // printfUART("probe: %i\n", current_dsn); 
     97 
    9898        if (call CC2420Transmit.resend(TRUE) != SUCCESS) { 
    9999          goto fail; 
     
    125125  } 
    126126 
     127  event void PowerCycleInfo.stopDone(uint32_t on_time) { 
     128    printfUART("awake for %i\n", on_time); 
     129  } 
     130 
    127131  event void RadioControl.stopDone(error_t err) { 
    128132    atomic { 
    129133      if (call HotmacState.isState(S_RECEIVE)) { 
    130134        call HotmacState.toIdle(); 
    131         // call Leds.led2Toggle(); 
    132135      } 
    133136    } 
     
    176179  task void stopAndPut() { 
    177180    uint32_t now = call ProbeAlarm.getNow(); 
    178     uint32_t current_phase = (now - probe_phase) % probe_interval; 
    179     uint32_t wake_dt = probe_interval - current_phase; 
     181    uint32_t wake_dt; 
    180182     
     183    if (now > probe_phase) { 
     184      wake_dt = probe_interval -  
     185        ((now - probe_phase) % probe_interval); 
     186    } else { 
     187      wake_dt = probe_phase - now; 
     188    } 
     189 
    181190    if (wake_dt < HOTMAC_WAKEUP_LOAD_TIME) { 
    182191      // we schedule the wakeup a little before when we need to send 
     
    201210        // compute exactly when to send the next beacon 
    202211        uint32_t now = call ProbeAlarm.getNow(); 
    203         uint32_t current_phase = (now - probe_phase) % probe_interval; 
    204         uint32_t wake_dt = probe_interval - current_phase + probe_phase; 
     212        uint32_t wake_dt; 
     213     
     214        if (now > probe_phase) { 
     215          wake_dt = probe_interval -  
     216            ((now - probe_phase) % probe_interval); 
     217        } else { 
     218          wake_dt = probe_phase - now; 
     219        } 
    205220 
    206221        if (wake_dt > HOTMAC_WAKEUP_TOO_LONG) { 
     
    355370  command error_t SplitControl.start() { 
    356371    stopping = FALSE; 
     372    probe_phase = (call Random.rand16()) % probe_phase; 
    357373    call HotmacState.forceState(S_IDLE); 
    358374    call ProbeAlarm.start(probe_interval + probe_phase); 
  • code/tinyos-2.x/tos/chips/cc2420_hotmac/transmit/HotmacTransmitP.nc

    r2836 r2837  
    5353  void sendDone(error_t error, uint32_t shutdown_delay); 
    5454  void giveupRadio(); 
    55   void scheduleWakeup(uint16_t extra); 
     55  void scheduleWakeup(); 
    5656 
    5757  command error_t Init.init() { 
     
    7272  } 
    7373 
    74   void scheduleWakeup(uint16_t extra) { 
     74  void scheduleWakeup() { 
    7575    struct hotmac_neigh_entry *entry; 
    7676 
     
    8383    } else { 
    8484      uint32_t now = call SendAlarm.getNow(); 
    85       uint32_t wakeTime = now + extra; 
     85      uint32_t wakeTime; 
    8686      if (wakeTime > entry->phase) { 
    8787        wakeTime = entry->period -  
    8888          ((wakeTime - entry->phase) % entry->period); 
    8989      } else { 
    90         wakeTime = entry->phase - wakeTime; 
     90        wakeTime = entry->phase - now; 
    9191      } 
    9292