00001
00002
00003
00004
#include "opale_internal.h"
00005
00037 unsigned char*
indexToLowestSettedBit;
00038
00039 unsigned short numberOfNestedISRs;
00040 unsigned short numberOfNestedShedulerHalts;
00041
00043 t_TASK
idleTask;
00045 char*
idleTaskStack;
00046
00048 t_TASK**
runningTasks;
00049
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
00082
00083
readyTasks->rowIndex = 0;
00084
roundRobin->rowIndex = rotationMask;
00085
00086
00087
00088
for( i = 0; i<_Y_; )
00089 {
00090
readyTasks->tasksTable[ i ] = 0;
00091
roundRobin->tasksTable[ i++ ] = 0;
00092 }
00093
00094
for( i = 0; i<NUM_TASKS ; )
00095 {
00096
runningTasks[ i++ ] = NULL;
00097 }
00098
00099 InitIntVectors();
00100
00101
op_TaskStart( &
idleTask, IdleTaskFunction, &
idleTaskStack[ IDLE_TASK_STACK_SIZE ], IDLE_TASK_IDENT, NULL );
00102
00103 }
00104
00108 void PerformDelay(
void )
00109 {
00110
00111 t_TASK* task = &
idleTask;
00112
00113
while( ( task = task->nextSleeping ) != NULL )
00114 {
00115
if( --(task->tickDelay) == 0 )
00116 {
00117
00118
addTaskToTable(
readyTasks, task->ident );
00119
00120
if( ( (task->prevSleeping)->nextSleeping = task->nextSleeping ) )
00121 (task->nextSleeping)->prevSleeping = task->prevSleeping;
00122
00123 }
00124 }
00125 }
00126
00127
00128 static unsigned char rotate(
unsigned char t,
register unsigned char n
asm(
"%d2") )
00129 {
00130
return (((t>>n)|(t<<(_X_-n))));
00131 }
00132
00135 void Scheduler(
void )
00136 {
00137
00204
00205
register unsigned char y
asm(
"%d1") =
indexToLowestSettedBit[
readyTasks->rowIndex ];
00206
register unsigned char x
asm(
"%d0") ;
00207
00208
if(
roundRobin->rowIndex & indexToSettedBit( y ) )
00209 {
00210
00211
register unsigned char decalage
asm(
"%d2") =
roundRobin->tasksTable[ y ] + 1;
00212
00213 x = (
indexToLowestSettedBit[
rotate(
readyTasks->tasksTable[ y ], decalage ) ] + decalage ) & MASK_X;
00214
roundRobin->tasksTable[ y ] = x;
00215 }
00216
else
00217 {
00218 x =
indexToLowestSettedBit[
readyTasks->tasksTable[ y ] ];
00219 }
00220
00221 x += ( y << MASK_Y );
00222
00223
00224
if( currentTask->ident != x )
00225 {
00226
00227
register t_TASK* highestPriorityTaskReady
asm(
"%a3") =
runningTasks[ x ];
00228
00229 ContextSwitch( highestPriorityTaskReady, ¤tTask );
00230 }
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