sam3: add twi definitions for SAM3N, SAM3S and SAM3U
[bertos.git] / bertos / cpu / cortex-m3 / io / sam3.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 2010,2011 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Stefano Fedrigo <aleph@develer.com>
34  */
35
36 #ifndef SAM3_H
37 #define SAM3_H
38
39 #include <cpu/detect.h>
40 #include <cfg/compiler.h>
41
42 /*
43  * Peripherals IDs.
44  */
45 /*\{*/
46 #if CPU_CM3_SAM3N
47         #define SUPC_ID      0   ///< Supply Controller (SUPC)
48         #define RSTC_ID      1   ///< Reset Controller (RSTC)
49         #define RTC_ID       2   ///< Real Time Clock (RTC)
50         #define RTT_ID       3   ///< Real Time Timer (RTT)
51         #define WDT_ID       4   ///< Watchdog Timer (WDT)
52         #define PMC_ID       5   ///< Power Management Controller (PMC)
53         #define EEFC0_ID     6   ///< Enhanced Flash Controller
54         #define UART0_ID     8   ///< UART 0 (UART0)
55         #define UART1_ID     9   ///< UART 1 (UART1)
56         #define PIOA_ID     11   ///< Parallel I/O Controller A (PIOA)
57         #define PIOB_ID     12   ///< Parallel I/O Controller B (PIOB)
58         #define PIOC_ID     13   ///< Parallel I/O Controller C (PIOC)
59         #define US0_ID      14   ///< USART 0 (USART0)
60         #define US1_ID      15   ///< USART 1 (USART1)
61         #define TWI0_ID     19   ///< Two Wire Interface 0 (TWI0)
62         #define TWI1_ID     20   ///< Two Wire Interface 1 (TWI1)
63         #define SPI0_ID     21   ///< Serial Peripheral Interface (SPI)
64         #define TC0_ID      23   ///< Timer/Counter 0 (TC0)
65         #define TC1_ID      24   ///< Timer/Counter 1 (TC1)
66         #define TC2_ID      25   ///< Timer/Counter 2 (TC2)
67         #define TC3_ID      26   ///< Timer/Counter 3 (TC3)
68         #define TC4_ID      27   ///< Timer/Counter 4 (TC4)
69         #define TC5_ID      28   ///< Timer/Counter 5 (TC5)
70         #define ADC_ID      29   ///< Analog To Digital Converter (ADC)
71         #define DACC_ID     30   ///< Digital To Analog Converter (DACC)
72         #define PWM_ID      31   ///< Pulse Width Modulation (PWM)
73 #elif CPU_CM3_SAM3X
74         #define SUPC_ID        0   ///< Supply Controller (SUPC)
75         #define RSTC_ID        1   ///< Reset Controller (RSTC)
76         #define RTC_ID         2   ///< Real Time Clock (RTC)
77         #define RTT_ID         3   ///< Real Time Timer (RTT)
78         #define WDT_ID         4   ///< Watchdog Timer (WDT)
79         #define PMC_ID         5   ///< Power Management Controller (PMC)
80         #define EEFC0_ID       6   ///< Enhanced Flash Controller
81         #define EEFC1_ID       7   ///< Enhanced Flash Controller
82         #define UART0_ID       8   ///< UART 0 (UART0)
83         #define SMC_SDRAMC_ID  9   ///< Satic memory controller / SDRAM controller
84         #define SDRAMC_ID     10   ///< Satic memory controller / SDRAM controller
85         #define PIOA_ID       11   ///< Parallel I/O Controller A
86         #define PIOB_ID       12   ///< Parallel I/O Controller B
87         #define PIOC_ID       13   ///< Parallel I/O Controller C
88         #define PIOD_ID       14   ///< Parallel I/O Controller D
89         #define PIOE_ID       15   ///< Parallel I/O Controller E
90         #define PIOF_ID       16   ///< Parallel I/O Controller F
91         #define US0_ID        17   ///< USART 0
92         #define US1_ID        18   ///< USART 1
93         #define US2_ID        19   ///< USART 2
94         #define US3_ID        20   ///< USART 3
95         #define HSMCI_ID      21   ///< High speed multimedia card interface
96         #define TWI0_ID       22   ///< Two Wire Interface 0
97         #define TWI1_ID       23   ///< Two Wire Interface 1
98         #define SPI0_ID       24   ///< Serial Peripheral Interface
99         #define SPI1_ID       25   ///< Serial Peripheral Interface
100         #define SSC_ID        26   ///< Synchronous serial controller
101         #define TC0_ID        27   ///< Timer/Counter 0
102         #define TC1_ID        28   ///< Timer/Counter 1
103         #define TC2_ID        29   ///< Timer/Counter 2
104         #define TC3_ID        30   ///< Timer/Counter 3
105         #define TC4_ID        31   ///< Timer/Counter 4
106         #define TC5_ID        32   ///< Timer/Counter 5
107         #define TC6_ID        33   ///< Timer/Counter 6
108         #define TC7_ID        34   ///< Timer/Counter 7
109         #define TC8_ID        35   ///< Timer/Counter 8
110         #define PWM_ID        36   ///< Pulse width modulation controller
111         #define ADC_ID        37   ///< ADC controller
112         #define DACC_ID       38   ///< DAC controller
113         #define DMAC_ID       39   ///< DMA controller
114         #define UOTGHS_ID     40   ///< USB OTG high speed
115         #define TRNG_ID       41   ///< True random number generator
116         #define EMAC_ID       42   ///< Ethernet MAC
117     #define CAN0_ID       43   ///< CAN controller 0
118     #define CAN1_ID       44   ///< CAN controller 1
119 #else
120         #error Peripheral IDs undefined
121 #endif
122 /*\}*/
123
124 /*
125  * Hardware features for drivers.
126  */
127 #define USART_HAS_PDC  1
128 #define SPI_HAS_PDC    1
129
130 #if CPU_CM3_SAM3X || CPU_CM3_SAM3U
131         #define USART_PORTS    1
132         #define UART_PORTS     4
133 #elif CPU_CM3_SAM3N || CPU_CM3_SAM3S
134         #define USART_PORTS    2
135         #define UART_PORTS     2
136 #else
137         #error undefined U(S)ART_PORTS for this cpu
138 #endif
139
140 /* PDC registers */
141 #define PERIPH_RPR_OFF  0x100  // Receive Pointer Register.
142 #define PERIPH_RCR_OFF  0x104  // Receive Counter Register.
143 #define PERIPH_TPR_OFF  0x108  // Transmit Pointer Register.
144 #define PERIPH_TCR_OFF  0x10C  // Transmit Counter Register.
145 #define PERIPH_RNPR_OFF 0x110  // Receive Next Pointer Register.
146 #define PERIPH_RNCR_OFF 0x114  // Receive Next Counter Register.
147 #define PERIPH_TNPR_OFF 0x118  // Transmit Next Pointer Register.
148 #define PERIPH_TNCR_OFF 0x11C  // Transmit Next Counter Register.
149 #define PERIPH_PTCR_OFF 0x120  // PDC Transfer Control Register.
150 #define PERIPH_PTSR_OFF 0x124  // PDC Transfer Status Register.
151
152 #define PDC_RXTEN  0
153 #define PDC_RXTDIS 1
154 #define PDC_TXTEN  8
155 #define PDC_TXTDIS 9
156
157
158 #include "sam3_sysctl.h"
159 #include "sam3_pmc.h"
160 #include "sam3_smc.h"
161 #include "sam3_sdramc.h"
162 #include "sam3_ints.h"
163 #include "sam3_pio.h"
164 #include "sam3_nvic.h"
165 #include "sam3_uart.h"
166 #include "sam3_usart.h"
167 #include "sam3_spi.h"
168 #include "sam3_flash.h"
169 #include "sam3_wdt.h"
170 #include "sam3_emac.h"
171 #include "sam3_rstc.h"
172 #include "sam3_adc.h"
173 #include "sam3_dacc.h"
174 #include "sam3_tc.h"
175 #include "sam3_twi.h"
176
177 /**
178  * U(S)ART I/O pins
179  */
180 /*\{*/
181 #if CPU_CM3_SAM3U
182         #define UART0_PORT   PIOA_BASE
183         #define USART0_PORT  PIOA_BASE
184         #define USART1_PORT  PIOA_BASE
185         #define USART2_PORT  PIOA_BASE
186         #define USART3_PORT  PIOC_BASE
187
188         #define UART0_PERIPH   PIO_PERIPH_A
189         #define USART0_PERIPH  PIO_PERIPH_A
190         #define USART1_PERIPH  PIO_PERIPH_A
191         #define USART2_PERIPH  PIO_PERIPH_A
192         #define USART3_PERIPH  PIO_PERIPH_B
193
194         #define URXD0   11
195         #define UTXD0   12
196         #define RXD0    19
197         #define TXD0    18
198         #define RXD1    21
199         #define TXD1    20
200         #define RXD2    23
201         #define TXD2    22
202         #define RXD3    13
203         #define TXD3    12
204 #elif CPU_CM3_SAM3X
205         #define UART0_PORT   PIOA_BASE
206         #define USART0_PORT  PIOA_BASE
207         #define USART1_PORT  PIOA_BASE
208         #define USART2_PORT  PIOB_BASE
209         #define USART3_PORT  PIOD_BASE
210
211         #define UART0_PERIPH   PIO_PERIPH_A
212         #define USART0_PERIPH  PIO_PERIPH_A
213         #define USART1_PERIPH  PIO_PERIPH_A
214         #define USART2_PERIPH  PIO_PERIPH_A
215         #define USART3_PERIPH  PIO_PERIPH_B
216
217         #define URXD0    8
218         #define UTXD0    9
219         #define RXD0    10
220         #define TXD0    11
221         #define RXD1    12
222         #define TXD1    13
223         #define RXD2    21
224         #define TXD2    20
225         #define RXD3     5
226         #define TXD3     4
227 #elif CPU_CM3_SAM3N || CPU_CM3_SAM3S
228         #define UART0_PORT   PIOA_BASE
229         #define UART1_PORT   PIOB_BASE
230         #define USART0_PORT  PIOA_BASE
231         #define USART1_PORT  PIOA_BASE
232
233         #define UART0_PERIPH   PIO_PERIPH_A
234         #define UART1_PERIPH   PIO_PERIPH_A
235         #define USART0_PERIPH  PIO_PERIPH_A
236         #define USART1_PERIPH  PIO_PERIPH_A
237
238         #define URXD0    9
239         #define UTXD0   10
240         #define URXD1    2
241         #define UTXD1    3
242         #define RXD0     5
243         #define TXD0     6
244         #define RXD1    21
245         #define TXD1    22
246 #endif
247 /*\}*/
248
249 /**
250  * SPI I/O pins
251  */
252 /*\{*/
253 #if CPU_CM3_SAM3U
254         #define SPI0_SPCK   15
255         #define SPI0_MOSI   14
256         #define SPI0_MISO   13
257 #elif CPU_CM3_SAM3X
258         #define SPI0_SPCK   27
259         #define SPI0_MOSI   26
260         #define SPI0_MISO   25
261 #else
262         #define SPI0_SPCK   14
263         #define SPI0_MOSI   13
264         #define SPI0_MISO   12
265 #endif
266 /*\}*/
267
268 /**
269  * TWI I/O pins
270  */
271 /*\{*/
272 #if CPU_CM3_SAM3X
273         #define TWI0_PORT   PIOA_BASE
274         #define TWI1_PORT   PIOA_BASE
275
276         #define TWI0_PERIPH  PIO_PERIPH_A
277         #define TWI1_PERIPH  PIO_PERIPH_A
278
279         #define TWI0_TWD    17
280         #define TWI0_TWCK   18
281         #define TWI1_TWD    12
282         #define TWI1_TWCK   13
283 #elif CPU_CM3_SAM3N || CPU_CM3_SAM3S
284         #define TWI0_PORT   PIOA_BASE
285         #define TWI1_PORT   PIOB_BASE
286
287         #define TWI0_PERIPH  PIO_PERIPH_A
288         #define TWI1_PERIPH  PIO_PERIPH_A
289
290         #define TWI0_TWD    3
291         #define TWI0_TWCK   4
292         #define TWI1_TWD    4
293         #define TWI1_TWCK   5
294 #elif CPU_CM3_SAM3U
295         #define TWI0_PORT   PIOA_BASE
296         #define TWI1_PORT   PIOA_BASE
297
298         #define TWI0_PERIPH  PIO_PERIPH_A
299         #define TWI1_PERIPH  PIO_PERIPH_A
300
301         #define TWI0_TWD    9
302         #define TWI0_TWCK   10
303         #define TWI1_TWD    24
304         #define TWI1_TWCK   25
305 #endif
306
307 /*\}*/
308 #endif /* SAM3_H */