28#if OS_FEATURE_WATCHDOG_ENABLED == 1
29#include "os_watchdog.h"
32#if OS_USE_SCHEDULER_1ms == 1
34#ifndef OS_TIMER_NUMBER_OF_TIMERS
35#warning OS_TIMER_NUMBER_OF_TIMERS needs to be defined in main/project_setting.h
38#warning OS_USE_SYSTIME needs to be defined in main/project_setting.h
40#include "os_sys_time.h"
42#include "os_scheduler.h"
75#if OS_TIMER_NUMBER_OF_TIMERS > 0
76 void OS_Timer_Tick(
void);
79static volatile uint16_t scheduler_interrupt_leader_1ms = 0;
80static volatile uint16_t scheduler_interrupt_follower_1ms = 0;
81volatile static uint16_t scheduler_1ms_timer = 0;
82volatile static uint16_t scheduler_10ms_timer = 0;
83volatile static uint16_t scheduler_100ms_timer = 0;
84volatile static uint16_t scheduler_1s_timer = 0;
91#if OS_USE_MCC_TIMER1 == 0
92static inline void OS_Scheduler_Init_Timer1(
void)
100 T1CONbits.TMWDIS = 0;
104 T1CONbits.TECS = 0b01;
107 T1CONbits.TCKPS = 0b01;
117 PR1 = (FCY / 1000 / 8);
118 T1CON = ((T1ON << 15) | (T1TCKPS << 4) | (T1TCS));
134void OS_Scheduler_Init(
void)
136#if OS_USE_MCC_TIMER1 == 0
137 OS_Scheduler_Init_Timer1();
140#if OS_USE_SYSTIME == 1
141 OS_SysTime_ResetTime();
143 scheduler_interrupt_leader_1ms = 0U;
144 scheduler_interrupt_follower_1ms = 0U;
152#if OS_USE_MCC_TIMER1 == 1
155void TMR1_CallBack(
void)
157void __attribute__((__interrupt__,no_auto_psv)) _T1Interrupt(
void)
160 scheduler_interrupt_leader_1ms++;
162#if OS_TIMER_NUMBER_OF_TIMERS > 0
165#if OS_USE_SYSTIME == 1
166 OS_SysTime_IncrementTime_1ms();
182void OS_Scheduler_RunOnce(
void)
184 if (scheduler_interrupt_follower_1ms != scheduler_interrupt_leader_1ms)
186 scheduler_interrupt_follower_1ms++;
188 scheduler_10ms_timer += 1U;
189 if (scheduler_10ms_timer >= 10U)
191 scheduler_10ms_timer = 0U;
193 scheduler_100ms_timer += 1U;
194 if (scheduler_100ms_timer >= 10U)
196 scheduler_100ms_timer = 0U;
198 scheduler_1s_timer += 1U;
199 if (scheduler_1s_timer >= 10U)
201 scheduler_1s_timer = 0U;
202 #if OS_FEATURE_WATCHDOG_ENABLED == 1
203 OS_Watchdog_KeepAlivePing();
222void OS_Scheduler_RunForever(
void)
225 scheduler_interrupt_leader_1ms = 0U;
226 scheduler_interrupt_follower_1ms = 0U;
234 OS_Scheduler_RunOnce();
void __attribute__((weak))
void Tasks_10ms(void)
Tasks_10ms gets called every 10ms, put your things in it that need to be called regularly.
void Tasks_1ms(void)
Tasks_1ms gets called every millisecond, put your things in it that need to be called regularly.
void Tasks_Realtime_1ms(void)
Tasks_Realtime_1ms gets called directly from the timer interrupt every millisecond.
void Tasks_100ms(void)
Tasks_100ms gets called every 100 ms, put your things in it that need to be called regularly.
void Tasks_Background(void)
Tasks_Background gets called all the time when no other of the above tasks are being called.
void Tasks_1s(void)
Tasks_1s gets called every second, put your things in it that need to be called regularly.