Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 8:cdb739697925, committed 2021-02-15
- Comitter:
- wavespectrum
- Date:
- Mon Feb 15 21:03:43 2021 +0000
- Parent:
- 7:274ca9fe1080
- Commit message:
- prep
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CwTransmitter/CwTransmitter.cpp Mon Feb 15 21:03:43 2021 +0000
@@ -0,0 +1,305 @@
+#include "mbed.h"
+#include "radio.h"
+#include "sx126x-hal.h"
+#include "Eeprom.h"
+#include "CwTransmitter.h"
+
+/*!
+ * \brief Defines the local payload buffer size
+ */
+#define BUFFER_SIZE 255
+
+/*!
+ * \brief Defines the size of the token defining message type in the payload
+ * cf. above.
+ */
+#define PER_SIZE 3
+
+/*!
+ * \brief Define time used in PingPong demo to synch with cycle
+ * RX_TIMEOUT_MARGIN is the free time between each cycle (time reserve)
+ */
+#define RX_TIMEOUT_MARGIN 150 // ms
+#define RX_TX_TRANSITION_WAIT 5 // ms
+
+
+/*!
+ * \brief Define the possible message type for the Ping-Pong and PER apps
+ */
+
+/*!
+ * \brief Buffer and its size
+ */
+uint8_t BufferSize = BUFFER_SIZE;
+uint8_t Buffer[BUFFER_SIZE];
+
+/*!
+ * \brief Function to be executed on Radio Tx Done event
+ */
+
+
+
+/*!
+ * \brief Function executed on Radio Rx Error event
+ */
+void OnRxError( IrqErrorCode_t );
+
+/*!
+ * \brief Function executed on Radio CAD Done event
+ */
+void OnCadDone( bool channelActivityDetected );
+
+/*!
+ * \brief All the callbacks are stored in a structure
+ */
+RadioCallbacks_t RadioEvents =
+{
+};
+
+// SPI
+// mosi, miso, sclk, nss, dio0, dio1, dio2, dio3, rst, freqSel, deviceSel, antSwPower, callbacks...
+SX126xHal Radio( D11, D12, D13, D7, D3, D5, NC, NC, A0, A1, A2, D8, &RadioEvents );
+
+/*!
+ * \brief Tx LED toggling on transmition success
+ */
+DigitalOut TX_LED( A4 );
+
+/*!
+ * \brief Rx LED toggling on reception success
+ */
+DigitalOut RX_LED( A5 );
+
+/*!
+ * \brief Mask of IRQs
+ */
+uint16_t IrqMask = 0x0000;
+
+/*!
+ * \brief Locals parameters and status for radio API
+ * NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
+ */
+PacketParams_t PacketParams;
+PacketStatus_t PacketStatus;
+ModulationParams_t ModulationParams;
+
+/*!
+ * \brief Ticker for master to synch Tx frames. Flags for PER and PingPong demo
+ * for Synch TX in cycle.
+ */
+Ticker SendNextPacket;
+static bool SendNext = false;
+
+/*!
+ * \brief Hold last Rx packet number to compute PER in PER and PingPong demo
+ */
+static uint32_t PacketRxSequence = 0;
+static uint32_t PacketRxSequencePrev = 0;
+
+void LedBlink( void );
+void InitializeDemoParameters( uint8_t modulation );
+uint16_t GetTimeOnAir( uint8_t modulation );
+void SendNextPacketEvent( void );
+
+// ************************** RF Test Demo ******************************
+// * *
+// * *
+// * *
+// *****************************************************************************
+
+uint8_t DemoStandby( void )
+{
+ Radio.SetStandby( STDBY_XOSC );
+ return 0;
+}
+
+uint8_t PrepDemoTxCw( uint32_t rf_frequency,int8_t power, RadioRampTimes_t rampTime )
+{
+
+ RX_LED = 1;
+ TX_LED = 1;
+
+ Radio.Init( );
+
+ // Can also be set in LDO mode but consume more power
+ Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
+
+ memset( &Buffer, 0x00, BufferSize );
+
+ RX_LED = 0;
+ TX_LED = 0;
+
+ PacketRxSequence = 0;
+ PacketRxSequencePrev = 0;
+ Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
+ Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
+ Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
+ Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
+
+
+ if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
+ {
+ return 0;
+ }
+ InitializeDemoParameters( PACKET_TYPE_LORA );
+ TX_LED = 0;
+ RX_LED = 0;
+ uint8_t value = Radio.ReadReg( 0x08d8 );
+ Radio.WriteReg( 0x08d8, value | 0x1E );
+ Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
+ Radio.SetRfFrequency( rf_frequency );
+ Radio.SetTxParams( power, rampTime );
+ Radio.SetStandby( STDBY_XOSC );
+ return 0;
+}
+
+uint8_t RunDemoTxCw( void )
+{
+ Radio.SetTxContinuousWave( );
+ return 0;
+}
+
+
+void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize )
+{
+ uint32_t i = 0;
+
+ Eeprom.EepromData.DemoSettings.CntPacketRxOK++;
+ PacketRxSequence = ( ( uint32_t )buffer[1] << 24 ) | \
+ ( ( uint32_t )buffer[2] << 16 ) | \
+ ( ( uint32_t )buffer[3] << 8 ) | \
+ buffer[4];
+
+ if( ( PacketRxSequence <= PacketRxSequencePrev ) || \
+ ( PacketRxSequencePrev == 0xFFFFFFFF ) )
+ {
+ // Sequence went back => resynchronization
+ // Don't count missed packets this time
+ i = 0;
+ }
+ else
+ {
+ // Determine number of missed packets
+ i = PacketRxSequence - PacketRxSequencePrev - 1;
+ }
+ // Be ready for the next
+ PacketRxSequencePrev = PacketRxSequence;
+ // increment 'missed' counter for the RX session
+ Eeprom.EepromData.DemoSettings.CntPacketRxKO += i;
+ Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
+}
+
+
+uint8_t GetConnectedDevice( void )
+{
+ return( Radio.GetDeviceType( ) );
+}
+
+uint8_t GetMatchingFrequency( void )
+{
+ return( Radio.GetFreqSelect( ) );
+}
+
+
+void InitializeDemoParameters( uint8_t modulation )
+{
+ Radio.SetStandby( STDBY_RC );
+
+ Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
+
+ printf("> InitializeDemoParameters\n\r");
+ if( modulation == PACKET_TYPE_LORA )
+ {
+ printf("set param LORA for demo\n\r");
+ ModulationParams.PacketType = PACKET_TYPE_LORA;
+ PacketParams.PacketType = PACKET_TYPE_LORA;
+
+ ModulationParams.Params.LoRa.SpreadingFactor = ( RadioLoRaSpreadingFactors_t ) Eeprom.EepromData.DemoSettings.ModulationParam1;
+ ModulationParams.Params.LoRa.Bandwidth = ( RadioLoRaBandwidths_t ) Eeprom.EepromData.DemoSettings.ModulationParam2;
+ ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
+
+ PacketParams.Params.LoRa.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
+ PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2;
+ PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3;
+ PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
+ PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5;
+
+ Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength;
+
+ if( ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF6 ) || ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF5 ) )
+ {
+ if( PacketParams.Params.LoRa.PreambleLength < 12 )
+ {
+ PacketParams.Params.LoRa.PreambleLength = 12;
+ }
+ }
+ }
+ else// if( modulation == PACKET_TYPE_GFSK )
+ {
+ printf("set param GFSK for demo\n\r");
+ ModulationParams.PacketType = PACKET_TYPE_GFSK;
+ PacketParams.PacketType = PACKET_TYPE_GFSK;
+
+ ModulationParams.Params.Gfsk.BitRate = Eeprom.EepromData.DemoSettings.ModulationParam1;
+ ModulationParams.Params.Gfsk.Fdev = Eeprom.EepromData.DemoSettings.ModulationParam2;
+ ModulationParams.Params.Gfsk.ModulationShaping = ( RadioModShapings_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
+ ModulationParams.Params.Gfsk.Bandwidth = ( RadioRxBandwidth_t ) Eeprom.EepromData.DemoSettings.ModulationParam4;
+ PacketParams.Params.Gfsk.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
+ PacketParams.Params.Gfsk.PreambleMinDetect = ( RadioPreambleDetection_t )Eeprom.EepromData.DemoSettings.PacketParam2;
+ PacketParams.Params.Gfsk.SyncWordLength = Eeprom.EepromData.DemoSettings.PacketParam3;
+ PacketParams.Params.Gfsk.AddrComp = ( RadioAddressComp_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
+ PacketParams.Params.Gfsk.HeaderType = ( RadioPacketLengthModes_t )Eeprom.EepromData.DemoSettings.PacketParam5;
+ PacketParams.Params.Gfsk.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam6;
+
+ PacketParams.Params.Gfsk.CrcLength = ( RadioCrcTypes_t ) Eeprom.EepromData.DemoSettings.PacketParam7;
+ PacketParams.Params.Gfsk.DcFree = ( RadioDcFree_t ) Eeprom.EepromData.DemoSettings.PacketParam8;
+
+ Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.Gfsk.PayloadLength;
+ }
+
+ Radio.SetStandby( STDBY_RC );
+ Radio.ClearIrqStatus( IRQ_RADIO_ALL );
+ Radio.SetPacketType( ModulationParams.PacketType );
+ Radio.SetModulationParams( &ModulationParams );
+ Radio.SetPacketParams( &PacketParams );
+ Radio.SetBufferBaseAddresses( 0x00, 0x00 );
+
+
+
+ // only used in GFSK
+ Radio.SetSyncWord( ( uint8_t[] ){ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } );
+ Radio.SetWhiteningSeed( 0x01FF );
+
+ RX_LED = 0;
+ TX_LED = 0;
+}
+
+/*!
+ * \brief Callback of ticker PerSendNextPacket
+ */
+void SendNextPacketEvent( void )
+{
+ SendNext = true;
+}
+
+void LedBlink( void )
+{
+ if( ( TX_LED == 0 ) && ( RX_LED == 0 ) )
+ {
+ TX_LED = 1;
+ }
+ else if( ( TX_LED == 1 ) && ( RX_LED == 0 ) )
+ {
+ RX_LED = 1;
+ }
+ else if( ( TX_LED == 1 ) && ( RX_LED == 1 ) )
+ {
+ TX_LED = 0;
+ }
+ else
+ {
+ RX_LED = 0;
+ }
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CwTransmitter/CwTransmitter.h Mon Feb 15 21:03:43 2021 +0000
@@ -0,0 +1,239 @@
+#ifndef DEMO_APPLICATION_H
+#define DEMO_APPLICATION_H
+#include "sx126x.h"
+
+/*!
+ * \brief Used to display firmware version on TFT (Utilities menu)
+ */
+#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 180706" )
+
+/*!
+ * \brief Define range of central frequency [Hz]
+ */
+#define DEMO_CENTRAL_FREQ_MIN 150000000UL
+#define DEMO_CENTRAL_FREQ_MAX 950000000UL
+
+/*!
+ * \brief Define 3 preset central frequencies [Hz]
+ */
+#define DEMO_CENTRAL_FREQ_PRESET1 169000000UL
+#define DEMO_CENTRAL_FREQ_PRESET2 280000000UL
+#define DEMO_CENTRAL_FREQ_PRESET3 434000000UL
+#define DEMO_CENTRAL_FREQ_PRESET4 490000000UL
+#define DEMO_CENTRAL_FREQ_PRESET5 783000000UL
+#define DEMO_CENTRAL_FREQ_PRESET6 868000000UL
+#define DEMO_CENTRAL_FREQ_PRESET7 915000000UL
+#define DEMO_CENTRAL_FREQ_PRESET8 930000000UL
+#define DEMO_CENTRAL_FREQ_PRESET9 510000000UL
+
+/*!
+ * \brief Define min and max Tx power [dBm]
+ */
+#define SX1261_POWER_TX_MIN -17
+#define SX1261_POWER_TX_MAX 15
+
+#define SX1262_POWER_TX_MIN -10
+#define SX1262_POWER_TX_MAX 22
+
+/*!
+ * \brief Define current demo mode
+ */
+enum DemoMode
+{
+ MASTER = 0,
+ SLAVE
+};
+
+/*!
+ * \brief Define GFSK bitrate
+ */
+typedef enum
+{
+ DEMO_BR_100 = 100,
+ DEMO_BR_600 = 600,
+ DEMO_BR_4800 = 4800,
+ DEMO_BR_9600 = 9600,
+ DEMO_BR_19200 = 19200,
+ DEMO_BR_57600 = 57600,
+ DEMO_BR_100000 = 100000,
+ DEMO_BR_250000 = 250000,
+}DemoBitrate_t;
+
+/*!
+ * \brief Define GFSK frequency deviation
+ */
+typedef enum
+{
+ DEMO_FDEV_5000 = 5000,
+ DEMO_FDEV_10000 = 10000,
+ DEMO_FDEV_25000 = 25000,
+ DEMO_FDEV_50000 = 50000,
+ DEMO_FDEV_75000 = 75000,
+ DEMO_FDEV_100000 = 100000,
+ DEMO_FDEV_150000 = 150000,
+}DemoFrequencyDev_t;
+
+/*!
+ * \brief List of states for demo state machine
+ */
+enum DemoInternalStates
+{
+ APP_IDLE = 0, // nothing to do (or wait a radio interrupt)
+ SEND_PING_MSG,
+ SEND_PONG_MSG,
+ APP_RX, // Rx done
+ APP_RX_TIMEOUT, // Rx timeout
+ APP_RX_ERROR, // Rx error
+ APP_TX, // Tx done
+ APP_TX_TIMEOUT, // Tx error
+ PER_TX_START, // PER master
+ PER_RX_START, // PER slave
+ CAD_DONE, // CAD Done
+ CAD_DONE_CHANNEL_DETECTED // Channel Detected following a CAD
+};
+
+/*!
+ * \brief Demo Settings structure of Eeprom structure
+ */
+typedef struct
+{
+ uint8_t Entity; // Master or Slave
+ uint8_t HoldDemo; // Put demo in hold status
+ uint8_t BoostedRx; // Use Boosted Rx if true
+ uint32_t Frequency; // Demo frequency
+ uint8_t LastDeviceConnected;// Last Device Connected
+ int8_t TxPower; // Demo Tx power
+ uint8_t RadioPowerMode; // Radio Power Mode [0: LDO, 1:DC_DC]
+ uint8_t PayloadLength; // Demo payload length
+ uint8_t ModulationType; // Demo modulation type (LORA, GFSK)
+ uint32_t ModulationParam1; // Demo Mod. Param1 (depend on modulation type)
+ uint32_t ModulationParam2; // Demo Mod. Param2 (depend on modulation type)
+ uint8_t ModulationParam3; // Demo Mod. Param3 (depend on modulation type)
+ uint8_t ModulationParam4; // Demo Mod. Param4 (depend on modulation type)
+ uint16_t PacketParam1; // Demo Pack. Param1 (depend on packet type)
+ uint8_t PacketParam2; // Demo Pack. Param2 (depend on packet type)
+ uint8_t PacketParam3; // Demo Pack. Param3 (depend on packet type)
+ uint8_t PacketParam4; // Demo Pack. Param4 (depend on packet type)
+ uint8_t PacketParam5; // Demo Pack. Param5 (depend on packet type)
+ uint8_t PacketParam6; // Demo Pack. Param6 (depend on packet type)
+ uint8_t PacketParam7; // Demo Pack. Param7 (depend on packet type)
+ uint8_t PacketParam8; // Demo Pack. Param8 (depend on packet type)
+ uint32_t MaxNumPacket; // Demo Max Num Packet for PingPong and PER
+ uint16_t InterPacketDelay; // Demo Inter-Packet Delay for PingPong and PER
+ uint32_t CntPacketTx; // Tx packet transmitted
+ uint32_t CntPacketRxOK; // Rx packet received OK
+ uint32_t CntPacketRxOKSlave;// Rx packet received OK (slave side)
+ uint32_t CntPacketRxKO; // Rx packet received KO
+ uint32_t CntPacketRxKOSlave;// Rx packet received KO (slave side)
+ uint16_t RxTimeOutCount; // Rx packet received KO (by timeout)
+ int8_t RssiValue; // Demo Rssi Value
+ int8_t SnrValue; // Demo Snr Value (only for LR24 mod. type)
+ uint32_t FreqErrorEst; // Estimation of the frequency error on the Rx side
+}DemoSettings_t;
+
+/*!
+ * \brief Define freq offset for config central freq in "Radio Config Freq" menu
+ */
+enum FreqBase
+{
+ FB1 = 1, // 1 Hz
+ FB10 = 10, // 10 Hz
+ FB100 = 100, // 100 Hz
+ FB1K = 1000, // 1 kHz
+ FB10K = 10000, // 10 kHz
+ FB100K = 100000, // 100 kHz
+ FB1M = 1000000, // 1 MHz
+ FB10M = 10000000 // 10 MHz
+};
+
+
+/*!
+ * \brief Simple Function which return the device connected.
+ *
+ * \retval deviceConnected device type connected
+ */
+uint8_t GetConnectedDevice( void );
+
+/*!
+ * \brief Simple Function which return the board matching frequency
+ *
+ * \retval freq 1: 868 MHz 0: 915 MHz
+ */
+uint8_t GetMatchingFrequency( void );
+
+
+
+/*!
+ * \brief Run Demo in sleep mode.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoSleepMode( void );
+
+/*!
+ * \brief Run Demo in standby RC mode.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoStandbyRcMode( void );
+
+/*!
+ * \brief Run Demo in standby XOSC mode.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoStandbyXoscMode( void );
+
+/*!
+ * \brief Run Demo Tx in continuous mode without modulation.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t PrepDemoTxCw( uint32_t rf_frequency,int8_t power, RadioRampTimes_t rampTime );
+uint8_t RunDemoTxCw( void );
+uint8_t DemoStandby( void );
+/*!
+ * \brief Run Demo Tx in continuous modulation.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoTxContinuousModulation( void );
+
+/*!
+ * \brief Run Demo Rx in continuous mode.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoRxContinuous( void );
+
+/*!
+ * \brief Run demo PingPong.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoApplicationPingPong( void );
+
+/*!
+ * \brief Compute payload of Rx frame and update current counts and indicators.
+ *
+ * \param [in] buffer buffer with frame to compute
+ * \param [in] buffersize size of frame data in the buffer
+ */
+void ComputePingPongPayload( uint8_t *buffer, uint8_t bufferSize );
+
+/*!
+ * \brief Run demo PER.
+ *
+ * \retval demoStatusUpdate page refresh status ( >0 : refresh)
+ */
+uint8_t RunDemoApplicationPer( void );
+
+/*!
+ * \brief Compute payload of Rx frame and update current counts and indicators.
+ *
+ * \param [in] buffer buffer with frame to compute
+ * \param [in] buffersize size of frame data in the buffer
+ */
+void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize );
+
+#endif // DEMO_APPLICATION_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CwTransmitter/SX126xLib.lib Mon Feb 15 21:03:43 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Semtech/code/SX126xLib/#1e2345700991
--- a/Demo/DemoApplication.cpp Mon Feb 15 19:20:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,621 +0,0 @@
-/*
- ______ _
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2016 Semtech
-
-Description: PingPong, PER demo implementation.
-
-Maintainer: Gregory Cristian & Gilbert Menth
-*/
-
-#include "mbed.h"
-#include "radio.h"
-#include "sx126x-hal.h"
-#include "Eeprom.h"
-#include "DemoApplication.h"
-
-/*!
- * \brief Defines the local payload buffer size
- */
-#define BUFFER_SIZE 255
-
-/*!
- * \brief Defines the size of the token defining message type in the payload
- * cf. above.
- */
-#define PINGPONG_SIZE 4
-#define PER_SIZE 3
-
-/*!
- * \brief Define time used in PingPong demo to synch with cycle
- * RX_TIMEOUT_MARGIN is the free time between each cycle (time reserve)
- */
-#define RX_TIMEOUT_MARGIN 150 // ms
-#define RX_TX_TRANSITION_WAIT 5 // ms
-
-
-/*!
- * \brief Define the possible message type for the Ping-Pong and PER apps
- */
-
-/*!
- * \brief Buffer and its size
- */
-uint8_t BufferSize = BUFFER_SIZE;
-uint8_t Buffer[BUFFER_SIZE];
-
-/*!
- * \brief Function to be executed on Radio Tx Done event
- */
-void OnTxDone( void );
-
-/*!
- * \brief Function to be executed on Radio Rx Done event
- */
-void OnRxDone( void );
-
-/*!
- * \brief Function executed on Radio Tx Timeout event
- */
-void OnTxTimeout( void );
-
-/*!
- * \brief Function executed on Radio Rx Timeout event
- */
-void OnRxTimeout( void );
-
-/*!
- * \brief Function executed on Radio Rx Error event
- */
-void OnRxError( IrqErrorCode_t );
-
-/*!
- * \brief Function executed on Radio CAD Done event
- */
-void OnCadDone( bool channelActivityDetected );
-
-/*!
- * \brief All the callbacks are stored in a structure
- */
-RadioCallbacks_t RadioEvents =
-{
- &OnTxDone, // txDone
- &OnRxDone, // rxDone
- NULL, // rxPreambleDetect
- NULL, // rxSyncWordDone
- NULL, // rxHeaderDone
- &OnTxTimeout, // txTimeout
- &OnRxTimeout, // rxTimeout
- &OnRxError, // rxError
- &OnCadDone, // cadDone
-};
-
-// SPI
-// mosi, miso, sclk, nss, dio0, dio1, dio2, dio3, rst, freqSel, deviceSel, antSwPower, callbacks...
-SX126xHal Radio( D11, D12, D13, D7, D3, D5, NC, NC, A0, A1, A2, D8, &RadioEvents );
-
-/*!
- * \brief Tx LED toggling on transmition success
- */
-DigitalOut TX_LED( A4 );
-
-/*!
- * \brief Rx LED toggling on reception success
- */
-DigitalOut RX_LED( A5 );
-
-/*!
- * \brief Mask of IRQs
- */
-uint16_t IrqMask = 0x0000;
-
-/*!
- * \brief Locals parameters and status for radio API
- * NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
- */
-PacketParams_t PacketParams;
-PacketStatus_t PacketStatus;
-ModulationParams_t ModulationParams;
-
-/*!
- * \brief Flag to indicate if the demo is already running
- */
-static bool DemoRunning = false;
-
-/*!
- * \brief Frequency Error (only LSB)
- */
-static double FreErrorLsb = 0.0;
-
-/*!
- * \brief Flag holding the current internal state of the demo application
- */
-static uint8_t DemoInternalState = APP_IDLE;
-
-/*!
- * \brief Ticker for master to synch Tx frames. Flags for PER and PingPong demo
- * for Synch TX in cycle.
- */
-Ticker SendNextPacket;
-static bool SendNext = false;
-
-/*!
- * \brief Hold last Rx packet number to compute PER in PER and PingPong demo
- */
-static uint32_t PacketRxSequence = 0;
-static uint32_t PacketRxSequencePrev = 0;
-
-void LedBlink( void );
-void InitializeDemoParameters( uint8_t modulation );
-uint16_t GetTimeOnAir( uint8_t modulation );
-void SendNextPacketEvent( void );
-
-// ************************** RF Test Demo ******************************
-// * *
-// * *
-// * *
-// *****************************************************************************
-
-uint8_t DemoStandby( void )
-{
- //Radio.SetRx(1);
- Radio.SetStandby( STDBY_XOSC );
- return 0;
-}
-
-uint8_t PrepDemoTxCw( void )
-{
- if( Eeprom.EepromData.DemoSettings.HoldDemo == true )
- {
- return 0;
- }
-
-
- InitializeDemoParameters( PACKET_TYPE_LORA );
- TX_LED = 0;
- RX_LED = 0;
- Radio.SetStandby( STDBY_RC );
- Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
- Radio.SetRfFrequency( Eeprom.EepromData.DemoSettings.Frequency );
- Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_200_US );
-
- return 0;
-}
-
-uint8_t RunDemoTxCw( void )
-{
- Radio.SetTxContinuousWave( );
- DemoRunning = true;
- return 0;
-}
-
-
-void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize )
-{
- uint32_t i = 0;
-
- Eeprom.EepromData.DemoSettings.CntPacketRxOK++;
- PacketRxSequence = ( ( uint32_t )buffer[1] << 24 ) | \
- ( ( uint32_t )buffer[2] << 16 ) | \
- ( ( uint32_t )buffer[3] << 8 ) | \
- buffer[4];
-
- if( ( PacketRxSequence <= PacketRxSequencePrev ) || \
- ( PacketRxSequencePrev == 0xFFFFFFFF ) )
- {
- // Sequence went back => resynchronization
- // Don't count missed packets this time
- i = 0;
- }
- else
- {
- // Determine number of missed packets
- i = PacketRxSequence - PacketRxSequencePrev - 1;
- }
- // Be ready for the next
- PacketRxSequencePrev = PacketRxSequence;
- // increment 'missed' counter for the RX session
- Eeprom.EepromData.DemoSettings.CntPacketRxKO += i;
- Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
-}
-
-// ************************ Ping Pong Demo *****************************
-// * *
-// * *
-// * *
-// *****************************************************************************
-
-
-// ************************ Utils ****************************
-// * *
-// * *
-// * *
-// *****************************************************************************
-
-uint8_t GetConnectedDevice( void )
-{
- return( Radio.GetDeviceType( ) );
-}
-
-uint8_t GetMatchingFrequency( void )
-{
- return( Radio.GetFreqSelect( ) );
-}
-
-void InitDemoApplication( void )
-{
- RX_LED = 1;
- TX_LED = 1;
-
- Radio.Init( );
-
- // Can also be set in LDO mode but consume more power
- Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
- Radio.SetStandby( STDBY_RC );
-
- memset( &Buffer, 0x00, BufferSize );
-
- RX_LED = 0;
- TX_LED = 0;
-
- PacketRxSequence = 0;
- PacketRxSequencePrev = 0;
- Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
- Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
- Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
- Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
-}
-
-void StopDemoApplication( void )
-{
- if( DemoRunning == true )
- {
- Radio.CheckDeviceReady( );
-
- RX_LED = 0;
- TX_LED = 0;
- DemoRunning = false;
- SendNext = false;
- PacketRxSequence = 0;
- PacketRxSequencePrev = 0;
- Eeprom.EepromData.DemoSettings.CntPacketTx = 0;
- Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0;
- Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0;
- Eeprom.EepromData.DemoSettings.RxTimeOutCount = 0;
-
- DemoInternalState = APP_IDLE;
- Radio.SetStandby( STDBY_RC );
- Radio.ClearIrqStatus( IRQ_RADIO_ALL );
- SendNextPacket.detach( );
- }
-}
-
-/*
- * Function still being implemented >>> To be completed
- * WARNING: Computation is in float and his really slow
- * LongInterLeaving vs LegacyInterLeaving has no influence on TimeOnAir.
- */
-uint16_t GetTimeOnAir( uint8_t modulation )
-{
- uint16_t result = 2000;
- uint8_t LowDatarateOptimize = 0;
-
- if( modulation == PACKET_TYPE_LORA )
- {
- volatile double loraBw = 0.0;
- volatile double FreqErrorUnits = 0.0;
-
- switch( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth )
- {
- case LORA_BW_500:
- loraBw = 500e3;
- break;
-
- case LORA_BW_250:
- loraBw = 250e3;
- break;
-
- case LORA_BW_125:
- loraBw = 125e3;
- break;
-
- case LORA_BW_062:
- loraBw = 62e3;
- break;
-
- case LORA_BW_041:
- loraBw = 41e3;
- break;
-
- case LORA_BW_031:
- loraBw = 31e3;
- break;
-
- case LORA_BW_020:
- loraBw = 20e3;
- break;
-
- case LORA_BW_015:
- loraBw = 15e3;
- break;
-
- case LORA_BW_010:
- loraBw = 10e3;
- break;
-
- case LORA_BW_007:
- loraBw = 7e3;
- break;
-
- default:
- loraBw = 7e3;
- break;
- }
-
- /* Used to compute the freq Error */
- FreqErrorUnits = FREQ_ERR;
- FreErrorLsb = FreqErrorUnits * ( ( double )loraBw / 1000 ) / 500;
-
- float ts = 1 << Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor; // time for one symbol in ms
- ts = (float)ts / (float)loraBw;
- ts = ts * 1000; // from seconds to miliseconds
-
- float tPreamble = ( Eeprom.EepromData.PacketParams.Params.LoRa.PreambleLength + 4.25 + ( ( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor > 6 ) ? 2 : 0 )) * ts; // time of preamble
-
- switch( Eeprom.EepromData.ModulationParams.Params.LoRa.Bandwidth )
- {
- case LORA_BW_500:
- break;
-
- case LORA_BW_250:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF12 )
- {
- LowDatarateOptimize = 1;
- }
- break;
-
- case LORA_BW_125:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF11 )
- {
- LowDatarateOptimize = 1;
- }
- break;
-
- case LORA_BW_062:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF10 )
- {
- LowDatarateOptimize = 1;
- }
- break;
-
- case LORA_BW_041:
- case LORA_BW_031:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF9 )
- {
- LowDatarateOptimize = 1;
- }
- break;
-
- case LORA_BW_020:
- case LORA_BW_015:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF8 )
- {
- LowDatarateOptimize = 1;
- }
- break;
-
- case LORA_BW_010:
- case LORA_BW_007:
- if( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor >= LORA_SF7 )
- {
- LowDatarateOptimize = 1;
- }
- break;
- }
-
- float nData = ceil( ( float )( ( 8 * Eeprom.EepromData.PacketParams.Params.LoRa.PayloadLength + \
- 16 * ( ( Eeprom.EepromData.PacketParams.Params.LoRa.CrcMode == LORA_CRC_OFF ) ? 0 : 1 ) + \
- ( ( Eeprom.EepromData.PacketParams.Params.LoRa.HeaderType == LORA_PACKET_VARIABLE_LENGTH ) ? 20 : 0 ) - \
- ( 4 * Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor ) + 8 - \
- ( 8 *( ( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor > 6 ) ? 1 : 0 ) ) ) / 4 ) );
-
- nData = ceil( ( float )nData / ( ( float )( Eeprom.EepromData.ModulationParams.Params.LoRa.SpreadingFactor - \
- ( LowDatarateOptimize * 2 ) ) ) * ( ( Eeprom.EepromData.ModulationParams.Params.LoRa.CodingRate % 4 ) + 4 ) );
-
- float tPayload = nData * ts;
-
- float tHeader = 8 * ts;
- // Time on air [ms]
- float ToA = ceil( tPreamble + tPayload + tHeader );
-
- result = ( uint16_t )ToA + ( ( uint16_t )ToA >> 1 ); // Set some margin
- }
- else if( modulation == PACKET_TYPE_GFSK )
- {
- uint16_t packetBitCount = Eeprom.EepromData.PacketParams.Params.Gfsk.PreambleLength;
-
- packetBitCount += ( Eeprom.EepromData.PacketParams.Params.Gfsk.SyncWordLength + 1 );
- packetBitCount += Eeprom.EepromData.PacketParams.Params.Gfsk.PayloadLength + 3;
- packetBitCount *= 8;
- // 1500 = 1000 * 1.5 : 1000 for translate s in ms and 1.5 is some margin
- result = ( uint16_t )( ceil( 1500 * ( float )packetBitCount / Eeprom.EepromData.ModulationParams.Params.Gfsk.BitRate ) );
- }
- return result;
-}
-
-void InitializeDemoParameters( uint8_t modulation )
-{
- Radio.SetStandby( STDBY_RC );
-
- Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode );
-
- printf("> InitializeDemoParameters\n\r");
- if( modulation == PACKET_TYPE_LORA )
- {
- printf("set param LORA for demo\n\r");
- ModulationParams.PacketType = PACKET_TYPE_LORA;
- PacketParams.PacketType = PACKET_TYPE_LORA;
-
- ModulationParams.Params.LoRa.SpreadingFactor = ( RadioLoRaSpreadingFactors_t ) Eeprom.EepromData.DemoSettings.ModulationParam1;
- ModulationParams.Params.LoRa.Bandwidth = ( RadioLoRaBandwidths_t ) Eeprom.EepromData.DemoSettings.ModulationParam2;
- ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
-
- PacketParams.Params.LoRa.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
- PacketParams.Params.LoRa.HeaderType = ( RadioLoRaPacketLengthsMode_t )Eeprom.EepromData.DemoSettings.PacketParam2;
- PacketParams.Params.LoRa.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam3;
- PacketParams.Params.LoRa.CrcMode = ( RadioLoRaCrcModes_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
- PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5;
-
- Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength;
-
- if( ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF6 ) || ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF5 ) )
- {
- if( PacketParams.Params.LoRa.PreambleLength < 12 )
- {
- PacketParams.Params.LoRa.PreambleLength = 12;
- }
- }
- }
- else// if( modulation == PACKET_TYPE_GFSK )
- {
- printf("set param GFSK for demo\n\r");
- ModulationParams.PacketType = PACKET_TYPE_GFSK;
- PacketParams.PacketType = PACKET_TYPE_GFSK;
-
- ModulationParams.Params.Gfsk.BitRate = Eeprom.EepromData.DemoSettings.ModulationParam1;
- ModulationParams.Params.Gfsk.Fdev = Eeprom.EepromData.DemoSettings.ModulationParam2;
- ModulationParams.Params.Gfsk.ModulationShaping = ( RadioModShapings_t ) Eeprom.EepromData.DemoSettings.ModulationParam3;
- ModulationParams.Params.Gfsk.Bandwidth = ( RadioRxBandwidth_t ) Eeprom.EepromData.DemoSettings.ModulationParam4;
- PacketParams.Params.Gfsk.PreambleLength = Eeprom.EepromData.DemoSettings.PacketParam1;
- PacketParams.Params.Gfsk.PreambleMinDetect = ( RadioPreambleDetection_t )Eeprom.EepromData.DemoSettings.PacketParam2;
- PacketParams.Params.Gfsk.SyncWordLength = Eeprom.EepromData.DemoSettings.PacketParam3;
- PacketParams.Params.Gfsk.AddrComp = ( RadioAddressComp_t ) Eeprom.EepromData.DemoSettings.PacketParam4;
- PacketParams.Params.Gfsk.HeaderType = ( RadioPacketLengthModes_t )Eeprom.EepromData.DemoSettings.PacketParam5;
- PacketParams.Params.Gfsk.PayloadLength = Eeprom.EepromData.DemoSettings.PacketParam6;
-
- PacketParams.Params.Gfsk.CrcLength = ( RadioCrcTypes_t ) Eeprom.EepromData.DemoSettings.PacketParam7;
- PacketParams.Params.Gfsk.DcFree = ( RadioDcFree_t ) Eeprom.EepromData.DemoSettings.PacketParam8;
-
- Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.Gfsk.PayloadLength;
- }
-
- Radio.SetStandby( STDBY_RC );
- Radio.ClearIrqStatus( IRQ_RADIO_ALL );
- Radio.SetPacketType( ModulationParams.PacketType );
- Radio.SetModulationParams( &ModulationParams );
- Radio.SetPacketParams( &PacketParams );
-
- Radio.SetRfFrequency( Eeprom.EepromData.DemoSettings.Frequency );
- Radio.SetBufferBaseAddresses( 0x00, 0x00 );
-
-
- Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_200_US );
-
- // only used in GFSK
- Radio.SetSyncWord( ( uint8_t[] ){ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } );
- Radio.SetWhiteningSeed( 0x01FF );
-
- RX_LED = 0;
- TX_LED = 0;
-}
-
-/*!
- * \brief Callback of ticker PerSendNextPacket
- */
-void SendNextPacketEvent( void )
-{
- SendNext = true;
-}
-
-void LedBlink( void )
-{
- if( ( TX_LED == 0 ) && ( RX_LED == 0 ) )
- {
- TX_LED = 1;
- }
- else if( ( TX_LED == 1 ) && ( RX_LED == 0 ) )
- {
- RX_LED = 1;
- }
- else if( ( TX_LED == 1 ) && ( RX_LED == 1 ) )
- {
- TX_LED = 0;
- }
- else
- {
- RX_LED = 0;
- }
-}
-
-// ************************ Radio Callbacks ****************************
-// * *
-// * These functions are called through function pointer by the Radio low *
-// * level drivers *
-// * *
-// *****************************************************************************
-void OnTxDone( void )
-{
- DemoInternalState = APP_TX;
-}
-
-void OnRxDone( void )
-{
- DemoInternalState = APP_RX;
-}
-
-void OnTxTimeout( void )
-{
- DemoInternalState = APP_TX_TIMEOUT;
-}
-
-void OnRxTimeout( void )
-{
- DemoInternalState = APP_RX_TIMEOUT;
-}
-
-void OnRxError( IrqErrorCode_t errorCode )
-{
- DemoInternalState = APP_RX_ERROR;
-
- if( errorCode == IRQ_HEADER_ERROR_CODE )
- {
-#ifdef ADV_DEBUG
- printf( ">> IRQ_HEADER_ERROR_CODE\n\r" );
-#endif
- }
- else if( errorCode == IRQ_SYNCWORD_ERROR_CODE )
- {
-#ifdef ADV_DEBUG
- printf( ">> IRQ_SYNCWORD_ERROR_CODE\n\r" );
-#endif
- }
- else if( errorCode == IRQ_CRC_ERROR_CODE )
- {
-#ifdef ADV_DEBUG
- printf( ">> IRQ_CRC_ERROR_CODE\n\r" );
-#endif
- }
- else
- {
-#ifdef ADV_DEBUG
- printf( "unknown error\n\r" );
-#endif
- }
- Radio.GetPacketStatus( &PacketStatus );
-}
-
-void OnCadDone( bool channelActivityDetected )
-{
- if( channelActivityDetected == true )
- {
- DemoInternalState = CAD_DONE_CHANNEL_DETECTED;
- }
- else
- {
- DemoInternalState = CAD_DONE;
- }
-}
--- a/Demo/DemoApplication.h Mon Feb 15 19:20:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,269 +0,0 @@
-/*
- ______ _
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2016 Semtech
-
-Description: Display driver header
-
-Maintainer: Gregory Cristian & Gilbert Menth
-*/
-
-#ifndef DEMO_APPLICATION_H
-#define DEMO_APPLICATION_H
-
-
-/*!
- * \brief Used to display firmware version on TFT (Utilities menu)
- */
-#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 180706" )
-
-/*!
- * \brief Define range of central frequency [Hz]
- */
-#define DEMO_CENTRAL_FREQ_MIN 150000000UL
-#define DEMO_CENTRAL_FREQ_MAX 950000000UL
-
-/*!
- * \brief Define 3 preset central frequencies [Hz]
- */
-#define DEMO_CENTRAL_FREQ_PRESET1 169000000UL
-#define DEMO_CENTRAL_FREQ_PRESET2 280000000UL
-#define DEMO_CENTRAL_FREQ_PRESET3 434000000UL
-#define DEMO_CENTRAL_FREQ_PRESET4 490000000UL
-#define DEMO_CENTRAL_FREQ_PRESET5 783000000UL
-#define DEMO_CENTRAL_FREQ_PRESET6 868000000UL
-#define DEMO_CENTRAL_FREQ_PRESET7 915000000UL
-#define DEMO_CENTRAL_FREQ_PRESET8 930000000UL
-#define DEMO_CENTRAL_FREQ_PRESET9 510000000UL
-
-/*!
- * \brief Define min and max Tx power [dBm]
- */
-#define SX1261_POWER_TX_MIN -17
-#define SX1261_POWER_TX_MAX 15
-
-#define SX1262_POWER_TX_MIN -10
-#define SX1262_POWER_TX_MAX 22
-
-/*!
- * \brief Define current demo mode
- */
-enum DemoMode
-{
- MASTER = 0,
- SLAVE
-};
-
-/*!
- * \brief Define GFSK bitrate
- */
-typedef enum
-{
- DEMO_BR_100 = 100,
- DEMO_BR_600 = 600,
- DEMO_BR_4800 = 4800,
- DEMO_BR_9600 = 9600,
- DEMO_BR_19200 = 19200,
- DEMO_BR_57600 = 57600,
- DEMO_BR_100000 = 100000,
- DEMO_BR_250000 = 250000,
-}DemoBitrate_t;
-
-/*!
- * \brief Define GFSK frequency deviation
- */
-typedef enum
-{
- DEMO_FDEV_5000 = 5000,
- DEMO_FDEV_10000 = 10000,
- DEMO_FDEV_25000 = 25000,
- DEMO_FDEV_50000 = 50000,
- DEMO_FDEV_75000 = 75000,
- DEMO_FDEV_100000 = 100000,
- DEMO_FDEV_150000 = 150000,
-}DemoFrequencyDev_t;
-
-/*!
- * \brief List of states for demo state machine
- */
-enum DemoInternalStates
-{
- APP_IDLE = 0, // nothing to do (or wait a radio interrupt)
- SEND_PING_MSG,
- SEND_PONG_MSG,
- APP_RX, // Rx done
- APP_RX_TIMEOUT, // Rx timeout
- APP_RX_ERROR, // Rx error
- APP_TX, // Tx done
- APP_TX_TIMEOUT, // Tx error
- PER_TX_START, // PER master
- PER_RX_START, // PER slave
- CAD_DONE, // CAD Done
- CAD_DONE_CHANNEL_DETECTED // Channel Detected following a CAD
-};
-
-/*!
- * \brief Demo Settings structure of Eeprom structure
- */
-typedef struct
-{
- uint8_t Entity; // Master or Slave
- uint8_t HoldDemo; // Put demo in hold status
- uint8_t BoostedRx; // Use Boosted Rx if true
- uint32_t Frequency; // Demo frequency
- uint8_t LastDeviceConnected;// Last Device Connected
- int8_t TxPower; // Demo Tx power
- uint8_t RadioPowerMode; // Radio Power Mode [0: LDO, 1:DC_DC]
- uint8_t PayloadLength; // Demo payload length
- uint8_t ModulationType; // Demo modulation type (LORA, GFSK)
- uint32_t ModulationParam1; // Demo Mod. Param1 (depend on modulation type)
- uint32_t ModulationParam2; // Demo Mod. Param2 (depend on modulation type)
- uint8_t ModulationParam3; // Demo Mod. Param3 (depend on modulation type)
- uint8_t ModulationParam4; // Demo Mod. Param4 (depend on modulation type)
- uint16_t PacketParam1; // Demo Pack. Param1 (depend on packet type)
- uint8_t PacketParam2; // Demo Pack. Param2 (depend on packet type)
- uint8_t PacketParam3; // Demo Pack. Param3 (depend on packet type)
- uint8_t PacketParam4; // Demo Pack. Param4 (depend on packet type)
- uint8_t PacketParam5; // Demo Pack. Param5 (depend on packet type)
- uint8_t PacketParam6; // Demo Pack. Param6 (depend on packet type)
- uint8_t PacketParam7; // Demo Pack. Param7 (depend on packet type)
- uint8_t PacketParam8; // Demo Pack. Param8 (depend on packet type)
- uint32_t MaxNumPacket; // Demo Max Num Packet for PingPong and PER
- uint16_t InterPacketDelay; // Demo Inter-Packet Delay for PingPong and PER
- uint32_t CntPacketTx; // Tx packet transmitted
- uint32_t CntPacketRxOK; // Rx packet received OK
- uint32_t CntPacketRxOKSlave;// Rx packet received OK (slave side)
- uint32_t CntPacketRxKO; // Rx packet received KO
- uint32_t CntPacketRxKOSlave;// Rx packet received KO (slave side)
- uint16_t RxTimeOutCount; // Rx packet received KO (by timeout)
- int8_t RssiValue; // Demo Rssi Value
- int8_t SnrValue; // Demo Snr Value (only for LR24 mod. type)
- uint32_t FreqErrorEst; // Estimation of the frequency error on the Rx side
-}DemoSettings_t;
-
-/*!
- * \brief Define freq offset for config central freq in "Radio Config Freq" menu
- */
-enum FreqBase
-{
- FB1 = 1, // 1 Hz
- FB10 = 10, // 10 Hz
- FB100 = 100, // 100 Hz
- FB1K = 1000, // 1 kHz
- FB10K = 10000, // 10 kHz
- FB100K = 100000, // 100 kHz
- FB1M = 1000000, // 1 MHz
- FB10M = 10000000 // 10 MHz
-};
-
-
-/*!
- * \brief Simple Function which return the device connected.
- *
- * \retval deviceConnected device type connected
- */
-uint8_t GetConnectedDevice( void );
-
-/*!
- * \brief Simple Function which return the board matching frequency
- *
- * \retval freq 1: 868 MHz 0: 915 MHz
- */
-uint8_t GetMatchingFrequency( void );
-
-/*!
- * \brief Init RAM copy of Eeprom structure and init radio with it.
- *
- */
-void InitDemoApplication( void );
-
-/*!
- * \brief Init vars of demo and fix APP_IDLE state to demo state machine.
- */
-void StopDemoApplication( void );
-
-/*!
- * \brief Run demo reading constantly the RSSI.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoTestRssi( void );
-
-/*!
- * \brief Run Demo in sleep mode.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoSleepMode( void );
-
-/*!
- * \brief Run Demo in standby RC mode.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoStandbyRcMode( void );
-
-/*!
- * \brief Run Demo in standby XOSC mode.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoStandbyXoscMode( void );
-
-/*!
- * \brief Run Demo Tx in continuous mode without modulation.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t PrepDemoTxCw( void );
-uint8_t RunDemoTxCw( void );
-uint8_t DemoStandby( void );
-/*!
- * \brief Run Demo Tx in continuous modulation.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoTxContinuousModulation( void );
-
-/*!
- * \brief Run Demo Rx in continuous mode.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoRxContinuous( void );
-
-/*!
- * \brief Run demo PingPong.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoApplicationPingPong( void );
-
-/*!
- * \brief Compute payload of Rx frame and update current counts and indicators.
- *
- * \param [in] buffer buffer with frame to compute
- * \param [in] buffersize size of frame data in the buffer
- */
-void ComputePingPongPayload( uint8_t *buffer, uint8_t bufferSize );
-
-/*!
- * \brief Run demo PER.
- *
- * \retval demoStatusUpdate page refresh status ( >0 : refresh)
- */
-uint8_t RunDemoApplicationPer( void );
-
-/*!
- * \brief Compute payload of Rx frame and update current counts and indicators.
- *
- * \param [in] buffer buffer with frame to compute
- * \param [in] buffersize size of frame data in the buffer
- */
-void ComputePerPayload( uint8_t *buffer, uint8_t bufferSize );
-
-#endif // DEMO_APPLICATION_H
--- a/Demo/SX126xLib.lib Mon Feb 15 19:20:41 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/teams/Semtech/code/SX126xLib/#1e2345700991
--- a/Peripherals/Eeprom.cpp Mon Feb 15 19:20:41 2021 +0000 +++ b/Peripherals/Eeprom.cpp Mon Feb 15 21:03:43 2021 +0000 @@ -15,7 +15,7 @@ #include "mbed.h" #include "string.h" #include "Eeprom.h" -#include "DemoApplication.h" +#include "CwTransmitter.h" #include "sx126x.h" #if defined( TARGET_NUCLEO_L476RG ) #include "stm32l4xx_hal_flash.h"
--- a/Peripherals/Eeprom.h Mon Feb 15 19:20:41 2021 +0000 +++ b/Peripherals/Eeprom.h Mon Feb 15 21:03:43 2021 +0000 @@ -17,7 +17,7 @@ //#include "Menu.h" -#include "DemoApplication.h" +#include "CwTransmitter.h" #include "sx126x.h"
--- a/Peripherals/Timers.cpp Mon Feb 15 19:20:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- ______ _
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2016 Semtech
-
-Description: Timers
-
-Maintainer: Gregory Cristian & Gilbert Menth
-*/
-
-#include "mbed.h"
-#include "Timers.h"
-
-
-Ticker TickTimer;
-
-static uint32_t SoftTimer = 0;
-static void TimersIncSoftTimer( void );
-
-
-void TimersInit( void )
-{
- TickTimer.attach_us( &TimersIncSoftTimer, 1000 ); // Ticks every millisecond
-}
-
-static void TimersIncSoftTimer( void )
-{
- SoftTimer++;
-}
-
-void TimersSetTimer( uint32_t *sTimer, uint32_t timeLength )
-{
- if( timeLength > MAX_TIMER_VALUE )
- {
- timeLength = MAX_TIMER_VALUE;
- }
- *sTimer = SoftTimer + timeLength;
-}
-
-uint32_t TimersTimerHasExpired ( const uint32_t * sTimer )
-{
- if( ( SoftTimer - *sTimer ) > 0x7fffffff )
- {
- return false;
- }
- return true;
-}
-
-uint32_t TimersTimerValue ( void )
-{
- return SoftTimer;
-}
--- a/Peripherals/Timers.h Mon Feb 15 19:20:41 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - ______ _ - / _____) _ | | -( (____ _____ ____ _| |_ _____ ____| |__ - \____ \| ___ | (_ _) ___ |/ ___) _ \ - _____) ) ____| | | || |_| ____( (___| | | | -(______/|_____)_|_|_| \__)_____)\____)_| |_| - (C)2016 Semtech - -Description: Timers header - -Maintainer: Gregory Cristian & Gilbert Menth -*/ - -#ifndef TIMERS_H -#define TIMERS_H - - -#define TIM_MSEC ( uint32_t )1 -#define TIM_SEC ( uint32_t )1000 -#define TIM_MIN ( uint32_t )60000 -#define TIM_HOUR ( uint32_t )3600000 -#define MAX_TIMER_VALUE ( TIM_MIN * 150 ) // maximum time for timer - - - /*! - * \brief Initialses the hardware and variables associated with the timers. - */ -void TimersInit( void ); - - /*! - * \brief Sets a timer to a specific value - * - * \param [in] *STimer Pointer to the timer value to be set. - * \param [in] TimeLength Value to set the timer to in milliseconds. - */ -void TimersSetTimer( uint32_t *sTimer, uint32_t timeLength ); - - /*! - * \brief Checks if a timer has expired. - * - * \param [in] *STimer Pointer to the timer value to be read. - * - * \retval Status Non zero if the timer has not expired and is still - * running. - */ -uint32_t TimersTimerHasExpired ( const uint32_t * sTimer ); - - /*! - * \brief Returns the value of the current time in milliseconds - * - * \param [in] refresh Flag indicates refresh display required (touch) - * - * \retval Value value of current time in milliseconds - */ -uint32_t TimersTimerValue ( void ); - -#endif //TIMERS_H
--- a/main.cpp Mon Feb 15 19:20:41 2021 +0000
+++ b/main.cpp Mon Feb 15 21:03:43 2021 +0000
@@ -1,19 +1,4 @@
-/*
- ______ _
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2016 Semtech
-
-Description: Main program
-
-Maintainer: Gregory Cristian & Gilbert Menth
-*/
-
#include "mbed.h"
-#include "Timers.h"
#include "Eeprom.h"
#include "stm32l4xx_hal.h"
@@ -24,6 +9,20 @@
InterruptIn tact(USER_BUTTON);
volatile uint8_t tactFlag=0,t1Flag=0,t2Flag=0;
+// RfFrequency
+#define SET_RF_FREQUENCY 915000000
+// Tx power
+#define TX_POWER 22
+// rampTime
+#define RAMP_TIME RADIO_RAMP_10_US
+// pilotduration, us
+#define PILOT_DURATION 500
+// pilotdelay, us
+#define PILOT_START_DELAY 271
+#define PILOT_STOP_DELAY 462
+
+
+
void baud( int baudrate )
{
@@ -35,9 +34,7 @@
void cwStop()
{
DemoStandby();
- //StopDemoApplication( );
cwTrigger.detach();
- //PrepDemoTxCw( );
}
void cwStart()
@@ -67,16 +64,14 @@
matchingFreq = GetMatchingFrequency( );
EepromInit( deviceConnected, matchingFreq );
- InitDemoApplication( );
- TimersInit( );
-
printf( "Start SX126xDevKit : %s\n\r", FIRMWARE_VERSION );
- PrepDemoTxCw( );
+ PrepDemoTxCw(SET_RF_FREQUENCY,TX_POWER,RAMP_TIME);
+ uint32_t cwTimer = PILOT_DURATION + PILOT_START_DELAY - PILOT_STOP_DELAY;
while( true )
{
if(tactFlag){
RunDemoTxCw( );
- cwTrigger.attach_us(&cwStop, 300); // the address of the function to be attached (cwStop) and the interval (2000000 microseconds)
+ cwTrigger.attach_us(&cwStop, cwTimer);
tactFlag=0;
}