51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
#include <os_idle.h>
|
|||
|
|
#include "os_align.h"
|
||
|
|
#include "os_critical.h"
|
||
|
|
|
||
|
|
os_task_t g_os_idle_task;
|
||
|
|
|
||
|
|
#ifndef OS_CFG_IDLE_TASK_STACK_SIZE
|
||
|
|
#define OS_CFG_IDLE_TASK_STACK_SIZE 1024
|
||
|
|
#endif /* OS_CFG_IDLE_TASK_STACK_SIZE */
|
||
|
|
|
||
|
|
#ifndef OS_CFG_IDLE_TASK_TICKS
|
||
|
|
#define OS_CFG_IDLE_TASK_TICKS 5
|
||
|
|
#endif /* OS_CFG_IDLE_TASK_TICKS */
|
||
|
|
|
||
|
|
#ifndef OS_CFG_IDLE_TASK_PRIORITY
|
||
|
|
#define OS_CFG_IDLE_TASK_PRIORITY OS_PRIORITY_IDLE
|
||
|
|
#endif /* OS_CFG_IDLE_TASK_PRIORITY */
|
||
|
|
|
||
|
|
OS_ALIGNED(OS_ALIGN_SIZE)
|
||
|
|
static uint8_t s_os_idle_stack[OS_CFG_IDLE_TASK_STACK_SIZE];
|
||
|
|
|
||
|
|
static volatile os_idle_entry_t s_os_idle_entry;
|
||
|
|
static volatile void* s_os_idle_entry_param;
|
||
|
|
|
||
|
|
static OS_NORETURN void os_idle_entry(void* p){
|
||
|
|
while(1){
|
||
|
|
if(s_os_idle_entry){
|
||
|
|
s_os_idle_entry((void*)s_os_idle_entry_param);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void os_idle_init(void){
|
||
|
|
os_task_init(&g_os_idle_task, os_idle_entry, 0
|
||
|
|
, s_os_idle_stack, OS_ARRAY_SIZE(s_os_idle_stack)
|
||
|
|
, OS_CFG_IDLE_TASK_TICKS, OS_CFG_IDLE_TASK_PRIORITY);
|
||
|
|
}
|
||
|
|
|
||
|
|
os_idle_closure_t os_idle_register(os_idle_entry_t entry, void* param){
|
||
|
|
os_idle_closure_t closure;
|
||
|
|
|
||
|
|
os_critical_enter();
|
||
|
|
closure.entry = s_os_idle_entry;
|
||
|
|
closure.param = (void*)s_os_idle_entry_param;
|
||
|
|
s_os_idle_entry = entry;
|
||
|
|
s_os_idle_entry_param = param;
|
||
|
|
os_critical_leave();
|
||
|
|
return closure;
|
||
|
|
}
|
||
|
|
|