Changeset 2837
- Timestamp:
- 11/09/09 11:19:18 (7 weeks ago)
- Location:
- code/tinyos-2.x/tos/chips/cc2420_hotmac
- Files:
-
- 4 modified
-
HotmacC.nc (modified) (4 diffs)
-
hotmac.h (modified) (1 diff)
-
receive/HotmacReceiveP.nc (modified) (9 diffs)
-
transmit/HotmacTransmitP.nc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
code/tinyos-2.x/tos/chips/cc2420_hotmac/HotmacC.nc
r2836 r2837 16 16 components new StateC(); 17 17 components NeighborTableC; 18 components RandomC; 18 19 19 20 SplitControl = HotmacReceiveP; … … 38 39 HotmacReceiveP.CC2420PacketBody -> CC2420PacketC; 39 40 HotmacReceiveP.Packet -> CC2420PacketC; 40 /* HotmacReceiveP.MessagePool -> PoolC; */41 41 HotmacReceiveP.SubReceive -> CC2420ReceiveC; 42 42 HotmacReceiveP.ReceiveIndicator -> CC2420ReceiveC; … … 44 44 HotmacReceiveP.CC2420Config -> CC2420ControlC; 45 45 HotmacReceiveP.CC2420Receive -> CC2420ReceiveC; 46 // HotmacReceiveP.TransmitTransfer -> HotmacTransmitP.TransmitTransfer;47 46 HotmacReceiveP.PacketTimeStamp -> CC2420PacketC.PacketTimeStamp32khz; 47 HotmacReceiveP.PowerCycleInfo -> CC2420PowerC; 48 HotmacReceiveP.Random -> RandomC; 48 49 49 50 // Transmit wiring 50 51 components new Alarm32khz32C() as SendAlarmC; 51 //components new Alarm32khz32C() as ShutdownAlarmC;52 components new Alarm32khz32C() as ShutdownAlarmC; 52 53 components new TimerMilliC() as ShutdownTimerC; 53 components RandomC;54 54 MainC.SoftwareInit -> HotmacTransmitP.Init; 55 55 HotmacTransmitP.CC2420PacketBody -> CC2420PacketC; … … 66 66 HotmacTransmitP.PacketAcknowledgements -> CC2420PacketC; 67 67 68 68 69 components NoLedsC as LedsC; 69 70 HotmacReceiveP.Leds -> LedsC; 70 71 HotmacTransmitP.Leds -> LedsC; 72 73 //components new Alarm32khz32C(); 71 74 } 72 75 -
code/tinyos-2.x/tos/chips/cc2420_hotmac/hotmac.h
r2836 r2837 53 53 54 54 // jiffies 55 HOTMAC_DEFAULT_CHECK_PERIOD = 64L << 5,55 HOTMAC_DEFAULT_CHECK_PERIOD = 1024L << 5, 56 56 57 57 // 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 29 29 interface CC2420Receive; 30 30 interface PacketTimeStamp<T32khz, uint32_t>; 31 31 interface Random; 32 33 interface PowerCycleInfo; 32 34 interface Leds; 33 35 } … … 35 37 36 38 // phase in the 32khz time 37 uint32_t probe_phase = 0;39 uint32_t probe_phase; 38 40 // how many 32khz tics between probes 39 41 uint32_t probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; … … 53 55 command error_t Init.init() { 54 56 printfUART_init(); 55 probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; // T_HOTMAC_PERIOD(HOTMAC_DEFAULT_CHECK_PERIOD);57 probe_interval = HOTMAC_DEFAULT_CHECK_PERIOD; 56 58 probe_phase = 0; 57 59 current_probe = &probe; 58 60 return SUCCESS; 59 // call HotmacState.forceState(S_OFF);60 61 } 61 62 … … 88 89 } 89 90 90 // call Leds.led0Toggle();91 91 // reset the contention window used by senders 92 92 cwl = 1; … … 95 95 // we turned and scheduled the probe for NOW 96 96 call Leds.led1Toggle(); 97 // printfUART("probe: %i\n", current_dsn); 97 98 98 if (call CC2420Transmit.resend(TRUE) != SUCCESS) { 99 99 goto fail; … … 125 125 } 126 126 127 event void PowerCycleInfo.stopDone(uint32_t on_time) { 128 printfUART("awake for %i\n", on_time); 129 } 130 127 131 event void RadioControl.stopDone(error_t err) { 128 132 atomic { 129 133 if (call HotmacState.isState(S_RECEIVE)) { 130 134 call HotmacState.toIdle(); 131 // call Leds.led2Toggle();132 135 } 133 136 } … … 176 179 task void stopAndPut() { 177 180 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; 180 182 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 181 190 if (wake_dt < HOTMAC_WAKEUP_LOAD_TIME) { 182 191 // we schedule the wakeup a little before when we need to send … … 201 210 // compute exactly when to send the next beacon 202 211 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 } 205 220 206 221 if (wake_dt > HOTMAC_WAKEUP_TOO_LONG) { … … 355 370 command error_t SplitControl.start() { 356 371 stopping = FALSE; 372 probe_phase = (call Random.rand16()) % probe_phase; 357 373 call HotmacState.forceState(S_IDLE); 358 374 call ProbeAlarm.start(probe_interval + probe_phase); -
code/tinyos-2.x/tos/chips/cc2420_hotmac/transmit/HotmacTransmitP.nc
r2836 r2837 53 53 void sendDone(error_t error, uint32_t shutdown_delay); 54 54 void giveupRadio(); 55 void scheduleWakeup( uint16_t extra);55 void scheduleWakeup(); 56 56 57 57 command error_t Init.init() { … … 72 72 } 73 73 74 void scheduleWakeup( uint16_t extra) {74 void scheduleWakeup() { 75 75 struct hotmac_neigh_entry *entry; 76 76 … … 83 83 } else { 84 84 uint32_t now = call SendAlarm.getNow(); 85 uint32_t wakeTime = now + extra;85 uint32_t wakeTime; 86 86 if (wakeTime > entry->phase) { 87 87 wakeTime = entry->period - 88 88 ((wakeTime - entry->phase) % entry->period); 89 89 } else { 90 wakeTime = entry->phase - wakeTime;90 wakeTime = entry->phase - now; 91 91 } 92 92
