PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timer_11u6x.c Source File

timer_11u6x.c

00001 /*
00002  * @brief LPC11u6x 16/32-bit Timer/PWM control functions
00003  *
00004  * @note
00005  * Copyright(C) NXP Semiconductors, 2013
00006  * All rights reserved.
00007  *
00008  * @par
00009  * Software that is described herein is for illustrative purposes only
00010  * which provides customers with programming information regarding the
00011  * LPC products.  This software is supplied "AS IS" without any warranties of
00012  * any kind, and NXP Semiconductors and its licensor disclaim any and
00013  * all warranties, express or implied, including all implied warranties of
00014  * merchantability, fitness for a particular purpose and non-infringement of
00015  * intellectual property rights.  NXP Semiconductors assumes no responsibility
00016  * or liability for the use of the software, conveys no license or rights under any
00017  * patent, copyright, mask work right, or any other intellectual property rights in
00018  * or to any products. NXP Semiconductors reserves the right to make changes
00019  * in the software without notification. NXP Semiconductors also makes no
00020  * representation or warranty that such application will be suitable for the
00021  * specified use without further testing or modification.
00022  *
00023  * @par
00024  * Permission to use, copy, modify, and distribute this software and its
00025  * documentation is hereby granted, under NXP Semiconductors' and its
00026  * licensor's relevant copyrights in the software, without fee, provided that it
00027  * is used in conjunction with NXP Semiconductors microcontrollers.  This
00028  * copyright, permission, and disclaimer notice must appear in all copies of
00029  * this code.
00030  */
00031 
00032 //#include "chip.h"
00033 //#include "lpc_defs.h"
00034 #include "timer_11u6x.h"
00035 #include "clock_11u6x.h"
00036 
00037 /* System oscillator rate and RTC oscillator rate */
00038 const uint32_t OscRateIn = 12000000;
00039 const uint32_t RTCOscRateIn = 32768;
00040 
00041 
00042 /*****************************************************************************
00043  * Private types/enumerations/variables
00044  ****************************************************************************/
00045 
00046 /*****************************************************************************
00047  * Public types/enumerations/variables
00048  ****************************************************************************/
00049 
00050 /*****************************************************************************
00051  * Private functions
00052  ****************************************************************************/
00053 
00054 /* Static data/function define */
00055 #define STATIC static
00056 /* External data/function define */
00057 #define EXTERN extern
00058 
00059 
00060 
00061 
00062 /* Returns clock index for a specific timer referenced by IP block address */
00063 STATIC CHIP_SYSCTL_CLOCK_T Chip_TIMER_GetClock(LPC_TIMER_T *pTMR)
00064 {
00065     CHIP_SYSCTL_CLOCK_T tmrClk;
00066     if (pTMR == LPC_TIMER32_1) {
00067         tmrClk = SYSCTL_CLOCK_CT32B1 ;
00068     }
00069     else if (pTMR == LPC_TIMER16_0) {
00070         tmrClk = SYSCTL_CLOCK_CT16B0 ;
00071     }
00072     else if (pTMR == LPC_TIMER16_1) {
00073         tmrClk = SYSCTL_CLOCK_CT16B1 ;
00074     }
00075     else {
00076         tmrClk = SYSCTL_CLOCK_CT32B0 ;
00077     }
00078 
00079     return tmrClk;
00080 }
00081 
00082 /*****************************************************************************
00083  * Public functions
00084  ****************************************************************************/
00085 
00086 /* Initialize a timer */
00087 void Chip_TIMER_Init(LPC_TIMER_T *pTMR)
00088 {
00089     Chip_Clock_EnablePeriphClock(Chip_TIMER_GetClock(pTMR));
00090 }
00091 
00092 /*  Shutdown a timer */
00093 void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR)
00094 {
00095     Chip_Clock_DisablePeriphClock(Chip_TIMER_GetClock(pTMR));
00096 }
00097 
00098 /* Resets the timer terminal and prescale counts to 0 */
00099 void Chip_TIMER_Reset(LPC_TIMER_T *pTMR)
00100 {
00101     uint32_t reg;
00102 
00103     /* Disable timer, set terminal count to non-0 */
00104     reg = pTMR->TCR ;
00105     pTMR->TCR  = 0;
00106     pTMR->TC  = 1;
00107 
00108     /* Reset timer counter */
00109     pTMR->TCR  = TIMER_RESET;
00110 
00111     /* Wait for terminal count to clear */
00112     while (pTMR->TC  != 0) {}
00113 
00114     /* Restore timer state */
00115     pTMR->TCR  = reg;
00116 }
00117 
00118 /* Sets external match control (MATn.matchnum) pin control */
00119 void Chip_TIMER_ExtMatchControlSet(LPC_TIMER_T *pTMR, int8_t initial_state,
00120                                    TIMER_PIN_MATCH_STATE_T matchState, int8_t matchnum)
00121 {
00122     uint32_t mask, reg;
00123 
00124     /* Clear bits corresponding to selected match register */
00125     mask = (1 << matchnum) | (0x03 << (4 + (matchnum * 2)));
00126     reg = pTMR->EMR  &= ~mask;
00127 
00128     /* Set new configuration for selected match register */
00129     pTMR->EMR  = reg | (((uint32_t) initial_state) << matchnum) |
00130                 (((uint32_t) matchState) << (4 + (matchnum * 2)));
00131 }
00132