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
Diff: radio/radio.h
- Revision:
- 0:6b3ac9c5a042
- Child:
- 4:e4bfe9183f94
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/radio/radio.h Wed Feb 28 10:48:11 2018 -0800 @@ -0,0 +1,136 @@ +#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 RadioState_t GetStatus(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 void Send(uint8_t size); + static void PrintStatus(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 dio0callback(void); + static void dio1callback(void); + static void boardInit(void); + static SX127x_lora lora; + static SX127x_fsk fsk; + static void rfsw_callback(void); + static InterruptIn dio0; + static InterruptIn dio1; + static void set_tx_dbm(int8_t dbm); + static void ocp(uint8_t ma); + +}; + +