projekty/Source/example1/src/sysTime.c

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * $RCSfile: $
00004  * $Revision: $
00005  *
00006  * This module provides the interface routines for initializing and
00007  * accessing the system timing functions.
00008  * Copyright 2004, R O SoftWare
00009  * No guarantees, warrantees, or promises, implied or otherwise.
00010  * May be used for hobby or commercial purposes provided copyright
00011  * notice remains intact.
00012  *
00013  *****************************************************************************/
00014 #if 1
00015         #include "lpc229x.h"
00016 #else
00017         #include "lpc2114.h"
00018 #endif
00019         
00020 #include "lpcTMR.h"
00021 #include "lpcVIC.h"
00022         
00023 
00024 
00025 #include "types.h"
00026 #include "sysTime.h"
00027 
00028 static uint32_t sysTICs;
00029 static uint32_t lastT0TC;
00030 
00031 /******************************************************************************
00032  *
00033  * Function Name: initSysTime()
00034  *
00035  * Description:
00036  *    This function initializes the LPC's Timer 0 for use as the system timer.
00037  *
00038  * Calling Sequence: 
00039  *    void
00040  *
00041  * Returns:
00042  *    void
00043  *
00044  *****************************************************************************/
00045 void initSysTime(void)
00046 {
00047   // setup Timer 1 to count forever
00048   T0_TCR = TCR_RESET;                    // reset & disable timer 0
00049   T0_PR = T0_PCLK_DIV - 1;               // set the prescale divider
00050   T0_MCR = 0;                            // disable match registers
00051   T0_CCR = 0;                            // disable compare registers
00052   T0_EMR = 0;                            // disable external match register
00053   T0_TCR = TCR_ENABLE;                   // enable timer 0
00054   sysTICs = 0;
00055 }
00056 
00057 /******************************************************************************
00058  *
00059  * Function Name: getSysTICs()
00060  *
00061  * Description:
00062  *    This function returns the current syetem time in TICs.
00063  *
00064  * Calling Sequence: 
00065  *    void
00066  *
00067  * Returns:
00068  *    The current time in TICs as represented by sysTICs
00069  *
00070  *****************************************************************************/
00071 uint32_t getSysTICs(void)
00072 {
00073   uint32_t now = T0_TC;
00074 
00075   sysTICs += (uint32_t)(now - lastT0TC);
00076   lastT0TC = now;
00077   return sysTICs;
00078 }
00079 
00080 
00081 /******************************************************************************
00082  *
00083  * Function Name: getElapsedSysTICs()
00084  *
00085  * Description:
00086  *    This function then returns the difference in TICs between the
00087  *    given starting time and the current system time.
00088  *
00089  * Calling Sequence: 
00090  *    The starting time.
00091  *
00092  * Returns:
00093  *    The time difference.
00094  *
00095  *****************************************************************************/
00096 uint32_t getElapsedSysTICs(uint32_t startTime)
00097 {
00098   return getSysTICs() - startTime;
00099 }
00100 
00101 
00102 /******************************************************************************
00103  *
00104  * Function Name: pause()
00105  *
00106  * Description:
00107  *    This function does not return until the specified 'duration' in
00108  *    TICs has elapsed.
00109  *
00110  * Calling Sequence: 
00111  *    duration - length of time in TICs to wait before returning
00112  *
00113  * Returns:
00114  *    void
00115  *
00116  *****************************************************************************/
00117 void pause(uint32_t duration)
00118 {
00119   uint32_t startTime = getSysTICs();
00120 
00121   while (getElapsedSysTICs(startTime) < duration) ;
00122 }

Generated on Fri Sep 21 13:41:54 2007 for example1 by  doxygen 1.4.7