SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.55
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 #define SL_DEVICE_DICE_VERSION (14)
192 
193 /* Events list to mask/unmask*/
194 #define SL_DEVICE_EVENT_CLASS_DEVICE (1)
195 #define SL_DEVICE_EVENT_CLASS_WLAN (2)
196 #define SL_DEVICE_EVENT_CLASS_BSD (3)
197 #define SL_DEVICE_EVENT_CLASS_NETAPP (4)
198 #define SL_DEVICE_EVENT_CLASS_NETCFG (5)
199 #define SL_DEVICE_EVENT_CLASS_FS (6)
200 #define SL_DEVICE_EVENT_CLASS_NETUTIL (7)
201 
202 /****************** SYSCONFIG ****************/
203 #define SL_DEVICE_SYSCONFIG_AS_CONFIGURED (99)
204 
205 /****************** DEVICE CLASS status ****************/
206 #define SL_DEVICE_EVENT_DROPPED_DEVICE_ASYNC_GENERAL_ERROR (0x00000001L)
207 #define SL_DEVICE_STATUS_DEVICE_SMART_CONFIG_ACTIVE (0x80000000L)
208 
209 /****************** WLAN CLASS status ****************/
210 #define SL_DEVICE_EVENT_DROPPED_WLAN_WLANASYNCONNECTEDRESPONSE (0x00000001L)
211 #define SL_DEVICE_EVENT_DROPPED_WLAN_WLANASYNCDISCONNECTEDRESPONSE (0x00000002L)
212 #define SL_DEVICE_EVENT_DROPPED_WLAN_STA_CONNECTED (0x00000004L)
213 #define SL_DEVICE_EVENT_DROPPED_WLAN_STA_DISCONNECTED (0x00000008L)
214 #define SL_DEVICE_EVENT_DROPPED_WLAN_P2P_DEV_FOUND (0x00000010L)
215 #define SL_DEVICE_EVENT_DROPPED_WLAN_CONNECTION_FAILED (0x00000020L)
216 #define SL_DEVICE_EVENT_DROPPED_WLAN_P2P_NEG_REQ_RECEIVED (0x00000040L)
217 #define SL_DEVICE_EVENT_DROPPED_WLAN_RX_FILTERS (0x00000080L)
218 
219 /****************** NETAPP CLASS status ****************/
220 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED (0x00000001L)
221 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED_V6 (0x00000002L)
222 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_LEASED (0x00000004L)
223 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_RELEASED (0x00000008L)
224 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV4_LOST (0x00000010L)
225 #define SL_DEVICE_EVENT_DROPPED_NETAPP_DHCP_ACQUIRE_TIMEOUT (0x00000020L)
226 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_COLLISION (0x00000040L)
227 #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV6_LOST (0x00000080L)
228 
229 /****************** BSD CLASS status ****************/
230 #define SL_DEVICE_EVENT_DROPPED_SOCKET_TXFAILEDASYNCRESPONSE (0x00000001L)
231 
232 /****************** FS CLASS ****************/
233 
234 /*****************************************************************************/
235 /* Structure/Enum declarations */
236 /*****************************************************************************/
237 
238 #ifdef SL_IF_TYPE_UART
239 typedef struct
240 {
241  _u32 BaudRate;
242  _u8 FlowControlEnable;
243  _u8 CommPort;
245 #endif
246 
247 #ifdef SL_IF_TYPE_UART
248 
249 #define SL_DEVICE_BAUD_9600 (9600L)
250 #define SL_DEVICE_BAUD_14400 (14400L)
251 #define SL_DEVICE_BAUD_19200 (19200L)
252 #define SL_DEVICE_BAUD_38400 (38400L)
253 #define SL_DEVICE_BAUD_57600 (57600L)
254 #define SL_DEVICE_BAUD_115200 (115200L)
255 #define SL_DEVICE_BAUD_230400 (230400L)
256 #define SL_DEVICE_BAUD_460800 (460800L)
257 #define SL_DEVICE_BAUD_921600 (921600L)
258 
259 #endif
260 
261 typedef struct
262 {
263  _u32 ChipId;
264  _u8 FwVersion[4];
265  _u8 PhyVersion[4];
266  _u8 NwpVersion[4];
267  _u16 RomVersion;
268  _u16 Padding;
270 
271 
272 typedef struct
273 {
274  /* time */
275  _u32 tm_sec;
276  _u32 tm_min;
277  _u32 tm_hour;
278  /* date */
279  _u32 tm_day; /* 1-31 */
280  _u32 tm_mon; /* 1-12 */
281  _u32 tm_year; /* YYYY 4 digits */
282  _u32 tm_week_day; /* not required */
283  _u32 tm_year_day; /* not required */
284  _u32 reserved[3];
285 }SlDateTime_t;
286 
287 
288 
289 
290 /******************************************************************************/
291 /* Type declarations */
292 /******************************************************************************/
293 typedef struct
294 {
295  _u32 ChipId;
296  _u32 MoreData;
298 
299 typedef void (*P_INIT_CALLBACK)(_u32 Status, SlDeviceInitInfo_t *DeviceInitInfo);
300 
301 /* Device statistics structs */
302 typedef struct
303 {
304  _u32 ReceivedValidPacketsNumber; /* sum of the packets that been received OK (include filtered) */
305  _u32 ReceivedFcsErrorPacketsNumber; /* sum of the packets that been dropped due to FCS error */
306  _u32 ReceivedAddressMismatchPacketsNumber; /* sum of the packets that been received but filtered out by one of the HW filters */
307  _i16 AvarageDataCtrlRssi; /* average RSSI for all valid data packets received */
308  _i16 AvarageMgMntRssi; /* average RSSI for all valid management packets received */
309  _u16 RateHistogram[SL_WLAN_NUM_OF_RATE_INDEXES]; /* rate histogram for all valid packets received */
310  _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) */
311  _u32 StartTimeStamp; /* the time stamp started collecting the statistics in uSec */
312  _u32 GetTimeStamp; /* the time stamp called the get statistics command */
314 
315 typedef struct
316 {
317  _u32 Disconnects; // clear on read - disconnect count
318  _u32 TxFramesCount; // clear on read - Tx Frame count
319  _u32 ReceivedBytesCount; // clear on read
320  _u32 reserved[4]; // reserved for additional clear on read statistics
322 
323 /*
324  * The following statistics are 64 bits represented as array of two 32 Bit
325  * where the first index is the LSB and the second index is MSB.
326  *
327  * For example: TimeMacAwake[0] = LSB, TimeMacAwake[1] = MSB,
328  * TimeMacSleep[0] = LSB, TimeMacSleep[1] = MSB, etc.
329  * */
330 typedef struct
331 {
332  _u32 TimeMacAwake[2];
333  _u32 TimeMacSleep[2];
334  _u32 TimeMacListen11B[2];
335  _u32 TimeNWPDeepSleep[2];
336  _u32 TimeNWPStandBy[2];
337  _u32 TimeNWPAwake[2];
339 
340 
341 typedef struct
342 {
343  SlDeviceGetPmStatClrOnRdTypes_t PmClrOnRd; // Clear on read types
344  SlDeviceGetPmStatAcc_t PmAcc; // Accumulated types
345  _u32 Reserved[4];
346  _u32 StartTimeStamp;
347  _u32 GetTimeStamp;
349 
350 /*****************************************************************************/
351 /* Function prototypes */
352 /*****************************************************************************/
353 
428 #if _SL_INCLUDE_FUNC(sl_Start)
429 _i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack);
430 #endif
431 
460 #if _SL_INCLUDE_FUNC(sl_Stop)
461 _i16 sl_Stop(const _u16 Timeout);
462 #endif
463 
464 
515 #if _SL_INCLUDE_FUNC(sl_DeviceSet)
516 _i16 sl_DeviceSet(const _u8 DeviceSetId ,const _u8 Option,const _u16 ConfigLen,const _u8 *pValues);
517 #endif
518 
622 #if _SL_INCLUDE_FUNC(sl_DeviceGet)
623 _i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption,_u16 *pConfigLen, _u8 *pValues);
624 #endif
625 
626 
695 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskSet)
696 _i16 sl_DeviceEventMaskSet(const _u8 EventClass ,const _u32 Mask);
697 #endif
698 
734 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskGet)
735 _i16 sl_DeviceEventMaskGet(const _u8 EventClass,_u32 *pMask);
736 #endif
737 
738 
759 #if _SL_INCLUDE_FUNC(sl_Task)
760 void* sl_Task(void* pEntry);
761 #endif
762 
763 
764 
765 
781 #ifdef SL_IF_TYPE_UART
782 #if _SL_INCLUDE_FUNC(sl_DeviceUartSetMode)
783 _i16 sl_DeviceUartSetMode(const SlDeviceUartIfParams_t* pUartParams);
784 #endif
785 #endif
786 
810 _i32 sl_WifiConfig();
811 
874 _i16 sl_DeviceStatStart(const _u32 Flags); // start collecting the statistics
917 _i16 sl_DeviceStatGet(const _u16 ConfigId,_u16 length,void* buffer);
929 _i16 sl_DeviceStatStop(const _u32 Flags);
930 
931 
941 #ifdef __cplusplus
942 }
943 #endif /* __cplusplus */
944 
945 #endif /* __DEVICE_H__ */
946 
947 
_i16 sl_DeviceStatStop(const _u32 Flags)
Stop collecting Device statistic, (if previous called sl_DeviceStatStart)
Definition: device.c:778
_i16 sl_DeviceEventMaskSet(const _u8 EventClass, const _u32 Mask)
Set asynchronous event mask.
Definition: device.c:412
_i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption, _u16 *pConfigLen, _u8 *pValues)
Internal function for getting device configurations.
Definition: device.c:491
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:563
_i16 sl_Stop(const _u16 Timeout)
Stop the SimpleLink device.
Definition: device.c:280
_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:450
_i16 sl_DeviceStatStart(const _u32 Flags)
Start collecting Device statistics (including RX statistics), for unlimited time. ...
Definition: device.c:718
_i16 sl_DeviceUartSetMode(const SlDeviceUartIfParams_t *pUartParams)
Setting the internal uart mode.
Definition: device.c:820
_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:741