LMiC adapted to work with SX1272MB2xAS LoRa shield.
Fork of LMiC by
Diff: radio.cpp
- Revision:
- 8:5879e83f632a
- Parent:
- 7:29058a7ccf23
--- a/radio.cpp Thu Feb 25 21:28:23 2016 +0000 +++ b/radio.cpp Mon Apr 02 12:04:59 2018 +0000 @@ -13,6 +13,18 @@ * radio driver. The selection is done by setting * USE_SMTC_RADIO_DRIVER preprocessing directive * in lmic.h + * + * ///////////////////////////////////////////////////////////////////////////// + * + * Used by Giorgos Tsapparellas for Internet of Things (IoT) smart monitoring + * device for agriculture using LoRaWAN technology. + * + * Date of issued copy: 25 January 2018 + * + * Modifications: + * - Updated to support MBED sx1272 driver library. + * - Disabled continuous reception od sx1272 LoRa shield under radio_init funtion + * as it is used only for transmitting data. *******************************************************************************/ #include "lmic.h" @@ -73,7 +85,7 @@ * Radio object declraration */ //SX1272MB1xAS Radio( NULL ); -SX1272MB1xAS *Radio; +SX1272MB2xAS *Radio; static const u2_t LORA_RXDONE_FIXUP[] = { [FSK] = us2osticks(0), // ( 0 ticks) @@ -87,7 +99,7 @@ void OnTxDone( void ) { - debug("OnTxDone enter\r\n"); + //debug("OnTxDone enter\r\n"); ostime_t now = os_getTime( ); // save exact tx time LMIC.txend = now - us2osticks( RADIO_WAKEUP_TIME ); // TXDONE FIXUP @@ -100,7 +112,7 @@ void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { - debug("OnRxDone enter\r\n"); + //debug("OnRxDone enter\r\n"); ostime_t now = os_getTime( ); // save exact rx time if( getBw( LMIC.rps ) == BW125 ) @@ -124,7 +136,7 @@ void OnTxTimeout( void ) { - debug("OnTxTimeout enter\r\n"); + //debug("OnTxTimeout enter\r\n"); ostime_t now = os_getTime( ); // indicate error @@ -138,7 +150,7 @@ void OnRxTimeout( void ) { - debug("OnRxTimeout enter\r\n"); + //debug("OnRxTimeout enter\r\n"); ostime_t now = os_getTime( ); // indicate timeout LMIC.dataLen = 0; @@ -151,7 +163,7 @@ void OnRxError( void ) { - debug("OnRxError enter\r\n"); + //debug("OnRxError enter\r\n"); ostime_t now = os_getTime( ); // indicate error @@ -173,8 +185,8 @@ // get random seed from wideband noise rssi void radio_init( void ) { - debug("radio_init1 enter\r\n"); - Radio = new SX1272MB1xAS(NULL); + //debug_str("radio_init1 enter\r\n"); + Radio = new SX1272MB2xAS(NULL); hal_disableIRQs( ); // Initialize Radio driver @@ -199,7 +211,7 @@ RFLR_IRQFLAGS_CADDETECTED ); // Set radio in continuous reception - Radio->Rx( 0 ); + /*Radio->Rx( 0 ); for( int i = 1; i < 16; i++ ) { @@ -209,23 +221,23 @@ while( ( b = Radio->Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) == ( Radio->Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) ); randbuf[i] = ( randbuf[i] << 1 ) | b; } - } + }*/ randbuf[0] = 16; // set initial index - + // Change LoRa modem SyncWord Radio->Write( REG_LR_SYNCWORD, LORA_MAC_SYNCWORD ); Radio->Sleep( ); hal_enableIRQs( ); - debug("radio_init exit\r\n"); + //debug_str("radio_init exit\r\n"); } // return next random byte derived from seed buffer // (buf[0] holds index of next byte to be returned) u1_t radio_rand1( void ) { - debug("radio_rand1 enter\r\n"); + //debug("radio_rand1 enter\r\n"); u1_t i = randbuf[0]; ASSERT( i != 0 ); if( i == 16 ) @@ -240,7 +252,7 @@ void os_radio( u1_t mode ) { -//debug_val("os_radio enter ",mode); + //debug_val("os_radio enter ",mode); hal_disableIRQs( ); switch( mode ) { @@ -1030,7 +1042,7 @@ hal_disableIRQs(); // manually reset radio -#ifdef CFG_sx1276_radio +#ifdef CFG_sx1272_radio hal_pin_rst(0); // drive RST pin low #else hal_pin_rst(1); // drive RST pin high @@ -1197,8 +1209,8 @@ void os_radio (u1_t mode) { -//debug("os_radio enter\r\n"); - // hal_disableIRQs(); + //debug("os_radio enter\r\n"); + // hal_disableIRQs(); switch (mode) { case RADIO_RST: // put radio to sleep