00001 /***************************************************************************** 00002 * * 00003 * ********** * 00004 * ************ * 00005 * *** *** * 00006 * *** +++ *** * 00007 * *** + + *** * 00008 * *** + CHIPCON CC1010 * 00009 * *** + + *** HAL - Wait * 00010 * *** +++ *** * 00011 * *** *** * 00012 * *********** * 00013 * ********* * 00014 * * 00015 ***************************************************************************** 00016 * * 00017 ***************************************************************************** 00018 * Author: ROH * 00019 ***************************************************************************** 00020 * Revision history: * 00021 * * 00022 * $Log: Wait.c,v $ 00023 * Revision 1.4 2004/01/08 19:21:46 tos 00024 * Reverted to "old" algorithm constant. 00025 * 00026 * Revision 1.3 2003/08/11 15:02:39 tos 00027 * Corrected reentrant usage in library: reentrant only if using large memory model. 00028 * 00029 * Revision 1.2 2003/07/29 11:25:33 tos 00030 * Made halWait() and halConfigTimer23() reentrant. 00031 * 00032 * Revision 1.1 2002/10/14 13:04:37 tos 00033 * Initial version in CVS. 00034 * 00035 * * 00036 ****************************************************************************/ 00037 00038 #include <chipcon/hal.h> 00039 00040 00041 //---------------------------------------------------------------------------- 00042 // byte* halWait(...) 00043 // 00044 // Description: 00045 // A wait functions which performs a number of iterations of a simple 00046 // wait loop, so that at least _timeOut_ ms goes by before the 00047 // function returns. 00048 // 00049 // Arguments: 00050 // byte timeOut 00051 // The time to wait in ms. 00052 // word clkFreq 00053 // The XOSC clock frequency in kHz. 00054 // 00055 // Return value: 00056 // void 00057 //---------------------------------------------------------------------------- 00058 #if (__MODEL__ == 0) // Memory model: 0 = SMALL, 1 = COMPACT, 2 = LARGE 00059 void halWait(byte timeOut, xdata word clkFreq) { 00060 #else 00061 void halWait(byte timeOut, xdata word clkFreq) reentrant { 00062 #endif 00063 unsigned long wait; 00064 00065 #ifdef SDCC 00066 // the sdcc seems to make more efficient code, so we have to wait longer (smaller divisor) 00067 wait= ((unsigned long)timeOut * (unsigned long)clkFreq) / 162; 00068 #else 00069 wait= ((unsigned long)timeOut * (unsigned long)clkFreq) / 192; 00070 #endif 00071 while (wait--); 00072 }