TI's MQTT Demo with freertos CM4F

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fPtr_func.cpp Source File

fPtr_func.cpp

00001 /*
00002  *  - CC31xx/CC32xx Host Driver Implementation
00003  *
00004  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00005  *
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *    Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  *    Neither the name of Texas Instruments Incorporated nor the names of
00020  *    its contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036 
00037 #include "simplelink/cc3100_simplelink.h"
00038 
00039 #include "simplelink/cc3100.h"
00040 #include "simplelink/cc3100_driver.h"
00041 #include "simplelink/G_functions/fPtr_func.h"
00042 #include "simplelink/cc3100_nonos.h"
00043 #include "cli_uart.h"
00044 
00045 #include "cc3100_trace.h"
00046 
00047     
00048 using namespace mbed_cc3100;
00049        
00050 cc3100 _cc3100_(PB_9, PB_8, PD_12, PD_13, PD_11, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 
00057 #define PRINT_BUF_LEN    128
00058 extern int8_t print_buf[PRINT_BUF_LEN]; 
00059 
00060 /* General Events handling*/
00061 #if defined (EXT_LIB_REGISTERED_GENERAL_EVENTS)
00062 
00063 typedef _SlEventPropogationStatus_e (*general_callback) (SlDeviceEvent_t *);
00064 
00065 static const general_callback  general_callbacks[] =
00066 {
00067 #ifdef SlExtLib1GeneralEventHandler
00068     SlExtLib1GeneralEventHandler,
00069 #endif
00070 
00071 #ifdef SlExtLib2GeneralEventHandler
00072     SlExtLib2GeneralEventHandler,
00073 #endif
00074 
00075 #ifdef SlExtLib3GeneralEventHandler
00076     SlExtLib3GeneralEventHandler,
00077 #endif
00078 
00079 #ifdef SlExtLib4GeneralEventHandler
00080     SlExtLib4GeneralEventHandler,
00081 #endif
00082 
00083 #ifdef SlExtLib5GeneralEventHandler
00084     SlExtLib5GeneralEventHandler,
00085 #endif
00086 };
00087 
00088 #undef _SlDrvHandleGeneralEvents
00089 
00090 /********************************************************************
00091   _SlDrvHandleGeneralEvents
00092   Iterates through all the general(device) event handlers which are
00093   registered by   the external libs/user application.
00094 *********************************************************************/
00095 void _SlDrvHandleGeneralEvents(SlDeviceEvent_t *slGeneralEvent)
00096 {
00097     uint8_t i;
00098 
00099     /* Iterate over all the extenal libs handlers */
00100     for ( i = 0 ; i < sizeof(general_callbacks)/sizeof(general_callbacks[0]) ; i++ )
00101     {
00102         if (EVENT_PROPAGATION_BLOCK == general_callbacks[i](slGeneralEvent) )
00103         {
00104             /* exit immediately and do not call the user specific handler as well */
00105             return;
00106         }
00107     }
00108 
00109 /* At last call the Application specific handler if registered */
00110 #ifdef sl_GeneralEvtHdlr
00111     sl_GeneralEvtHdlr(slGeneralEvent);
00112 #endif
00113 
00114 }
00115 #endif
00116 
00117 
00118 
00119 /* WLAN Events handling*/
00120 
00121 #if defined (EXT_LIB_REGISTERED_WLAN_EVENTS)
00122 
00123 typedef _SlEventPropogationStatus_e (*wlan_callback) (SlWlanEvent_t *);
00124 
00125 static wlan_callback  wlan_callbacks[] =
00126 {
00127 #ifdef SlExtLib1WlanEventHandler
00128         SlExtLib1WlanEventHandler,
00129 #endif
00130 
00131 #ifdef SlExtLib2WlanEventHandler
00132         SlExtLib2WlanEventHandler,
00133 #endif
00134 
00135 #ifdef SlExtLib3WlanEventHandler
00136         SlExtLib3WlanEventHandler,
00137 #endif
00138 
00139 #ifdef SlExtLib4WlanEventHandler
00140         SlExtLib4WlanEventHandler,
00141 #endif
00142 
00143 #ifdef SlExtLib5WlanEventHandler
00144         SlExtLib5WlanEventHandler,
00145 #endif
00146 };
00147 
00148 #undef _SlDrvHandleWlanEvents
00149 
00150 /***********************************************************
00151   _SlDrvHandleWlanEvents
00152   Iterates through all the wlan event handlers which are
00153   registered by the external libs/user application.
00154 ************************************************************/
00155 void _SlDrvHandleWlanEvents(SlWlanEvent_t *slWlanEvent)
00156 {
00157     uint8_t i;
00158 
00159     /* Iterate over all the extenal libs handlers */
00160     for ( i = 0 ; i < sizeof(wlan_callbacks)/sizeof(wlan_callbacks[0]) ; i++ )
00161     {
00162         if ( EVENT_PROPAGATION_BLOCK == wlan_callbacks[i](slWlanEvent) )
00163         {
00164             /* exit immediately and do not call the user specific handler as well */
00165             return;
00166         }
00167     }
00168 
00169 /* At last call the Application specific handler if registered */
00170 #ifdef sl_WlanEvtHdlr
00171     sl_WlanEvtHdlr(slWlanEvent);
00172 #endif
00173 
00174 }
00175 #endif
00176 
00177 
00178 /* NetApp Events handling */
00179 #if defined (EXT_LIB_REGISTERED_NETAPP_EVENTS)
00180 
00181 typedef _SlEventPropogationStatus_e (*netApp_callback) (SlNetAppEvent_t *);
00182 
00183 static const netApp_callback  netApp_callbacks[] =
00184 {
00185 #ifdef SlExtLib1NetAppEventHandler
00186      SlExtLib1NetAppEventHandler,
00187 #endif
00188 
00189 #ifdef SlExtLib2NetAppEventHandler
00190      SlExtLib2NetAppEventHandler,
00191 #endif
00192 
00193 #ifdef SlExtLib3NetAppEventHandler
00194      SlExtLib3NetAppEventHandler,
00195 #endif
00196 
00197 #ifdef SlExtLib4NetAppEventHandler
00198      SlExtLib4NetAppEventHandler,
00199 #endif
00200 
00201 #ifdef SlExtLib5NetAppEventHandler
00202      SlExtLib5NetAppEventHandler,
00203 #endif
00204 };
00205 
00206 #undef _SlDrvHandleNetAppEvents
00207 
00208 /************************************************************
00209   _SlDrvHandleNetAppEvents
00210   Iterates through all the net app event handlers which are
00211   registered by   the external libs/user application.
00212 ************************************************************/
00213 void _SlDrvHandleNetAppEvents(SlNetAppEvent_t *slNetAppEvent)
00214 {
00215     uint8_t i;
00216 
00217     /* Iterate over all the extenal libs handlers */
00218     for ( i = 0 ; i < sizeof(netApp_callbacks)/sizeof(netApp_callbacks[0]) ; i++ )
00219     {
00220         if (EVENT_PROPAGATION_BLOCK == netApp_callbacks[i](slNetAppEvent) )
00221         {
00222             /* exit immediately and do not call the user specific handler as well */
00223             return;
00224         }
00225     }
00226 
00227 /* At last call the Application specific handler if registered */
00228 #ifdef sl_NetAppEvtHdlr
00229     sl_NetAppEvtHdlr(slNetAppEvent);
00230 #endif
00231 
00232 }
00233 #endif
00234 
00235 
00236 /* Http Server Events handling */
00237 #if defined (EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
00238 
00239 typedef _SlEventPropogationStatus_e (*httpServer_callback) (SlHttpServerEvent_t*, SlHttpServerResponse_t*);
00240 
00241 static const httpServer_callback  httpServer_callbacks[] =
00242 {
00243 #ifdef SlExtLib1HttpServerEventHandler
00244         SlExtLib1HttpServerEventHandler,
00245 #endif
00246 
00247 #ifdef SlExtLib2HttpServerEventHandler
00248         SlExtLib2HttpServerEventHandler,
00249 #endif
00250 
00251 #ifdef SlExtLib3HttpServerEventHandler
00252         SlExtLib3HttpServerEventHandler,
00253 #endif
00254 
00255 #ifdef SlExtLib4HttpServerEventHandler
00256         SlExtLib4HttpServerEventHandler,
00257 #endif
00258 
00259 #ifdef SlExtLib5HttpServerEventHandler
00260       SlExtLib5HttpServerEventHandler,
00261 #endif
00262 };
00263 
00264 #undef _SlDrvHandleHttpServerEvents
00265 
00266 /*******************************************************************
00267   _SlDrvHandleHttpServerEvents
00268   Iterates through all the http server event handlers which are
00269   registered by the external libs/user application.
00270 ********************************************************************/
00271 void _SlDrvHandleHttpServerEvents(SlHttpServerEvent_t *slHttpServerEvent, SlHttpServerResponse_t *slHttpServerResponse)
00272 {
00273     _u8 i;
00274 
00275     /* Iterate over all the external libs handlers */
00276     for ( i = 0 ; i < sizeof(httpServer_callbacks)/sizeof(httpServer_callbacks[0]) ; i++ )
00277     {
00278         if ( EVENT_PROPAGATION_BLOCK == httpServer_callbacks[i](slHttpServerEvent, slHttpServerResponse) )
00279         {
00280             /* exit immediately and do not call the user specific handler as well */
00281             return;
00282         }
00283     }
00284 
00285 /* At last call the Application specific handler if registered */
00286 #ifdef sl_HttpServerCallback
00287     sl_HttpServerCallback(slHttpServerEvent, slHttpServerResponse);
00288 #endif
00289 
00290 }
00291 #endif
00292 
00293 
00294 /* Socket Events */
00295 #if defined (EXT_LIB_REGISTERED_SOCK_EVENTS)
00296 
00297 typedef _SlEventPropogationStatus_e (*sock_callback) (SlSockEvent_t *);
00298 
00299 static const sock_callback  sock_callbacks[] =
00300 {
00301 #ifdef SlExtLib1SockEventHandler
00302         SlExtLib1SockEventHandler,
00303 #endif
00304 
00305 #ifdef SlExtLib2SockEventHandler
00306         SlExtLib2SockEventHandler,
00307 #endif
00308 
00309 #ifdef SlExtLib3SockEventHandler
00310         SlExtLib3SockEventHandler,
00311 #endif
00312 
00313 #ifdef SlExtLib4SockEventHandler
00314         SlExtLib4SockEventHandler,
00315 #endif
00316 
00317 #ifdef SlExtLib5SockEventHandler
00318         SlExtLib5SockEventHandler,
00319 #endif
00320 };
00321 
00322 /*************************************************************
00323   _SlDrvHandleSockEvents
00324   Iterates through all the socket event handlers which are
00325   registered by the external libs/user application.
00326 **************************************************************/
00327 void _SlDrvHandleSockEvents(SlSockEvent_t *slSockEvent)
00328 {
00329     uint8_t i;
00330 
00331     /* Iterate over all the external libs handlers */
00332     for ( i = 0 ; i < sizeof(sock_callbacks)/sizeof(sock_callbacks[0]) ; i++ )
00333     {
00334         if ( EVENT_PROPAGATION_BLOCK == sock_callbacks[i](slSockEvent) )
00335         {
00336             /* exit immediately and do not call the user specific handler as well */
00337             return;
00338         }
00339     }
00340 
00341 /* At last call the Application specific handler if registered */
00342 #ifdef sl_SockEvtHdlr
00343     sl_SockEvtHdlr(slSockEvent);
00344 #endif
00345 
00346 }
00347 
00348 #endif   
00349 
00350 /*!
00351     \brief This function handles ping report events
00352 
00353     \param[in]      pPingReport holds the ping report statistics
00354 
00355     \return         None
00356 
00357     \note
00358 
00359     \warning
00360 */
00361 void SimpleLinkPingReport(SlPingReport_t *pPingReport)
00362 {
00363     _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
00364 
00365     if(pPingReport == NULL)
00366         Uart_Write((uint8_t *)" [PING REPORT] NULL Pointer Error\r\n");
00367 
00368     g_PingPacketsRecv = pPingReport->PacketsReceived;
00369 }
00370 
00371 
00372 /*******************************************************************************/
00373 /*   _sl_HandleAsync_Accept */
00374 /*******************************************************************************/
00375 #ifndef SL_TINY_EXT
00376 void _sl_HandleAsync_Accept(void *pVoidBuf)
00377 {
00378     _SocketAddrResponse_u *pMsgArgs = (_SocketAddrResponse_u *)_SL_RESP_ARGS_START(pVoidBuf);
00379 
00380     _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
00381 
00382     VERIFY_PROTOCOL(( pMsgArgs->IpV4.sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
00383     VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
00384 
00385     memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs,sizeof(_SocketAddrResponse_u));
00386     _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00387 
00388     _cc3100_._driver._SlDrvProtectionObjUnLock();
00389     return;
00390 }
00391 
00392 /*******************************************************************************/
00393 /*   _sl_HandleAsync_Connect */
00394 /*******************************************************************************/
00395 void _sl_HandleAsync_Connect(void *pVoidBuf)
00396 {
00397     _SocketResponse_t *pMsgArgs = (_SocketResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00398 
00399     _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
00400 
00401     VERIFY_PROTOCOL((pMsgArgs->sd & BSD_SOCKET_ID_MASK) <= SL_MAX_SOCKETS);
00402     VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
00403 
00404     ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->sd = pMsgArgs->sd;
00405     ((_SocketResponse_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->statusOrLen = pMsgArgs->statusOrLen;
00406 
00407     _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00408     _cc3100_._driver._SlDrvProtectionObjUnLock();
00409     return;
00410 }
00411 
00412 /*******************************************************************************/
00413 /*   _sl_HandleAsync_Select */
00414 /*******************************************************************************/
00415 void _sl_HandleAsync_Select(void *pVoidBuf)
00416 {
00417     _SelectAsyncResponse_t     *pMsgArgs   = (_SelectAsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00418 
00419     _cc3100_._driver._SlDrvProtectionObjLockWaitForever();    
00420 
00421     VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
00422 
00423     memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_SelectAsyncResponse_t));
00424 
00425     _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00426     _cc3100_._driver._SlDrvProtectionObjUnLock();
00427 
00428     return;
00429 }
00430 
00431 #endif
00432 
00433 /******************************************************************************/
00434 /*  _sl_HandleAsync_DnsGetHostByName */
00435 /******************************************************************************/
00436 void _sl_HandleAsync_DnsGetHostByName(void *pVoidBuf)
00437 {
00438     _GetHostByNameIPv4AsyncResponse_t *pMsgArgs = (_GetHostByNameIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00439 
00440     _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
00441 
00442     VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
00443 
00444     /*IPv6 */
00445     if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
00446         memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv6AsyncResponse_t));
00447     }
00448     /*IPv4 */
00449     else 
00450     {
00451         memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_GetHostByNameIPv4AsyncResponse_t));
00452     }
00453     
00454     _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00455     _cc3100_._driver._SlDrvProtectionObjUnLock();
00456     
00457     return;
00458 }
00459 
00460 /******************************************************************************/
00461 
00462 /******************************************************************************
00463     _sl_HandleAsync_DnsGetHostByService
00464 
00465     CALLER          NWP - Async event on sl_DnsGetHostByService with IPv4 Family
00466 
00467 
00468     DESCRIPTION:
00469 
00470                     Async event on sl_DnsGetHostByService command with IPv4 Family.
00471                     Return service attributes like IP address, port and text according to service name.
00472                     The user sets a service name Full/Part (see example below), and should get the:
00473                     1. IP of the service
00474                     2. The port of service.
00475                     3. The text of service.
00476 
00477                     Hence it can make a connection to the specific service and use it.
00478                     It is similar to get host by name method.
00479 
00480                     It is done by a single shot query with PTR type on the service name.
00481 
00482 
00483 
00484                     Note:
00485                     1. The return's attributes are belonged to first service that is found.
00486                     It can be other services with the same service name will response to
00487                     the query. The results of these responses are saved in the peer cache of the NWP, and
00488                     should be read by another API.
00489 
00490 
00491         PARAMETERS:
00492 
00493                   pVoidBuf - is point to opcode of the event.
00494                   it contains the outputs that are given to the user
00495 
00496                   outputs description:
00497 
00498                    1.out_pAddr[]                    - output: Contain the IP address of the service.
00499                    2.out_pPort                      - output: Contain the port of the service.
00500                    3.inout_TextLen                  - Input:  Contain the max length of the text that the user wants to get.
00501                                                               it means that if the test of service is bigger that its value than
00502                                                               the text is cut to inout_TextLen value.
00503                                                       Output: Contain the length of the text that is returned. Can be full text or part
00504                                                               of the text (see above).
00505 
00506                    4.out_pText                      - Contain the text of the service (full or part see above- inout_TextLen description).
00507 
00508   *
00509 
00510 
00511     RETURNS:        success or fail.
00512 
00513 ******************************************************************************/
00514 #ifndef SL_TINY_EXT
00515 void _sl_HandleAsync_DnsGetHostByService(void *pVoidBuf)
00516 {
00517     _GetHostByServiceAsyncResponse_t* Res;
00518     uint16_t TextLen;
00519     uint16_t UserTextLen;
00520 
00521     /*pVoidBuf - is point to opcode of the event.*/
00522 
00523     /*set pMsgArgs to point to the attribute of the event.*/
00524     _GetHostByServiceIPv4AsyncResponse_t *pMsgArgs = (_GetHostByServiceIPv4AsyncResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00525 
00526     VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
00527 
00528     /*IPv6*/
00529     if(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) {
00530         return;
00531     }
00532     /*IPv4*/
00533     else {
00534         /*************************************************************************************************
00535 
00536         1. Copy the attribute part of the evnt to the attribute part of the response
00537         memcpy(g_pCB->GetHostByServiceCB.pAsyncRsp, pMsgArgs, sizeof(_GetHostByServiceIPv4AsyncResponse_t));
00538 
00539         set to TextLen the text length of the service.*/
00540         TextLen = pMsgArgs->TextLen;
00541 
00542         /*Res pointed to mDNS global object struct */
00543         Res = (_GetHostByServiceAsyncResponse_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs;
00544 
00545 
00546 
00547         /*It is 4 bytes so we avoid from memcpy*/
00548         Res->out_pAddr[0]   = pMsgArgs->Address;
00549         Res->out_pPort[0]   = pMsgArgs->Port;
00550         Res->Status         = pMsgArgs->Status;
00551 
00552         /*set to TextLen the text length of the user (input fromthe user).*/
00553         UserTextLen = Res->inout_TextLen[0];
00554 
00555         /*Cut the service text if the user requested for smaller text.*/
00556         UserTextLen = (TextLen <= UserTextLen) ? TextLen : UserTextLen;
00557         Res->inout_TextLen[0] = UserTextLen ;
00558 
00559         /**************************************************************************************************
00560 
00561         2. Copy the payload part of the evnt (the text) to the payload part of the response
00562         the lenght of the copy is according to the text length in the attribute part. */
00563 
00564 
00565         memcpy(Res->out_pText,
00566                   (int8_t *)(& pMsgArgs[1]),   /* & pMsgArgs[1] -> 1st byte after the fixed header = 1st byte of variable text.*/
00567                   UserTextLen);
00568 
00569 
00570         /**************************************************************************************************/
00571         _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00572         return;
00573     }
00574 }
00575 #endif
00576 
00577 /*****************************************************************************/
00578 /*  _sl_HandleAsync_PingResponse */
00579 /*****************************************************************************/
00580 #ifndef SL_TINY_EXT
00581 void _sl_HandleAsync_PingResponse(void *pVoidBuf)
00582 {
00583     _PingReportResponse_t *pMsgArgs  = (_PingReportResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00584     SlPingReport_t pingReport;
00585 
00586     if(pPingCallBackFunc) {
00587         _cc3100_._netapp.CopyPingResultsToReport(pMsgArgs,&pingReport);
00588         pPingCallBackFunc(&pingReport);
00589     } else {
00590 
00591         _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
00592         VERIFY_SOCKET_CB(NULL != g_pCB->PingCB.PingAsync.pAsyncRsp);
00593 
00594         if (NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs) {
00595             memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_PingReportResponse_t));
00596             _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00597         }
00598         _cc3100_._driver._SlDrvProtectionObjUnLock();
00599     }
00600     return;
00601 }
00602 #endif
00603 
00604 /* ******************************************************************************/
00605 /*  _SlDrvMsgReadSpawnCtx                                                       */
00606 /* ******************************************************************************/
00607 _SlReturnVal_t _SlDrvMsgReadSpawnCtx(void *pValue)
00608 {
00609 
00610 #ifdef SL_POLLING_MODE_USED
00611     int16_t retCode = OSI_OK;
00612     /*  for polling based systems */
00613     do {
00614         retCode = _cc3100_._nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, 0);
00615         if ( OSI_OK != retCode ) {
00616             if (TRUE == g_pCB->IsCmdRespWaited) {
00617                 OSI_RET_OK_CHECK( _cc3100_._nonos.sl_SyncObjSignal(&g_pCB->CmdSyncObj) );
00618                 return SL_RET_CODE_OK;
00619             }
00620         }
00621 
00622     } while (OSI_OK != retCode);
00623 
00624 #else 
00625 #ifndef SL_PLATFORM_MULTI_THREADED
00626     _cc3100_._driver._SlDrvObjLockWaitForever(&g_pCB->GlobalLockObj); 
00627 //    OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) );
00628 #else    
00629     OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->GlobalLockObj, SL_OS_WAIT_FOREVER) );
00630 #endif    
00631 #endif    
00632     g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/*  buffer must be allocated by _SlDrvMsgRead */
00633     g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler= NULL;
00634     g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;/* init to illegal value and verify it's overwritten with the valid one */
00635 
00636     /*  Messages might have been read by CmdResp context. Therefore after */
00637     /*  getting LockObj, check again where the Pending Rx Msg is still present. */
00638     if(FALSE == (_cc3100_._driver._SL_PENDING_RX_MSG(g_pCB))) {
00639 #ifndef SL_PLATFORM_MULTI_THREADED
00640         _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj);       
00641 //        OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj));
00642 #else        
00643         OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj));
00644 #endif        
00645         return SL_RET_CODE_OK;
00646     }
00647    
00648     VERIFY_RET_OK(_cc3100_._driver._SlDrvMsgRead());
00649 
00650     g_pCB->RxDoneCnt++;
00651 
00652     switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) {
00653         case ASYNC_EVT_CLASS:
00654             /*  If got here and protected by LockObj a message is waiting  */
00655             /*  to be read */
00656             VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
00657 
00658             _cc3100_._driver._SlAsyncEventGenericHandler();
00659 
00660 #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC)
00661             g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;
00662 #else
00663             free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf);
00664 #endif
00665             break;
00666         case DUMMY_MSG_CLASS:
00667         case RECV_RESP_CLASS:
00668             /* These types are legal in this context. Do nothing */
00669             break;
00670         case CMD_RESP_CLASS:
00671             /* Command response is illegal in this context. */
00672             /* No 'break' here: Assert! */
00673         default:
00674             VERIFY_PROTOCOL(0);
00675     }
00676 #ifndef SL_PLATFORM_MULTI_THREADED
00677     _cc3100_._driver._SlDrvObjUnLock(&g_pCB->GlobalLockObj);
00678 //    OSI_RET_OK_CHECK(_cc3100_._nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj));
00679 #else    
00680     OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->GlobalLockObj));
00681 #endif    
00682     return(SL_RET_CODE_OK);   
00683 
00684 }
00685 
00686 /***************************************************************************
00687 _sl_HandleAsync_Stop - handles stop signalling to
00688 a waiting object
00689 ****************************************************************************/
00690 void _sl_HandleAsync_Stop(void *pVoidBuf)
00691 {
00692     _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
00693 
00694     VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
00695 
00696     _cc3100_._driver._SlDrvProtectionObjLockWaitForever();
00697 
00698     memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
00699     _cc3100_._driver._SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
00700     _cc3100_._driver._SlDrvProtectionObjUnLock();
00701     return;
00702 }
00703 
00704 /******************************************************************************
00705 _SlDrvDeviceEventHandler - handles internally device async events
00706 ******************************************************************************/
00707 void _SlDrvDeviceEventHandler(void *pArgs)
00708 {
00709     _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
00710    
00711     switch(pHdr->GenHeader.Opcode) {
00712         case SL_OPCODE_DEVICE_INITCOMPLETE:
00713             _cc3100_._sl_HandleAsync_InitComplete(pHdr);
00714             
00715             break;
00716         case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
00717             _sl_HandleAsync_Stop(pHdr);
00718             
00719             break;
00720         
00721 
00722         case SL_OPCODE_DEVICE_ABORT:
00723             {
00724 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
00725                 SlDeviceEvent_t      devHandler;
00726                 devHandler.Event = SL_DEVICE_ABORT_ERROR_EVENT; 
00727                 devHandler.EventData.deviceReport.AbortType = *((uint32_t*)pArgs + 2);
00728                 devHandler.EventData.deviceReport.AbortData = *((uint32_t*)pArgs + 3);
00729                 _SlDrvHandleGeneralEvents(&devHandler);
00730 #endif      
00731             }
00732         break;    
00733         case  SL_OPCODE_DEVICE_DEVICEASYNCFATALERROR:
00734 #if defined (sl_GeneralEvtHdlr) || defined(EXT_LIB_REGISTERED_GENERAL_EVENTS)
00735         {
00736             _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
00737             SlDeviceEvent_t devHandler;
00738             devHandler.Event = SL_DEVICE_FATAL_ERROR_EVENT;
00739             devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF;
00740             devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF);
00741             _SlDrvHandleGeneralEvents(&devHandler);
00742         }
00743 #endif
00744         break;
00745         default:
00746             SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
00747             //printf("ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
00748             
00749     }
00750 }
00751 
00752 /*****************************************************************************/
00753 /* _SlDrvNetAppEventHandler */
00754 /*****************************************************************************/
00755 void _SlDrvNetAppEventHandler(void *pArgs)
00756 {
00757     _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)pArgs;
00758 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)
00759     SlHttpServerEvent_t     httpServerEvent;    
00760     SlHttpServerResponse_t  httpServerResponse;
00761 #endif
00762     switch(pHdr->GenHeader.Opcode) {
00763         case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE:
00764         case SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE_V6:
00765             _sl_HandleAsync_DnsGetHostByName(pArgs);
00766             break;
00767 #ifndef SL_TINY_EXT             
00768         case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE:
00769         case SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE_V6:
00770             _sl_HandleAsync_DnsGetHostByService(pArgs);
00771             break;
00772         case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE:
00773             _sl_HandleAsync_PingResponse(pArgs);
00774             break;
00775 #endif
00776 
00777 #if defined(sl_HttpServerCallback) || defined(EXT_LIB_REGISTERED_HTTP_SERVER_EVENTS)            
00778         case SL_OPCODE_NETAPP_HTTPGETTOKENVALUE: {
00779 
00780             uint8_t *pTokenName;
00781             slHttpServerData_t Token_value;
00782             sl_NetAppHttpServerGetToken_t *httpGetToken = (sl_NetAppHttpServerGetToken_t *)_SL_RESP_ARGS_START(pHdr);
00783             pTokenName = (uint8_t *)((sl_NetAppHttpServerGetToken_t *)httpGetToken + 1);
00784 
00785             httpServerResponse.Response = SL_NETAPP_HTTPSETTOKENVALUE;
00786             httpServerResponse.ResponseData.token_value.len = MAX_TOKEN_VALUE_LEN;
00787 
00788             /* Reuse the async buffer for getting the token value response from the user */
00789             httpServerResponse.ResponseData.token_value.data = (uint8_t *)_SL_RESP_ARGS_START(pHdr) + MAX_TOKEN_NAME_LEN;
00790             httpServerEvent.Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT;
00791 
00792             httpServerEvent.EventData.httpTokenName.len = httpGetToken->token_name_len;
00793             httpServerEvent.EventData.httpTokenName.data = pTokenName;
00794 
00795             Token_value.token_name =  pTokenName;
00796 
00797             _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse);
00798 
00799             Token_value.value_len = httpServerResponse.ResponseData.token_value.len;
00800             Token_value.name_len = httpServerEvent.EventData.httpTokenName.len;
00801 
00802             Token_value.token_value = httpServerResponse.ResponseData.token_value.data;
00803 
00804 
00805             _cc3100_._netapp.sl_NetAppSendTokenValue(&Token_value);
00806 #endif
00807         }
00808         break;
00809 
00810         case SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE: {
00811 #ifdef sl_HttpServerCallback
00812             uint8_t *pPostParams;
00813 
00814             sl_NetAppHttpServerPostToken_t *httpPostTokenArgs = (sl_NetAppHttpServerPostToken_t *)_SL_RESP_ARGS_START(pHdr);
00815             pPostParams = (uint8_t *)((sl_NetAppHttpServerPostToken_t *)httpPostTokenArgs + 1);
00816 
00817             httpServerEvent.Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT;
00818 
00819             httpServerEvent.EventData.httpPostData.action.len = httpPostTokenArgs->post_action_len;
00820             httpServerEvent.EventData.httpPostData.action.data = pPostParams;
00821             pPostParams+=httpPostTokenArgs->post_action_len;
00822 
00823             httpServerEvent.EventData.httpPostData.token_name.len = httpPostTokenArgs->token_name_len;
00824             httpServerEvent.EventData.httpPostData.token_name.data = pPostParams;
00825             pPostParams+=httpPostTokenArgs->token_name_len;
00826 
00827             httpServerEvent.EventData.httpPostData.token_value.len = httpPostTokenArgs->token_value_len;
00828             httpServerEvent.EventData.httpPostData.token_value.data = pPostParams;
00829 
00830             httpServerResponse.Response = SL_NETAPP_RESPONSE_NONE;
00831 
00832 
00833             _SlDrvHandleHttpServerEvents (&httpServerEvent, &httpServerResponse);
00834         }
00835         break;
00836 #endif        
00837         default:
00838             SL_ERROR_TRACE2(MSG_305, "ASSERT: _SlDrvNetAppEventHandler : invalid opcode = 0x%x = %i", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
00839             VERIFY_PROTOCOL(0);
00840     }
00841 }
00842 
00843 /*
00844  * ASYNCHRONOUS EVENT HANDLERS -- Start
00845  */
00846 
00847 /*!
00848     \brief This function handles WLAN events
00849 
00850     \param[in]      pWlanEvent is the event passed to the handler
00851 
00852     \return         None
00853 
00854     \note
00855 
00856     \warning
00857 */
00858 #if (defined(sl_WlanEvtHdlr))
00859 void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
00860 {
00861     unsigned char  g_ucConnectionSSID[32+1]; //Connection SSID
00862     unsigned char  g_ucConnectionBSSID[6]; //Connection BSSID
00863     
00864     if(pWlanEvent == NULL)
00865         Uart_Write((uint8_t *)" [WLAN EVENT] NULL Pointer Error \n\r");
00866 
00867     switch(pWlanEvent->Event) {
00868         case SL_WLAN_CONNECT_EVENT: {
00869             _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
00870             
00871             // Copy new connection SSID and BSSID to global parameters
00872             memcpy(g_ucConnectionSSID,pWlanEvent->EventData.
00873                    STAandP2PModeWlanConnected.ssid_name,
00874                    pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len);
00875             memcpy(g_ucConnectionBSSID,
00876                    pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid,
00877                    SL_BSSID_LENGTH);
00878             memset(print_buf, 0x00, PRINT_BUF_LEN);
00879             sprintf((char*) print_buf, "[WLAN EVENT] STA Connected to the AP: %s ,""BSSID: %x:%x:%x:%x:%x:%x\n\r",
00880                        g_ucConnectionSSID,g_ucConnectionBSSID[0],
00881                        g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
00882                        g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
00883                        g_ucConnectionBSSID[5]);
00884             Uart_Write((uint8_t *) print_buf);           
00885             /*
00886              * Information about the connected AP (like name, MAC etc) will be
00887              * available in 'slWlanConnectAsyncResponse_t' - Applications
00888              * can use it if required
00889              *
00890              * slWlanConnectAsyncResponse_t *pEventData = NULL;
00891              * pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
00892              *
00893              */
00894         }
00895         break;
00896 
00897         case SL_WLAN_DISCONNECT_EVENT: {
00898             slWlanConnectAsyncResponse_t*  pEventData = NULL;
00899 
00900             _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
00901             _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);
00902 
00903             pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;
00904 
00905             /* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */
00906             if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) {
00907                 memset(print_buf, 0x00, PRINT_BUF_LEN);
00908                 sprintf((char*) print_buf, "[WLAN EVENT]Device disconnected from the AP: %s,"
00909                     "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r",
00910                            g_ucConnectionSSID,g_ucConnectionBSSID[0],
00911                            g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
00912                            g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
00913                            g_ucConnectionBSSID[5]);
00914                 Uart_Write((uint8_t *) print_buf);
00915             } else {
00916                 memset(print_buf, 0x00, PRINT_BUF_LEN);
00917                 sprintf((char*) print_buf, "[WLAN ERROR]Device disconnected from the AP AP: %s,"
00918                         "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r",
00919                            g_ucConnectionSSID,g_ucConnectionBSSID[0],
00920                            g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
00921                            g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
00922                            g_ucConnectionBSSID[5]);
00923                 Uart_Write((uint8_t *) print_buf);            
00924             }
00925             memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID));
00926             memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID));
00927         }
00928         break;
00929 
00930         case SL_WLAN_STA_CONNECTED_EVENT: {
00931             _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
00932         }
00933         break;
00934 
00935         case SL_WLAN_STA_DISCONNECTED_EVENT: {
00936             _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_STA_CONNECTED);
00937             _cc3100_.CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
00938         }
00939         break;
00940 
00941         default: {
00942             memset(print_buf, 0x00, PRINT_BUF_LEN);
00943             sprintf((char*) print_buf, "[WLAN EVENT] Unexpected event [0x%x]\n\r",pWlanEvent->Event);
00944             Uart_Write((uint8_t *) print_buf); 
00945         }
00946         break;
00947     }
00948 }
00949 #endif
00950 
00951 /*!
00952     \brief This function handles events for IP address acquisition via DHCP
00953            indication
00954 
00955     \param[in]      pNetAppEvent is the event passed to the handler
00956 
00957     \return         None
00958 
00959     \note
00960 
00961     \warning
00962 */
00963 #if (defined(sl_NetAppEvtHdlr))
00964 void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
00965 {
00966     
00967     if(pNetAppEvent == NULL){
00968         Uart_Write((uint8_t *)" [NETAPP EVENT] NULL Pointer Error \n\r");
00969     }
00970     
00971     switch(pNetAppEvent->Event) {
00972         case SL_NETAPP_IPV4_IPACQUIRED_EVENT: {
00973             SlIpV4AcquiredAsync_t *pEventData = NULL;
00974             _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);            
00975             pEventData = &pNetAppEvent->EventData.ipAcquiredV4;           
00976             g_GatewayIP = pEventData->gateway;
00977             
00978             memset(print_buf, 0x00, PRINT_BUF_LEN);
00979             sprintf((char*) print_buf, "[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , ""Gateway=%d.%d.%d.%d\n\r",
00980             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3),
00981             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2),
00982             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1),
00983             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0),
00984             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3),
00985             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2),
00986             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1),
00987             _cc3100_._netcfg.SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0));
00988             Uart_Write((uint8_t *) print_buf);
00989         }
00990         break;
00991 
00992         case SL_NETAPP_IP_LEASED_EVENT: {           
00993             g_StationIP = pNetAppEvent->EventData.ipLeased.ip_address;          
00994             _cc3100_.SET_STATUS_BIT(g_Status, STATUS_BIT_IP_LEASED);
00995                        
00996         }
00997         break;
00998 
00999         default: {
01000             memset(print_buf, 0x00, PRINT_BUF_LEN);
01001             sprintf((char*) print_buf, "[NETAPP EVENT] Unexpected event [0x%x] \n\r",pNetAppEvent->Event);
01002             Uart_Write((uint8_t *) print_buf);
01003         }
01004         break;
01005     }
01006 }
01007 #endif 
01008 
01009 /*!
01010     \brief This function handles socket events indication
01011 
01012     \param[in]      pSock is the event passed to the handler
01013 
01014     \return         None
01015 */
01016 #if (defined(sl_SockEvtHdlr))
01017 void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
01018 {
01019     if(pSock == NULL)
01020         Uart_Write((uint8_t *)" [SOCK EVENT] NULL Pointer Error \n\r");
01021     
01022     switch( pSock->Event )
01023     {
01024         case SL_SOCKET_TX_FAILED_EVENT:
01025             /*
01026              * TX Failed
01027              *
01028              * Information about the socket descriptor and status will be
01029              * available in 'SlSockEventData_t' - Applications can use it if
01030              * required
01031              *
01032              * SlSockEventData_t *pEventData = NULL;
01033              * pEventData = & pSock->EventData;
01034              */
01035             
01036             switch( pSock->socketAsyncEvent.SockTxFailData.status )
01037             {
01038                 case SL_ECLOSE:
01039                     Uart_Write((uint8_t *)" [SOCK EVENT] Close socket operation, failed to transmit all queued packets\n\r");
01040                     break;
01041                 default:
01042                      memset(print_buf, 0x00, PRINT_BUF_LEN);
01043                      sprintf((char*) print_buf, "[SOCK ERROR] - TX FAILED : socket %d , reason""(%d) \n\n", pSock->socketAsyncEvent.SockTxFailData.sd, pSock->socketAsyncEvent.SockTxFailData.status);           
01044                      Uart_Write((uint8_t *) print_buf);
01045                  
01046                     break;
01047             }
01048             break;
01049 
01050         default:
01051             memset(print_buf, 0x00, PRINT_BUF_LEN);
01052             sprintf((char*) print_buf, "[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event);
01053             Uart_Write((uint8_t *) print_buf);
01054             break;
01055     }
01056 }
01057 #endif
01058 
01059 /*!
01060     \brief This function handles callback for the HTTP server events
01061 
01062     \param[in]      pHttpEvent - Contains the relevant event information
01063     \param[in]      pHttpResponse - Should be filled by the user with the
01064                     relevant response information
01065 
01066     \return         None
01067 
01068     \note
01069 
01070     \warning
01071 */
01072 #if (defined(sl_HttpServerCallback))
01073 void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
01074 {
01075     /*
01076      * This application doesn't work with HTTP server - Hence these
01077      * events are not handled here
01078      */
01079     Uart_Write((uint8_t *)" [HTTP EVENT] Unexpected event \n\r");
01080 }
01081 #endif
01082 /*!
01083     \brief This function handles general error events indication
01084 
01085     \param[in]      pDevEvent is the event passed to the handler
01086 
01087     \return         None
01088 */
01089 #if (defined(sl_GeneralEvtHdlr))
01090 void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
01091 {
01092     /*
01093      * Most of the general errors are not FATAL are are to be handled
01094      * appropriately by the application
01095      */
01096     memset(print_buf, 0x00, PRINT_BUF_LEN);
01097     sprintf((char*) print_buf, "[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n", pDevEvent->EventData.deviceEvent.status, pDevEvent->EventData.deviceEvent.sender); 
01098     Uart_Write((uint8_t *) print_buf);
01099 }
01100 #endif
01101 
01102 #ifdef  __cplusplus
01103 }
01104 #endif /*  __cplusplus */
01105 
01106 //}//namespace