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