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 00018 00019 volatile int TStamp; 00020 00021 00022 extern PQ ActiveTasks; 00023 extern ECB *TimeoutList; 00024 static ECB *PostList; 00025 00026 /*********************************************************************** 00027 ** TimerTicker ** 00028 ** ** 00029 ** This function is called by the real time interrupt handler ** 00030 ** This function Increments the clock, scans through the Event ** 00031 ** Control Blocks looking for timed out events. ** 00032 ** ** 00033 ***********************************************************************/ 00034 00035 00036 void TimerTicker(void) 00037 { 00038 //we need to process the list of tasks waiting 00039 //for queues 00040 ECB *e; 00041 TCB *t,**prev; 00042 00043 00044 ++TStamp; 00045 for(e = TimeoutList;e;e=e->Tnext) //go through whole list 00046 { 00047 for(prev = &(e->task_h),t = e->task_h;t;) 00048 { 00049 if(t->timeout > 0) //if less than zero, infinate timeout 00050 { 00051 if( --(t->timeout) <= 0) //decrement timeout counter 00052 { 00053 e->EventCount++; //fake a post 00054 t->status = EVENT_TIMEOUT; //event caused by semaphore 00055 *prev = t->next; 00056 t->next = 0; 00057 Insert(&ActiveTasks,t); 00058 } 00059 } 00060 prev = &(t->next); 00061 t = t->next; 00062 } 00063 } 00064 e = PostList; 00065 while(e) 00066 { 00067 PostSemaphore(e,0); 00068 e = e->Tnext; 00069 } 00070 } 00071 00072 void RegisterTickerPost(ECB *pS) 00073 { 00074 char sr; 00075 00076 sr = Disable(); 00077 pS->Tnext = PostList; 00078 PostList = pS; 00079 Enable(sr); 00080 }