nmdrv.c
Go to the documentation of this file.
1 
36 #include "driver/source/nmbus.h"
37 #include "bsp/include/nm_bsp.h"
38 #include "driver/source/nmdrv.h"
39 #include "driver/source/nmasic.h"
41 
42 #ifdef CONF_WINC_USE_SPI
43 #include "driver/source/nmspi.h"
44 #endif
45 
55 sint8 nm_get_hif_info(uint16 *pu16FwHifInfo, uint16 *pu16OtaHifInfo)
56 {
57  sint8 ret = M2M_SUCCESS;
58  uint32 reg = 0;
59 
60  ret = nm_read_reg_with_ret(NMI_REV_REG, &reg);
61  if(ret == M2M_SUCCESS)
62  {
63  if(pu16FwHifInfo != NULL)
64  {
65  *pu16FwHifInfo = (uint16)reg;
66  }
67  if(pu16OtaHifInfo)
68  {
69  *pu16OtaHifInfo = (uint16)(reg>>16);
70  }
71  }
72  return ret;
73 }
82 {
83  uint16 fw_hif_info = 0;
84  uint32 reg = 0;
85  sint8 ret = M2M_SUCCESS;
86  tstrGpRegs strgp = {0};
87 
88  m2m_memset((uint8*)pstrRev,0,sizeof(tstrM2mRev));
89  nm_get_hif_info(&fw_hif_info, NULL);
90 
91  M2M_INFO("Fw HIF: %04x\n", fw_hif_info);
92  if(M2M_GET_HIF_BLOCK(fw_hif_info) == M2M_HIF_BLOCK_VALUE)
93  {
95  if(ret == M2M_SUCCESS)
96  {
97  if(reg != 0)
98  {
99  ret = nm_read_block(reg|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs));
100  if(ret == M2M_SUCCESS)
101  {
102  reg = strgp.u32Firmware_Ota_rev;
103  reg &= 0x0000ffff;
104  if(reg != 0)
105  {
106  ret = nm_read_block(reg|0x30000,(uint8*)pstrRev,sizeof(tstrM2mRev));
107  if(ret == M2M_SUCCESS)
108  {
109  M2M_INFO("Firmware HIF (%u) : %u.%u \n", M2M_GET_HIF_BLOCK(pstrRev->u16FirmwareHifInfo), M2M_GET_HIF_MAJOR(pstrRev->u16FirmwareHifInfo), M2M_GET_HIF_MINOR(pstrRev->u16FirmwareHifInfo));
110  M2M_INFO("Firmware ver : %u.%u.%u \n", pstrRev->u8FirmwareMajor, pstrRev->u8FirmwareMinor, pstrRev->u8FirmwarePatch);
111  M2M_INFO("Firmware Build %s Time %s\n", pstrRev->BuildDate, pstrRev->BuildTime);
112 
113  /* Check Hif info is consistent */
114  if(fw_hif_info != pstrRev->u16FirmwareHifInfo)
115  {
116  ret = M2M_ERR_FAIL;
117  M2M_ERR("Inconsistent Firmware Version\n");
118  }
119  }
120  }
121  else
122  {
123  ret = M2M_ERR_FAIL;
124  }
125  }
126  }
127  else
128  {
129  ret = M2M_ERR_FAIL;
130  }
131  }
132  }
133  else
134  {
135  ret = M2M_ERR_FAIL;
136  }
137  if(ret != M2M_SUCCESS)
138  {
139  M2M_ERR("Unknown Firmware Version\n");
140  }
141  return ret;
142 }
152 {
153  uint16 ota_hif_info = 0;
154  uint32 reg = 0;
155  sint8 ret = M2M_SUCCESS;
156  tstrGpRegs strgp = {0};
157 
158  m2m_memset((uint8*)pstrRev,0,sizeof(tstrM2mRev));
159  nm_get_hif_info(NULL, &ota_hif_info);
160 
161  M2M_INFO("Ota HIF: %04x\n", ota_hif_info);
162  if(M2M_GET_HIF_BLOCK(ota_hif_info) == M2M_HIF_BLOCK_VALUE)
163  {
164  ret = nm_read_reg_with_ret(rNMI_GP_REG_0, &reg);
165  if(ret == M2M_SUCCESS)
166  {
167  if(reg != 0)
168  {
169  ret = nm_read_block(reg|0x30000,(uint8*)&strgp,sizeof(tstrGpRegs));
170  if(ret == M2M_SUCCESS)
171  {
172  reg = strgp.u32Firmware_Ota_rev;
173  reg >>= 16;
174  if(reg != 0)
175  {
176  ret = nm_read_block(reg|0x30000,(uint8*)pstrRev,sizeof(tstrM2mRev));
177  if(ret == M2M_SUCCESS)
178  {
179  M2M_INFO("OTA HIF (%u) : %u.%u \n", M2M_GET_HIF_BLOCK(pstrRev->u16FirmwareHifInfo), M2M_GET_HIF_MAJOR(pstrRev->u16FirmwareHifInfo), M2M_GET_HIF_MINOR(pstrRev->u16FirmwareHifInfo));
180  M2M_INFO("OTA ver : %u.%u.%u \n", pstrRev->u8FirmwareMajor, pstrRev->u8FirmwareMinor, pstrRev->u8FirmwarePatch);
181  M2M_INFO("OTA Build %s Time %s\n", pstrRev->BuildDate, pstrRev->BuildTime);
182 
183  /* Check Hif info is consistent */
184  if(ota_hif_info != pstrRev->u16FirmwareHifInfo)
185  {
186  ret = M2M_ERR_FAIL;
187  M2M_ERR("Inconsistent OTA Version\n");
188  }
189  }
190  }
191  else
192  {
193  ret = M2M_ERR_FAIL;
194  }
195  }
196  }
197  else
198  {
199  ret = M2M_ERR_FAIL;
200  }
201  }
202  }
203  else
204  {
205  ret = M2M_ERR_FAIL;
206  }
207  if(ret != M2M_SUCCESS)
208  {
209  M2M_INFO("No valid Ota image\n");
210  }
211  return ret;
212 }
213 
214 /*
215 * @fn nm_drv_init_download_mode
216 * @brief Initialize NMC1000 driver
217 * @return M2M_SUCCESS in case of success and Negative error code in case of failure
218 * @param [in] arg
219 * Generic argument
220 * @author Viswanathan Murugesan
221 * @date 10 Oct 2014
222 * @version 1.0
223 */
225 {
226  sint8 ret = M2M_SUCCESS;
227 
228  ret = nm_bus_iface_init(NULL, req_serial_number);
229  if (M2M_SUCCESS != ret) {
230  M2M_ERR("[nmi start]: fail init bus\n");
231  goto ERR1;
232  }
233 
234 
235 #ifdef CONF_WINC_USE_SPI
236  /* Must do this after global reset to set SPI data packet size. */
237  nm_spi_init();
238 #endif
239 
240  M2M_INFO("Chip ID %lx\n", nmi_get_chipid());
241 
242  /*disable all interrupt in ROM (to disable uart) in 2b0 chip*/
243  nm_write_reg(0x20300,0);
244 
245 ERR1:
246  return ret;
247 }
248 
249 sint8 nm_drv_init_hold(uint32 req_serial_number)
250 {
251  sint8 ret = M2M_SUCCESS;
252 
253  ret = nm_bus_iface_init(NULL, req_serial_number);
254  if (M2M_SUCCESS != ret) {
255  M2M_ERR("[nmi start]: fail init bus\n");
256  goto ERR1;
257  }
258 
259 #ifdef BUS_ONLY
260  return;
261 #endif
262 
263  ret = chip_wake();
264  nm_bsp_sleep(10);
265  if (M2M_SUCCESS != ret) {
266  M2M_ERR("[nmi start]: fail chip_wakeup\n");
267  goto ERR2;
268  }
272  ret = chip_reset();
273  if (M2M_SUCCESS != ret) {
274  goto ERR2;
275  }
276  M2M_INFO("Chip ID %lx\n", nmi_get_chipid());
277 #ifdef CONF_WINC_USE_SPI
278  /* Must do this after global reset to set SPI data packet size. */
279  nm_spi_init();
280 #endif
281  /*return power save to default value*/
282  chip_idle();
283 
284  return ret;
285 ERR2:
287 ERR1:
288  return ret;
289 }
290 
292 {
293  sint8 ret = M2M_SUCCESS;
294  uint8 u8Mode = M2M_WIFI_MODE_NORMAL;
295 
296  if(NULL != arg) {
297  if(M2M_WIFI_MODE_CONFIG == *((uint8 *)arg)) {
298  u8Mode = M2M_WIFI_MODE_CONFIG;
299  } else {
300  /*continue running*/
301  }
302  } else {
303  /*continue running*/
304  }
305 
306  ret = cpu_start();
307  if (M2M_SUCCESS != ret) {
308  goto ERR2;
309  }
310  ret = wait_for_bootrom(u8Mode);
311  if (M2M_SUCCESS != ret) {
312  goto ERR2;
313  }
314 
315  ret = wait_for_firmware_start(u8Mode);
316  if (M2M_SUCCESS != ret) {
317  goto ERR2;
318  }
319 
320  if(M2M_WIFI_MODE_CONFIG == u8Mode) {
321  goto ERR1;
322  } else {
323  /*continue running*/
324  }
325 
326  ret = enable_interrupts();
327  if (M2M_SUCCESS != ret) {
328  M2M_ERR("failed to enable interrupts..\n");
329  goto ERR2;
330  }
331 
332  return ret;
333 ERR2:
335 #ifdef CONF_WINC_USE_SPI
336  nm_spi_deinit();
337 #endif
338 ERR1:
339  return ret;
340 }
341 
342 /*
343 * @fn nm_drv_init
344 * @brief Initialize NMC1000 driver
345 * @return M2M_SUCCESS in case of success and Negative error code in case of failure
346 * @param [in] arg - Generic argument passed on to nm_drv_init_start
347 * @author M. Abdelmawla
348 * @date 15 July 2012
349 * @version 1.0
350 */
351 sint8 nm_drv_init(void * arg, uint32 req_serial_number)
352 {
353  sint8 ret = M2M_SUCCESS;
354 
355  ret = nm_drv_init_hold(req_serial_number);
356 
357  if(ret == M2M_SUCCESS)
358  ret = nm_drv_init_start(arg);
359 
360  return ret;
361 }
362 
363 /*
364 * @fn nm_drv_deinit
365 * @brief Deinitialize NMC1000 driver
366 * @author M. Abdelmawla
367 * @date 17 July 2012
368 * @version 1.0
369 */
370 sint8 nm_drv_deinit(void * arg)
371 {
372  sint8 ret;
373 
374  ret = chip_deinit();
375  if (M2M_SUCCESS != ret) {
376  M2M_ERR("[nmi stop]: chip_deinit fail\n");
377  goto ERR1;
378  }
379 
380  ret = nm_bus_iface_deinit();
381  if (M2M_SUCCESS != ret) {
382  M2M_ERR("[nmi stop]: fail init bus\n");
383  goto ERR1;
384  }
385 #ifdef CONF_WINC_USE_SPI
386  /* Must do this after global reset to set SPI data packet size. */
387  nm_spi_deinit();
388 #endif
389 
390 ERR1:
391  return ret;
392 }
393 
394 
402 {
403  sint8 ret;
404 
405  ret = cpu_start();
406  return ret;
407 }
sint8 enable_interrupts(void)
Definition: nmasic.c:213
sint8 nm_drv_init_download_mode(uint32 req_serial_number)
Definition: nmdrv.c:224
sint8 nm_drv_init_hold(uint32 req_serial_number)
Definition: nmdrv.c:249
#define M2M_ERR_FAIL
Definition: nm_common.h:63
sint8 nm_get_firmware_full_info(tstrM2mRev *pstrRev)
Get Firmware version info.
Definition: nmdrv.c:81
sint8 nm_read_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz)
Definition: nmbus.c:195
This module contains common APIs declarations.
sint8 nm_get_hif_info(uint16 *pu16FwHifInfo, uint16 *pu16OtaHifInfo)
Get Hif info of images in both partitions (Firmware and Ota).
Definition: nmdrv.c:55
#define M2M_HIF_BLOCK_VALUE
Definition: m2m_types.h:133
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
#define M2M_GET_HIF_MINOR(hif_info)
Definition: m2m_types.h:123
sint8 nm_read_reg_with_ret(uint32 u32Addr, uint32 *pu32RetVal)
Definition: nmbus.c:130
This module contains WINC3400 M2M driver APIs declarations.
sint8 chip_wake(void)
Definition: nmasic.c:405
#define M2M_GET_HIF_MAJOR(hif_info)
Definition: m2m_types.h:122
#define M2M_SUCCESS
Definition: nm_common.h:51
WINC3400 IoT Application Interface Internal Types.
#define NULL
Definition: nm_bsp.h:52
sint8 nm_bus_iface_deinit(void)
Deinitialize bus interface.
Definition: nmbus.c:67
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
sint8 wait_for_bootrom(uint8 arg)
Definition: nmasic.c:469
This module contains WINC3400 ASIC specific internal APIs.
void nm_bsp_sleep(uint32 u32TimeMsec)
sint8 nm_get_ota_firmware_info(tstrM2mRev *pstrRev)
Get Firmware version info.
Definition: nmdrv.c:151
NMI_API void m2m_memset(uint8 *pBuf, uint8 val, uint32 sz)
Set specified number of data bytes in specified data buffer to specified value.
Definition: nm_common.c:58
sint8 chip_reset(void)
Definition: nmasic.c:450
sint8 nm_write_reg(uint32 u32Addr, uint32 u32Val)
Definition: nmbus.c:155
#define M2M_ERR(...)
Definition: nm_debug.h:80
sint8 nm_cpu_start(void)
Start CPU from the WINC module.
Definition: nmdrv.c:401
sint8 nm_spi_init(void)
Initialize the SPI.
void chip_idle(void)
Definition: nmasic.c:189
sint8 wait_for_firmware_start(uint8 arg)
Definition: nmasic.c:528
uint32 nmi_get_chipid(void)
Definition: nmasic.c:278
This module contains WINC3400 bus APIs implementation.
sint8 nm_drv_deinit(void *arg)
Definition: nmdrv.c:370
sint8 nm_drv_init(void *arg, uint32 req_serial_number)
Definition: nmdrv.c:351
#define M2M_INFO(...)
Definition: nm_debug.h:83
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
sint8 nm_drv_init_start(void *arg)
Definition: nmdrv.c:291
This module contains WINC3400 BSP APIs declarations.
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
#define NMI_REV_REG
Definition: nmasic.h:47
sint8 cpu_start(void)
Definition: nmasic.c:244
This module contains WINC3400 SPI protocol bus APIs implementation.
sint8 nm_spi_deinit(void)
DeInitialize the SPI.
sint8 chip_deinit(void)
Definition: nmasic.c:566
#define M2M_GET_HIF_BLOCK(hif_info)
Definition: m2m_types.h:120
Structure holding firmware version parameters and build date/time.
Definition: nmdrv.h:44
sint8 nm_bus_iface_init(uint8 *pvInitVal, uint32 req_serial_number)
Definition: nmbus.c:51
#define rNMI_GP_REG_0
Definition: nmasic.h:41


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58