*** stock_iot-lab_M3/openwsn/02a-MAClow/IEEE802154E.h Thu Apr 24 11:01:36 2014 --- riot-openwsn-wip/openwsn/02a-MAClow/IEEE802154E.h Thu Apr 24 16:55:54 2014 *************** *** 10,21 **** #include "openwsn.h" #include "board_info.h" //=========================== debug define ==================================== //=========================== define ========================================== ! #define SYNCHRONIZING_CHANNEL 20 // channel the mote listens on to synchronize #define TXRETRIES 3 // number of MAC retries before declaring failed #define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value) #define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to succesfully synchronize --- 10,22 ---- #include "openwsn.h" #include "board_info.h" + #include "schedule.h" //=========================== debug define ==================================== //=========================== define ========================================== ! #define SYNCHRONIZING_CHANNEL 0x1a // channel the mote listens on to synchronize #define TXRETRIES 3 // number of MAC retries before declaring failed #define TX_POWER 31 // 1=-25dBm, 31=0dBm (max value) #define RESYNCHRONIZATIONGUARD 5 // in 32kHz ticks. min distance to the end of the slot to succesfully synchronize *************** *** 25,30 **** --- 26,79 ---- #define LIMITLARGETIMECORRECTION 5 // threshold number of ticks to declare a timeCorrection "large" #define LENGTH_IEEE154_MAX 128 // max length of a valid radio packet + //15.4e information elements related + #define IEEE802154E_PAYLOAD_DESC_LEN_SHIFT 0x04 + #define IEEE802154E_PAYLOAD_DESC_GROUP_ID_MLME (0x01 << 1) //includes shift 1 + #define IEEE802154E_DESC_TYPE_LONG 0x01 + #define IEEE802154E_DESC_TYPE_SHORT 0x00 + + #define IEEE802154E_DESC_TYPE_HEADER_IE 0x00 + #define IEEE802154E_DESC_TYPE_PAYLOAD_IE 0x01 + //len field on PAYLOAD/HEADER DESC + #define IEEE802154E_DESC_LEN_HEADER_IE_MASK 0xFE00 + #define IEEE802154E_DESC_LEN_PAYLOAD_IE_MASK 0xFFE0 + + #define IEEE802154E_DESC_LEN_HEADER_IE_SHIFT 9 + #define IEEE802154E_DESC_LEN_PAYLOAD_IE_SHIFT 5 + + //groupID/elementID field on PAYLOAD/HEADER DESC + #define IEEE802154E_DESC_ELEMENTID_HEADER_IE_MASK 0x01FE + #define IEEE802154E_DESC_GROUPID_PAYLOAD_IE_MASK 0x001E + + #define IEEE802154E_DESC_ELEMENTID_HEADER_IE_SHIFT 1 + #define IEEE802154E_DESC_GROUPID_PAYLOAD_IE_SHIFT 1 + + //MLME Sub IE LONG page 83 + #define IEEE802154E_DESC_LEN_LONG_MLME_IE_MASK 0xFFE0 + #define IEEE802154E_DESC_SUBID_LONG_MLME_IE_MASK 0x001E + + #define IEEE802154E_DESC_LEN_LONG_MLME_IE_SHIFT 5 + #define IEEE802154E_DESC_SUBID_LONG_MLME_IE_SHIFT 1 + + //MLME Sub IE SHORT page 82 + #define IEEE802154E_DESC_LEN_SHORT_MLME_IE_MASK 0xFF00 + #define IEEE802154E_DESC_SUBID_SHORT_MLME_IE_MASK 0x00FE + + #define IEEE802154E_DESC_LEN_SHORT_MLME_IE_SHIFT 8 + #define IEEE802154E_DESC_SUBID_SHORT_MLME_IE_SHIFT 1 + + + #define IEEE802154E_MLME_SYNC_IE_SUBID 0x1A + #define IEEE802154E_MLME_SYNC_IE_SUBID_SHIFT 1 + #define IEEE802154E_MLME_SLOTFRAME_LINK_IE_SUBID 0x1B + #define IEEE802154E_MLME_SLOTFRAME_LINK_IE_SUBID_SHIFT 1 + #define IEEE802154E_MLME_TIMESLOT_IE_SUBID 0x1c + #define IEEE802154E_MLME_TIMESLOT_IE_SUBID_SHIFT 1 + + #define IEEE802154E_MLME_IE_GROUPID 0x01 + #define IEEE802154E_ACK_NACK_TIMECORRECTION_ELEMENTID 0x1E + + #define IEEE802154E_ /** When a packet is received, it is written inside the OpenQueueEntry_t->packet buffer, starting at the byte defined below. When a packet is relayed, it *************** *** 81,86 **** --- 130,136 ---- TsLongGT = 43, // 1300us TsTxAckDelay = 151, // 4606us TsShortGT = 16, // 500us + // TsShortGT = 30, // 900us, stm32 can work well with this value TsSlotDuration = PORT_TsSlotDuration, // 15000us // execution speed related maxTxDataPrepare = PORT_maxTxDataPrepare, *************** *** 97,102 **** --- 147,159 ---- }; + //shift of bytes in the linkOption bitmap + enum ieee154e_linkOption_enum { + FLAG_TX_S = 7, + FLAG_RX_S = 6, + FLAG_SHARED_S = 5, + FLAG_TIMEKEEPING_S = 4, + }; // FSM timer durations (combinations of atomic durations) // TX *************** *** 125,150 **** PORT_SIGNED_INT_WIDTH timeCorrection; } IEEE802154E_ACK_ht; ! #define ADV_PAYLOAD_LENGTH 5 ! //=========================== variables ======================================= //=========================== prototypes ====================================== // admin ! void ieee154e_init(); // public ! PORT_TIMER_WIDTH ieee154e_asnDiff(asn_t* someASN); ! bool ieee154e_isSynch(); ! void asnWriteToPkt(OpenQueueEntry_t* frame); ! void asnWriteToSerial(uint8_t* array); // events ! void ieee154e_startOfFrame(PORT_TIMER_WIDTH capturedTime); ! void ieee154e_endOfFrame(PORT_TIMER_WIDTH capturedTime); // misc ! bool debugPrint_asn(); ! bool debugPrint_isSync(); ! bool debugPrint_macStats(); /** \} --- 182,304 ---- PORT_SIGNED_INT_WIDTH timeCorrection; } IEEE802154E_ACK_ht; ! //includes payload header IE short + MLME short Header + Sync IE ! #define ADV_PAYLOAD_LENGTH sizeof(payload_IE_descriptor_t) + \ ! sizeof(MLME_IE_subHeader_t) + \ ! sizeof(synch_IE_t) ! ! ! ! ! //=========================== module variables ================================ ! ! typedef struct { ! // misc ! asn_t asn; // current absolute slot number ! slotOffset_t slotOffset; // current slot offset ! slotOffset_t nextActiveSlotOffset; // next active slot offset ! PORT_RADIOTIMER_WIDTH deSyncTimeout; // how many slots left before looses sync ! bool isSync; // TRUE iff mote is synchronized to network ! // as shown on the chronogram ! ieee154e_state_t state; // state of the FSM ! OpenQueueEntry_t* dataToSend; // pointer to the data to send ! OpenQueueEntry_t* dataReceived; // pointer to the data received ! OpenQueueEntry_t* ackToSend; // pointer to the ack to send ! OpenQueueEntry_t* ackReceived; // pointer to the ack received ! PORT_RADIOTIMER_WIDTH lastCapturedTime; // last captured time ! PORT_RADIOTIMER_WIDTH syncCapturedTime; // captured time used to sync ! //channel hopping ! uint8_t freq; // frequency of the current slot ! uint8_t asnOffset; // offset inside the frame ! ! PORT_RADIOTIMER_WIDTH radioOnInit; //when within the slot the radio turns on ! PORT_RADIOTIMER_WIDTH radioOnTics;//how many tics within the slot the radio is on ! bool radioOnThisSlot; //to control if the radio has been turned on in a slot. ! } ieee154e_vars_t; ! ! PRAGMA(pack(1)); ! typedef struct { ! uint8_t numSyncPkt; // how many times synchronized on a non-ACK packet ! uint8_t numSyncAck; // how many times synchronized on an ACK ! PORT_SIGNED_INT_WIDTH minCorrection; // minimum time correction ! PORT_SIGNED_INT_WIDTH maxCorrection; // maximum time correction ! uint8_t numDeSync; // number of times a desync happened ! float dutyCycle; // mac dutyCycle at each superframe ! } ieee154e_stats_t; ! PRAGMA(pack()); ! typedef struct { ! PORT_RADIOTIMER_WIDTH num_newSlot; ! PORT_RADIOTIMER_WIDTH num_timer; ! PORT_RADIOTIMER_WIDTH num_startOfFrame; ! PORT_RADIOTIMER_WIDTH num_endOfFrame; ! } ieee154e_dbg_t; ! ! ! //=========================== IEs ============================================= ! //the header for all header IEs ! typedef struct{ ! uint16_t length_elementid_type; ! }header_IE_descriptor_t; ! //header descriptor. elementid will be 0 as described in 15.4e pag. 81 ! //type is 0 as described on p. 80 ! ! ! //the content for ack ie -- it is a header IE with values - element id =0x1e len=2 type=0 ! PRAGMA(pack(1)); ! typedef struct { ! int16_t timesync_info; ! }ack_timecorrection_IE_t; ! PRAGMA(pack()); ! //the header for all payload IEs ! ! ! typedef struct{//11b len 4b gid 1b type ! uint16_t length_groupid_type; //bytes on the IE content- that is the embedded MLME or Header IE. ! //groupid == 0x01 MLME | type long = 1 ! }payload_IE_descriptor_t; // payload descriptor. groupid will be 1 as described in 15.4e pag. 81 ! ! //MLME sub id header appended to payload descriptor. we use group id=1 type=1 ! typedef struct{ ! uint16_t length_subID_type; ! }MLME_IE_subHeader_t; ! ! //the Synchronization IE. it is a payload IE with values - subid=0x1a type=0 (short) len=6 ! PRAGMA(pack(1)); ! typedef struct { ! uint8_t asn[5]; ! uint8_t join_priority; ! }synch_IE_t; ! PRAGMA(pack()); ! ! //the Slotframe and Link IE ! typedef struct { ! uint8_t slotframehandle; ! uint16_t slotframesize; ! uint8_t numlinks; ! }slotframelink_IE_t; ! ! typedef struct { ! uint16_t tsNum; ! uint16_t choffset; ! uint8_t linkoptions; ! }linkInfo_subIE_t; //=========================== prototypes ====================================== // admin ! void ieee154e_init(void); // public ! PORT_RADIOTIMER_WIDTH ieee154e_asnDiff(asn_t* someASN); ! bool ieee154e_isSynch(void); ! void ieee154e_getAsn(uint8_t* array); // events ! void ieee154e_startOfFrame(PORT_RADIOTIMER_WIDTH capturedTime); ! void ieee154e_endOfFrame(PORT_RADIOTIMER_WIDTH capturedTime); // misc ! bool debugPrint_asn(void); ! bool debugPrint_isSync(void); ! bool debugPrint_macStats(void); /** \}