MultitaskingKernel


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 ECBECBPool
ECBNewSemaphore (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 ECBAllocECB (void)
 Allocate memory for a new semaphore.
static void FreeECB (ECB *e)
 Free memory that was used by a semaphore.
TCBNextTask
int OsRunning
HEAP_BLOCKpStackHeap
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

ECBMasterList
ECBTimeoutList
PQ ActiveTasks
TCBCurrentTask
TCBNextTask
ECBLCDBlocker
int OsRunning
volatile int TStamp
volatile int InterruptCount
volatile int Blocking

Define Documentation

#define EVENT_DELETED   -4

Event was deleted by task

Definition at line 29 of file task.h.

Referenced by DeleteSemaphore().

#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

Event timed out

Definition at line 28 of file task.h.

Referenced by TimerTicker().

#define HI (  )     ((x >> 8) & 0x0ff)

High 8 bits of word

Definition at line 21 of file task.h.

Referenced by CreateTask().

#define LO (  )     (x & 0x0ff)

Low 8 bits of word

Definition at line 20 of file task.h.

Referenced by CreateTask().

 
#define RESTORE_CONTEXT (  ) 

Definition at line 376 of file task.h.

Referenced by DoSwap(), IrqSwap(), and StartOS().

 
#define RESTORE_CONTEXT_OLD (  ) 

Definition at line 325 of file task.h.

 
#define RESTORE_IRQ (  ) 

 
#define SAVE_CONTEXT (  ) 

Definition at line 231 of file task.h.

Referenced by DoSwap().

 
#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

Semaphore in Timeout Mode

Definition at line 81 of file task.h.

Referenced by TimeDelay().

#define STACK_SIZE   96

Default Stack Size

Definition at line 23 of file task.h.

#define THREAD ( func,
arg   ) 

Value:

void func(void *arg) __attribute__((noreturn)); \
void func(void *arg)
Macro used to define a thread function

Definition at line 87 of file task.h.


Typedef Documentation

typedef struct ecb ECB

Semaphore Object Event Control Block

typedef struct tcb TCB

Definition at line 51 of file task.h.


Function Documentation

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

Returns:
returns a pointer to a block of memory for use as a semaphore, NULL on fail

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]

Definition at line 36 of file createtask.c.

References HeapAlloc().

Referenced by CreateTask().

void CreateSemaphore ( ECB e,
int  InitCount,
int  Mode,
char *  n 
)

Initialize a new semaphore.

This function is used to initialize a semaphore object.

Parameters:
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.

Parameters:
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.

Parameters:
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   ) 

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  ) 

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

Parameters:
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.

Parameters:
InitCount Initial count for semaphore event count
Mode 0=No Timeout, 1 = Semaphore times out
name Name given to semaphore
Returns:
Pointer to semaphore on success, NULL on fail

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 
)

int PostSemaphore ( ECB e,
int  Value 
)

int PostSemaphoreIrq ( ECB e,
int  Value 
)

int PostSemaphoreWithData ( ECB e,
int  Value,
unsigned  data 
)

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.

Returns:
Number of bytes left in Stack Heap

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  ) 

void TimerTicker ( void   ) 

void vPortStartFirstTask ( void   ) 

void vPortYieldProcessor ( void   ) 

void Yeild ( void   ) 


Variable Documentation

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

ECB* ECBPool [static]

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


Generated on Sun Aug 31 13:31:35 2008 for FrankenRTOS by  doxygen 1.5.6