Main Page | File List | Globals

opale_core.c

Go to the documentation of this file.
00001 // C Source File 00002 // Created 05/02/05; 00:41:54 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 /* inits the number of running ISR to 0 */ 00077 numberOfNestedISRs = 0; 00078 00079 /* inits the number of requests to stop the scheduler to 1 (halted) */ 00080 numberOfNestedShedulerHalts = 1; 00081 00082 /* no tasks are ready yet, so we clear the ready row index */ 00083 readyTasks->rowIndex = 0; 00084 roundRobin->rowIndex = rotationMask; 00085 00086 /* inits each element of the readyTable to 0 (no active task) */ 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 /* x and y shall not be allocated on the stack ! */ 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 /* perform context switch if this is not the current task */ 00224 if( currentTask->ident != x ) 00225 { 00226 00227 register t_TASK* highestPriorityTaskReady asm("%a3") = runningTasks[ x ]; 00228 /* context switch */ 00229 ContextSwitch( highestPriorityTaskReady, &currentTask ); 00230 } 00231 00232 /* work done ... */ 00233 00234 } 00235 00236 // 00237 //void op_EnterISR( void ) 00238 //{ 00239 // /* increments the number of ISR in execution ... should be performed in an atomic assembly instruction 00240 // (I need to check the assembly output) */ 00241 // 00242 // numberOfNestedISRs ++; 00243 // 00244 //} 00245 00246 00247 //void op_ExitISR( void ) 00248 //{ 00249 /* decrements the number of ISR in execution ... should also be performed in an atomic assembly instruction 00250 (I need to check the assembly output, too) 00251 If the number is back to , the we are back to a non-ISR function, we then call the scheduler 00252 (if it is enabled) to check if one of the ISR that just finished hasn't woken 00253 a high priority thread */ 00254 00255 // if( !( -- numberOfNestedISRs ) && ( numberOfNestedShedulerHalts ) ) 00256 // { 00257 // op_Scheduler(); 00258 // } 00259 //} 00260

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