4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
34 * \author Daniele Basile <asterix@develer.com>
36 * AT91SAM7 Conunter timer definition.
37 * This file is based on NUT/OS implementation. See license below.
41 * Copyright (C) 2005-2006 by egnite Software GmbH. All rights reserved.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. Neither the name of the copyright holders nor the names of
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
57 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
59 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
60 * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
63 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
64 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
66 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * For additional information see http://www.ethernut.de/
77 * Timer Counter Control Register
79 #define TC_TC0_OFF 0x00000000 ///< Channel 0 control register offset.
80 #define TC_TC1_OFF 0x00000040 ///< Channel 1 control register offset.
81 #define TC_TC2_OFF 0x00000080 ///< Channel 2 control register offset.
82 #define TC0_CCR (*((reg32_t *)(TC_BASE + TC_TC0_OFF))) ///< Channel 0 control register address.
83 #define TC1_CCR (*((reg32_t *)(TC_BASE + TC_TC1_OFF))) ///< Channel 1 control register address.
84 #define TC2_CCR (*((reg32_t *)(TC_BASE + TC_TC2_OFF))) ///< Channel 2 control register address.
85 #define TC_CLKEN 0 ///< Clock enable command.
86 #define TC_CLKDIS 1 ///< Clock disable command.
87 #define TC_SWTRG 2 ///< Software trigger command.
90 * Timer Counter Channel Mode Register
92 #define TC_CMR_OFF 0x00000004 ///< Mode register offset.
93 #define TC0_CMR (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_CMR_OFF))) ///< Channel 0 mode register address.
94 #define TC1_CMR (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_CMR_OFF))) ///< Channel 1 mode register address.
95 #define TC2_CMR (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_CMR_OFF))) ///< Channel 2 mode register address.
97 #define TC_CLKS_MASK 0x00000007 ///< Clock selection mask.
98 #define TC_CLKS_MCK2 0x00000000 ///< Selects MCK / 2.
99 #define TC_CLKS_MCK8 0x00000001 ///< Selects MCK / 8.
100 #define TC_CLKS_MCK32 0x00000002 ///< Selects MCK / 32.
101 #define TC_CLKS_MCK128 0x00000003 ///< Selects MCK / 128.
102 #define TC_CLKS_MCK1024 0x00000004 ///< Selects MCK / 1024.
103 #define TC_CLKS_XC0 0x00000005 ///< Selects external clock 0.
104 #define TC_CLKS_XC1 0x00000006 ///< Selects external clock 1.
105 #define TC_CLKS_XC2 0x00000007 ///< Selects external clock 2.
107 #define TC_CLKI 3 ///< Increments on falling edge.
109 #define TC_BURST_MASK 0x00000030 ///< Burst signal selection mask.
110 #define TC_BURST_NONE 0x00000000 ///< Clock is not gated by an external signal.
111 #define TC_BUSRT_XC0 0x00000010 ///< ANDed with external clock 0.
112 #define TC_BURST_XC1 0x00000020 ///< ANDed with external clock 1.
113 #define TC_BURST_XC2 0x00000030 ///< ANDed with external clock 2.
117 #define TC_WAVE 15 ///< Selects waveform mode.
118 //To select capture mode you must set TC_WAVE bit to 0.
119 //#define TC_CAPT 15 ///< Selects capture mode.
124 #define TC_CPCTRG 14 ///< RC Compare Enable Trigger Enable.
125 #define TC_LDBSTOP 6 ///< Counter clock stopped on RB loading.
126 #define TC_LDBDIS 7 ///< Counter clock disabled on RB loading.
128 #define TC_ETRGEDG_MASK 0x00000300 ///< External trigger edge selection mask.
129 #define TC_ETRGEDG_RISING_EDGE 0x00000100 ///< Trigger on external rising edge.
130 #define TC_ETRGEDG_FALLING_EDGE 0x00000200 ///< Trigger on external falling edge.
131 #define TC_ETRGEDG_BOTH_EDGE 0x00000300 ///< Trigger on both external edges.
133 #define TC_ABETRG_MASK 0x00000400 ///< TIOA or TIOB external trigger selection mask.
134 #define TC_ABETRG_TIOA 10 ///< TIOA used as an external trigger.
135 //To use external trigger TIOB you must set TC_ABETRG_TIOA bit to 0.
136 //#define TC_ABETRG_TIOB 10 ///< TIOB used as an external trigger.
139 #define TC_LDRA_MASK 0x00030000 ///< RA loading selection mask.
140 #define TC_LDRA_RISING_EDGE 0x00010000 ///< Load RA on rising edge of TIOA.
141 #define TC_LDRA_FALLING_EDGE 0x00020000 ///< Load RA on falling edge of TIOA.
142 #define TC_LDRA_BOTH_EDGE 0x00030000 ///< Load RA on any edge of TIOA.
144 #define TC_LDRB_MASK 0x000C0000 ///< RB loading selection mask.
145 #define TC_LDRB_RISING_EDGE 0x00040000 ///< Load RB on rising edge of TIOA.
146 #define TC_LDRB_FALLING_EDGE 0x00080000 ///< Load RB on falling edge of TIOA.
147 #define TC_LDRB_BOTH_EDGE 0x000C0000 ///< Load RB on any edge of TIOA.
153 #define TC_CPCSTOP 6 ///< Counter clock stopped on RC compare.
154 #define TC_CPCDIS 7 ///< Counter clock disabled on RC compare.
156 #define TC_EEVTEDG_MASK 0x00000300 ///< External event edge selection mask.
157 #define TC_EEVTEDG_RISING_EDGE 0x00000100 ///< External event on rising edge..
158 #define TC_EEVTEDG_FALLING_EDGE 0x00000200 ///< External event on falling edge..
159 #define TC_EEVTEDG_BOTH_EDGE 0x00000300 ///< External event on any edge..
161 #define TC_EEVT_MASK 0x00000C00 ///< External event selection mask.
162 #define TC_EEVT_TIOB 0x00000000 ///< TIOB selected as external event.
163 #define TC_EEVT_XC0 0x00000400 ///< XC0 selected as external event.
164 #define TC_EEVT_XC1 0x00000800 ///< XC1 selected as external event.
165 #define TC_EEVT_XC2 0x00000C00 ///< XC2 selected as external event.
167 #define TC_ENETRG 12 ///< External event trigger enable.
169 #define TC_WAVSEL_MASK 0x00006000 ///< Waveform selection mask.
170 #define TC_WAVSEL_UP 0x00000000 ///< UP mode whitout automatic trigger on RC compare.
171 #define TC_WAVSEL_UP_RC_TRG 0x00004000 ///< UP mode whit automatic trigger on RC compare.
172 #define TC_WAVSEL_UPDOWN 0x00002000 ///< UPDOWN mode whitout automatic trigger on RC compare.
173 #define TC_WAVSEL_UPDOWN_RC_TRG 0x00003000 ///< UPDOWN mode whit automatic trigger on RC compare.
176 #define TC_ACPA_MASK 0x00030000 ///< Masks RA compare effect on TIOA.
177 #define TC_ACPA_SET_OUTPUT 0x00010000 ///< RA compare sets TIOA.
178 #define TC_ACPA_CLEAR_OUTPUT 0x00020000 ///< RA compare clears TIOA.
179 #define TC_ACPA_TOGGLE_OUTPUT 0x00030000 ///< RA compare toggles TIOA.
181 #define TC_ACPC_MASK 0x000C0000 ///< Masks RC compare effect on TIOA.
182 #define TC_ACPC_SET_OUTPUT 0x00040000 ///< RC compare sets TIOA.
183 #define TC_ACPC_CLEAR_OUTPUT 0x00080000 ///< RC compare clears TIOA.
184 #define TC_ACPC_TOGGLE_OUTPUT 0x000C0000 ///< RC compare toggles TIOA.
186 #define TC_AEEVT_MASK 0x00300000 ///< Masks external event effect on TIOA.
187 #define TC_AEEVT_SET_OUTPUT 0x00100000 ///< External event sets TIOA.
188 #define TC_AEEVT_CLEAR_OUTPUT 0x00200000 ///< External event clears TIOA.
189 #define TC_AEEVT_TOGGLE_OUTPUT 0x00300000 ///< External event toggles TIOA.
191 #define TC_ASWTRG_MASK 0x00C00000 ///< Masks software trigger effect on TIOA.
192 #define TC_ASWTRG_SET_OUTPUT 0x00400000 ///< Software trigger sets TIOA.
193 #define TC_ASWTRG_CLEAR_OUTPUT 0x00800000 ///< Software trigger clears TIOA.
194 #define TC_ASWTRG_TOGGLE_OUTPUT 0x00C00000 ///< Software trigger toggles TIOA.
196 #define TC_BCPB_MASK 0x03000000 ///< Masks RB compare effect on TIOB.
197 #define TC_BCPB_SET_OUTPUT 0x01000000 ///< RB compare sets TIOB.
198 #define TC_BCPB_CLEAR_OUTPUT 0x02000000 ///< RB compare clears TIOB.
199 #define TC_BCPB_TOGGLE_OUTPUT 0x03000000 ///< RB compare toggles TIOB.
201 #define TC_BCPC_MASK 0x0C000000 ///< Masks RC compare effect on TIOB.
202 #define TC_BCPC_SET_OUTPUT 0x04000000 ///< RC compare sets TIOB.
203 #define TC_BCPC_CLEAR_OUTPUT 0x08000000 ///< RC compare clears TIOB.
204 #define TC_BCPC_TOGGLE_OUTPUT 0x0C000000 ///< RC compare toggles TIOB.
206 #define TC_BEEVT_MASK 0x30000000 ///< Masks external event effect on TIOB.
207 #define TC_BEEVT_SET_OUTPUT 0x10000000 ///< External event sets TIOB.
208 #define TC_BEEVT_CLEAR_OUTPUT 0x20000000 ///< External event clears TIOB.
209 #define TC_BEEVT_TOGGLE_OUTPUT 0x30000000 ///< External event toggles TIOB.
211 #define TC_BSWTRG_MASK 0xC0000000 ///< Masks software trigger effect on TIOB.
212 #define TC_BSWTRG_SET_OUTPUT 0x40000000 ///< Software trigger sets TIOB.
213 #define TC_BSWTRG_CLEAR_OUTPUT 0x80000000 ///< Software trigger clears TIOB.
214 #define TC_BSWTRG_TOGGLE_OUTPUT 0xC0000000 ///< Software trigger toggles TIOB.
217 * Counter Value Register
219 #define TC_CV_OFF 0x00000010 ///< Counter register value offset.
220 #define TC0_CV (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_CV_OFF))) ///< Counter 0 value.
221 #define TC1_CV (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_CV_OFF))) ///< Counter 1 value.
222 #define TC2_CV (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_CV_OFF))) ///< Counter 2 value.
225 * Timer Counter Register A
227 #define TC_RA_OFF 0x00000014 ///< Register A offset.
228 #define TC0_RA (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_RA_OFF))) ///< Channel 0 register A.
229 #define TC1_RA (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_RA_OFF))) ///< Channel 1 register A.
230 #define TC2_RA (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_RA_OFF))) ///< Channel 2 register A.
234 * Timer Counter Register B
236 #define TC_RB_OFF 0x00000018 ///< Register B offset.
237 #define TC0_RB (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_RB_OFF))) ///< Channel 0 register B.
238 #define TC1_RB (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_RB_OFF))) ///< Channel 1 register B.
239 #define TC2_RB (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_RB_OFF))) ///< Channel 2 register B.
243 * Timer Counter Register C
245 #define TC_RC_OFF 0x0000001C ///< Register C offset.
246 #define TC0_RC (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_RC_OFF))) ///< Channel 0 register C.
247 #define TC1_RC (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_RC_OFF))) ///< Channel 1 register C.
248 #define TC2_RC (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_RC_OFF))) ///< Channel 2 register C.
253 * Timer Counter Status and Interrupt Registers
255 #define TC_SR_OFF 0x00000020 ///< Status Register offset.
256 #define TC0_SR (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_SR_OFF))) ///< Status register address.
257 #define TC1_SR (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_SR_OFF))) ///< Status register address.
258 #define TC2_SR (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_SR_OFF))) ///< Status register address.
260 #define TC_IER_OFF 0x00000024 ///< Interrupt Enable Register offset.
261 #define TC0_IER (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_IER_OFF))) ///< Channel 0 interrupt enable register address.
262 #define TC1_IER (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_IER_OFF))) ///< Channel 1 interrupt enable register address.
263 #define TC2_IER (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_IER_OFF))) ///< Channel 2 interrupt enable register address.
265 #define TC_IDR_OFF 0x00000028 ///< Interrupt Disable Register offset.
266 #define TC0_IDR (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_IDR_OFF))) ///< Channel 0 interrupt disable register address.
267 #define TC1_IDR (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_IDR_OFF))) ///< Channel 1 interrupt disable register address.
268 #define TC2_IDR (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_IDR_OFF))) ///< Channel 2 interrupt disable register address.
270 #define TC_IMR_OFF 0x0000002C ///< Interrupt Mask Register offset.
271 #define TC0_IMR (*((reg32_t *)(TC_BASE + TC_TC0_OFF + TC_IMR_OFF))) ///< Channel 0 interrupt mask register address.
272 #define TC1_IMR (*((reg32_t *)(TC_BASE + TC_TC1_OFF + TC_IMR_OFF))) ///< Channel 1 interrupt mask register address.
273 #define TC2_IMR (*((reg32_t *)(TC_BASE + TC_TC2_OFF + TC_IMR_OFF))) ///< Channel 2 interrupt mask register address.
275 #define TC_COVFS 0 ///< Counter overflow flag.
276 #define TC_LOVRS 1 ///< Load overrun flag.
277 #define TC_CPAS 2 ///< RA compare flag.
278 #define TC_CPBS 3 ///< RB compare flag.
279 #define TC_CPCS 4 ///< RC compare flag.
280 #define TC_LDRAS 5 ///< RA loading flag.
281 #define TC_LDRBS 6 ///< RB loading flag.
282 #define TC_ETRGS 7 ///< External trigger flag.
283 #define TC_CLKSTA 16 ///< Clock enable flag.
284 #define TC_MTIOA 17 ///< TIOA flag.
285 #define TC_MTIOB 18 ///< TIOB flag.
289 * Timer Counter Block Control Register
291 #define TC_BCR_OFF 0x000000C0 ///< Block control register offset.
292 #define TC_BCR (*((reg32_t *)(TC_BASE + TC_BCR_OFF))) ///< Block control register address.
293 #define TC_SYNC 0 ///< Synchronisation trigger
297 * Timer Counter Block Mode Register
299 #define TC_BMR_OFF 0x000000C4 ///< Block mode register offset.
300 #define TC_BMR (*((reg32_t *)(TC_BASE + TC_BMR_OFF))) ///< Block mode register address.
301 #define TC_TC0XC0S 0x00000003 ///< External clock signal 0 selection mask.
302 #define TC_TCLK0XC0 0x00000000 ///< Selects TCLK0.
303 #define TC_NONEXC0 0x00000001 ///< None selected.
304 #define TC_TIOA1XC0 0x00000002 ///< Selects TIOA1.
305 #define TC_TIOA2XC0 0x00000003 ///< Selects TIOA2.
307 #define TC_TC1XC1S 0x0000000C ///< External clock signal 1 selection mask.
308 #define TC_TCLK1XC1 0x00000000 ///< Selects TCLK1.
309 #define TC_NONEXC1 0x00000004 ///< None selected.
310 #define TC_TIOA0XC1 0x00000008 ///< Selects TIOA0.
311 #define TC_TIOA2XC1 0x0000000C ///< Selects TIOA2.
313 #define TC_TC2XC2S 0x00000030 ///< External clock signal 2 selection mask.
314 #define TC_TCLK2XC2 0x00000000 ///< Selects TCLK2.
315 #define TC_NONEXC2 0x00000010 ///< None selected.
316 #define TC_TIOA0XC2 0x00000020 ///< Selects TIOA0.
317 #define TC_TIOA1XC2 0x00000030 ///< Selects TIOA1.
320 #endif /* AT91_TC_H */