Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LoRaWAN-SanJose_Bootcamp LoRaWAN-grove-cayenne LoRaWAN-classC-demo LoRaWAN-grove-cayenne ... more
radio/radio.h
- Committer:
- Wayne Roberts
- Date:
- 2018-05-04
- Revision:
- 7:4b6f960dcca2
- Parent:
- 4:e4bfe9183f94
- Child:
- 8:5a5ea7cc946f
File content as of revision 7:4b6f960dcca2:
#include "sx127x_lora.h" #include "sx127x_fsk.h" #define RADIO_OSC_STARTUP_us 1000 // [ms] #define RADIO_SLEEP_TO_RX_us 2000 // [ms] #define RADIO_WAKEUP_TIME_us ( RADIO_OSC_STARTUP_us + RADIO_SLEEP_TO_RX_us ) typedef enum { MODEM_FSK = 0, MODEM_LORA, } RadioModems_t; typedef enum { RF_IDLE = 0, RF_RX_RUNNING, RF_TX_RUNNING, RF_CAD, } RadioState_t; /*! * \brief Radio driver callback functions */ typedef struct { void (*Dio0_top_half)(us_timestamp_t curTime); /*! * \brief Tx Done callback prototype. */ void ( *TxDone )(us_timestamp_t curTime); /*! * \brief Tx Timeout callback prototype. */ void ( *TxTimeout )( void ); /*! * \brief Rx Done callback prototype. * * \param [IN] payload Received buffer pointer * \param [IN] size Received buffer size * \param [IN] rssi RSSI value computed while receiving the frame [dBm] * \param [IN] snr Raw SNR value given by the radio hardware * FSK : N/A ( set to 0 ) * LoRa: SNR value in dB * \param [IN] curTime captured time at RxDone event occurance */ void ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, us_timestamp_t curTime); /*! * \brief Rx Timeout callback prototype. */ void ( *RxTimeout )( void ); /*! * \brief Rx Error callback prototype. */ void ( *RxError )( void ); /*! * \brief FHSS Change Channel callback prototype. * * \param [IN] currentChannel Index number of the current channel */ void ( *FhssChangeChannel )( uint8_t currentChannel ); /*! * \brief CAD Done callback prototype. * * \param [IN] channelDetected Channel Activity detected during the CAD */ void ( *CadDone ) ( bool channelActivityDetected ); } RadioEvents_t; class Radio { public: static void SetTxContinuousWave(unsigned hz, int8_t txPower, unsigned timeout); static uint32_t Random(void); static void SetPublicNetwork(bool); static void Sleep(void); static void SetChannel(unsigned hz); static void SetRxMaxPayloadLength(RadioModems_t, uint8_t); static void Rx(unsigned timeout); static void Standby(void); static bool CheckRfFrequency(unsigned hz); static void Init(const RadioEvents_t*); static int Send(uint8_t size, timestamp_t maxListenTime, timestamp_t channelFreeTime, int rssiThresh); static void PrintStatus(void); static void UserContext(void); #ifdef DUTY_ENABLE static us_timestamp_t TimeOnAir(RadioModems_t, uint8_t); #endif /* DUTY_ENABLE */ static void SetRxConfig( RadioModems_t modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, uint8_t payloadLen, bool crcOn, bool iqInverted ); static void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preambleLen, bool fixLen, bool crcOn, bool iqInverted ); static LowPowerTimer lpt; static SX127x radio; private: static void LoRaConfig(uint32_t bandwidth, uint8_t datarate, uint8_t coderate, uint16_t preambleLen, bool fixLen, bool crcOn); static void boardInit(void); static SX127x_lora lora; static SX127x_fsk fsk; static void rfsw_callback(void); static void set_tx_dbm(int8_t dbm); static void ocp(uint8_t ma); static InterruptIn dio0; static InterruptIn dio1; static void dio0isr(void); static void dio1isr(void); static void dio0UserContext(void); static void dio1UserContext(void); };