rtx_kernel.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Copyright (c) 2013-2017 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: Kernel functions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #include "rtx_lib.h"
  26. // OS Runtime Information
  27. osRtxInfo_t osRtxInfo __attribute__((section(".data.os"))) =
  28. { .os_id = osRtxKernelId, .version = osRtxVersionKernel, .kernel.state = osRtxKernelInactive };
  29. // ==== Helper functions ====
  30. /// Block Kernel (disable: thread switching, time tick, post ISR processing).
  31. static void KernelBlock (void) {
  32. OS_Tick_Disable();
  33. osRtxInfo.kernel.blocked = 1U;
  34. __DSB();
  35. if (GetPendSV() != 0U) {
  36. ClrPendSV();
  37. osRtxInfo.kernel.pendSV = 1U;
  38. }
  39. }
  40. /// Unblock Kernel
  41. static void KernelUnblock (void) {
  42. osRtxInfo.kernel.blocked = 0U;
  43. __DSB();
  44. if (osRtxInfo.kernel.pendSV != 0U) {
  45. osRtxInfo.kernel.pendSV = 0U;
  46. SetPendSV();
  47. }
  48. OS_Tick_Enable();
  49. }
  50. // ==== Service Calls ====
  51. // Service Calls definitions
  52. SVC0_0 (KernelInitialize, osStatus_t)
  53. SVC0_3 (KernelGetInfo, osStatus_t, osVersion_t *, char *, uint32_t)
  54. SVC0_0 (KernelStart, osStatus_t)
  55. SVC0_0 (KernelLock, int32_t)
  56. SVC0_0 (KernelUnlock, int32_t)
  57. SVC0_1 (KernelRestoreLock, int32_t, int32_t)
  58. SVC0_0 (KernelSuspend, uint32_t)
  59. SVC0_1N(KernelResume, void, uint32_t)
  60. SVC0_0 (KernelGetState, osKernelState_t)
  61. SVC0_0 (KernelGetTickCount, uint32_t)
  62. SVC0_0 (KernelGetTickFreq, uint32_t)
  63. SVC0_0 (KernelGetSysTimerCount, uint32_t)
  64. SVC0_0 (KernelGetSysTimerFreq, uint32_t)
  65. /// Initialize the RTOS Kernel.
  66. /// \note API identical to osKernelInitialize
  67. osStatus_t svcRtxKernelInitialize (void) {
  68. if (osRtxInfo.kernel.state == osRtxKernelReady) {
  69. EvrRtxKernelInitializeCompleted();
  70. return osOK;
  71. }
  72. if (osRtxInfo.kernel.state != osKernelInactive) {
  73. EvrRtxKernelError((int32_t)osError);
  74. return osError;
  75. }
  76. // Initialize osRtxInfo
  77. memset(&osRtxInfo.kernel, 0, sizeof(osRtxInfo) - offsetof(osRtxInfo_t, kernel));
  78. if (osRtxConfig.thread_stack_size < (64U + 8U)) {
  79. EvrRtxKernelError(osRtxErrorInvalidThreadStack);
  80. return osError;
  81. }
  82. if ((osRtxConfig.isr_queue.data == NULL) || (osRtxConfig.isr_queue.max == 0U)) {
  83. EvrRtxKernelError((int32_t)osError);
  84. return osError;
  85. }
  86. osRtxInfo.isr_queue.data = osRtxConfig.isr_queue.data;
  87. osRtxInfo.isr_queue.max = osRtxConfig.isr_queue.max;
  88. osRtxInfo.thread.robin.timeout = osRtxConfig.robin_timeout;
  89. // Initialize Memory Pools (Variable Block Size)
  90. if (osRtxMemoryInit(osRtxConfig.mem.common_addr, osRtxConfig.mem.common_size) != 0U) {
  91. osRtxInfo.mem.common = osRtxConfig.mem.common_addr;
  92. }
  93. if (osRtxMemoryInit(osRtxConfig.mem.stack_addr, osRtxConfig.mem.stack_size) != 0U) {
  94. osRtxInfo.mem.stack = osRtxConfig.mem.stack_addr;
  95. } else {
  96. osRtxInfo.mem.stack = osRtxInfo.mem.common;
  97. }
  98. if (osRtxMemoryInit(osRtxConfig.mem.mp_data_addr, osRtxConfig.mem.mp_data_size) != 0U) {
  99. osRtxInfo.mem.mp_data = osRtxConfig.mem.mp_data_addr;
  100. } else {
  101. osRtxInfo.mem.mp_data = osRtxInfo.mem.common;
  102. }
  103. if (osRtxMemoryInit(osRtxConfig.mem.mq_data_addr, osRtxConfig.mem.mq_data_size) != 0U) {
  104. osRtxInfo.mem.mq_data = osRtxConfig.mem.mq_data_addr;
  105. } else {
  106. osRtxInfo.mem.mq_data = osRtxInfo.mem.common;
  107. }
  108. // Initialize Memory Pools (Fixed Block Size)
  109. if ((osRtxConfig.mpi.stack != NULL) &&
  110. (osRtxMemoryPoolInit(osRtxConfig.mpi.stack,
  111. osRtxConfig.mpi.stack->max_blocks,
  112. osRtxConfig.mpi.stack->block_size,
  113. osRtxConfig.mpi.stack->block_base) != 0U)) {
  114. osRtxInfo.mpi.stack = osRtxConfig.mpi.stack;
  115. }
  116. if ((osRtxConfig.mpi.thread != NULL) &&
  117. (osRtxMemoryPoolInit(osRtxConfig.mpi.thread,
  118. osRtxConfig.mpi.thread->max_blocks,
  119. osRtxConfig.mpi.thread->block_size,
  120. osRtxConfig.mpi.thread->block_base) != 0U)) {
  121. osRtxInfo.mpi.thread = osRtxConfig.mpi.thread;
  122. }
  123. if ((osRtxConfig.mpi.timer != NULL) &&
  124. (osRtxMemoryPoolInit(osRtxConfig.mpi.timer,
  125. osRtxConfig.mpi.timer->max_blocks,
  126. osRtxConfig.mpi.timer->block_size,
  127. osRtxConfig.mpi.timer->block_base) != 0U)) {
  128. osRtxInfo.mpi.timer = osRtxConfig.mpi.timer;
  129. }
  130. if ((osRtxConfig.mpi.event_flags != NULL) &&
  131. (osRtxMemoryPoolInit(osRtxConfig.mpi.event_flags,
  132. osRtxConfig.mpi.event_flags->max_blocks,
  133. osRtxConfig.mpi.event_flags->block_size,
  134. osRtxConfig.mpi.event_flags->block_base) != 0U)) {
  135. osRtxInfo.mpi.event_flags = osRtxConfig.mpi.event_flags;
  136. }
  137. if ((osRtxConfig.mpi.mutex != NULL) &&
  138. (osRtxMemoryPoolInit(osRtxConfig.mpi.mutex,
  139. osRtxConfig.mpi.mutex->max_blocks,
  140. osRtxConfig.mpi.mutex->block_size,
  141. osRtxConfig.mpi.mutex->block_base) != 0U)) {
  142. osRtxInfo.mpi.mutex = osRtxConfig.mpi.mutex;
  143. }
  144. if ((osRtxConfig.mpi.semaphore != NULL) &&
  145. (osRtxMemoryPoolInit(osRtxConfig.mpi.semaphore,
  146. osRtxConfig.mpi.semaphore->max_blocks,
  147. osRtxConfig.mpi.semaphore->block_size,
  148. osRtxConfig.mpi.semaphore->block_base) != 0U)) {
  149. osRtxInfo.mpi.semaphore = osRtxConfig.mpi.semaphore;
  150. }
  151. if ((osRtxConfig.mpi.memory_pool != NULL) &&
  152. (osRtxMemoryPoolInit(osRtxConfig.mpi.memory_pool,
  153. osRtxConfig.mpi.memory_pool->max_blocks,
  154. osRtxConfig.mpi.memory_pool->block_size,
  155. osRtxConfig.mpi.memory_pool->block_base) != 0U)) {
  156. osRtxInfo.mpi.memory_pool = osRtxConfig.mpi.memory_pool;
  157. }
  158. if ((osRtxConfig.mpi.message_queue != NULL) &&
  159. (osRtxMemoryPoolInit(osRtxConfig.mpi.message_queue,
  160. osRtxConfig.mpi.message_queue->max_blocks,
  161. osRtxConfig.mpi.message_queue->block_size,
  162. osRtxConfig.mpi.message_queue->block_base) != 0U)) {
  163. osRtxInfo.mpi.message_queue = osRtxConfig.mpi.message_queue;
  164. }
  165. #if (__DOMAIN_NS == 1U)
  166. // Initialize Secure Process Stack
  167. if (TZ_InitContextSystem_S() == 0U) {
  168. EvrRtxKernelError(osRtxErrorTZ_InitContext_S);
  169. return osError;
  170. }
  171. #endif
  172. osRtxInfo.kernel.state = osRtxKernelReady;
  173. EvrRtxKernelInitializeCompleted();
  174. return osOK;
  175. }
  176. /// Get RTOS Kernel Information.
  177. /// \note API identical to osKernelGetInfo
  178. osStatus_t svcRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) {
  179. if (version != NULL) {
  180. version->api = osRtxVersionAPI;
  181. version->kernel = osRtxVersionKernel;
  182. }
  183. if ((id_buf != NULL) && (id_size != 0U)) {
  184. if (id_size > sizeof(osRtxKernelId)) {
  185. id_size = sizeof(osRtxKernelId);
  186. }
  187. memcpy(id_buf, osRtxKernelId, id_size);
  188. }
  189. EvrRtxKernelInfoRetrieved(version, id_buf);
  190. return osOK;
  191. }
  192. /// Get the current RTOS Kernel state.
  193. /// \note API identical to osKernelGetState
  194. osKernelState_t svcRtxKernelGetState (void) {
  195. EvrRtxKernelGetState((osKernelState_t)(osRtxInfo.kernel.state));
  196. return ((osKernelState_t)(osRtxInfo.kernel.state));
  197. }
  198. /// Start the RTOS Kernel scheduler.
  199. /// \note API identical to osKernelStart
  200. osStatus_t svcRtxKernelStart (void) {
  201. os_thread_t *thread;
  202. if (osRtxInfo.kernel.state != osRtxKernelReady) {
  203. EvrRtxKernelError(osRtxErrorKernelNotReady);
  204. return osError;
  205. }
  206. // Create Idle Thread
  207. if (osRtxInfo.thread.idle == NULL) {
  208. osRtxInfo.thread.idle = svcRtxThreadNew(osRtxIdleThread, NULL, osRtxConfig.idle_thread_attr);
  209. if (osRtxInfo.thread.idle == NULL) {
  210. EvrRtxKernelError((int32_t)osError);
  211. return osError;
  212. }
  213. }
  214. // Create Timer Thread
  215. if (osRtxConfig.timer_mq_mcnt != 0U) {
  216. if (osRtxInfo.timer.thread == NULL) {
  217. osRtxInfo.timer.thread = svcRtxThreadNew(osRtxTimerThread, NULL, osRtxConfig.timer_thread_attr);
  218. if (osRtxInfo.timer.thread == NULL) {
  219. EvrRtxKernelError((int32_t)osError);
  220. return osError;
  221. }
  222. }
  223. }
  224. // Setup SVC and PendSV System Service Calls
  225. SVC_Setup();
  226. // Setup RTOS Tick
  227. if (OS_Tick_Setup(osRtxConfig.tick_freq, OS_TICK_HANDLER) != 0U) {
  228. return osError;
  229. }
  230. osRtxInfo.tick_irqn = OS_Tick_GetIRQn();
  231. // Enable RTOS Tick
  232. if (OS_Tick_Enable() != 0U) {
  233. return osError;
  234. }
  235. // Switch to Ready Thread with highest Priority
  236. thread = osRtxThreadListGet(&osRtxInfo.thread.ready);
  237. if (thread == NULL) {
  238. EvrRtxKernelError((int32_t)osError);
  239. return osError;
  240. }
  241. osRtxThreadSwitch(thread);
  242. if ((osRtxConfig.flags & osRtxConfigPrivilegedMode) != 0U) {
  243. // Privileged Thread mode & PSP
  244. __set_CONTROL(0x02U);
  245. } else {
  246. // Unprivileged Thread mode & PSP
  247. __set_CONTROL(0x03U);
  248. }
  249. osRtxInfo.kernel.state = osRtxKernelRunning;
  250. EvrRtxKernelStarted();
  251. return osOK;
  252. }
  253. /// Lock the RTOS Kernel scheduler.
  254. /// \note API identical to osKernelLock
  255. int32_t svcRtxKernelLock (void) {
  256. if (osRtxInfo.kernel.state == osRtxKernelLocked) {
  257. EvrRtxKernelLocked(1);
  258. return 1;
  259. }
  260. if (osRtxInfo.kernel.state == osRtxKernelRunning) {
  261. osRtxInfo.kernel.state = osRtxKernelLocked;
  262. EvrRtxKernelLocked(0);
  263. return 0;
  264. }
  265. EvrRtxKernelError((int32_t)osError);
  266. return osError;
  267. }
  268. /// Unlock the RTOS Kernel scheduler.
  269. /// \note API identical to osKernelUnlock
  270. int32_t svcRtxKernelUnlock (void) {
  271. if (osRtxInfo.kernel.state == osRtxKernelLocked) {
  272. osRtxInfo.kernel.state = osRtxKernelRunning;
  273. EvrRtxKernelUnlocked(1);
  274. return 1;
  275. }
  276. if (osRtxInfo.kernel.state == osRtxKernelRunning) {
  277. EvrRtxKernelUnlocked(0);
  278. return 0;
  279. }
  280. EvrRtxKernelError((int32_t)osError);
  281. return osError;
  282. }
  283. /// Restore the RTOS Kernel scheduler lock state.
  284. /// \note API identical to osKernelRestoreLock
  285. int32_t svcRtxKernelRestoreLock (int32_t lock) {
  286. if ((osRtxInfo.kernel.state == osRtxKernelRunning) ||
  287. (osRtxInfo.kernel.state == osRtxKernelLocked)) {
  288. switch (lock) {
  289. case 1:
  290. osRtxInfo.kernel.state = osRtxKernelLocked;
  291. EvrRtxKernelLockRestored(1);
  292. return 1;
  293. case 0:
  294. osRtxInfo.kernel.state = osRtxKernelRunning;
  295. EvrRtxKernelLockRestored(0);
  296. return 0;
  297. default:
  298. break;
  299. }
  300. }
  301. EvrRtxKernelError((int32_t)osError);
  302. return osError;
  303. }
  304. /// Suspend the RTOS Kernel scheduler.
  305. /// \note API identical to osKernelSuspend
  306. uint32_t svcRtxKernelSuspend (void) {
  307. os_thread_t *thread;
  308. os_timer_t *timer;
  309. uint32_t delay;
  310. if (osRtxInfo.kernel.state != osRtxKernelRunning) {
  311. EvrRtxKernelError(osRtxErrorKernelNotRunning);
  312. return 0U;
  313. }
  314. KernelBlock();
  315. delay = osWaitForever;
  316. // Check Thread Delay list
  317. thread = osRtxInfo.thread.delay_list;
  318. if (thread != NULL) {
  319. delay = thread->delay;
  320. }
  321. // Check Active Timer list
  322. timer = osRtxInfo.timer.list;
  323. if (timer != NULL) {
  324. if (timer->tick < delay) {
  325. delay = timer->tick;
  326. }
  327. }
  328. osRtxInfo.kernel.state = osRtxKernelSuspended;
  329. EvrRtxKernelSuspended(delay);
  330. return delay;
  331. }
  332. /// Resume the RTOS Kernel scheduler.
  333. /// \note API identical to osKernelResume
  334. void svcRtxKernelResume (uint32_t sleep_ticks) {
  335. os_thread_t *thread;
  336. os_timer_t *timer;
  337. uint32_t delay;
  338. if (osRtxInfo.kernel.state != osRtxKernelSuspended) {
  339. EvrRtxKernelResumed();
  340. return;
  341. }
  342. // Process Thread Delay list
  343. thread = osRtxInfo.thread.delay_list;
  344. if (thread != NULL) {
  345. delay = sleep_ticks;
  346. if (delay >= thread->delay) {
  347. delay -= thread->delay;
  348. osRtxInfo.kernel.tick += thread->delay;
  349. thread->delay = 1U;
  350. do {
  351. osRtxThreadDelayTick();
  352. if (delay == 0U) {
  353. break;
  354. }
  355. delay--;
  356. osRtxInfo.kernel.tick++;
  357. } while (osRtxInfo.thread.delay_list != NULL);
  358. } else {
  359. thread->delay -= delay;
  360. osRtxInfo.kernel.tick += delay;
  361. }
  362. } else {
  363. osRtxInfo.kernel.tick += sleep_ticks;
  364. }
  365. // Process Active Timer list
  366. timer = osRtxInfo.timer.list;
  367. if (timer != NULL) {
  368. if (sleep_ticks >= timer->tick) {
  369. sleep_ticks -= timer->tick;
  370. timer->tick = 1U;
  371. do {
  372. osRtxInfo.timer.tick();
  373. if (sleep_ticks == 0U) {
  374. break;
  375. }
  376. sleep_ticks--;
  377. } while (osRtxInfo.timer.list != NULL);
  378. } else {
  379. timer->tick -= sleep_ticks;
  380. }
  381. }
  382. osRtxInfo.kernel.state = osRtxKernelRunning;
  383. osRtxThreadDispatch(NULL);
  384. KernelUnblock();
  385. EvrRtxKernelResumed();
  386. }
  387. /// Get the RTOS kernel tick count.
  388. /// \note API identical to osKernelGetTickCount
  389. uint32_t svcRtxKernelGetTickCount (void) {
  390. EvrRtxKernelGetTickCount(osRtxInfo.kernel.tick);
  391. return osRtxInfo.kernel.tick;
  392. }
  393. /// Get the RTOS kernel tick frequency.
  394. /// \note API identical to osKernelGetTickFreq
  395. uint32_t svcRtxKernelGetTickFreq (void) {
  396. EvrRtxKernelGetTickFreq(osRtxConfig.tick_freq);
  397. return osRtxConfig.tick_freq;
  398. }
  399. /// Get the RTOS kernel system timer count.
  400. /// \note API identical to osKernelGetSysTimerCount
  401. uint32_t svcRtxKernelGetSysTimerCount (void) {
  402. uint32_t tick;
  403. uint32_t count;
  404. tick = (uint32_t)osRtxInfo.kernel.tick;
  405. count = OS_Tick_GetCount();
  406. if (OS_Tick_GetOverflow()) {
  407. count = OS_Tick_GetCount();
  408. tick++;
  409. }
  410. count += tick * OS_Tick_GetInterval();
  411. EvrRtxKernelGetSysTimerCount(count);
  412. return count;
  413. }
  414. /// Get the RTOS kernel system timer frequency.
  415. /// \note API identical to osKernelGetSysTimerFreq
  416. uint32_t svcRtxKernelGetSysTimerFreq (void) {
  417. uint32_t freq = OS_Tick_GetClock();
  418. EvrRtxKernelGetSysTimerFreq(freq);
  419. return freq;
  420. }
  421. // ==== Public API ====
  422. /// Initialize the RTOS Kernel.
  423. osStatus_t osKernelInitialize (void) {
  424. EvrRtxKernelInitialize();
  425. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  426. EvrRtxKernelError((int32_t)osErrorISR);
  427. return osErrorISR;
  428. }
  429. return __svcKernelInitialize();
  430. }
  431. /// Get RTOS Kernel Information.
  432. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) {
  433. EvrRtxKernelGetInfo(version, id_buf, id_size);
  434. if (IS_PRIVILEGED() || IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  435. return svcRtxKernelGetInfo(version, id_buf, id_size);
  436. } else {
  437. return __svcKernelGetInfo(version, id_buf, id_size);
  438. }
  439. }
  440. /// Get the current RTOS Kernel state.
  441. osKernelState_t osKernelGetState (void) {
  442. if (IS_PRIVILEGED() || IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  443. return svcRtxKernelGetState();
  444. } else {
  445. return __svcKernelGetState();
  446. }
  447. }
  448. /// Start the RTOS Kernel scheduler.
  449. osStatus_t osKernelStart (void) {
  450. EvrRtxKernelStart();
  451. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  452. EvrRtxKernelError((int32_t)osErrorISR);
  453. return osErrorISR;
  454. }
  455. return __svcKernelStart();
  456. }
  457. /// Lock the RTOS Kernel scheduler.
  458. int32_t osKernelLock (void) {
  459. EvrRtxKernelLock();
  460. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  461. EvrRtxKernelError((int32_t)osErrorISR);
  462. return osErrorISR;
  463. }
  464. return __svcKernelLock();
  465. }
  466. /// Unlock the RTOS Kernel scheduler.
  467. int32_t osKernelUnlock (void) {
  468. EvrRtxKernelUnlock();
  469. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  470. EvrRtxKernelError((int32_t)osErrorISR);
  471. return osErrorISR;
  472. }
  473. return __svcKernelUnlock();
  474. }
  475. /// Restore the RTOS Kernel scheduler lock state.
  476. int32_t osKernelRestoreLock (int32_t lock) {
  477. EvrRtxKernelRestoreLock(lock);
  478. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  479. EvrRtxKernelError((int32_t)osErrorISR);
  480. return osErrorISR;
  481. }
  482. return __svcKernelRestoreLock(lock);
  483. }
  484. /// Suspend the RTOS Kernel scheduler.
  485. uint32_t osKernelSuspend (void) {
  486. EvrRtxKernelSuspend();
  487. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  488. EvrRtxKernelError((int32_t)osErrorISR);
  489. return 0U;
  490. }
  491. return __svcKernelSuspend();
  492. }
  493. /// Resume the RTOS Kernel scheduler.
  494. void osKernelResume (uint32_t sleep_ticks) {
  495. EvrRtxKernelResume(sleep_ticks);
  496. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  497. EvrRtxKernelError((int32_t)osErrorISR);
  498. return;
  499. }
  500. __svcKernelResume(sleep_ticks);
  501. }
  502. /// Get the RTOS kernel tick count.
  503. uint32_t osKernelGetTickCount (void) {
  504. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  505. return svcRtxKernelGetTickCount();
  506. } else {
  507. return __svcKernelGetTickCount();
  508. }
  509. }
  510. /// Get the RTOS kernel tick frequency.
  511. uint32_t osKernelGetTickFreq (void) {
  512. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  513. return svcRtxKernelGetTickFreq();
  514. } else {
  515. return __svcKernelGetTickFreq();
  516. }
  517. }
  518. /// Get the RTOS kernel system timer count.
  519. uint32_t osKernelGetSysTimerCount (void) {
  520. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  521. return svcRtxKernelGetSysTimerCount();
  522. } else {
  523. return __svcKernelGetSysTimerCount();
  524. }
  525. }
  526. /// Get the RTOS kernel system timer frequency.
  527. uint32_t osKernelGetSysTimerFreq (void) {
  528. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  529. return svcRtxKernelGetSysTimerFreq();
  530. } else {
  531. return __svcKernelGetSysTimerFreq();
  532. }
  533. }