Main Page | Data Structures | File List | Data Fields | Globals
Short Term Loads Small Business Loans Merchant Cash Advances best business loans Working Capital Equipment Financingbusiness loans Long Term Loans SBA Loans Big Lines of Credit

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(" "), register unsigned char rotationMask asm("Ð"))
void PerformDelay (void)
unsigned char rotate (unsigned char t, register unsigned char n asm("Ò"))
void Scheduler (void)

Variables

t_TASK idleTask
char * idleTaskStack
unsigned char * indexToLowestSettedBit
unsigned short kernelStarted
unsigned short  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 109 of file opale_core.c.

References addTaskToTable(), t_TASK::ident, idleTask, t_TASK::nextSleeping, t_TASK::prevSleeping, readyTasks, and t_TASK::tickDelay.

Here is the call graph for this function:

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

Definition at line 129 of file opale_core.c.

References _X_.

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 136 of file opale_core.c.

References ContextSwitch(), currentTask, t_TASK::ident, indexToLowestSettedBit, indexToSettedBit, MASK_X, MASK_Y, readyTasks, rotate(), roundRobin, t_TASK_BLOCK::rowIndex, runningTasks, and t_TASK_BLOCK::tasksTable.

Here is the call graph for this function:


Variable Documentation

t_TASK idleTask
 

Task Control Block for the idle task. Definition at line 44 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 46 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 kernelStarted
 

Definition at line 41 of file opale_core.c.

Referenced by op_KernelInit().

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 49 of file opale_core.c.

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


Generated on Sun May 14 22:31:06 2006 for Opale by doxygen 1.3.8