#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "os.h"
#include "queue.h"
Go to the source code of this file.
Definition at line 8 of file os.c.
Application level main function. Creates the required tasks and then terminates
Definition at line 317 of file base.c.
This internal kernel function is the context switching mechanism. It consists two halves: the top half is called "Exit_Kernel()", and the bottom half is called "Enter_Kernel()". When kernel calls this function, it starts the top half (i.e., exit). Right in the middle, "Cp" is activated; as a result, Cp is running and the kernel is suspended in the middle of this function. When Cp makes a system call, it enters the kernel via the Enter_Kernel() software interrupt into the middle of this function, where the kernel was suspended. After executing the bottom half, the context of Cp is saved and the context of the kernel is restore. Hence, when this function returns, kernel is active again, but Cp is not running any more. (See file "cswitch.S" for details.)
Contained in cswitch.S, context switches to the kernel
EVENT Event_Init |
( |
void |
| ) |
|
Application level event init to setup system call
Definition at line 711 of file os.c.
void Event_Signal |
( |
EVENT |
e | ) |
|
Application level event signal to setup system call
Definition at line 735 of file os.c.
void Event_Wait |
( |
EVENT |
e | ) |
|
Application level event wait to setup system call
Definition at line 723 of file os.c.
ISR |
( |
TIMER1_COMPA_vect |
| ) |
|
ISR for timer1
Definition at line 875 of file os.c.
ISR |
( |
TIMER3_COMPA_vect |
| ) |
|
ISR for timer3
Definition at line 899 of file os.c.
Sets up a task's stack with Task_Terminate() at the bottom, The return address of the function and dummy data to be popped off when the task first runs
Definition at line 120 of file os.c.
EVENT Kernel_Init_Event_At |
( |
volatile EVT * |
e | ) |
|
Initialize an event
Definition at line 410 of file os.c.
MUTEX Kernel_Init_Mutex_At |
( |
volatile MTX * |
m | ) |
|
Initialize a mutex
Definition at line 270 of file os.c.
This function boots the OS and creates the first task: a_main
Definition at line 906 of file os.c.
MUTEX Mutex_Init |
( |
void |
| ) |
|
Application level mutex init to setup system call
Definition at line 674 of file os.c.
void Mutex_Lock |
( |
MUTEX |
m | ) |
|
Application level mutex lock to setup system call
Definition at line 686 of file os.c.
void Mutex_Unlock |
( |
MUTEX |
m | ) |
|
Application level mutex unlock to setup system call
Definition at line 699 of file os.c.
Just quits
Definition at line 667 of file os.c.
This function initializes the RTOS and must be called first
Definition at line 624 of file os.c.
This function starts the RTOS after creating a_main
Definition at line 654 of file os.c.
Setup pins and timers
initialize Timer1 16 bit timer
Timer 1
Set TCCR1A register to 0
Set TCCR1B register to 0
Initialize counter to 0
Compare match register (TOP comparison value) [(16MHz/(100Hz*8)] - 1
Turns on CTC mode (TOP is now OCR1A)
Prescaler 256
Enable timer compare interrupt
Timer 3
Set TCCR0A register to 0
Set TCCR0B register to 0
Initialize counter to 0
Compare match register (TOP comparison value) [(16MHz/(100Hz*8)] - 1
Turns on CTC mode (TOP is now OCR1A)
Prescaler 1024
Definition at line 836 of file os.c.
Application or kernel level task create to setup system call
Definition at line 747 of file os.c.
Application level task getarg to return intiial arg value
Definition at line 829 of file os.c.
Application level task next to setup system call to give up CPU
Definition at line 768 of file os.c.
void Task_Resume |
( |
PID |
p | ) |
|
Application level task resume to setup system call
Definition at line 805 of file os.c.
void Task_Sleep |
( |
TICK |
t | ) |
|
Application level task sleep to setup system call
Definition at line 779 of file os.c.
void Task_Suspend |
( |
PID |
p | ) |
|
Application level task suspend to setup system call
Definition at line 793 of file os.c.
void Task_Terminate |
( |
void |
| ) |
|
Prototypes
Application level task terminate to setup system call
Definition at line 817 of file os.c.
volatile unsigned char* CurrentSp |
This is a "shadow" copy of the stack pointer of "Cp", the currently running task. During context switching, we need to save and restore it into the appropriate process descriptor.
Definition at line 83 of file os.c.
volatile unsigned char* KernelSp |
Since this is a "full-served" model, the kernel is executing using its own stack. We can allocate a new workspace for this kernel stack, or we can use the stack of the "main()" function, i.e., the initial C runtime stack. (Note: This and the following stack pointers are used primarily by the context switching code, i.e., CSwitch(), which is written in assembly language.)
Definition at line 76 of file os.c.
The ReadyQueue for tasks
Definition at line 104 of file os.c.
Definition at line 105 of file os.c.
The SleepQueue for tasks
Definition at line 108 of file os.c.
Definition at line 109 of file os.c.
volatile unsigned int tickOverflowCount = 0 |
Global tick overflow count
Definition at line 101 of file os.c.
The WaitingQueue for tasks
Definition at line 112 of file os.c.
Definition at line 113 of file os.c.