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 "stdio.h" 00016 #include "stdlib.h" 00017 #include "string.h" 00018 #include "task.h" 00019 00020 int TimeDelay(int mSec) 00021 { 00022 //-------------------------------------------------------------------------- 00023 // Delay task for a time 00024 // parameters: 00025 // mSec.............number of milliseconds to delay for 00026 // 00027 // return value: 00028 // returns non zero value if something happened out of the ordinary 00029 //-------------------------------------------------------------------------- 00030 int retval; 00031 static int DCount = 0; //keeps track of the number of times its called 00032 ECB *e; //pointer to event control block for semaphore 00033 char sr; //save area for status register 00034 00035 sr = Disable(); //disable interrupts 00036 char *s = malloc(32); //get a new block of memory 00037 Enable(sr); //bring interrupts back up 00038 s[0] = 'D'; //create name for semaphore 00039 itoa(DCount++,&s[1],10); 00040 e = NewSemaphore(0,SEMAPHORE_MODE_TIMEOUT,s); //create semaphore 00041 sr = Disable(); 00042 free(s); //return memory block 00043 Enable(sr); 00044 retval = PendSemaphore(e,mSec); //pend for time delay period 00045 DeleteSemaphore(e); //return semaphore back to pool 00046 return retval; //exit 00047 }