sx1262 module telemetry + SPP service implementation. More...
#include "spp/services/sx1262/sx1262.h"#include "spp/hal/spi/spi.h"#include "spp/hal/gpio/gpio.h"#include "spp/hal/time/time.h"#include <stdio.h>Go to the source code of this file.
Variables | |
| static SX1262_Ctx_t | s_sx1262Ctx |
| static SPP_Packet_t | mailboxData [K_SX1262_MAILBOX_SIZE] = {0} |
| static spp_uint8_t | mailboxHead = 0 |
| static spp_uint8_t | mailboxTail = 0 |
| static spp_uint8_t | mailboxCount = 0 |
| volatile spp_bool_t | g_txDoneFlag = false |
| SPP_GpioIsrCtx_t | g_dio1Ctx = {.p_flag = &g_txDoneFlag} |
| static SPP_SERVICE_ConsumerContract_t | sx1262Contract |
sx1262 module telemetry + SPP service implementation.
Definition in file sx1262.c.
|
static |
Initializes the SX1262 radio for LoRa transmission.
Initializes SPI and GPIO, resets the radio, configures the TCXO, regulator, RF frequency, modulation, transmission parameters and DIO1 interrupts.
Definition at line 99 of file sx1262.c.
References K_SPP_ERROR, K_SPP_OK, K_SX1262_SPI, SX1262_Ctx_t::p_spi, s_sx1262Ctx, SPP_HAL_GPIO_configInterrupt(), SPP_HAL_GPIO_write(), SPP_HAL_SPI_deviceInit(), SPP_HAL_SPI_getHandle(), SPP_HAL_TIME_delayMs(), SPP_SERVICES_SX1262_init(), SX1262_BUSY_PIN, SX1262_Calibrate(), SX1262_CalibrateImage(), SX1262_ClearDeviceErrors(), SX1262_GetDeviceErrors(), SX1262_InitInterrupts(), SX1262_SetBufferBaseAddress(), SX1262_SetDio3AsTcxoCtrl(), SX1262_SetDioIrqParams(), SX1262_SetModulationParams(), SX1262_SetPacketType(), SX1262_SetPaConfig(), SX1262_SetRegulatorMode(), SX1262_SetRfFrequency(), SX1262_SetStandby(), SX1262_SetTxParams(), SX1262_WriteRegister(), and SX126X_NRESET_PIN.
Referenced by SPP_SERVICES_SX1262_init().
|
static |
Advances the radio transmission state machine.
Processes one transmission stage per call: IDLE, WRITE_BUFFER, SET_PARAMS, SET_TX or WAIT_TX_DONE.
Transmits 64-byte SPP packets individually. If more than K_SX1262_MAX_PACKETS_TO_TRANSMIT packets are queued when transmission starts, the oldest excess packets are discarded.
Transmission completion is verified through DIO1 and IRQ status. Timeouts clear the transmission mailbox.
| p_data | Unused. |
Definition at line 282 of file sx1262.c.
References SX1262_Ctx_t::frame_number, g_txDoneFlag, K_SPP_ERROR, K_SPP_OK, K_SPP_TOTAL_PACKET_SIZE, K_SX1262_MAILBOX_SIZE, K_SX1262_MAX_PACKETS_TO_TRANSMIT, mailboxCount, mailboxData, mailboxHead, SX1262_Ctx_t::p_spi, s_sx1262Ctx, SPP_HAL_GPIO_read(), SPP_HAL_TIME_getTimeMs(), SPP_SERVICES_SX1262_consumeData(), SX1262_BUSY_PIN, SX1262_ClearIrqStatus(), SX1262_GetIrqStatus(), SX1262_IRQ_TIMEOUT, SX1262_IRQ_TX_DONE, SX1262_MAX_BUSY_TIMEOUT_MS, SX1262_MAX_DONE_TIMEOUT_MS, SX1262_SetPacketParams(), SX1262_SetTx(), SX1262_Timeout_Sequence(), SX1262_TX_STATE_IDLE, SX1262_TX_STATE_SET_PARAMS, SX1262_TX_STATE_SET_TX, SX1262_TX_STATE_WAIT_TX_DONE, SX1262_TX_STATE_WRITE_BUFFER, SX1262_WriteBuffer(), SX1262_Ctx_t::timer_ms, and SX1262_Ctx_t::tx_state.
Referenced by SPP_SERVICES_SX1262_consumeData().
|
static |
Copies a received SPP packet into the transmission mailbox.
The mailbox is a circular buffer. If full, the oldest packet is overwritten.
| pqt | Packet received from PUBSUB. |
Definition at line 248 of file sx1262.c.
References K_SPP_OK, K_SX1262_MAILBOX_SIZE, mailboxCount, mailboxData, mailboxHead, mailboxTail, SPP_Packet_t, and SPP_SERVICES_SX1262_deliverToMailbox().
Referenced by SPP_SERVICES_SX1262_deliverToMailbox().
|
static |
Waits until the SX1262 BUSY pin becomes low.
Polls the GPIO until the radio is ready or the timeout is reached. This function blocks during the wait.
Definition at line 852 of file sx1262.c.
References K_SPP_ERROR, K_SPP_OK, SPP_HAL_GPIO_read(), SPP_HAL_TIME_getTimeMs(), SX1262_BUSY_PIN, SX1262_MAX_BUSY_TIMEOUT_MS, and SX1262_WaitBusy().
Referenced by SX1262_Calibrate(), SX1262_CalibrateImage(), SX1262_ClearDeviceErrors(), SX1262_ClearIrqStatus(), SX1262_GetDeviceErrors(), SX1262_GetIrqStatus(), SX1262_SetBufferBaseAddress(), SX1262_SetDio3AsTcxoCtrl(), SX1262_SetDioIrqParams(), SX1262_SetModulationParams(), SX1262_SetPacketType(), SX1262_SetPaConfig(), SX1262_SetRegulatorMode(), SX1262_SetRfFrequency(), SX1262_SetStandby(), SX1262_SetTxParams(), SX1262_WaitBusy(), and SX1262_WriteRegister().
|
static |
Definition at line 453 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_STANDBY, SX1262_SetStandby(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetStandby().
|
static |
Definition at line 573 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_PACKET_TYPE, SX1262_SetPacketType(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetPacketType().
|
static |
Definition at line 586 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_RF_FRECUENCY, SX1262_SetRfFrequency(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetRfFrequency().
|
static |
Definition at line 601 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_PA_CONFIG, SX1262_SetPaConfig(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetPaConfig().
|
static |
Definition at line 616 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_CalibrateImage(), SX1262_OPCODE_CALIBRATE_IMAGE, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_CalibrateImage().
|
static |
Definition at line 630 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_TX_PARAMS, SX1262_SetTxParams(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetTxParams().
|
static |
Definition at line 646 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_BUFFER_BASE_ADDRESS, SX1262_SetBufferBaseAddress(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetBufferBaseAddress().
|
static |
Definition at line 690 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_MODULATION_PARAMS, SX1262_SetModulationParams(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetModulationParams().
|
static |
Definition at line 706 of file sx1262.c.
References SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_PACKET_PARAMS, and SX1262_SetPacketParams().
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_SetPacketParams().
|
static |
Definition at line 725 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_DIO_IRQ_PARAMS, SX1262_SetDioIrqParams(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetDioIrqParams().
|
static |
Definition at line 745 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_ClearIrqStatus(), SX1262_OPCODE_CLEAR_IRQ_STATUS, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_ClearIrqStatus().
|
static |
Configures DIO1 as a rising-edge interrupt input.
Registers the ISR context used to set g_txDoneFlag.
Definition at line 802 of file sx1262.c.
References g_dio1Ctx, K_SPP_ERROR, K_SPP_OK, SPP_HAL_GPIO_configInterrupt(), SPP_HAL_GPIO_registerIsr(), SX1262_DIO1_PIN, and SX1262_InitInterrupts().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_InitInterrupts().
|
static |
Writes a payload into the SX1262 internal TX buffer.
Uses buffer offset 0 and prepends the SPI opcode and offset.
| p_handle | SPI device handle. |
| p_data | Payload to transmit. |
| length | Payload size in bytes. |
Definition at line 669 of file sx1262.c.
References SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_WRITE_BUFFER, and SX1262_WriteBuffer().
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_WriteBuffer().
|
static |
Definition at line 531 of file sx1262.c.
References SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_TX, and SX1262_SetTx().
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_SetTx().
|
static |
Definition at line 823 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_WaitBusy(), and SX1262_WriteRegister().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_WriteRegister().
|
static |
Resets the software transmission state after a timeout.
Returns the TX FSM to IDLE, discards all queued packets and clears the TX completion flag.
Does not perform a hardware reset of the radio.
Definition at line 878 of file sx1262.c.
References g_txDoneFlag, K_SPP_ERROR, mailboxCount, mailboxHead, mailboxTail, s_sx1262Ctx, SX1262_Timeout_Sequence(), SX1262_TX_STATE_IDLE, and SX1262_Ctx_t::tx_state.
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_Timeout_Sequence().
|
static |
Reads the radio IRQ status register.
Used to distinguish successful transmission completion from timeout or unexpected interrupts.
| p_handle | SPI device handle. |
| p_irqStatus | Output pointer for the 16-bit IRQ flags. |
Definition at line 769 of file sx1262.c.
References K_SPP_ERROR_NULL_POINTER, K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_GetIrqStatus(), SX1262_OPCODE_GET_IRQ_STATUS, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_GetIrqStatus().
|
static |
Definition at line 465 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_REGULATOR_MODE, SX1262_REGULATOR_DC_DC, SX1262_SetRegulatorMode(), and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetRegulatorMode().
|
static |
Definition at line 481 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_OPCODE_SET_DIO3_AS_TCXO_CTRL, SX1262_SetDio3AsTcxoCtrl(), SX1262_TCXO_STARTUP_DELAY, SX1262_TCXO_VOLTAGE_1V7, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_SetDio3AsTcxoCtrl().
|
static |
Definition at line 515 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_Calibrate(), SX1262_CALIBRATE_ALL, SX1262_OPCODE_CALIBRATE, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_Calibrate().
|
static |
Definition at line 502 of file sx1262.c.
References K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_ClearDeviceErrors(), SX1262_OPCODE_CLEAR_DEVICE_ERRORS, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_ClearDeviceErrors().
|
static |
Definition at line 544 of file sx1262.c.
References K_SPP_ERROR_NULL_POINTER, K_SPP_OK, SPP_HAL_SPI_transmitRaw(), SX1262_GetDeviceErrors(), SX1262_OPCODE_GET_DEVICE_ERRORS, and SX1262_WaitBusy().
Referenced by SPP_SERVICES_SX1262_init(), and SX1262_GetDeviceErrors().
| const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_SX1262_getConsumerContract | ( | void | ) |
Returns the SX1262 consumer contract for PUBSUB registration.
Definition at line 80 of file sx1262.c.
References SPP_SERVICES_SX1262_getConsumerContract(), and sx1262Contract.
Referenced by CUSTOM_registerConsumerProducer(), guard_startInitializationOfModules(), and SPP_SERVICES_SX1262_getConsumerContract().
|
static |
Definition at line 17 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_consumeData(), SPP_SERVICES_SX1262_init(), and SX1262_Timeout_Sequence().
|
static |
Definition at line 27 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_consumeData(), and SPP_SERVICES_SX1262_deliverToMailbox().
|
static |
Definition at line 28 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_consumeData(), SPP_SERVICES_SX1262_deliverToMailbox(), and SX1262_Timeout_Sequence().
|
static |
Definition at line 29 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_deliverToMailbox(), and SX1262_Timeout_Sequence().
|
static |
Definition at line 30 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_consumeData(), SPP_SERVICES_SX1262_deliverToMailbox(), and SX1262_Timeout_Sequence().
| volatile spp_bool_t g_txDoneFlag = false |
Definition at line 33 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_consumeData(), and SX1262_Timeout_Sequence().
| SPP_GpioIsrCtx_t g_dio1Ctx = {.p_flag = &g_txDoneFlag} |
Definition at line 34 of file sx1262.c.
Referenced by SX1262_InitInterrupts().
|
static |
Definition at line 68 of file sx1262.c.
Referenced by SPP_SERVICES_SX1262_getConsumerContract().