22#include "SEGGER_RTT.h"
23#define printf(format, ...) SEGGER_RTT_printf(0, format, ## __VA_ARGS__)
26#ifndef RADIO_BUSY_PORT
27#define RADIO_BUSY_PORT RADIO_BUSY_GPIO_Port
30#define RADIO_BUSY_PIN RADIO_BUSY_Pin
32#ifndef RADIO_nRESET_PORT
33#define RADIO_nRESET_PORT RADIO_nRESET_GPIO_Port
35#ifndef RADIO_nRESET_PIN
36#define RADIO_nRESET_PIN RADIO_nRESET_Pin
39#define RADIO_NSS_PORT RADIO_NSS_GPIO_Port
42#define RADIO_NSS_PIN RADIO_NSS_Pin
53#define MAX_HAL_BUFFER_SIZE 0xFFF
55#define IRQ_HIGH_PRIORITY 0
159static void spi_tx(
SPI_HandleTypeDef *hspi,
const uint8_t * tx_data, uint16_t tx_len){
161 uint8_t tx_byte = *tx_data++;
166 tx_byte = *tx_data++;
173static void spi_rx(
SPI_HandleTypeDef *hspi, uint8_t * rx_buffer, uint16_t rx_len){
184static void spi_tx_only_dma(
const uint8_t * tx_data, uint16_t tx_len) {
197static void spi_tx_rx_dma(
const uint8_t * tx_data, uint8_t * rx_buffer, uint16_t
size) {
221 const uint16_t dma_min_size_tx = 100;
223 if (tx_len < dma_min_size_tx) {
228 spi_tx_only_dma( halTxBuffer, tx_len );
234 if (rx_len == 0)
return;
237 const uint16_t dma_min_size_rx = 100;
239 if (rx_len < dma_min_size_rx){
244 spi_tx_rx_dma( halZeroBuffer, rx_buffer, rx_len);
271 dioIrqHandlers = irqHandlers;
293 for( uint16_t index = 0; index <
IRAM_SIZE; index++ )
295 halTxBuffer[3+index] = 0x00;
316 uint16_t halSize = 2;
318 halTxBuffer[1] = 0x00;
332 uint16_t halSize =
size + 1;
337 halTxBuffer[0] = command;
338 memcpy( halTxBuffer + 1, ( uint8_t * )buffer,
size *
sizeof( uint8_t ) );
352 halTxBuffer[0] = command;
353 halTxBuffer[1] = 0x00;
368 uint16_t halSize =
size + 3;
370 halTxBuffer[1] = ( address & 0xFF00 ) >> 8;
371 halTxBuffer[2] = address & 0x00FF;
393 halTxBuffer[1] = ( address & 0xFF00 ) >> 8;
394 halTxBuffer[2] = address & 0x00FF;
395 halTxBuffer[3] = 0x00;
419 uint16_t halSize =
size + 2;
421 halTxBuffer[1] = offset;
438 halTxBuffer[1] = offset;
439 halTxBuffer[2] = 0x00;
456#if( RADIO_DIO1_ENABLE )
459#if( RADIO_DIO2_ENABLE )
462#if( RADIO_DIO3_ENABLE )
465#if( !RADIO_DIO1_ENABLE && !RADIO_DIO2_ENABLE && !RADIO_DIO3_ENABLE )
466#error "Please define a DIO"
const struct Radio_s Radio
Radio driver.
const struct lc3_ltpf_data * data
#define __enable_irq
Enable IRQ Interrupts.
#define __disable_irq
Disable IRQ Interrupts.
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout)
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
#define SET_BIT(REG, BIT)
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
#define __HAL_SPI_ENABLE(__HANDLE__)
Enable the SPI peripheral.
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__)
Check whether the specified SPI flag is set or not.
struct __SPI_HandleTypeDef SPI_HandleTypeDef
SPI handle Structure definition.
#define SPI_RXFIFO_THRESHOLD
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
#define RADIO_DIO2_GPIO_Port
#define RADIO_DIO3_GPIO_Port
#define RADIO_DIO1_GPIO_Port
Class holding the basic communications with a radio.
void SX1280HalWriteRegisters(uint16_t address, uint8_t *buffer, uint16_t size)
Write data to the radio memory.
void SX1280HalReset(void)
Soft resets the radio.
void SX1280HalSpiTxThenRx(uint16_t tx_len, uint8_t *rx_buffer, uint16_t rx_len)
void SX1280HalInit(DioIrqHandler **irqHandlers)
uint8_t SX1280HalGetDioStatus(void)
Returns the status of DIOs pins.
#define RADIO_nRESET_PORT
void SX1280HalWaitOnBusy(void)
Used to block execution waiting for low state on radio busy pin. Essentially used in SPI communicatio...
uint8_t SX1280HalReadRegister(uint16_t address)
Read a single byte of data from the radio memory.
void SX1280HalWriteCommand(RadioCommands_t command, uint8_t *buffer, uint16_t size)
Send a command that write data to the radio.
void SX1280HalReadCommand(RadioCommands_t command, uint8_t *buffer, uint16_t size)
Send a command that read data from the radio.
void SX1280HalReadBuffer(uint8_t offset, uint8_t *buffer, uint8_t size)
Read data from the buffer holding the payload in the radio.
void SX1280HalWriteRegister(uint16_t address, uint8_t value)
Write a single byte of data to the radio memory.
void SX1280HalReadRegisters(uint16_t address, uint8_t *buffer, uint16_t size)
Read data from the radio memory.
void SX1280HalIoIrqInit(DioIrqHandler **irqHandlers)
void SX1280HalWriteBuffer(uint8_t offset, uint8_t *buffer, uint8_t size)
Write data to the buffer holding the payload in the radio.
void SX1280HalWakeup(void)
Wakes up the radio.
#define MAX_HAL_BUFFER_SIZE
Define the size of tx and rx hal buffers.
void SX1280HalClearInstructionRam(void)
Clears the instruction ram memory block.
void SX1280SetBufferBaseAddresses(uint8_t txBaseAddress, uint8_t rxBaseAddress)
Sets the data buffer base address for transmission and reception.
void SX1280SetBleAdvertizerAccessAddress(void)
Set the Access Address for Advertizer BLE packets.
double SX1280GetFrequencyError()
Return the Estimated Frequency Error in LORA and RANGING operations.
void SX1280DisableManualGain(void)
Disable the manual gain control and enable AGC.
void SX1280GetPacketStatus(PacketStatus_t *pktStatus)
Gets the last received packet payload length.
void SX1280ClearIrqStatus(uint16_t irq)
Clears the IRQs.
RadioPacketTypes_t SX1280GetPacketType(void)
Gets the current radio protocol.
void SX1280SetSyncWordErrorTolerance(uint8_t ErrorBits)
Defines how many error bits are tolerated in sync word detection.
double SX1280GetRangingResult(RadioRangingResultTypes_t resultType)
Return the ranging result value.
void SX1280SetDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask)
Sets the IRQ mask and DIO masks.
RadioStatus_t SX1280GetStatus(void)
Gets the current radio status.
void SX1280SetTxParams(int8_t power, RadioRampTimes_t rampTime)
Sets the transmission parameters.
void SX1280SetStandby(RadioStandbyModes_t standbyConfig)
Sets the radio in configuration mode.
void SX1280SetInterruptMode(void)
Set the driver in interrupt mode.
void SX1280SetRegistersDefault(void)
Initializes the radio registers to the recommended default values.
void SX1280SetTxContinuousPreamble(void)
Sets the radio in continuous preamble transmission mode.
int8_t SX1280GetRssiInst(void)
Returns the instantaneous RSSI value for the last packet received.
void SX1280SetWhiteningSeed(uint8_t seed)
Sets the Initial value of the LFSR used for the whitening in GFSK, FLRC and BLE protocols.
void SX1280SendPayload(uint8_t *payload, uint8_t size, TickTime_t timeout)
Sends a payload.
void SX1280SetPayload(uint8_t *buffer, uint8_t size)
Saves the payload to be send in the radio buffer.
void SX1280SetPacketParams(PacketParams_t *packetParams)
Sets the packet parameters.
void SX1280SetRangingRequestAddress(uint32_t address)
Sets the device id to ping in a ranging request.
void SX1280SetAutoTx(uint16_t time)
Sets the chip to automatically send a packet after the end of a packet reception.
void SX1280SetAutoFS(uint8_t enable)
Sets the chip to automatically receive a packet after the end of a packet transmission.
void SX1280SetBleAccessAddress(uint32_t accessAddress)
Set the Access Address field of BLE packet.
void SX1280SetCrcPolynomial(uint16_t polynomial)
Sets the seed used for the CRC calculation.
RadioOperatingModes_t SX1280GetOpMode(void)
Gets the current Operation Mode of the Radio.
void SX1280RangingSetFilterNumSamples(uint8_t num)
Set the number of samples considered in the built-in filter.
void SX1280GetRxBufferStatus(uint8_t *payloadLength, uint8_t *rxStartBufferPointer)
Gets the last received packet buffer status.
uint8_t SX1280SetSyncWord(uint8_t syncWordIdx, uint8_t *syncWord)
Sets the Sync Word given by index used in GFSK, FLRC and BLE protocols.
void SX1280SetLNAGainSetting(const RadioLnaSettings_t lnaSetting)
Configure the LNA regime of operation.
void SX1280SetCad(void)
Sets the radio in CAD mode.
void SX1280RangingClearFilterResult(void)
Clears the ranging filter.
void SX1280SetRx(TickTime_t timeout)
Sets the radio in reception mode.
void SX1280SetTxContinuousWave(void)
Sets the radio in continuous wave transmission mode.
void SX1280SetRangingIdLength(RadioRangingIdCheckLengths_t length)
Sets the number of bits used to check that ranging request match ranging ID.
void SX1280StopAutoTx(void)
Stop the chip from automatically sending a packet after the end of a packet reception if previously a...
void SX1280Calibrate(CalibrationParams_t calibParam)
Calibrates the given radio block.
uint16_t SX1280GetFirmwareVersion(void)
Returns the current device firmware version.
void SX1280EnableManualGain(void)
Enable manual gain and disable AGC.
void SX1280SetFs(void)
Sets the radio in FS mode.
void SX1280SetSleep(SleepParams_t sleepConfig)
Sets the radio in sleep mode.
void SX1280SetCadParams(RadioLoRaCadSymbols_t cadSymbolNum)
Sets the number of symbols to be used for Channel Activity Detection operation.
void SX1280SetTx(TickTime_t timeout)
Sets the radio in transmission mode.
void SX1280SetRegulatorMode(RadioRegulatorModes_t mode)
Sets the power regulators operating mode.
void SX1280SetRxDutyCycle(RadioTickSizes_t Step, uint16_t NbStepRx, uint16_t RxNbStepSleep)
Sets the Rx duty cycle management parameters.
uint8_t SX1280GetRangingPowerDeltaThresholdIndicator(void)
Return the last ranging result power indicator.
void SX1280SetManualGainValue(uint8_t gain)
Set the gain for LNA.
void SX1280SetDeviceRangingAddress(uint32_t address)
Sets ranging device id.
void SX1280SetModulationParams(ModulationParams_t *modulationParams)
Set the modulation parameters.
void SX1280SetRangingRole(RadioRangingRoles_t role)
Set the role of the radio during ranging operations.
void SX1280SetRfFrequency(uint32_t frequency)
Sets the RF frequency.
uint8_t SX1280GetPayload(uint8_t *buffer, uint8_t *size, uint8_t maxSize)
Reads the payload received. If the received payload is longer than maxSize, then the method returns 1...
uint16_t SX1280GetIrqStatus(void)
Returns the current IRQ status.
void SX1280SetSaveContext(void)
Saves the current selected modem configuration into data RAM.
void SX1280SetLongPreamble(uint8_t enable)
Enables or disables long preamble detection mode.
void SX1280SetRangingCalibration(uint16_t cal)
Sets the standard processing delay between Master and Slave.
void SX1280Init(RadioCallbacks_t *callbacks)
Initializes the radio driver.
void SX1280SetCrcSeed(uint16_t seed)
Sets the Initial value for the LFSR used for the CRC calculation.
void SX1280SetPollingMode(void)
Set the driver in polling mode.
void SX1280SetPacketType(RadioPacketTypes_t packetType)
Sets the radio for the given protocol.
void DioIrqHandler(void)
Hardware IO IRQ callback function definition.
#define IRAM_START_ADDRESS
The address of the instruction RAM and its size.
enum RadioCommands_u RadioCommands_t
Represents all possible opcode understood by the radio.