rtx_kernel.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 == 1)
  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. OS_Tick_Enable();
  233. // Switch to Ready Thread with highest Priority
  234. thread = osRtxThreadListGet(&osRtxInfo.thread.ready);
  235. if (thread == NULL) {
  236. EvrRtxKernelError((int32_t)osError);
  237. return osError;
  238. }
  239. osRtxThreadSwitch(thread);
  240. if ((osRtxConfig.flags & osRtxConfigPrivilegedMode) != 0U) {
  241. // Privileged Thread mode & PSP
  242. __set_CONTROL(0x02U);
  243. } else {
  244. // Unprivileged Thread mode & PSP
  245. __set_CONTROL(0x03U);
  246. }
  247. osRtxInfo.kernel.state = osRtxKernelRunning;
  248. EvrRtxKernelStarted();
  249. return osOK;
  250. }
  251. /// Lock the RTOS Kernel scheduler.
  252. /// \note API identical to osKernelLock
  253. int32_t svcRtxKernelLock (void) {
  254. if (osRtxInfo.kernel.state == osRtxKernelLocked) {
  255. EvrRtxKernelLocked(1);
  256. return 1;
  257. }
  258. if (osRtxInfo.kernel.state == osRtxKernelRunning) {
  259. osRtxInfo.kernel.state = osRtxKernelLocked;
  260. EvrRtxKernelLocked(0);
  261. return 0;
  262. }
  263. EvrRtxKernelError((int32_t)osError);
  264. return osError;
  265. }
  266. /// Unlock the RTOS Kernel scheduler.
  267. /// \note API identical to osKernelUnlock
  268. int32_t svcRtxKernelUnlock (void) {
  269. if (osRtxInfo.kernel.state == osRtxKernelLocked) {
  270. osRtxInfo.kernel.state = osRtxKernelRunning;
  271. EvrRtxKernelUnlocked(1);
  272. return 1;
  273. }
  274. if (osRtxInfo.kernel.state == osRtxKernelRunning) {
  275. EvrRtxKernelUnlocked(0);
  276. return 0;
  277. }
  278. EvrRtxKernelError((int32_t)osError);
  279. return osError;
  280. }
  281. /// Restore the RTOS Kernel scheduler lock state.
  282. /// \note API identical to osKernelRestoreLock
  283. int32_t svcRtxKernelRestoreLock (int32_t lock) {
  284. if ((osRtxInfo.kernel.state == osRtxKernelRunning) ||
  285. (osRtxInfo.kernel.state == osRtxKernelLocked)) {
  286. switch (lock) {
  287. case 1:
  288. osRtxInfo.kernel.state = osRtxKernelLocked;
  289. EvrRtxKernelLockRestored(1);
  290. return 1;
  291. case 0:
  292. osRtxInfo.kernel.state = osRtxKernelRunning;
  293. EvrRtxKernelLockRestored(0);
  294. return 0;
  295. default:
  296. break;
  297. }
  298. }
  299. EvrRtxKernelError((int32_t)osError);
  300. return osError;
  301. }
  302. /// Suspend the RTOS Kernel scheduler.
  303. /// \note API identical to osKernelSuspend
  304. uint32_t svcRtxKernelSuspend (void) {
  305. os_thread_t *thread;
  306. os_timer_t *timer;
  307. uint32_t delay;
  308. if (osRtxInfo.kernel.state != osRtxKernelRunning) {
  309. EvrRtxKernelError(osRtxErrorKernelNotRunning);
  310. return 0U;
  311. }
  312. KernelBlock();
  313. delay = osWaitForever;
  314. // Check Thread Delay list
  315. thread = osRtxInfo.thread.delay_list;
  316. if (thread != NULL) {
  317. delay = thread->delay;
  318. }
  319. // Check Active Timer list
  320. timer = osRtxInfo.timer.list;
  321. if (timer != NULL) {
  322. if (timer->tick < delay) {
  323. delay = timer->tick;
  324. }
  325. }
  326. osRtxInfo.kernel.state = osRtxKernelSuspended;
  327. EvrRtxKernelSuspended(delay);
  328. return delay;
  329. }
  330. /// Resume the RTOS Kernel scheduler.
  331. /// \note API identical to osKernelResume
  332. void svcRtxKernelResume (uint32_t sleep_ticks) {
  333. os_thread_t *thread;
  334. os_timer_t *timer;
  335. uint32_t delay;
  336. if (osRtxInfo.kernel.state != osRtxKernelSuspended) {
  337. EvrRtxKernelResumed();
  338. return;
  339. }
  340. // Process Thread Delay list
  341. thread = osRtxInfo.thread.delay_list;
  342. if (thread != NULL) {
  343. delay = sleep_ticks;
  344. if (delay >= thread->delay) {
  345. delay -= thread->delay;
  346. osRtxInfo.kernel.tick += thread->delay;
  347. thread->delay = 1U;
  348. do {
  349. osRtxThreadDelayTick();
  350. if (delay == 0U) {
  351. break;
  352. }
  353. delay--;
  354. osRtxInfo.kernel.tick++;
  355. } while (osRtxInfo.thread.delay_list != NULL);
  356. } else {
  357. thread->delay -= delay;
  358. osRtxInfo.kernel.tick += delay;
  359. }
  360. } else {
  361. osRtxInfo.kernel.tick += sleep_ticks;
  362. }
  363. // Process Active Timer list
  364. timer = osRtxInfo.timer.list;
  365. if (timer != NULL) {
  366. if (sleep_ticks >= timer->tick) {
  367. sleep_ticks -= timer->tick;
  368. timer->tick = 1U;
  369. do {
  370. osRtxInfo.timer.tick();
  371. if (sleep_ticks == 0U) {
  372. break;
  373. }
  374. sleep_ticks--;
  375. } while (osRtxInfo.timer.list != NULL);
  376. } else {
  377. timer->tick -= sleep_ticks;
  378. }
  379. }
  380. osRtxInfo.kernel.state = osRtxKernelRunning;
  381. osRtxThreadDispatch(NULL);
  382. KernelUnblock();
  383. EvrRtxKernelResumed();
  384. }
  385. /// Get the RTOS kernel tick count.
  386. /// \note API identical to osKernelGetTickCount
  387. uint32_t svcRtxKernelGetTickCount (void) {
  388. EvrRtxKernelGetTickCount(osRtxInfo.kernel.tick);
  389. return osRtxInfo.kernel.tick;
  390. }
  391. /// Get the RTOS kernel tick frequency.
  392. /// \note API identical to osKernelGetTickFreq
  393. uint32_t svcRtxKernelGetTickFreq (void) {
  394. EvrRtxKernelGetTickFreq(osRtxConfig.tick_freq);
  395. return osRtxConfig.tick_freq;
  396. }
  397. /// Get the RTOS kernel system timer count.
  398. /// \note API identical to osKernelGetSysTimerCount
  399. uint32_t svcRtxKernelGetSysTimerCount (void) {
  400. uint32_t tick;
  401. uint32_t count;
  402. tick = (uint32_t)osRtxInfo.kernel.tick;
  403. count = OS_Tick_GetCount();
  404. if (OS_Tick_GetOverflow()) {
  405. count = OS_Tick_GetCount();
  406. tick++;
  407. }
  408. count += tick * OS_Tick_GetInterval();
  409. EvrRtxKernelGetSysTimerCount(count);
  410. return count;
  411. }
  412. /// Get the RTOS kernel system timer frequency.
  413. /// \note API identical to osKernelGetSysTimerFreq
  414. uint32_t svcRtxKernelGetSysTimerFreq (void) {
  415. uint32_t freq = OS_Tick_GetClock();
  416. EvrRtxKernelGetSysTimerFreq(freq);
  417. return freq;
  418. }
  419. // ==== Public API ====
  420. /// Initialize the RTOS Kernel.
  421. osStatus_t osKernelInitialize (void) {
  422. EvrRtxKernelInitialize();
  423. if (IsIrqMode() || IsIrqMasked()) {
  424. EvrRtxKernelError((int32_t)osErrorISR);
  425. return osErrorISR;
  426. }
  427. return __svcKernelInitialize();
  428. }
  429. /// Get RTOS Kernel Information.
  430. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) {
  431. EvrRtxKernelGetInfo(version, id_buf, id_size);
  432. if (IsPrivileged() || IsIrqMode() || IsIrqMasked()) {
  433. return svcRtxKernelGetInfo(version, id_buf, id_size);
  434. } else {
  435. return __svcKernelGetInfo(version, id_buf, id_size);
  436. }
  437. }
  438. /// Get the current RTOS Kernel state.
  439. osKernelState_t osKernelGetState (void) {
  440. if (IsPrivileged() || IsIrqMode() || IsIrqMasked()) {
  441. return svcRtxKernelGetState();
  442. } else {
  443. return __svcKernelGetState();
  444. }
  445. }
  446. /// Start the RTOS Kernel scheduler.
  447. osStatus_t osKernelStart (void) {
  448. EvrRtxKernelStart();
  449. if (IsIrqMode() || IsIrqMasked()) {
  450. EvrRtxKernelError((int32_t)osErrorISR);
  451. return osErrorISR;
  452. }
  453. return __svcKernelStart();
  454. }
  455. /// Lock the RTOS Kernel scheduler.
  456. int32_t osKernelLock (void) {
  457. EvrRtxKernelLock();
  458. if (IsIrqMode() || IsIrqMasked()) {
  459. EvrRtxKernelError((int32_t)osErrorISR);
  460. return osErrorISR;
  461. }
  462. return __svcKernelLock();
  463. }
  464. /// Unlock the RTOS Kernel scheduler.
  465. int32_t osKernelUnlock (void) {
  466. EvrRtxKernelUnlock();
  467. if (IsIrqMode() || IsIrqMasked()) {
  468. EvrRtxKernelError((int32_t)osErrorISR);
  469. return osErrorISR;
  470. }
  471. return __svcKernelUnlock();
  472. }
  473. /// Restore the RTOS Kernel scheduler lock state.
  474. int32_t osKernelRestoreLock (int32_t lock) {
  475. EvrRtxKernelRestoreLock(lock);
  476. if (IsIrqMode() || IsIrqMasked()) {
  477. EvrRtxKernelError((int32_t)osErrorISR);
  478. return osErrorISR;
  479. }
  480. return __svcKernelRestoreLock(lock);
  481. }
  482. /// Suspend the RTOS Kernel scheduler.
  483. uint32_t osKernelSuspend (void) {
  484. EvrRtxKernelSuspend();
  485. if (IsIrqMode() || IsIrqMasked()) {
  486. EvrRtxKernelError((int32_t)osErrorISR);
  487. return 0U;
  488. }
  489. return __svcKernelSuspend();
  490. }
  491. /// Resume the RTOS Kernel scheduler.
  492. void osKernelResume (uint32_t sleep_ticks) {
  493. EvrRtxKernelResume(sleep_ticks);
  494. if (IsIrqMode() || IsIrqMasked()) {
  495. EvrRtxKernelError((int32_t)osErrorISR);
  496. return;
  497. }
  498. __svcKernelResume(sleep_ticks);
  499. }
  500. /// Get the RTOS kernel tick count.
  501. uint32_t osKernelGetTickCount (void) {
  502. if (IsIrqMode() || IsIrqMasked()) {
  503. return svcRtxKernelGetTickCount();
  504. } else {
  505. return __svcKernelGetTickCount();
  506. }
  507. }
  508. /// Get the RTOS kernel tick frequency.
  509. uint32_t osKernelGetTickFreq (void) {
  510. if (IsIrqMode() || IsIrqMasked()) {
  511. return svcRtxKernelGetTickFreq();
  512. } else {
  513. return __svcKernelGetTickFreq();
  514. }
  515. }
  516. /// Get the RTOS kernel system timer count.
  517. uint32_t osKernelGetSysTimerCount (void) {
  518. if (IsIrqMode() || IsIrqMasked()) {
  519. return svcRtxKernelGetSysTimerCount();
  520. } else {
  521. return __svcKernelGetSysTimerCount();
  522. }
  523. }
  524. /// Get the RTOS kernel system timer frequency.
  525. uint32_t osKernelGetSysTimerFreq (void) {
  526. if (IsIrqMode() || IsIrqMasked()) {
  527. return svcRtxKernelGetSysTimerFreq();
  528. } else {
  529. return __svcKernelGetSysTimerFreq();
  530. }
  531. }