pingpong coragem

Dependents:   SX1272PingPong

Committer:
mluis
Date:
Tue Jan 05 16:43:48 2016 +0000
Revision:
0:45c4f0364ca4
Child:
1:b0372ef620d0
Library creation based on SX1276Lib and https://github.com/Lora-net/LoRaMac-node

Who changed what in which revision?

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