Microchip® Advanced Software Framework

radio_driver_hal.c File Reference

This is the Radio Driver HAL source file which contains LoRa-specific Radio Driver Hardware Abstract Layer.

Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "radio_driver_hal.h"
#include "board.h"
#include "spi.h"
#include "sys.h"
#include "pmm.h"

Macros

#define ENABLE_DIO0
 
#define ENABLE_DIO1
 
#define ENABLE_DIO2
 
#define RADIO_CLK_SRC   XTAL
 
#define RADIO_CLK_STABILITATION_DELAY   0
 
#define SX_RF_SPI_BAUDRATE   2000000
 

Functions

uint8_t HAL_DIO0PinValue (void)
 This function is used to read the status of DIO0 pin. More...
 
uint8_t HAL_DIO1PinValue (void)
 This function is used to read the status of DIO1 pin. More...
 
uint8_t HAL_DIO2PinValue (void)
 This function is used to read the status of DIO2 pin. More...
 
void HAL_DisableRFCtrl (RFCtrl1_t RFCtrl1, RFCtrl2_t RFCtrl2)
 This function Disables RF Control pins. More...
 
void HAL_DisbleDIO0Interrupt (void)
 This function is used to disable DIO0 interrupt. More...
 
void HAL_DisbleDIO1Interrupt (void)
 This function is used to disable DIO2 interrupt. More...
 
void HAL_DisbleDIO2Interrupt (void)
 This function is used to disable DIO2 interrupt. More...
 
void HAL_EnableDIO0Interrupt (void)
 This function is used to enable DIO0 interrupt. More...
 
void HAL_EnableDIO1Interrupt (void)
 This function is used to enable DIO1 interrupt. More...
 
void HAL_EnableDIO2Interrupt (void)
 This function is used to enable DIO2 interrupt. More...
 
void HAL_EnableRFCtrl (RFCtrl1_t RFCtrl1, RFCtrl2_t RFCtrl2)
 This function Enables RF Control pins. More...
 
RadioClockSources_t HAL_GetRadioClkSrc (void)
 This function gets the clock source of Radio defined by user. More...
 
uint8_t HAL_GetRadioClkStabilizationDelay (void)
 This function gets the time taken for the radio clock to stabilize. More...
 
void HAL_Radio_resources_init (void)
 This function is used to initialize the SPI Interface after PMM wakeup. More...
 
void HAL_RadioDeInit (void)
 This function is used to deinitialize the SPI Interface. More...
 
static void HAL_RadioDIO0Callback (void)
 
static void HAL_RadioDIO1Callback (void)
 
static void HAL_RadioDIO2Callback (void)
 
void HAL_RadioInit (void)
 This function is used to initialize the Radio Hardware The SPI interface,DIO and reset pins are initialized by this api. More...
 
static void HAL_RadioIOInit (void)
 
static void HAL_RadioSpiInit (void)
 
void HAL_RegisterDioInterruptHandler (uint8_t dioPin, DioInterruptHandler_t handler)
 This function sets the interrupt handler for given DIO interrupt. More...
 
static void HAL_ResetPinMakeInput (void)
 
static void HAL_ResetPinMakeOutput (void)
 
static void HAL_ResetPinOutputValue (uint8_t value)
 
static void HAL_SPICSAssert (void)
 
static void HAL_SPICSDeassert (void)
 
static uint8_t HAL_SPISend (uint8_t data)
 
void HAL_TCXOPowerOff (void)
 This function Powering off the TCXO oscillator. More...
 
void HAL_TCXOPowerOn (void)
 This function Powering up the TCXO oscillator. More...
 
uint8_t INTERRUPT_GetDioStatus (void)
 This function is used to get the interrupt status The interrupt status is cleared after calling this function. More...
 
uint8_t INTERRUPT_PeekDioStatus (void)
 This function is used to get the interrupt status The interrupt status is not cleared after calling this function. More...
 
void RADIO_FrameRead (uint8_t offset, uint8_t *buffer, uint8_t bufferLen)
 This function is used to read a stream of data from the Radio Frame buffer. More...
 
void RADIO_FrameWrite (uint8_t offset, uint8_t *buffer, uint8_t bufferLen)
 This function is used to write a stream of data into the Radio Frame buffer. More...
 
uint8_t RADIO_RegisterRead (uint8_t reg)
 This function is used to read a byte of data from the radio register. More...
 
