LPCOpen Platform for LPC112X microcontrollers
112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
Main Page
Modules
Data Structures
Files
File List
Globals
software
lpc_core
lpc_chip
chip_112x
timer_112x.c
Go to the documentation of this file.
1
/*
2
* @brief 16/32-bit Timer/PWM control functions
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
chip.h
"
33
34
/*****************************************************************************
35
* Private types/enumerations/variables
36
****************************************************************************/
37
38
/*****************************************************************************
39
* Public types/enumerations/variables
40
****************************************************************************/
41
42
/*****************************************************************************
43
* Private functions
44
****************************************************************************/
45
46
/* Returns clock index for a specific timer referenced by IP block address */
47
STATIC
CHIP_SYSCON_CLOCK_T
Chip_TIMER_GetClock
(
LPC_TIMER_T
*pTMR)
48
{
49
CHIP_SYSCON_CLOCK_T
tmrClk;
50
if
(pTMR ==
LPC_TIMER32_1
) {
51
tmrClk =
SYSCON_CLOCK_CT32B1
;
52
}
53
else
if
(pTMR ==
LPC_TIMER16_0
) {
54
tmrClk =
SYSCON_CLOCK_CT16B0
;
55
}
56
else
if
(pTMR ==
LPC_TIMER16_1
) {
57
tmrClk =
SYSCON_CLOCK_CT16B1
;
58
}
59
else
{
60
tmrClk =
SYSCON_CLOCK_CT32B0
;
61
}
62
63
return
tmrClk;
64
}
65
66
/*****************************************************************************
67
* Public functions
68
****************************************************************************/
69
70
/* Initialize a timer */
71
void
Chip_TIMER_Init
(
LPC_TIMER_T
*pTMR)
72
{
73
Chip_Clock_EnablePeriphClock
(
Chip_TIMER_GetClock
(pTMR));
74
}
75
76
/* Shutdown a timer */
77
void
Chip_TIMER_DeInit
(
LPC_TIMER_T
*pTMR)
78
{
79
Chip_Clock_DisablePeriphClock
(
Chip_TIMER_GetClock
(pTMR));
80
}
81
82
/* Resets the timer terminal and prescale counts to 0 */
83
void
Chip_TIMER_Reset
(
LPC_TIMER_T
*pTMR)
84
{
85
uint32_t reg;
86
87
/* Disable timer, set terminal count to non-0 */
88
reg = pTMR->
TCR
;
89
pTMR->
TCR
= 0;
90
pTMR->
TC
= 1;
91
92
/* Reset timer counter */
93
pTMR->
TCR
=
TIMER_RESET
;
94
95
/* Wait for terminal count to clear */
96
while
(pTMR->
TC
!= 0) {}
97
98
/* Restore timer state */
99
pTMR->
TCR
= reg;
100
}
101
102
/* Sets external match control (MATn.matchnum) pin control */
103
void
Chip_TIMER_ExtMatchControlSet
(
LPC_TIMER_T
*pTMR, int8_t initial_state,
104
TIMER_PIN_MATCH_STATE_T
matchState, int8_t matchnum)
105
{
106
uint32_t mask, reg;
107
108
/* Clear bits corresponding to selected match register */
109
mask = (1 << matchnum) | (0x03 << (4 + (matchnum * 2)));
110
reg = pTMR->
EMR
&= ~mask;
111
112
/* Set new configuration for selected match register */
113
pTMR->
EMR
= reg | (((uint32_t) initial_state) << matchnum) |
114
(((uint32_t) matchState) << (4 + (matchnum * 2)));
115
}
Generated on Fri Feb 20 2015 22:12:06 for LPCOpen Platform for LPC112X microcontrollers by
1.8.3.1