Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

271 linhas
7.8 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains M2M host interface APIs implementation.
  6. *
  7. * Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. #ifndef _M2M_HIF_
  35. #define _M2M_HIF_
  36. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  37. INCLUDES
  38. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  39. #include "common/include/nm_common.h"
  40. /*!< Include depends on UNO Board is used or not*/
  41. #ifdef ENABLE_UNO_BOARD
  42. #include "m2m_uno_hif.h"
  43. #endif
  44. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  45. MACROS
  46. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  47. #define M2M_HIF_MAX_PACKET_SIZE (1600 - 4)
  48. /*!< Maximum size of the buffer could be transferred between Host and Firmware.
  49. */
  50. #define M2M_HIF_HDR_OFFSET (sizeof(tstrHifHdr) + 4)
  51. /**
  52. * @struct tstrHifHdr
  53. * @brief Structure to hold HIF header
  54. */
  55. typedef struct
  56. {
  57. uint8 u8Gid; /*!< Group ID */
  58. uint8 u8Opcode; /*!< OP code */
  59. uint16 u16Length; /*!< Payload length */
  60. }tstrHifHdr;
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. /*!
  65. @typedef typedef void (*tpfHifCallBack)(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr);
  66. @brief used to point to Wi-Fi call back function depend on Arduino project or other projects.
  67. @param [in] u8OpCode
  68. HIF Opcode type.
  69. @param [in] u16DataSize
  70. HIF data length.
  71. @param [in] u32Addr
  72. HIF address.
  73. @param [in] grp
  74. HIF group type.
  75. */
  76. typedef void (*tpfHifCallBack)(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr);
  77. /**
  78. * @fn NMI_API sint8 hif_init(void * arg);
  79. * @brief
  80. To initialize HIF layer.
  81. * @param [in] arg
  82. * Pointer to the arguments.
  83. * @return
  84. The function shall return ZERO for successful operation and a negative value otherwise.
  85. */
  86. NMI_API sint8 hif_init(void * arg);
  87. /**
  88. * @fn NMI_API sint8 hif_deinit(void * arg);
  89. * @brief
  90. To Deinitialize HIF layer.
  91. * @param [in] arg
  92. * Pointer to the arguments.
  93. * @return
  94. The function shall return ZERO for successful operation and a negative value otherwise.
  95. */
  96. NMI_API sint8 hif_deinit(void * arg);
  97. /**
  98. * @fn sint8 hif_check_compatibility(uint16 u16HifInfo);
  99. * @brief
  100. * To check the compatibility of an image with the current driver.
  101. * @param [in] u16HifInfo
  102. * HIF info of image to be checked.
  103. * @return The function shall return ZERO for compatible image and a negative value otherwise.
  104. */
  105. sint8 hif_check_compatibility(uint16 u16HifInfo);
  106. /**
  107. * @fn sint8 hif_enable_access(void);
  108. * @brief
  109. * To enable access to HIF layer, based on HIF level of Firmware.
  110. * This function reads HIF level directly from a register written by Firmware.
  111. * @return The function shall return ZERO for full match operation and a negative value if operation is restricted.
  112. */
  113. sint8 hif_enable_access(void);
  114. /**
  115. * @fn sint8 hif_check_code(uint8 u8Gid, uint8 u8OpCode);
  116. * @brief
  117. * To check that a particular hif message is supported with the current driver/firmware pair.
  118. * @param [in] u8Gid
  119. * Group ID.
  120. * @param [in] u8Opcode
  121. * Operation ID.
  122. * @return The function shall return ZERO for support and a negative value otherwise.
  123. */
  124. sint8 hif_check_code(uint8 u8Gid, uint8 u8OpCode);
  125. /**
  126. * @fn NMI_API sint8 hif_send(uint8 u8Gid,uint8 u8Opcode,uint8 *pu8CtrlBuf,uint16 u16CtrlBufSize,
  127. uint8 *pu8DataBuf,uint16 u16DataSize, uint16 u16DataOffset)
  128. * @brief Send packet using host interface.
  129. * @param [in] u8Gid
  130. * Group ID.
  131. * @param [in] u8Opcode
  132. * Operation ID.
  133. * @param [in] pu8CtrlBuf
  134. * Pointer to the Control buffer.
  135. * @param [in] u16CtrlBufSize
  136. Control buffer size.
  137. * @param [in] u16DataOffset
  138. Packet Data offset.
  139. * @param [in] pu8DataBuf
  140. * Packet buffer Allocated by the caller.
  141. * @param [in] u16DataSize
  142. Packet buffer size (including the HIF header).
  143. * @return The function shall return ZERO for successful operation and a negative value otherwise.
  144. */
  145. NMI_API sint8 hif_send(uint8 u8Gid,uint8 u8Opcode,uint8 *pu8CtrlBuf,uint16 u16CtrlBufSize,
  146. uint8 *pu8DataBuf,uint16 u16DataSize, uint16 u16DataOffset);
  147. /**
  148. * @fn hif_receive
  149. * @brief Host interface interrupt serviece routine
  150. * @param [in] u32Addr
  151. * Receive start address
  152. * @param [out] pu8Buf
  153. * Pointer to receive buffer. Allocated by the caller
  154. * @param [in] u16Sz
  155. * Receive buffer size
  156. * @param [in] isDone
  157. * If you don't need any more packets send True otherwise send false
  158. * @return
  159. The function shall return ZERO for successful operation and a negative value otherwise.
  160. */
  161. NMI_API sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone);
  162. /**
  163. * @fn hif_register_cb
  164. * @brief
  165. To set Callback function for every Component.
  166. * @param [in] u8Grp
  167. * Group to which the Callback function should be set.
  168. * @param [in] fn
  169. * function to be set to the specified group.
  170. * @return
  171. The function shall return ZERO for successful operation and a negative value otherwise.
  172. */
  173. NMI_API sint8 hif_register_cb(uint8 u8Grp,tpfHifCallBack fn);
  174. /**
  175. * @fn NMI_API sint8 hif_chip_sleep(void);
  176. * @brief
  177. To make the chip sleep.
  178. * @return
  179. The function shall return ZERO for successful operation and a negative value otherwise.
  180. */
  181. NMI_API sint8 hif_chip_sleep(void);
  182. /**
  183. * @fn NMI_API sint8 hif_chip_wake(void);
  184. * @brief
  185. To Wakeup the chip.
  186. * @return
  187. The function shall return ZERO for successful operation and a negative value otherwise.
  188. */
  189. NMI_API sint8 hif_chip_wake(void);
  190. /*!
  191. @fn \
  192. NMI_API void hif_set_sleep_mode(uint8 u8Pstype);
  193. @brief
  194. Set the sleep mode of the HIF layer.
  195. @param [in] u8Pstype
  196. Sleep mode.
  197. @return
  198. The function SHALL return 0 for success and a negative value otherwise.
  199. */
  200. NMI_API void hif_set_sleep_mode(uint8 u8Pstype);
  201. /*!
  202. @fn \
  203. NMI_API uint8 hif_get_sleep_mode(void);
  204. @brief
  205. Get the sleep mode of the HIF layer.
  206. @return
  207. The function SHALL return the sleep mode of the HIF layer.
  208. */
  209. NMI_API uint8 hif_get_sleep_mode(void);
  210. #ifdef CORTUS_APP
  211. /**
  212. * @fn hif_Resp_handler(uint8 *pu8Buffer, uint16 u16BufferSize)
  213. * @brief
  214. Response handler for HIF layer.
  215. * @param [in] pu8Buffer
  216. Pointer to the buffer.
  217. * @param [in] u16BufferSize
  218. Buffer size.
  219. * @return
  220. The function SHALL return 0 for success and a negative value otherwise.
  221. */
  222. NMI_API sint8 hif_Resp_handler(uint8 *pu8Buffer, uint16 u16BufferSize);
  223. #endif
  224. /**
  225. * @fn hif_yield(void)
  226. * @brief
  227. Yields control from interrupt event handler.
  228. */
  229. NMI_API void hif_yield(void);
  230. /**
  231. * @fn hif_handle_isr(void)
  232. * @brief
  233. Handle interrupt received from NMC1500 firmware.
  234. * @return
  235. The function SHALL return 0 for success and a negative value otherwise.
  236. */
  237. NMI_API sint8 hif_handle_isr(void);
  238. #ifdef __cplusplus
  239. }
  240. #endif
  241. #endif