EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1
ezradio_plugin_manager.c
Go to the documentation of this file.
1 /***************************************************************************/
34 #include <stddef.h>
35 #include <stdio.h>
36 #include <stdbool.h>
37 
38 #include "em_gpio.h"
39 #include "gpiointerrupt.h"
40 #include "ustimer.h"
41 
42 #include "ezradio_cmd.h"
43 #include "ezradio_prop.h"
44 #include "ezradio_hal.h"
45 #include "ezradio_api_lib.h"
46 #include "ezradio_api_lib_add.h"
47 #include "ezradio_plugin_manager.h"
48 
50 
51 /* Radio configuration data array. */
52 static const uint8_t Radio_Configuration_Data_Array[] = \
53  RADIO_CONFIGURATION_DATA_ARRAY;
54 
55 /* Radio interrupt receive flag */
56 static bool ezradioIrqReceived = false;
57 
58 #if ( defined EZRADIO_PLUGIN_TRANSMIT )
59 Ecode_t ezradioHandleTransmitPlugin( EZRADIODRV_Handle_t radioHandle, EZRADIODRV_ReplyHandle_t radioReplyHandle );
60 #endif
61 
62 #if ( defined EZRADIO_PLUGIN_RECEIVE )
63 Ecode_t ezradioHandleReceivePlugin( EZRADIODRV_Handle_t radioHandle, EZRADIODRV_ReplyHandle_t radioReplyHandle );
64 #endif
65 
66 #if ( defined EZRADIO_PLUGIN_CRC_ERROR )
67 Ecode_t ezradioHandleCrcErrorPlugin( EZRADIODRV_Handle_t radioHandle, EZRADIODRV_ReplyHandle_t radioReplyHandle );
68 #endif
69 
70 static void ezradioPowerUp(void);
71 
72 static void GPIO_EZRadio_INT_IRQHandler( uint8_t pin );
73 
75 
76 /**************************************************************************/
82 {
83  uint16_t wDelay;
84 
85  (void)handle;
86 
87  /* Initialize radio GPIOs and SPI port */
88 #if ( defined EZRADIO_PLUGIN_PTI )
89  ezradio_hal_GpioInit( GPIO_EZRadio_INT_IRQHandler, true );
90 #else
91  ezradio_hal_GpioInit( GPIO_EZRadio_INT_IRQHandler, false );
92 #endif
94 
95  /* Power Up the radio chip */
96  ezradioPowerUp();
97 
98  /* Load radio configuration */
99  while (EZRADIO_CONFIG_SUCCESS != ezradio_configuration_init(Radio_Configuration_Data_Array))
100  {
101  /* Error hook */
102 #ifdef ERROR_HOOK
103  ERROR_HOOK;
104 #else
105  printf("ERROR: Radio configuration failed!\n");
106 #endif
107  for (wDelay = 0x7FFF; wDelay--; ) ;
108 
109  /* Power Up the radio chip */
110  ezradioPowerUp();
111  }
112 
113  /* Read ITs, clear pending ones */
114  ezradio_get_int_status(0u, 0u, 0u, NULL);
115 
116 }
117 
118 /**************************************************************************/
126 {
127  /* EZRadio response structure union */
128  ezradio_cmd_reply_t radioReplyData;
129  EZRADIODRV_ReplyHandle_t radioReplyHandle = &radioReplyData;
130 
131  if ( radioHandle == NULL )
132  {
134  }
135 
136  /* Check is radio interrupt is received. */
137  if (ezradioIrqReceived)
138  {
139  /* Accept interrupt before clearing IT in the radio, so prevent race conditions. */
140  ezradioIrqReceived = false;
141 
142  /* Read ITs, clear all pending ones */
143  ezradio_get_int_status(0x0, 0x0, 0x0, radioReplyHandle);
144 
145 #if ( defined EZRADIO_PLUGIN_TRANSMIT )
146  ezradioHandleTransmitPlugin( radioHandle, radioReplyHandle );
147 #endif
148 
149 #if ( defined EZRADIO_PLUGIN_RECEIVE )
150  ezradioHandleReceivePlugin( radioHandle, radioReplyHandle );
151 #endif
152 
153 #if ( defined EZRADIO_PLUGIN_CRC_ERROR )
154  ezradioHandleCrcErrorPlugin( radioHandle, radioReplyHandle );
155 #endif
156 
157  }
158 
160 }
161 
162 /**************************************************************************/
166 {
167 #if ( defined EZRADIO_PLUGIN_RECEIVE )
168  ezradio_fifo_info(EZRADIO_CMD_FIFO_INFO_ARG_FIFO_RX_BIT, NULL);
169 #endif //#if ( defined EZRADIO_PLUGIN_RECEIVE )
170 
171 #if ( defined EZRADIO_PLUGIN_TRANSMIT )
172  ezradio_fifo_info(EZRADIO_CMD_FIFO_INFO_ARG_FIFO_TX_BIT, NULL);
173 #endif //#if ( defined EZRADIO_PLUGIN_TRANSMIT )
174 }
175 
177 
178 /**************************************************************************/
181 static void ezradioPowerUp(void)
182 {
183  /* Hardware reset the chip */
184  ezradio_reset();
185 
186  /* Initialize ustimer */
187  USTIMER_Init();
188  /* Delay for preconfigured time */
189  USTIMER_Delay( RADIO_CONFIG_DATA_RADIO_DELAY_AFTER_RESET_US );
190  /* Deinit ustimer */
191  USTIMER_DeInit();
192 }
193 
194 /**************************************************************************/
197 static void GPIO_EZRadio_INT_IRQHandler( uint8_t pin )
198 {
199  (void)pin;
200 
201  /* Sign radio interrupt received */
202  ezradioIrqReceived = true;
203 }
204 
206 
207 /******** THE REST OF THE FILE IS DOCUMENTATION ONLY !**********************/
void ezradioResetTRxFifo(void)
Resets both the TX and RX FIFOs.
void ezradioInit(EZRADIODRV_Handle_t handle)
Radio Initialization.
#define ECODE_EMDRV_EZRADIODRV_OK
Success return value.
void ezradio_hal_SpiInit(void)
Definition: ezradio_hal.c:117
This file contains the common API library of the EZRadio and EZRadioPRO families. ...
void ezradio_get_int_status(uint8_t ph_clr_pend, uint8_t modem_clr_pend, uint8_t chip_clr_pend, ezradio_cmd_reply_t *ezradioReply)
This file contains the plug-in manager for the EZRadio and EZRadioPRO chip families.
void ezradio_hal_GpioInit(GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI)
Definition: ezradio_hal.c:63
Ecode_t USTIMER_Init(void)
Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.
Definition: ustimer.c:86
This file contains EZRadio HAL.
void ezradio_fifo_info(uint8_t fifo, ezradio_cmd_reply_t *ezradioReply)
General Purpose IO (GPIO) peripheral API.
EZRADIO_ConfigRet_t ezradio_configuration_init(const uint8_t *pSetPropCmd)
Ecode_t USTIMER_DeInit(void)
Deinitialize USTIMER driver.
Definition: ustimer.c:137
#define ECODE_EMDRV_EZRADIODRV_ILLEGAL_HANDLE
Illegal SPI handle.
GPIOINT API definition.
uint32_t Ecode_t
Typedef for API function errorcode return values.
Definition: ecode.h:31
Microsecond delay function API definition.
ezradio_cmd_reply_t * EZRADIODRV_ReplyHandle_t
EZradio reply union handle.
void ezradio_reset(void)
Ecode_t USTIMER_Delay(uint32_t usec)
Delay a given number of microseconds.
Definition: ustimer.c:168
Ecode_t ezradioPluginManager(EZRADIODRV_Handle_t radioHandle)
EzRadio plugin manager state machine handler. This function should be called in the application in an...