1 /*
2  * user.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017-2019 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 *   user.h - CC31xx/CC32xx Host Driver Implementation
39 ******************************************************************************/
40 
41 #ifndef __USER_H__
42 #define __USER_H__
43 
44 #ifdef  __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 #include <string.h>
50 #include <ti/drivers/net/wifi/porting/cc_pal.h>
51 
52 typedef signed int _SlFd_t;
53 
54 #define SL_TIMESTAMP_MAX_VALUE                    (_u32)(0xFFFFFFFF)
55 
56 /*!
57  ******************************************************************************
58 
59     \defgroup   configuration_mem_mgm             Configuration - Memory Management
60 
61     This section declare in which memory management model the SimpleLink driver
62     will run:
63         -# Static
64         -# Dynamic
65 
66     This section IS NOT REQUIRED in case Static model is selected.
67 
68     The default memory model is Static
69 
70 
71     @{
72 
73  *****************************************************************************
74 */
75 
76 /*!
77     \brief      Defines whether the SimpleLink driver is working in dynamic
78                 memory model or not
79 
80                 When defined, the SimpleLink driver use dynamic allocations
81                 if dynamic allocation is selected malloc and free functions
82                 must be retrieved
83 
84     \sa
85 
86     \note       belongs to \ref configuration_sec
87 
88     \warning
89 */
90 
91 #define SL_MEMORY_MGMT_DYNAMIC
92 
93 #ifdef SL_MEMORY_MGMT_DYNAMIC
94 
95 
96 #include <stdlib.h>
97 /*!
98     \brief
99     \sa
100     \note           belongs to \ref configuration_sec
101     \warning
102 */
103 #define sl_Malloc(Size)                                 malloc(Size)
104 
105 /*!
106     \brief
107     \sa
108     \note           belongs to \ref configuration_sec
109     \warning
110 */
111 #define sl_Free(pMem)                                   free(pMem)
112 #endif
113 
114 
115 /*!
116 
117  Close the Doxygen group.
118  @}
119 
120 */
121 
122 /*!
123 
124     \def        MAX_CONCURRENT_ACTIONS
125 
126     \brief      Defines the maximum number of concurrent action in the system
127                 Min:1 , Max: 32
128 
129                 Actions which has async events as return, will be blocked until the event arrive
130 
131     \sa
132 
133     \note       In case there are not enough resources for the actions needed in the system,
134                 error is received: SL_POOL_IS_EMPTY
135                 one option is to increase MAX_CONCURRENT_ACTIONS
136                 (improves performance but results in memory consumption)
137                 Other option is to call the API later (decrease performance)
138 
139                 Async events which arrive during command context will be dynamically or static
140                 allocated and handled in spawn context. If MAX_CONCURRENT_ACTIONS
141                 is high, there will be more events which might arrive during this period.
142                 Due to memory constrains MAX_CONCURRENT_ACTIONS is lower in static allocation mode.
143 
144 
145     \warning    In case of setting to one, recommend to use non-blocking recv\recvfrom to allow
146                 multiple socket recv
147 */
148 
149 #ifdef SL_MEMORY_MGMT_DYNAMIC
150 #define MAX_CONCURRENT_ACTIONS 18
151 #else
152 #define MAX_CONCURRENT_ACTIONS 5
153 #endif
154 
155 
156     /*!
157     \def        SL_MAX_ASYNC_BUFFERS
158 
159 
160 
161     \brief      Defines the maximum static buffers to store asycn events which
162                 arrives during command context. The event is stored in a buffer (if free)
163                 and handle in spwan cotext. value must be set to MAX_CONCURRENT_ACTIONS which
164                 is the maximum simultaniuos async event which could arrive in command context.
165     value:      MAX_CONCURRENT_ACTIONS
166 
167     \sa
168 
169     \note       Events which arrive when there is no free buffer will be dropped.
170                 If there is a command which is waiting on this event, it will be released
171                 with error SL_RET_CODE_NO_FREE_ASYNC_BUFFERS_ERROR.
172                 In this case need to increase MAX_CONCURRENT_ACTIONS
173                 (improves performance but results in memory consumption)
174 
175 
176     */
177 
178 #define SL_MAX_ASYNC_BUFFERS  MAX_CONCURRENT_ACTIONS
179 /*!
180     \def        CPU_FREQ_IN_MHZ
181     \brief      Defines CPU frequency for Host side, for better accuracy of busy loops, if any
182     \sa
183     \note
184 
185     \warning    If not set the default CPU frequency is set to 200MHz
186                 This option will be deprecated in future release
187 */
188 
189 /* #define CPU_FREQ_IN_MHZ        80 */
190 
191 
192 
193 /*!
194     \def        SL_RUNTIME_EVENT_REGISTERATION
195 
196     \brief      Defines whether the SimpleLink driver uses dynamic event registration
197                 or static precompiled event mechanism
198     \sa
199 
200     \note       belongs to \ref configuration_sec
201 
202 */
203 #define SL_RUNTIME_EVENT_REGISTERATION
204 
205 
206 /*!
207     \def        SL_INC_ARG_CHECK
208 
209     \brief      Defines whether the SimpleLink driver perform argument check
210                 or not
211 
212                 When defined, the SimpleLink driver perform argument check on
213                 function call. Removing this define could reduce some code
214                 size and improve slightly the performances but may impact in
215                 unpredictable behavior in case of invalid arguments
216 
217     \sa
218 
219     \note       belongs to \ref configuration_sec
220 
221     \warning    Removing argument check may cause unpredictable behavior in
222                 case of invalid arguments.
223                 In this case the user is responsible to argument validity
224                 (for example all handlers must not be NULL)
225 */
226 #define SL_INC_ARG_CHECK
227 
228 
229 /*!
230     \brief      Defines whether to include extended API in SimpleLink driver
231                 or not
232 
233                 When defined, the SimpleLink driver will include also all
234                 extended API of the included packages
235 
236     \sa         ext_api
237 
238     \note       belongs to \ref configuration_sec
239 
240     \warning
241 */
242 #define SL_INC_EXT_API
243 
244 
245 /*!
246     \brief      Defines whether to include WLAN package in SimpleLink driver
247                 or not
248 
249                 When defined, the SimpleLink driver will include also
250                 the WLAN package
251 
252     \sa
253 
254     \note       belongs to \ref configuration_sec
255 
256     \warning
257 */
258 #define SL_INC_WLAN_PKG
259 
260 
261 /*!
262     \brief      Defines whether to include SOCKET package in SimpleLink
263                 driver or not
264 
265                 When defined, the SimpleLink driver will include also
266                 the SOCKET package
267 
268     \sa
269 
270     \note       belongs to \ref configuration_sec
271 
272     \warning
273 */
274 #define SL_INC_SOCKET_PKG
275 
276 
277 /*!
278     \brief      Defines whether to include NET_APP package in SimpleLink
279                 driver or not
280 
281                 When defined, the SimpleLink driver will include also the
282                 NET_APP package
283 
284     \sa
285 
286     \note       belongs to \ref configuration_sec
287 
288     \warning
289 */
290 #define SL_INC_NET_APP_PKG
291 
292 
293 /*!
294     \brief      Defines whether to include NET_CFG package in SimpleLink
295                 driver or not
296 
297                 When defined, the SimpleLink driver will include also
298                 the NET_CFG package
299 
300     \sa
301 
302     \note       belongs to \ref configuration_sec
303 
304     \warning
305 */
306 #define SL_INC_NET_CFG_PKG
307 
308 
309 /*!
310     \brief      Defines whether to include NVMEM package in SimpleLink
311                 driver or not
312 
313                 When defined, the SimpleLink driver will include also the
314                 NVMEM package
315 
316     \sa
317 
318     \note       belongs to \ref configuration_sec
319 
320     \warning
321 */
322 #define SL_INC_NVMEM_PKG
323 
324 
325 /*!
326     \brief      Defines whether to include NVMEM extended package in SimpleLink
327                 driver or not
328 
329                 When defined, the SimpleLink driver will include also the
330                 NVMEM extended package
331 
332     \sa
333 
334     \note       belongs to \ref nvmem_ext
335 
336     \warning
337 */
338 #define SL_INC_NVMEM_EXT_PKG
339 
340 
341 /*!
342     \brief      Defines whether to include socket server side APIs
343                 in SimpleLink driver or not
344 
345                 When defined, the SimpleLink driver will include also socket
346                 server side APIs
347 
348     \sa         server_side
349 
350     \note
351 
352     \warning
353 */
354 #define SL_INC_SOCK_SERVER_SIDE_API
355 
356 
357 /*!
358     \brief      Defines whether to include socket client side APIs in SimpleLink
359                 driver or not
360 
361                 When defined, the SimpleLink driver will include also socket
362                 client side APIs
363 
364     \sa         client_side
365 
366     \note       belongs to \ref configuration_sec
367 
368     \warning
369 */
370 #define SL_INC_SOCK_CLIENT_SIDE_API
371 
372 
373 /*!
374     \brief      Defines whether to include socket receive APIs in SimpleLink
375                 driver or not
376 
377                 When defined, the SimpleLink driver will include also socket
378                 receive side APIs
379 
380     \sa         recv_api
381 
382     \note       belongs to \ref configuration_sec
383 
384     \warning
385 */
386 #define SL_INC_SOCK_RECV_API
387 
388 
389 /*!
390     \brief      Defines whether to include socket send APIs in SimpleLink
391                 driver or not
392 
393                 When defined, the SimpleLink driver will include also socket
394                 send side APIs
395 
396     \sa         send_api
397 
398     \note       belongs to \ref configuration_sec
399 
400     \warning
401 */
402 #define SL_INC_SOCK_SEND_API
403 
404 
405 /*!
406 
407  Close the Doxygen group.
408  @}
409 
410  */
411 
412 
413 /*!
414  ******************************************************************************
415 
416     \defgroup   configuration_enable_device       Configuration - Device Enable/Disable
417 
418     The enable/disable API provide mechanism to enable/disable the network processor
419 
420 
421     porting ACTION:
422         - None
423     @{
424 
425  ******************************************************************************
426  */
427 
428 /*!
429     \brief      Preamble to the enabling the Network Processor.
430                         Placeholder to implement any pre-process operations
431                         before enabling networking operations.
432 
433     \sa         sl_DeviceEnable
434 
435     \note       belongs to \ref configuration_sec
436 
437 */
438 #define sl_DeviceEnablePreamble()
439 
440 
441 
442 /*!
443     \brief      Enable the Network Processor
444 
445     \sa         sl_DeviceDisable
446 
447     \note       belongs to \ref configuration_sec
448 
449 */
450 #define sl_DeviceEnable()           NwpPowerOn()
451 
452 
453 /*!
454     \brief      Disable the Network Processor
455 
456     \sa         sl_DeviceEnable
457 
458     \note       belongs to \ref configuration_sec
459 */
460 #define sl_DeviceDisable()          NwpPowerOff()
461 
462 
463 /*!
464 
465  Close the Doxygen group.
466  @}
467 
468  */
469 
470 /*!
471  ******************************************************************************
472 
473     \defgroup   configuration_interface         Configuration - Communication Interface
474 
475     The SimpleLink device supports several standard communication protocol among SPI and
476     UART. CC32XX Host Driver implements SPI Communication Interface
477 
478 
479     \note           In CC32XX, SPI implementation uses DMA in order to increase the utilization
480             of the communication channel. If user prefers to user UART, these interfaces
481             need to be redefined
482 
483 
484     porting ACTION:
485         - None
486 
487     @{
488 
489  ******************************************************************************
490 */
491 
492 #define _SlFd_t                 Fd_t
493 
494 
495 /*!
496     \brief      Opens an interface communication port to be used for communicating
497                 with a SimpleLink device
498 
499                 Given an interface name and option flags, this function opens
500                 the communication port and creates a file descriptor.
501                 This file descriptor is used afterwards to read and write
502                 data from and to this specific communication channel.
503                 The speed, clock polarity, clock phase, chip select and all other
504                 specific attributes of the channel are all should be set to hardcoded
505                 in this function.
506 
507     \param      ifName  -   points to the interface name/path. The interface name is an
508                             optional attributes that the SimpleLink driver receives
509                             on opening the driver (sl_Start).
510                             In systems that the spi channel is not implemented as
511                             part of the os device drivers, this parameter could be NULL.
512 
513     \param      flags   -   optional flags parameters for future use
514 
515     \return     upon successful completion, the function shall open the channel
516                 and return a non-negative integer representing the file descriptor.
517                 Otherwise, -1 shall be returned
518 
519     \sa         sl_IfClose , sl_IfRead , sl_IfWrite
520 
521     \note       The prototype of the function is as follow:
522                     Fd_t xxx_IfOpen(char* pIfName , unsigned long flags);
523 
524     \note       belongs to \ref configuration_sec
525 
526     \warning
527 */
528 #define sl_IfOpen                           spi_Open
529 
530 
531 /*!
532     \brief      Closes an opened interface communication port
533 
534     \param      fd  -   file descriptor of opened communication channel
535 
536     \return     upon successful completion, the function shall return 0.
537                 Otherwise, -1 shall be returned
538 
539     \sa         sl_IfOpen , sl_IfRead , sl_IfWrite
540 
541     \note       The prototype of the function is as follow:
542                     int xxx_IfClose(Fd_t Fd);
543 
544     \note       belongs to \ref configuration_sec
545 
546     \warning
547 */
548 #define sl_IfClose                          spi_Close
549 
550 
551 /*!
552     \brief      Attempts to read up to len bytes from an opened communication channel
553                 into a buffer starting at pBuff.
554 
555     \param      fd      -   file descriptor of an opened communication channel
556 
557     \param      pBuff   -   pointer to the first location of a buffer that contains enough
558                             space for all expected data
559 
560     \param      len     -   number of bytes to read from the communication channel
561 
562     \return     upon successful completion, the function shall return the number of read bytes.
563                 Otherwise, 0 shall be returned
564 
565     \sa         sl_IfClose , sl_IfOpen , sl_IfWrite
566 
567 
568     \note       The prototype of the function is as follow:
569                     int xxx_IfRead(Fd_t Fd , char* pBuff , int Len);
570 
571     \note       belongs to \ref configuration_sec
572 
573     \warning
574 */
575 #define sl_IfRead                           spi_Read
576 
577 
578 /*!
579     \brief attempts to write up to len bytes to the SPI channel
580 
581     \param      fd      -   file descriptor of an opened communication channel
582 
583     \param      pBuff   -   pointer to the first location of a buffer that contains
584                             the data to send over the communication channel
585 
586     \param      len     -   number of bytes to write to the communication channel
587 
588     \return     upon successful completion, the function shall return the number of sent bytes.
589                 therwise, 0 shall be returned
590 
591     \sa         sl_IfClose , sl_IfOpen , sl_IfRead
592 
593     \note       This function could be implemented as zero copy and return only upon successful completion
594                 of writing the whole buffer, but in cases that memory allocation is not too tight, the
595                 function could copy the data to internal buffer, return back and complete the write in
596                 parallel to other activities as long as the other SPI activities would be blocked until
597                 the entire buffer write would be completed
598 
599                The prototype of the function is as follow:
600                     int xxx_IfWrite(Fd_t Fd , char* pBuff , int Len);
601 
602     \note       belongs to \ref configuration_sec
603 
604     \warning
605 */
606 #define sl_IfWrite                          spi_Write
607 
608 
609 /*!
610     \brief      register an interrupt handler routine for the host IRQ
611 
612     \param      InterruptHdl    -   pointer to interrupt handler routine
613 
614     \param      pValue          -   pointer to a memory structure that is passed
615                                     to the interrupt handler.
616 
617     \return     upon successful registration, the function shall return 0.
618                 Otherwise, -1 shall be returned
619 
620     \sa
621 
622     \note       If there is already registered interrupt handler, the function
623                 should overwrite the old handler with the new one
624 
625     \note       If the handler is a null pointer, the function should un-register the
626                 interrupt handler, and the interrupts can be disabled.
627 
628     \note       belongs to \ref configuration_sec
629 
630     \warning
631 */
632 #define sl_IfRegIntHdlr(InterruptHdl , pValue)          NwpRegisterInterruptHandler(InterruptHdl , pValue)
633 
634 
635 /*!
636     \brief      Masks the Host IRQ
637 
638     \sa     sl_IfUnMaskIntHdlr
639 
640 
641 
642     \note       belongs to \ref configuration_sec
643 
644     \warning
645 */
646 #define sl_IfMaskIntHdlr()                              NwpMaskInterrupt()
647 
648 
649 /*!
650     \brief      Unmasks the Host IRQ
651 
652     \sa     sl_IfMaskIntHdlr
653 
654 
655 
656     \note       belongs to \ref configuration_sec
657 
658     \warning
659 */
660 #define sl_IfUnMaskIntHdlr()                            NwpUnMaskInterrupt()
661 
662 
663 /*!
664     \brief      Write Handers for statistics debug on write
665 
666     \param      interface handler   -   pointer to interrupt handler routine
667 
668 
669     \return     no return value
670 
671     \sa
672 
673     \note       An optional hooks for monitoring before and after write info
674 
675     \note       belongs to \ref configuration_sec
676 
677     \warning
678 */
679 /* #define SL_START_WRITE_STAT */
680 
681 #ifdef SL_START_WRITE_STAT
682 #define sl_IfStartWriteSequence
683 #define sl_IfEndWriteSequence
684 #endif
685 
686 
687 /*!
688     \brief      Get the timer counter value (timestamp).
689                 The timer must count from zero to its MAX value.
690 
691     \param      None.
692 
693 
694     \return     Returns 32-bit timer counter value (ticks unit)
695 
696     \sa
697 
698     \note
699 
700     \note       belongs to \ref porting_sec
701 
702     \warning
703 */
704 
705 #undef slcb_GetTimestamp
706 /* A timer must be started before using this function */
707 #define slcb_GetTimestamp           TimerGetCurrentTimestamp
708 
709 
710 /*!
711     \brief      This macro wait for the NWP to raise a ready for shutdown indication.
712 
713     \param      None.
714 
715     \note       This function is unique for the CC32XX family
716 
717     \warning
718 */
719 
720 #define WAIT_NWP_SHUTDOWN_READY          NwpWaitForShutDownInd()
721 
722 /*!
723     \brief      User's errno setter function. User must provide an errno setter
724                 in order to let the SimpleLink Wi-Fi driver to support BSD API
725                 alongside the user's errno mechanism.
726 
727     \param      None.
728 
729     \sa         SL_INC_INTERNAL_ERRNO
730 
731     \note
732 
733     \note       belongs to \ref porting_sec
734 
735     \warning
736 */
737 #ifndef SL_INC_INTERNAL_ERRNO
738 /*
739  * Zephyr Port: use Zephyr SDK's errno.h definitions, and supply those missing
740  * to allow the SimpleLink driver.c to compile
741  * Also, supply the external errno setter function.
742  */
743 #include <errno.h>
744 #define ERROR  EIO
745 #define INEXE  EALREADY
746 #define ENSOCK ENFILE
747 
748 extern int dpl_set_errno(int err);
749 #define slcb_SetErrno dpl_set_errno
750 
751 #endif
752 
753 /*!
754  Close the Doxygen group.
755  @}
756 
757 */
758 
759 /*!
760  ******************************************************************************
761 
762     \defgroup   configuration_os          Configuration - Operating System
763 
764     The SimpleLink driver could run on two kind of platforms:
765        -# Non-Os / Single Threaded (default)
766        -# Multi-Threaded
767 
768     CC32XX SimpleLink Host Driver is ported on both Non-Os and Multi Threaded OS enviroment.
769     The Host driver is made OS independent by implementing an OS Abstraction layer.
770     Reference implementation for OS Abstraction is available for FreeRTOS and TI-RTOS.
771 
772 
773     If you choose to work in multi-threaded environment under different operating system you
774     will have to provide some basic adaptation routines to allow the driver to protect access to
775     resources for different threads (locking object) and to allow synchronization between threads
776     (sync objects). In additional the driver support running without dedicated thread allocated solely
777     to the SimpleLink driver. If you choose to work in this mode, you should also supply a spawn
778     method that will enable to run function on a temporary context.
779 
780     \note - This Macro is defined in the IDE to generate Driver for both OS and Non-OS
781 
782      porting ACTION:
783          - None
784 
785      @{
786 
787  ******************************************************************************
788 */
789 
790 /*
791 #define SL_PLATFORM_MULTI_THREADED
792 */
793 
794 #ifdef SL_PLATFORM_MULTI_THREADED
795 
796 /*!
797     \brief
798     \sa
799     \note           belongs to \ref configuration_sec
800     \warning
801 */
802 #define SL_OS_RET_CODE_OK                       ((int)OS_OK)
803 
804 /*!
805     \brief
806     \sa
807     \note           belongs to \ref configuration_sec
808     \warning
809 */
810 #define SL_OS_WAIT_FOREVER                      ((uint32_t)OS_WAIT_FOREVER)
811 
812 /*!
813     \brief
814     \sa
815     \note           belongs to \ref configuration_sec
816     \warning
817 */
818 #define SL_OS_NO_WAIT                           ((uint32_t)OS_NO_WAIT)
819 
820 /*!
821     \brief type definition for a time value
822 
823     \note   On each configuration or platform the type could be whatever is needed - integer, pointer to structure etc.
824 
825     \note       belongs to \ref configuration_sec
826 */
827 #define _SlTime_t               uint32_t
828 
829 
830 
831 
832 /*!
833     \brief  type definition for a sync object container
834 
835     Sync object is object used to synchronize between two threads or thread and interrupt handler.
836     One thread is waiting on the object and the other thread send a signal, which then
837     release the waiting thread.
838     The signal must be able to be sent from interrupt context.
839     This object is generally implemented by binary semaphore or events.
840 
841     \note   On each configuration or platform the type could be whatever is needed - integer, structure etc.
842 
843     \note       belongs to \ref configuration_sec
844 */
845 #define _SlSyncObj_t                sem_t
846 
847 
848 /*!
849     \brief  This function creates a sync object
850 
851     The sync object is used for synchronization between different thread or ISR and
852     a thread.
853 
854     \param  pSyncObj    -   pointer to the sync object control block
855 
856     \return upon successful creation the function should return 0
857             Otherwise, a negative value indicating the error code shall be returned
858 
859     \note       belongs to \ref configuration_sec
860     \warning
861 */
862 #define sl_SyncObjCreate(pSyncObj,pName)             sem_init(pSyncObj, 0, 0)
863 
864 
865 /*!
866     \brief  This function deletes a sync object
867 
868     \param  pSyncObj    -   pointer to the sync object control block
869 
870     \return upon successful deletion the function should return 0
871             Otherwise, a negative value indicating the error code shall be returned
872     \note       belongs to \ref configuration_sec
873     \warning
874 */
875 #define sl_SyncObjDelete(pSyncObj)                  sem_destroy(pSyncObj)
876 
877 
878 /*!
879     \brief      This function generates a sync signal for the object.
880 
881     All suspended threads waiting on this sync object are resumed
882 
883     \param      pSyncObj    -   pointer to the sync object control block
884 
885     \return     upon successful signaling the function should return 0
886                 Otherwise, a negative value indicating the error code shall be returned
887     \note       the function could be called from ISR context
888     \warning
889 */
890 #define sl_SyncObjSignal(pSyncObj)                sem_post(pSyncObj)
891 
892 
893 /*!
894     \brief      This function generates a sync signal for the object from Interrupt
895 
896     This is for RTOS that should signal from IRQ using a dedicated API
897 
898     \param      pSyncObj    -   pointer to the sync object control block
899 
900     \return     upon successful signaling the function should return 0
901                 Otherwise, a negative value indicating the error code shall be returned
902     \note       the function could be called from ISR context
903     \warning
904 */
905 #define sl_SyncObjSignalFromIRQ(pSyncObj)           sem_post(pSyncObj)
906 
907 
908 /*!
909     \brief  This function waits for a sync signal of the specific sync object
910 
911     \param  pSyncObj    -   pointer to the sync object control block
912     \param  Timeout     -   numeric value specifies the maximum number of mSec to
913                             stay suspended while waiting for the sync signal
914                             Currently, the SimpleLink driver uses these values:
915                                 - OSI_NO_WAIT
916                                 - SL_DRIVER_TIMEOUT_SHORT
917                                 - SL_DRIVER_TIMEOUT_LONG
918                                 - SL_OS_WAIT_FOREVER
919     \return                 upon successful reception of the signal within the timeout window return 0
920                             Otherwise, a negative value indicating the error code shall be returned
921     \note                   belongs to \ref configuration_sec
922     \warning
923 */
924 #define sl_SyncObjWait(pSyncObj,Timeout)            Semaphore_pend_handle(pSyncObj,Timeout)
925 
926 
927 /*!
928     \brief  This function return the value for a counting semaphore
929 
930     \param  pSyncObj    -   pointer to the sync object control block
931     \param  pValue      -   return value for the counting semaphore
932 
933     \note                   belongs to \ref configuration_sec
934     \warning
935 */
936 #define sl_SyncObjGetCount(pSyncObj,pValue)         sem_getvalue(pSyncObj, pValue);
937 
938 /*!
939     \brief  type definition for a locking object container
940 
941     Locking object are used to protect a resource from mutual accesses of two or more threads.
942     The locking object should support reentrant locks by a signal thread.
943     This object is generally implemented by mutex semaphore
944 
945     \note   On each configuration or platform the type could be whatever is needed - integer, structure etc.
946     \note       belongs to \ref configuration_sec
947 */
948 #define _SlLockObj_t                         pthread_mutex_t
949 
950 /*!
951     \brief  This function creates a locking object.
952 
953     The locking object is used for protecting a shared resources between different
954     threads.
955 
956     \param  pLockObj    -   pointer to the locking object control block
957 
958     \return upon successful creation the function should return 0
959             Otherwise, a negative value indicating the error code shall be returned
960     \note       belongs to \ref configuration_sec
961     \warning
962 */
963 #define sl_LockObjCreate(pLockObj, pName)     Mutex_create_handle(pLockObj)
964 
965 
966 /*!
967     \brief  This function deletes a locking object.
968 
969     \param  pLockObj    -   pointer to the locking object control block
970 
971     \return upon successful deletion the function should return 0
972             Otherwise, a negative value indicating the error code shall be returned
973     \note       belongs to \ref configuration_sec
974     \warning
975 */
976 #define sl_LockObjDelete(pLockObj)                  pthread_mutex_destroy(pLockObj)
977 
978 
979 /*!
980     \brief  This function locks a locking object.
981 
982     All other threads that call this function before this thread calls
983     the osi_LockObjUnlock would be suspended
984 
985     \param  pLockObj    -   pointer to the locking object control block
986     \param  Timeout     -   numeric value specifies the maximum number of mSec to
987                             stay suspended while waiting for the locking object
988                             Currently, the SimpleLink driver uses only two values:
989                                 - OSI_WAIT_FOREVER
990                                 - OSI_NO_WAIT
991 
992 
993     \return upon successful reception of the locking object the function should return 0
994             Otherwise, a negative value indicating the error code shall be returned
995     \note       belongs to \ref configuration_sec
996     \warning
997 */
998 #define sl_LockObjLock(pLockObj,Timeout)          pthread_mutex_lock(pLockObj)
999 
1000 
1001 /*!
1002     \brief  This function return the thread ID
1003 
1004     \return upon successful return the thread ID
1005             Otherwise, return NULL
1006     \note       belongs to \ref configuration_sec
1007     \warning
1008 */
1009 #define sl_GetThreadID()                  pthread_self()
1010 
1011 /*!
1012     \brief  This function unlock a locking object.
1013 
1014     \param  pLockObj    -   pointer to the locking object control block
1015 
1016     \return upon successful unlocking the function should return 0
1017             Otherwise, a negative value indicating the error code shall be returned
1018     \note       belongs to \ref configuration_sec
1019     \warning
1020 */
1021 #define sl_LockObjUnlock(pLockObj)                  pthread_mutex_unlock(pLockObj)
1022 
1023 #else
1024 
1025 /*!
1026     \brief  type definition for a sync object container
1027 
1028     Sync object is object used to synchronize between two threads or thread and interrupt handler.
1029     One thread is waiting on the object and the other thread send a signal, which then
1030     release the waiting thread.
1031     The signal must be able to be sent from interrupt context.
1032     This object is generally implemented by binary semaphore or events.
1033 
1034     \note   On each configuration or platform the type could be whatever is needed - integer, structure etc.
1035 
1036     \note       belongs to \ref configuration_sec
1037 */
1038 #define _SlSyncObj_t                SemaphoreP_Handle
1039 
1040 
1041 /*!
1042     \brief  This function creates a sync object
1043 
1044     The sync object is used for synchronization between different thread or ISR and
1045     a thread.
1046 
1047     \param  pSyncObj    -   pointer to the sync object control block
1048 
1049     \return upon successful creation the function should return 0
1050             Otherwise, a negative value indicating the error code shall be returned
1051 
1052     \note       belongs to \ref configuration_sec
1053     \warning
1054 */
1055 #define sl_SyncObjCreate(pSyncObj,pName)            SemaphoreP_create_handle(pSyncObj)
1056 
1057 
1058 /*!
1059     \brief  This function deletes a sync object
1060 
1061     \param  pSyncObj    -   pointer to the sync object control block
1062 
1063     \return upon successful deletion the function should return 0
1064             Otherwise, a negative value indicating the error code shall be returned
1065     \note       belongs to \ref configuration_sec
1066     \warning
1067 */
1068 #define sl_SyncObjDelete(pSyncObj)                  SemaphoreP_delete_handle(pSyncObj)
1069 
1070 
1071 /*!
1072     \brief      This function generates a sync signal for the object.
1073 
1074     All suspended threads waiting on this sync object are resumed
1075 
1076     \param      pSyncObj    -   pointer to the sync object control block
1077 
1078     \return     upon successful signaling the function should return 0
1079                 Otherwise, a negative value indicating the error code shall be returned
1080     \note       the function could be called from ISR context
1081     \warning
1082 */
1083 #define sl_SyncObjSignal(pSyncObj)                SemaphoreP_post_handle(pSyncObj)
1084 
1085 
1086 /*!
1087     \brief      This function generates a sync signal for the object from Interrupt
1088 
1089     This is for RTOS that should signal from IRQ using a dedicated API
1090 
1091     \param      pSyncObj    -   pointer to the sync object control block
1092 
1093     \return     upon successful signaling the function should return 0
1094                 Otherwise, a negative value indicating the error code shall be returned
1095     \note       the function could be called from ISR context
1096     \warning
1097 */
1098 #define sl_SyncObjSignalFromIRQ(pSyncObj)           SemaphoreP_post_handle(pSyncObj)
1099 
1100 
1101 /*!
1102     \brief  This function waits for a sync signal of the specific sync object
1103 
1104     \param  pSyncObj    -   pointer to the sync object control block
1105     \param  Timeout     -   numeric value specifies the maximum number of mSec to
1106                             stay suspended while waiting for the sync signal
1107                             Currently, the SimpleLink driver uses only two values:
1108                                 - OSI_WAIT_FOREVER
1109                                 - OSI_NO_WAIT
1110 
1111     \return upon successful reception of the signal within the timeout window return 0
1112             Otherwise, a negative value indicating the error code shall be returned
1113     \note       belongs to \ref configuration_sec
1114     \warning
1115 */
1116 #define sl_SyncObjWait(pSyncObj,Timeout)            SemaphoreP_pend((*(pSyncObj)),Timeout)
1117 
1118 
1119 
1120 #define sl_SyncObjGetCount(pSyncObj,pValue)
1121 /*!
1122     \brief  type definition for a locking object container
1123 
1124     Locking object are used to protect a resource from mutual accesses of two or more threads.
1125     The locking object should support reentrant locks by a signal thread.
1126     This object is generally implemented by mutex semaphore
1127 
1128     \note   On each configuration or platform the type could be whatever is needed - integer, structure etc.
1129     \note       belongs to \ref configuration_sec
1130 */
1131 #define _SlLockObj_t                         MutexP_Handle
1132 
1133 /*!
1134     \brief  This function creates a locking object.
1135 
1136     The locking object is used for protecting a shared resources between different
1137     threads.
1138 
1139     \param  pLockObj    -   pointer to the locking object control block
1140 
1141     \return upon successful creation the function should return 0
1142             Otherwise, a negative value indicating the error code shall be returned
1143     \note       belongs to \ref configuration_sec
1144     \warning
1145 */
1146 #define sl_LockObjCreate(pLockObj, pName)     Mutex_create_handle(pLockObj)
1147 
1148 
1149 /*!
1150     \brief  This function deletes a locking object.
1151 
1152     \param  pLockObj    -   pointer to the locking object control block
1153 
1154     \return upon successful deletion the function should return 0
1155             Otherwise, a negative value indicating the error code shall be returned
1156     \note       belongs to \ref configuration_sec
1157     \warning
1158 */
1159 #define sl_LockObjDelete(pLockObj)                  MutexP_delete_handle(pLockObj)
1160 
1161 
1162 /*!
1163     \brief  This function locks a locking object.
1164 
1165     All other threads that call this function before this thread calls
1166     the osi_LockObjUnlock would be suspended
1167 
1168     \param  pLockObj    -   pointer to the locking object control block
1169     \param  Timeout     -   numeric value specifies the maximum number of mSec to
1170                             stay suspended while waiting for the locking object
1171                             Currently, the SimpleLink driver uses only two values:
1172                                 - OSI_WAIT_FOREVER
1173                                 - OSI_NO_WAIT
1174 
1175 
1176     \return upon successful reception of the locking object the function should return 0
1177             Otherwise, a negative value indicating the error code shall be returned
1178     \note       belongs to \ref configuration_sec
1179     \warning
1180 */
1181 #define sl_LockObjLock(pLockObj,Timeout)          Mutex_lock(*(pLockObj))
1182 
1183 
1184 /*!
1185     \brief  This function unlock a locking object.
1186 
1187     \param  pLockObj    -   pointer to the locking object control block
1188 
1189     \return upon successful unlocking the function should return 0
1190             Otherwise, a negative value indicating the error code shall be returned
1191     \note       belongs to \ref configuration_sec
1192     \warning
1193 */
1194 #define sl_LockObjUnlock(pLockObj)                   Mutex_unlock(*(pLockObj))
1195 
1196 #endif
1197 
1198 /*!
1199     \brief  This function call the pEntry callback from a different context
1200 
1201     \param  pEntry      -   pointer to the entry callback function
1202 
1203     \param  pValue      -   pointer to any type of memory structure that would be
1204                             passed to pEntry callback from the execution thread.
1205 
1206     \param  flags       -   execution flags - reserved for future usage
1207 
1208     \return upon successful registration of the spawn the function should return 0
1209             (the function is not blocked till the end of the execution of the function
1210             and could be returned before the execution is actually completed)
1211             Otherwise, a negative value indicating the error code shall be returned
1212     \note       belongs to \ref configuration_sec
1213 
1214     \warning                User must implement it's own 'os_Spawn' function.
1215 */
1216 /* Zephyr Port provides its own os_Spawn() implementation */
1217 #define SL_PLATFORM_EXTERNAL_SPAWN
1218 
1219 #ifdef SL_PLATFORM_EXTERNAL_SPAWN
1220 extern  _i16 os_Spawn(P_OS_SPAWN_ENTRY pEntry, void *pValue, unsigned long flags);
1221 #define sl_Spawn(pEntry,pValue,flags)       os_Spawn(pEntry,pValue,flags)
1222 #endif
1223 
1224 
1225 
1226 /*!
1227     \brief  This function return the number of ticks in 10ms
1228 
1229     \return Number of ticks in 10ms
1230     \note
1231     \warning
1232 */
1233 #define SL_TIMESTAMP_TICKS_IN_10_MILLISECONDS     (10000/ClockP_getSystemTickPeriod())
1234 /*!
1235  *
1236  Close the Doxygen group.
1237  @}
1238 
1239  */
1240 
1241 /*!
1242  ******************************************************************************
1243 
1244     \defgroup       configuration_events      Configuration - Event Handlers
1245 
1246     This section includes the asynchronous event handlers routines
1247 
1248     porting ACTION:
1249         -define your routine as the value of this handler
1250 
1251     @{
1252 
1253  ******************************************************************************
1254  */
1255 
1256 
1257 
1258 /*!
1259     \brief      Fatal Error async event for inspecting fatal error events.
1260                 This event handles events/errors reported from the device/host driver
1261 
1262     \param[out] pSlFatalErrorEvent
1263 
1264     \par
1265              Parameters:
1266 
1267              - <b> slFatalErrorEvent->Id = SL_DEVICE_EVENT_FATAL_DEVICE_ABORT </b>,
1268 
1269              - <b> slFatalErrorEvent->Id = SL_DEVICE_EVENT_FATAL_DRIVER_ABORT </b>,
1270 
1271              - <b> slFatalErrorEvent->Id = SL_DEVICE_EVENT_FATAL_NO_CMD_ACK </b>,
1272 
1273              - <b> slFatalErrorEvent->Id = SL_DEVICE_EVENT_FATAL_SYNC_LOSS </b>,
1274 
1275              - <b> slFatalErrorEvent->Id = SL_DEVICE_EVENT_FATAL_CMD_TIMEOUT </b>,
1276 
1277 
1278     \note       belongs to \ref configuration_sec
1279 
1280     \warning
1281 */
1282 
1283 #define slcb_DeviceFatalErrorEvtHdlr      SimpleLinkFatalErrorEventHandler
1284 
1285 /*!
1286     \brief      General async event for inspecting general events.
1287                 This event handles events/errors reported from the device/host driver
1288     \sa
1289 
1290     \note       belongs to \ref configuration_sec
1291 
1292     \warning
1293 */
1294 
1295 #define slcb_DeviceGeneralEvtHdlr         SimpleLinkGeneralEventHandler
1296 
1297 /*!
1298     \brief WLAN Async event handler
1299 
1300     \param[out]      pSlWlanEvent   pointer to SlWlanEvent_t data
1301 
1302     \par
1303              Parameters:
1304 
1305              - <b>pSlWlanEvent->Event = SL_WLAN_CONNECT_EVENT </b>, STA or P2P client connection indication event
1306                  - pSlWlanEvent->EventData.STAandP2PModeWlanConnected main fields:
1307                       - ssid_name
1308                       - ssid_len
1309                       - bssid
1310                       - go_peer_device_name
1311                       - go_peer_device_name_len
1312 
1313              - <b>pSlWlanEvent->Event = SL_WLAN_DISCONNECT_EVENT </b>, STA or P2P client disconnection event
1314                  - pSlWlanEvent->EventData.STAandP2PModeDisconnected main fields:
1315                       - ssid_name
1316                       - ssid_len
1317                       - reason_code
1318 
1319              - <b>pSlWlanEvent->Event = SL_WLAN_STA_CONNECTED_EVENT </b>, AP/P2P(Go) connected STA/P2P(Client)
1320                   - pSlWlanEvent->EventData.APModeStaConnected fields:
1321                       - go_peer_device_name
1322                       - mac
1323                       - go_peer_device_name_len
1324                       - wps_dev_password_id
1325                       - own_ssid:  relevant for event sta-connected only
1326                       - own_ssid_len:  relevant for event sta-connected only
1327 
1328              - <b>pSlWlanEvent->Event = SL_WLAN_STA_DISCONNECTED_EVENT </b>, AP/P2P(Go) disconnected STA/P2P(Client)
1329                   - pSlWlanEvent->EventData.APModestaDisconnected fields:
1330                       - go_peer_device_name
1331                       - mac
1332                       - go_peer_device_name_len
1333                       - wps_dev_password_id
1334                       - own_ssid:  relevant for event sta-connected only
1335                       - own_ssid_len:  relevant for event sta-connected only
1336 
1337              - <b>pSlWlanEvent->Event = SL_WLAN_SMART_CONFIG_COMPLETE_EVENT </b>
1338                   - pSlWlanEvent->EventData.smartConfigStartResponse fields:
1339                      - status
1340                      - ssid_len
1341                      - ssid
1342                      - private_token_len
1343                      - private_token
1344 
1345              - <b>pSlWlanEvent->Event = SL_WLAN_SMART_CONFIG_STOP_EVENT </b>
1346                      - pSlWlanEvent->EventData.smartConfigStopResponse fields:
1347                          - status
1348 
1349              - <b>pSlWlanEvent->Event = SL_WLAN_P2P_DEV_FOUND_EVENT </b>
1350                      - pSlWlanEvent->EventData.P2PModeDevFound fields:
1351                          - go_peer_device_name
1352                          - mac
1353                          - go_peer_device_name_len
1354                          - wps_dev_password_id
1355                          - own_ssid:  relevant for event sta-connected only
1356                          - own_ssid_len:  relevant for event sta-connected only
1357 
1358              - <b>pSlWlanEvent->Event = SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT </b>
1359                       - pSlWlanEvent->EventData.P2PModeNegReqReceived fields
1360                           - go_peer_device_name
1361                           - mac
1362                           - go_peer_device_name_len
1363                           - wps_dev_password_id
1364                           - own_ssid:  relevant for event sta-connected only
1365 
1366              - <b>pSlWlanEvent->Event = SL_WLAN_CONNECTION_FAILED_EVENT </b>, P2P only
1367                        - pSlWlanEvent->EventData.P2PModewlanConnectionFailure fields:
1368                            - status
1369 
1370     \sa
1371 
1372     \note           belongs to \ref configuration_sec
1373 
1374     \warning
1375 */
1376 
1377 #define slcb_WlanEvtHdlr                     SimpleLinkWlanEventHandler
1378 
1379 
1380 /*!
1381     \brief NETAPP Async event handler
1382 
1383     \param[out]      pSlNetApp   pointer to SlNetAppEvent_t data
1384 
1385     \par
1386              Parameters:
1387               - <b>pSlWlanEvent->Event = SL_NETAPP_IPV4_IPACQUIRED_EVENT</b>, IPV4 acquired event
1388                   - pSlWlanEvent->EventData.ipAcquiredV4 fields:
1389                        - ip
1390                        - gateway
1391                        - dns
1392 
1393               - <b>pSlWlanEvent->Event = SL_NETAPP_IP_LEASED_EVENT</b>, AP or P2P go dhcp lease event
1394                   - pSlWlanEvent->EventData.ipLeased  fields:
1395                        - ip_address
1396                        - lease_time
1397                        - mac
1398 
1399               - <b>pSlWlanEvent->Event = SL_NETAPP_IP_RELEASED_EVENT</b>, AP or P2P go dhcp ip release event
1400                    - pSlWlanEvent->EventData.ipReleased fields
1401                        - ip_address
1402                        - mac
1403                        - reason
1404 
1405 
1406     \sa
1407 
1408     \note           belongs to \ref configuration_sec
1409 
1410     \warning
1411 */
1412 
1413 #define slcb_NetAppEvtHdlr                      SimpleLinkNetAppEventHandler
1414 
1415 /*!
1416     \brief HTTP server async event
1417 
1418     \param[out] pSlHttpServerEvent   pointer to SlHttpServerEvent_t
1419     \param[in] pSlHttpServerResponse pointer to SlHttpServerResponse_t
1420 
1421     \par
1422           Parameters: \n
1423 
1424           - <b>pSlHttpServerEvent->Event = SL_NETAPP_HTTPGETTOKENVALUE_EVENT</b>
1425              - pSlHttpServerEvent->EventData fields:
1426                  - httpTokenName
1427                      - data
1428                      - len
1429              - pSlHttpServerResponse->ResponseData fields:
1430                      - data
1431                      - len
1432 
1433           - <b>pSlHttpServerEvent->Event = SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT</b>
1434               - pSlHttpServerEvent->EventData.httpPostData fields:
1435                      - action
1436                      - token_name
1437                      - token_value
1438               - pSlHttpServerResponse->ResponseData fields:
1439                      - data
1440                      - len
1441 
1442 
1443     \sa
1444 
1445     \note           belongs to \ref configuration_sec
1446 
1447     \warning
1448 */
1449 
1450 #define slcb_NetAppHttpServerHdlr   SimpleLinkHttpServerEventHandler
1451 
1452 
1453 
1454 /*!
1455     \brief          A handler for handling Netapp requests.
1456                     Netapp request types:
1457                     For HTTP server: GET / POST (future: PUT / DELETE)
1458 
1459     \param
1460 
1461     \param
1462 
1463     \sa
1464 
1465     \note           belongs to \ref porting_sec
1466 
1467     \warning
1468 */
1469 
1470 #define slcb_NetAppRequestHdlr  SimpleLinkNetAppRequestEventHandler
1471 
1472 
1473 
1474 /*!
1475     \brief          A handler for freeing the memory of the NetApp response.
1476 
1477     \param
1478 
1479     \param
1480 
1481     \sa
1482 
1483     \note           belongs to \ref porting_sec
1484 
1485     \warning
1486 */
1487 
1488 #define slcb_NetAppRequestMemFree  SimpleLinkNetAppRequestMemFreeEventHandler
1489 
1490 
1491 
1492 /*!
1493     \brief Socket Async event handler
1494 
1495     \param[out]      pSlSockEvent   pointer to SlSockEvent_t data
1496 
1497     \par
1498              Parameters:\n
1499              - <b>pSlSockEvent->Event = SL_SOCKET_TX_FAILED_EVENT</b>
1500                  - pSlSockEvent->EventData fields:
1501                      - sd
1502                      - status
1503              - <b>pSlSockEvent->Event = SL_SOCKET_ASYNC_EVENT</b>
1504                 - pSlSockEvent->EventData fields:
1505                      - sd
1506                      - type: SSL_ACCEPT  or RX_FRAGMENTATION_TOO_BIG or OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED
1507                      - val
1508 
1509     \sa
1510 
1511     \note           belongs to \ref configuration_sec
1512 
1513     \warning
1514 */
1515 
1516 #define slcb_SockEvtHdlr         SimpleLinkSockEventHandler
1517 
1518 
1519 /*!
1520     \brief Trigger Async event handler. If define, sl_Select operates only in trigger mode.
1521                            To disable trigger mode, handler should not be defined.
1522 
1523     \param[out]      pSlTriggerEvent   pointer to SlSockTriggerEvent_t data
1524 
1525     \par
1526              Parameters:\n
1527              - <b>pSlTriggerEvent->Event = SL_SOCKET_TRIGGER_EVENT_SELECT</b>
1528              - pSlTriggerEvent->EventData: Not in use
1529 
1530 
1531     \sa
1532 
1533     \note           belongs to \ref configuration_sec
1534 
1535     \warning
1536 */
1537 #ifndef SL_PLATFORM_MULTI_THREADED
1538 #define slcb_SocketTriggerEventHandler SimpleLinkSocketTriggerEventHandler
1539 #endif
1540 /*!
1541 
1542  Close the Doxygen group.
1543  @}
1544 
1545  */
1546 
1547 
1548 #ifdef  __cplusplus
1549 }
1550 #endif // __cplusplus
1551 
1552 #endif // __USER_H__
1553