Basic MAC data interface for LoRa transceiver
Dependents: LoRaBaseStation LoRaTerminal
Diff: AlohaTransceiver.cpp
- Revision:
- 28:2c0e115b4f72
- Parent:
- 27:463688e3bd12
- Child:
- 29:6c59b0bba861
--- a/AlohaTransceiver.cpp Sat Sep 03 02:02:22 2016 +0000 +++ b/AlohaTransceiver.cpp Sat Sep 03 02:37:53 2016 +0000 @@ -5,7 +5,12 @@ #include "AlohaFrame.h" #include "RingBuffer.h" +#define ALLOW_CALLBACK_DEBUG 0 +#define SET_FLAG(t, x) (t) |= 1 << (x) +#define CLEAR_FLAG(t, x) (t) &= ~(1 << (x)) +#define TOGGLE_FLAG(t, x) (t) ^= 1 << (x) +#define CHECK_FLAG(t, x) (t) >> (x) & 1 // declear the type of radio state typedef enum @@ -66,6 +71,9 @@ // initialize sequenceid memset(seqid, 0x0, sizeof(seqid)); + // clear flags + flags = 0xff; + // configure properties #if USE_MODEM_LORA == 1 Settings.Power = TX_OUTPUT_POWER; @@ -209,6 +217,9 @@ } case TX: { + // set tx to done, allow next transmission + setTxDoneFlag(); + Radio.Rx( 0 ); State = LOWPOWER; break; @@ -234,7 +245,7 @@ case LOWPOWER: { // transmit packet when the radio is free - if (AlohaTxQueue.getCounter() > 0) + if (getTxDoneFlag() && AlohaTxQueue.getCounter() > 0) { AlohaFrame *frame = AlohaTxQueue.dequeue(); @@ -249,6 +260,9 @@ // send to radio Radio.Send(buffer, frame_length); + // block the next transmission until previous transmission is done + clearTxDoneFlag(); + // free memory delete frame; } @@ -360,6 +374,21 @@ #endif } +bool AlohaTransceiver::getTxDoneFlag() +{ + return CHECK_FLAG(flags, 0); +} + +void AlohaTransceiver::setTxDoneFlag() +{ + SET_FLAG(flags, 0); +} + +void AlohaTransceiver::clearTxDoneFlag() +{ + CLEAR_FLAG(flags, 0); +} + void AlohaTransceiver::registerType(AlohaFrame::AlohaType_t type, aloha_callback_func f) { AlohaTypeCallbackTable[type] = f; @@ -417,7 +446,7 @@ State = TX; #ifdef DEBUG_ALOHA - debug(0, "> OnTxDone\n\r" ); + debug_if(ALLOW_CALLBACK_DEBUG, "> OnTxDone\n\r" ); #endif } @@ -441,7 +470,7 @@ State = RX; #ifdef DEBUG_ALOHA - debug(0, "> OnRxDone\n\r" ); + debug_if(ALLOW_CALLBACK_DEBUG, "> OnRxDone\n\r" ); #endif } @@ -451,7 +480,7 @@ State = TX_TIMEOUT; #ifdef DEBUG_ALOHA - debug(0, "> OnTxTimeout\n\r" ); + debug_if(ALLOW_CALLBACK_DEBUG, "> OnTxTimeout\n\r" ); #endif } @@ -461,7 +490,7 @@ State = RX_TIMEOUT; #ifdef DEBUG_ALOHA - debug(0, "> OnRxTimeout\n\r" ); + debug_if(ALLOW_CALLBACK_DEBUG, "> OnRxTimeout\n\r" ); #endif } @@ -471,7 +500,7 @@ State = RX_ERROR; #ifdef DEBUG_ALOHA - debug(0, "> OnRxError\n\r" ); + debug_if(ALLOW_CALLBACK_DEBUG, "> OnRxError\n\r" ); #endif }