Hardware Abstraction Layer, permitting any LoRa application to use any LoRa radio chip

Dependents:   alarm_slave alarm_master lora_p2p lorawan1v1 ... more

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
if you're using LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

Pin assigned to arduino LoRa radio shield form-factor

Revision:
0:9c052ff8dd6a
Child:
1:e79b0a55135f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/radio.h	Thu Jul 05 17:31:54 2018 -0700
@@ -0,0 +1,147 @@
+#include "sx12xx.h"
+#ifdef SX127x_H 
+#include "sx127x_lora.h"
+#include "sx127x_fsk.h"
+#endif /* SX127x_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,
+    MODEM_FLRC,
+} RadioModems_t;
+
+/*!
+ * \brief Radio driver callback functions
+ */
+typedef struct
+{
+    void (*Dio0_top_half)(us_timestamp_t curTime);
+    /*!
+     * \brief  Tx Done callback prototype.
+     */
+    void    (*TxDone_topHalf)(void);    // read irqAt for timestamp of interrupt
+    void    (*TxDone_botHalf)(void);    // read irqAt for timestamp of interrupt
+    /*!
+     * \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 )(uint16_t size, int16_t rssi, int8_t snr);
+    void    ( *RxDone )(uint8_t size, float rssi, float snr);    // read radio.rx_buf for payload, irqAt for timestamp of interrupt
+    /*!
+     * \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 float getFrfMHz(void);
+        static void SetRxMaxPayloadLength(RadioModems_t, uint8_t);
+        static void Rx(unsigned timeout); // timeout 0 for continuous rx
+        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 service(void);
+		static uint32_t lora_toa_us(uint8_t pktLen);
+        static volatile us_timestamp_t irqAt;
+#ifdef DUTY_ENABLE
+        static us_timestamp_t TimeOnAir(RadioModems_t, uint8_t);
+#endif /* DUTY_ENABLE */
+
+        static void LoRaModemConfig(unsigned bwKHz, uint8_t sf, uint8_t cr);
+        static void LoRaPacketConfig(unsigned preambleLen, bool fixLen, bool crcOn, bool invIQ);
+        static void SetLoRaSymbolTimeout(uint8_t symbs);
+
+        static void GFSKModemConfig(unsigned bps, unsigned bwKHz, unsigned fdev_hz);
+        static void GFSKPacketConfig(unsigned preambleLen, bool fixLen, bool crcOn);
+
+        static void set_tx_dbm(int8_t dbm);
+
+        static LowPowerTimer lpt;
+#ifdef SX127x_H 
+        static SX127x radio;
+#elif defined(SX126x_H)
+        static SX126x radio;
+#elif defined(SX128x_H)
+        static SX128x radio;
+#else
+        #error import radio driver library
+#endif
+
+    private:
+        static void boardInit(void);
+#ifdef SX127x_H 
+        static SX127x_lora lora;
+        static SX127x_fsk fsk;
+#endif /* SX127x_H */
+#ifdef SX126x_H 
+        static RadioModems_t _m_;
+        static void rx_done(uint8_t, float, float);
+        static void txDoneBottom(void);
+        static void timeout_callback(bool);
+        static void dio1_top_half(void);
+        static PacketParams_t pp;
+#endif /* SX126x_H */
+#ifdef SX128x_H 
+        static RadioModems_t _m_;
+        static void readChip(void);
+        static PacketParams_t ppGFSK, ppLORA, ppFLRC;
+        static ModulationParams_t mpFLRC, mpBLE_GFSK, mpLORA;
+        static void diox_top_half(void);
+        static void rxDone(uint8_t size, const pktStatus_t*);
+        static void txDoneBottom(void);
+        static void timeout_callback(bool);
+#endif /* SX128x_H */
+        static void chipModeChange(void);
+        static void rfsw_callback(void);
+        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);
+};
+
+