nmbus.c
Go to the documentation of this file.
1 
34 #ifndef CORTUS_APP
35 
36 #include "nmbus.h"
37 #include "nmi2c.h"
38 #include "nmspi.h"
39 #include "nmuart.h"
40 
41 #define MAX_TRX_CFG_SZ 8
42 
51 sint8 nm_bus_iface_init(uint8 *pvInitVal, uint32 req_serial_number)
52 {
53  sint8 ret = M2M_SUCCESS;
54  ret = nm_bus_init(pvInitVal, req_serial_number);
55 
56  return ret;
57 }
58 
68 {
69  sint8 ret = M2M_SUCCESS;
70  ret = nm_bus_deinit();
71 
72  return ret;
73 }
74 
84 {
85  sint8 ret = M2M_SUCCESS;
86 #ifdef CONF_WINC_USE_UART
87  if(ptr)
88  ret = nm_uart_reconfigure(ptr);
89  else
90  ret = M2M_ERR_BUS_FAIL;
91 #endif
92  return ret;
93 }
94 /*
95 * @fn nm_read_reg
96 * @brief Read register
97 * @param [in] u32Addr
98 * Register address
99 * @return Register value
100 * @author M. Abdelmawla
101 * @date 11 July 2012
102 * @version 1.0
103 */
105 {
106 #ifdef CONF_WINC_USE_UART
107  return nm_uart_read_reg(u32Addr);
108 #elif defined (CONF_WINC_USE_SPI)
109  return nm_spi_read_reg(u32Addr);
110 #elif defined (CONF_WINC_USE_I2C)
111  return nm_i2c_read_reg(u32Addr);
112 #else
113 #error "Plesae define bus usage"
114 #endif
115 
116 }
117 
118 /*
119 * @fn nm_read_reg_with_ret
120 * @brief Read register with error code return
121 * @param [in] u32Addr
122 * Register address
123 * @param [out] pu32RetVal
124 * Pointer to u32 variable used to return the read value
125 * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
126 * @author M. Abdelmawla
127 * @date 11 July 2012
128 * @version 1.0
129 */
131 {
132 #ifdef CONF_WINC_USE_UART
133  return nm_uart_read_reg_with_ret(u32Addr,pu32RetVal);
134 #elif defined (CONF_WINC_USE_SPI)
135  return nm_spi_read_reg_with_ret(u32Addr,pu32RetVal);
136 #elif defined (CONF_WINC_USE_I2C)
137  return nm_i2c_read_reg_with_ret(u32Addr,pu32RetVal);
138 #else
139 #error "Plesae define bus usage"
140 #endif
141 }
142 
143 /*
144 * @fn nm_write_reg
145 * @brief write register
146 * @param [in] u32Addr
147 * Register address
148 * @param [in] u32Val
149 * Value to be written to the register
150 * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
151 * @author M. Abdelmawla
152 * @date 11 July 2012
153 * @version 1.0
154 */
155 sint8 nm_write_reg(uint32 u32Addr, uint32 u32Val)
156 {
157 #ifdef CONF_WINC_USE_UART
158  return nm_uart_write_reg(u32Addr,u32Val);
159 #elif defined (CONF_WINC_USE_SPI)
160  return nm_spi_write_reg(u32Addr,u32Val);
161 #elif defined (CONF_WINC_USE_I2C)
162  return nm_i2c_write_reg(u32Addr,u32Val);
163 #else
164 #error "Plesae define bus usage"
165 #endif
166 }
167 
168 static inline sint8 p_nm_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
169 {
170 #ifdef CONF_WINC_USE_UART
171  return nm_uart_read_block(u32Addr,puBuf,u16Sz);
172 #elif defined (CONF_WINC_USE_SPI)
173  return nm_spi_read_block(u32Addr,puBuf,u16Sz);
174 #elif defined (CONF_WINC_USE_I2C)
175  return nm_i2c_read_block(u32Addr,puBuf,u16Sz);
176 #else
177 #error "Plesae define bus usage"
178 #endif
179 
180 }
181 /*
182 * @fn nm_read_block
183 * @brief Read block of data
184 * @param [in] u32Addr
185 * Start address
186 * @param [out] puBuf
187 * Pointer to a buffer used to return the read data
188 * @param [in] u32Sz
189 * Number of bytes to read. The buffer size must be >= u32Sz
190 * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure
191 * @author M. Abdelmawla
192 * @date 11 July 2012
193 * @version 1.0
194 */
195 sint8 nm_read_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz)
196 {
198  uint32 off = 0;
199  sint8 s8Ret = M2M_SUCCESS;
200 
201  for(;;)
202  {
203  if(u32Sz <= u16MaxTrxSz)
204  {
205  s8Ret += p_nm_read_block(u32Addr, &puBuf[off], (uint16)u32Sz);
206  break;
207  }
208  else
209  {
210  s8Ret += p_nm_read_block(u32Addr, &puBuf[off], u16MaxTrxSz);
211  if(M2M_SUCCESS != s8Ret) break;
212  u32Sz -= u16MaxTrxSz;
213  off += u16MaxTrxSz;
214  u32Addr += u16MaxTrxSz;
215  }
216  }
217 
218  return s8Ret;
219 }
220 
221 static inline sint8 p_nm_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
222 {
223 #ifdef CONF_WINC_USE_UART
224  return nm_uart_write_block(u32Addr,puBuf,u16Sz);
225 #elif defined (CONF_WINC_USE_SPI)
226  return nm_spi_write_block(u32Addr,puBuf,u16Sz);
227 #elif defined (CONF_WINC_USE_I2C)
228  return nm_i2c_write_block(u32Addr,puBuf,u16Sz);
229 #else
230 #error "Plesae define bus usage"
231 #endif
232 
233 }
248 sint8 nm_write_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz)
249 {
251  uint32 off = 0;
252  sint8 s8Ret = M2M_SUCCESS;
253 
254  for(;;)
255  {
256  if(u32Sz <= u16MaxTrxSz)
257  {
258  s8Ret += p_nm_write_block(u32Addr, &puBuf[off], (uint16)u32Sz);
259  break;
260  }
261  else
262  {
263  s8Ret += p_nm_write_block(u32Addr, &puBuf[off], u16MaxTrxSz);
264  if(M2M_SUCCESS != s8Ret) break;
265  u32Sz -= u16MaxTrxSz;
266  off += u16MaxTrxSz;
267  u32Addr += u16MaxTrxSz;
268  }
269  }
270 
271  return s8Ret;
272 }
273 
274 #endif
275 
sint8 nm_read_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz)
Definition: nmbus.c:195
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
sint8 nm_spi_read_reg_with_ret(uint32 u32Addr, uint32 *pu32RetVal)
sint8 nm_read_reg_with_ret(uint32 u32Addr, uint32 *pu32RetVal)
Definition: nmbus.c:130
sint8 nm_write_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz)
Definition: nmbus.c:248
sint8 nm_i2c_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
sint8 nm_i2c_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
sint8 nm_uart_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
#define M2M_SUCCESS
Definition: nm_common.h:51
sint8 nm_uart_read_reg_with_ret(uint32 u32Addr, uint32 *pu32RetVal)
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 nm_i2c_write_reg(uint32 u32Addr, uint32 u32Val)
sint8 nm_bus_init(uint8 *req_com_port, uint32 req_serial_number)
sint8 nm_bus_iface_reconfigure(void *ptr)
Definition: nmbus.c:83
sint8 nm_uart_write_reg(uint32 u32Addr, uint32 u32Val)
static sint8 p_nm_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
Definition: nmbus.c:168
#define MAX_TRX_CFG_SZ
Definition: nmbus.c:41
sint8 nm_uart_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
sint8 nm_write_reg(uint32 u32Addr, uint32 u32Val)
Definition: nmbus.c:155
tstrNmBusCapabilities egstrNmBusCapabilities
sint8 nm_spi_write_reg(uint32 u32Addr, uint32 u32Val)
sint8 nm_uart_reconfigure(void *ptr)
sint8 nm_spi_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
static sint8 p_nm_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
Definition: nmbus.c:221
This module contains WINC3400 I2C protocol bus APIs implementation.
This module contains WINC3400 bus APIs implementation.
This module contains WINC3400 UART protocol bus APIs implementation.
uint32 nm_spi_read_reg(uint32 u32Addr)
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
sint8 nm_i2c_read_reg_with_ret(uint32 u32Addr, uint32 *pu32RetVal)
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
uint32 nm_uart_read_reg(uint32 u32Addr)
sint8 nm_spi_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz)
sint8 nm_bus_deinit(void)
De-initialize the bus wrapper.
uint32 nm_i2c_read_reg(uint32 u32Addr)
This module contains WINC3400 SPI protocol bus APIs implementation.
uint32 nm_read_reg(uint32 u32Addr)
Definition: nmbus.c:104
#define M2M_ERR_BUS_FAIL
Definition: nm_common.h:57
sint8 nm_bus_iface_init(uint8 *pvInitVal, uint32 req_serial_number)
Definition: nmbus.c:51


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