00001
00002
00003
00004
#include "opale_internal.h"
00005
00037 unsigned char*
indexToLowestSettedBit;
00038
00039 unsigned short numberOfNestedISRs;
00040 unsigned short numberOfNestedShedulerHalts;
00041 unsigned short kernelStarted;
00042
00044 t_TASK idleTask;
00046 char*
idleTaskStack;
00047
00049 t_TASK**
runningTasks;
00051 t_TASK_BLOCK*
roundRobin;
00053 t_TASK_BLOCK*
readyTasks;
00054
00063 void op_KernelInit(
register t_op_BUFFER* buffer
asm(
"%a0"),
register unsigned char rotationMask
asm(
"%d0") )
00064 {
00065
00066
short i,j;
00067
00068
indexToLowestSettedBit = buffer->indexToLowestSettedBit;
00069
readyTasks = &buffer->readyTasks;
00070
roundRobin = &buffer->roundRobin;
00071
idleTaskStack = buffer->idleTaskStack;
00072
runningTasks = buffer->runningTasks;
00073
00074
for(i=1; i< TO_LOWEST_SETTED_BIT_TABLE_SIZE; indexToLowestSettedBit[i++]=j) for(j=0; !((i>>j)&1); j++);
00075
00076
00077
numberOfNestedISRs = 0;
00078
00079
00080
numberOfNestedShedulerHalts = 1;
00081
kernelStarted = 0;
00082
00083
00084
readyTasks->
rowIndex = 0;
00085
roundRobin->
rowIndex = rotationMask;
00086
00087
00088
00089
for( i = 0; i<
_Y_; )
00090 {
00091
readyTasks->
tasksTable[ i ] = 0;
00092
roundRobin->
tasksTable[ i++ ] = 0;
00093 }
00094
00095
for( i = 0; i<
NUM_TASKS ; )
00096 {
00097
runningTasks[ i++ ] = NULL;
00098 }
00099
00100
InitIntVectors();
00101
00102
op_TaskStart( &
idleTask,
IdleTaskFunction, &
idleTaskStack[
IDLE_TASK_STACK_SIZE ],
IDLE_TASK_IDENT, NULL );
00103
00104 }
00105
00109 void PerformDelay(
void )
00110 {
00111
00112
t_TASK* task = &
idleTask;
00113
00114
while( ( task = task->
nextSleeping ) != NULL )
00115 {
00116
if( --(task->
tickDelay) <= 0 )
00117 {
00118
00119
addTaskToTable(
readyTasks, task->
ident );
00120
00121
if( ( (task->
prevSleeping)->nextSleeping = task->
nextSleeping ) )
00122 (task->
nextSleeping)->prevSleeping = task->
prevSleeping;
00123
00124 }
00125 }
00126 }
00127
00128
00129 static unsigned char rotate(
unsigned char t,
register unsigned char n
asm(
"%d2") )
00130 {
00131
return (((t>>n)|(t<<(
_X_-n))));
00132 }
00133
00136 void Scheduler(
void )
00137 {
00138
00205
00206
register unsigned char y
asm(
"%d1") =
indexToLowestSettedBit[
readyTasks->
rowIndex ];
00207
register unsigned char x
asm(
"%d0") ;
00208
00209
if(
roundRobin->
rowIndex &
indexToSettedBit( y ) )
00210 {
00211
00212
register unsigned char decalage
asm(
"%d2") =
roundRobin->
tasksTable[ y ] + 1;
00213
00214 x = (
indexToLowestSettedBit[
rotate(
readyTasks->
tasksTable[ y ], decalage ) ] + decalage ) &
MASK_X;
00215
roundRobin->
tasksTable[ y ] = x;
00216 }
00217
else
00218 {
00219 x =
indexToLowestSettedBit[
readyTasks->
tasksTable[ y ] ];
00220 }
00221
00222 x += ( y <<
MASK_Y );
00223
00224
00225
if(
currentTask->
ident != x )
00226 {
00227
00228
register t_TASK* highestPriorityTaskReady
asm(
"%a3") =
runningTasks[ x ];
00229
00230
ContextSwitch( highestPriorityTaskReady, &
currentTask );
00231 }
00232
00233
00234
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261