libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
timer.h
Go to the documentation of this file.
1/** @defgroup timer_defines Timer
2
3@brief <b>Defined Constants and Types for the LPC43xx timer</b>
4
5@ingroup LPC43xx_defines
6
7@version 1.0.0
8
9@author @htmlonly &copy; @endhtmlonly 2012 Michael Ossmann <mike@ossmann.com>
10
11@date 10 March 2013
12
13LGPL License Terms @ref lgpl_license
14 */
15/*
16 * This file is part of the libopencm3 project.
17 *
18 * Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34#ifndef LPC43XX_TIMER_H
35#define LPC43XX_TIMER_H
36
37/**@{*/
38
41
42/* --- Convenience macros -------------------------------------------------- */
43
44/* Timer base addresses */
45#define TIMER0 TIMER0_BASE
46#define TIMER1 TIMER1_BASE
47#define TIMER2 TIMER2_BASE
48#define TIMER3 TIMER3_BASE
49
50
51/* --- Timer registers ----------------------------------------------------- */
52
53/* Interrupt Register */
54#define TIMER_IR(timer) MMIO32((timer) + 0x000)
55#define TIMER0_IR TIMER_IR(TIMER0)
56#define TIMER1_IR TIMER_IR(TIMER1)
57#define TIMER2_IR TIMER_IR(TIMER2)
58#define TIMER3_IR TIMER_IR(TIMER3)
59
60/* Timer Control Register */
61#define TIMER_TCR(timer) MMIO32((timer) + 0x004)
62#define TIMER0_TCR TIMER_TCR(TIMER0)
63#define TIMER1_TCR TIMER_TCR(TIMER1)
64#define TIMER2_TCR TIMER_TCR(TIMER2)
65#define TIMER3_TCR TIMER_TCR(TIMER3)
66
67/* Timer Counter */
68#define TIMER_TC(timer) MMIO32((timer) + 0x008)
69#define TIMER0_TC TIMER_TC(TIMER0)
70#define TIMER1_TC TIMER_TC(TIMER1)
71#define TIMER2_TC TIMER_TC(TIMER2)
72#define TIMER3_TC TIMER_TC(TIMER3)
73
74/* Prescale Register */
75#define TIMER_PR(timer) MMIO32((timer) + 0x00C)
76#define TIMER0_PR TIMER_PR(TIMER0)
77#define TIMER1_PR TIMER_PR(TIMER1)
78#define TIMER2_PR TIMER_PR(TIMER2)
79#define TIMER3_PR TIMER_PR(TIMER3)
80
81/* Prescale Counter */
82#define TIMER_PC(timer) MMIO32((timer) + 0x010)
83#define TIMER0_PC TIMER_PC(TIMER0)
84#define TIMER1_PC TIMER_PC(TIMER1)
85#define TIMER2_PC TIMER_PC(TIMER2)
86#define TIMER3_PC TIMER_PC(TIMER3)
87
88/* Match Control Register */
89#define TIMER_MCR(timer) MMIO32((timer) + 0x014)
90#define TIMER0_MCR TIMER_MCR(TIMER0)
91#define TIMER1_MCR TIMER_MCR(TIMER1)
92#define TIMER2_MCR TIMER_MCR(TIMER2)
93#define TIMER3_MCR TIMER_MCR(TIMER3)
94
95/* Match Register 0 */
96#define TIMER_MR0(timer) MMIO32((timer) + 0x018)
97#define TIMER0_MR0 TIMER_MR0(TIMER0)
98#define TIMER1_MR0 TIMER_MR0(TIMER1)
99#define TIMER2_MR0 TIMER_MR0(TIMER2)
100#define TIMER3_MR0 TIMER_MR0(TIMER3)
101
102/* Match Register 1 */
103#define TIMER_MR1(timer) MMIO32((timer) + 0x01C)
104#define TIMER0_MR1 TIMER_MR1(TIMER0)
105#define TIMER1_MR1 TIMER_MR1(TIMER1)
106#define TIMER2_MR1 TIMER_MR1(TIMER2)
107#define TIMER3_MR1 TIMER_MR1(TIMER3)
108
109/* Match Register 2 */
110#define TIMER_MR2(timer) MMIO32((timer) + 0x020)
111#define TIMER0_MR2 TIMER_MR2(TIMER0)
112#define TIMER1_MR2 TIMER_MR2(TIMER1)
113#define TIMER2_MR2 TIMER_MR2(TIMER2)
114#define TIMER3_MR2 TIMER_MR2(TIMER3)
115
116/* Match Register 3 */
117#define TIMER_MR3(timer) MMIO32((timer) + 0x024)
118#define TIMER0_MR3 TIMER_MR3(TIMER0)
119#define TIMER1_MR3 TIMER_MR3(TIMER1)
120#define TIMER2_MR3 TIMER_MR3(TIMER2)
121#define TIMER3_MR3 TIMER_MR3(TIMER3)
122
123/* Capture Control Register */
124#define TIMER_CCR(timer) MMIO32((timer) + 0x028)
125#define TIMER0_CCR TIMER_CCR(TIMER0)
126#define TIMER1_CCR TIMER_CCR(TIMER1)
127#define TIMER2_CCR TIMER_CCR(TIMER2)
128#define TIMER3_CCR TIMER_CCR(TIMER3)
129
130/* Capture Register 0 */
131#define TIMER_CR0(timer) MMIO32((timer) + 0x02C)
132#define TIMER0_CR0 TIMER_CR0(TIMER0)
133#define TIMER1_CR0 TIMER_CR0(TIMER1)
134#define TIMER2_CR0 TIMER_CR0(TIMER2)
135#define TIMER3_CR0 TIMER_CR0(TIMER3)
136
137/* Capture Register 1 */
138#define TIMER_CR1(timer) MMIO32((timer) + 0x030)
139#define TIMER0_CR1 TIMER_CR1(TIMER0)
140#define TIMER1_CR1 TIMER_CR1(TIMER1)
141#define TIMER2_CR1 TIMER_CR1(TIMER2)
142#define TIMER3_CR1 TIMER_CR1(TIMER3)
143
144/* Capture Register 2 */
145#define TIMER_CR2(timer) MMIO32((timer) + 0x034)
146#define TIMER0_CR2 TIMER_CR2(TIMER0)
147#define TIMER1_CR2 TIMER_CR2(TIMER1)
148#define TIMER2_CR2 TIMER_CR2(TIMER2)
149#define TIMER3_CR2 TIMER_CR2(TIMER3)
150
151/* Capture Register 3 */
152#define TIMER_CR3(timer) MMIO32((timer) + 0x038)
153#define TIMER0_CR3 TIMER_CR3(TIMER0)
154#define TIMER1_CR3 TIMER_CR3(TIMER1)
155#define TIMER2_CR3 TIMER_CR3(TIMER2)
156#define TIMER3_CR3 TIMER_CR3(TIMER3)
157
158/* External Match Register */
159#define TIMER_EMR(timer) MMIO32((timer) + 0x03C)
160#define TIMER0_EMR TIMER_EMR(TIMER0)
161#define TIMER1_EMR TIMER_EMR(TIMER1)
162#define TIMER2_EMR TIMER_EMR(TIMER2)
163#define TIMER3_EMR TIMER_EMR(TIMER3)
164
165/* Count Control Register */
166#define TIMER_CTCR(timer) MMIO32((timer) + 0x070)
167#define TIMER0_CTCR TIMER_CTCR(TIMER0)
168#define TIMER1_CTCR TIMER_CTCR(TIMER1)
169#define TIMER2_CTCR TIMER_CTCR(TIMER2)
170#define TIMER3_CTCR TIMER_CTCR(TIMER3)
171
172/* --- TIMERx_IR values ----------------------------------------------------- */
173
174#define TIMER_IR_MR0INT (1 << 0)
175#define TIMER_IR_MR1INT (1 << 1)
176#define TIMER_IR_MR2INT (1 << 2)
177#define TIMER_IR_MR3INT (1 << 3)
178#define TIMER_IR_CR0INT (1 << 4)
179#define TIMER_IR_CR1INT (1 << 5)
180#define TIMER_IR_CR2INT (1 << 6)
181#define TIMER_IR_CR3INT (1 << 7)
182
183/* --- TIMERx_TCR values --------------------------------------------------- */
184
185#define TIMER_TCR_CEN (1 << 0)
186#define TIMER_TCR_CRST (1 << 1)
187
188/* --- TIMERx_MCR values --------------------------------------------------- */
189
190#define TIMER_MCR_MR0I (1 << 0)
191#define TIMER_MCR_MR0R (1 << 1)
192#define TIMER_MCR_MR0S (1 << 2)
193#define TIMER_MCR_MR1I (1 << 3)
194#define TIMER_MCR_MR1R (1 << 4)
195#define TIMER_MCR_MR1S (1 << 5)
196#define TIMER_MCR_MR2I (1 << 6)
197#define TIMER_MCR_MR2R (1 << 7)
198#define TIMER_MCR_MR2S (1 << 8)
199#define TIMER_MCR_MR3I (1 << 9)
200#define TIMER_MCR_MR3R (1 << 10)
201#define TIMER_MCR_MR3S (1 << 11)
202
203/* --- TIMERx_MCR values --------------------------------------------------- */
204
205#define TIMER_CCR_CAP0RE (1 << 0)
206#define TIMER_CCR_CAP0FE (1 << 1)
207#define TIMER_CCR_CAP0I (1 << 2)
208#define TIMER_CCR_CAP1RE (1 << 3)
209#define TIMER_CCR_CAP1FE (1 << 4)
210#define TIMER_CCR_CAP1I (1 << 5)
211#define TIMER_CCR_CAP2RE (1 << 6)
212#define TIMER_CCR_CAP2FE (1 << 7)
213#define TIMER_CCR_CAP2I (1 << 8)
214#define TIMER_CCR_CAP3RE (1 << 9)
215#define TIMER_CCR_CAP3FE (1 << 10)
216#define TIMER_CCR_CAP3I (1 << 11)
217
218/* --- TIMERx_EMR values --------------------------------------------------- */
219
220#define TIMER_EMR_EM0 (1 << 0)
221#define TIMER_EMR_EM1 (1 << 1)
222#define TIMER_EMR_EM2 (1 << 2)
223#define TIMER_EMR_EM3 (1 << 3)
224#define TIMER_EMR_EMC0_SHIFT 4
225#define TIMER_EMR_EMC0_MASK (0x3 << TIMER_EMR_EMC0_SHIFT)
226#define TIMER_EMR_EMC1_SHIFT 6
227#define TIMER_EMR_EMC1_MASK (0x3 << TIMER_EMR_EMC1_SHIFT)
228#define TIMER_EMR_EMC2_SHIFT 8
229#define TIMER_EMR_EMC2_MASK (0x3 << TIMER_EMR_EMC2_SHIFT)
230#define TIMER_EMR_EMC3_SHIFT 10
231#define TIMER_EMR_EMC3_MASK (0x3 << TIMER_EMR_EMC3_SHIFT)
232
233#define TIMER_EMR_EMC_NOTHING 0x0
234#define TIMER_EMR_EMC_CLEAR 0x1
235#define TIMER_EMR_EMC_SET 0x2
236#define TIMER_EMR_EMC_TOGGLE 0x3
237
238/* --- TIMERx_CTCR values -------------------------------------------------- */
239
240#define TIMER_CTCR_MODE_TIMER (0x0 << 0)
241#define TIMER_CTCR_MODE_COUNTER_RISING (0x1 << 0)
242#define TIMER_CTCR_MODE_COUNTER_FALLING (0x2 << 0)
243#define TIMER_CTCR_MODE_COUNTER_BOTH (0x3 << 0)
244#define TIMER_CTCR_MODE_MASK (0x3 << 0)
245
246#define TIMER_CTCR_CINSEL_CAPN_0 (0x0 << 2)
247#define TIMER_CTCR_CINSEL_CAPN_1 (0x1 << 2)
248#define TIMER_CTCR_CINSEL_CAPN_2 (0x2 << 2)
249#define TIMER_CTCR_CINSEL_CAPN_3 (0x3 << 2)
250#define TIMER_CTCR_CINSEL_MASK (0x3 << 2)
251
252/* --- TIMER function prototypes ------------------------------------------- */
253
255
256void timer_reset(uint32_t timer_peripheral);
257void timer_enable_counter(uint32_t timer_peripheral);
258void timer_disable_counter(uint32_t timer_peripheral);
259uint32_t timer_get_counter(uint32_t timer_peripheral);
260void timer_set_counter(uint32_t timer_peripheral, uint32_t count);
261uint32_t timer_get_prescaler(uint32_t timer_peripheral);
262void timer_set_prescaler(uint32_t timer_peripheral, uint32_t prescaler);
263void timer_set_mode(uint32_t timer_peripheral, uint32_t mode);
264void timer_set_count_input(uint32_t timer_peripheral, uint32_t input);
265
267
268/**@}*/
269
270#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void timer_disable_counter(uint32_t timer_peripheral)
void timer_set_count_input(uint32_t timer_peripheral, uint32_t input)
void timer_set_counter(uint32_t timer_peripheral, uint32_t count)
uint32_t timer_get_prescaler(uint32_t timer_peripheral)
void timer_set_mode(uint32_t timer_peripheral, uint32_t mode)
void timer_enable_counter(uint32_t timer_peripheral)
void timer_reset(uint32_t timer_peripheral)
void timer_set_prescaler(uint32_t timer_peripheral, uint32_t prescaler)
uint32_t timer_get_counter(uint32_t timer_peripheral)