Refactor BeRTOS to be in his own directory.
[bertos.git] / cpu / arm / io / at91_pwm.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \version $Id$
34  *
35  * \author Francesco Sacchi <batt@develer.com>
36  *
37  * AT91SAM7 Pulse Width Modulation Controller.
38  */
39
40 #ifndef AT91_PWM_H
41 #define AT91_PWM_H
42
43 /**
44  * PWM Mode Register.
45  */
46 /*\{*/
47 #define PWM_MR_OFF              0x00000000    ///< PWM Mode Register offset.
48 #define PWM_MR     (*((reg32_t *)(PWMC_BASE + PWM_MR_OFF))) ///< PWM Mode Register.
49 #define PWM_MR_DIVA_MASK        0x000000FF    ///< PWM Mode Divide factor A Mask.
50 #define PWM_MR_DIVA_SHIFT       0             ///< PWM Mode Divide factor A LSB.
51 #define PWM_MR_DIVB_MASK        0x00FF0000    ///< PWM Mode Divide factor B Mask.
52 #define PWM_MR_DIVB_SHIFT       16            ///< PWM Mode Divide factor B LSB.
53
54 #define PWM_MR_PREA_MASK        0x00000F00    ///< PWM Mode prescaler A Mask.
55 #define PWM_MR_PREA_SHIFT       8             ///< PWM Mode prescaler A LSB.
56 #define PWM_MR_PREB_MASK        0x0F000000    ///< PWM Mode prescaler B Mask.
57 #define PWM_MR_PREB_SHIFT       24            ///< PWM Mode prescaler B LSB.
58
59 #define PWM_MR_PRE_MCK          0             ///< PWM Mode prescaler set to MCK.
60 #define PWM_MR_PRE_MCK_DIV2     1             ///< PWM Mode prescaler set to MCK/2.
61 #define PWM_MR_PRE_MCK_DIV4     2             ///< PWM Mode prescaler set to MCK/4.
62 #define PWM_MR_PRE_MCK_DIV8     3             ///< PWM Mode prescaler set to MCK/8.
63 #define PWM_MR_PRE_MCK_DIV16    4             ///< PWM Mode prescaler set to MCK/16.
64 #define PWM_MR_PRE_MCK_DIV32    5             ///< PWM Mode prescaler set to MCK/32.
65 #define PWM_MR_PRE_MCK_DIV64    6             ///< PWM Mode prescaler set to MCK/64.
66 #define PWM_MR_PRE_MCK_DIV128   7             ///< PWM Mode prescaler set to MCK/128.
67 #define PWM_MR_PRE_MCK_DIV256   8             ///< PWM Mode prescaler set to MCK/256.
68 #define PWM_MR_PRE_MCK_DIV512   9             ///< PWM Mode prescaler set to MCK/512.
69 #define PWM_MR_PRE_MCK_DIV1024  10            ///< PWM Mode prescaler set to MCK/1024.
70 /*\}*/
71
72 /**
73  * PWM Channel IDs.
74  */
75 /*\{*/
76 #define PWM_CHID_MASK           0x0000000F
77 #define PWM_CHID0               0
78 #define PWM_CHID1               1
79 #define PWM_CHID2               2
80 #define PWM_CHID3               3
81 /*\}*/
82
83 /**
84  * PWM Enable Register.
85  */
86 /*\{*/
87 #define PWM_ENA_OFF             0x00000004    ///< PWM Enable Register offset.
88 #define PWM_ENA     (*((reg32_t *)(PWMC_BASE + PWM_ENA_OFF))) ///< PWM Enable Register.
89 /*\}*/
90
91 /**
92  * PWM Disable Register.
93  */
94 /*\{*/
95 #define PWM_DIS_OFF             0x00000008    ///< PWM Disable Register offset.
96 #define PWM_DIS     (*((reg32_t *)(PWMC_BASE + PWM_DIS_OFF))) ///< PWM Disable Register.
97 /*\}*/
98
99 /**
100  * PWM Status Register.
101  */
102 /*\{*/
103 #define PWM_SR_OFF              0x0000000C    ///< PWM Status Register offset.
104 #define PWM_SR      (*((reg32_t *)(PWMC_BASE + PWM_SR_OFF)))  ///< PWM Status Register.
105 /*\}*/
106
107 /**
108  * PWM Interrupt Enable Register.
109  */
110 /*\{*/
111 #define PWM_IER_OFF             0x00000010    ///< PWM Interrupt Enable Register offset.
112 #define PWM_IER     (*((reg32_t *)(PWMC_BASE + PWM_IER_OFF))) ///< PWM Interrupt Enable Register.
113 /*\}*/
114
115 /**
116  * PWM Interrupt Disable Register.
117  */
118 /*\{*/
119 #define PWM_IDR_OFF             0x00000014    ///< PWM Interrupt Disable Register offset.
120 #define PWM_IDR     (*((reg32_t *)(PWMC_BASE + PWM_IDR_OFF))) ///< PWM Interrupt Disable Register.
121 /*\}*/
122
123 /**
124  * PWM Interrupt Mask Register.
125  */
126 /*\{*/
127 #define PWM_IMR_OFF             0x00000018    ///< PWM Interrupt Mask Register offset.
128 #define PWM_IMR     (*((reg32_t *)(PWMC_BASE + PWM_IMR_OFF))) ///< PWM Interrupt Mask Register.
129 /*\}*/
130
131 /**
132  * PWM Interrupt Status Register.
133  */
134 /*\{*/
135 #define PWM_ISR_OFF             0x0000001C    ///< PWM Interrupt Status Register offset.
136 #define PWM_ISR     (*((reg32_t *)(PWMC_BASE + PWM_ISR_OFF))) ///< PWM Interrupt Status Register.
137 /*\}*/
138
139 #define PWM_CH0_OFF             0x00000200    ///< PWM Channel 0 registers offset.
140 #define PWM_CH1_OFF             0x00000220    ///< PWM Channel 1 registers offset.
141 #define PWM_CH2_OFF             0x00000240    ///< PWM Channel 2 registers offset.
142 #define PWM_CH3_OFF             0x00000260    ///< PWM Channel 3 registers offset.
143
144 /**
145  * PWM Channel Mode Register.
146  */
147 /*\{*/
148 #define PWM_CMR_OFF             0x00000000    ///< PWM Channel Mode Register offset.
149 #define PWM_CMR0    (*((reg32_t *)(PWMC_BASE + PWM_CMR_OFF + PWM_CH0_OFF))) ///< PWM Channel 0 Mode Register.
150 #define PWM_CMR1    (*((reg32_t *)(PWMC_BASE + PWM_CMR_OFF + PWM_CH1_OFF))) ///< PWM Channel 1 Mode Register.
151 #define PWM_CMR2    (*((reg32_t *)(PWMC_BASE + PWM_CMR_OFF + PWM_CH2_OFF))) ///< PWM Channel 2 Mode Register.
152 #define PWM_CMR3    (*((reg32_t *)(PWMC_BASE + PWM_CMR_OFF + PWM_CH3_OFF))) ///< PWM Channel 3 Mode Register.
153
154 #define PWM_CPRE_MCK            0             ///< PWM Mode prescaler set to MCK.
155 #define PWM_CPRE_MCK_DIV2       1             ///< PWM Mode prescaler set to MCK/2.
156 #define PWM_CPRE_MCK_DIV4       2             ///< PWM Mode prescaler set to MCK/4.
157 #define PWM_CPRE_MCK_DIV8       3             ///< PWM Mode prescaler set to MCK/8.
158 #define PWM_CPRE_MCK_DIV16      4             ///< PWM Mode prescaler set to MCK/16.
159 #define PWM_CPRE_MCK_DIV32      5             ///< PWM Mode prescaler set to MCK/32.
160 #define PWM_CPRE_MCK_DIV64      6             ///< PWM Mode prescaler set to MCK/64.
161 #define PWM_CPRE_MCK_DIV128     7             ///< PWM Mode prescaler set to MCK/128.
162 #define PWM_CPRE_MCK_DIV256     8             ///< PWM Mode prescaler set to MCK/256.
163 #define PWM_CPRE_MCK_DIV512     9             ///< PWM Mode prescaler set to MCK/512.
164 #define PWM_CPRE_MCK_DIV1024    10            ///< PWM Mode prescaler set to MCK/1024.
165 #define PWM_CPRE_CLKA           11            ///< PWM Mode prescaler set to CLKA.
166 #define PWM_CPRE_CLKB           12            ///< PWM Mode prescaler set to CLKB.
167
168 #define PWM_CALG                8             ///< PWM Mode channel alignment.
169 #define PWM_CPOL                9             ///< PWM Mode channel polarity.
170 #define PWM_CPD                 10            ///< PWM Mode channel update period.
171 /*\}*/
172
173
174 /**
175  * PWM Channel Duty Cycle Register.
176  */
177 /*\{*/
178 #define PWM_CDTY_OFF            0x00000004    ///< PWM Channel Duty Cycle Register offset.
179 #define PWM_CDTY0   (*((reg32_t *)(PWMC_BASE + PWM_CDTY_OFF + PWM_CH0_OFF))) ///< PWM Channel 0 Duty Cycle Register.
180 #define PWM_CDTY1   (*((reg32_t *)(PWMC_BASE + PWM_CDTY_OFF + PWM_CH1_OFF))) ///< PWM Channel 1 Duty Cycle Register.
181 #define PWM_CDTY2   (*((reg32_t *)(PWMC_BASE + PWM_CDTY_OFF + PWM_CH2_OFF))) ///< PWM Channel 2 Duty Cycle Register.
182 #define PWM_CDTY3   (*((reg32_t *)(PWMC_BASE + PWM_CDTY_OFF + PWM_CH3_OFF))) ///< PWM Channel 3 Duty Cycle Register.
183 /*\}*/
184
185
186 /**
187  * PWM Channel Period Register.
188  */
189 /*\{*/
190 #define PWM_CPRD_OFF            0x00000008    ///< PWM Channel Period Register offset.
191 #define PWM_CPRD0   (*((reg32_t *)(PWMC_BASE + PWM_CPRD_OFF + PWM_CH0_OFF))) ///< PWM Channel 0 Period Register.
192 #define PWM_CPRD1   (*((reg32_t *)(PWMC_BASE + PWM_CPRD_OFF + PWM_CH1_OFF))) ///< PWM Channel 1 Period Register.
193 #define PWM_CPRD2   (*((reg32_t *)(PWMC_BASE + PWM_CPRD_OFF + PWM_CH2_OFF))) ///< PWM Channel 2 Period Register.
194 #define PWM_CPRD3   (*((reg32_t *)(PWMC_BASE + PWM_CPRD_OFF + PWM_CH3_OFF))) ///< PWM Channel 3 Period Register.
195 /*\}*/
196
197
198 /**
199  * PWM Channel Counter Register.
200  */
201 /*\{*/
202 #define PWM_CCNT_OFF            0x0000000C    ///< PWM Channel Counter Register offset.
203 #define PWM_CCNT0   (*((reg32_t *)(PWMC_BASE + PWM_CCNT_OFF + PWM_CH0_OFF))) ///< PWM Channel 0 Counter Register.
204 #define PWM_CCNT1   (*((reg32_t *)(PWMC_BASE + PWM_CCNT_OFF + PWM_CH1_OFF))) ///< PWM Channel 1 Counter Register.
205 #define PWM_CCNT2   (*((reg32_t *)(PWMC_BASE + PWM_CCNT_OFF + PWM_CH2_OFF))) ///< PWM Channel 2 Counter Register.
206 #define PWM_CCNT3   (*((reg32_t *)(PWMC_BASE + PWM_CCNT_OFF + PWM_CH3_OFF))) ///< PWM Channel 3 Counter Register.
207 /*\}*/
208
209
210 /**
211  * PWM Channel Update Register.
212  */
213 /*\{*/
214 #define PWM_CUPD_OFF            0x00000010    ///< PWM Channel Update Register offset.
215 #define PWM_CUPD0   (*((reg32_t *)(PWMC_BASE + PWM_CUPD_OFF + PWM_CH0_OFF))) ///< PWM Channel 0 Update Register.
216 #define PWM_CUPD1   (*((reg32_t *)(PWMC_BASE + PWM_CUPD_OFF + PWM_CH1_OFF))) ///< PWM Channel 1 Update Register.
217 #define PWM_CUPD2   (*((reg32_t *)(PWMC_BASE + PWM_CUPD_OFF + PWM_CH2_OFF))) ///< PWM Channel 2 Update Register.
218 #define PWM_CUPD3   (*((reg32_t *)(PWMC_BASE + PWM_CUPD_OFF + PWM_CH3_OFF))) ///< PWM Channel 3 Update Register.
219 /*\}*/
220
221 #endif /* AT91_PWM_H */