timer.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *   timer.c:  Timer C file for Philips LPC214x Family Microprocessors
00003  *
00004  *   Copyright(C) 2006, Philips Semiconductor
00005  *   All rights reserved.
00006  *
00007  *   History
00008  *   2005.10.01  ver 1.00    Prelimnary version, first Release
00009  *
00010 ******************************************************************************/
00011 #include "LPC214x.h"            /* LPC21XX Peripheral Registers */
00012 #include "type.h"
00013 #include "irq.h"
00014 #include "timer.h"
00015 
00016 #include "interrupt_utils.h"
00017 
00018 volatile DWORD timer_counter = 0;
00019 
00020 /******************************************************************************
00021 ** Function name:               Timer0Handler
00022 **
00023 ** Descriptions:                Timer/Counter 0 interrupt handler
00024 **                              executes each 10ms @ 60 MHz CPU Clock
00025 **
00026 ** parameters:                  None
00027 ** Returned value:              None
00028 ** 
00029 ******************************************************************************/
00030 // mthomas: static inserted to avoid warning by gcc 4.1.0
00031 #if 1
00032 static void /*RAMFUNC*/ Timer0Handler (void) __irq
00033 {  
00034     T0IR = 1;                   /* clear interrupt flag */
00035     IENABLE;                    /* handles nested interrupt */
00036 
00037     timer_counter++;
00038 
00039     IDISABLE;
00040     VICVectAddr = 0;            /* Acknowledge Interrupt */
00041 }
00042 #endif
00043 
00044 #if 0
00045 // mthomas: macro-approach - not needed since there
00046 // is an assembler-wrapper provided in Startup.S
00047 static void NACKEDFUNC Timer0Handler (void) __irq
00048 {  
00049         ISR_STORE();
00050     T0IR = 1;                   /* clear interrupt flag */
00051         ISR_ENABLE_NEST();  /* handles nested interrupt */
00052 
00053     timer_counter++;
00054 
00055         ISR_DISABLE_NEST();     /* Disable Interrupt nesting */
00056     VICVectAddr = 0;            /* Acknowledge Interrupt */
00057         ISR_RESTORE();
00058 }
00059 #endif
00060 
00061 /******************************************************************************
00062 ** Function name:               enable_timer
00063 **
00064 ** Descriptions:                Enable timer
00065 **
00066 ** parameters:                  timer number: 0 or 1
00067 ** Returned value:              None
00068 ** 
00069 ******************************************************************************/
00070 void enable_timer( BYTE timer_num )
00071 {
00072     if ( timer_num == 0 )
00073     {
00074         T0TCR = 1;
00075     }
00076     else
00077     {
00078         T1TCR = 1;
00079     }
00080     return;
00081 }
00082 
00083 /******************************************************************************
00084 ** Function name:               disable_timer
00085 **
00086 ** Descriptions:                Disable timer
00087 **
00088 ** parameters:                  timer number: 0 or 1
00089 ** Returned value:              None
00090 ** 
00091 ******************************************************************************/
00092 void disable_timer( BYTE timer_num )
00093 {
00094     if ( timer_num == 0 )
00095     {
00096         T0TCR = 0;
00097     }
00098     else
00099     {
00100         T1TCR = 0;
00101     }
00102     return;
00103 }
00104 
00105 /******************************************************************************
00106 ** Function name:               reset_timer
00107 **
00108 ** Descriptions:                Reset timer
00109 **
00110 ** parameters:                  timer number: 0 or 1
00111 ** Returned value:              None
00112 ** 
00113 ******************************************************************************/
00114 void reset_timer( BYTE timer_num )
00115 {
00116     DWORD regVal;
00117 
00118     if ( timer_num == 0 )
00119     {
00120         regVal = T0TCR;
00121         regVal |= 0x02;
00122         T0TCR = regVal;
00123     }
00124     else
00125     {
00126         regVal = T1TCR;
00127         regVal |= 0x02;
00128         T1TCR = regVal;
00129     }
00130     return;
00131 }
00132 
00133 /******************************************************************************
00134 ** Function name:               init_timer
00135 **
00136 ** Descriptions:                Initialize timer, set timer interval, reset timer,
00137 **                              install timer interrupt handler
00138 **
00139 ** parameters:                  None
00140 ** Returned value:              true or false, if the interrupt handler can't be
00141 **                              installed, return false.
00142 ** 
00143 ******************************************************************************/
00144 DWORD init_timer (void) 
00145 {
00146     timer_counter = 0;
00147     T0MR0 = INTERVAL_10MS;      /* 10mSec = 150.000-1 counts */
00148     T0MCR = 3;                  /* Interrupt and Reset on MR0 */
00149     if ( install_irq( TIMER0_INT, (void *)Timer0Handler ) == FALSE )
00150     {
00151         return (FALSE);
00152     }
00153     else
00154     {
00155         return (TRUE);
00156     }
00157 }
00158 


ccny_asctec_firmware
Author(s): Ivan Dryanovski, Roberto G. Valenti
autogenerated on Tue Jan 7 2014 11:04:32