123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- #include "board.h"
- #include "myRadio.h"
- #include "myRadio_gpio.h"
- /**-------------------------radio include----------------------------------**/
- #include "radio.h"
- #include "sx1280.h"
- #include "sx1280-hal.h"
- /**-------------------------radio include end----------------------------------**/
- static int8_t rfTxPower;
- static uint32_t rfFrequence;
- static uint32_t rfBaudrate;
- static rfRxCallBack rxCb;
- static uint8_t rfRxBuffer[255];
- static uint32_t rf_handle;
- static uint8_t rf_workProcess;
- static uint8_t chipType;
- static uint8_t rfModuleMode = RF_MM_MODE_FLRC;
- /**-------------------------radio params----------------------------------**/
- ModulationParams_t modulationParams;
- rfRxPacket_ts rfRxPacket;
- const loraBaudrateFrame_ts loraBaudrateFrame[MAX_RF_BAUDRATE_LR_COUNT] =
- {
- {//216.264204545455bps,SF=12,BW=203kHz,CR=7
- .SpreadingFactor = LORA_SF12,
- .SignalBw = LORA_BW_0200,
- .ErrorCoding = LORA_CR_LI_4_7,
- },
- {//991.2109375bps,SF=10,BW=203kHz,CR=4
- .SpreadingFactor = LORA_SF10,
- .SignalBw = LORA_BW_0200,
- .ErrorCoding = LORA_CR_4_8,
- },
- {//4987.44419642857bps,SF=11,BW=1625kHz,CR=3
- .SpreadingFactor = LORA_SF11,
- .SignalBw = LORA_BW_1600,
- .ErrorCoding = LORA_CR_4_7,
- },
- {//10150bps,SF=8,BW=812kHz,CR=6
- .SpreadingFactor = LORA_SF8,
- .SignalBw = LORA_BW_0800,
- .ErrorCoding = LORA_CR_LI_4_6,
- },
- {//20300bps,SF=8,BW=812kHz,CR=1
- .SpreadingFactor = LORA_SF8,
- .SignalBw = LORA_BW_0800,
- .ErrorCoding = LORA_CR_4_5,
- },
- {//60900bps,SF=6,BW=812kHz,CR=1
- .SpreadingFactor = LORA_SF6,
- .SignalBw = LORA_BW_0800,
- .ErrorCoding = LORA_CR_4_5,
- },
- {//126953.125bps,SF=5,BW=1625kHz,CR=4
- .SpreadingFactor = LORA_SF5,
- .SignalBw = LORA_BW_1600,
- .ErrorCoding = LORA_CR_4_8,
- },
- {//203125bps,SF=5,BW=1625kHz,CR=1
- .SpreadingFactor = LORA_SF5,
- .SignalBw = LORA_BW_1600,
- .ErrorCoding = LORA_CR_4_5,
- },
- };
- const fastloraBaudrateFrame_ts fastLoraConfigList[] =
- {
- {//0.13Mbps
- .BitrateBandwidth =FLRC_BR_0_260_BW_0_3,
- .CodingRate =FLRC_CR_1_2,
- .ModulationShaping =RADIO_MOD_SHAPING_BT_1_0,
- },
- {//0.26Mbps
- .BitrateBandwidth =FLRC_BR_0_520_BW_0_6,
- .CodingRate =FLRC_CR_1_2,
- .ModulationShaping =RADIO_MOD_SHAPING_BT_1_0,
- },
- {//0.52Mbps
- .BitrateBandwidth =FLRC_BR_1_040_BW_1_2,
- .CodingRate =FLRC_CR_1_2,
- .ModulationShaping =RADIO_MOD_SHAPING_BT_1_0,
- },
- {//1.04Mbps
- .BitrateBandwidth =FLRC_BR_1_040_BW_1_2,
- .CodingRate =FLRC_CR_1_0,
- .ModulationShaping =RADIO_MOD_SHAPING_BT_1_0,
- },
- };
- #define RF_BL_ADV_CHANNEL_38 2478000000 // Hz
- /*!
- * \brief Defines the nominal frequency
- */
- #define RF_FREQUENCY RF_BL_ADV_CHANNEL_38 // Hz
- /*!
- * \brief Defines the output power in dBm
- *
- * \remark The range of the output power is [-18..+13] dBm
- */
- #define TX_OUTPUT_POWER 13
- /*!
- * \brief Defines the buffer size, i.e. the payload size
- */
- #define BUFFER_SIZE 64
- /*!
- * \brief Number of tick size steps for tx timeout
- */
- #define TX_TIMEOUT_VALUE 3000 // ms
- /*!
- * \brief Number of tick size steps for rx timeout
- */
- #define RX_TIMEOUT_VALUE 0//1000 // ms
- /*!
- * \brief Size of ticks (used for Tx and Rx timeout)
- */
- #define RX_TIMEOUT_TICK_SIZE RADIO_TICK_SIZE_1000_US
- /*!
- * \brief Defines the size of the token defining message type in the payload
- */
- #define PINGPONGSIZE 4
- /*!
- * \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 );
- RadioCallbacks_t Callbacks =
- {
- &OnTxDone, // txDone
- &OnRxDone, // rxDone
- NULL, // syncWordDone
- NULL, // headerDone
- &OnTxTimeout, // txTimeout
- &OnRxTimeout, // rxTimeout
- &OnRxError, // rxError
- NULL, // rangingDone
- NULL, // cadDone
- };
- /*!
- * \brief Define the possible message type for this application
- */
- const uint8_t PingMsg[] = "PING";
- const uint8_t PongMsg[] = "PONG";
- typedef enum
- {
- APP_LOWPOWER,
- APP_RUNNING,
- APP_RX,
- APP_RX_TIMEOUT,
- APP_RX_ERROR,
- APP_TX,
- APP_TX_TIMEOUT,
- }AppStates_t;
- /*!
- * \brief The size of the buffer
- */
- uint8_t BufferSize = BUFFER_SIZE;
- /*!
- * \brief The buffer
- */
- uint8_t Buffer[BUFFER_SIZE];
- /*!
- * \brief Mask of IRQs to listen to in rx mode
- */
- uint16_t RxIrqMask = IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT | IRQ_CRC_ERROR;
- /*!
- * \brief Mask of IRQs to listen to in tx mode
- */
- uint16_t TxIrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT | IRQ_CRC_ERROR;
- /*!
- * \brief The State of the application
- */
- AppStates_t AppState = APP_LOWPOWER;
- // #if defined( MODE_BLE )
- /*!
- * \brief In case of BLE, the payload must contain the header
- */
- typedef union
- {
- struct BleAdvHeaderField_s
- {
- uint8_t pduType: 4;
- uint8_t rfu1:2;
- uint8_t txAddr:1;
- uint8_t rxAddr:1;
- uint8_t length:6;
- uint8_t rfu2:2;
- } Fields;
- uint8_t Serial[ 2 ];
- }BleAdvHeaders_t;
- BleAdvHeaders_t ble_header_adv;
- // #endif // MODE_BLE
- PacketParams_t packetParams;
- PacketStatus_t packetStatus;
- /**-------------------------radio params end----------------------------------**/
- void myRadio_delay(uint32_t time_ms)
- {
- uint32_t i, j;
- i = time_ms;
- while (i --)
- {
- for ( j = 0; j < 1000; j++)
- {
- ;
- }
- }
- }
- /**
- * @brief IO口中断回调
- * IO口产生中断后会执行该函数
- * 用于接收射频工作的中断响应
- *
- * @param index
- */
- void myRadio_gpioCallback(uint8_t index)
- {
- SX1280OnDioIrq();
- }
- void myRadio_setRfModuleMode(uint8_t mode)
- {
- rfModuleMode = mode;
- }
- /**
- * @brief 射频初始化
- *
- * @param agr0
- * @param agr1_ptr 无线工作状态响应回调
- * 产生回调给外部使用,@rfRxCallBack
- */
- void myRadio_init(int agr0, void *agr1_ptr)
- {
- myRadio_gpio_init(myRadio_gpioCallback);
-
- /**-------------------------radio init----------------------------------**/
- uint16_t ver = 0;
- myRadio_delay(1000);
- Radio.Init( &Callbacks );
- Radio.SetRegulatorMode( USE_DCDC ); // Can also be set in LDO mode but consume more power
- {
-
- ver = Radio.GetFirmwareVersion();//获取芯片信息 0xA9B5 可用于测试SPI的读写情况
- }
- if (rfModuleMode == RF_MM_MODE_BLE)
- {
- modulationParams.PacketType = PACKET_TYPE_BLE;
- modulationParams.Params.Ble.BitrateBandwidth = GFS_BLE_BR_1_000_BW_1_2;
- modulationParams.Params.Ble.ModulationIndex = GFS_BLE_MOD_IND_0_50;
- modulationParams.Params.Ble.ModulationShaping = RADIO_MOD_SHAPING_BT_0_5;
-
- packetParams.PacketType = PACKET_TYPE_BLE;
- packetParams.Params.Ble.BlePacketType = BLE_EYELONG_1_0;
- packetParams.Params.Ble.ConnectionState = BLE_ADVERTISER;
- packetParams.Params.Ble.CrcField = BLE_CRC_3B;
- packetParams.Params.Ble.Whitening = RADIO_WHITENING_ON;
- }
- else if(rfModuleMode == RF_MM_MODE_LORA)
- {
- modulationParams.PacketType = PACKET_TYPE_LORA;
- modulationParams.Params.LoRa.SpreadingFactor = LORA_SF5;//
- modulationParams.Params.LoRa.Bandwidth = LORA_BW_0400;
- modulationParams.Params.LoRa.CodingRate = LORA_CR_LI_4_5;
-
- packetParams.PacketType = PACKET_TYPE_LORA;
- packetParams.Params.LoRa.PreambleLength = 12;
- packetParams.Params.LoRa.HeaderType = LORA_PACKET_VARIABLE_LENGTH;
- packetParams.Params.LoRa.PayloadLength = BUFFER_SIZE;
- packetParams.Params.LoRa.CrcMode = LORA_CRC_ON;
- packetParams.Params.LoRa.InvertIQ = LORA_IQ_NORMAL;
- }
- else if(rfModuleMode == RF_MM_MODE_GFSK)
- {
- modulationParams.PacketType = PACKET_TYPE_GFSK;
- modulationParams.Params.Gfsk.BitrateBandwidth = GFS_BLE_BR_0_125_BW_0_3;
- modulationParams.Params.Gfsk.ModulationIndex = GFS_BLE_MOD_IND_1_00;
- modulationParams.Params.Gfsk.ModulationShaping = RADIO_MOD_SHAPING_BT_1_0;
- packetParams.PacketType = PACKET_TYPE_GFSK;
- packetParams.Params.Gfsk.PreambleLength = PREAMBLE_LENGTH_24_BITS;
- packetParams.Params.Gfsk.SyncWordLength = GFS_SYNCWORD_LENGTH_5_BYTE;
- packetParams.Params.Gfsk.SyncWordMatch = RADIO_RX_MATCH_SYNCWORD_1_2_3;
- packetParams.Params.Gfsk.HeaderType = RADIO_PACKET_FIXED_LENGTH;
- packetParams.Params.Gfsk.PayloadLength = BUFFER_SIZE;
- packetParams.Params.Gfsk.CrcLength = RADIO_CRC_OFF;
- packetParams.Params.Gfsk.Whitening = RADIO_WHITENING_OFF;
- // packetParams.PacketType = PACKET_TYPE_GFSK;
- // packetParams.Params.Gfsk.PreambleLength = PREAMBLE_LENGTH_32_BITS;
- // packetParams.Params.Gfsk.SyncWordLength = GFS_SYNCWORD_LENGTH_5_BYTE;
- // packetParams.Params.Gfsk.SyncWordMatch = RADIO_RX_MATCH_SYNCWORD_1;
- // packetParams.Params.Gfsk.HeaderType = RADIO_PACKET_VARIABLE_LENGTH;
- // packetParams.Params.Gfsk.PayloadLength = BUFFER_SIZE;
- // packetParams.Params.Gfsk.CrcLength = RADIO_CRC_3_BYTES;
- // packetParams.Params.Gfsk.Whitening = RADIO_WHITENING_ON;
-
-
- }
- else if(rfModuleMode == RF_MM_MODE_FLRC)
- {
- modulationParams.PacketType = PACKET_TYPE_FLRC;
- modulationParams.Params.Flrc.BitrateBandwidth = FLRC_BR_0_325_BW_0_3;
- modulationParams.Params.Flrc.CodingRate = FLRC_CR_1_2;
- modulationParams.Params.Flrc.ModulationShaping = RADIO_MOD_SHAPING_BT_1_0;
- packetParams.PacketType = PACKET_TYPE_FLRC;
- packetParams.Params.Flrc.PreambleLength = PREAMBLE_LENGTH_32_BITS;
- packetParams.Params.Flrc.SyncWordLength = FLRC_SYNCWORD_LENGTH_4_BYTE;
- packetParams.Params.Flrc.SyncWordMatch = RADIO_RX_MATCH_SYNCWORD_1;
- packetParams.Params.Flrc.HeaderType = RADIO_PACKET_VARIABLE_LENGTH;
- packetParams.Params.Flrc.PayloadLength = BUFFER_SIZE;
- packetParams.Params.Flrc.CrcLength = RADIO_CRC_3_BYTES;
- packetParams.Params.Flrc.Whitening = RADIO_WHITENING_OFF;
- }
- else
- {
- modulationParams.PacketType = PACKET_TYPE_FLRC;
- modulationParams.Params.Flrc.BitrateBandwidth = FLRC_BR_0_325_BW_0_3;
- modulationParams.Params.Flrc.CodingRate = FLRC_CR_1_2;
- modulationParams.Params.Flrc.ModulationShaping = RADIO_MOD_SHAPING_BT_1_0;
- packetParams.PacketType = PACKET_TYPE_FLRC;
- packetParams.Params.Flrc.PreambleLength = PREAMBLE_LENGTH_32_BITS;
- packetParams.Params.Flrc.SyncWordLength = FLRC_SYNCWORD_LENGTH_4_BYTE;
- packetParams.Params.Flrc.SyncWordMatch = RADIO_RX_MATCH_SYNCWORD_1;
- packetParams.Params.Flrc.HeaderType = RADIO_PACKET_VARIABLE_LENGTH;
- packetParams.Params.Flrc.PayloadLength = BUFFER_SIZE;
- packetParams.Params.Flrc.CrcLength = RADIO_CRC_3_BYTES;
- packetParams.Params.Flrc.Whitening = RADIO_WHITENING_OFF;
-
- }
-
-
-
-
- // #elif defined( MODE_GFSK )
-
- // #elif defined( MODE_LORA )
-
-
- // #elif defined( MODE_FLRC )
-
- // #else
- // #error "Please select the mode of operation for the Ping Ping demo"
- // #endif
-
- Radio.SetStandby( STDBY_RC );
- Radio.SetPacketType( modulationParams.PacketType );
- Radio.SetModulationParams( &modulationParams );
- Radio.SetPacketParams( &packetParams );
- Radio.SetRfFrequency( RF_FREQUENCY );//频点设置
- Radio.SetBufferBaseAddresses( 0x00, 0x00 );
- Radio.SetTxParams( TX_OUTPUT_POWER, RADIO_RAMP_02_US );//功率设置
-
- // Radio.SetInterruptMode();
- Radio.SetPollingMode();
-
- if(rfModuleMode == RF_MM_MODE_GFSK)
- {
- //接收灵敏度测试
- Radio.SetSyncWord( 1, ( uint8_t[] ){ 0xDD, 0xA0, 0x96, 0x69, 0xDD } );
- }
- if(rfModuleMode == RF_MM_MODE_BLE)
- {
- // only used in GENERIC and BLE mode
- Radio.WriteRegister(0x9c7, 0x55 );
- Radio.WriteRegister(0x9c8, 0x55 );
- Radio.WriteRegister(0x9c9, 0x55 );
- //Radio.WriteRegister( 0x9c5, 0x33 );
- Radio.SetBleAdvertizerAccessAddress( );
- Radio.SetWhiteningSeed( 0x33 );
- ble_header_adv.Fields.length = PINGPONGSIZE + 2;
- ble_header_adv.Fields.pduType = 2;
- }
- AppState = APP_LOWPOWER;
- /**-------------------------radio init end----------------------------------**/
- RF_EXT_PA_TO_IDLE();
- if ((rfRxCallBack )agr1_ptr)
- {
- rxCb = (rfRxCallBack )agr1_ptr;
- }
- rf_handle = 0xe5;
- }
- /**
- * @brief 射频底层执行程序
- * 要放在主循环中执行
- *
- */
- void myRadio_process(void)
- {
- if (rf_handle == 0)
- {
- return;
- }
- SX1280ProcessIrqs();
- }
- /**
- * @brief 退出射频进入休眠
- *
- */
- void myRadio_abort(void)
- {
- if (rf_handle == 0)
- {
- return;
- }
- RF_EXT_PA_TO_IDLE();
- SleepParams_t SleepParams;
- SleepParams.DataBufferRetention = 1;
- SleepParams.DataRamRetention = 1;
- SleepParams.InstructionRamRetention = 1;
- SleepParams.WakeUpRTC = 0;
- // Radio.SetSleep( SleepParams );
- Radio.SetStandby( STDBY_RC );
- }
- /**
- * @brief 获取射频工作中心频率
- *
- * @return uint32_t
- */
- uint32_t myRadio_getFrequency(void)
- {
- if (rf_handle == 0)
- {
- return 0;
- }
- return rfFrequence;
- }
- /**
- * @brief 设置射频工作中心频率
- *
- * @param freq
- * 具体频点,单位:Hz
- */
- void myRadio_setFrequency(uint32_t freq)
- {
- if (rf_handle == 0)
- {
- return;
- }
- rfFrequence = freq;
- Radio.SetRfFrequency(freq);
- }
- /**
- * @brief 获取发射功率
- *
- * @return int8_t
- */
- int8_t myRadio_getTxPower(void)
- {
- if (rf_handle == 0)
- {
- return 0;
- }
- return rfTxPower;
- }
- /**
- * @brief 设置发射功率
- *
- * @param power
- * 单位:dbm
- */
- void myRadio_setTxPower(int8_t power)
- {
- if (rf_handle == 0)
- {
- return;
- }
- rfTxPower = power;
- Radio.SetTxParams( rfTxPower, RADIO_RAMP_02_US );
- }
- /**
- * 获取射频波特率
- * @param : br->
- */
- uint32_t myRadio_getBaudrate(void)
- {
- if (rf_handle == 0)
- {
- return 0;
- }
- return rfBaudrate;
- }
- /**
- * 设置射频波特率
- * @param : br->
- */
- void myRadio_setBaudrate(uint32_t br)
- {
- if (rf_handle == 0)
- {
- return;
- }
- rfBaudrate = br;
- if(rfModuleMode == RF_MM_MODE_GFSK)
- {
- }
- else if (rfModuleMode == RF_MM_MODE_LORA)
- {
- modulationParams.Params.LoRa.SpreadingFactor = loraBaudrateFrame[rfBaudrate].SpreadingFactor;//
- modulationParams.Params.LoRa.Bandwidth = loraBaudrateFrame[rfBaudrate].SignalBw;
- modulationParams.Params.LoRa.CodingRate = loraBaudrateFrame[rfBaudrate].ErrorCoding;
- }
- else if (rfModuleMode == RF_MM_MODE_FLRC)
- {
- modulationParams.Params.Flrc.BitrateBandwidth = fastLoraConfigList[rfBaudrate].BitrateBandwidth;//
- modulationParams.Params.Flrc.CodingRate = fastLoraConfigList[rfBaudrate].CodingRate;
- modulationParams.Params.Flrc.ModulationShaping = fastLoraConfigList[rfBaudrate].ModulationShaping;
- }
- else
- {
- modulationParams.Params.Flrc.BitrateBandwidth = fastLoraConfigList[rfBaudrate].BitrateBandwidth;//
- modulationParams.Params.Flrc.CodingRate = fastLoraConfigList[rfBaudrate].CodingRate;
- modulationParams.Params.Flrc.ModulationShaping = fastLoraConfigList[rfBaudrate].ModulationShaping;
- }
-
- Radio.SetModulationParams( &modulationParams );
- }
- /**
- * @brief 设置模组型号
- *
- * @param type
- */
- void myRadio_setChipType(uint8_t type)
- {
- chipType = type;
- }
- /**
- * @brief 获取模组型号
- *
- * @return uint8_t
- */
- uint8_t myRadio_getChipType(void)
- {
- return chipType;
- }
- int16_t myRadio_getRssi(void)
- {
- return Radio.GetRssiInst();;
- }
- /**
- * @brief 无线发送数据包
- *
- * @param packet
- */
- void myRadio_transmit(rfTxPacket_ts *packet)
- {
- if (rf_handle == 0)
- {
- return;
- }
- RF_EXT_PA_TO_TX();
- if (Radio.GetOpMode() == MODE_SLEEP)
- {
- myRadio_delay(1);
- }
- TickTime_t TickTime ={ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE };
- Radio.SetDioIrqParams( TxIrqMask, TxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
- if(rfModuleMode == RF_MM_MODE_GFSK)
- {
- packetParams.Params.Gfsk.PayloadLength = packet->len;
- }
- else if (rfModuleMode == RF_MM_MODE_LORA)
- {
- packetParams.Params.LoRa.PayloadLength = packet->len;
- }
- else if (rfModuleMode == RF_MM_MODE_FLRC)
- {
- packetParams.Params.Flrc.PayloadLength = packet->len;
- }
- else
- {
- packetParams.Params.Flrc.PayloadLength = packet->len;
- }
- Radio.SetPacketParams( &packetParams );
- Radio.SendPayload( packet->payload, packet->len, TickTime);
- }
- /**
- * @brief 进入无线接收
- *
- */
- void myRadio_receiver(void)
- {
- if (rf_handle == 0)
- {
- return;
- }
- RF_EXT_PA_TO_RX();
- TickTime_t TickTime ={ RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE };
- Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
- Radio.SetRx( TickTime );
- }
- void myRadio_setCtrl(controlMode_te mode, uint32_t value)
- {
- if (rf_handle == 0)
- {
- return;
- }
- myRadio_setRfModuleMode(RF_MM_MODE_GFSK);
- myRadio_init(0, 0);
- switch (mode)
- {
- case RADIO_EXT_CONTROL_TX_UNMODULATED:
- {
- RF_EXT_PA_TO_TX();
- Radio.SetRfFrequency(rfFrequence);
- Radio.SetTxParams( rfTxPower, RADIO_RAMP_02_US );
- Radio.SetTxContinuousWave();
- }
- break;
- case RADIO_EXT_CONTROL_TX_MODULATED:
- {
- RF_EXT_PA_TO_TX();
- Radio.SetRfFrequency(rfFrequence);
- Radio.SetTxParams( rfTxPower, RADIO_RAMP_02_US );
- Radio.SetTxContinuousWave();
- }
- break;
- case RADIO_EXT_CONTROL_RX_SENSITIVITY:
- {
- RF_EXT_PA_TO_RX();
- myRadio_receiver();
- }
- break;
-
- default:
- break;
- }
- }
- /**-------------------------radio funtion----------------------------------**/
- void OnTxDone( void )
- {
- AppState = APP_TX;
- RF_EXT_PA_TO_IDLE();
- if (rxCb)
- {
- rxCb(TX_STA_SECCESS, rfRxPacket);
- }
- }
- void OnRxDone( void )
- {
-
- AppState = APP_RX;
- memset(rfRxPacket.payload, 0, sizeof(rfRxPacket.payload));
- Radio.GetPayload( rfRxPacket.payload, &rfRxPacket.len, sizeof(rfRxPacket.payload) );
- rfRxPacket.rssi = Radio.GetRssiInst();
- if (rxCb)
- {
- rxCb(RX_STA_SECCESS, rfRxPacket);
- }
- }
- void OnTxTimeout( void )
- {
- AppState = APP_TX_TIMEOUT;
- }
- void OnRxTimeout( void )
- {
- rfRxPacket_ts rfRxPacket;
- AppState = APP_RX_TIMEOUT;
- if (rxCb)
- {
- rxCb(RX_STA_TIMEOUT, rfRxPacket);
- }
- }
- void OnRxError( IrqErrorCode_t errorCode )
- {
- rfRxPacket_ts rfRxPacket;
- AppState = APP_RX_ERROR;
- if (rxCb)
- {
- rxCb(RX_STA_PAYLOAD_ERROR, rfRxPacket);
- }
- }
- void OnRangingDone( IrqRangingCode_t val )
- {
-
- }
- void OnCadDone( bool channelActivityDetected )
- {
-
- }
- /**-------------------------radio funtion end----------------------------------**/
|