rtx_lib.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * -----------------------------------------------------------------------------
  19. *
  20. * Project: CMSIS-RTOS RTX
  21. * Title: RTX Library definitions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #ifndef RTX_LIB_H_
  26. #define RTX_LIB_H_
  27. #include <string.h>
  28. #include "rtx_core_c.h" // Cortex core definitions
  29. #if ((defined(__ARM_ARCH_8M_BASE__) && (__ARM_ARCH_8M_BASE__ != 0)) || \
  30. (defined(__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ != 0)))
  31. #include "tz_context.h" // TrustZone Context API
  32. #endif
  33. #include "os_tick.h" // CMSIS OS Tick API
  34. #include "cmsis_os2.h" // CMSIS RTOS API
  35. #include "RTX_Config.h" // RTX Configuration
  36. #include "rtx_os.h" // RTX OS definitions
  37. #include "rtx_evr.h" // RTX Event Recorder definitions
  38. // ==== Library defines ====
  39. #define os_thread_t osRtxThread_t
  40. #define os_timer_t osRtxTimer_t
  41. #define os_timer_finfo_t osRtxTimerFinfo_t
  42. #define os_event_flags_t osRtxEventFlags_t
  43. #define os_mutex_t osRtxMutex_t
  44. #define os_semaphore_t osRtxSemaphore_t
  45. #define os_mp_info_t osRtxMpInfo_t
  46. #define os_memory_pool_t osRtxMemoryPool_t
  47. #define os_message_t osRtxMessage_t
  48. #define os_message_queue_t osRtxMessageQueue_t
  49. #define os_object_t osRtxObject_t
  50. // ==== Inline functions ====
  51. // Thread ID
  52. __STATIC_INLINE os_thread_t *osRtxThreadId (osThreadId_t thread_id) {
  53. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  54. return ((os_thread_t *)thread_id);
  55. }
  56. // Timer ID
  57. __STATIC_INLINE os_timer_t *osRtxTimerId (osTimerId_t timer_id) {
  58. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  59. return ((os_timer_t *)timer_id);
  60. }
  61. // Event Flags ID
  62. __STATIC_INLINE os_event_flags_t *osRtxEventFlagsId (osEventFlagsId_t ef_id) {
  63. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  64. return ((os_event_flags_t *)ef_id);
  65. }
  66. // Mutex ID
  67. __STATIC_INLINE os_mutex_t *osRtxMutexId (osMutexId_t mutex_id) {
  68. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  69. return ((os_mutex_t *)mutex_id);
  70. }
  71. // Semaphore ID
  72. __STATIC_INLINE os_semaphore_t *osRtxSemaphoreId (osSemaphoreId_t semaphore_id) {
  73. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  74. return ((os_semaphore_t *)semaphore_id);
  75. }
  76. // Memory Pool ID
  77. __STATIC_INLINE os_memory_pool_t *osRtxMemoryPoolId (osMemoryPoolId_t mp_id) {
  78. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  79. return ((os_memory_pool_t *)mp_id);
  80. }
  81. // Message Queue ID
  82. __STATIC_INLINE os_message_queue_t *osRtxMessageQueueId (osMessageQueueId_t mq_id) {
  83. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 2]
  84. return ((os_message_queue_t *)mq_id);
  85. }
  86. // Generic Object
  87. __STATIC_INLINE os_object_t *osRtxObject (void *object) {
  88. //lint -e{9079} -e{9087} "cast from pointer to void to pointer to object type" [MISRA Note 3]
  89. return ((os_object_t *)object);
  90. }
  91. // Thread Object
  92. __STATIC_INLINE os_thread_t *osRtxThreadObject (os_object_t *object) {
  93. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  94. return ((os_thread_t *)object);
  95. }
  96. // Timer Object
  97. __STATIC_INLINE os_timer_t *osRtxTimerObject (os_object_t *object) {
  98. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  99. return ((os_timer_t *)object);
  100. }
  101. // Event Flags Object
  102. __STATIC_INLINE os_event_flags_t *osRtxEventFlagsObject (os_object_t *object) {
  103. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  104. return ((os_event_flags_t *)object);
  105. }
  106. // Mutex Object
  107. __STATIC_INLINE os_mutex_t *osRtxMutexObject (os_object_t *object) {
  108. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  109. return ((os_mutex_t *)object);
  110. }
  111. // Semaphore Object
  112. __STATIC_INLINE os_semaphore_t *osRtxSemaphoreObject (os_object_t *object) {
  113. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  114. return ((os_semaphore_t *)object);
  115. }
  116. // Memory Pool Object
  117. __STATIC_INLINE os_memory_pool_t *osRtxMemoryPoolObject (os_object_t *object) {
  118. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  119. return ((os_memory_pool_t *)object);
  120. }
  121. // Message Queue Object
  122. __STATIC_INLINE os_message_queue_t *osRtxMessageQueueObject (os_object_t *object) {
  123. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  124. return ((os_message_queue_t *)object);
  125. }
  126. // Message Object
  127. __STATIC_INLINE os_message_t *osRtxMessageObject (os_object_t *object) {
  128. //lint -e{740} -e{826} -e{9087} "cast from pointer to generic object to specific object" [MISRA Note 4]
  129. return ((os_message_t *)object);
  130. }
  131. // Kernel State
  132. __STATIC_INLINE osKernelState_t osRtxKernelState (void) {
  133. //lint -e{9030} -e{9034} "cast to enum"
  134. return ((osKernelState_t)(osRtxInfo.kernel.state));
  135. }
  136. // Thread State
  137. __STATIC_INLINE osThreadState_t osRtxThreadState (const os_thread_t *thread) {
  138. uint8_t state = thread->state & osRtxThreadStateMask;
  139. //lint -e{9030} -e{9034} "cast to enum"
  140. return ((osThreadState_t)state);
  141. }
  142. // Thread Priority
  143. __STATIC_INLINE osPriority_t osRtxThreadPriority (const os_thread_t *thread) {
  144. //lint -e{9030} -e{9034} "cast to enum"
  145. return ((osPriority_t)thread->priority);
  146. }
  147. // Kernel Get State
  148. __STATIC_INLINE uint8_t osRtxKernelGetState (void) {
  149. return osRtxInfo.kernel.state;
  150. }
  151. // Thread Get/Set Running
  152. __STATIC_INLINE os_thread_t *osRtxThreadGetRunning (void) {
  153. return osRtxInfo.thread.run.curr;
  154. }
  155. __STATIC_INLINE void osRtxThreadSetRunning (os_thread_t *thread) {
  156. osRtxInfo.thread.run.curr = thread;
  157. }
  158. // ==== Library functions ====
  159. // Thread Library functions
  160. extern void osRtxThreadListPut (os_object_t *object, os_thread_t *thread);
  161. extern os_thread_t *osRtxThreadListGet (os_object_t *object);
  162. extern void osRtxThreadListSort (os_thread_t *thread);
  163. extern void osRtxThreadListRemove (os_thread_t *thread);
  164. extern void osRtxThreadReadyPut (os_thread_t *thread);
  165. extern void osRtxThreadDelayTick (void);
  166. extern uint32_t *osRtxThreadRegPtr (const os_thread_t *thread);
  167. extern void osRtxThreadSwitch (os_thread_t *thread);
  168. extern void osRtxThreadDispatch (os_thread_t *thread);
  169. extern void osRtxThreadWaitExit (os_thread_t *thread, uint32_t ret_val, bool_t dispatch);
  170. extern bool_t osRtxThreadWaitEnter (uint8_t state, uint32_t timeout);
  171. extern void osRtxThreadStackCheck (void);
  172. extern bool_t osRtxThreadStartup (void);
  173. // Timer Library functions
  174. extern void osRtxTimerThread (void *argument);
  175. // Mutex Library functions
  176. extern void osRtxMutexOwnerRelease (os_mutex_t *mutex_list);
  177. // Memory Heap Library functions
  178. extern uint32_t osRtxMemoryInit (void *mem, uint32_t size);
  179. extern void *osRtxMemoryAlloc(void *mem, uint32_t size, uint32_t type);
  180. extern uint32_t osRtxMemoryFree (void *mem, void *block);
  181. // Memory Pool Library functions
  182. extern uint32_t osRtxMemoryPoolInit (os_mp_info_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem);
  183. extern void *osRtxMemoryPoolAlloc (os_mp_info_t *mp_info);
  184. extern osStatus_t osRtxMemoryPoolFree (os_mp_info_t *mp_info, void *block);
  185. // System Library functions
  186. extern void osRtxTick_Handler (void);
  187. extern void osRtxPendSV_Handler (void);
  188. extern void osRtxPostProcess (os_object_t *object);
  189. #endif // RTX_LIB_H_