Go to the documentation of this file.
23 #include <avr/interrupt.h>
24 #include <util/atomic.h>
40 static uint8_t intStates;
48 static uint8_t osIntStates;
74 static void OS_StartSysTimer()
76 #if defined(__AVR_ATmega32__) || defined(__AVR_ATmega128__)
77 TCCR0 = 1 << CS02 | 1 << CS00;
79 #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega2560__)
81 TCCR0B = 1 << CS02 | 1 << CS00;
84 #warning Unknown CPU defined. Setup of Timer0 overflow interrupt is required for sysTick and preemptive scheduling.
97 activeApplicationMode = mode;
104 #if defined(OS_CONFIG_HOOK_STARTUP) && OS_CONFIG_HOOK_STARTUP == true
115 #if defined(OS_CONFIG_HOOK_POST_TASK) && OS_CONFIG_HOOK_POST_TASK == true
125 asm volatile (
"ret");
134 #if defined(OS_CONFIG_HOOK_SHUTDOWN) && OS_CONFIG_HOOK_SHUTDOWN == true
147 #if defined(OS_CONFIG_STACK_MONITORING) && OS_CONFIG_STACK_MONITORING >= 1
156 #if OS_CONFIG_STACK_MONITORING >= 2
178 #if defined(OS_CONFIG_HOOK_PRE_TASK) && OS_CONFIG_HOOK_PRE_TASK == true
200 #if defined(OS_CONFIG_HOOK_POST_TASK) && OS_CONFIG_HOOK_POST_TASK == true
230 asm volatile (
"ret");
235 int16_t highestPrio = -1;
236 highestPrioTask = INVALID_TASK;
240 &&
TCB_Cfg[i]->curPrio >= highestPrio) {
265 bool enable = (intStates & 0b1);
266 intStates = (intStates >> 1);
277 intStates = (intStates << 1) | ((SREG >> SREG_I) & 0b1);
286 bool enable = (osIntStates & 0b1);
287 osIntStates = (osIntStates >> 1);
298 osIntStates = (osIntStates << 1) | ((SREG >> SREG_I) & 0b1);
307 return activeApplicationMode;
314 #if defined(OS_CONFIG_HOOK_PROTECTION) && OS_CONFIG_HOOK_PROTECTION == true
345 while (*resPtr != NULL) {
346 assert((*resPtr)->assigned ==
true);
349 (*resPtr)->assigned =
false;
360 while (osIntStates != 0) {
365 while (intStates != 0) {
375 asm volatile(
"reti");
uint8_t curPrio
Current priority.
enum tasks_e TaskType
Type for task reference.
StatusType Task_TerminateTask(void)
Terminate active task.
enum ProtectionReturnType_e ProtectionReturnType
Return type for protection hook.
@ PRO_TERMINATETASKISR
Terminate faulty task or ISR.
enum StatusType_e StatusType
Type for status.
struct resource_s *volatile isrResourceQueue
Resource queue for resources taken by Cat2 ISRs.
void restore_context(void)
Restore context of current task.
void __attribute__((naked))
Task switch.
uint8_t *volatile * ptrCurrentStack
Stack-Pointer saved in current task control block.
Schedule tables management.
Operating system control.
@ PRO_IGNORE
Ignore protection error.
void OS_ShutdownOSStackOverrun(void)
Call OS_ShutdownOS() with E_OS_STACKFAULT.
struct resource_s * resourceQueue
Current queue of allocated resources.
ProtectionReturnType ProtectionHook(StatusType fatalError)
ProtectionHook function.
void ScheduleTable_startup(void)
Startup function for schedule table management.
Assert macros and functions.
@ E_OS_PROTECTION_ARRIVAL
volatile TaskType currentTask
Task currently being executed.
void OS_Switch(void)
Switch to new task.
@ PREEMPTIVE
The task may be preempted by another task.
@ OSServiceId_ResumeOSInterrupts
#define OS_SET_ERROR_INFO1(serviceId, paramPtr1, size1)
Set error info with up to one parameter.
uint8_t *const stack
Pointer to stack base.
volatile struct task_s * TCB_Cfg[]
Current task control blocks.
void OS_SuspendOSInterrupts(void)
Suspend OS interrupts.
TaskStateType curState
Current state of the task.
void OS_ResumeOSInterrupts(void)
Resume OS interrupts.
@ RUNNING
The task is currently running.
#define OS_SET_ERROR_INFO0(serviceId)
Set error info with zero parameters.
void PreTaskHook(void)
PreTask hook function.
volatile uint8_t isCat2ISR
Priority of current Cat 2 ISR (zero if not in Cat 2 ISR)
volatile bool isISR
Is currently ISR context?
uint8_t * context
Current context/stack pointer.
@ READY
The task is ready to be scheduled.
#define assert(expression)
void Resource_GetInternalResource(void)
Get internal resource of the current task if one is assigned.
Data structure for OS resource.
@ OSServiceId_GetActiveApplicationMode
const uint8_t prio
Static priority of the task.
@ OSServiceId_ResumeAllInterrupts
const uint16_t stackSize
Size of stack in bytes.
void OS_ResumeAllInterrupts(void)
Resume all interrupts.
void OS_DisableAllInterrupts(void)
Disable all interrupts.
pTaskFxn ptrCurrentFxnAddr
Function pointer to current task function.
struct resource_s * next
Pointer to next resource in resource queue.
@ OSServiceId_SuspendOSInterrupts
void PostTaskHook(void)
PostTask hook function.
void OS_EnableAllInterrupts(void)
Enable all interrupts.
void OS_ShutdownOS(StatusType error)
Shutdown operating system.
void init_context(void)
Initialize context of current task.
void ShutdownHook(StatusType error)
enum OsTaskState_e TaskStateType
Task state.
const pTaskFxn taskFxn
Pointer to task function.
#define TASK_COUNT
Count of tasks defined.
void OS_ProtectionHookInternal(StatusType error)
Internal function for protection hook handling.
AppModeType OS_GetActiveApplicationMode(void)
Get currently active application mode.
@ PRO_SHUTDOWN
Shutdown system.
bool forceScheduling
Force the next rescheduling.
void Alarm_startup(void)
Startup function for alarm management.
void OS_StartOS(AppModeType mode)
Start operating system.
@ OSServiceId_SuspendAllInterrupts
void Task_startup(void)
Startup function for task management.
void save_context(void)
Save context of current task.
void OS_SuspendAllInterrupts(void)
Suspend all interrupts.
enum applicationMode_e AppModeType
Type for application mode.
volatile uint8_t needScheduling
Scheduling needed during timer interrupt.
@ PRE_READY
The task is ready but its stack is uninitialized.