EFR32 Blue Gecko 1 Software Documentation  efr32bg1-doc-5.1.2
ezradio_api_lib_add.c
Go to the documentation of this file.
1 /***************************************************************************/
34 #include <stddef.h>
35 #include <stdint.h>
36 #include <stdarg.h>
37 #include "em_gpio.h"
38 #include "gpiointerrupt.h"
39 
40 #include "ezradio_cmd.h"
41 #include "ezradio_prop.h"
42 #include "ezradio_hal.h"
43 #include "ezradio_comm.h"
44 #include "ezradio_api_lib.h"
45 #include "ezradio_api_lib_add.h"
46 
54 {
55  /* EZRadio command buffer */
56  uint8_t ezradioCmd[16u];
57  ezradio_cmd_reply_t ezradioReply;
58 
59  uint8_t col;
60  uint8_t response;
61  uint8_t numOfBytes;
62 
63  /* While cycle as far as the pointer points to a command */
64  while (*pSetPropCmd != 0x00)
65  {
66  /* Commands structure in the array:
67  * --------------------------------
68  * LEN | <LEN length of data>
69  */
70 
71  numOfBytes = *pSetPropCmd++;
72 
73  if (numOfBytes > 16u)
74  {
75  /* Initial configuration of Si4x55 */
76  if ( EZRADIO_CMD_ID_EZCONFIG_ARRAY_WRITE == *pSetPropCmd )
77  {
78  if (numOfBytes > 128u)
79  {
80  /* Number of command bytes exceeds maximal allowable length */
82  }
83 
84  /* Load array to the device */
85  pSetPropCmd++;
86  ezradio_write_ezconfig_array( numOfBytes - 1, (uint8_t*) pSetPropCmd);
87 
88  /* Point to the next command */
89  pSetPropCmd += numOfBytes - 1;
90 
91  /* Continue command interpreter */
92  continue;
93 
94  }
95  else
96  {
97  /* Number of command bytes exceeds maximal allowable length */
99  }
100  }
101 
102  for (col = 0u; col < numOfBytes; col++)
103  {
104  ezradioCmd[col] = *pSetPropCmd;
105  pSetPropCmd++;
106  }
107 
108  if (ezradio_comm_SendCmdGetResp(numOfBytes, ezradioCmd, 1, &response) != 0xFF)
109  {
110  /* Timeout occured */
112  }
113 
114  /* Check response byte of EZCONFIG_CHECK command */
115  if ( EZRADIO_CMD_ID_EZCONFIG_CHECK == ezradioCmd[0] )
116  {
117  if (EZRADIO_CMD_EZCONFIG_CHECK_REP_RESULT_RESULT_ENUM_BAD_CHECKSUM == ezradioReply.EZCONFIG_CHECK.RESULT)
118  {
120  }
121  else if (EZRADIO_CMD_EZCONFIG_CHECK_REP_RESULT_RESULT_ENUM_INVALID_STATE == ezradioReply.EZCONFIG_CHECK.RESULT)
122  {
124  }
125  }
126 
127  if (ezradio_hal_NirqLevel() == 0)
128  {
129  /* Get and clear all interrupts. An error has occured... */
130  ezradio_get_int_status(0, 0, 0, &ezradioReply);
131  if (ezradioReply.GET_INT_STATUS.CHIP_PEND & EZRADIO_CMD_GET_CHIP_STATUS_REP_CHIP_PEND_CMD_ERROR_PEND_MASK)
132  {
134  }
135  }
136  }
137 
138  return EZRADIO_CONFIG_SUCCESS;
139 }
140 
141 
148 void ezradio_write_ezconfig_array(uint8_t numBytes, uint8_t* pEzConfigArray)
149 {
150  ezradio_comm_WriteData(EZRADIO_CMD_ID_EZCONFIG_ARRAY_WRITE, 1, numBytes, pEzConfigArray);
151 }
152 
159 void ezradio_ezconfig_check(uint16_t checksum, ezradio_cmd_reply_t *ezradioReply)
160 {
161  /* EZRadio command buffer */
162  uint8_t ezradioCmd[3u];
163 
164  ezradioCmd[0] = EZRADIO_CMD_ID_EZCONFIG_CHECK;
165  ezradioCmd[1] = (uint8_t) (checksum >> 8u);
166  ezradioCmd[2] = (uint8_t) (checksum & 0x00FF);
167 
168  /* Do not check CTS after sending the ezconfig array */
170 
171  ezradio_comm_SendCmdGetResp( EZRADIO_CMD_ARG_COUNT_EZCONFIG_CHECK,
172  ezradioCmd,
173  EZRADIO_CMD_REPLY_COUNT_EZCONFIG_CHECK,
174  ezradioCmd );
175 
176  if (ezradioReply != NULL)
177  {
178  ezradioReply->EZCONFIG_CHECK.RESULT = ezradioCmd[0];
179  }
180 }
181 
182 #ifdef EZRADIO_DRIVER_EXTENDED_SUPPORT
183 /* Extended driver support functions */
184 
185 #ifdef EZRADIO_DRIVER_FULL_SUPPORT
186 /* Full driver support functions */
187 
195 void ezradio_get_adc_reading( uint8_t adc_en, uint8_t adc_cfg, ezradio_cmd_reply_t *ezradioReply)
196 {
197  /* EZRadio command buffer */
198  uint8_t ezradioCmd[EZRADIO_CMD_REPLY_COUNT_GET_ADC_READING];
199 
200  ezradioCmd[0] = EZRADIO_CMD_ID_GET_ADC_READING;
201  ezradioCmd[1] = adc_en;
202  ezradioCmd[2] = adc_cfg;
203 
204  ezradio_comm_SendCmdGetResp( EZRADIO_CMD_ARG_COUNT_GET_ADC_READING,
205  ezradioCmd,
206  EZRADIO_CMD_REPLY_COUNT_GET_ADC_READING,
207  ezradioCmd );
208 
209  if (ezradioReply != NULL)
210  {
211  ezradioReply->GET_ADC_READING.GPIO_ADC = ((uint16_t)ezradioCmd[0] << 8) & 0xFF00;
212  ezradioReply->GET_ADC_READING.GPIO_ADC |= (uint16_t)ezradioCmd[1] & 0x00FF;
213  ezradioReply->GET_ADC_READING.BATTERY_ADC = ((uint16_t)ezradioCmd[2] << 8) & 0xFF00;
214  ezradioReply->GET_ADC_READING.BATTERY_ADC |= (uint16_t)ezradioCmd[3] & 0x00FF;
215  }
216 }
217 
218 #endif /* EZRADIO_DRIVER_FULL_SUPPORT */
219 
220 #endif /* EZRADIO_DRIVER_EXTENDED_SUPPORT */
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)
void ezradio_write_ezconfig_array(uint8_t numBytes, uint8_t *pEzConfigArray)
This file contains EZRadio HAL.
void ezradio_ezconfig_check(uint16_t checksum, ezradio_cmd_reply_t *ezradioReply)
General Purpose IO (GPIO) peripheral API.
EZRADIO_ConfigRet_t ezradio_configuration_init(const uint8_t *pSetPropCmd)
uint8_t ezradio_comm_SendCmdGetResp(uint8_t cmdByteCount, uint8_t *pCmdData, uint8_t respByteCount, uint8_t *pRespData)
Definition: ezradio_comm.c:293
void ezradio_comm_WriteData(uint8_t cmd, uint8_t pollCts, uint8_t byteCount, uint8_t *pData)
Definition: ezradio_comm.c:207
GPIOINT API definition.
uint8_t ezradio_hal_NirqLevel(void)
Definition: ezradio_hal.c:175
void ezradio_get_adc_reading(uint8_t adc_en, uint8_t adc_cfg, ezradio_cmd_reply_t *ezradioReply)
This file contains the EZRadio communication layer.
EZRADIO_ConfigRet_t
uint8_t ezradio_comm_CtsWentHigh
Definition: ezradio_comm.c:44