Files | |
file | ExitInterrupt.c |
file | ByteQueue.c |
file | createsemaphore.c |
file | createtask.c |
file | DoSwap.c |
file | ExitInterrupt.c |
file | HeapFreeSpace.c |
file | heapmanager.c |
Data Structures | |
struct | tcb |
Definition of a Task Control Block (TCB). More... | |
struct | ecb |
static ECB * | ECBPool |
ECB * | NewSemaphore (int InitCount, int Mode, char *name) |
Create a new semaphore. | |
void | CreateSemaphore (ECB *e, int InitCount, int Mode, char *n) |
Initialize a new semaphore. | |
void | DeleteSemaphore (ECB *e) |
Delete a semaphore. | |
static ECB * | AllocECB (void) |
Allocate memory for a new semaphore. | |
static void | FreeECB (ECB *e) |
Free memory that was used by a semaphore. | |
TCB * | NextTask |
int | OsRunning |
HEAP_BLOCK * | pStackHeap |
PQ | ActiveTasks |
static void * | AllocStack (size_t len) |
volatile int | Blocking |
void | ExitInterrupt (void) |
This function is called at the end of an interrupt. | |
void | DoSwap (void) |
Do a Context Switch. | |
Defines | |
#define | LO(x) (x & 0x0ff) |
#define | HI(x) ((x >> 8) & 0x0ff) |
#define | STACK_SIZE 96 |
#define | EVENT_NOERROR 0 |
#define | EVENT_NOTASKS -1 |
#define | EVENT_OVERFLOW -2 |
#define | EVENT_TIMEOUT -3 |
#define | EVENT_DELETED -4 |
#define | SEMAPHORE_MODE_BLOCKING 0 |
#define | SEMAPHORE_MODE_TIMEOUT 1 |
#define | THREAD(func, arg) |
#define | SAVE_IRQ() |
Save context in Interrupt Routine. | |
#define | RESTORE_IRQ() |
#define | SAVE_CONTEXT() |
#define | RESTORE_CONTEXT_OLD() |
#define | RESTORE_CONTEXT() |
Typedefs | |
typedef struct tcb | TCB |
typedef struct ecb | ECB |
Functions | |
void | CreateTask (TCB *t, void(*task)(void *), int stacksize, int priority, char *name, void *arg) |
Create a task. | |
void | IrqSwap (void) |
void | OSInit (void) |
void | Yeild (void) |
int | PendSemaphore (ECB *e, int Timeout) |
int | PostSemaphore (ECB *e, int Value) |
int | PostSemaphoreWithData (ECB *e, int Value, unsigned data) |
int | PostSemaphoreIrq (ECB *e, int Value) |
void | TimerTicker (void) |
void | vPortYieldProcessor (void) |
void | vPortStartFirstTask (void) |
int | TimeDelay (int mSec) |
void | Enable (char sr) |
char | Disable (void) |
void | StartOS (void) |
unsigned | MeasureStackUsage (char *s, unsigned max) |
unsigned | StackHeapAvailiable (void) |
Get the amount of memory available for Stacks. | |
void | RegisterTickerPost (ECB *pS) |
Variables | |
ECB * | MasterList |
ECB * | TimeoutList |
PQ | ActiveTasks |
TCB * | CurrentTask |
TCB * | NextTask |
ECB * | LCDBlocker |
int | OsRunning |
volatile int | TStamp |
volatile int | InterruptCount |
volatile int | Blocking |
#define EVENT_DELETED -4 |
#define EVENT_NOERROR 0 |
Event Succesful
Definition at line 25 of file task.h.
Referenced by BQget(), BQPut(), PendSemaphore(), PostSemaphore(), PostSemaphoreIrq(), and PostSemaphoreWithData().
#define EVENT_NOTASKS -1 |
No Tasks in Priority Queue
Definition at line 26 of file task.h.
Referenced by BQget(), and PendSemaphore().
#define EVENT_OVERFLOW -2 |
Event count overflowed
Definition at line 27 of file task.h.
Referenced by BQPut(), PostSemaphore(), PostSemaphoreIrq(), and PostSemaphoreWithData().
#define EVENT_TIMEOUT -3 |
#define HI | ( | x | ) | ((x >> 8) & 0x0ff) |
#define LO | ( | x | ) | (x & 0x0ff) |
#define RESTORE_CONTEXT | ( | ) |
#define RESTORE_IRQ | ( | ) |
Definition at line 190 of file task.h.
Referenced by INT5_vect(), INT6_vect(), INT7_vect(), USART0_RX_vect(), USART0_UDRE_vect(), USART1_RX_vect(), and USART1_UDRE_vect().
#define SAVE_IRQ | ( | ) |
Save context in Interrupt Routine.
this macro is used to save processor context withing an interrupt routine
Definition at line 151 of file task.h.
Referenced by INT5_vect(), INT6_vect(), INT7_vect(), USART0_RX_vect(), USART0_UDRE_vect(), USART1_RX_vect(), and USART1_UDRE_vect().
#define SEMAPHORE_MODE_BLOCKING 0 |
Semaphore in Blocking Mode
Definition at line 80 of file task.h.
Referenced by CioInit(), HeapInit(), InitMessageQueueManager(), InitPort(), InitTimerServices(), InitVGA(), InitXPort(), InitXspi(), and MqInit().
#define SEMAPHORE_MODE_TIMEOUT 1 |
#define THREAD | ( | func, | |||
arg | ) |
Value:
void func(void *arg) __attribute__((noreturn)); \ void func(void *arg)
static ECB * AllocECB | ( | void | ) | [static] |
Allocate memory for a new semaphore.
This function first will check a pool of semaphore objects and if there are any objects there, pick the first one it finds and reuse that one.
Otherwise, use malloc to get a new block of memory
Definition at line 45 of file createsemaphore.c.
References Disable(), Enable(), malloc, and ecb::Tnext.
Referenced by NewSemaphore().
static void* AllocStack | ( | size_t | len | ) | [static] |
void CreateSemaphore | ( | ECB * | e, | |
int | InitCount, | |||
int | Mode, | |||
char * | n | |||
) |
Initialize a new semaphore.
This function is used to initialize a semaphore object.
e | pointer to semaphore to initialize | |
InitCount | Initial count for semaphore event count | |
Mode | 0=No Timeout, 1 = Semaphore times out | |
n | Name given to semaphore |
Definition at line 144 of file createsemaphore.c.
References Disable(), Enable(), ecb::EventCount, ecb::name, ecb::SemaphoreMode, strcpy(), ecb::task_h, ecb::task_t, ecb::Tnext, and ecb::Tprev.
Referenced by HeapInit(), InitVGA(), and NewSemaphore().
void CreateTask | ( | TCB * | t, | |
void(*)(void *) | task, | |||
int | stacksize, | |||
int | priority, | |||
char * | name, | |||
void * | arg | |||
) |
Create a task.
This funciton creates a task control block for a task function.
The user has the option of supplying a pointer to a block of memory that contains extra parameters for the task, or that pointer can be used as a value as well.
t | pointer to the task control block | |
task | pointer to function that will be the task | |
stacksize | size of stack in number of longs | |
priority | task priority | |
name | tag to identify task control block for debug purposes | |
arg | argument to be passed to function...it chan either be a value, or a pointer to some data |
Definition at line 79 of file createtask.c.
References AllocStack(), Disable(), Enable(), HI, tcb::list, LO, tcb::name, tcb::next, tcb::priority, tcb::stack, tcb::stacksize, tcb::stacktop, tcb::TcbSwaps, and tcb::TimeStamp.
Referenced by InitTimerServices(), and mmcInit().
void DeleteSemaphore | ( | ECB * | e | ) |
Delete a semaphore.
This function is used to delete a semaphore.
This is done by first notifying any thread waiting on that semaphore that it has been deleted.
e | pointer to semaphore to delete |
Definition at line 200 of file createsemaphore.c.
References ActiveTasks, Disable(), Enable(), EVENT_DELETED, FreeECB(), Insert(), tcb::next, tcb::status, and ecb::task_h.
Referenced by TimeDelay().
char Disable | ( | void | ) |
Referenced by AllocECB(), BQget(), BQPut(), CioAddHandler(), CreateSemaphore(), CreateTask(), DeleteSemaphore(), FreeECB(), KillTimer(), MqGet(), MqPut(), PendSemaphore(), PostSemaphore(), PostSemaphoreWithData(), RegisterTickerPost(), RGetC(), RPutC(), StartTimer(), THREAD(), TimeDelay(), and Yeild().
void DoSwap | ( | void | ) |
Do a Context Switch.
This function does a context switch at the 'task' level.
It should be noted, that before you call this function, NextTask needs to be set to point to the Task Control Block (TCB) of the thread that is going to run next.
Definition at line 33 of file DoSwap.c.
References CurrentTask, NextTask, RESTORE_CONTEXT, and SAVE_CONTEXT.
Referenced by BQget(), PendSemaphore(), and Yeild().
void Enable | ( | char | sr | ) |
Referenced by AllocECB(), BQget(), BQPut(), CioAddHandler(), CreateSemaphore(), CreateTask(), DeleteSemaphore(), FreeECB(), KillTimer(), MqGet(), MqPut(), PendSemaphore(), PostSemaphore(), PostSemaphoreWithData(), RegisterTickerPost(), RGetC(), RPutC(), StartTimer(), THREAD(), TimeDelay(), and Yeild().
void ExitInterrupt | ( | void | ) |
This function is called at the end of an interrupt.
This function keeps track of the nesting level of interrupts If nesting level is == 0, then do a context swap to the highest priority task
WARNING! Don't mess with this function, you will be sorry Adding any local variables or passed parameters Messes with the stack. IrqSwap alters the stack and if it is different from what it expects, it will mess up the stack.
Hey, you don't even need to add any local variables, just add a Little bit more code and it will mess things up. Always check the listing file to see how much might get pushed onto the stack
ExitInterrupt will alocate at least 4 bytes on the stack probably for sr, depending on how it does this. Currently ExitInterrupt uses 4 bytes on the stack to save various registers that it doesn't really have to
Currently IrqSwap() needs to remove 6 bytes from stack for the ATmega2561 or 4 bytes for the ATmega128 (using -O1,-O2,-O3 or -Os
Definition at line 64 of file ExitInterrupt.c.
References ActiveTasks, Blocking, CurrentTask, InterruptCount, IrqSwap(), NextTask, Replace(), tcb::TimeStamp, and TStamp.
Referenced by INT5_vect(), INT6_vect(), INT7_vect(), USART0_RX_vect(), USART0_UDRE_vect(), USART1_RX_vect(), and USART1_UDRE_vect().
static void FreeECB | ( | ECB * | e | ) | [static] |
Free memory that was used by a semaphore.
This function will return the block of memory used by a semaphore back to a pool of semaphore objects
e | pointer to the semaphore object to free |
Definition at line 83 of file createsemaphore.c.
References Disable(), Enable(), ecb::SemaphoreMode, ecb::Tnext, and ecb::Tprev.
Referenced by DeleteSemaphore().
void IrqSwap | ( | void | ) |
Definition at line 26 of file IrqSwap.c.
References CurrentTask, NextTask, and RESTORE_CONTEXT.
Referenced by ExitInterrupt().
unsigned MeasureStackUsage | ( | char * | s, | |
unsigned | max | |||
) |
Definition at line 18 of file MeasureStackUsage.c.
ECB * NewSemaphore | ( | int | InitCount, | |
int | Mode, | |||
char * | name | |||
) |
Create a new semaphore.
This function creates a new semaphore, by first allocating memory and then initializing the semaphore.
InitCount | Initial count for semaphore event count | |
Mode | 0=No Timeout, 1 = Semaphore times out | |
name | Name given to semaphore |
Definition at line 122 of file createsemaphore.c.
References AllocECB(), and CreateSemaphore().
Referenced by CioInit(), InitMessageQueueManager(), InitPort(), InitTimerServices(), InitXPort(), InitXspi(), MqInit(), and TimeDelay().
void OSInit | ( | void | ) |
Definition at line 45 of file OSinit.c.
References ActiveTasks, HeapInit(), InitPQ(), and PriorityCompare().
int PendSemaphore | ( | ECB * | e, | |
int | Timeout | |||
) |
Definition at line 37 of file pendsemaphore.c.
References ActiveTasks, CurrentTask, Delete(), Disable(), DoSwap(), Enable(), EVENT_NOERROR, EVENT_NOTASKS, ecb::EventCount, tcb::next, NextTask, ecb::SemaphoreMode, tcb::status, ecb::task_h, ecb::task_t, tcb::timeout, tcb::TimeStamp, and TStamp.
Referenced by AllocIOCB(), FreeIOCB(), HeapAlloc(), HeapFree(), MqGet(), MqInit(), RGetC(), RWrite(), THREAD(), TimeDelay(), WaitXspiDone(), XspiTransfer(), and XspiTransferByte().
int PostSemaphore | ( | ECB * | e, | |
int | Value | |||
) |
Definition at line 41 of file postsemaphore.c.
References ActiveTasks, Disable(), Enable(), EVENT_NOERROR, EVENT_OVERFLOW, ecb::EventCount, Insert(), tcb::next, tcb::status, ecb::task_h, and Yeild().
Referenced by AllocIOCB(), FreeIOCB(), HeapAlloc(), HeapFree(), INT7_vect(), MqInit(), MqPut(), RWrite(), RxIsr(), TimerTicker(), XspiTransfer(), and XspiTransferByte().
int PostSemaphoreIrq | ( | ECB * | e, | |
int | Value | |||
) |
Definition at line 81 of file postsemaphore.c.
References ActiveTasks, EVENT_NOERROR, EVENT_OVERFLOW, ecb::EventCount, Insert(), tcb::next, tcb::status, and ecb::task_h.
Referenced by INT5_vect().
int PostSemaphoreWithData | ( | ECB * | e, | |
int | Value, | |||
unsigned | data | |||
) |
Definition at line 111 of file postsemaphore.c.
References ActiveTasks, Disable(), Enable(), EVENT_NOERROR, EVENT_OVERFLOW, ecb::EventCount, Insert(), tcb::misc, tcb::next, tcb::status, ecb::task_h, and Yeild().
void RegisterTickerPost | ( | ECB * | pS | ) |
Definition at line 72 of file timerticker.c.
References Disable(), Enable(), and ecb::Tnext.
Referenced by InitTimerServices().
unsigned StackHeapAvailiable | ( | void | ) |
Get the amount of memory available for Stacks.
Definition at line 48 of file createtask.c.
References HeapFreeSpace().
void StartOS | ( | void | ) |
Definition at line 22 of file StartOS.c.
References ActiveTasks, CurrentTask, Delete(), NextTask, and RESTORE_CONTEXT.
int TimeDelay | ( | int | mSec | ) |
Definition at line 20 of file timedelay.c.
References DeleteSemaphore(), Disable(), Enable(), free, itoa(), malloc, NewSemaphore(), PendSemaphore(), and SEMAPHORE_MODE_TIMEOUT.
Referenced by mmcReset().
void TimerTicker | ( | void | ) |
Definition at line 36 of file timerticker.c.
References EVENT_TIMEOUT, ecb::EventCount, Insert(), tcb::next, PostSemaphore(), tcb::status, ecb::task_h, tcb::timeout, ecb::Tnext, and TStamp.
void vPortStartFirstTask | ( | void | ) |
void vPortYieldProcessor | ( | void | ) |
void Yeild | ( | void | ) |
Definition at line 26 of file yeild.c.
References ActiveTasks, CurrentTask, Disable(), DoSwap(), Enable(), InterruptCount, NextTask, Replace(), tcb::TimeStamp, and TStamp.
Referenced by BQPut(), PostSemaphore(), and PostSemaphoreWithData().
Priority Queue or waiting TASKs
Definition at line 30 of file createtask.c.
Referenced by BQget(), BQPut(), DeleteSemaphore(), ExitInterrupt(), InitTimerServices(), mmcInit(), OSInit(), PendSemaphore(), PostSemaphore(), PostSemaphoreIrq(), PostSemaphoreWithData(), StartOS(), and Yeild().
Priority Queue or waiting TASKs
Definition at line 30 of file createtask.c.
Referenced by BQget(), BQPut(), DeleteSemaphore(), ExitInterrupt(), InitTimerServices(), mmcInit(), OSInit(), PendSemaphore(), PostSemaphore(), PostSemaphoreIrq(), PostSemaphoreWithData(), StartOS(), and Yeild().
volatile int Blocking |
Keeps track of Blocking depth
This variable is incremented in code when task switching needs to be inhibited, and decremented when task switching is desired.
I have not found a lot of use for this feature, and will probably just get rid of it someday.
Definition at line 26 of file ExitInterrupt.c.
Referenced by ExitInterrupt().
volatile int Blocking |
Keeps track of Blocking depth
This variable is incremented in code when task switching needs to be inhibited, and decremented when task switching is desired.
I have not found a lot of use for this feature, and will probably just get rid of it someday.
Definition at line 26 of file ExitInterrupt.c.
Referenced by ExitInterrupt().
Current Running Task
Definition at line 26 of file createtask.c.
Referenced by BQget(), DoSwap(), ExitInterrupt(), IrqSwap(), PendSemaphore(), StartOS(), and Yeild().
List of deleted semaphores to re-allocate
Definition at line 30 of file createsemaphore.c.
volatile int InterruptCount |
Keeps track of interrupt call depth
Definition at line 25 of file ExitInterrupt.c.
Referenced by ExitInterrupt(), INT5_vect(), INT6_vect(), INT7_vect(), USART0_RX_vect(), USART0_UDRE_vect(), USART1_RX_vect(), USART1_UDRE_vect(), and Yeild().
Task that will run next
Definition at line 27 of file createtask.c.
Referenced by BQget(), DoSwap(), ExitInterrupt(), IrqSwap(), PendSemaphore(), StartOS(), and Yeild().
Task that will run next
Definition at line 27 of file createtask.c.
Referenced by BQget(), DoSwap(), ExitInterrupt(), IrqSwap(), PendSemaphore(), StartOS(), and Yeild().
int OsRunning |
Flag to indicate OS is running
Definition at line 28 of file createtask.c.
int OsRunning |
Flag to indicate OS is running
Definition at line 28 of file createtask.c.
place to allocate stacks from
Definition at line 29 of file createtask.c.
List of semaphores to check for timeouts
Definition at line 29 of file createsemaphore.c.
volatile int TStamp |
Definition at line 19 of file timerticker.c.
Referenced by BQget(), ExitInterrupt(), PendSemaphore(), TimerTicker(), and Yeild().