23#if VSF_USE_KERNEL == ENABLED && defined(__EDA_GADGET__)
25#if __IS_COMPILER_IAR__
27# pragma diag_suppress=pe111
33#if VSF_CALLBACK_TIMER_CFG_SUPPORT_ISR == ENABLED
34# define __vsf_callback_timer_protect vsf_protect(interrupt)
35# define __vsf_callback_timer_unprotect vsf_unprotect(interrupt)
37# define __vsf_callback_timer_protect vsf_protect(scheduler)
38# define __vsf_callback_timer_unprotect vsf_unprotect(scheduler)
46#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
47# if VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_NONE
48# if (VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS) \
49 && (VSF_SYSTIMER_CFG_IMPL_MODE == VSF_SYSTIMER_IMPL_TICK_MODE)
50# error systimer is in tick mode while tickless mode is required on kernel
52# if (VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICK) \
53 && (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_TICK_MODE)
54# warning systimer is not in tick mode while tick mode is required on kernel,\
55 ignore this warning if your arch does not support tick mode systimer,\
56 or set VSF_SYSTIMER_CFG_IMPL_MODE to VSF_SYSTIMER_IMPL_TICK_MODE\
57 for better optimization.
61# if VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS \
62 && (VSF_SYSTIMER_CFG_IMPL_MODE == VSF_SYSTIMER_IMPL_NONE)
81#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
95#if (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_NONE) \
96 && (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_TICK_MODE)
97# if VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS
98static void __vsf_systimer_wakeup(
void);
100static void __vsf_systimer_update(
bool force)
110# if VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS
111 if (force || (teda->due != __vsf_eda.timer.pre_tick)) {
112 __vsf_eda.timer.pre_tick = teda->due;
114 __vsf_systimer_wakeup();
124#if VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS
126static void __vsf_systimer_wakeup(
void)
128 if (!__vsf_eda.timer.processing) {
129 __vsf_eda.timer.processing =
true;
131 __vsf_eda.timer.processing =
false;
143static
void __vsf_systimer_start(
void)
153#if VSF_KERNEL_CFG_TRACE == ENABLED
154 if (!__vsf_eda.timer.is_isr_info_sent) {
155 __vsf_eda.timer.is_isr_info_sent =
true;
162 __vsf_systimer_wakeup();
164#if VSF_KERNEL_CFG_TRACE == ENABLED
172 __vsf_teda_timer_enqueue(this_ptr, due);
173#if (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_NONE) \
174 && (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_TICK_MODE)
175 __vsf_systimer_update(
false);
187static
void __vsf_systimer_start(
void)
221 vsf_eda_post_evt(task, VSF_EVT_TIMER);
223#elif defined(__VSF_OS_CFG_EVTQ_ARRAY)
224 if (0 == task->evt_cnt) {
225 vsf_eda_post_evt(task, VSF_EVT_TIMER);
235 __vsf_teda_timer_enqueue(this_ptr, due);
239#if (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_NONE) \
240 && (VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_TICK_MODE)
241 __vsf_systimer_update(
false);
254static
void __vsf_systimer_init(
void)
256#if VSF_KERNEL_CFG_TIMER_MODE == VSF_KERNEL_CFG_TIMER_MODE_TICKLESS
257 __vsf_eda.timer.processing =
false;
260#if VSF_KERNEL_CFG_SUPPORT_CALLBACK_TIMER == ENABLED
265#if VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_IMPL_NONE
277 this_ptr->use_as__vsf_eda_t.flag.state.is_timed =
true;
278#if VSF_KERNEL_OPT_AVOID_UNNECESSARY_YIELD_EVT == ENABLED
280 this_ptr->use_as__vsf_eda_t.is_evt_incoming =
true;
285#if VSF_KERNEL_CFG_SUPPORT_CALLBACK_TIMER == ENABLED
296# if VSF_CALLBACK_TIMER_CFG_SUPPORT_ISR == ENABLED
299 bool is_to_update =
false;
303 if (timer->due != 0) {
309# if VSF_CALLBACK_TIMER_CFG_SUPPORT_ISR == ENABLED
310 lock_status = __vsf_callback_timer_protect();
314 if (
NULL == timer->timer_node.prev) {
317# if VSF_CALLBACK_TIMER_CFG_SUPPORT_ISR == ENABLED
318 __vsf_callback_timer_unprotect(lock_status);
322 __vsf_teda_set_timer_imp((
vsf_teda_t *)&__vsf_eda.task, timer->due);
340 lock_status = __vsf_callback_timer_protect();
341 if (timer->due != 0) {
345 __vsf_callback_timer_unprotect(lock_status);
349# if VSF_CALLBACK_TIMER_CFG_SUPPORT_ISR == ENABLED
354 if (timer->due != 0) {
403 err = __vsf_teda_set_timer_imp(this_ptr, due);
418#if __IS_COMPILER_ARM_COMPILER_6__
419# pragma clang diagnostic push
420# pragma clang diagnostic ignored "-Wcast-align"
423#if __IS_COMPILER_GCC__
424# pragma GCC diagnostic push
425# pragma GCC diagnostic ignored "-Wcast-align"
436#if __IS_COMPILER_ARM_COMPILER_6__
437# pragma clang diagnostic pop
440#if __IS_COMPILER_GCC__
441# pragma GCC diagnostic pop
444#if __IS_COMPILER_ARM_COMPILER_6__
445# pragma clang diagnostic push
446# pragma clang diagnostic ignored "-Wcast-align"
449#if __IS_COMPILER_GCC__
450# pragma GCC diagnostic push
451# pragma GCC diagnostic ignored "-Wcast-align"
463 if (this_ptr->use_as__vsf_eda_t.flag.state.is_timed) {
465 this_ptr->use_as__vsf_eda_t.flag.state.is_timed =
false;
467#if (VSF_KERNEL_CFG_SUPPORT_SYNC == ENABLED) && defined(__VSF_OS_CFG_EVTQ_LIST)
468 this_ptr->use_as__vsf_eda_t.flag.state.is_to_set_due =
false;
478#if VSF_KERNEL_CFG_ALLOW_KERNEL_BEING_PREEMPTED == ENABLED
484#if __IS_COMPILER_ARM_COMPILER_6__
485# pragma clang diagnostic pop
488#if __IS_COMPILER_GCC__
489# pragma GCC diagnostic pop
494#if __IS_COMPILER_IAR__
496# pragma diag_warning=pe111
#define VSF_CAL_SECTION(__SEC_STR)
Definition __compiler.h:189
#define VSF_UNUSED_PARAM(__VAL)
Definition __type.h:190
vsf_err_t
Definition __type.h:42
@ VSF_ERR_NONE
none error
Definition __type.h:44
@ VSF_ERR_NOT_AVAILABLE
service not available
Definition __type.h:47
@ VSF_ERR_FAIL
failed
Definition __type.h:51
Task-independent timer; when it expires the kernel task invokes the user callback.
Definition vsf_eda.h:1937
The event-driven task (TCB); every VSF task is an eda at the bottom. Tasks share stacks and only occu...
Definition vsf_eda.h:1838
eda with timer support (can use vsf_teda_set_timer() etc.); derived classes (task/pt/thread) inherit ...
Definition vsf_eda.h:1916
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:70
void vsf_systimer_prio_set(vsf_arch_prio_t priority)
Definition cortex_m_generic.c:249
int vsf_get_interrupt_id(void)
Definition cortex_m_generic.c:434
void vsf_systimer_set_idle(void)
Definition linux_generic.c:398
bool vsf_systimer_is_due(vsf_systimer_tick_t due)
Definition linux_generic.c:430
vsf_systimer_tick_t vsf_systimer_ms_to_tick(uint_fast32_t time_ms)
Definition linux_generic.c:440
vsf_systimer_tick_t vsf_systimer_us_to_tick(uint_fast32_t time_us)
Definition linux_generic.c:435
vsf_systimer_tick_t vsf_systimer_tick_to_ms(vsf_systimer_tick_t tick)
Definition linux_generic.c:450
vsf_err_t vsf_systimer_start(void)
Definition linux_generic.c:390
bool vsf_systimer_set(vsf_systimer_tick_t due)
Definition linux_generic.c:409
#define NULL
Definition lvgl.h:26
unsigned int uint_fast32_t
Definition stdint.h:27
Configuration for starting an eda/teda task (vsf_eda_start(), vsf_teda_start(), init_vsf_peda(),...
Definition vsf_eda.h:1804
uintalu_t vsf_protect_t
Definition vsf_arch_abstraction.h:60
#define vsf_protect_int
Definition vsf_arch_abstraction.h:376
#define vsf_unprotect_int
Definition vsf_arch_abstraction.h:377
vsf_err_t vsf_eda_post_evt(vsf_eda_t *pthis, vsf_evt_t evt)
Post an event to an eda task.
Definition vsf_eda.c:935
vsf_err_t vsf_eda_post_evt_msg(vsf_eda_t *pthis, vsf_evt_t evt, void *msg)
Post an event carrying a pointer message to an eda task; the pointer is retrieved with vsf_eda_get_cu...
Definition vsf_eda.c:969
vsf_eda_t * vsf_eda_get_cur(void)
Get the eda task currently being dispatched.
Definition vsf_eda.c:416
vsf_err_t vsf_eda_start(vsf_eda_t *pthis, vsf_eda_cfg_t *cfg_ptr)
Start an eda task with the given configuration and post VSF_EVT_INIT to it.
Definition vsf_eda.c:835
void vsf_kernel_err_report(enum vsf_kernel_error_t err)
Report a kernel error.
Definition vsf_eda.c:409
void vsf_systimer_on_tick(void)
System timer tick handler; called by the user on every system tick to drive the kernel timers.
vsf_err_t vsf_teda_cancel_timer(void)
Cancel the pending timer of the current teda task.
vsf_err_t vsf_callback_timer_add_isr(vsf_callback_timer_t *timer, vsf_systimer_tick_t tick)
Add a callback timer with a relative interval in ticks from interrupt context.
vsf_err_t vsf_callback_timer_remove_isr(vsf_callback_timer_t *timer)
Remove a callback timer from interrupt context.
vsf_err_t vsf_teda_set_timer(vsf_systimer_tick_t tick)
Set a one-shot timer of the given ticks for the current teda task; the task receives VSF_EVT_TIMER wh...
@ VSF_EVT_TIMER
teda timer expired (only for teda tasks)
Definition vsf_eda.h:1569
@ VSF_KERNEL_ERR_INVALID_USAGE
API used incorrectly.
Definition vsf_eda.h:2370
void vsf_callback_timer_init(vsf_callback_timer_t *timer)
Initialize a task-independent callback timer; set the on_timer callback before adding the timer.
vsf_systimer_tick_t vsf_systimer_get_elapsed(vsf_systimer_tick_t from_time)
Get the ticks elapsed from the given tick count to now.
vsf_systimer_tick_t vsf_systimer_get_tick(void)
Get the current system timer tick count.
vsf_err_t vsf_callback_timer_add_due(vsf_callback_timer_t *timer, vsf_systimer_tick_t due)
Add a callback timer with an absolute due tick.
vsf_err_t vsf_teda_set_timer_ex(vsf_teda_t *pthis, vsf_systimer_tick_t tick)
Set a one-shot timer of the given ticks for the given teda task; the task receives VSF_EVT_TIMER when...
vsf_err_t vsf_callback_timer_add(vsf_callback_timer_t *timer, vsf_systimer_tick_t tick)
Add a callback timer with a relative interval in ticks.
vsf_err_t vsf_teda_start(vsf_teda_t *pthis, vsf_eda_cfg_t *cfg)
Start a teda (eda with timer support) task with the given configuration and post VSF_EVT_INIT to it.
@ VSF_KERNEL_EVT_CALLBACK_TIMER_ADD
Definition vsf_eda.h:1608
vsf_err_t vsf_teda_set_due_ex(vsf_teda_t *this_ptr, vsf_systimer_tick_t due)
Set a one-shot timer with an absolute due tick for the given teda task.
vsf_err_t vsf_callback_timer_add_due_isr(vsf_callback_timer_t *timer, vsf_systimer_tick_t due)
Add a callback timer with an absolute due tick from interrupt context.
vsf_systimer_tick_t vsf_systimer_get_duration(vsf_systimer_tick_t from_time, vsf_systimer_tick_t to_time)
Get the tick duration between two tick counts, handling wrap-around.
vsf_err_t __vsf_teda_cancel_timer(vsf_teda_t *pthis)
Cancel the pending timer of the given teda task.
vsf_err_t vsf_callback_timer_remove(vsf_callback_timer_t *timer)
Remove a callback timer before it expires.
void vsf_evtq_clean_evt(vsf_evt_t evt)
Clean the pending event(s) posted to the current eda.
Definition vsf_evtq_list.c:257
#define __VSF_OS_CFG_EVTQ_LIST
Definition vsf_kernel_cfg.h:304
#define VSF_KERNEL_ASSERT
Definition vsf_kernel_cfg.h:32
#define vsf_slist_queue_is_empty(__queue_ptr)
Definition vsf_list.h:642
#define vsf_protect_sched()
Lock the scheduler and return the previous status as vsf_protect_t.
Definition vsf_os.h:271
#define vsf_unprotect_sched(__prot)
Restore the scheduler lock status saved by vsf_protect_sched()
Definition vsf_os.h:283
vsf_systimer_tick_t vsf_systimer_get(void)
Definition linux_generic.c:402
vsf_systimer_tick_t vsf_systimer_tick_to_us(vsf_systimer_tick_t tick)
Definition linux_generic.c:445
vsf_err_t vsf_systimer_init(void)
initialise SysTick to generate a system timer !
Definition linux_generic.c:365
#define vsf_callback_timq_remove(__queue, __timer)
Remove a callback timer from the timer queue.
Definition vsf_timq_dlist.h:184
#define vsf_timq_peek(__queue, __teda)
Get the head timer eda (the earliest due) of the timer queue without removing it.
Definition vsf_timq_dlist.h:95
#define vsf_timq_init(__queue)
Initialize a timer queue.
Definition vsf_timq_dlist.h:42
#define vsf_timq_insert(__queue, __teda)
Insert a timer eda into the timer queue, sorted in ascending order of due.
Definition vsf_timq_dlist.h:56
#define vsf_callback_timq_init(__queue)
Initialize a callback timer queue.
Definition vsf_timq_dlist.h:133
#define vsf_timq_remove(__queue, __teda)
Remove a timer eda from the timer queue.
Definition vsf_timq_dlist.h:75
#define vsf_callback_timq_insert(__queue, __timer)
Insert a callback timer into the timer queue, sorted in ascending order of due.
Definition vsf_timq_dlist.h:165