void RADIO_RegisterWrite (uint8_t reg, uint8_t value)
 This function is used to write a byte of data to the radio register. More...
 
void RADIO_Reset (void)
 This function resets the Radio hardware by pulling the reset pin low. More...
 

Variables

static uint8_t dioStatus
 
static DioInterruptHandler_t interruptHandlerDio0 = NULL
 
static DioInterruptHandler_t interruptHandlerDio1 = NULL
 
static DioInterruptHandler_t interruptHandlerDio2 = NULL
 
static struct spi_module master
 
struct spi_slave_inst slave
 

#define ENABLE_DIO0
#define ENABLE_DIO1
#define ENABLE_DIO2
#define RADIO_CLK_SRC   XTAL

Referenced by HAL_GetRadioClkSrc().

#define RADIO_CLK_STABILITATION_DELAY   0
#define SX_RF_SPI_BAUDRATE   2000000

Referenced by HAL_RadioSpiInit().

uint8_t HAL_DIO0PinValue ( void  )

This function is used to read the status of DIO0 pin.

References port_pin_get_input_level().

uint8_t HAL_DIO1PinValue ( void  )

This function is used to read the status of DIO1 pin.

References port_pin_get_input_level().

uint8_t HAL_DIO2PinValue ( void  )

This function is used to read the status of DIO2 pin.

References port_pin_get_input_level().

void HAL_DisableRFCtrl ( RFCtrl1_t  RFCtrl1,
RFCtrl2_t  RFCtrl2 
)

This function Disables RF Control pins.

Parameters
[in]RFCtrl1RFO_LF = 0 RFO_HF = 1 PA_BOOST = 2
[in]RFCtrl2RX = 0 TX = 1
[out]None

References port_pin_set_output_level(), RFO_HF, and RX.

void HAL_DisbleDIO0Interrupt ( void  )

This function is used to disable DIO0 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_disable_callback().

void HAL_DisbleDIO1Interrupt ( void  )

This function is used to disable DIO2 interrupt.

This function is used to disable DIO1 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_disable_callback().

void HAL_DisbleDIO2Interrupt ( void  )

This function is used to disable DIO2 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_disable_callback().

void HAL_EnableDIO0Interrupt ( void  )

This function is used to enable DIO0 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_enable_callback().

void HAL_EnableDIO1Interrupt ( void  )

This function is used to enable DIO1 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_enable_callback().

void HAL_EnableDIO2Interrupt ( void  )

This function is used to enable DIO2 interrupt.

References EXTINT_CALLBACK_TYPE_DETECT, and extint_chan_enable_callback().

void HAL_EnableRFCtrl ( RFCtrl1_t  RFCtrl1,
RFCtrl2_t  RFCtrl2 
)

This function Enables RF Control pins.

Parameters
[in]RFCtrl1RFO_LF = 0 RFO_HF = 1 PA_BOOST = 2
[in]RFCtrl2RX = 0 TX = 1
[out]None

References PA_BOOST, port_pin_set_output_level(), RFO_HF, RX, and TX.

RadioClockSources_t HAL_GetRadioClkSrc ( void  )

This function gets the clock source of Radio defined by user.

Parameters
[in]None
[out]Typeof clock source TCXO or XTAL

References RADIO_CLK_SRC.

uint8_t HAL_GetRadioClkStabilizationDelay ( void  )

This function gets the time taken for the radio clock to stabilize.

Parameters
[in]None
[out]Timevalue in ms

References RADIO_CLK_STABILITATION_DELAY.

void HAL_Radio_resources_init ( void  )

This function is used to initialize the SPI Interface after PMM wakeup.

This function is used to initialize the Radio SPI after PMM wakeup.

References master, spi_enable(), and spi_is_syncing().

Referenced by appWakeup(), and processJoinAndSend().

void HAL_RadioDeInit ( void  )

This function is used to deinitialize the SPI Interface.

This function is used to deinitialize the Radio SPI.

References master, and spi_disable().

Referenced by app_resources_uninit().

static void HAL_RadioDIO0Callback ( void  )
static

References interruptHandlerDio0, and PMM_Wakeup().

Referenced by HAL_RadioIOInit().

static void HAL_RadioDIO1Callback ( void  )
static

References interruptHandlerDio1, and PMM_Wakeup().

Referenced by HAL_RadioIOInit().

static void HAL_RadioDIO2Callback ( void  )
static

References interruptHandlerDio2, and PMM_Wakeup().

Referenced by HAL_RadioIOInit().

