Main Page | File List | Globals

opale_core.c File Reference

#include "opale_internal.h"

Include dependency graph for opale_core.c:

Include dependency graph

Go to the source code of this file.

Functions

void op_KernelInit (register t_op_BUFFER *buffer asm("%a0"), register unsigned char rotationMask asm("%d0"))
void PerformDelay (void)
unsigned char rotate (unsigned char t, register unsigned char n asm("%d2"))
void Scheduler (void)

Variables

unsigned char * indexToLowestSettedBit
unsigned short numberOfNestedISRs
unsigned short numberOfNestedShedulerHalts
t_TASK idleTask
char * idleTaskStack
t_TASK ** runningTasks
t_TASK_BLOCK * roundRobin
t_TASK_BLOCK * readyTasks


Function Documentation

void op_KernelInit register t_op_BUFFER *buffer   asm("%a0"),
register unsigned char rotationMask   asm("%d0")
 

Inits the kernel. It is the first function you have to call before using any other function of Opale.

Parameters:
(a0.l) buffer Pointer to a buffer of sizeof(t_op_BUFFER) bytes. Can be allocated in any writable memory (Heap or stack). When NUM_TASKS is big, be carefull to stack overflow.
(d0.b) rotationEnableMask MAsk enabling priority rotation for groups while scheduling. There are _Y_ groups of _X_ tasks each, when the correponding bit of rotationEnableMask is setted, all the tasks of the group have the same priority, and are run sequencially.
Definition at line 63 of file opale_core.c.

References idleTask, idleTaskStack, indexToLowestSettedBit, numberOfNestedISRs, numberOfNestedShedulerHalts, op_TaskStart(), readyTasks, roundRobin, and runningTasks.

Here is the call graph for this function:

void PerformDelay void   ) 
 

Advance each sleeping task's counter and wake any task whose counter reaches zero.
This function is called by the kernel tick interruption subroutine. Definition at line 108 of file opale_core.c.

References addTaskToTable(), idleTask, and readyTasks.

Here is the call graph for this function:

unsigned char rotate unsigned char  t,
register unsigned char n   asm("%d2")
[static]
 

Definition at line 128 of file opale_core.c.

Referenced by Scheduler().

void Scheduler void   ) 
 

The scheduler is used to find the task that is to be run

Find the task with the highest priority ready to run, and make switch the context to run it if it isn't already running.

Let's see the tools we'll use to do the job ...

indexToLowestSettedBitIndex :

                        static const unsigned char indexToLowestUnsettedBitIndex [ 16 ] = {     0, 0, 1, 0,
                                                                                                                                                                                                                                                                                                        2, 0, 1, 0,
                                                                                                                                                                                                                                                                                                        3, 0, 1, 0,
2, 0, 1, 0 }; This table converts the number you give as an index to the correspondinb less significant setted bit it contains.
It works for a 4-bits index, since we have 16 tasks max.
The first 8 values (index 0-7) are never used since there's always alt least the idle task runnig.

ex :
0b00001000 -> 3
0b00001101 -> 1
0b00001111 -> 0
etc...

readyTasksTable :

                        <-------- X -----------+
                          7 6 5 4   3 2 1 0    |
                        --------------------+  |                        It is a table of 4 bytes, but we use ontly the lowest 4 bits of those.
                        | . . . . | 3 2 1 0 |  |        0               I draw on here the representation of the array with the bits correspounding
                        | . . . . | 7 6 5 4 |  Y        1               to the tasks' priorities. When a bit is set, the task is ready and pending.
                        | . . . . | B A 9 8 |  |        2               The 0 is the highest priority.
                        | . . . . | F E D C |  V        3               The table is never empty since the 15th task (idle) is always runnig !

readyRowIndex :

| . . . . | 3 2 1 0 |

The bit n°x of readyTasksRowIndex is set when the row n°x of readyTasksTable is not 0.
That means at least one task is pending in that row.
That index cannot be 0 since there's always at least one task running (the idle task).

priority :

<-Y-> <-X->
| . . . . | 3 2 | 1 0 |

A task priority is unique, and goes from 0 (highest) to 15 (lowest)
Writen in binary, it can be used like that :

bits 0-1 are the X index in the ready tasks table.
bits 2-3 are the Y index.

It is just because of how you write it in binary, and because the ready tasks table is 4*4.
Priorities are also used as idents for the tasks.

Now it becomes easy to get the highest priority task :

indexToLowestSettedBitIndex[ readyTasksRowIndex ] gives y (the lowest index of a row containing pending tasks)
indexToLowestSettedBitIndex[ readyTasksTable[ y ] ] gives X (index of the lowest setted bit of the lowest row containing setted bit, taht is: pending tasks)

Here we have the priority / ident of the task:

ident = ( y << 2 ) + x
Definition at line 135 of file opale_core.c.

References indexToLowestSettedBit, readyTasks, rotate(), roundRobin, and runningTasks.

Here is the call graph for this function:


Variable Documentation

t_TASK idleTask
 

Task Control Block for the idle task. Definition at line 43 of file opale_core.c.

Referenced by op_KernelInit(), op_TaskWaitForTicks(), and PerformDelay().

char* idleTaskStack
 

Pointer to the idle task's stack. Its depths is IDLE_TASK_STACK_SIZE bytes. Definition at line 45 of file opale_core.c.

Referenced by op_KernelInit().

unsigned char* indexToLowestSettedBit
 

indexToLowestSettedBit is a pointer to a table used to get the index of the lowest weighted setted bit of a number. Given the number, the value at indexToLowestSettedBit[ number ] is the index of the wanted bit.
The size of the table is calculated in compilation time, since it doesn't have to be more than max( 2^X, 2^Y ) (cf TO_LOWEST_SETTED_BIT_TABLE_SIZE).
The memory for the table is taken from the t_op_BUFFER given as an argument of op_KernelInit, and the table itself is initialized by taht function.

Here is what would the table looks like fo 64 tasks:

                
indexToLowestSettedBit[ TO_LOWEST_SETTED_BIT_TABLE_SIZE ] =
{
        0, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        5, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        6, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        5, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        7, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        5, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        6, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        5, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0,
        4, 0, 1, 0,     2, 0, 1, 0,     3, 0, 1, 0,     2, 0, 1, 0
};
Definition at line 37 of file opale_core.c.

Referenced by MakeTaskReady(), op_KernelInit(), and Scheduler().

unsigned short numberOfNestedISRs
 

Definition at line 39 of file opale_core.c.

Referenced by op_KernelInit().

unsigned short numberOfNestedShedulerHalts
 

Definition at line 40 of file opale_core.c.

Referenced by op_KernelInit().

t_TASK_BLOCK* readyTasks
 

pointer to the task block used for general purpose scheduling. Definition at line 53 of file opale_core.c.

Referenced by MakeTaskReady(), op_KernelInit(), op_TaskStart(), op_TaskStop(), op_TaskWaitForTicks(), PerformDelay(), Scheduler(), and WaitForEvent().

t_TASK_BLOCK* roundRobin
 

Pointer to the task block used for round-robin scheduling. Definition at line 51 of file opale_core.c.

Referenced by op_KernelInit(), and Scheduler().

t_TASK** runningTasks
 

Pointer to the array of running tasks. Definition at line 48 of file opale_core.c.

Referenced by op_KernelInit(), op_TaskStart(), op_TaskStop(), and Scheduler().


Generated on Sat Jul 30 16:25:53 2005 for Opale by doxygen 1.3.8