This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

How to install

  • Create an account on Mbed: https://os.mbed.com/account/signup/
  • Import project into Compiler
  • In the Program Workspace select "Formula_Nucleo_Reader"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "B-L072Z-LRWAN1" and then "Add to your Mbed Compiler"
  • Finally click "Compile", if the build was successful, the binary would download automatically
  • To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
Committer:
wardm
Date:
Sat May 19 11:41:10 2018 +0000
Revision:
12:02d779e8c4f6
Code for Technion Formula car sensors reader transmit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wardm 12:02d779e8c4f6 1 /*
wardm 12:02d779e8c4f6 2 / _____) _ | |
wardm 12:02d779e8c4f6 3 ( (____ _____ ____ _| |_ _____ ____| |__
wardm 12:02d779e8c4f6 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
wardm 12:02d779e8c4f6 5 _____) ) ____| | | || |_| ____( (___| | | |
wardm 12:02d779e8c4f6 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
wardm 12:02d779e8c4f6 7 (C) 2014 Semtech
wardm 12:02d779e8c4f6 8
wardm 12:02d779e8c4f6 9 Description: -
wardm 12:02d779e8c4f6 10
wardm 12:02d779e8c4f6 11 License: Revised BSD License, see LICENSE.TXT file include in the project
wardm 12:02d779e8c4f6 12
wardm 12:02d779e8c4f6 13 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
wardm 12:02d779e8c4f6 14 */
wardm 12:02d779e8c4f6 15
wardm 12:02d779e8c4f6 16 /*
wardm 12:02d779e8c4f6 17 * additional development to make it more generic across multiple OS versions
wardm 12:02d779e8c4f6 18 * (c) 2017 Helmut Tschemernjak
wardm 12:02d779e8c4f6 19 * 30826 Garbsen (Hannover) Germany
wardm 12:02d779e8c4f6 20 */
wardm 12:02d779e8c4f6 21
wardm 12:02d779e8c4f6 22 #ifndef __SX1276_MBED_HAL_H__
wardm 12:02d779e8c4f6 23 #define __SX1276_MBED_HAL_H__
wardm 12:02d779e8c4f6 24
wardm 12:02d779e8c4f6 25
wardm 12:02d779e8c4f6 26 #include "sx1276.h"
wardm 12:02d779e8c4f6 27
wardm 12:02d779e8c4f6 28
wardm 12:02d779e8c4f6 29 #ifdef __MBED__
wardm 12:02d779e8c4f6 30 #define XSPI SPI
wardm 12:02d779e8c4f6 31 #endif
wardm 12:02d779e8c4f6 32
wardm 12:02d779e8c4f6 33
wardm 12:02d779e8c4f6 34 /*!
wardm 12:02d779e8c4f6 35 * Actual implementation of a SX1276 radio, includes some modifications to make it
wardm 12:02d779e8c4f6 36 * compatible with the MB1 LAS board
wardm 12:02d779e8c4f6 37 */
wardm 12:02d779e8c4f6 38 class SX1276Generic : public SX1276
wardm 12:02d779e8c4f6 39 {
wardm 12:02d779e8c4f6 40 protected:
wardm 12:02d779e8c4f6 41 /*!
wardm 12:02d779e8c4f6 42 * Antenna switch GPIO pins objects
wardm 12:02d779e8c4f6 43 */
wardm 12:02d779e8c4f6 44 DigitalOut *_antSwitch;
wardm 12:02d779e8c4f6 45 DigitalOut *_antSwitchTX;
wardm 12:02d779e8c4f6 46 DigitalOut *_antSwitchTXBoost;
wardm 12:02d779e8c4f6 47
wardm 12:02d779e8c4f6 48 /*!
wardm 12:02d779e8c4f6 49 * SX1276 Reset pin
wardm 12:02d779e8c4f6 50 */
wardm 12:02d779e8c4f6 51 DigitalInOut *_reset;
wardm 12:02d779e8c4f6 52
wardm 12:02d779e8c4f6 53 /*!
wardm 12:02d779e8c4f6 54 * TCXO being used with the Murata Module
wardm 12:02d779e8c4f6 55 */
wardm 12:02d779e8c4f6 56 DigitalOut *_tcxo;
wardm 12:02d779e8c4f6 57
wardm 12:02d779e8c4f6 58 /*!
wardm 12:02d779e8c4f6 59 * SPI Interface
wardm 12:02d779e8c4f6 60 */
wardm 12:02d779e8c4f6 61 XSPI *_spi; // mosi, miso, sclk
wardm 12:02d779e8c4f6 62 DigitalOut *_nss;
wardm 12:02d779e8c4f6 63
wardm 12:02d779e8c4f6 64 /*!
wardm 12:02d779e8c4f6 65 * SX1276 DIO pins
wardm 12:02d779e8c4f6 66 */
wardm 12:02d779e8c4f6 67 InterruptIn *_dio0;
wardm 12:02d779e8c4f6 68 InterruptIn *_dio1;
wardm 12:02d779e8c4f6 69 InterruptIn *_dio2;
wardm 12:02d779e8c4f6 70 InterruptIn *_dio3;
wardm 12:02d779e8c4f6 71 InterruptIn *_dio4;
wardm 12:02d779e8c4f6 72 DigitalIn *_dio5;
wardm 12:02d779e8c4f6 73
wardm 12:02d779e8c4f6 74 /*!
wardm 12:02d779e8c4f6 75 * Tx and Rx timers
wardm 12:02d779e8c4f6 76 */
wardm 12:02d779e8c4f6 77 Timeout txTimeoutTimer;
wardm 12:02d779e8c4f6 78 Timeout rxTimeoutTimer;
wardm 12:02d779e8c4f6 79 Timeout rxTimeoutSyncWord;
wardm 12:02d779e8c4f6 80
wardm 12:02d779e8c4f6 81
wardm 12:02d779e8c4f6 82 private:
wardm 12:02d779e8c4f6 83 /*!
wardm 12:02d779e8c4f6 84 * triggers definition
wardm 12:02d779e8c4f6 85 */
wardm 12:02d779e8c4f6 86 typedef void (SX1276Generic::*Trigger)(void);
wardm 12:02d779e8c4f6 87
wardm 12:02d779e8c4f6 88
wardm 12:02d779e8c4f6 89 public:
wardm 12:02d779e8c4f6 90 SX1276Generic( RadioEvents_t *events, BoardType_t board,
wardm 12:02d779e8c4f6 91 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
wardm 12:02d779e8c4f6 92 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
wardm 12:02d779e8c4f6 93 PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC);
wardm 12:02d779e8c4f6 94
wardm 12:02d779e8c4f6 95
wardm 12:02d779e8c4f6 96 SX1276Generic( RadioEvents_t *events );
wardm 12:02d779e8c4f6 97
wardm 12:02d779e8c4f6 98 virtual ~SX1276Generic();
wardm 12:02d779e8c4f6 99
wardm 12:02d779e8c4f6 100 protected:
wardm 12:02d779e8c4f6 101 /*!
wardm 12:02d779e8c4f6 102 * @brief Initializes the radio I/Os pins interface
wardm 12:02d779e8c4f6 103 */
wardm 12:02d779e8c4f6 104 virtual void IoInit( void );
wardm 12:02d779e8c4f6 105
wardm 12:02d779e8c4f6 106 /*!
wardm 12:02d779e8c4f6 107 * @brief Initializes the radio SPI
wardm 12:02d779e8c4f6 108 */
wardm 12:02d779e8c4f6 109 virtual void SpiInit( void );
wardm 12:02d779e8c4f6 110
wardm 12:02d779e8c4f6 111 /*!
wardm 12:02d779e8c4f6 112 * @brief Initializes DIO IRQ handlers
wardm 12:02d779e8c4f6 113 *
wardm 12:02d779e8c4f6 114 * @param [IN] irqHandlers Array containing the IRQ callback functions
wardm 12:02d779e8c4f6 115 */
wardm 12:02d779e8c4f6 116 virtual void IoIrqInit( DioIrqHandler *irqHandlers );
wardm 12:02d779e8c4f6 117
wardm 12:02d779e8c4f6 118 /*!
wardm 12:02d779e8c4f6 119 * @brief De-initializes the radio I/Os pins interface.
wardm 12:02d779e8c4f6 120 *
wardm 12:02d779e8c4f6 121 * \remark Useful when going in MCU lowpower modes
wardm 12:02d779e8c4f6 122 */
wardm 12:02d779e8c4f6 123 virtual void IoDeInit( void );
wardm 12:02d779e8c4f6 124
wardm 12:02d779e8c4f6 125 /*!
wardm 12:02d779e8c4f6 126 * @brief Gets the board PA selection configuration
wardm 12:02d779e8c4f6 127 *
wardm 12:02d779e8c4f6 128 * @param [IN] channel Channel frequency in Hz
wardm 12:02d779e8c4f6 129 * @retval PaSelect RegPaConfig PaSelect value
wardm 12:02d779e8c4f6 130 */
wardm 12:02d779e8c4f6 131 virtual uint8_t GetPaSelect( uint32_t channel );
wardm 12:02d779e8c4f6 132
wardm 12:02d779e8c4f6 133 /*!
wardm 12:02d779e8c4f6 134 * @brief Set the RF Switch I/Os pins in Low Power mode
wardm 12:02d779e8c4f6 135 *
wardm 12:02d779e8c4f6 136 * @param [IN] status enable or disable
wardm 12:02d779e8c4f6 137 */
wardm 12:02d779e8c4f6 138 virtual void SetAntSwLowPower( bool status );
wardm 12:02d779e8c4f6 139
wardm 12:02d779e8c4f6 140 /*!
wardm 12:02d779e8c4f6 141 * @brief Initializes the RF Switch I/Os pins interface
wardm 12:02d779e8c4f6 142 */
wardm 12:02d779e8c4f6 143 virtual void AntSwInit( void );
wardm 12:02d779e8c4f6 144
wardm 12:02d779e8c4f6 145 /*!
wardm 12:02d779e8c4f6 146 * @brief De-initializes the RF Switch I/Os pins interface
wardm 12:02d779e8c4f6 147 *
wardm 12:02d779e8c4f6 148 * @remark Needed to decrease the power consumption in MCU lowpower modes
wardm 12:02d779e8c4f6 149 */
wardm 12:02d779e8c4f6 150 virtual void AntSwDeInit( void );
wardm 12:02d779e8c4f6 151
wardm 12:02d779e8c4f6 152 /*!
wardm 12:02d779e8c4f6 153 * @brief Controls the antena switch if necessary.
wardm 12:02d779e8c4f6 154 *
wardm 12:02d779e8c4f6 155 * @remark see errata note
wardm 12:02d779e8c4f6 156 *
wardm 12:02d779e8c4f6 157 * @param [IN] opMode Current radio operating mode
wardm 12:02d779e8c4f6 158 */
wardm 12:02d779e8c4f6 159 virtual void SetAntSw( uint8_t opMode );
wardm 12:02d779e8c4f6 160
wardm 12:02d779e8c4f6 161 /*
wardm 12:02d779e8c4f6 162 * The the Timeout for a given Timer.
wardm 12:02d779e8c4f6 163 */
wardm 12:02d779e8c4f6 164 virtual void SetTimeout(TimeoutTimer_t timer, timeoutFuncPtr, int timeout_ms = 0);
wardm 12:02d779e8c4f6 165
wardm 12:02d779e8c4f6 166 /*
wardm 12:02d779e8c4f6 167 * A simple ms sleep
wardm 12:02d779e8c4f6 168 */
wardm 12:02d779e8c4f6 169 virtual void Sleep_ms(int ms);
wardm 12:02d779e8c4f6 170
wardm 12:02d779e8c4f6 171
wardm 12:02d779e8c4f6 172 public:
wardm 12:02d779e8c4f6 173
wardm 12:02d779e8c4f6 174 /*!
wardm 12:02d779e8c4f6 175 * @brief Detect the board connected by reading the value of the antenna switch pin
wardm 12:02d779e8c4f6 176 */
wardm 12:02d779e8c4f6 177 virtual uint8_t DetectBoardType( void );
wardm 12:02d779e8c4f6 178
wardm 12:02d779e8c4f6 179 /*!
wardm 12:02d779e8c4f6 180 * @brief Checks if the given RF frequency is supported by the hardware
wardm 12:02d779e8c4f6 181 *
wardm 12:02d779e8c4f6 182 * @param [IN] frequency RF frequency to be checked
wardm 12:02d779e8c4f6 183 * @retval isSupported [true: supported, false: unsupported]
wardm 12:02d779e8c4f6 184 */
wardm 12:02d779e8c4f6 185 virtual bool CheckRfFrequency( uint32_t frequency );
wardm 12:02d779e8c4f6 186
wardm 12:02d779e8c4f6 187 /*!
wardm 12:02d779e8c4f6 188 * @brief Writes the radio register at the specified address
wardm 12:02d779e8c4f6 189 *
wardm 12:02d779e8c4f6 190 * @param [IN]: addr Register address
wardm 12:02d779e8c4f6 191 * @param [IN]: data New register value
wardm 12:02d779e8c4f6 192 */
wardm 12:02d779e8c4f6 193 virtual void Write ( uint8_t addr, uint8_t data ) ;
wardm 12:02d779e8c4f6 194
wardm 12:02d779e8c4f6 195 /*!
wardm 12:02d779e8c4f6 196 * @brief Reads the radio register at the specified address
wardm 12:02d779e8c4f6 197 *
wardm 12:02d779e8c4f6 198 * @param [IN]: addr Register address
wardm 12:02d779e8c4f6 199 * @retval data Register value
wardm 12:02d779e8c4f6 200 */
wardm 12:02d779e8c4f6 201 virtual uint8_t Read ( uint8_t addr ) ;
wardm 12:02d779e8c4f6 202
wardm 12:02d779e8c4f6 203 /*!
wardm 12:02d779e8c4f6 204 * @brief Writes multiple radio registers starting at address
wardm 12:02d779e8c4f6 205 *
wardm 12:02d779e8c4f6 206 * @param [IN] addr First Radio register address
wardm 12:02d779e8c4f6 207 * @param [IN] buffer Buffer containing the new register's values
wardm 12:02d779e8c4f6 208 * @param [IN] size Number of registers to be written
wardm 12:02d779e8c4f6 209 */
wardm 12:02d779e8c4f6 210 virtual void Write( uint8_t addr, void *buffer, uint8_t size ) ;
wardm 12:02d779e8c4f6 211
wardm 12:02d779e8c4f6 212 /*!
wardm 12:02d779e8c4f6 213 * @brief Reads multiple radio registers starting at address
wardm 12:02d779e8c4f6 214 *
wardm 12:02d779e8c4f6 215 * @param [IN] addr First Radio register address
wardm 12:02d779e8c4f6 216 * @param [OUT] buffer Buffer where to copy the registers data
wardm 12:02d779e8c4f6 217 * @param [IN] size Number of registers to be read
wardm 12:02d779e8c4f6 218 */
wardm 12:02d779e8c4f6 219 virtual void Read ( uint8_t addr, void *buffer, uint8_t size ) ;
wardm 12:02d779e8c4f6 220
wardm 12:02d779e8c4f6 221 /*!
wardm 12:02d779e8c4f6 222 * @brief Writes the buffer contents to the SX1276 FIFO
wardm 12:02d779e8c4f6 223 *
wardm 12:02d779e8c4f6 224 * @param [IN] buffer Buffer containing data to be put on the FIFO.
wardm 12:02d779e8c4f6 225 * @param [IN] size Number of bytes to be written to the FIFO
wardm 12:02d779e8c4f6 226 */
wardm 12:02d779e8c4f6 227 virtual void WriteFifo( void *buffer, uint8_t size ) ;
wardm 12:02d779e8c4f6 228
wardm 12:02d779e8c4f6 229 /*!
wardm 12:02d779e8c4f6 230 * @brief Reads the contents of the SX1276 FIFO
wardm 12:02d779e8c4f6 231 *
wardm 12:02d779e8c4f6 232 * @param [OUT] buffer Buffer where to copy the FIFO read data.
wardm 12:02d779e8c4f6 233 * @param [IN] size Number of bytes to be read from the FIFO
wardm 12:02d779e8c4f6 234 */
wardm 12:02d779e8c4f6 235 virtual void ReadFifo( void *buffer, uint8_t size ) ;
wardm 12:02d779e8c4f6 236
wardm 12:02d779e8c4f6 237 /*!
wardm 12:02d779e8c4f6 238 * @brief Reset the SX1276
wardm 12:02d779e8c4f6 239 */
wardm 12:02d779e8c4f6 240 virtual void Reset( void );
wardm 12:02d779e8c4f6 241
wardm 12:02d779e8c4f6 242 /*!
wardm 12:02d779e8c4f6 243 * \brief Sets the radio output power.
wardm 12:02d779e8c4f6 244 *
wardm 12:02d779e8c4f6 245 * @param [IN] power Sets the RF output power
wardm 12:02d779e8c4f6 246 */
wardm 12:02d779e8c4f6 247 virtual void SetRfTxPower( int8_t power );
wardm 12:02d779e8c4f6 248
wardm 12:02d779e8c4f6 249 };
wardm 12:02d779e8c4f6 250
wardm 12:02d779e8c4f6 251 #endif // __SX1276_MBED_HAL_H__