void HAL_RadioInit ( void  )

This function is used to initialize the Radio Hardware The SPI interface,DIO and reset pins are initialized by this api.

References HAL_RadioIOInit(), and HAL_RadioSpiInit().

void HAL_RegisterDioInterruptHandler ( uint8_t  dioPin,
DioInterruptHandler_t  handler 
)

This function sets the interrupt handler for given DIO interrupt.

Parameters
[in]dioPin- DIO pin
[in]handler- function to be called upon given DIO interrupt

References DIO0, DIO1, DIO2, DIO3, DIO4, DIO5, interruptHandlerDio0, interruptHandlerDio1, and interruptHandlerDio2.

static void HAL_ResetPinMakeInput ( void  )
static
static void HAL_ResetPinMakeOutput ( void  )
static
static void HAL_ResetPinOutputValue ( uint8_t  value)
static

References port_pin_set_output_level().

Referenced by RADIO_Reset().

static void HAL_SPICSAssert ( void  )
static
static void HAL_SPICSDeassert ( void  )
static
void HAL_TCXOPowerOff ( void  )

This function Powering off the TCXO oscillator.

Parameters
[in]None
[out]None

References port_pin_set_output_level().

void HAL_TCXOPowerOn ( void  )

This function Powering up the TCXO oscillator.

Parameters
[in]None
[out]None

References delay_ms, port_pin_set_output_level(), and RADIO_CLK_STABILITATION_DELAY.

uint8_t INTERRUPT_GetDioStatus ( void  )

This function is used to get the interrupt status The interrupt status is cleared after calling this function.

Return values
Returnsthe mask of received interrupts

References dioStatus, INTERRUPT_GlobalInterruptDisable, and INTERRUPT_GlobalInterruptEnable.

uint8_t INTERRUPT_PeekDioStatus ( void  )

This function is used to get the interrupt status The interrupt status is not cleared after calling this function.

Return values
Returnsthe mask of received interrupts

References dioStatus.

void RADIO_FrameRead ( uint8_t  offset,
uint8_t *  buffer,
uint8_t  bufferLen 
)

This function is used to read a stream of data from the Radio Frame buffer.

Parameters
[in]FIFOoffset to be read from
[in]bufferPointer to the data where the data is read and stored
[in]bufferLenLength of the data to be read from the frame buffer

References HAL_SPICSAssert(), HAL_SPICSDeassert(), HAL_SPISend(), and i.

void RADIO_FrameWrite ( uint8_t  offset,
uint8_t *  buffer,
uint8_t  bufferLen 
)

This function is used to write a stream of data into the Radio Frame buffer.

Parameters
[in]FIFOoffset to be written to
[in]bufferPointer to the data to be written into the frame buffer
[in]bufferLenLength of the data to be written

References HAL_SPICSAssert(), HAL_SPICSDeassert(), HAL_SPISend(), i, and REG_WRITE_CMD.

uint8_t RADIO_RegisterRead ( uint8_t  reg)

This function is used to read a byte of data from the radio register.

Parameters
[in]regRadio register to be read
Return values
Valueread from the radio register

References HAL_SPICSAssert(), HAL_SPICSDeassert(), and HAL_SPISend().

Referenced by RADIO_FHSSChangeChannel(), Radio_ReadFSKRssi(), Radio_ReadLoraRssi(), RADIO_ReadRandom(), and Radio_WriteMode().

void RADIO_RegisterWrite ( uint8_t  reg,
uint8_t  value 
)

This function is used to write a byte of data to the radio register.

Parameters
[in]regRadio register to be written
[in]valueValue to be written into the radio register

References HAL_SPICSAssert(), HAL_SPICSDeassert(), HAL_SPISend(), and REG_WRITE_CMD.

Referenced by RADIO_FHSSChangeChannel(), RADIO_ReadRandom(), and Radio_WriteMode().

void RADIO_Reset ( void  )

This function resets the Radio hardware by pulling the reset pin low.

References HAL_ResetPinMakeInput(), HAL_ResetPinMakeOutput(), HAL_ResetPinOutputValue(), and SystemBlockingWaitMs().

uint8_t dioStatus
static
DioInterruptHandler_t interruptHandlerDio0 = NULL
static
DioInterruptHandler_t interruptHandlerDio1 = NULL
static
DioInterruptHandler_t interruptHandlerDio2 = NULL
static
struct spi_module master
static
struct spi_slave_inst slave