nonos.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * nonos.h - CC31xx/CC32xx Host Driver Implementation
  3. *
  4. * Copyright (C) 2014 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. #ifndef __NONOS_H__
  37. #define __NONOS_H__
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #ifndef SL_PLATFORM_MULTI_THREADED
  42. /* This function call the user defined function, if defined, from the sync wait loop */
  43. /* The use case of this function is to allow nonos system to call a user function to put the device into sleep */
  44. /* The wake up should be activated after getting an interrupt from the device to Host */
  45. /* The user function must return without blocking to prevent a delay on the event handling */
  46. /*
  47. #define _SlSyncWaitLoopCallback UserSleepFunction
  48. */
  49. #define NONOS_WAIT_FOREVER 0xFF
  50. #define NONOS_NO_WAIT 0x00
  51. #define NONOS_RET_OK (0)
  52. #define NONOS_RET_ERR (0xFF)
  53. #define OSI_OK NONOS_RET_OK
  54. #define __NON_OS_SYNC_OBJ_CLEAR_VALUE 0x11
  55. #define __NON_OS_SYNC_OBJ_SIGNAL_VALUE 0x22
  56. #define __NON_OS_LOCK_OBJ_UNLOCK_VALUE 0x33
  57. #define __NON_OS_LOCK_OBJ_LOCK_VALUE 0x44
  58. /*!
  59. \brief type definition for the return values of this adaptation layer
  60. */
  61. typedef _i8 _SlNonOsRetVal_t;
  62. /*!
  63. \brief type definition for a time value
  64. */
  65. typedef _u8 _SlNonOsTime_t;
  66. /*!
  67. \brief type definition for a sync object container
  68. Sync object is object used to synchronize between two threads or thread and interrupt handler.
  69. One thread is waiting on the object and the other thread send a signal, which then
  70. release the waiting thread.
  71. The signal must be able to be sent from interrupt context.
  72. This object is generally implemented by binary semaphore or events.
  73. */
  74. typedef _u8 _SlNonOsSemObj_t;
  75. #define _SlTime_t _SlNonOsTime_t
  76. #define _SlSyncObj_t _SlNonOsSemObj_t
  77. #define _SlLockObj_t _SlNonOsSemObj_t
  78. #define SL_OS_WAIT_FOREVER NONOS_WAIT_FOREVER
  79. #define SL_OS_RET_CODE_OK NONOS_RET_OK
  80. #define SL_OS_NO_WAIT NONOS_NO_WAIT
  81. /*!
  82. \brief This function creates a sync object
  83. The sync object is used for synchronization between different thread or ISR and
  84. a thread.
  85. \param pSyncObj - pointer to the sync object control block
  86. \return upon successful creation the function return 0
  87. Otherwise, a negative value indicating the error code shall be returned
  88. \note
  89. \warning
  90. */
  91. #define _SlNonOsSyncObjCreate(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE)
  92. /*!
  93. \brief This function deletes a sync object
  94. \param pSyncObj - pointer to the sync object control block
  95. \return upon successful deletion the function should return 0
  96. Otherwise, a negative value indicating the error code shall be returned
  97. \note
  98. \warning
  99. */
  100. #define _SlNonOsSyncObjDelete(pSyncObj) _SlNonOsSemSet(pSyncObj,0)
  101. /*!
  102. \brief This function generates a sync signal for the object.
  103. All suspended threads waiting on this sync object are resumed
  104. \param pSyncObj - pointer to the sync object control block
  105. \return upon successful signaling the function should return 0
  106. Otherwise, a negative value indicating the error code shall be returned
  107. \note the function could be called from ISR context
  108. \warning
  109. */
  110. #define _SlNonOsSyncObjSignal(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE)
  111. /*!
  112. \brief This function waits for a sync signal of the specific sync object
  113. \param pSyncObj - pointer to the sync object control block
  114. \param Timeout - numeric value specifies the maximum number of mSec to
  115. stay suspended while waiting for the sync signal
  116. Currently, the simple link driver uses only two values:
  117. - NONOS_WAIT_FOREVER
  118. - NONOS_NO_WAIT
  119. \return upon successful reception of the signal within the timeout window return 0
  120. Otherwise, a negative value indicating the error code shall be returned
  121. \note
  122. \warning
  123. */
  124. #define _SlNonOsSyncObjWait(pSyncObj , Timeout) _SlNonOsSemGet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE,__NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)
  125. /*!
  126. \brief This function clears a sync object
  127. \param pSyncObj - pointer to the sync object control block
  128. \return upon successful clearing the function should return 0
  129. Otherwise, a negative value indicating the error code shall be returned
  130. \note
  131. \warning
  132. */
  133. #define _SlNonOsSyncObjClear(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE)
  134. /*!
  135. \brief This function creates a locking object.
  136. The locking object is used for protecting a shared resources between different
  137. threads.
  138. \param pLockObj - pointer to the locking object control block
  139. \return upon successful creation the function should return 0
  140. Otherwise, a negative value indicating the error code shall be returned
  141. \note
  142. \warning
  143. */
  144. #define _SlNonOsLockObjCreate(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE)
  145. /*!
  146. \brief This function deletes a locking object.
  147. \param pLockObj - pointer to the locking object control block
  148. \return upon successful deletion the function should return 0
  149. Otherwise, a negative value indicating the error code shall be returned
  150. \note
  151. \warning
  152. */
  153. #define _SlNonOsLockObjDelete(pLockObj) _SlNonOsSemSet(pLockObj,0)
  154. /*!
  155. \brief This function locks a locking object.
  156. All other threads that call this function before this thread calls
  157. the _SlNonOsLockObjUnlock would be suspended
  158. \param pLockObj - pointer to the locking object control block
  159. \param Timeout - numeric value specifies the maximum number of mSec to
  160. stay suspended while waiting for the locking object
  161. Currently, the simple link driver uses only two values:
  162. - NONOS_WAIT_FOREVER
  163. - NONOS_NO_WAIT
  164. \return upon successful reception of the locking object the function should return 0
  165. Otherwise, a negative value indicating the error code shall be returned
  166. \note
  167. \warning
  168. */
  169. #define _SlNonOsLockObjLock(pLockObj , Timeout) _SlNonOsSemGet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE,__NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)
  170. /*!
  171. \brief This function unlock a locking object.
  172. \param pLockObj - pointer to the locking object control block
  173. \return upon successful unlocking the function should return 0
  174. Otherwise, a negative value indicating the error code shall be returned
  175. \note
  176. \warning
  177. */
  178. #define _SlNonOsLockObjUnlock(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE)
  179. /*!
  180. \brief This function call the pEntry callback from a different context
  181. \param pEntry - pointer to the entry callback function
  182. \param pValue - pointer to any type of memory structure that would be
  183. passed to pEntry callback from the execution thread.
  184. \param flags - execution flags - reserved for future usage
  185. \return upon successful registration of the spawn the function return 0
  186. (the function is not blocked till the end of the execution of the function
  187. and could be returned before the execution is actually completed)
  188. Otherwise, a negative value indicating the error code shall be returned
  189. \note
  190. \warning
  191. */
  192. _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags);
  193. /*!
  194. \brief This function must be called from the main loop in non-os paltforms
  195. \param None
  196. \return 0 - No more activities
  197. 1 - Activity still in progress
  198. \note
  199. \warning
  200. */
  201. _SlNonOsRetVal_t _SlNonOsMainLoopTask(void);
  202. extern _SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout);
  203. extern _SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value);
  204. extern _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags);
  205. #if (defined(_SlSyncWaitLoopCallback))
  206. extern void _SlSyncWaitLoopCallback(void);
  207. #endif
  208. /*****************************************************************************
  209. Overwrite SimpleLink driver OS adaptation functions
  210. *****************************************************************************/
  211. #undef sl_SyncObjCreate
  212. #define sl_SyncObjCreate(pSyncObj,pName) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_CLEAR_VALUE)
  213. #undef sl_SyncObjDelete
  214. #define sl_SyncObjDelete(pSyncObj) _SlNonOsSemSet(pSyncObj,0)
  215. #undef sl_SyncObjSignal
  216. #define sl_SyncObjSignal(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE)
  217. #undef sl_SyncObjSignalFromIRQ
  218. #define sl_SyncObjSignalFromIRQ(pSyncObj) _SlNonOsSemSet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE)
  219. #undef sl_SyncObjWait
  220. #define sl_SyncObjWait(pSyncObj,Timeout) _SlNonOsSemGet(pSyncObj,__NON_OS_SYNC_OBJ_SIGNAL_VALUE,__NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)
  221. #undef sl_LockObjCreate
  222. #define sl_LockObjCreate(pLockObj,pName) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE)
  223. #undef sl_LockObjDelete
  224. #define sl_LockObjDelete(pLockObj) _SlNonOsSemSet(pLockObj,0)
  225. #undef sl_LockObjLock
  226. #define sl_LockObjLock(pLockObj,Timeout) _SlNonOsSemGet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE,__NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)
  227. #undef sl_LockObjUnlock
  228. #define sl_LockObjUnlock(pLockObj) _SlNonOsSemSet(pLockObj,__NON_OS_LOCK_OBJ_UNLOCK_VALUE)
  229. #undef sl_Spawn
  230. #define sl_Spawn(pEntry,pValue,flags) _SlNonOsSpawn(pEntry,pValue,flags)
  231. #undef _SlTaskEntry
  232. #define _SlTaskEntry _SlNonOsMainLoopTask
  233. #endif /* !SL_PLATFORM_MULTI_THREADED */
  234. #ifdef __cplusplus
  235. }
  236. #endif /* __cplusplus */
  237. #endif