This code holds the complete demo set for the sx1280: PingPong, PER and Ranging Outdoor demo application. >>>>> This code MUST run on the mbed library release 127 or everything will be painfully slow.

Dependencies:   mbed SX1280Lib DmTftLibrary

* This code MUST run on the mbed library release 127 or everything will be painfully slow.*
Committer:
GregCr
Date:
Mon Apr 03 14:58:51 2017 +0000
Revision:
5:a0f5842fb337
Parent:
2:8ebe57eb273a
Child:
8:c0a5f53fe196
Corrected missing wakeup call when leaving sleep mode; Correction of BW not being updated when going into Settings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:9c0917bfde97 1 /*
GregCr 0:9c0917bfde97 2 ______ _
GregCr 0:9c0917bfde97 3 / _____) _ | |
GregCr 0:9c0917bfde97 4 ( (____ _____ ____ _| |_ _____ ____| |__
GregCr 0:9c0917bfde97 5 \____ \| ___ | (_ _) ___ |/ ___) _ \
GregCr 0:9c0917bfde97 6 _____) ) ____| | | || |_| ____( (___| | | |
GregCr 0:9c0917bfde97 7 (______/|_____)_|_|_| \__)_____)\____)_| |_|
GregCr 0:9c0917bfde97 8 (C)2016 Semtech
GregCr 0:9c0917bfde97 9
GregCr 0:9c0917bfde97 10 Description: Display driver header
GregCr 0:9c0917bfde97 11
GregCr 0:9c0917bfde97 12 Maintainer: Gregory Cristian & Gilbert Menth
GregCr 0:9c0917bfde97 13 */
GregCr 0:9c0917bfde97 14
GregCr 0:9c0917bfde97 15 #ifndef DEMO_APPLICATION_H
GregCr 0:9c0917bfde97 16 #define DEMO_APPLICATION_H
GregCr 0:9c0917bfde97 17
GregCr 0:9c0917bfde97 18
GregCr 0:9c0917bfde97 19 /*!
GregCr 0:9c0917bfde97 20 * \brief Used to display firmware version on TFT (Utilities menu)
GregCr 0:9c0917bfde97 21 */
GregCr 5:a0f5842fb337 22 #define FIRMWARE_VERSION ( ( char* )"Firmware Version: 170331A" )
GregCr 0:9c0917bfde97 23
GregCr 0:9c0917bfde97 24 /*!
GregCr 0:9c0917bfde97 25 * \brief Define range of central frequency [Hz]
GregCr 0:9c0917bfde97 26 */
GregCr 0:9c0917bfde97 27 #define DEMO_CENTRAL_FREQ_MIN 2400000000UL
GregCr 0:9c0917bfde97 28 #define DEMO_CENTRAL_FREQ_MAX 2483500000UL
GregCr 0:9c0917bfde97 29
GregCr 0:9c0917bfde97 30 /*!
GregCr 0:9c0917bfde97 31 * \brief Define 3 preset central frequencies [Hz]
GregCr 0:9c0917bfde97 32 */
GregCr 0:9c0917bfde97 33 #define DEMO_CENTRAL_FREQ_PRESET1 2402000000UL
GregCr 0:9c0917bfde97 34 #define DEMO_CENTRAL_FREQ_PRESET2 2450000000UL
GregCr 0:9c0917bfde97 35 #define DEMO_CENTRAL_FREQ_PRESET3 2480000000UL
GregCr 0:9c0917bfde97 36
GregCr 0:9c0917bfde97 37 /*!
GregCr 0:9c0917bfde97 38 * \brief Define 5 preset ranging addresses
GregCr 0:9c0917bfde97 39 */
GregCr 0:9c0917bfde97 40 #define DEMO_RNG_ADDR_1 0x10000000
GregCr 0:9c0917bfde97 41 #define DEMO_RNG_ADDR_2 0x32100000
GregCr 0:9c0917bfde97 42 #define DEMO_RNG_ADDR_3 0x20012301
GregCr 0:9c0917bfde97 43 #define DEMO_RNG_ADDR_4 0x20000abc
GregCr 0:9c0917bfde97 44 #define DEMO_RNG_ADDR_5 0x32101230
GregCr 0:9c0917bfde97 45
GregCr 0:9c0917bfde97 46 /*!
GregCr 0:9c0917bfde97 47 * \brief Define antenna selection for ranging
GregCr 0:9c0917bfde97 48 */
GregCr 0:9c0917bfde97 49 #define DEMO_RNG_ANT_1 1
GregCr 0:9c0917bfde97 50 #define DEMO_RNG_ANT_2 2
GregCr 0:9c0917bfde97 51 #define DEMO_RNG_ANT_BOTH 0
GregCr 0:9c0917bfde97 52
GregCr 0:9c0917bfde97 53 /*!
GregCr 0:9c0917bfde97 54 * \brief Define units for ranging distances
GregCr 0:9c0917bfde97 55 */
GregCr 0:9c0917bfde97 56 #define DEMO_RNG_UNIT_CONV_M 1.0 // not used
GregCr 0:9c0917bfde97 57 #define DEMO_RNG_UNIT_CONV_YD 1.0936
GregCr 0:9c0917bfde97 58 #define DEMO_RNG_UNIT_CONV_MI 6.2137e-4
GregCr 0:9c0917bfde97 59 #define DEMO_RNG_UNIT_SEL_M 0
GregCr 0:9c0917bfde97 60 #define DEMO_RNG_UNIT_SEL_YD 1
GregCr 0:9c0917bfde97 61 #define DEMO_RNG_UNIT_SEL_MI 2
GregCr 0:9c0917bfde97 62
GregCr 0:9c0917bfde97 63 /*!
GregCr 0:9c0917bfde97 64 * \brief Define min and max Tx power [dBm]
GregCr 0:9c0917bfde97 65 */
GregCr 0:9c0917bfde97 66 #define DEMO_POWER_TX_MIN -18
GregCr 0:9c0917bfde97 67 #define DEMO_POWER_TX_MAX 13
GregCr 0:9c0917bfde97 68
GregCr 0:9c0917bfde97 69 /*!
GregCr 0:9c0917bfde97 70 * \brief Define min and max ranging channels count
GregCr 0:9c0917bfde97 71 */
GregCr 0:9c0917bfde97 72 #define DEMO_RNG_CHANNELS_COUNT_MAX 90
GregCr 0:9c0917bfde97 73 #define DEMO_RNG_CHANNELS_COUNT_MIN 10
GregCr 0:9c0917bfde97 74
GregCr 0:9c0917bfde97 75 /*!
GregCr 0:9c0917bfde97 76 * \brief Define min and max Z Score for ranging filtered results
GregCr 0:9c0917bfde97 77 */
GregCr 0:9c0917bfde97 78 #define DEMO_RNG_ZSCORE_MIN 1
GregCr 0:9c0917bfde97 79 #define DEMO_RNG_ZSCORE_MAX 5
GregCr 0:9c0917bfde97 80
GregCr 0:9c0917bfde97 81 /*!
GregCr 0:9c0917bfde97 82 * \brief Define min and max payload length for demo applications
GregCr 0:9c0917bfde97 83 */
GregCr 0:9c0917bfde97 84 #define DEMO_MIN_PAYLOAD 12
GregCr 0:9c0917bfde97 85 #define DEMO_FLRC_MAX_PAYLOAD 127
GregCr 0:9c0917bfde97 86 #define DEMO_GFS_LORA_MAX_PAYLOAD 255
GregCr 0:9c0917bfde97 87
GregCr 0:9c0917bfde97 88
GregCr 0:9c0917bfde97 89 /*!
GregCr 0:9c0917bfde97 90 * \brief Define current demo mode
GregCr 0:9c0917bfde97 91 */
GregCr 0:9c0917bfde97 92 enum DemoMode
GregCr 0:9c0917bfde97 93 {
GregCr 0:9c0917bfde97 94 MASTER = 0,
GregCr 0:9c0917bfde97 95 SLAVE
GregCr 0:9c0917bfde97 96 };
GregCr 0:9c0917bfde97 97
GregCr 0:9c0917bfde97 98 /*!
GregCr 0:9c0917bfde97 99 * \brief Status of ranging distance
GregCr 0:9c0917bfde97 100 */
GregCr 0:9c0917bfde97 101 enum RangingStatus
GregCr 0:9c0917bfde97 102 {
GregCr 0:9c0917bfde97 103 RNG_INIT = 0,
GregCr 0:9c0917bfde97 104 RNG_PROCESS,
GregCr 0:9c0917bfde97 105 RNG_VALID,
GregCr 0:9c0917bfde97 106 RNG_TIMEOUT,
GregCr 0:9c0917bfde97 107 RNG_PER_ERROR
GregCr 0:9c0917bfde97 108 };
GregCr 0:9c0917bfde97 109
GregCr 0:9c0917bfde97 110 /*!
GregCr 0:9c0917bfde97 111 * \brief List of states for demo state machine
GregCr 0:9c0917bfde97 112 */
GregCr 0:9c0917bfde97 113 enum DemoInternalStates
GregCr 0:9c0917bfde97 114 {
GregCr 0:9c0917bfde97 115 APP_IDLE = 0, // nothing to do (or wait a radio interrupt)
GregCr 0:9c0917bfde97 116 APP_RANGING_DONE,
GregCr 0:9c0917bfde97 117 APP_RANGING_TIMEOUT,
GregCr 0:9c0917bfde97 118 APP_RANGING_CONFIG,
GregCr 0:9c0917bfde97 119 APP_RNG,
GregCr 0:9c0917bfde97 120 SEND_PING_MSG,
GregCr 0:9c0917bfde97 121 SEND_PONG_MSG,
GregCr 0:9c0917bfde97 122 APP_RX, // Rx done
GregCr 0:9c0917bfde97 123 APP_RX_TIMEOUT, // Rx timeout
GregCr 0:9c0917bfde97 124 APP_RX_ERROR, // Rx error
GregCr 0:9c0917bfde97 125 APP_TX, // Tx done
GregCr 0:9c0917bfde97 126 APP_TX_TIMEOUT, // Tx error
GregCr 0:9c0917bfde97 127 PER_TX_START, // PER master
GregCr 0:9c0917bfde97 128 PER_RX_START // PER slave
GregCr 0:9c0917bfde97 129 };
GregCr 0:9c0917bfde97 130
GregCr 0:9c0917bfde97 131 /*!
GregCr 0:9c0917bfde97 132 * \brief Demo Settings structure of Eeprom structure
GregCr 0:9c0917bfde97 133 */
GregCr 0:9c0917bfde97 134 typedef struct
GregCr 0:9c0917bfde97 135 {
GregCr 0:9c0917bfde97 136 uint8_t Entity; // Master or Slave
GregCr 0:9c0917bfde97 137 uint8_t HoldDemo; // Put demo in hold status
GregCr 0:9c0917bfde97 138 uint8_t AntennaSwitch; // Witch antenna connected
GregCr 0:9c0917bfde97 139 uint32_t Frequency; // Demo frequency
GregCr 0:9c0917bfde97 140 int8_t TxPower; // Demo Tx power
GregCr 0:9c0917bfde97 141 uint8_t RadioPowerMode; // Radio Power Mode [0: LDO, 1:DC_DC]
GregCr 0:9c0917bfde97 142 uint8_t PayloadLength; // Demo payload length
GregCr 0:9c0917bfde97 143 uint8_t ModulationType; // Demo modulation type (LORA, GFSK, FLRC)
GregCr 0:9c0917bfde97 144 uint8_t ModulationParam1; // Demo Mod. Param1 (depend on modulation type)
GregCr 0:9c0917bfde97 145 uint8_t ModulationParam2; // Demo Mod. Param2 (depend on modulation type)
GregCr 0:9c0917bfde97 146 uint8_t ModulationParam3; // Demo Mod. Param3 (depend on modulation type)
GregCr 0:9c0917bfde97 147 uint8_t PacketParam1; // Demo Pack. Param1 (depend on packet type)
GregCr 0:9c0917bfde97 148 uint8_t PacketParam2; // Demo Pack. Param2 (depend on packet type)
GregCr 0:9c0917bfde97 149 uint8_t PacketParam3; // Demo Pack. Param3 (depend on packet type)
GregCr 0:9c0917bfde97 150 uint8_t PacketParam4; // Demo Pack. Param4 (depend on packet type)
GregCr 0:9c0917bfde97 151 uint8_t PacketParam5; // Demo Pack. Param5 (depend on packet type)
GregCr 0:9c0917bfde97 152 uint8_t PacketParam6; // Demo Pack. Param6 (depend on packet type)
GregCr 0:9c0917bfde97 153 uint8_t PacketParam7; // Demo Pack. Param7 (depend on packet type)
GregCr 0:9c0917bfde97 154 uint32_t MaxNumPacket; // Demo Max Num Packet for PingPong and PER
GregCr 0:9c0917bfde97 155 uint16_t InterPacketDelay; // Demo Inter-Packet Delay for PingPong and PER
GregCr 0:9c0917bfde97 156 uint32_t CntPacketTx; // Tx packet transmitted
GregCr 0:9c0917bfde97 157 uint32_t CntPacketRxOK; // Rx packet received OK
GregCr 0:9c0917bfde97 158 uint32_t CntPacketRxOKSlave; // Rx packet received OK (slave side)
GregCr 0:9c0917bfde97 159 uint32_t CntPacketRxKO; // Rx packet received KO
GregCr 0:9c0917bfde97 160 uint32_t CntPacketRxKOSlave; // Rx packet received KO (slave side)
GregCr 0:9c0917bfde97 161 uint16_t RxTimeOutCount; // Rx packet received KO (by timeout)
GregCr 0:9c0917bfde97 162 double RngDistance; // Distance measured by ranging demo
GregCr 0:9c0917bfde97 163 double RngRawDistance; // Uncorrected measured distance [m]
GregCr 0:9c0917bfde97 164 uint32_t RngAddress; // Ranging Address
GregCr 0:9c0917bfde97 165 uint16_t RngFullScale; // Full range of measuring distance (Ranging)
GregCr 0:9c0917bfde97 166 uint8_t RngRequestCount; // Ranging Request Count
GregCr 0:9c0917bfde97 167 uint8_t RngUnit; // Ranging distance unit [m]/[mi]
GregCr 0:9c0917bfde97 168 uint8_t RngStatus; // Status of ranging distance
GregCr 0:9c0917bfde97 169 double RngFei; // Ranging Frequency Error Indicator
GregCr 0:9c0917bfde97 170 uint8_t RngAntenna; // Ranging antenna selection
GregCr 0:9c0917bfde97 171 double RngFeiFactor; // Ranging frequency correction factor
GregCr 0:9c0917bfde97 172 uint16_t RngReqDelay; // Time between ranging request
GregCr 0:9c0917bfde97 173 uint16_t RngCalib; // Ranging Calibration
GregCr 0:9c0917bfde97 174 uint8_t RngZscoreMax; // Max Zscore for ranging value ( ! *10 ! )
GregCr 0:9c0917bfde97 175 int8_t RssiValue; // Demo Rssi Value
GregCr 0:9c0917bfde97 176 int8_t SnrValue; // Demo Snr Value (only for LORA mod. type)
GregCr 0:9c0917bfde97 177 }DemoSettings_t;
GregCr 0:9c0917bfde97 178
GregCr 0:9c0917bfde97 179 /*!
GregCr 0:9c0917bfde97 180 * \brief Define freq offset for config central freq in "Radio Config Freq" menu
GregCr 0:9c0917bfde97 181 */
GregCr 0:9c0917bfde97 182 enum FreqBase
GregCr 0:9c0917bfde97 183 {
GregCr 0:9c0917bfde97 184 FB1 = 1, // 1 Hz
GregCr 0:9c0917bfde97 185 FB10 = 10, // 10 Hz
GregCr 0:9c0917bfde97 186 FB100 = 100, // 100 Hz
GregCr 0:9c0917bfde97 187 FB1K = 1000, // 1 kHz
GregCr 0:9c0917bfde97 188 FB10K = 10000, // 10 kHz
GregCr 0:9c0917bfde97 189 FB100K = 100000, // 100 kHz
GregCr 0:9c0917bfde97 190 FB1M = 1000000, // 1 MHz
GregCr 0:9c0917bfde97 191 FB10M = 10000000 // 10 MHz
GregCr 0:9c0917bfde97 192 };
GregCr 0:9c0917bfde97 193
GregCr 0:9c0917bfde97 194
GregCr 0:9c0917bfde97 195 /*!
GregCr 0:9c0917bfde97 196 * \brief Init RAM copy of Eeprom structure and init radio with it.
GregCr 0:9c0917bfde97 197 */
GregCr 0:9c0917bfde97 198 void InitDemoApplication( void );
GregCr 0:9c0917bfde97 199
GregCr 0:9c0917bfde97 200 /*!
GregCr 0:9c0917bfde97 201 * \brief Init vars of demo and fix APP_IDLE state to demo state machine.
GregCr 0:9c0917bfde97 202 */
GregCr 0:9c0917bfde97 203 void StopDemoApplication( void );
GregCr 0:9c0917bfde97 204
GregCr 0:9c0917bfde97 205 /*!
GregCr 0:9c0917bfde97 206 * \brief Run Demo in sleep mode.
GregCr 0:9c0917bfde97 207 *
GregCr 0:9c0917bfde97 208 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 209 */
GregCr 0:9c0917bfde97 210 uint8_t RunDemoSleepMode( void );
GregCr 0:9c0917bfde97 211
GregCr 0:9c0917bfde97 212 /*!
GregCr 0:9c0917bfde97 213 * \brief Run Demo in standby RC mode.
GregCr 0:9c0917bfde97 214 *
GregCr 0:9c0917bfde97 215 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 216 */
GregCr 0:9c0917bfde97 217 uint8_t RunDemoStandbyRcMode( void );
GregCr 0:9c0917bfde97 218
GregCr 0:9c0917bfde97 219 /*!
GregCr 0:9c0917bfde97 220 * \brief Run Demo in standby XOSC mode.
GregCr 0:9c0917bfde97 221 *
GregCr 0:9c0917bfde97 222 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 223 */
GregCr 0:9c0917bfde97 224 uint8_t RunDemoStandbyXoscMode( void );
GregCr 0:9c0917bfde97 225
GregCr 0:9c0917bfde97 226 /*!
GregCr 0:9c0917bfde97 227 * \brief Run Demo Tx in continuous mode without modulation.
GregCr 0:9c0917bfde97 228 *
GregCr 0:9c0917bfde97 229 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 230 */
GregCr 0:9c0917bfde97 231 uint8_t RunDemoTxCw( void );
GregCr 0:9c0917bfde97 232
GregCr 0:9c0917bfde97 233 /*!
GregCr 0:9c0917bfde97 234 * \brief Run Demo Tx in continuous modulation.
GregCr 0:9c0917bfde97 235 *
GregCr 0:9c0917bfde97 236 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 237 */
GregCr 0:9c0917bfde97 238 uint8_t RunDemoTxContinuousModulation( void );
GregCr 0:9c0917bfde97 239
GregCr 0:9c0917bfde97 240 /*!
GregCr 0:9c0917bfde97 241 * \brief Run demo PingPong.
GregCr 0:9c0917bfde97 242 *
GregCr 0:9c0917bfde97 243 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 244 */
GregCr 0:9c0917bfde97 245 uint8_t RunDemoApplicationPingPong( void );
GregCr 0:9c0917bfde97 246
GregCr 0:9c0917bfde97 247 /*!
GregCr 0:9c0917bfde97 248 * \brief Compute payload of Rx frame and update current counts and indicators.
GregCr 0:9c0917bfde97 249 *
GregCr 0:9c0917bfde97 250 * \param [in] buffer buffer with frame to compute
GregCr 0:9c0917bfde97 251 * \param [in] buffersize size of frame data in the buffer
GregCr 0:9c0917bfde97 252 */
GregCr 0:9c0917bfde97 253 void ComputePingPongPayload( uint8_t *buffer, uint8_t bufferSize );
GregCr 0:9c0917bfde97 254
GregCr 0:9c0917bfde97 255 /*!
GregCr 0:9c0917bfde97 256 * \brief Run demo PER.
GregCr 0:9c0917bfde97 257 *
GregCr 0:9c0917bfde97 258 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 259 */
GregCr 0:9c0917bfde97 260 uint8_t RunDemoApplicationPer( void );
GregCr 0:9c0917bfde97 261
GregCr 0:9c0917bfde97 262 /*!
GregCr 0:9c0917bfde97 263 * \brief Compute payload of Rx frame and update current counts and indicators.
GregCr 0:9c0917bfde97 264 *
GregCr 0:9c0917bfde97 265 * \param [in] buffer buffer with frame to compute
GregCr 0:9c0917bfde97 266 * \param [in] buffersize size of frame data in the buffer
GregCr 0:9c0917bfde97 267 */
GregCr 0:9c0917bfde97 268 void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize );
GregCr 0:9c0917bfde97 269
GregCr 0:9c0917bfde97 270 /*!
GregCr 0:9c0917bfde97 271 * \brief Run ranging demo.
GregCr 0:9c0917bfde97 272 *
GregCr 0:9c0917bfde97 273 * \retval demoStatusUpdate page refresh status ( >0 : refresh)
GregCr 0:9c0917bfde97 274 */
GregCr 0:9c0917bfde97 275 uint8_t RunDemoApplicationRanging( void );
GregCr 0:9c0917bfde97 276
GregCr 0:9c0917bfde97 277 #endif // DEMO_APPLICATION_H