EFM32 Pearl Gecko 12 Software Documentation  efm32pg12-doc-5.1.2
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  (void)handle;
84 
85  /* Initialize radio GPIOs and SPI port */
86 #if defined( EZRADIO_PLUGIN_PTI )
87  ezradio_hal_GpioInit( GPIO_EZRadio_INT_IRQHandler, true );
88 #else
89  ezradio_hal_GpioInit( GPIO_EZRadio_INT_IRQHandler, false );
90 #endif
92 
93  /* Power Up the radio chip */
94  ezradioPowerUp();
95 
96  /* Load radio configuration */
97  while (EZRADIO_CONFIG_SUCCESS != ezradio_configuration_init(Radio_Configuration_Data_Array))
98  {
99  /* Error hook */
100 #ifdef ERROR_HOOK
101  ERROR_HOOK;
102 #else
103  printf("ERROR: Radio configuration failed!\n");
104 #endif
105 
106  USTIMER_Init();
107  /* Delay for 10ms time */
108  USTIMER_Delay( 10000u );
109  /* Deinit ustimer */
110  USTIMER_DeInit();
111 
112  /* Power Up the radio chip */
113  ezradioPowerUp();
114  }
115 
116  /* Read ITs, clear pending ones */
117  ezradio_get_int_status(0u, 0u, 0u, NULL);
118 
119 }
120 
121 /**************************************************************************/
129 {
130  /* EZRadio response structure union */
131  ezradio_cmd_reply_t radioReplyData;
132  EZRADIODRV_ReplyHandle_t radioReplyHandle = &radioReplyData;
133 
134  if ( radioHandle == NULL )
135  {
137  }
138 
139  /* Check is radio interrupt is received. */
140  if (ezradioIrqReceived)
141  {
142  /* Accept interrupt before clearing IT in the radio, so prevent race conditions. */
143  ezradioIrqReceived = false;
144 
145  /* Read ITs, clear all pending ones */
146  ezradio_get_int_status(0x0, 0x0, 0x0, radioReplyHandle);
147 
148 #if defined( EZRADIO_PLUGIN_TRANSMIT )
149  ezradioHandleTransmitPlugin( radioHandle, radioReplyHandle );
150 #endif
151 
152 #if defined( EZRADIO_PLUGIN_RECEIVE )
153  ezradioHandleReceivePlugin( radioHandle, radioReplyHandle );
154 #endif
155 
156 #if defined( EZRADIO_PLUGIN_CRC_ERROR )
157  ezradioHandleCrcErrorPlugin( radioHandle, radioReplyHandle );
158 #endif
159 
160  }
161 
163 }
164 
165 /**************************************************************************/
169 {
170 #if defined( EZRADIO_PLUGIN_RECEIVE )
171  ezradio_fifo_info(EZRADIO_CMD_FIFO_INFO_ARG_FIFO_RX_BIT, NULL);
172 #endif //#if defined( EZRADIO_PLUGIN_RECEIVE )
173 
174 #if defined( EZRADIO_PLUGIN_TRANSMIT )
175  ezradio_fifo_info(EZRADIO_CMD_FIFO_INFO_ARG_FIFO_TX_BIT, NULL);
176 #endif //#if defined( EZRADIO_PLUGIN_TRANSMIT )
177 }
178 
180 
181 /**************************************************************************/
184 static void ezradioPowerUp(void)
185 {
186  /* Hardware reset the chip */
187  ezradio_reset();
188 
189  /* Initialize ustimer */
190  USTIMER_Init();
191  /* Delay for preconfigured time */
192  USTIMER_Delay( RADIO_CONFIG_DATA_RADIO_DELAY_AFTER_RESET_US );
193  /* Deinit ustimer */
194  USTIMER_DeInit();
195 }
196 
197 /**************************************************************************/
200 static void GPIO_EZRadio_INT_IRQHandler( uint8_t pin )
201 {
202  (void)pin;
203 
204  /* Sign radio interrupt received */
205  ezradioIrqReceived = true;
206 }
207 
209 
210 /******** 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:126
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:66
Ecode_t USTIMER_Init(void)
Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.
Definition: ustimer.c:139
This file contains EZRadio HAL.
void ezradio_fifo_info(uint8_t fifo, ezradio_cmd_reply_t *ezradioReply)
General Purpose IO (GPIO) peripheral API.
uint32_t Ecode_t
Typedef for API function error code return values.
Definition: ecode.h:51
EZRADIO_ConfigRet_t ezradio_configuration_init(const uint8_t *pSetPropCmd)
Ecode_t USTIMER_DeInit(void)
Deinitialize USTIMER driver.
Definition: ustimer.c:190
#define ECODE_EMDRV_EZRADIODRV_ILLEGAL_HANDLE
Illegal SPI handle.
GPIOINT API definition.
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:221
Ecode_t ezradioPluginManager(EZRADIODRV_Handle_t radioHandle)
EzRadio plugin manager state machine handler. This function should be called in the application in an...