Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

256 řádky
7.7 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief This module contains M2M host interface APIs implementation.
  6. *
  7. * Copyright (c) 2015 - 2017 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. #ifndef _M2M_HIF_
  42. #define _M2M_HIF_
  43. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  44. INCLUDES
  45. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  46. #include "common/include/nm_common.h"
  47. /*!< Include depends on UNO Board is used or not*/
  48. #ifdef ENABLE_UNO_BOARD
  49. #include "m2m_uno_hif.h"
  50. #endif
  51. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  52. MACROS
  53. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  54. #define M2M_HIF_MAX_PACKET_SIZE (1600 - 4)
  55. /*!< Maximum size of the buffer could be transferred between Host and Firmware.
  56. */
  57. #define M2M_HIF_HDR_OFFSET (sizeof(tstrHifHdr) + 4)
  58. /**
  59. * @struct tstrHifHdr
  60. * @brief Structure to hold HIF header
  61. */
  62. typedef struct {
  63. uint8 u8Gid; /*!< Group ID */
  64. uint8 u8Opcode; /*!< OP code */
  65. uint16 u16Length; /*!< Payload length */
  66. } tstrHifHdr;
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. /*!
  71. @typedef typedef void (*tpfHifCallBack)(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr);
  72. @brief used to point to Wi-Fi call back function depend on Arduino project or other projects.
  73. @param [in] u8OpCode
  74. HIF Opcode type.
  75. @param [in] u16DataSize
  76. HIF data length.
  77. @param [in] u32Addr
  78. HIF address.
  79. @param [in] grp
  80. HIF group type.
  81. */
  82. typedef void (*tpfHifCallBack)(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr);
  83. /**
  84. * @fn NMI_API sint8 hif_init(void * arg);
  85. * @brief
  86. To initialize HIF layer.
  87. * @param [in] arg
  88. * Pointer to the arguments.
  89. * @return
  90. The function shall return ZERO for successful operation and a negative value otherwise.
  91. */
  92. NMI_API sint8 hif_init(void *arg);
  93. /**
  94. * @fn NMI_API sint8 hif_deinit(void * arg);
  95. * @brief
  96. To Deinitialize HIF layer.
  97. * @param [in] arg
  98. * Pointer to the arguments.
  99. * @return
  100. The function shall return ZERO for successful operation and a negative value otherwise.
  101. */
  102. NMI_API sint8 hif_deinit(void *arg);
  103. /**
  104. * @fn NMI_API sint8 hif_send(uint8 u8Gid,uint8 u8Opcode,uint8 *pu8CtrlBuf,uint16 u16CtrlBufSize,
  105. uint8 *pu8DataBuf,uint16 u16DataSize, uint16 u16DataOffset)
  106. * @brief Send packet using host interface.
  107. * @param [in] u8Gid
  108. * Group ID.
  109. * @param [in] u8Opcode
  110. * Operation ID.
  111. * @param [in] pu8CtrlBuf
  112. * Pointer to the Control buffer.
  113. * @param [in] u16CtrlBufSize
  114. Control buffer size.
  115. * @param [in] u16DataOffset
  116. Packet Data offset.
  117. * @param [in] pu8DataBuf
  118. * Packet buffer Allocated by the caller.
  119. * @param [in] u16DataSize
  120. Packet buffer size (including the HIF header).
  121. * @return The function shall return ZERO for successful operation and a negative value otherwise.
  122. */
  123. NMI_API sint8 hif_send(uint8 u8Gid, uint8 u8Opcode, uint8 *pu8CtrlBuf, uint16 u16CtrlBufSize, uint8 *pu8DataBuf,
  124. uint16 u16DataSize, uint16 u16DataOffset);
  125. /*
  126. * @fn hif_receive
  127. * @brief Host interface interrupt serviece routine
  128. * @param [in] u32Addr
  129. * Receive start address
  130. * @param [out] pu8Buf
  131. * Pointer to receive buffer. Allocated by the caller
  132. * @param [in] u16Sz
  133. * Receive buffer size
  134. * @param [in] isDone
  135. * If you don't need any more packets send True otherwise send false
  136. * @return
  137. The function shall return ZERO for successful operation and a negative value otherwise.
  138. */
  139. NMI_API sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone);
  140. /**
  141. * @fn hif_register_cb
  142. * @brief
  143. To set Callback function for every Component.
  144. * @param [in] u8Grp
  145. * Group to which the Callback function should be set.
  146. * @param [in] fn
  147. * function to be set to the specified group.
  148. * @return
  149. The function shall return ZERO for successful operation and a negative value otherwise.
  150. */
  151. NMI_API sint8 hif_register_cb(uint8 u8Grp, tpfHifCallBack fn);
  152. /**
  153. * @fn NMI_API sint8 hif_chip_sleep(void);
  154. * @brief
  155. To make the chip sleep.
  156. * @return
  157. The function shall return ZERO for successful operation and a negative value otherwise.
  158. */
  159. NMI_API sint8 hif_chip_sleep(void);
  160. /**
  161. * @fn NMI_API sint8 hif_chip_sleep_sc(void);
  162. * @brief
  163. To clear the chip count only but keep the chip awake
  164. * @return
  165. The function shall return ZERO for successful operation and a negative value otherwise.
  166. */
  167. NMI_API sint8 hif_chip_sleep_sc(void);
  168. /**
  169. * @fn NMI_API sint8 hif_chip_wake(void);
  170. * @brief
  171. To Wakeup the chip.
  172. * @return
  173. The function shall return ZERO for successful operation and a negative value otherwise.
  174. */
  175. NMI_API sint8 hif_chip_wake(void);
  176. /*!
  177. @fn \
  178. NMI_API void hif_set_sleep_mode(uint8 u8Pstype);
  179. @brief
  180. Set the sleep mode of the HIF layer.
  181. @param [in] u8Pstype
  182. Sleep mode.
  183. @return
  184. The function SHALL return 0 for success and a negative value otherwise.
  185. */
  186. NMI_API void hif_set_sleep_mode(uint8 u8Pstype);
  187. /*!
  188. @fn \
  189. NMI_API uint8 hif_get_sleep_mode(void);
  190. @brief
  191. Get the sleep mode of the HIF layer.
  192. @return
  193. The function SHALL return the sleep mode of the HIF layer.
  194. */
  195. NMI_API uint8 hif_get_sleep_mode(void);
  196. #ifdef CORTUS_APP
  197. /**
  198. * @fn hif_Resp_handler(uint8 *pu8Buffer, uint16 u16BufferSize)
  199. * @brief
  200. Response handler for HIF layer.
  201. * @param [in] pu8Buffer
  202. Pointer to the buffer.
  203. * @param [in] u16BufferSize
  204. Buffer size.
  205. * @return
  206. The function SHALL return 0 for success and a negative value otherwise.
  207. */
  208. NMI_API sint8 hif_Resp_handler(uint8 *pu8Buffer, uint16 u16BufferSize);
  209. #endif
  210. /**
  211. * @fn hif_yield(void)
  212. * @brief
  213. Yields control from interrupt event handler.
  214. */
  215. NMI_API void hif_yield(void);
  216. /**
  217. * @fn hif_handle_isr(void)
  218. * @brief
  219. Handle interrupt received from NMC1500 firmware.
  220. * @return
  221. The function SHALL return 0 for success and a negative value otherwise.
  222. */
  223. NMI_API sint8 hif_handle_isr(void);
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif