Changeset 1164


Ignore:
Timestamp:
09/12/11 15:52:56 (21 months ago)
Author:
thomas
Message:

selecting the neighbor to sync with is done before calling the synchronize* functions. Partically fixes #92.

Location:
firmware/openos/openwsn
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • firmware/openos/openwsn/02a-MAC/IEEE802154E.c

    r1163 r1164  
    8888uint16_t asnRead (OpenQueueEntry_t* advFrame); 
    8989// synchronization 
    90 void     synchronizePacket(uint16_t timeReceived, open_addr_t* advFrom); 
    91 void     synchronizeAck(int16_t timeCorrection, open_addr_t* advFrom); 
     90void     synchronizePacket(uint16_t timeReceived); 
     91void     synchronizeAck(int16_t timeCorrection); 
    9292void     changeIsSync(bool newIsSync); 
    9393// notifying upper layer 
     
    470470          
    471471         // 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); 
    473473          
    474474         // declare synchronized 
     
    890890      if (isValidAck(&ieee802514_header,ieee154e_vars.dataToSend)==TRUE) { 
    891891          
    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         } 
    895898          
    896899         // inform upper layer 
     
    10831086         ieee154etimer_schedule(DURATION_rt5); 
    10841087      } 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         } 
    10871092         // indicate reception to upper layer (no ACK asked) 
    10881093         notif_receive(ieee154e_vars.dataReceived); 
     
    12511256    
    12521257   // 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   } 
    12541261    
    12551262   // inform upper layer of reception (after ACK sent) 
     
    13491356//======= synchronization 
    13501357 
    1351 void synchronizePacket(uint16_t timeReceived,open_addr_t* advFrom) { 
     1358void synchronizePacket(uint16_t timeReceived) { 
    13521359   int16_t  timeCorrection; 
    13531360   uint16_t newTaccr0; 
     
    13571364   currentTar           =  TAR; 
    13581365   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 
     1386void synchronizeAck(int16_t timeCorrection) { 
    13821387   uint16_t newTaccr0; 
    13831388   uint16_t currentTaccr0; 
    1384    // record the current states of the TAR and TACCR0 registers 
     1389   // resynchronize 
    13851390   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); 
    13941396} 
    13951397 
  • firmware/openos/openwsn/02b-RES/neighbors.c

    r1162 r1164  
    199199 
    200200__monitor bool neighbors_isPreferredParent(open_addr_t* address) { 
    201    return TRUE; //poipoipoipoi 
     201   return TRUE; // poipoipoi 
     202   /* 
    202203   uint8_t i; 
    203204   for (i=0;i<MAXNUMNEIGHBORS;i++) { 
     
    207208   } 
    208209   return FALSE; 
     210   */ 
    209211} 
    210212 
Note: See TracChangeset for help on using the changeset viewer.