Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

318 wiersze
11 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC BSP API Declarations.
  6. *
  7. * Copyright (c) 2015 - 2018 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. /** \defgroup nm_bsp BSP
  42. */
  43. /**@defgroup BSPDefine Defines
  44. * @ingroup nm_bsp
  45. * @{
  46. */
  47. #ifndef _NM_BSP_H_
  48. #define _NM_BSP_H_
  49. #define NMI_API
  50. #include "winc1500_config.h"
  51. #include "math.h"
  52. #define NM_EDGE_INTERRUPT (1)
  53. #define NM_DEBUG CONF_WINC_DEBUG
  54. #define NM_BSP_PRINTF CONF_WINC_PRINTF
  55. /*!<
  56. * Attribute used to define memory section to map Functions in host memory.
  57. */
  58. #define CONST const
  59. /*!<
  60. * Used for code portability.
  61. */
  62. #ifndef NULL
  63. #define NULL ((void *)0)
  64. #endif
  65. /*!<
  66. * Void Pointer to '0' in case of NULL is not defined.
  67. */
  68. #define BSP_MIN(x, y) ((x) > (y) ? (y) : (x))
  69. /*!<
  70. * Computes the minimum of \b x and \b y.
  71. */
  72. //@}
  73. /**@defgroup DataT DataTypes
  74. * @ingroup nm_bsp
  75. * @{
  76. */
  77. /*!
  78. * @typedef void (*tpfNmBspIsr) (void);
  79. * @brief Pointer to function.\n
  80. * Used as a data type of ISR function registered by \ref nm_bsp_register_isr
  81. * @return None
  82. */
  83. typedef void (*tpfNmBspIsr)(void);
  84. /*!
  85. * @ingroup DataTypes
  86. * @typedef unsigned char uint8;
  87. * @brief Range of values between 0 to 255
  88. */
  89. typedef unsigned char uint8;
  90. /*!
  91. * @ingroup DataTypes
  92. * @typedef unsigned short uint16;
  93. * @brief Range of values between 0 to 65535
  94. */
  95. typedef unsigned short uint16;
  96. /*!
  97. * @ingroup Data Types
  98. * @typedef unsigned long uint32;
  99. * @brief Range of values between 0 to 4294967295
  100. */
  101. typedef unsigned long uint32;
  102. /*!
  103. * @ingroup Data Types
  104. * @typedef signed char sint8;
  105. * @brief Range of values between -128 to 127
  106. */
  107. typedef signed char sint8;
  108. /*!
  109. * @ingroup DataTypes
  110. * @typedef signed short sint16;
  111. * @brief Range of values between -32768 to 32767
  112. */
  113. typedef signed short sint16;
  114. /*!
  115. * @ingroup DataTypes
  116. * @typedef signed long sint32;
  117. * @brief Range of values between -2147483648 to 2147483647
  118. */
  119. typedef signed long sint32;
  120. //@}
  121. #ifndef CORTUS_APP
  122. #ifdef __cplusplus
  123. extern "C" {
  124. #endif
  125. /** \defgroup BSPAPI Function
  126. * @ingroup nm_bsp
  127. */
  128. /** @defgroup NmBspInitFn nm_bsp_init
  129. * @ingroup BSPAPI
  130. *
  131. * Initialization for BSP (<strong>B</strong>oard <strong>S</strong>upport <strong>P</strong>ackage) such as Reset and Chip Enable Pins for WINC, delays,
  132. * register ISR, enable/disable IRQ for WINC, ...etc. You must use this function in the head of your application to
  133. * enable WINC and Host Driver to communicate with each other.
  134. */
  135. /**@{*/
  136. /*!
  137. * @fn sint8 nm_bsp_init(void);
  138. * @brief This function is used to initialize the <strong>B</strong>oard <strong>S</strong>upport <strong>P</strong>ackage <strong>(BSP)</strong> in order to prepare the WINC
  139. * before it start working.
  140. *
  141. * The nm_bsp_init function is the first function that should be called at the beginning of
  142. * every application to initialize the BSP and the WINC board. Otherwise, the rest of the BSP function
  143. * calls will return with failure. This function should also be called after the WINC has been switched off
  144. with
  145. * a successful call to "nm_bsp_deinit" in order to reinitialize the BSP before the user can use any of the
  146. WINC API
  147. * functions again. After the function initialize the WINC. Hard reset must be applied to start the WINC
  148. board.
  149. * @note Implementation of this function is host dependent.
  150. * @warning inappropriate use of this function will lead to unavailability of host-chip communication.\n
  151. *
  152. * @see nm_bsp_deinit, nm_bsp_reset
  153. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  154. */
  155. sint8 nm_bsp_init(void);
  156. /**@}*/
  157. /** @defgroup NmBspDeinitFn nm_bsp_deinit
  158. * @ingroup BSPAPI
  159. * De-initialization for BSP ((<strong>B</strong>oard <strong>S</strong>upport <strong>P</strong>ackage)). This function should be called only after
  160. * a successful call to nm_bsp_init.
  161. */
  162. /**@{*/
  163. /*!
  164. * @fn sint8 nm_bsp_deinit(void);
  165. * @pre The BSP should be initialized through \ref nm_bsp_init first.
  166. * @brief This function is used to de-initialize the BSP and turn off the WINC board.
  167. *
  168. * The nm_bsp_deinit is the last function that should be called after the application has finished and
  169. before the WINC is switched * off. The function call turns off the WINC board by setting CHIP_EN and
  170. RESET_N signals low.Every function call of "nm_bsp_init" should
  171. * be matched with a call to nm_bsp_deinit. Failure to do so may result in the WINC consuming higher power
  172. than expected.
  173. * @note Implementation of this function is host dependent.
  174. * @warning misuse may lead to unknown behavior in case of soft reset.\n
  175. * @see nm_bsp_init
  176. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  177. */
  178. sint8 nm_bsp_deinit(void);
  179. /**@}*/
  180. /** @defgroup NmBspResetFn nm_bsp_reset
  181. * @ingroup BSPAPI
  182. * Resetting WINC1500 SoC by setting CHIP_EN and RESET_N signals low, then after specific delay the function will
  183. * put CHIP_EN high then RESET_N high, for the timing between signals please review the WINC data-sheet
  184. */
  185. /**@{*/
  186. /*!
  187. * @fn void nm_bsp_reset(void);
  188. * @param [in] None
  189. * @brief Applies a hardware reset to the WINC board.
  190. * The "nm_bsp_reset" is used to apply a hard reset to the WINC board by setting CHIP_EN and RESET_N
  191. signals low, then after specific delay
  192. * the function will put CHIP_EN high then RESET_N high, for the detailed timing between signals please
  193. review the WINC data-sheet. After a * successful call, the WINC board firmware will kick off to load and
  194. kick off the WINC firmware. This function should be called to reset the * WINC firmware after the BSP is
  195. initialized and before the start of any communication with WINC board. Calling this function at any other time *
  196. will result in losing the state and connections saved in the WINC board and starting again from the initial state. The
  197. host driver will need
  198. * to be de-initialized before calling nm_bsp_reset and initialized again after it using the "
  199. m2m_wifi_(de)init".
  200. * @pre Initialize \ref nm_bsp_init first
  201. * @note Implementation of this function is host dependent and called by HIF layer.
  202. * @warning Calling this function will drop any connection and internal state saved on the WINC firmware.
  203. * @see nm_bsp_init, m2m_wifi_init, m2m_wifi_deinit
  204. * @return None
  205. */
  206. void nm_bsp_reset(void);
  207. /**@}*/
  208. /** @defgroup NmBspSleepFn nm_bsp_sleep
  209. * @ingroup BSPAPI
  210. * Sleep in units of milliseconds.\n
  211. * This function used by HIF Layer according to different situations.
  212. */
  213. /**@{*/
  214. /*!
  215. * @fn void nm_bsp_sleep(uint32);
  216. * @brief Used to put the host to sleep for the specified duration.
  217. * Forcing the host to sleep for extended period may lead to host not being able to respond to WINC board
  218. *events.It's important to be considerate while choosing the sleep period.
  219. * @param [in] u32TimeMsec
  220. * Time unit in milliseconds
  221. * @pre Initialize \ref nm_bsp_init first
  222. * @warning Maximum value must nor exceed 4294967295 milliseconds which is equal to 4294967.295 seconds.\n
  223. * @note Implementation of this function is host dependent.
  224. * @see nm_bsp_init
  225. * @return None
  226. */
  227. void nm_bsp_sleep(uint32 u32TimeMsec);
  228. /**@}*/
  229. /** @defgroup NmBspRegisterFn nm_bsp_register_isr
  230. * @ingroup BSPAPI
  231. * Register ISR (Interrupt Service Routine) in the initialization of HIF (Host Interface) Layer.
  232. * When the interrupt trigger the BSP layer should call the pfisr function once inside the interrupt.
  233. */
  234. /**@{*/
  235. /*!
  236. * @fn void nm_bsp_register_isr(tpfNmBspIsr);
  237. * @param [in] tpfNmBspIsr pfIsr
  238. * Pointer to ISR handler in HIF
  239. * @brief Register the host interface interrupt service routine.
  240. * WINC board utilize SPI interface to communicate with the host. This function register the SPI interrupt
  241. the notify * the host whenever there is an outstanding message from the WINC board. The function should
  242. be called during the initialization * of the host interface. It an internal driver function and shouldn't
  243. be called by the application.
  244. * @warning Make sure that ISR for IRQ pin for WINC is disabled by default in your implementation.
  245. * @note Implementation of this function is host dependent and called by HIF layer.
  246. * @see tpfNmBspIsr
  247. * @return None
  248. */
  249. void nm_bsp_register_isr(tpfNmBspIsr pfIsr);
  250. /**@}*/
  251. /** @defgroup NmBspInterruptCtrl nm_bsp_interrupt_ctrl
  252. * @ingroup BSPAPI
  253. * Synchronous enable/disable interrupts function
  254. */
  255. /**@{*/
  256. /*!
  257. * @fn void nm_bsp_interrupt_ctrl(uint8);
  258. * @pre The interrupt must be registered using nm_bsp_register_isr first.
  259. * @brief Enable/Disable interrupts
  260. * This function can be used to enable/disable the WINC to host interrupt as the depending on how the driver
  261. is implemented.
  262. * It an internal driver function and shouldn't be called by the application.
  263. * @param [in] u8Enable
  264. * '0' disable interrupts. '1' enable interrupts
  265. * @see tpfNmBspIsr, nm_bsp_register_isr
  266. * @note Implementation of this function is host dependent and called by HIF layer.
  267. * @return None
  268. */
  269. void nm_bsp_interrupt_ctrl(uint8 u8Enable);
  270. /**@}*/
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274. #endif
  275. #ifdef _NM_BSP_BIG_END
  276. #define NM_BSP_B_L_32(x) \
  277. ((((x)&0x000000FF) << 24) + (((x)&0x0000FF00) << 8) + (((x)&0x00FF0000) >> 8) + (((x)&0xFF000000) >> 24))
  278. #define NM_BSP_B_L_16(x) ((((x)&0x00FF) << 8) + (((x)&0xFF00) >> 8))
  279. #else
  280. #define NM_BSP_B_L_32(x) (x)
  281. #define NM_BSP_B_L_16(x) (x)
  282. #endif
  283. #endif /*_NM_BSP_H_*/