00001 00002 // This file is compiled with WinAVR version 4.1.2 00003 // 00004 // These routines mess with the stack 00005 // 00006 // you must use either of these optimizations: 00007 // -O1 00008 // -O3 00009 // -O2 00010 // 00011 // Whatever you do, do NOT use -O0....it will NOT work 00012 // 00013 // ///////////////////////////////////////////////////////////////////////////////////////// 00014 00015 #include "task.h" 00016 #include "pq.h" 00017 #include "HeapManager.h" 00018 00019 extern HEAP_BLOCK *pStackHeap; 00020 //---------------------------------------------------------------------- 00021 // 00022 // This function is used to compare two items in the priority queue 00023 // to see which one has the highest priority 00024 // 00025 // The function is passes two pointers that point to the pointers 00026 // that point to the actual objects 00027 // 00028 //---------------------------------------------------------------------- 00029 // 00030 static int PriorityCompare(void **s1, void **s2) 00031 { 00032 int r; 00033 00034 //check priority levels 00035 if( (r = ((TCB *)*s1)->priority - ((TCB *)*s2)->priority) != 0) 00036 return r; 00037 //if priority levels are the same, then check time stamps 00038 return (int)(((TCB *)*s2)->TimeStamp - ((TCB *)*s1)->TimeStamp); 00039 } 00040 00041 //-------------------------------------------------------------------------- 00042 // Initialize system 00043 //-------------------------------------------------------------------------- 00044 00045 void OSInit(void) 00046 { 00047 extern char IntRam[]; 00048 InitPQ(&ActiveTasks,32,PriorityCompare); 00049 pStackHeap = HeapInit(IntRam, &IntRam[8191]); 00050 } 00051