SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.54
Simplifies the implementation of Internet connectivity
device.h
1 /*
2  * device.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
5  *
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 
38 
39 /*****************************************************************************/
40 /* Include files */
41 /*****************************************************************************/
42 #include <ti/drivers/net/wifi/simplelink.h>
43 
44 #ifndef __DEVICE_H__
45 #define __DEVICE_H__
46 
47 
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
66 /*****************************************************************************/
67 /* Macro declarations */
68 /*****************************************************************************/
69 /* Convert event id to event mask to be used in sl_DeviceEventMaskSet and sl_DeviceEventMaskGet */
70 #define SL_DEVICE_EVENT_BIT(EventId) (SL_WLAN_VAL_2_MASK(EventId,1) )
71 
72 
73 
74 typedef enum
75 {
76  SL_DEVICE_EVENT_FATAL_DEVICE_ABORT = 1,
77  SL_DEVICE_EVENT_FATAL_DRIVER_ABORT,
78  SL_DEVICE_EVENT_FATAL_SYNC_LOSS,
79  SL_DEVICE_EVENT_FATAL_NO_CMD_ACK,
80  SL_DEVICE_EVENT_FATAL_CMD_TIMEOUT,
81  SL_DEVICE_EVENT_RESET_REQUEST,
82  SL_DEVICE_EVENT_ERROR,
83  SL_DEVICE_EVENT_MAX
84 
85 } SlDeviceEventId_e;
86 
87 typedef struct
88 {
89  _i16 Status;
90  _u16 Caller;
92 
93 typedef enum
94 {
95  SL_DEVICE_SOURCE_OTHER,
96  SL_DEVICE_SOURCE_WLAN,
97  SL_DEVICE_SOURCE_NETCFG,
98  SL_DEVICE_SOURCE_NETAPP,
99  SL_DEVICE_SOURCE_SECURITY,
100 
101  SL_DEVICE_SOURCE_LAST = 0xFF /* last one */
102 }SlDeviceSource_e;
103 
104 typedef struct
105 {
106  SlDeviceSource_e Source;
107  _i16 Code;
109 
110 typedef union
111 {
112  SlDeviceEventResetRequest_t ResetRequest;
113  SlDeviceEventError_t Error;
115 
116 
117 
118 typedef enum
119 {
120  SL_DEVICE_RESET_REQUEST_CALLER_PROVISIONING,
121  SL_DEVICE_RESET_REQUEST_CALLER_PROVISIONING_EXTERNAL_CONFIGURATION,
122  SL_DEVICE_RESET_REQUEST_NUM_OF_CALLERS
123 }SlDeviceResetRequestCaller_e;
124 
125 typedef struct
126 {
127  _u32 Id;
128  SlDeviceEventData_u Data;
130 
134 void slcb_DeviceEvtHdlr(SlDeviceEvent_t* pEvent);
139 typedef struct
140 {
141  _u32 Code;
142  _u32 Value;
144 
145 
146 typedef struct
147 {
148  _u32 Code;
150 
151 
152 typedef union
153 {
154  SlDeviceFatalDeviceAssert_t DeviceAssert;
155  SlDeviceFatalNoCmdAck_t NoCmdAck;
156  SlDeviceFatalCmdTimeout_t CmdTimeout;
158 
159 
160 typedef struct
161 {
162  _u32 Id;
163  SlDeviceFatalData_u Data;
165 
166 
167 
168 /*
169  Declare the different IDs for sl_DeviceGet and sl_DeviceSet
170  */
171 #define SL_DEVICE_GENERAL (1)
172 #define SL_DEVICE_IOT (4)
173 #define SL_DEVICE_STATUS (2)
174 #define SL_DEVICE_FIPS (6)
175 /*
176  Declare the different Options for SL_DEVICE_GENERAL in sl_DeviceGet and sl_DeviceSet
177  */
178 #define SL_DEVICE_GENERAL_DATE_TIME (11)
179 #define SL_DEVICE_GENERAL_PERSISTENT (5)
180 #define SL_DEVICE_GENERAL_VERSION (12)
181 #define SL_DEVICE_FIPS_ZEROIZATION (20)
182 
183 /* Under SL_DEVICE_GENERAL - Statistics */
184 #define SL_DEVICE_STAT_WLAN_RX (16)
185 #define SL_DEVICE_STAT_PM (14)
186 
187 /*
188  Declare the different Options for SL_DEVICE_IOT in sl_DeviceGet and sl_DeviceSet
189 */
190 #define SL_DEVICE_IOT_UDID (41)
191 
192 /* Events list to mask/unmask*/
193 #define SL_DEVICE_EVENT_CLASS_DEVICE (1)
194 #define SL_DEVICE_EVENT_CLASS_WLAN (2)
195 #define SL_DEVICE_EVENT_CLASS_BSD (3)
196 #define SL_DEVICE_EVENT_CLASS_NETAPP (4)
197 #define SL_DEVICE_EVENT_CLASS_NETCFG (5)
198 #define SL_DEVICE_EVENT_CLASS_FS (6)
199 #define SL_DEVICE_EVENT_CLASS_NETUTIL (7)
200 
201 /****************** SYSCONFIG ****************/
202 #define SL_DEVICE_SYSCONFIG_AS_CONFIGURED (99)
203 
204 /****************** DEVICE CLASS status ****************/
205 #define SL_DEVICE_EVENT_DROPPED_DEVICE_ASYNC_GENERAL_ERROR (0x00000001L)
206 #define SL_DEVICE_STATUS_DEVICE_SMART_CONFIG_ACTIVE (0x80000000L)
207 
208 /****************** WLAN CLASS status ****************/
209 #define SL_DEVICE_EVENT_DROPPED_WLAN_WLANASYNCONNECTEDRESPONSE (0x00000001L)
210 #define SL_DEVICE_EVENT_DROPPED_WLAN_WLANASYNCDISCONNECTEDRESPONSE (0x00000002L)
211 #define SL_DEVICE_EVENT_DROPPED_WLAN_STA_CONNECTED (0x00000004L)
212 #define SL_DEVICE_EVENT_DROPPED_WLAN_STA_DISCONNECTED (0x00000008L)
213 #define SL_DEVICE_EVENT_DROPPED_WLAN_P2P_DEV_FOUND (0x00000010L)
214 #define SL_DEVICE_EVENT_DROPPED_WLAN_CONNECTION_FAILED (0x00000020L)
215 #define SL_DEVICE_EVENT_DROPPED_WLAN_P2P_NEG_REQ_RECEIVED (0x00000040L)
216 #define SL_DEVICE_EVENT_DROPPED_WLAN_RX_FILTERS (0x00000080L)
217 
218 /****************** NETAPP CLASS status ****************/
219 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED (0x00000001L)
220 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED_V6 (0x00000002L)
221 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_LEASED (0x00000004L)
222 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_RELEASED (0x00000008L)
223 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV4_LOST (0x00000010L)
224 #define SL_DEVICE_EVENT_DROPPED_NETAPP_DHCP_ACQUIRE_TIMEOUT (0x00000020L)
225 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_COLLISION (0x00000040L)
226 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV6_LOST (0x00000080L)
227 
228 /****************** BSD CLASS status ****************/
229 #define SL_DEVICE_EVENT_DROPPED_SOCKET_TXFAILEDASYNCRESPONSE (0x00000001L)
230 
231 /****************** FS CLASS ****************/
232 
233 /*****************************************************************************/
234 /* Structure/Enum declarations */
235 /*****************************************************************************/
236 
237 #ifdef SL_IF_TYPE_UART
238 typedef struct
239 {
240  _u32 BaudRate;
241  _u8 FlowControlEnable;
242  _u8 CommPort;
244 #endif
245 
246 #ifdef SL_IF_TYPE_UART
247 
248 #define SL_DEVICE_BAUD_9600 (9600L)
249 #define SL_DEVICE_BAUD_14400 (14400L)
250 #define SL_DEVICE_BAUD_19200 (19200L)
251 #define SL_DEVICE_BAUD_38400 (38400L)
252 #define SL_DEVICE_BAUD_57600 (57600L)
253 #define SL_DEVICE_BAUD_115200 (115200L)
254 #define SL_DEVICE_BAUD_230400 (230400L)
255 #define SL_DEVICE_BAUD_460800 (460800L)
256 #define SL_DEVICE_BAUD_921600 (921600L)
257 
258 #endif
259 
260 typedef struct
261 {
262  _u32 ChipId;
263  _u8 FwVersion[4];
264  _u8 PhyVersion[4];
265  _u8 NwpVersion[4];
266  _u16 RomVersion;
267  _u16 Padding;
269 
270 
271 typedef struct
272 {
273  /* time */
274  _u32 tm_sec;
275  _u32 tm_min;
276  _u32 tm_hour;
277  /* date */
278  _u32 tm_day; /* 1-31 */
279  _u32 tm_mon; /* 1-12 */
280  _u32 tm_year; /* YYYY 4 digits */
281  _u32 tm_week_day; /* not required */
282  _u32 tm_year_day; /* not required */
283  _u32 reserved[3];
284 }SlDateTime_t;
285 
286 
287 
288 
289 /******************************************************************************/
290 /* Type declarations */
291 /******************************************************************************/
292 typedef struct
293 {
294  _u32 ChipId;
295  _u32 MoreData;
297 
298 typedef void (*P_INIT_CALLBACK)(_u32 Status, SlDeviceInitInfo_t *DeviceInitInfo);
299 
300 /* Device statistics structs */
301 typedef struct
302 {
303  _u32 ReceivedValidPacketsNumber; /* sum of the packets that been received OK (include filtered) */
304  _u32 ReceivedFcsErrorPacketsNumber; /* sum of the packets that been dropped due to FCS error */
305  _u32 ReceivedAddressMismatchPacketsNumber; /* sum of the packets that been received but filtered out by one of the HW filters */
306  _i16 AvarageDataCtrlRssi; /* average RSSI for all valid data packets received */
307  _i16 AvarageMgMntRssi; /* average RSSI for all valid management packets received */
308  _u16 RateHistogram[SL_WLAN_NUM_OF_RATE_INDEXES]; /* rate histogram for all valid packets received */
309  _u16 RssiHistogram[SL_WLAN_SIZE_OF_RSSI_HISTOGRAM]; /* RSSI histogram from -40 until -87 (all below and above\n RSSI will appear in the first and last cells) */
310  _u32 StartTimeStamp; /* the time stamp started collecting the statistics in uSec */
311  _u32 GetTimeStamp; /* the time stamp called the get statistics command */
313 
314 typedef struct
315 {
316  _u32 Disconnects; // clear on read - disconnect count
317  _u32 TxFramesCount; // clear on read - Tx Frame count
318  _u32 ReceivedBytesCount; // clear on read
319  _u32 reserved[4]; // reserved for additional clear on read statistics
321 
322 /*
323  * The following statistics are 64 bits represented as array of two 32 Bit
324  * where the first index is the LSB and the second index is MSB.
325  *
326  * For example: TimeMacAwake[0] = LSB, TimeMacAwake[1] = MSB,
327  * TimeMacSleep[0] = LSB, TimeMacSleep[1] = MSB, etc.
328  * */
329 typedef struct
330 {
331  _u32 TimeMacAwake[2];
332  _u32 TimeMacSleep[2];
333  _u32 TimeMacListen11B[2];
334  _u32 TimeNWPDeepSleep[2];
335  _u32 TimeNWPStandBy[2];
336  _u32 TimeNWPAwake[2];
338 
339 
340 typedef struct
341 {
342  SlDeviceGetPmStatClrOnRdTypes_t PmClrOnRd; // Clear on read types
343  SlDeviceGetPmStatAcc_t PmAcc; // Accumulated types
344  _u32 Reserved[4];
345  _u32 StartTimeStamp;
346  _u32 GetTimeStamp;
348 
349 /*****************************************************************************/
350 /* Function prototypes */
351 /*****************************************************************************/
352 
427 #if _SL_INCLUDE_FUNC(sl_Start)
428 _i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack);
429 #endif
430 
459 #if _SL_INCLUDE_FUNC(sl_Stop)
460 _i16 sl_Stop(const _u16 Timeout);
461 #endif
462 
463 
514 #if _SL_INCLUDE_FUNC(sl_DeviceSet)
515 _i16 sl_DeviceSet(const _u8 DeviceSetId ,const _u8 Option,const _u16 ConfigLen,const _u8 *pValues);
516 #endif
517 
611 #if _SL_INCLUDE_FUNC(sl_DeviceGet)
612 _i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption,_u16 *pConfigLen, _u8 *pValues);
613 #endif
614 
615 
684 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskSet)
685 _i16 sl_DeviceEventMaskSet(const _u8 EventClass ,const _u32 Mask);
686 #endif
687 
723 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskGet)
724 _i16 sl_DeviceEventMaskGet(const _u8 EventClass,_u32 *pMask);
725 #endif
726 
727 
748 #if _SL_INCLUDE_FUNC(sl_Task)
749 void* sl_Task(void* pEntry);
750 #endif
751 
752 
753 
754 
770 #ifdef SL_IF_TYPE_UART
771 #if _SL_INCLUDE_FUNC(sl_DeviceUartSetMode)
772 _i16 sl_DeviceUartSetMode(const SlDeviceUartIfParams_t* pUartParams);
773 #endif
774 #endif
775 
799 _i32 sl_WifiConfig();
800 
863 _i16 sl_DeviceStatStart(const _u32 Flags); // start collecting the statistics
906 _i16 sl_DeviceStatGet(const _u16 ConfigId,_u16 length,void* buffer);
918 _i16 sl_DeviceStatStop(const _u32 Flags);
919 
920 
930 #ifdef __cplusplus
931 }
932 #endif /* __cplusplus */
933 
934 #endif /* __DEVICE_H__ */
935 
936 
_i16 sl_DeviceStatStop(const _u32 Flags)
Stop collecting Device statistic, (if previous called sl_DeviceStatStart)
Definition: device.c:765
_i16 sl_DeviceEventMaskSet(const _u8 EventClass, const _u32 Mask)
Set asynchronous event mask.
Definition: device.c:399
_i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption, _u16 *pConfigLen, _u8 *pValues)
Internal function for getting device configurations.
Definition: device.c:478
void * sl_Task(void *pEntry)
The SimpleLink task entry.
Definition: device.c:105
_i16 sl_DeviceSet(const _u8 DeviceSetId, const _u8 Option, const _u16 ConfigLen, const _u8 *pValues)
Setting device configurations.
Definition: device.c:550
_i16 sl_Stop(const _u16 Timeout)
Stop the SimpleLink device.
Definition: device.c:273
_i32 sl_WifiConfig()
Configure SimpleLink to default state.
Definition: wlanconfig.c:46
_i16 sl_DeviceEventMaskGet(const _u8 EventClass, _u32 *pMask)
Get current event mask of the device.
Definition: device.c:437
_i16 sl_DeviceStatStart(const _u32 Flags)
Start collecting Device statistics (including RX statistics), for unlimited time. ...
Definition: device.c:705
_i16 sl_DeviceUartSetMode(const SlDeviceUartIfParams_t *pUartParams)
Setting the internal uart mode.
Definition: device.c:807
_i16 sl_Start(const void *pIfHdl, _i8 *pDevName, const P_INIT_CALLBACK pInitCallBack)
Start the SimpleLink device.
Definition: device.c:119
_i16 sl_DeviceStatGet(const _u16 ConfigId, _u16 length, void *buffer)
Getting DEVICE statistics.
Definition: device.c:728