Roomba Tank
CSC 460 Project 3
Macros | Functions | Variables
os.c File Reference
#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.

Macros

#define DEBUG
 

Functions

void a_main ()
 
void CSwitch ()
 
void Exit_Kernel ()
 
void Task_Terminate (void)
 
void Enter_Kernel ()
 
PID Kernel_Create_Task_At (volatile PD *p, voidfuncptr f, PRIORITY py, int arg)
 
MUTEX Kernel_Init_Mutex_At (volatile MTX *m)
 
EVENT Kernel_Init_Event_At (volatile EVT *e)
 
void OS_Init ()
 
void OS_Start ()
 
void OS_Abort ()
 
MUTEX Mutex_Init ()
 
void Mutex_Lock (MUTEX m)
 
void Mutex_Unlock (MUTEX m)
 
EVENT Event_Init ()
 
void Event_Wait (EVENT e)
 
void Event_Signal (EVENT e)
 
PID Task_Create (voidfuncptr f, PRIORITY py, int arg)
 
void Task_Next ()
 
void Task_Sleep (TICK t)
 
void Task_Suspend (PID p)
 
void Task_Resume (PID p)
 
int Task_GetArg (PID p)
 
void setup ()
 
 ISR (TIMER1_COMPA_vect)
 
 ISR (TIMER3_COMPA_vect)
 
void main ()
 

Variables

volatile unsigned char * KernelSp
 
volatile unsigned char * CurrentSp
 
volatile unsigned int tickOverflowCount = 0
 
volatile PDReadyQueue [MAXTHREAD]
 
volatile int RQCount = 0
 
volatile PDSleepQueue [MAXTHREAD]
 
volatile int SQCount = 0
 
volatile PDWaitingQueue [MAXTHREAD]
 
volatile int WQCount = 0
 

Macro Definition Documentation

#define DEBUG

Definition at line 8 of file os.c.

Function Documentation

void a_main ( )

Application level main function. Creates the required tasks and then terminates

Definition at line 317 of file base.c.

void CSwitch ( )

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.)

void Enter_Kernel ( )

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.

void Exit_Kernel ( )
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.

PID Kernel_Create_Task_At ( volatile PD p,
voidfuncptr  f,
PRIORITY  py,
int  arg 
)

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.

void main ( )

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.

void OS_Abort ( void  )

Just quits

Definition at line 667 of file os.c.

void OS_Init ( )

This function initializes the RTOS and must be called first

Definition at line 624 of file os.c.

void OS_Start ( )

This function starts the RTOS after creating a_main

Definition at line 654 of file os.c.

void setup ( )

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.

PID Task_Create ( voidfuncptr  f,
PRIORITY  py,
int  arg 
)

Application or kernel level task create to setup system call

Definition at line 747 of file os.c.

int Task_GetArg ( PID  p)

Application level task getarg to return intiial arg value

Definition at line 829 of file os.c.

void Task_Next ( void  )

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.

Variable Documentation

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.

volatile PD* ReadyQueue[MAXTHREAD]

The ReadyQueue for tasks

Definition at line 104 of file os.c.

volatile int RQCount = 0

Definition at line 105 of file os.c.

volatile PD* SleepQueue[MAXTHREAD]

The SleepQueue for tasks

Definition at line 108 of file os.c.

volatile int SQCount = 0

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.

volatile PD* WaitingQueue[MAXTHREAD]

The WaitingQueue for tasks

Definition at line 112 of file os.c.

volatile int WQCount = 0

Definition at line 113 of file os.c.