2022-08-15 04:20:27 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2019 Arm Limited. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Project: CMSIS-RTOS RTX
|
|
|
|
* Title: Timer functions
|
|
|
|
*
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rtx_lib.h"
|
|
|
|
|
|
|
|
// OS Runtime Object Memory Usage
|
|
|
|
#if ((defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0)))
|
2023-02-01 14:52:54 -06:00
|
|
|
osRtxObjectMemUsage_t osRtxTimerMemUsage
|
|
|
|
__attribute__((section(".data.os.timer.obj"))) = {0U, 0U, 0U};
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// ==== Helper functions ====
|
|
|
|
|
|
|
|
/// Insert Timer into the Timer List sorted by Time.
|
|
|
|
/// \param[in] timer timer object.
|
|
|
|
/// \param[in] tick timer tick.
|
2023-02-01 14:52:54 -06:00
|
|
|
static void TimerInsert(os_timer_t *timer, uint32_t tick) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *prev, *next;
|
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
next = osRtxInfo.timer.list;
|
|
|
|
while ((next != NULL) && (next->tick <= tick)) {
|
|
|
|
tick -= next->tick;
|
2023-02-01 14:52:54 -06:00
|
|
|
prev = next;
|
|
|
|
next = next->next;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
timer->tick = tick;
|
|
|
|
timer->prev = prev;
|
|
|
|
timer->next = next;
|
|
|
|
if (next != NULL) {
|
|
|
|
next->tick -= timer->tick;
|
2023-02-01 14:52:54 -06:00
|
|
|
next->prev = timer;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
if (prev != NULL) {
|
|
|
|
prev->next = timer;
|
|
|
|
} else {
|
|
|
|
osRtxInfo.timer.list = timer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove Timer from the Timer List.
|
|
|
|
/// \param[in] timer timer object.
|
2023-02-01 14:52:54 -06:00
|
|
|
static void TimerRemove(const os_timer_t *timer) {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
if (timer->next != NULL) {
|
|
|
|
timer->next->tick += timer->tick;
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->next->prev = timer->prev;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
if (timer->prev != NULL) {
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->prev->next = timer->next;
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
|
|
|
osRtxInfo.timer.list = timer->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Unlink Timer from the Timer List Head.
|
|
|
|
/// \param[in] timer timer object.
|
2023-02-01 14:52:54 -06:00
|
|
|
static void TimerUnlink(const os_timer_t *timer) {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
if (timer->next != NULL) {
|
|
|
|
timer->next->prev = timer->prev;
|
|
|
|
}
|
|
|
|
osRtxInfo.timer.list = timer->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==== Library functions ====
|
|
|
|
|
|
|
|
/// Timer Tick (called each SysTick).
|
2023-02-01 14:52:54 -06:00
|
|
|
static void osRtxTimerTick(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer;
|
2023-02-01 14:52:54 -06:00
|
|
|
osStatus_t status;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
timer = osRtxInfo.timer.list;
|
|
|
|
if (timer == NULL) {
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->tick--;
|
|
|
|
while ((timer != NULL) && (timer->tick == 0U)) {
|
|
|
|
TimerUnlink(timer);
|
|
|
|
status = osMessageQueuePut(osRtxInfo.timer.mq, &timer->finfo, 0U, 0U);
|
|
|
|
if (status != osOK) {
|
|
|
|
(void)osRtxErrorNotify(osRtxErrorTimerQueueOverflow, timer);
|
|
|
|
}
|
|
|
|
if (timer->type == osRtxTimerPeriodic) {
|
|
|
|
TimerInsert(timer, timer->load);
|
|
|
|
} else {
|
|
|
|
timer->state = osRtxTimerStopped;
|
|
|
|
}
|
|
|
|
timer = osRtxInfo.timer.list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Timer Thread
|
2023-02-01 14:52:54 -06:00
|
|
|
__WEAK __NO_RETURN void osRtxTimerThread(void *argument) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_finfo_t finfo;
|
2023-02-01 14:52:54 -06:00
|
|
|
osStatus_t status;
|
|
|
|
(void)argument;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
osRtxInfo.timer.mq = osRtxMessageQueueId(
|
2023-02-01 14:52:54 -06:00
|
|
|
osMessageQueueNew(osRtxConfig.timer_mq_mcnt, sizeof(os_timer_finfo_t),
|
|
|
|
osRtxConfig.timer_mq_attr));
|
2022-08-15 04:20:27 -05:00
|
|
|
osRtxInfo.timer.tick = osRtxTimerTick;
|
|
|
|
|
|
|
|
for (;;) {
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{934} "Taking address of near auto variable"
|
2022-08-15 04:20:27 -05:00
|
|
|
status = osMessageQueueGet(osRtxInfo.timer.mq, &finfo, NULL, osWaitForever);
|
|
|
|
if (status == osOK) {
|
|
|
|
EvrRtxTimerCallback(finfo.func, finfo.arg);
|
|
|
|
(finfo.func)(finfo.arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==== Service Calls ====
|
|
|
|
|
|
|
|
/// Create and Initialize a timer.
|
|
|
|
/// \note API identical to osTimerNew
|
2023-02-01 14:52:54 -06:00
|
|
|
static osTimerId_t svcRtxTimerNew(osTimerFunc_t func, osTimerType_t type,
|
|
|
|
void *argument, const osTimerAttr_t *attr) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer;
|
2023-02-01 14:52:54 -06:00
|
|
|
uint8_t flags;
|
2022-08-15 04:20:27 -05:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((func == NULL) || ((type != osTimerOnce) && (type != osTimerPeriodic))) {
|
|
|
|
EvrRtxTimerError(NULL, (int32_t)osErrorParameter);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process attributes
|
|
|
|
if (attr != NULL) {
|
2023-02-01 14:52:54 -06:00
|
|
|
name = attr->name;
|
|
|
|
// lint -e{9079} "conversion from pointer to void to pointer to other type"
|
|
|
|
// [MISRA Note 6]
|
2022-08-15 04:20:27 -05:00
|
|
|
timer = attr->cb_mem;
|
|
|
|
if (timer != NULL) {
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e(923) -e(9078) "cast from pointer to unsigned int" [MISRA Note
|
|
|
|
// 7]
|
|
|
|
if ((((uint32_t)timer & 3U) != 0U) ||
|
|
|
|
(attr->cb_size < sizeof(os_timer_t))) {
|
2022-08-15 04:20:27 -05:00
|
|
|
EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (attr->cb_size != 0U) {
|
|
|
|
EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
name = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
timer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate object memory if not provided
|
|
|
|
if (timer == NULL) {
|
|
|
|
if (osRtxInfo.mpi.timer != NULL) {
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{9079} "conversion from pointer to void to pointer to other
|
|
|
|
// type" [MISRA Note 5]
|
2022-08-15 04:20:27 -05:00
|
|
|
timer = osRtxMemoryPoolAlloc(osRtxInfo.mpi.timer);
|
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{9079} "conversion from pointer to void to pointer to other
|
|
|
|
// type" [MISRA Note 5]
|
2022-08-15 04:20:27 -05:00
|
|
|
timer = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_timer_t), 1U);
|
|
|
|
}
|
|
|
|
#if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
|
|
|
|
if (timer != NULL) {
|
|
|
|
uint32_t used;
|
|
|
|
osRtxTimerMemUsage.cnt_alloc++;
|
|
|
|
used = osRtxTimerMemUsage.cnt_alloc - osRtxTimerMemUsage.cnt_free;
|
|
|
|
if (osRtxTimerMemUsage.max_used < used) {
|
|
|
|
osRtxTimerMemUsage.max_used = used;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
flags = osRtxFlagSystemObject;
|
|
|
|
} else {
|
|
|
|
flags = 0U;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer != NULL) {
|
|
|
|
// Initialize control block
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->id = osRtxIdTimer;
|
|
|
|
timer->state = osRtxTimerStopped;
|
|
|
|
timer->flags = flags;
|
|
|
|
timer->type = (uint8_t)type;
|
|
|
|
timer->name = name;
|
|
|
|
timer->prev = NULL;
|
|
|
|
timer->next = NULL;
|
|
|
|
timer->tick = 0U;
|
|
|
|
timer->load = 0U;
|
2022-08-15 04:20:27 -05:00
|
|
|
timer->finfo.func = func;
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->finfo.arg = argument;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
EvrRtxTimerCreated(timer, timer->name);
|
|
|
|
} else {
|
|
|
|
EvrRtxTimerError(NULL, (int32_t)osErrorNoMemory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get name of a timer.
|
|
|
|
/// \note API identical to osTimerGetName
|
2023-02-01 14:52:54 -06:00
|
|
|
static const char *svcRtxTimerGetName(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer = osRtxTimerId(timer_id);
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((timer == NULL) || (timer->id != osRtxIdTimer)) {
|
|
|
|
EvrRtxTimerGetName(timer, NULL);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EvrRtxTimerGetName(timer, timer->name);
|
|
|
|
|
|
|
|
return timer->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Start or restart a timer.
|
|
|
|
/// \note API identical to osTimerStart
|
2023-02-01 14:52:54 -06:00
|
|
|
static osStatus_t svcRtxTimerStart(osTimerId_t timer_id, uint32_t ticks) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer = osRtxTimerId(timer_id);
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((timer == NULL) || (timer->id != osRtxIdTimer) || (ticks == 0U)) {
|
|
|
|
EvrRtxTimerError(timer, (int32_t)osErrorParameter);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return osErrorParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer->state == osRtxTimerRunning) {
|
|
|
|
TimerRemove(timer);
|
|
|
|
} else {
|
|
|
|
if (osRtxInfo.timer.tick == NULL) {
|
|
|
|
EvrRtxTimerError(timer, (int32_t)osErrorResource);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return osErrorResource;
|
|
|
|
} else {
|
|
|
|
timer->state = osRtxTimerRunning;
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->load = ticks;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimerInsert(timer, ticks);
|
|
|
|
|
|
|
|
EvrRtxTimerStarted(timer);
|
|
|
|
|
|
|
|
return osOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Stop a timer.
|
|
|
|
/// \note API identical to osTimerStop
|
2023-02-01 14:52:54 -06:00
|
|
|
static osStatus_t svcRtxTimerStop(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer = osRtxTimerId(timer_id);
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((timer == NULL) || (timer->id != osRtxIdTimer)) {
|
|
|
|
EvrRtxTimerError(timer, (int32_t)osErrorParameter);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return osErrorParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check object state
|
|
|
|
if (timer->state != osRtxTimerRunning) {
|
|
|
|
EvrRtxTimerError(timer, (int32_t)osErrorResource);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return osErrorResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer->state = osRtxTimerStopped;
|
|
|
|
|
|
|
|
TimerRemove(timer);
|
|
|
|
|
|
|
|
EvrRtxTimerStopped(timer);
|
|
|
|
|
|
|
|
return osOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if a timer is running.
|
|
|
|
/// \note API identical to osTimerIsRunning
|
2023-02-01 14:52:54 -06:00
|
|
|
static uint32_t svcRtxTimerIsRunning(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer = osRtxTimerId(timer_id);
|
2023-02-01 14:52:54 -06:00
|
|
|
uint32_t is_running;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((timer == NULL) || (timer->id != osRtxIdTimer)) {
|
|
|
|
EvrRtxTimerIsRunning(timer, 0U);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return 0U;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer->state == osRtxTimerRunning) {
|
|
|
|
EvrRtxTimerIsRunning(timer, 1U);
|
|
|
|
is_running = 1U;
|
|
|
|
} else {
|
|
|
|
EvrRtxTimerIsRunning(timer, 0U);
|
|
|
|
is_running = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_running;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Delete a timer.
|
|
|
|
/// \note API identical to osTimerDelete
|
2023-02-01 14:52:54 -06:00
|
|
|
static osStatus_t svcRtxTimerDelete(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
os_timer_t *timer = osRtxTimerId(timer_id);
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
if ((timer == NULL) || (timer->id != osRtxIdTimer)) {
|
|
|
|
EvrRtxTimerError(timer, (int32_t)osErrorParameter);
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint -e{904} "Return statement before end of function" [MISRA Note 1]
|
2022-08-15 04:20:27 -05:00
|
|
|
return osErrorParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer->state == osRtxTimerRunning) {
|
|
|
|
TimerRemove(timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark object as inactive and invalid
|
|
|
|
timer->state = osRtxTimerInactive;
|
2023-02-01 14:52:54 -06:00
|
|
|
timer->id = osRtxIdInvalid;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
// Free object memory
|
|
|
|
if ((timer->flags & osRtxFlagSystemObject) != 0U) {
|
|
|
|
if (osRtxInfo.mpi.timer != NULL) {
|
|
|
|
(void)osRtxMemoryPoolFree(osRtxInfo.mpi.timer, timer);
|
|
|
|
} else {
|
|
|
|
(void)osRtxMemoryFree(osRtxInfo.mem.common, timer);
|
|
|
|
}
|
|
|
|
#if (defined(OS_OBJ_MEM_USAGE) && (OS_OBJ_MEM_USAGE != 0))
|
|
|
|
osRtxTimerMemUsage.cnt_free++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
EvrRtxTimerDestroyed(timer);
|
|
|
|
|
|
|
|
return osOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service Calls definitions
|
2023-02-01 14:52:54 -06:00
|
|
|
// lint ++flb "Library Begin" [MISRA Note 11]
|
|
|
|
SVC0_4(TimerNew, osTimerId_t, osTimerFunc_t, osTimerType_t, void *,
|
|
|
|
const osTimerAttr_t *)
|
|
|
|
SVC0_1(TimerGetName, const char *, osTimerId_t)
|
|
|
|
SVC0_2(TimerStart, osStatus_t, osTimerId_t, uint32_t)
|
|
|
|
SVC0_1(TimerStop, osStatus_t, osTimerId_t)
|
|
|
|
SVC0_1(TimerIsRunning, uint32_t, osTimerId_t)
|
|
|
|
SVC0_1(TimerDelete, osStatus_t, osTimerId_t)
|
|
|
|
// lint --flb "Library End"
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
// ==== Public API ====
|
|
|
|
|
|
|
|
/// Create and Initialize a timer.
|
2023-02-01 14:52:54 -06:00
|
|
|
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
|
|
|
|
const osTimerAttr_t *attr) {
|
2022-08-15 04:20:27 -05:00
|
|
|
osTimerId_t timer_id;
|
|
|
|
|
|
|
|
EvrRtxTimerNew(func, type, argument, attr);
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerError(NULL, (int32_t)osErrorISR);
|
|
|
|
timer_id = NULL;
|
|
|
|
} else {
|
|
|
|
timer_id = __svcTimerNew(func, type, argument, attr);
|
|
|
|
}
|
|
|
|
return timer_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get name of a timer.
|
2023-02-01 14:52:54 -06:00
|
|
|
const char *osTimerGetName(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerGetName(timer_id, NULL);
|
|
|
|
name = NULL;
|
|
|
|
} else {
|
|
|
|
name = __svcTimerGetName(timer_id);
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Start or restart a timer.
|
2023-02-01 14:52:54 -06:00
|
|
|
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) {
|
2022-08-15 04:20:27 -05:00
|
|
|
osStatus_t status;
|
|
|
|
|
|
|
|
EvrRtxTimerStart(timer_id, ticks);
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
|
|
|
|
status = osErrorISR;
|
|
|
|
} else {
|
|
|
|
status = __svcTimerStart(timer_id, ticks);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Stop a timer.
|
2023-02-01 14:52:54 -06:00
|
|
|
osStatus_t osTimerStop(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
osStatus_t status;
|
|
|
|
|
|
|
|
EvrRtxTimerStop(timer_id);
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
|
|
|
|
status = osErrorISR;
|
|
|
|
} else {
|
|
|
|
status = __svcTimerStop(timer_id);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if a timer is running.
|
2023-02-01 14:52:54 -06:00
|
|
|
uint32_t osTimerIsRunning(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
uint32_t is_running;
|
|
|
|
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerIsRunning(timer_id, 0U);
|
|
|
|
is_running = 0U;
|
|
|
|
} else {
|
|
|
|
is_running = __svcTimerIsRunning(timer_id);
|
|
|
|
}
|
|
|
|
return is_running;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Delete a timer.
|
2023-02-01 14:52:54 -06:00
|
|
|
osStatus_t osTimerDelete(osTimerId_t timer_id) {
|
2022-08-15 04:20:27 -05:00
|
|
|
osStatus_t status;
|
|
|
|
|
|
|
|
EvrRtxTimerDelete(timer_id);
|
|
|
|
if (IsIrqMode() || IsIrqMasked()) {
|
|
|
|
EvrRtxTimerError(timer_id, (int32_t)osErrorISR);
|
|
|
|
status = osErrorISR;
|
|
|
|
} else {
|
|
|
|
status = __svcTimerDelete(timer_id);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|