1 /* 2 * device.h - CC31xx/CC32xx Host Driver Implementation 3 * 4 * Copyright (C) 2017 Texas Instruments Incorporated - http://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 53 /*! 54 \defgroup Device 55 \short Controls the behaviour of the CC31xx/CC32xx device (start/stop, events masking and obtaining specific device status) 56 57 */ 58 59 /*! 60 61 \addtogroup Device 62 @{ 63 64 */ 65 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; 91 }SlDeviceEventResetRequest_t; 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; 108 }SlDeviceEventError_t; 109 110 typedef union 111 { 112 SlDeviceEventResetRequest_t ResetRequest; 113 SlDeviceEventError_t Error; 114 }SlDeviceEventData_u; 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; 129 }SlDeviceEvent_t; 130 131 /*! 132 \cond DOXYGEN_REMOVE 133 */ 134 void slcb_DeviceEvtHdlr(SlDeviceEvent_t* pEvent); 135 /*! 136 \endcond 137 */ 138 139 typedef struct 140 { 141 _u32 Code; 142 _u32 Value; 143 } SlDeviceFatalDeviceAssert_t; 144 145 146 typedef struct 147 { 148 _u32 Code; 149 } SlDeviceFatalNoCmdAck_t, SlDeviceFatalCmdTimeout_t; 150 151 152 typedef union 153 { 154 SlDeviceFatalDeviceAssert_t DeviceAssert; 155 SlDeviceFatalNoCmdAck_t NoCmdAck; 156 SlDeviceFatalCmdTimeout_t CmdTimeout; 157 }SlDeviceFatalData_u; 158 159 160 typedef struct 161 { 162 _u32 Id; 163 SlDeviceFatalData_u Data; 164 }SlDeviceFatal_t; 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; 244 } SlDeviceUartIfParams_t; 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; 269 }SlDeviceVersion_t; 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; 297 }SlDeviceInitInfo_t; 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 */ 313 }SlDeviceGetStat_t; 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 321 }SlDeviceGetPmStatClrOnRdTypes_t; 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]; 338 }SlDeviceGetPmStatAcc_t; 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; 348 }SlDeviceGetPmStat_t; 349 350 /*****************************************************************************/ 351 /* Function prototypes */ 352 /*****************************************************************************/ 353 354 /*! 355 \brief Start the SimpleLink device 356 357 This function initialize the communication interface, set the enable pin 358 of the device, and call to the init complete callback. 359 360 \param[in] pIfHdl Opened Interface Object. In case the interface 361 must be opened outside the SimpleLink Driver, the 362 user might give the handler to be used in \n 363 any access of the communication interface with the 364 device (UART/SPI). \n 365 The SimpleLink driver will open an interface port 366 only if this parameter is null! \n 367 \param[in] pDevName The name of the device to open. Could be used when 368 the pIfHdl is null, to transfer information to the 369 open interface function \n 370 This pointer could be used to pass additional information to 371 sl_IfOpen in case it is required (e.g. UART com port name) 372 \param[in] pInitCallBack Pointer to function that would be called 373 on completion of the initialization process.\n 374 If this parameter is NULL the function is 375 blocked until the device initialization 376 is completed, otherwise the function returns 377 immediately. 378 379 \return Returns the current active role (STA/AP/P2P/TAG) or an error code: 380 - ROLE_STA, ROLE_AP, ROLE_P2P, ROLE_TAG in case of success and when pInitCallBack is NULL (the third parameter),\n 381 or, in case of pInitCallBack is not null - sl_start will return zero in case of success, 382 otherwise in failure one of the following is return: 383 - SL_ERROR_ROLE_STA_ERR (Failure to load MAC/PHY in STA role) 384 - SL_ERROR_ROLE_AP_ERR (Failure to load MAC/PHY in AP role) 385 - SL_ERROR_ROLE_P2P_ERR (Failure to load MAC/PHY in P2P role) 386 - SL_ERROR_CALIB_FAIL (Failure of calibration) 387 - SL_ERROR_FS_CORRUPTED_ERR (FS is corrupted, Return to Factory Image or Program new image should be invoked (see sl_FsCtl, sl_FsProgram)) 388 - SL_ERROR_FS_ALERT_ERR (Device is locked, Return to Factory Image or Program new image should be invoked (see sl_FsCtl, sl_FsProgram)) 389 - SL_ERROR_RESTORE_IMAGE_COMPLETE (Return to factory image completed, perform reset) 390 - SL_ERROR_ROLE_TAG_ERR (Failure to start TAG role) 391 - SL_ERROR_FIPS_ERR (Failure to start with FIPS mode enabled) 392 - SL_ERROR_GENERAL_ERR (General error during init) 393 394 \sa sl_Stop 395 396 \note Belongs to \ref basic_api 397 398 \warning This function must be called before any other SimpleLink API is used, or after sl_Stop is called for reinit the device 399 \par Example: 400 401 - Open interface without callback routine. The interface name and handler are 402 handled by the sl_IfOpen routine: 403 \code 404 if( sl_Start(NULL, NULL, NULL) < 0 ) 405 { 406 LOG("Error opening interface to device\n"); 407 } 408 \endcode 409 <br> 410 411 - Open interface with a callback routine: 412 \code 413 void SimpleLinkInitCallback(_u32 status) 414 { 415 LOG("Handle SimpleLink Interface acording to ststus %d\n", status); 416 } 417 418 void main(void) 419 { 420 if (sl_Start(NULL, NULL, SimpleLinkInitCallback) < 0) 421 { 422 LOG("Error opening interface to device\n"); 423 } 424 } 425 \endcode 426 427 */ 428 #if _SL_INCLUDE_FUNC(sl_Start) 429 _i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack); 430 #endif 431 432 /*! 433 \brief Stop the SimpleLink device 434 435 This function clears the enable pin of the device, closes the communication \n 436 interface and invokes the stop complete callback 437 438 \param[in] Timeout Stop timeout in msec. Should be used to give the device time to finish \n 439 any transmission/reception that is not completed when the function was called. \n 440 Additional options: 441 - 0 Enter to hibernate immediately \n 442 - 0xFFFF Host waits for device's response before \n 443 hibernating, without timeout protection \n 444 - 0 < Timeout[msec] < 0xFFFF Host waits for device's response before \n 445 hibernating, with a defined timeout protection \n 446 This timeout defines the max time to wait. The NWP \n 447 response can be sent earlier than this timeout. 448 449 \return Zero on success, or a negative value if an error occurred 450 451 \sa sl_Start 452 453 \note This API will shutdown the device and invoke the "i/f close" function regardless \n 454 if it was opened implicitly or explicitly. \n 455 It is up to the platform interface library to properly handle interface close \n 456 routine \n 457 Belongs to \ref basic_api \n 458 \warning 459 */ 460 #if _SL_INCLUDE_FUNC(sl_Stop) 461 _i16 sl_Stop(const _u16 Timeout); 462 #endif 463 464 465 /*! 466 \brief Setting device configurations 467 468 \param[in] DeviceSetId configuration id: 469 - SL_DEVICE_GENERAL 470 471 \param[in] Option configurations option: 472 - SL_DEVICE_GENERAL_DATE_TIME 473 - SL_DEVICE_GENERAL_PERSISTENT 474 \param[in] ConfigLen configurations len 475 \param[in] pValues configurations values 476 477 \return Zero on success, or a negative value if an error occurred 478 \par Persistent 479 SL_DEVICE_GENERAL_DATE_TIME - System Persistent (kept during hibernate only, See Note for details) \n 480 SL_DEVICE_GENERAL_PERSISTENT - Persistent 481 \sa 482 \note Persistency for SL_DEVICE_GENERAL_DATE_TIME - The original setted value will be kept as System Persistence.\n 483 The updated date and time though, will be kept during hibernate only. 484 \warning 485 \par Examples: 486 487 - Setting device time and date example: 488 \code 489 SlDateTime_t dateTime= {0}; 490 dateTime.tm_day = (_u32)23; // Day of month (DD format) range 1-31 491 dateTime.tm_mon = (_u32)6; // Month (MM format) in the range of 1-12 492 dateTime.tm_year = (_u32)2014; // Year (YYYY format) 493 dateTime.tm_hour = (_u32)17; // Hours in the range of 0-23 494 dateTime.tm_min = (_u32)55; // Minutes in the range of 0-59 495 dateTime.tm_sec = (_u32)22; // Seconds in the range of 0-59 496 sl_DeviceSet(SL_DEVICE_GENERAL, 497 SL_DEVICE_GENERAL_DATE_TIME, 498 sizeof(SlDateTime_t), 499 (_u8 *)(&dateTime)); 500 \endcode 501 <br> 502 503 - Setting system persistent configuration: <br> 504 Sets the default system-wide configuration persistence mode. 505 In case true, all APIs that follow 'system configured' persistence (see persistence attribute noted per API) shall maintain the configured settings. 506 In case false, all calls to APIs that follow 'system configured' persistence shall be volatile. Configuration should revert to default after reset or power recycle 507 \code 508 _u8 persistent = 1; 509 sl_DeviceSet(SL_DEVICE_GENERAL, 510 SL_DEVICE_GENERAL_PERSISTENT, 511 sizeof(_u8), 512 (_u8 *)(&persistent)); 513 \endcode 514 */ 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 519 /*! 520 \brief Internal function for getting device configurations 521 \param[in] DeviceGetId configuration id: 522 - SL_DEVICE_STATUS 523 - SL_DEVICE_GENERAL 524 - SL_DEVICE_IOT 525 526 \param[out] pOption Get configurations option: 527 - SL_DEVICE_STATUS: 528 - SL_DEVICE_EVENT_CLASS_DEVICE 529 - SL_DEVICE_EVENT_CLASS_WLAN 530 - SL_DEVICE_EVENT_CLASS_BSD 531 - SL_DEVICE_EVENT_CLASS_NETAPP 532 - SL_DEVICE_EVENT_CLASS_NETCFG 533 - SL_DEVICE_EVENT_CLASS_FS 534 - SL_DEVICE_GENERAL: 535 - SL_DEVICE_GENERAL_VERSION 536 - SL_DEVICE_GENERAL_DATE_TIME 537 - SL_DEVICE_GENERAL_PERSISTENT 538 - SL_DEVICE_IOT: 539 - SL_DEVICE_IOT_UDID 540 - SL_DEVICE_DICE_VERSION 541 542 \param[out] pConfigLen The length of the allocated memory as input, when the 543 function complete, the value of this parameter would be 544 the len that actually read from the device.\n 545 If the device return length that is longer from the input 546 value, the function will cut the end of the returned structure 547 and will return SL_ESMALLBUF 548 \param[out] pValues Get requested configurations values 549 \return Zero on success, or a negative value if an error occurred 550 \sa 551 \note 552 \warning 553 \par Examples 554 555 - Getting WLAN class status (status is always cleared on read): 556 \code 557 _u32 statusWlan; 558 _u8 pConfigOpt; 559 _u16 pConfigLen; 560 pConfigOpt = SL_DEVICE_EVENT_CLASS_WLAN; 561 pConfigLen = sizeof(_u32); 562 sl_DeviceGet(SL_DEVICE_STATUS,&pConfigOpt,&pConfigLen,(_u8 *)(&statusWlan)); 563 if (SL_DEVICE_STATUS_WLAN_STA_CONNECTED & statusWlan ) 564 { 565 printf("Device is connected\n"); 566 } 567 if (SL_DEVICE_EVENT_DROPPED_WLAN_RX_FILTERS & statusWlan ) 568 { 569 printf("RX filer event dropped\n"); 570 } 571 572 \endcode 573 <br> 574 575 - Getting version: 576 \code 577 SlDeviceVersion_t ver; 578 pConfigLen = sizeof(ver); 579 pConfigOpt = SL_DEVICE_GENERAL_VERSION; 580 sl_DeviceGet(SL_DEVICE_GENERAL,&pConfigOpt,&pConfigLen,(_u8 *)(&ver)); 581 printf("CHIP %d\nMAC 31.%d.%d.%d.%d\nPHY %d.%d.%d.%d\nNWP %d.%d.%d.%d\nROM %d\nHOST %d.%d.%d.%d\n", 582 ver.ChipId, 583 ver.FwVersion[0],ver.FwVersion[1], 584 ver.FwVersion[2],ver.FwVersion[3], 585 ver.PhyVersion[0],ver.PhyVersion[1], 586 ver.PhyVersion[2],ver.PhyVersion[3], 587 ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], 588 ver.RomVersion, 589 SL_MAJOR_VERSION_NUM,SL_MINOR_VERSION_NUM,SL_VERSION_NUM,SL_SUB_VERSION_NUM); 590 591 \endcode 592 <br> 593 594 - Getting Device time and date: 595 \code 596 SlDateTime_t dateTime = {0}; 597 _i16 configLen = sizeof(SlDateTime_t); 598 _i8 configOpt = SL_DEVICE_GENERAL_DATE_TIME; 599 sl_DeviceGet(SL_DEVICE_GENERAL,&configOpt, &configLen,(_u8 *)(&dateTime)); 600 601 printf("Day %d,Mon %d,Year %d,Hour %,Min %d,Sec %d\n",dateTime.tm_day,dateTime.tm_mon,dateTime.tm_year, 602 dateTime.tm_hour,dateTime.tm_min,dateTime.tm_sec); 603 \endcode 604 605 - Getting persistency system configuration: 606 \code 607 _i16 configLen = sizeof(_u8); 608 _i8 configOpt = SL_DEVICE_GENERAL_PERSISTENT; 609 sl_DeviceGet(SL_DEVICE_GENERAL,&configOpt, &configLen,&persistent); 610 \endcode 611 612 - Getting DICE version: 613 \code 614 _i8 ver[2] = {0}; 615 _i16 configSize = sizeof(ver); 616 _i8 configOpt = SL_DEVICE_DICE_VERSION; 617 618 sl_DeviceGet(SL_DEVICE_IOT, &configOpt, &configSize,(uint8_t*)(&ver)); 619 \endcode 620 621 */ 622 #if _SL_INCLUDE_FUNC(sl_DeviceGet) 623 _i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption,_u16 *pConfigLen, _u8 *pValues); 624 #endif 625 626 627 /*! 628 \brief Set asynchronous event mask 629 630 Mask asynchronous events from the device.\n 631 Masked events do not generate asynchronous messages from the device.\n 632 By default - all events are active 633 634 635 636 \param[in] EventClass The classification groups that the 637 mask is referred to. Need to be one of 638 the following: 639 - SL_DEVICE_EVENT_CLASS_DEVICE 640 - SL_DEVICE_EVENT_CLASS_WLAN 641 - SL_DEVICE_EVENT_CLASS_BSD 642 - SL_DEVICE_EVENT_CLASS_NETAPP 643 - SL_DEVICE_EVENT_CLASS_NETCFG 644 - SL_DEVICE_EVENT_CLASS_FS 645 646 647 \param[in] Mask Event Mask bitmap. Valid mask are (per group): 648 - SL_DEVICE_EVENT_CLASS_WLAN user events 649 - SL_WLAN_EVENT_CONNECT 650 - SL_WLAN_EVENT_P2P_CONNECT 651 - SL_WLAN_EVENT_DISCONNECT 652 - SL_WLAN_EVENT_P2P_DISCONNECT 653 - SL_WLAN_EVENT_STA_ADDED 654 - SL_WLAN_EVENT_STA_REMOVED 655 - SL_WLAN_EVENT_P2P_CLIENT_ADDED 656 - SL_WLAN_EVENT_P2P_CLIENT_REMOVED 657 - SL_WLAN_EVENT_P2P_DEVFOUND 658 - SL_WLAN_EVENT_P2P_REQUEST 659 - SL_WLAN_EVENT_P2P_CONNECTFAIL 660 - SL_WLAN_EVENT_PROVISIONING_STATUS 661 - SL_WLAN_EVENT_PROVISIONING_PROFILE_ADDED 662 - SL_WLAN_EVENT_RXFILTER 663 664 - SL_DEVICE_EVENT_CLASS_DEVICE user events 665 - SL_DEVICE_EVENT_ERROR 666 667 - SL_DEVICE_EVENT_CLASS_BSD user events 668 - SL_SOCKET_TX_FAILED_EVENT 669 - SL_SOCKET_ASYNC_EVENT 670 671 - SL_DEVICE_EVENT_CLASS_NETAPP user events 672 - SL_NETAPP_EVENT_IPV4_ACQUIRED 673 - SL_NETAPP_EVENT_IPV6_ACQUIRED 674 - SL_NETAPP_EVENT_DHCPV4_LEASED 675 - SL_NETAPP_EVENT_DHCPV4_RELEASED 676 - SL_NETAPP_EVENT_IP_COLLISION 677 - SL_NETAPP_EVENT_IPV4_LOST 678 - SL_NETAPP_EVENT_DHCP_IPV4_ACQUIRE_TIMEOUT 679 - SL_NETAPP_EVENT_IPV6_LOST 680 681 682 \return Zero on success, or a negative value if an error occurred 683 \par Persistent System Persistent 684 \sa sl_DeviceEventMaskGet 685 686 \note Belongs to \ref ext_api \n 687 \warning 688 \par Example 689 690 - Masking connection/disconnection async events from WLAN class: 691 \code 692 sl_DeviceEventMaskSet(SL_DEVICE_EVENT_CLASS_WLAN, (SL_DEVICE_EVENT_BIT(SL_WLAN_EVENT_CONNECT) | SL_DEVICE_EVENT_BIT(SL_WLAN_EVENT_DISCONNECT) ) ); 693 \endcode 694 */ 695 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskSet) 696 _i16 sl_DeviceEventMaskSet(const _u8 EventClass ,const _u32 Mask); 697 #endif 698 699 /*! 700 \brief Get current event mask of the device 701 702 Return the events bit mask from the device. In case event is 703 masked, the device will not send that event. 704 705 \param[in] EventClass The classification groups that the 706 mask is referred to. Need to be one of 707 the following: 708 - SL_DEVICE_EVENT_CLASS_GLOBAL 709 - SL_DEVICE_EVENT_CLASS_DEVICE 710 - SL_DEVICE_EVENT_CLASS_WLAN 711 - SL_DEVICE_EVENT_CLASS_BSD 712 - SL_DEVICE_EVENT_CLASS_NETAPP 713 - SL_DEVICE_EVENT_CLASS_NETCFG 714 - SL_DEVICE_EVENT_CLASS_FS 715 716 \param[out] pMask Pointer to mask bitmap where the 717 value should be stored. Bitmasks are the same as in \ref sl_DeviceEventMaskSet 718 719 \return Zero on success, or a negative value if an error occurred 720 721 \sa sl_DeviceEventMaskSet 722 723 \note Belongs to \ref ext_api 724 725 \warning 726 \par Example 727 728 - Getting an event mask for WLAN class: 729 \code 730 _u32 maskWlan; 731 sl_DeviceEventMaskGet(SL_DEVICE_EVENT_CLASS_WLAN,&maskWlan); 732 \endcode 733 */ 734 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskGet) 735 _i16 sl_DeviceEventMaskGet(const _u8 EventClass,_u32 *pMask); 736 #endif 737 738 739 /*! 740 \brief The SimpleLink task entry 741 742 This function must be called from the main loop or from dedicated thread in 743 the following cases: 744 - Non-Os Platform - should be called from the mail loop 745 - Multi Threaded Platform when the user does not implement the external spawn functions - 746 should be called from dedicated thread allocated to the SimpleLink driver. 747 In this mode the function never return. 748 749 \par parameters 750 None 751 752 \return None 753 \sa 754 \note Belongs to \ref basic_api 755 756 \warning This function must be called from a thread that is start running before 757 any call to other SimpleLink API 758 */ 759 #if _SL_INCLUDE_FUNC(sl_Task) 760 void* sl_Task(void* pEntry); 761 #endif 762 763 764 765 766 /*! 767 \brief Setting the internal uart mode 768 769 \param[in] pUartParams Pointer to the uart configuration parameter set: 770 - baudrate - up to 711 Kbps 771 - flow control - enable/disable 772 - comm port - the comm port number 773 774 \return On success zero is returned, otherwise - Failed. 775 \par Persistent Non- Persistent 776 \sa 777 \note Belongs to \ref basic_api 778 779 \warning This function must consider the host uart capability 780 */ 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 787 /*! 788 \brief Configure SimpleLink to default state. 789 790 The sl_WifiConfig function allows to configure the device 791 to a pre-configured state by sysconfig UI\ ti_drivers_net_wifi_Config.c. 792 The configuration of the SimpleLink Wifi is usually persistent, 793 and can be reconfigured at runtime. 794 Reconfiguration should be performed only when needed since 795 the process involves flash writes and might impact 796 system lifetime (flash write endurance) and power consumption. 797 798 It's important to note that this is one example for a 799 'restore to default state' function, 800 which meet the needs of this application. 801 User who wish to incorporate this function into he's app, 802 must adjust the implementation 803 and make sure it meets he's needs. 804 805 \return Upon successful completion, 806 the function shall return 0. 807 In case of failure, this function would return -1. 808 809 */ 810 _i32 sl_WifiConfig(); 811 812 /*! 813 \brief Start collecting Device statistics (including RX statistics), for unlimited time. 814 815 \par Parameters const _u32 Flags, for future use. 816 \return Zero on success, or negative error code on failure 817 818 \sa sl_DeviceStatStop sl_DeviceStatGet 819 \warning This API should replace and extend the existing API of sl_WlanRxStatStart. 820 sl_WlanRxStatStart, sl_WlanRxStatStop and sl_WlanRxStatGet are deprecated API's 821 and exist only for backwards compatibility reasons. 822 The recommendation is to use ONLY sl_DeviceStatStart, sl_DeviceStatGet and sl_DeviceStatStop 823 API's. 824 The new APIs (sl_DeviceStat) contains all the capabilities of the deprecated APIs (sl_WlanRxStat). 825 PAY ATTENTION: Once the user starts to work with one of the API's flow (sl_WlanRxStat/sl_DeviceStat) 826 the other cannot be called until sl_XXStatStop is called. 827 meaning: sl_WlanRxStat flow and sl_DeviceStat flow cannot run at the same time. 828 829 \par Example 830 831 - Getting Device statistics: 832 \code 833 void CollectStatistics() 834 { 835 SlDeviceGetStat_t deviceRXStat; // this struct is equivalent to SlWlanGetRxStatResponse_t 836 SlDeviceGetPmStat_t devicePMStat; // PM statistics (new statistics) 837 int ret = 0; 838 839 ret = sl_DeviceStatStart(0); // start statistics mode - only one mode can be use in parallel (as described above) 840 if (ret != 0) 841 { 842 //check ret error 843 } 844 845 sleep(1); // sleep for 1 sec 846 847 // this call is equivalent to sl_WlanRxStatGet(&rxStat,0) 848 ret = sl_DeviceStatGet(SL_DEVICE_STAT_WLAN_RX, sizeof(SlDeviceGetStat_t), &deviceRXStat); // statistics has been cleared upon read 849 850 if (ret != 0) 851 { 852 //check ret error 853 } 854 855 // new statistics 856 ret = sl_DeviceStatGet(SL_DEVICE_STAT_PM, sizeof(SlDeviceGetPmStat_t), &devicePMStat); // statistics has been cleared upon read 857 if (ret != 0) 858 { 859 //check ret error 860 } 861 862 // Use the statistics that has returned from the API's. 863 864 ret = sl_DeviceStatStop(0); 865 if (ret != 0) 866 { 867 //check ret error 868 } 869 870 871 } 872 \endcode 873 */ 874 _i16 sl_DeviceStatStart(const _u32 Flags); // start collecting the statistics 875 /*! 876 \brief Getting DEVICE statistics 877 878 \param[in] ConfigId - configuration id 879 - <b>SL_DEVICE_STAT_WLAN_RX</b> 880 - <b>SL_DEVICE_STAT_PM</b> 881 882 \param[in] length - length of output data 883 884 \param[out] buffer - buffer for the requested device statistics 885 \return Zero on success, or negative error code on failure 886 \sa sl_DeviceStatGet, sl_DeviceStatStart 887 \note 888 There is 2 prototypes of variable - Accumulated and Clear On Read. 889 -Accumulated data will be store from the init time of the system. 890 -Clear On Read data will be delete when 891 sl_DeviceStatGet(clear on read per ConfigId) or sl_DeviceStatStart(clear on read all the ConfigId's) are used. 892 The division between Accumulated and Clear On Read is at the internal struct. 893 For the Accumulated types store in: SlDeviceGetPmStatAcc_t struct. 894 and the Clear On Read types store in: SlDeviceGetPmStatClrOnRdTypes_t struct. 895 896 897 \warning 898 \par Examples 899 900 - SL_DEVICE_STAT_WLAN_RX: 901 \code 902 SlDeviceGetStat_t deviceRXStat; 903 _u16 length = sizeof(SlDeviceGetStat_t); 904 sl_DeviceStatGet(SL_DEVICE_STAT_WLAN_RX, length, &deviceRXStat); 905 \endcode 906 <br> 907 908 - SL_DEVICE_STAT_PM: 909 \code 910 SlDeviceGetPmStat_t devicePMStat; 911 _u16 length = sizeof(SlDeviceGetPmStat_t); 912 sl_DeviceStatGet(SL_DEVICE_STAT_PM, length, &devicePMStat); 913 \endcode 914 <br> 915 916 */ 917 _i16 sl_DeviceStatGet(const _u16 ConfigId,_u16 length,void* buffer); 918 /*! 919 \brief Stop collecting Device statistic, (if previous called sl_DeviceStatStart) 920 921 \par Parameters const _u32 Flags, for future use. 922 923 \return Zero on success, or negative error code on failure 924 925 \sa sl_DeviceStatStart sl_DeviceStatGet 926 927 \warning Cannot be use when sl_WlanRxStatStart in called. 928 */ 929 _i16 sl_DeviceStatStop(const _u32 Flags); 930 931 932 /*! 933 934 Close the Doxygen group. 935 @} 936 937 */ 938 939 940 941 #ifdef __cplusplus 942 } 943 #endif /* __cplusplus */ 944 945 #endif /* __DEVICE_H__ */ 946 947 948