import
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#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){
|
||||
os_critical_enter();
|
||||
os_tick_t ticks = g_os_systick_ticks;
|
||||
os_critical_leave();
|
||||
return ticks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /*INCLUDED_OS_SYSTICK_H*/
|
||||
Reference in New Issue
Block a user