42#include "../project_settings.h"
43#if OS_FEATURE_WATCHDOG_ENABLED == 1
44#include "os_watchdog.h"
47#if OS_USE_SCHEDULER_1ms == 1
49#ifndef OS_TIMER_NUMBER_OF_TIMERS
50#warning OS_TIMER_NUMBER_OF_TIMERS needs to be defined in main/project_setting.h
53#warning OS_USE_SYSTIME needs to be defined in main/project_setting.h
55#include "os_sys_time.h"
57#include "os_scheduler.h"
90#if OS_TIMER_NUMBER_OF_TIMERS > 0
91 void OS_Timer_Tick(
void);
94static volatile uint16_t scheduler_interrupt_leader_1ms = 0;
95static volatile uint16_t scheduler_interrupt_follower_1ms = 0;
96volatile static uint16_t scheduler_1ms_timer = 0;
97volatile static uint16_t scheduler_10ms_timer = 0;
98volatile static uint16_t scheduler_100ms_timer = 0;
99volatile static uint16_t scheduler_1s_timer = 0;
106#if OS_USE_MCC_TIMER1 == 0
107static inline void OS_Scheduler_Init_Timer1(
void)
115 T1CONbits.TMWDIS = 0;
119 T1CONbits.TECS = 0b01;
122 T1CONbits.TCKPS = 0b01;
132 PR1 = (FCY / 1000 / 8);
133 T1CON = ((T1ON << 15) | (T1TCKPS << 4) | (T1TCS));
149void OS_Scheduler_Init(
void)
151#if OS_USE_MCC_TIMER1 == 0
152 OS_Scheduler_Init_Timer1();
155#if OS_USE_SYSTIME == 1
156 OS_SysTime_ResetTime();
158 scheduler_interrupt_leader_1ms = 0U;
159 scheduler_interrupt_follower_1ms = 0U;
167#if OS_USE_MCC_TIMER1 == 1
170void TMR1_CallBack(
void)
172void __attribute__((__interrupt__,no_auto_psv)) _T1Interrupt(
void)
175 scheduler_interrupt_leader_1ms++;
177#if OS_TIMER_NUMBER_OF_TIMERS > 0
180#if OS_USE_SYSTIME == 1
181 OS_SysTime_IncrementTime_1ms();
183 Tasks_Realtime_1ms();
197void OS_Scheduler_RunOnce(
void)
199 if (scheduler_interrupt_follower_1ms != scheduler_interrupt_leader_1ms)
201 scheduler_interrupt_follower_1ms++;
203 scheduler_10ms_timer += 1U;
204 if (scheduler_10ms_timer >= 10U)
206 scheduler_10ms_timer = 0U;
208 scheduler_100ms_timer += 1U;
209 if (scheduler_100ms_timer >= 10U)
211 scheduler_100ms_timer = 0U;
213 scheduler_1s_timer += 1U;
214 if (scheduler_1s_timer >= 10U)
216 scheduler_1s_timer = 0U;
217 #if OS_FEATURE_WATCHDOG_ENABLED == 1
218 OS_Watchdog_KeepAlivePing();
237void OS_Scheduler_RunForever(
void)
240 scheduler_interrupt_leader_1ms = 0U;
241 scheduler_interrupt_follower_1ms = 0U;
249 OS_Scheduler_RunOnce();
void __attribute__((__interrupt__, auto_psv))
Executes the power converter control loop.