rtx_timer.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright (c) 2013-2023 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: Timer functions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #include "rtx_lib.h"
  26. // OS Runtime Object Memory Usage
  27. #ifdef RTX_OBJ_MEM_USAGE
  28. osRtxObjectMemUsage_t osRtxTimerMemUsage \
  29. __attribute__((section(".data.os.timer.obj"))) =
  30. { 0U, 0U, 0U };
  31. #endif
  32. // ==== Helper functions ====
  33. /// Insert Timer into the Timer List sorted by Time.
  34. /// \param[in] timer timer object.
  35. /// \param[in] tick timer tick.
  36. static void TimerInsert (os_timer_t *timer, uint32_t tick) {
  37. os_timer_t *prev, *next;
  38. prev = NULL;
  39. next = osRtxInfo.timer.list;
  40. while ((next != NULL) && (next->tick <= tick)) {
  41. tick -= next->tick;
  42. prev = next;
  43. next = next->next;
  44. }
  45. timer->tick = tick;
  46. timer->prev = prev;
  47. timer->next = next;
  48. if (next != NULL) {
  49. next->tick -= timer->tick;
  50. next->prev = timer;
  51. }
  52. if (prev != NULL) {
  53. prev->next = timer;
  54. } else {
  55. osRtxInfo.timer.list = timer;
  56. }
  57. }
  58. /// Remove Timer from the Timer List.
  59. /// \param[in] timer timer object.
  60. static void TimerRemove (const os_timer_t *timer) {
  61. if (timer->next != NULL) {
  62. timer->next->tick += timer->tick;
  63. timer->next->prev = timer->prev;
  64. }
  65. if (timer->prev != NULL) {
  66. timer->prev->next = timer->next;
  67. } else {
  68. osRtxInfo.timer.list = timer->next;
  69. }
  70. }
  71. /// Unlink Timer from the Timer List Head.
  72. /// \param[in] timer timer object.
  73. static void TimerUnlink (const os_timer_t *timer) {
  74. if (timer->next != NULL) {
  75. timer->next->prev = timer->prev;
  76. }
  77. osRtxInfo.timer.list = timer->next;
  78. }
  79. /// Verify that Timer object pointer is valid.
  80. /// \param[in] timer timer object.
  81. /// \return true - valid, false - invalid.
  82. static bool_t IsTimerPtrValid (const os_timer_t *timer) {
  83. #ifdef RTX_OBJ_PTR_CHECK
  84. //lint --e{923} --e{9078} "cast from pointer to unsigned int" [MISRA Note 7]
  85. uint32_t cb_start = (uint32_t)&__os_timer_cb_start__;
  86. uint32_t cb_length = (uint32_t)&__os_timer_cb_length__;
  87. // Check the section boundaries
  88. if (((uint32_t)timer - cb_start) >= cb_length) {
  89. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  90. return FALSE;
  91. }
  92. // Check the object alignment
  93. if ((((uint32_t)timer - cb_start) % sizeof(os_timer_t)) != 0U) {
  94. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  95. return FALSE;
  96. }
  97. #else
  98. // Check NULL pointer
  99. if (timer == NULL) {
  100. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  101. return FALSE;
  102. }
  103. #endif
  104. return TRUE;
  105. }
  106. // ==== Library functions ====
  107. /// Timer Tick (called each SysTick).
  108. static void osRtxTimerTick (void) {
  109. os_thread_t *thread_running;
  110. os_timer_t *timer;
  111. osStatus_t status;
  112. timer = osRtxInfo.timer.list;
  113. if (timer == NULL) {
  114. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  115. return;
  116. }
  117. thread_running = osRtxThreadGetRunning();
  118. timer->tick--;
  119. while ((timer != NULL) && (timer->tick == 0U)) {
  120. TimerUnlink(timer);
  121. status = osMessageQueuePut(osRtxInfo.timer.mq, &timer->finfo, 0U, 0U);
  122. if (status != osOK) {
  123. const os_thread_t *thread = osRtxThreadGetRunning();
  124. osRtxThreadSetRunning(osRtxInfo.thread.run.next);
  125. (void)osRtxKernelErrorNotify(osRtxErrorTimerQueueOverflow, timer);
  126. if (osRtxThreadGetRunning() == NULL) {
  127. if (thread_running == thread) {
  128. thread_running = NULL;
  129. }
  130. }
  131. }
  132. if ((timer->attr & osRtxTimerPeriodic) != 0U) {
  133. TimerInsert(timer, timer->load);
  134. } else {
  135. timer->state = osRtxTimerStopped;
  136. }
  137. timer = osRtxInfo.timer.list;
  138. }
  139. osRtxThreadSetRunning(thread_running);
  140. }
  141. /// Setup Timer Thread objects.
  142. //lint -esym(714,osRtxTimerSetup) "Referenced from library configuration"
  143. //lint -esym(759,osRtxTimerSetup) "Prototype in header"
  144. //lint -esym(765,osRtxTimerSetup) "Global scope"
  145. int32_t osRtxTimerSetup (void) {
  146. int32_t ret = -1;
  147. if (osRtxMessageQueueTimerSetup() == 0) {
  148. osRtxInfo.timer.tick = osRtxTimerTick;
  149. ret = 0;
  150. }
  151. return ret;
  152. }
  153. /// Timer Thread
  154. //lint -esym(714,osRtxTimerThread) "Referenced from library configuration"
  155. //lint -esym(759,osRtxTimerThread) "Prototype in header"
  156. //lint -esym(765,osRtxTimerThread) "Global scope"
  157. __NO_RETURN void osRtxTimerThread (void *argument) {
  158. os_timer_finfo_t finfo;
  159. osStatus_t status;
  160. osMessageQueueId_t mq = (osMessageQueueId_t)argument;
  161. for (;;) {
  162. //lint -e{934} "Taking address of near auto variable"
  163. status = osMessageQueueGet(mq, &finfo, NULL, osWaitForever);
  164. if (status == osOK) {
  165. EvrRtxTimerCallback(finfo.func, finfo.arg);
  166. (finfo.func)(finfo.arg);
  167. }
  168. }
  169. }
  170. /// Destroy a Timer object.
  171. /// \param[in] timer timer object.
  172. static void osRtxTimerDestroy (os_timer_t *timer) {
  173. // Mark object as inactive and invalid
  174. timer->state = osRtxTimerInactive;
  175. timer->id = osRtxIdInvalid;
  176. // Free object memory
  177. if ((timer->flags & osRtxFlagSystemObject) != 0U) {
  178. #ifdef RTX_OBJ_PTR_CHECK
  179. (void)osRtxMemoryPoolFree(osRtxInfo.mpi.timer, timer);
  180. #else
  181. if (osRtxInfo.mpi.timer != NULL) {
  182. (void)osRtxMemoryPoolFree(osRtxInfo.mpi.timer, timer);
  183. } else {
  184. (void)osRtxMemoryFree(osRtxInfo.mem.common, timer);
  185. }
  186. #endif
  187. #ifdef RTX_OBJ_MEM_USAGE
  188. osRtxTimerMemUsage.cnt_free++;
  189. #endif
  190. }
  191. EvrRtxTimerDestroyed(timer);
  192. }
  193. #ifdef RTX_SAFETY_CLASS
  194. /// Delete a Timer safety class.
  195. /// \param[in] safety_class safety class.
  196. /// \param[in] mode safety mode.
  197. void osRtxTimerDeleteClass (uint32_t safety_class, uint32_t mode) {
  198. os_timer_t *timer;
  199. uint32_t length;
  200. //lint --e{923} --e{9078} "cast from pointer to unsigned int" [MISRA Note 7]
  201. timer = (os_timer_t *)(uint32_t)&__os_timer_cb_start__;
  202. length = (uint32_t)&__os_timer_cb_length__;
  203. while (length >= sizeof(os_timer_t)) {
  204. if ( (timer->id == osRtxIdTimer) &&
  205. ((((mode & osSafetyWithSameClass) != 0U) &&
  206. ((timer->attr >> osRtxAttrClass_Pos) == (uint8_t)safety_class)) ||
  207. (((mode & osSafetyWithLowerClass) != 0U) &&
  208. ((timer->attr >> osRtxAttrClass_Pos) < (uint8_t)safety_class)))) {
  209. if (timer->state == osRtxTimerRunning) {
  210. TimerRemove(timer);
  211. }
  212. osRtxTimerDestroy(timer);
  213. }
  214. length -= sizeof(os_timer_t);
  215. timer++;
  216. }
  217. }
  218. #endif
  219. // ==== Service Calls ====
  220. /// Create and Initialize a timer.
  221. /// \note API identical to osTimerNew
  222. static osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
  223. os_timer_t *timer;
  224. #ifdef RTX_SAFETY_CLASS
  225. const os_thread_t *thread = osRtxThreadGetRunning();
  226. uint32_t attr_bits;
  227. #endif
  228. uint8_t flags;
  229. const char *name;
  230. // Check parameters
  231. if ((func == NULL) || ((type != osTimerOnce) && (type != osTimerPeriodic))) {
  232. EvrRtxTimerError(NULL, (int32_t)osErrorParameter);
  233. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  234. return NULL;
  235. }
  236. // Process attributes
  237. if (attr != NULL) {
  238. name = attr->name;
  239. #ifdef RTX_SAFETY_CLASS
  240. attr_bits = attr->attr_bits;
  241. #endif
  242. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 6]
  243. timer = attr->cb_mem;
  244. #ifdef RTX_SAFETY_CLASS
  245. if ((attr_bits & osSafetyClass_Valid) != 0U) {
  246. if ((thread != NULL) &&
  247. ((thread->attr >> osRtxAttrClass_Pos) <
  248. (uint8_t)((attr_bits & osSafetyClass_Msk) >> osSafetyClass_Pos))) {
  249. EvrRtxTimerError(NULL, (int32_t)osErrorSafetyClass);
  250. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  251. return NULL;
  252. }
  253. }
  254. #endif
  255. if (timer != NULL) {
  256. if (!IsTimerPtrValid(timer) || (attr->cb_size != sizeof(os_timer_t))) {
  257. EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock);
  258. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  259. return NULL;
  260. }
  261. } else {
  262. if (attr->cb_size != 0U) {
  263. EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock);
  264. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  265. return NULL;
  266. }
  267. }
  268. } else {
  269. name = NULL;
  270. #ifdef RTX_SAFETY_CLASS
  271. attr_bits = 0U;
  272. #endif
  273. timer = NULL;
  274. }
  275. // Allocate object memory if not provided
  276. if (timer == NULL) {
  277. if (osRtxInfo.mpi.timer != NULL) {
  278. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  279. timer = osRtxMemoryPoolAlloc(osRtxInfo.mpi.timer);
  280. #ifndef RTX_OBJ_PTR_CHECK
  281. } else {
  282. //lint -e{9079} "conversion from pointer to void to pointer to other type" [MISRA Note 5]
  283. timer = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_timer_t), 1U);
  284. #endif
  285. }
  286. #ifdef RTX_OBJ_MEM_USAGE
  287. if (timer != NULL) {
  288. uint32_t used;
  289. osRtxTimerMemUsage.cnt_alloc++;
  290. used = osRtxTimerMemUsage.cnt_alloc - osRtxTimerMemUsage.cnt_free;
  291. if (osRtxTimerMemUsage.max_used < used) {
  292. osRtxTimerMemUsage.max_used = used;
  293. }
  294. }
  295. #endif
  296. flags = osRtxFlagSystemObject;
  297. } else {
  298. flags = 0U;
  299. }
  300. if (timer != NULL) {
  301. // Initialize control block
  302. timer->id = osRtxIdTimer;
  303. timer->state = osRtxTimerStopped;
  304. timer->flags = flags;
  305. if (type == osTimerPeriodic) {
  306. timer->attr = osRtxTimerPeriodic;
  307. } else {
  308. timer->attr = 0U;
  309. }
  310. timer->name = name;
  311. timer->prev = NULL;
  312. timer->next = NULL;
  313. timer->tick = 0U;
  314. timer->load = 0U;
  315. timer->finfo.func = func;
  316. timer->finfo.arg = argument;
  317. #ifdef RTX_SAFETY_CLASS
  318. if ((attr_bits & osSafetyClass_Valid) != 0U) {
  319. timer->attr |= (uint8_t)((attr_bits & osSafetyClass_Msk) >>
  320. (osSafetyClass_Pos - osRtxAttrClass_Pos));
  321. } else {
  322. // Inherit safety class from the running thread
  323. if (thread != NULL) {
  324. timer->attr |= (uint8_t)(thread->attr & osRtxAttrClass_Msk);
  325. }
  326. }
  327. #endif
  328. EvrRtxTimerCreated(timer, timer->name);
  329. } else {
  330. EvrRtxTimerError(NULL, (int32_t)osErrorNoMemory);
  331. }
  332. return timer;
  333. }
  334. /// Get name of a timer.
  335. /// \note API identical to osTimerGetName
  336. static const char *svcRtxTimerGetName (osTimerId_t timer_id) {
  337. os_timer_t *timer = osRtxTimerId(timer_id);
  338. // Check parameters
  339. if (!IsTimerPtrValid(timer) || (timer->id != osRtxIdTimer)) {
  340. EvrRtxTimerGetName(timer, NULL);
  341. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  342. return NULL;
  343. }
  344. EvrRtxTimerGetName(timer, timer->name);
  345. return timer->name;
  346. }
  347. /// Start or restart a timer.
  348. /// \note API identical to osTimerStart
  349. static osStatus_t svcRtxTimerStart (osTimerId_t timer_id, uint32_t ticks) {
  350. os_timer_t *timer = osRtxTimerId(timer_id);
  351. #ifdef RTX_SAFETY_CLASS
  352. const os_thread_t *thread;
  353. #endif
  354. // Check parameters
  355. if (!IsTimerPtrValid(timer) || (timer->id != osRtxIdTimer) || (ticks == 0U)) {
  356. EvrRtxTimerError(timer, (int32_t)osErrorParameter);
  357. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  358. return osErrorParameter;
  359. }
  360. #ifdef RTX_SAFETY_CLASS
  361. // Check running thread safety class
  362. thread = osRtxThreadGetRunning();
  363. if ((thread != NULL) &&
  364. ((thread->attr >> osRtxAttrClass_Pos) < (timer->attr >> osRtxAttrClass_Pos))) {
  365. EvrRtxTimerError(timer, (int32_t)osErrorSafetyClass);
  366. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  367. return osErrorSafetyClass;
  368. }
  369. #endif
  370. if (timer->state == osRtxTimerRunning) {
  371. timer->load = ticks;
  372. TimerRemove(timer);
  373. } else {
  374. if (osRtxInfo.timer.tick == NULL) {
  375. EvrRtxTimerError(timer, (int32_t)osErrorResource);
  376. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  377. return osErrorResource;
  378. } else {
  379. timer->state = osRtxTimerRunning;
  380. timer->load = ticks;
  381. }
  382. }
  383. TimerInsert(timer, ticks);
  384. EvrRtxTimerStarted(timer);
  385. return osOK;
  386. }
  387. /// Stop a timer.
  388. /// \note API identical to osTimerStop
  389. static osStatus_t svcRtxTimerStop (osTimerId_t timer_id) {
  390. os_timer_t *timer = osRtxTimerId(timer_id);
  391. #ifdef RTX_SAFETY_CLASS
  392. const os_thread_t *thread;
  393. #endif
  394. // Check parameters
  395. if (!IsTimerPtrValid(timer) || (timer->id != osRtxIdTimer)) {
  396. EvrRtxTimerError(timer, (int32_t)osErrorParameter);
  397. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  398. return osErrorParameter;
  399. }
  400. #ifdef RTX_SAFETY_CLASS
  401. // Check running thread safety class
  402. thread = osRtxThreadGetRunning();
  403. if ((thread != NULL) &&
  404. ((thread->attr >> osRtxAttrClass_Pos) < (timer->attr >> osRtxAttrClass_Pos))) {
  405. EvrRtxTimerError(timer, (int32_t)osErrorSafetyClass);
  406. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  407. return osErrorSafetyClass;
  408. }
  409. #endif
  410. // Check object state
  411. if (timer->state != osRtxTimerRunning) {
  412. EvrRtxTimerError(timer, (int32_t)osErrorResource);
  413. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  414. return osErrorResource;
  415. }
  416. timer->state = osRtxTimerStopped;
  417. TimerRemove(timer);
  418. EvrRtxTimerStopped(timer);
  419. return osOK;
  420. }
  421. /// Check if a timer is running.
  422. /// \note API identical to osTimerIsRunning
  423. static uint32_t svcRtxTimerIsRunning (osTimerId_t timer_id) {
  424. os_timer_t *timer = osRtxTimerId(timer_id);
  425. uint32_t is_running;
  426. // Check parameters
  427. if (!IsTimerPtrValid(timer) || (timer->id != osRtxIdTimer)) {
  428. EvrRtxTimerIsRunning(timer, 0U);
  429. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  430. return 0U;
  431. }
  432. if (timer->state == osRtxTimerRunning) {
  433. EvrRtxTimerIsRunning(timer, 1U);
  434. is_running = 1U;
  435. } else {
  436. EvrRtxTimerIsRunning(timer, 0U);
  437. is_running = 0;
  438. }
  439. return is_running;
  440. }
  441. /// Delete a timer.
  442. /// \note API identical to osTimerDelete
  443. static osStatus_t svcRtxTimerDelete (osTimerId_t timer_id) {
  444. os_timer_t *timer = osRtxTimerId(timer_id);
  445. #ifdef RTX_SAFETY_CLASS
  446. const os_thread_t *thread;
  447. #endif
  448. // Check parameters
  449. if (!IsTimerPtrValid(timer) || (timer->id != osRtxIdTimer)) {
  450. EvrRtxTimerError(timer, (int32_t)osErrorParameter);
  451. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  452. return osErrorParameter;
  453. }
  454. #ifdef RTX_SAFETY_CLASS
  455. // Check running thread safety class
  456. thread = osRtxThreadGetRunning();
  457. if ((thread != NULL) &&
  458. ((thread->attr >> osRtxAttrClass_Pos) < (timer->attr >> osRtxAttrClass_Pos))) {
  459. EvrRtxTimerError(timer, (int32_t)osErrorSafetyClass);
  460. //lint -e{904} "Return statement before end of function" [MISRA Note 1]
  461. return osErrorSafetyClass;
  462. }
  463. #endif
  464. if (timer->state == osRtxTimerRunning) {
  465. TimerRemove(timer);
  466. }
  467. osRtxTimerDestroy(timer);
  468. return osOK;
  469. }
  470. // Service Calls definitions
  471. //lint ++flb "Library Begin" [MISRA Note 11]
  472. SVC0_4(TimerNew, osTimerId_t, osTimerFunc_t, osTimerType_t, void *, const osTimerAttr_t *)
  473. SVC0_1(TimerGetName, const char *, osTimerId_t)
  474. SVC0_2(TimerStart, osStatus_t, osTimerId_t, uint32_t)
  475. SVC0_1(TimerStop, osStatus_t, osTimerId_t)
  476. SVC0_1(TimerIsRunning, uint32_t, osTimerId_t)
  477. SVC0_1(TimerDelete, osStatus_t, osTimerId_t)
  478. //lint --flb "Library End"
  479. // ==== Public API ====
  480. /// Create and Initialize a timer.
  481. osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
  482. osTimerId_t timer_id;
  483. EvrRtxTimerNew(func, type, argument, attr);
  484. if (IsException() || IsIrqMasked()) {
  485. EvrRtxTimerError(NULL, (int32_t)osErrorISR);
  486. timer_id = NULL;
  487. } else {
  488. timer_id = __svcTimerNew(func, type, argument, attr);
  489. }
  490. return timer_id;
  491. }
  492. /// Get name of a timer.
  493. const char *osTimerGetName (osTimerId_t timer_id) {
  494. const char *name;
  495. if (IsException() || IsIrqMasked()) {
  496. name = svcRtxTimerGetName(timer_id);
  497. } else {
  498. name = __svcTimerGetName(timer_id);
  499. }
  500. return name;
  501. }
  502. /// Start or restart a timer.
  503. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) {
  504. osStatus_t status;
  505. EvrRtxTimerStart(timer_id, ticks);
  506. if (IsException() || IsIrqMasked()) {
  507. EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
  508. status = osErrorISR;
  509. } else {
  510. status = __svcTimerStart(timer_id, ticks);
  511. }
  512. return status;
  513. }
  514. /// Stop a timer.
  515. osStatus_t osTimerStop (osTimerId_t timer_id) {
  516. osStatus_t status;
  517. EvrRtxTimerStop(timer_id);
  518. if (IsException() || IsIrqMasked()) {
  519. EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
  520. status = osErrorISR;
  521. } else {
  522. status = __svcTimerStop(timer_id);
  523. }
  524. return status;
  525. }
  526. /// Check if a timer is running.
  527. uint32_t osTimerIsRunning (osTimerId_t timer_id) {
  528. uint32_t is_running;
  529. if (IsException() || IsIrqMasked()) {
  530. EvrRtxTimerIsRunning(timer_id, 0U);
  531. is_running = 0U;
  532. } else {
  533. is_running = __svcTimerIsRunning(timer_id);
  534. }
  535. return is_running;
  536. }
  537. /// Delete a timer.
  538. osStatus_t osTimerDelete (osTimerId_t timer_id) {
  539. osStatus_t status;
  540. EvrRtxTimerDelete(timer_id);
  541. if (IsException() || IsIrqMasked()) {
  542. EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
  543. status = osErrorISR;
  544. } else {
  545. status = __svcTimerDelete(timer_id);
  546. }
  547. return status;
  548. }