Files
RTOS/Kernel/SingleCore/os_systick.h
T

92 lines
2.4 KiB
C
Raw Normal View History

2026-05-19 11:49:22 +08:00
#ifndef INCLUDED_OS_SYSTICK_H
#define INCLUDED_OS_SYSTICK_H
#ifndef INCLUDED_OS_TYPES_H
#include <os_types.h>
#endif /*INCLUDED_OS_TYPES_H*/
#ifndef INCLUDED_OS_COMPILER_H
#include <os_compiler.h>
#endif /*INCLUDED_OS_COMPILER_H*/
#ifndef INCLUDED_OS_CRITICAL_H
#include <os_critical.h>
#endif /*INCLUDED_OS_CRITICAL_H*/
#ifndef INCLUDED_OS_SCHED_H
#include <os_sched.h>
#endif /*INCLUDED_OS_SCHED_H*/
#ifndef INCLUDED_OS_YIELD_LIST_H
#include <os_yield_list.h>
#endif /*INCLUDED_OS_YIELD_LIST_H*/
#ifndef INCLUDED_OS_TIMEWHEEL_H
#include <os_timewheel.h>
#endif /*INCLUDED_OS_TIMEWHEEL_H*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
extern volatile os_tick_t g_os_systick_ticks;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
OS_STATIC_FORCE_INLINE
void os_systick_tick(void){
os_critical_enter_in_isr();
os_bool_t need_sched_flag = OS_FALSE;
g_os_systick_ticks++;
if(g_os_sched_current_task_p && g_os_sched_current_task_p->state == kOsTaskState_Running){
if(g_os_sched_current_task_p->remain_ticks>0
&& (g_os_sched_current_task_p->remain_ticks <= g_os_sched_current_task_p->init_ticks)){
g_os_sched_current_task_p->remain_ticks--;
if(g_os_sched_current_task_p->remain_ticks==0){
// 时间窗用完了
g_os_sched_current_task_p->remain_ticks = g_os_sched_current_task_p->init_ticks; // 重置时间窗
os_yield_list_insert((os_task_t*)g_os_sched_current_task_p); // 加入yield列表
need_sched_flag = OS_TRUE;
}
}
}
os_err_t err = os_timewheel_tick();
if(err==OS_TIMEWHEEL_TICK_NEED_SCHEDULE){
need_sched_flag = OS_TRUE;
}
os_critical_leave_in_isr();
if(need_sched_flag == OS_TRUE){
os_sched_in_isr();
}
}
OS_STATIC_FORCE_INLINE
os_tick_t os_systick_get(void){
2026-06-05 23:18:54 +08:00
return g_os_systick_ticks;
2026-05-19 11:49:22 +08:00
}
2026-07-19 17:55:03 +08:00
OS_STATIC_FORCE_INLINE
os_tick_t os_systick_safe_get(void) {
os_critical_enter();
const os_tick_t ticks = g_os_systick_ticks;
os_critical_leave();
return ticks;
}
2026-05-19 11:49:22 +08:00
2026-07-19 17:55:03 +08:00
OS_STATIC_FORCE_INLINE
os_tick_t os_systick_safe_get_in_isr(void) {
os_critical_enter_in_isr();
const os_tick_t ticks = g_os_systick_ticks;
os_critical_leave_in_isr();
return ticks;
}
2026-05-19 11:49:22 +08:00
#endif /*INCLUDED_OS_SYSTICK_H*/