Remove duplicate define. Put all phy chip specific defines in its
[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 #include "sam3_sysctl.h"
141 #include "sam3_pdc.h"
142 #include "sam3_pmc.h"
143 #include "sam3_dmac.h"
144 #include "sam3_smc.h"
145 #include "sam3_sdramc.h"
146 #include "sam3_ints.h"
147 #include "sam3_pio.h"
148 #include "sam3_nvic.h"
149 #include "sam3_uart.h"
150 #include "sam3_usart.h"
151 #include "sam3_spi.h"
152 #include "sam3_flash.h"
153 #include "sam3_wdt.h"
154 #include "sam3_emac.h"
155 #include "sam3_rstc.h"
156 #include "sam3_adc.h"
157 #include "sam3_dacc.h"
158 #include "sam3_tc.h"
159 #include "sam3_twi.h"
160 #include "sam3_ssc.h"
161 #include "sam3_hsmci.h"
162 #include "sam3_chipid.h"
163
164 /**
165  * U(S)ART I/O pins
166  */
167 /*\{*/
168 #if CPU_CM3_SAM3U
169         #define UART0_PORT   PIOA_BASE
170         #define USART0_PORT  PIOA_BASE
171         #define USART1_PORT  PIOA_BASE
172         #define USART2_PORT  PIOA_BASE
173         #define USART3_PORT  PIOC_BASE
174
175         #define UART0_PERIPH   PIO_PERIPH_A
176         #define USART0_PERIPH  PIO_PERIPH_A
177         #define USART1_PERIPH  PIO_PERIPH_A
178         #define USART2_PERIPH  PIO_PERIPH_A
179         #define USART3_PERIPH  PIO_PERIPH_B
180
181         #define URXD0   11
182         #define UTXD0   12
183         #define RXD0    19
184         #define TXD0    18
185         #define RXD1    21
186         #define TXD1    20
187         #define RXD2    23
188         #define TXD2    22
189         #define RXD3    13
190         #define TXD3    12
191 #elif CPU_CM3_SAM3X
192         #define UART0_PORT   PIOA_BASE
193         #define USART0_PORT  PIOA_BASE
194         #define USART1_PORT  PIOA_BASE
195         #define USART2_PORT  PIOB_BASE
196         #define USART3_PORT  PIOD_BASE
197
198         #define UART0_PERIPH   PIO_PERIPH_A
199         #define USART0_PERIPH  PIO_PERIPH_A
200         #define USART1_PERIPH  PIO_PERIPH_A
201         #define USART2_PERIPH  PIO_PERIPH_A
202         #define USART3_PERIPH  PIO_PERIPH_B
203
204         #define URXD0    8
205         #define UTXD0    9
206         #define RXD0    10
207         #define TXD0    11
208         #define RXD1    12
209         #define TXD1    13
210         #define RXD2    21
211         #define TXD2    20
212         #define RXD3     5
213         #define TXD3     4
214 #elif CPU_CM3_SAM3N || CPU_CM3_SAM3S
215         #define UART0_PORT   PIOA_BASE
216         #define UART1_PORT   PIOB_BASE
217         #define USART0_PORT  PIOA_BASE
218         #define USART1_PORT  PIOA_BASE
219
220         #define UART0_PERIPH   PIO_PERIPH_A
221         #define UART1_PERIPH   PIO_PERIPH_A
222         #define USART0_PERIPH  PIO_PERIPH_A
223         #define USART1_PERIPH  PIO_PERIPH_A
224
225         #define URXD0    9
226         #define UTXD0   10
227         #define URXD1    2
228         #define UTXD1    3
229         #define RXD0     5
230         #define TXD0     6
231         #define RXD1    21
232         #define TXD1    22
233 #endif
234 /*\}*/
235
236 /**
237  * SPI I/O pins
238  */
239 /*\{*/
240 #if CPU_CM3_SAM3U
241         #define SPI0_SPCK   15
242         #define SPI0_MOSI   14
243         #define SPI0_MISO   13
244 #elif CPU_CM3_SAM3X
245         #define SPI0_SPCK   27
246         #define SPI0_MOSI   26
247         #define SPI0_MISO   25
248 #else
249         #define SPI0_SPCK   14
250         #define SPI0_MOSI   13
251         #define SPI0_MISO   12
252 #endif
253 /*\}*/
254
255 /**
256  * TWI I/O pins
257  */
258 /*\{*/
259 #if CPU_CM3_SAM3X
260         #define TWI0_PORT   PIOA_BASE
261         #define TWI1_PORT   PIOA_BASE
262
263         #define TWI0_PERIPH  PIO_PERIPH_A
264         #define TWI1_PERIPH  PIO_PERIPH_A
265
266         #define TWI0_TWD    17
267         #define TWI0_TWCK   18
268         #define TWI1_TWD    12
269         #define TWI1_TWCK   13
270 #elif CPU_CM3_SAM3N || CPU_CM3_SAM3S
271         #define TWI0_PORT   PIOA_BASE
272         #define TWI1_PORT   PIOB_BASE
273
274         #define TWI0_PERIPH  PIO_PERIPH_A
275         #define TWI1_PERIPH  PIO_PERIPH_A
276
277         #define TWI0_TWD    3
278         #define TWI0_TWCK   4
279         #define TWI1_TWD    4
280         #define TWI1_TWCK   5
281 #elif CPU_CM3_SAM3U
282         #define TWI0_PORT   PIOA_BASE
283         #define TWI1_PORT   PIOA_BASE
284
285         #define TWI0_PERIPH  PIO_PERIPH_A
286         #define TWI1_PERIPH  PIO_PERIPH_A
287
288         #define TWI0_TWD    9
289         #define TWI0_TWCK   10
290         #define TWI1_TWD    24
291         #define TWI1_TWCK   25
292 #endif
293
294 #if CPU_CM3_SAM3X
295         #define SSC_PORT            PIOA_BASE
296         #define SSC_PIO_PDR         PIOA_PDR
297         #define SSC_RECV_PERIPH     PIO_PERIPH_A
298         #define SSC_TRAN_PERIPH     PIO_PERIPH_B
299         #define SSC_RD              18
300         #define SSC_RF              17
301         #define SSC_RK              19
302         #define SSC_TD              16
303         #define SSC_TF              15
304         #define SSC_TK              14
305 #elif CPU_CM3_SAM3N
306         #define SSC_PORT            /* None! */
307         #define SSC_PIO_PDR         /* None! */
308         #define SSC_RECV_PERIPH     /* None! */
309         #define SSC_TRAN_PERIPH     /* None! */
310         #define SSC_RD              /* None! */
311         #define SSC_RF              /* None! */
312         #define SSC_RK              /* None! */
313         #define SSC_TD              /* None! */
314         #define SSC_TF              /* None! */
315         #define SSC_TK              /* None! */
316 #elif CPU_CM3_SAM3S
317         #define SSC_PORT            PIOA_BASE
318         #define SSC_PIO_PDR         PIOA_PDR
319         #define SSC_RECV_PERIPH     PIO_PERIPH_A
320         #define SSC_TRAN_PERIPH     PIO_PERIPH_A
321         #define SSC_RD              18
322         #define SSC_RF              20
323         #define SSC_RK              19
324         #define SSC_TD              17
325         #define SSC_TF              15
326         #define SSC_TK              16
327 #elif CPU_CM3_SAM3U
328         #define SSC_PORT            PIOA_BASE
329         #define SSC_PIO_PDR         PIOA_PDR
330         #define SSC_RECV_PERIPH     PIO_PERIPH_A
331         #define SSC_TRAN_PERIPH     PIO_PERIPH_A
332         #define SSC_RD              27
333         #define SSC_RF              31
334         #define SSC_RK              29
335         #define SSC_TD              26
336         #define SSC_TF              30
337         #define SSC_TK              28
338 #else
339         #error no ssc pins are defined for this cpu
340 #endif
341
342
343 #if CPU_CM3_SAM3X8
344         #define FLASH_MEM_SIZE          0x80000UL ///< Internal flash memory size
345         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
346         #define FLASH_BANKS_NUM                 2 ///< Number of flash banks
347         #define FLASH_PAGES_FOR_BANK         1024 ///< Number pages for each bank
348         #define FLASH_BASE                0x80000 ///< Start address for bank 0
349 #elif CPU_CM3_SAM3U4
350         #define FLASH_MEM_SIZE          0x40000UL ///< Internal flash memory size
351         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
352         #define FLASH_BANKS_NUM                 2 ///< Number of flash banks
353         #define FLASH_PAGES_FOR_BANK          512 ///< Number pages for each bank
354         #define FLASH_BASE                0x80000 ///< Start address for bank 0
355 #elif CPU_CM3_SAM3N4 || CPU_CM3_SAM3S4
356         #define FLASH_MEM_SIZE          0x40000UL ///< Internal flash memory size
357         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
358         #define FLASH_BANKS_NUM                 1 ///< Number of flash banks
359         #define FLASH_PAGES_FOR_BANK         1024 ///< Number pages for each bank
360         #define FLASH_BASE               0x400000 ///< Start address for bank 0
361 #else
362         #error no internal flash info are defined for this cpu
363 #endif
364
365
366 #if CPU_CM3_SAM3X8
367         // Port B
368         #define PHY_REFCLK_XT2_BIT      0
369         #define PHY_TXEN_BIT            1
370         #define PHY_TXD0_BIT            2
371         #define PHY_TXD1_BIT            3
372         #define PHY_RXDV_TESTMODE_BIT   4
373         #define PHY_RXD0_AD0_BIT        5
374         #define PHY_RXD1_AD1_BIT        6
375         #define PHY_RXER_RXD4_RPTR_BIT  7
376         #define PHY_MDC_BIT             8
377         #define PHY_MDIO_BIT            9
378         // Port A
379         #define PHY_MDINTR_BIT          5
380 #elif (CPU_CM3_SAM3U || CPU_CM3_SAM3N)
381         /* No ethernet interface is present on this cpu */
382 #else
383         #error No MII/RMII PHY pins interface was define for select CPU.
384 #endif
385
386 #define PHY_MII_PINS_PORTB \
387         BV(PHY_REFCLK_XT2_BIT) \
388         | BV(PHY_TXEN_BIT) \
389         | BV(PHY_TXD0_BIT) \
390         | BV(PHY_TXD1_BIT) \
391         | BV(PHY_RXD0_AD0_BIT) \
392         | BV(PHY_RXD1_AD1_BIT) \
393         | BV(PHY_RXER_RXD4_RPTR_BIT) \
394         | BV(PHY_MDC_BIT) \
395         | BV(PHY_MDIO_BIT)
396
397
398 #endif /* SAM3_H */