Changeset 1164
- Timestamp:
- 09/12/11 15:52:56 (21 months ago)
- Location:
- firmware/openos/openwsn
- Files:
-
- 2 edited
-
02a-MAC/IEEE802154E.c (modified) (7 diffs)
-
02b-RES/neighbors.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firmware/openos/openwsn/02a-MAC/IEEE802154E.c
r1163 r1164 88 88 uint16_t asnRead (OpenQueueEntry_t* advFrame); 89 89 // synchronization 90 void synchronizePacket(uint16_t timeReceived , open_addr_t* advFrom);91 void synchronizeAck(int16_t timeCorrection , open_addr_t* advFrom);90 void synchronizePacket(uint16_t timeReceived); 91 void synchronizeAck(int16_t timeCorrection); 92 92 void changeIsSync(bool newIsSync); 93 93 // notifying upper layer … … 470 470 471 471 // synchronize (for the first time) to the sender's ADV 472 synchronizePacket(ieee154e_vars.syncCapturedTime ,&(ieee154e_vars.dataReceived->l2_nextORpreviousHop));472 synchronizePacket(ieee154e_vars.syncCapturedTime); 473 473 474 474 // declare synchronized … … 890 890 if (isValidAck(&ieee802514_header,ieee154e_vars.dataToSend)==TRUE) { 891 891 892 // resynchronize 893 timeCorrection = (int16_t)(ieee154e_vars.ackReceived->payload[1]<<8 | ieee154e_vars.ackReceived->payload[0]); 894 synchronizeAck(timeCorrection,&(ieee154e_vars.ackReceived->l2_nextORpreviousHop)); 892 // resynchronize if I'm not a DAGroot and ACK from preferred parent 893 if (idmanager_getIsDAGroot()==FALSE && 894 neighbors_isPreferredParent(&(ieee154e_vars.ackReceived->l2_nextORpreviousHop)) ) { 895 timeCorrection = (int16_t)(ieee154e_vars.ackReceived->payload[1]<<8 | ieee154e_vars.ackReceived->payload[0]); 896 synchronizeAck(timeCorrection); 897 } 895 898 896 899 // inform upper layer … … 1083 1086 ieee154etimer_schedule(DURATION_rt5); 1084 1087 } else { 1085 // synchronize to the received packet 1086 synchronizePacket(ieee154e_vars.syncCapturedTime,&(ieee154e_vars.dataReceived->l2_nextORpreviousHop)); 1088 // synchronize to the received packet iif I'm not a DAGroot and this is my preferred parent 1089 if (idmanager_getIsDAGroot()==FALSE && neighbors_isPreferredParent(&(ieee154e_vars.dataReceived->l2_nextORpreviousHop))) { 1090 synchronizePacket(ieee154e_vars.syncCapturedTime); 1091 } 1087 1092 // indicate reception to upper layer (no ACK asked) 1088 1093 notif_receive(ieee154e_vars.dataReceived); … … 1251 1256 1252 1257 // synchronize to the received packet 1253 synchronizePacket(ieee154e_vars.syncCapturedTime,&(ieee154e_vars.dataReceived->l2_nextORpreviousHop)); 1258 if (idmanager_getIsDAGroot()==FALSE && neighbors_isPreferredParent(&(ieee154e_vars.dataReceived->l2_nextORpreviousHop))) { 1259 synchronizePacket(ieee154e_vars.syncCapturedTime); 1260 } 1254 1261 1255 1262 // inform upper layer of reception (after ACK sent) … … 1349 1356 //======= synchronization 1350 1357 1351 void synchronizePacket(uint16_t timeReceived ,open_addr_t* advFrom) {1358 void synchronizePacket(uint16_t timeReceived) { 1352 1359 int16_t timeCorrection; 1353 1360 uint16_t newTaccr0; … … 1357 1364 currentTar = TAR; 1358 1365 currentTaccr0 = TACCR0; 1359 // only resynchronize if I'm not a DAGroot and this is my preferred parent 1360 if (idmanager_getIsDAGroot()==FALSE && neighbors_isPreferredParent(advFrom)) { 1361 timeCorrection = (int16_t)((int16_t)timeReceived-(int16_t)TsTxOffset); 1362 newTaccr0 = TsSlotDuration; 1363 // detect whether I'm too close to the edge of the slot, in that case, 1364 // skip a slot and increase the temporary slot length to be 2 slots long 1365 if (currentTar<timeReceived || 1366 currentTaccr0-currentTar<RESYNCHRONIZATIONGUARD) { 1367 DEBUG_PIN_SLOT_TOGGLE(); 1368 TACTL &= ~TAIFG; 1369 newTaccr0 += TsSlotDuration; 1370 ieee154e_vars.asn++; 1371 DEBUG_PIN_SLOT_TOGGLE(); 1372 } 1373 newTaccr0 = (uint16_t)((int16_t)newTaccr0+timeCorrection); 1374 TACCR0 = newTaccr0; 1375 ieee154e_vars.deSyncTimeout = DESYNCTIMEOUT; 1376 // update statistics 1377 updateStats(timeCorrection); 1378 } 1379 } 1380 1381 void synchronizeAck(int16_t timeCorrection,open_addr_t* advFrom) { 1366 // calculate new value for TACCR0 1367 timeCorrection = (int16_t)((int16_t)timeReceived-(int16_t)TsTxOffset); 1368 newTaccr0 = TsSlotDuration; 1369 // detect whether I'm too close to the edge of the slot, in that case, 1370 // skip a slot and increase the temporary slot length to be 2 slots long 1371 if (currentTar<timeReceived || 1372 currentTaccr0-currentTar<RESYNCHRONIZATIONGUARD) { 1373 DEBUG_PIN_SLOT_TOGGLE(); 1374 TACTL &= ~TAIFG; 1375 newTaccr0 += TsSlotDuration; 1376 ieee154e_vars.asn++; 1377 DEBUG_PIN_SLOT_TOGGLE(); 1378 } 1379 newTaccr0 = (uint16_t)((int16_t)newTaccr0+timeCorrection); 1380 TACCR0 = newTaccr0; 1381 ieee154e_vars.deSyncTimeout = DESYNCTIMEOUT; 1382 // update statistics 1383 updateStats(timeCorrection); 1384 } 1385 1386 void synchronizeAck(int16_t timeCorrection) { 1382 1387 uint16_t newTaccr0; 1383 1388 uint16_t currentTaccr0; 1384 // re cord the current states of the TAR and TACCR0 registers1389 // resynchronize 1385 1390 currentTaccr0 = TACCR0; 1386 // only resynchronize if I'm not a DAGroot and this is my preferred parent 1387 if (idmanager_getIsDAGroot()==FALSE && neighbors_isPreferredParent(advFrom)) { 1388 newTaccr0 = (uint16_t)((int16_t)currentTaccr0-timeCorrection); 1389 TACCR0 = newTaccr0; 1390 ieee154e_vars.deSyncTimeout = DESYNCTIMEOUT; 1391 // update statistics 1392 updateStats(timeCorrection); 1393 } 1391 newTaccr0 = (uint16_t)((int16_t)currentTaccr0-timeCorrection); 1392 TACCR0 = newTaccr0; 1393 ieee154e_vars.deSyncTimeout = DESYNCTIMEOUT; 1394 // update statistics 1395 updateStats(timeCorrection); 1394 1396 } 1395 1397 -
firmware/openos/openwsn/02b-RES/neighbors.c
r1162 r1164 199 199 200 200 __monitor bool neighbors_isPreferredParent(open_addr_t* address) { 201 return TRUE; //poipoipoipoi 201 return TRUE; // poipoipoi 202 /* 202 203 uint8_t i; 203 204 for (i=0;i<MAXNUMNEIGHBORS;i++) { … … 207 208 } 208 209 return FALSE; 210 */ 209 211 } 210 212
Note: See TracChangeset
for help on using the changeset viewer.
