Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

213 line
6.4 KiB

  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C) 2014 Semtech
  8. Description: -
  9. License: Revised BSD License, see LICENSE.TXT file include in the project
  10. Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
  11. */
  12. #ifndef __SX1276_HAL_H__
  13. #define __SX1276_HAL_H__
  14. #include "sx1276.h"
  15. /*!
  16. * @brief Radio hardware registers initialization definition
  17. *
  18. * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
  19. */
  20. #define RADIO_INIT_REGISTERS_VALUE \
  21. { \
  22. { MODEM_FSK , REG_LNA , 0x23 },\
  23. { MODEM_FSK , REG_RXCONFIG , 0x1E },\
  24. { MODEM_FSK , REG_RSSICONFIG , 0xD2 },\
  25. { MODEM_FSK , REG_AFCFEI , 0x01 },\
  26. { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\
  27. { MODEM_FSK , REG_OSC , 0x07 },\
  28. { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\
  29. { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\
  30. { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\
  31. { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\
  32. { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\
  33. { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\
  34. { MODEM_FSK , REG_IMAGECAL , 0x02 },\
  35. { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\
  36. { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\
  37. { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
  38. } \
  39. /*!
  40. * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
  41. */
  42. class SX1276MB1xAS : public SX1276
  43. {
  44. protected:
  45. /*!
  46. * Antenna switch GPIO pins objects
  47. */
  48. DigitalInOut AntSwitch;
  49. DigitalIn Fake;
  50. private:
  51. static const RadioRegisters_t RadioRegsInit[];
  52. public:
  53. SX1276MB1xAS( RadioEvents_t *events,
  54. PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
  55. PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
  56. PinName antSwitch );
  57. SX1276MB1xAS( RadioEvents_t *events );
  58. virtual ~SX1276MB1xAS( ) { };
  59. protected:
  60. /*!
  61. * @brief Initializes the radio I/Os pins interface
  62. */
  63. virtual void IoInit( void );
  64. /*!
  65. * @brief Initializes the radio registers
  66. */
  67. virtual void RadioRegistersInit( );
  68. /*!
  69. * @brief Initializes the radio SPI
  70. */
  71. virtual void SpiInit( void );
  72. /*!
  73. * @brief Initializes DIO IRQ handlers
  74. *
  75. * @param [IN] irqHandlers Array containing the IRQ callback functions
  76. */
  77. virtual void IoIrqInit( DioIrqHandler *irqHandlers );
  78. /*!
  79. * @brief De-initializes the radio I/Os pins interface.
  80. *
  81. * \remark Useful when going in MCU lowpower modes
  82. */
  83. virtual void IoDeInit( void );
  84. /*!
  85. * \brief Sets the radio output power.
  86. *
  87. * @param [IN] power Sets the RF output power
  88. */
  89. virtual void SetRfTxPower( int8_t power );
  90. /*!
  91. * @brief Gets the board PA selection configuration
  92. *
  93. * @param [IN] channel Channel frequency in Hz
  94. * @retval PaSelect RegPaConfig PaSelect value
  95. */
  96. virtual uint8_t GetPaSelect( uint32_t channel );
  97. /*!
  98. * @brief Set the RF Switch I/Os pins in Low Power mode
  99. *
  100. * @param [IN] status enable or disable
  101. */
  102. virtual void SetAntSwLowPower( bool status );
  103. /*!
  104. * @brief Initializes the RF Switch I/Os pins interface
  105. */
  106. virtual void AntSwInit( void );
  107. /*!
  108. * @brief De-initializes the RF Switch I/Os pins interface
  109. *
  110. * @remark Needed to decrease the power consumption in MCU lowpower modes
  111. */
  112. virtual void AntSwDeInit( void );
  113. /*!
  114. * @brief Controls the antena switch if necessary.
  115. *
  116. * @remark see errata note
  117. *
  118. * @param [IN] opMode Current radio operating mode
  119. */
  120. virtual void SetAntSw( uint8_t opMode );
  121. public:
  122. /*!
  123. * @brief Detect the board connected by reading the value of the antenna switch pin
  124. */
  125. virtual uint8_t DetectBoardType( void );
  126. /*!
  127. * @brief Checks if the given RF frequency is supported by the hardware
  128. *
  129. * @param [IN] frequency RF frequency to be checked
  130. * @retval isSupported [true: supported, false: unsupported]
  131. */
  132. virtual bool CheckRfFrequency( uint32_t frequency );
  133. /*!
  134. * @brief Writes the radio register at the specified address
  135. *
  136. * @param [IN]: addr Register address
  137. * @param [IN]: data New register value
  138. */
  139. virtual void Write ( uint8_t addr, uint8_t data ) ;
  140. /*!
  141. * @brief Reads the radio register at the specified address
  142. *
  143. * @param [IN]: addr Register address
  144. * @retval data Register value
  145. */
  146. virtual uint8_t Read ( uint8_t addr ) ;
  147. /*!
  148. * @brief Writes multiple radio registers starting at address
  149. *
  150. * @param [IN] addr First Radio register address
  151. * @param [IN] buffer Buffer containing the new register's values
  152. * @param [IN] size Number of registers to be written
  153. */
  154. virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  155. /*!
  156. * @brief Reads multiple radio registers starting at address
  157. *
  158. * @param [IN] addr First Radio register address
  159. * @param [OUT] buffer Buffer where to copy the registers data
  160. * @param [IN] size Number of registers to be read
  161. */
  162. virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
  163. /*!
  164. * @brief Writes the buffer contents to the SX1276 FIFO
  165. *
  166. * @param [IN] buffer Buffer containing data to be put on the FIFO.
  167. * @param [IN] size Number of bytes to be written to the FIFO
  168. */
  169. virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
  170. /*!
  171. * @brief Reads the contents of the SX1276 FIFO
  172. *
  173. * @param [OUT] buffer Buffer where to copy the FIFO read data.
  174. * @param [IN] size Number of bytes to be read from the FIFO
  175. */
  176. virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
  177. /*!
  178. * @brief Reset the SX1276
  179. */
  180. virtual void Reset( void );
  181. };
  182. #endif // __SX1276_HAL_H__