6c645dcab9074958f9860044f8770453e9cc9558
[bertos.git] / bertos / cpu / arm / io / at91sam7.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 2007 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  *
34  * \author Francesco Sacchi <batt@develer.com>
35  * \author Daniele Basile <asterix@develer.com>
36  *
37  * AT91SAM7 register definitions.
38  * This file is based on NUT/OS implementation. See license below.
39  */
40
41 /*
42  * Copyright (C) 2006-2007 by egnite Software GmbH. All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  *
48  * 1. Redistributions of source code must retain the above copyright
49  *    notice, this list of conditions and the following disclaimer.
50  * 2. Redistributions in binary form must reproduce the above copyright
51  *    notice, this list of conditions and the following disclaimer in the
52  *    documentation and/or other materials provided with the distribution.
53  * 3. Neither the name of the copyright holders nor the names of
54  *    contributors may be used to endorse or promote products derived
55  *    from this software without specific prior written permission.
56  *
57  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
58  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
60  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
61  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
62  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
63  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
64  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
65  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
66  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
67  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  *
70  * For additional information see http://www.ethernut.de/
71  */
72
73 #ifndef AT91SAM7_H
74 #define AT91SAM7_H
75
76 #include <cfg/compiler.h>
77
78 #if CPU_ARM_SAM7X || CPU_ARM_SAM7S_LARGE
79         #define FLASH_BASE      0x100000UL
80         #define RAM_BASE        0x200000UL
81
82         #define TC_BASE         0xFFFA0000      ///< Timer/counter base address.
83         #define UDP_BASE        0xFFFB0000      ///< USB device port base address.
84         #define TWI_BASE        0xFFFB8000      ///< Two-wire interface base address.
85         #define USART0_BASE     0xFFFC0000      ///< USART 0 base address.
86         #define USART1_BASE     0xFFFC4000      ///< USART 1 base address.
87         #define PWMC_BASE       0xFFFCC000      ///< PWM controller base address.
88         #define SSC_BASE        0xFFFD4000      ///< Serial synchronous controller base address.
89         #define ADC_BASE        0xFFFD8000      ///< ADC base address.
90
91         #define AIC_BASE        0xFFFFF000      ///< AIC base address.
92         #define DBGU_BASE       0xFFFFF200      ///< DBGU base address.
93         #define PIOA_BASE       0xFFFFF400      ///< PIO A base address.
94         #define PMC_BASE        0xFFFFFC00      ///< PMC base address.
95         #define RSTC_BASE       0xFFFFFD00      ///< Resect controller register base address.
96         #define RTT_BASE        0xFFFFFD20      ///< Realtime timer base address.
97         #define PIT_BASE        0xFFFFFD30      ///< Periodic interval timer base address.
98         #define WDT_BASE        0xFFFFFD40      ///< Watch Dog register base address.
99         #define VREG_BASE       0xFFFFFD60      ///< Voltage regulator mode controller base address.
100         #define MC_BASE         0xFFFFFF00      ///< Memory controller base.
101
102         #if CPU_ARM_SAM7X
103                 #define CAN_BASE        0xFFFD0000      ///< PWM controller base address.
104                 #define EMAC_BASE       0xFFFDC000      ///< Ethernet MAC address.
105                 #define SPI0_BASE       0xFFFE0000      ///< SPI0 base address.
106                 #define SPI1_BASE       0xFFFE4000      ///< SPI1 base address.
107                 #define PIOB_BASE       0xFFFFF600      ///< PIO base address.
108         #endif
109
110         #if CPU_ARM_SAM7S_LARGE
111                 #define SPI_BASE        0xFFFE0000      ///< SPI0 base address.
112         #endif
113
114         #define PIO_HAS_MULTIDRIVER        1
115         #define PIO_HAS_PULLUP             1
116         #define PIO_HAS_PERIPHERALSELECT   1
117         #define PIO_HAS_OUTPUTWRITEENABLE  1
118
119         #define DBGU_HAS_PDC               1
120         #define SPI_HAS_PDC                1
121         #define SSC_HAS_PDC                1
122         #define USART_HAS_PDC              1
123
124         /* PDC registers */
125         #define PERIPH_RPR_OFF  0x100  ///< Receive Pointer Register.
126         #define PERIPH_RCR_OFF  0x104  ///< Receive Counter Register.
127         #define PERIPH_TPR_OFF  0x108  ///< Transmit Pointer Register.
128         #define PERIPH_TCR_OFF  0x10C  ///< Transmit Counter Register.
129         #define PERIPH_RNPR_OFF 0x110  ///< Receive Next Pointer Register.
130         #define PERIPH_RNCR_OFF 0x114  ///< Receive Next Counter Register.
131         #define PERIPH_TNPR_OFF 0x118  ///< Transmit Next Pointer Register.
132         #define PERIPH_TNCR_OFF 0x11C  ///< Transmit Next Counter Register.
133         #define PERIPH_PTCR_OFF 0x120  ///< PDC Transfer Control Register.
134         #define PERIPH_PTSR_OFF 0x124  ///< PDC Transfer Status Register.
135
136         #define PDC_RXTEN  0
137         #define PDC_RXTDIS 1
138         #define PDC_TXTEN  8
139         #define PDC_TXTDIS 9
140
141 #else
142         #error No base address register definition for selected ARM CPU
143
144 #endif
145
146 #if CPU_ARM_AT91SAM7S64
147         #define FLASH_MEM_SIZE          0x10000UL ///< Internal flash memory size
148         #define FLASH_PAGE_SIZE_BYTES         128 ///< Size of cpu flash memory page in bytes
149         #define FLASH_BANKS_NUM                 1 ///< Number of flash banks
150         #define FLASH_SECTORS_NUM              16 ///< Number of flash sector
151         #define FLASH_PAGE_PER_SECTOR          32 ///< Number of page for sector
152
153 #elif CPU_ARM_AT91SAM7S128 || CPU_ARM_AT91SAM7X128
154         #define FLASH_MEM_SIZE          0x20000UL ///< Internal flash memory size
155         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
156         #define FLASH_BANKS_NUM                 1 ///< Number of flash banks
157         #define FLASH_SECTORS_NUM               8 ///< Number of flash sector
158         #define FLASH_PAGE_PER_SECTOR          64 ///< Number of page for sector
159
160 #elif CPU_ARM_AT91SAM7S256 || CPU_ARM_AT91SAM7X256
161         #define FLASH_MEM_SIZE          0x40000UL ///< Internal flash memory size
162         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
163         #define FLASH_BANKS_NUM                 1 ///< Number of flash banks
164         #define FLASH_SECTORS_NUM              16 ///< Number of flash sector
165         #define FLASH_PAGE_PER_SECTOR          64 ///< Number of page for sector
166
167 #elif CPU_ARM_AT91SAM7S512 || CPU_ARM_AT91SAM7X512
168         #define FLASH_MEM_SIZE          0x80000UL ///< Internal flash memory size
169         #define FLASH_PAGE_SIZE_BYTES         256 ///< Size of cpu flash memory page in bytes
170         #define FLASH_BANKS_NUM                 2 ///< Number of flash banks
171         #define FLASH_SECTORS_NUM              32 ///< Number of flash sector
172         #define FLASH_PAGE_PER_SECTOR          64 ///< Number of page for sector
173
174 #else
175         #error Memory size definition for selected ARM CPU
176 #endif
177
178 #include "at91_aic.h"
179 #include "at91_pit.h"
180 #include "at91_pmc.h"
181 #include "at91_mc.h"
182 #include "at91_wdt.h"
183 #include "at91_rstc.h"
184 #include "at91_pio.h"
185 #include "at91_us.h"
186 #include "at91_dbgu.h"
187 #include "at91_tc.h"
188 #include "at91_adc.h"
189 #include "at91_pwm.h"
190 #include "at91_spi.h"
191 #include "at91_twi.h"
192 #include "at91_ssc.h"
193 #include "at91_emac.h"
194 //TODO: add other peripherals
195
196 /**
197  * Peripheral Identifiers and Interrupts
198  *\{
199  */
200 #if CPU_ARM_SAM7X || CPU_ARM_SAM7S_LARGE
201         #define FIQ_ID      0       ///< Fast interrupt ID.
202         #define SYSC_ID     1       ///< System controller interrupt.
203         #define US0_ID      6       ///< USART 0 ID.
204         #define US1_ID      7       ///< USART 1 ID.
205         #define SSC_ID      8       ///< Synchronous serial controller ID.
206         #define TWI_ID      9       ///< Two-wire interface ID.
207         #define PWMC_ID     10      ///< PWM controller ID.
208         #define UDP_ID      11      ///< USB device port ID.
209         #define TC0_ID      12      ///< Timer 0 ID.
210         #define TC1_ID      13      ///< Timer 1 ID.
211         #define TC2_ID      14      ///< Timer 2 ID.
212
213         #define IRQ0_ID     30      ///< External interrupt 0 ID.
214         #define IRQ1_ID     31      ///< External interrupt 1 ID.
215
216         #if CPU_ARM_SAM7X
217                 #define PIOA_ID     2       ///< Parallel A I/O controller ID.
218                 #define PIOB_ID     3       ///< Parallel B I/O controller ID.
219                 #define SPI0_ID     4       ///< Serial peripheral interface 0 ID.
220                 #define SPI1_ID     5       ///< Serial peripheral interface 1 ID.
221                 #define CAN_ID      15      ///< CAN controller ID.
222                 #define EMAC_ID     16      ///< Ethernet MAC ID.
223                 #define ADC_ID      17      ///< Analog to digital converter ID.
224                 /* 18-29 Reserved */
225
226         #endif
227
228         #if CPU_ARM_SAM7S_LARGE
229                 #define PIOA_ID     2       ///< Parallel I/O controller ID.
230                 /* ID 3 is reserved */
231                 #define ADC_ID      4       ///< Analog to digital converter ID.
232                 #define SPI_ID      5       ///< Serial peripheral interface ID.
233                 #define SPI0_ID     SPI_ID  ///< Alias
234         #endif
235
236 #else
237         #error No peripheral ID and interrupts definition for selected ARM CPU
238
239 #endif
240 /*\}*/
241
242 /**
243  * USART & DEBUG pin names
244  *\{
245  */
246 #if CPU_ARM_SAM7S_LARGE
247         #define RXD0        5
248         #define TXD0        6
249         #define RXD1       21
250         #define TXD1       22
251         #define DTXD       10
252         #define DRXD        9
253 #elif CPU_ARM_SAM7X
254         #define RXD0        0 // PA0
255         #define TXD0        1 // PA1
256         #define RXD1        5 // PA5
257         #define TXD1        6 // PA6
258         #define DTXD       28 // PA28
259         #define DRXD       27 // PA27
260 #else
261         #error No USART & debug pin names definition for selected ARM CPU
262 #endif
263 /*\}*/
264
265 /**
266  * SPI pins name
267  *\{
268  */
269 #if CPU_ARM_SAM7S_LARGE
270         #define SPI0_NPCS0      11  // Same as NSS pin.
271         #define SPI0_MISO       12
272         #define SPI0_MOSI       13
273         #define SPI0_SPCK       14
274
275 #elif CPU_ARM_SAM7X
276         #define SPI0_NPCS0  12 // Same as NSS pin. PA12
277         #define SPI0_NPCS1  13 // PA13
278         #define SPI0_NPCS2  14 // PA14
279         #define SPI0_NPCS3  15 // PA15
280         #define SPI0_MISO   16 // PA16
281         #define SPI0_MOSI   17 // PA17
282         #define SPI0_SPCK   18 // PA18
283
284         #define SPI1_NPCS0  21 // Same as NSS pin. PA21
285         #define SPI1_NPCS1  25 // PA25
286         #define SPI1_NPCS2  26 // PA26
287         #define SPI1_NPCS3  29 // PA29
288         #define SPI1_MISO   24 // PA24
289         #define SPI1_MOSI   23 // PA23
290         #define SPI1_SPCK   22 // PA22
291
292 #else
293         #error No SPI pins name definition for selected ARM CPU
294
295 #endif
296 /*\}*/
297
298 /**
299  * SSC pins name
300  *\{
301  */
302 #if CPU_ARM_SAM7S_LARGE
303
304         #define SSC_TF     15 // PA15
305         #define SSC_TK     16 // PA16
306         #define SSC_TD     17 // PA17
307         #define SSC_RD     18 // PA18
308         #define SSC_RK     19 // PA19
309         #define SSC_RF     20 // PA20
310
311 #elif CPU_ARM_SAM7X
312
313         #define SSC_TF     21 // PA21
314         #define SSC_TK     22 // PA22
315         #define SSC_TD     23 // PA23
316         #define SSC_RD     24 // PA24
317         #define SSC_RK     25 // PA25
318         #define SSC_RF     26 // PA26
319
320 #else
321         #error No SSC pins name definition for selected ARM CPU
322
323 #endif
324 /*\}*/
325
326 /**
327  * Timer counter pins definition.
328  *\{
329  */
330 #if CPU_ARM_SAM7X
331         #define TIOA0  23 // PB23
332         #define TIOB0  24 // PB24
333         #define TIOA1  25 // PB25
334         #define TIOB1  26 // PB26
335         #define TIOA2  27 // PB27
336         #define TIOB2  28 // PB28
337
338         #define TIO_PIO_PDR     PIOB_PDR
339         #define TIO_PIO_ABSR    PIOB_ASR
340
341 #elif CPU_ARM_SAM7S_LARGE
342         #define TIOA0  0 // PA0
343         #define TIOB0  1 // PA1
344         #define TIOA1  15 // PA15
345         #define TIOB1  16 // PA16
346         #define TIOA2  26 // PA26
347         #define TIOB2  27 // PA27
348
349         #define TIO_PIO_PDR     PIOA_PDR
350         #define TIO_PIO_ABSR    PIOA_BSR
351
352 #else
353         #error No Timer Counter names of pins definition for selected ARM CPU
354
355 #endif
356 /*\}*/
357
358
359 /**
360  * PWM pins definition.
361  *\{
362  */
363 #if CPU_ARM_SAM7X
364         #define PWM0  19 // PB19
365         #define PWM1  20 // PB20
366         #define PWM2  21 // PB21
367         #define PWM3  22 // PB22
368
369         #define PWM_PIO_PDR     PIOB_PDR
370         #define PWM_PIO_PER     PIOB_PER
371         #define PWM_PIO_CODR    PIOB_CODR
372         #define PWM_PIO_SODR    PIOB_SODR
373         #define PWM_PIO_OER     PIOB_OER
374         #define PWM_PIO_ABSR    PIOB_ASR
375
376 #elif CPU_ARM_SAM7S_LARGE
377         #define PWM0  11 // PA11
378         #define PWM1  12 // PA12
379         #define PWM2  13 // PA13
380         #define PWM3  14 // PA14
381
382         #define PWM_PIO_PDR     PIOA_PDR
383         #define PWM_PIO_PER     PIOA_PER
384         #define PWM_PIO_CODR    PIOA_CODR
385         #define PWM_PIO_SODR    PIOA_SODR
386         #define PWM_PIO_OER     PIOA_OER
387         #define PWM_PIO_ABSR    PIOA_BSR
388
389 #else
390         #error No PWM names of pins definition for selected ARM CPU
391
392 #endif
393 /*\}*/
394
395 /**
396  * TWI pins definition.
397  *\{
398  */
399 #if CPU_ARM_SAM7X
400         #define TWD  10
401         #define TWCK 11
402
403 #elif CPU_ARM_SAM7S_LARGE
404         #define TWD  3    //PA3
405         #define TWCK 4    //PA4
406
407 #else
408         #error No TWI names of pins definition for selected ARM CPU
409 #endif
410
411 /**
412  * ADC pins definition.
413  *\{
414  */
415 #if CPU_ARM_SAM7X
416         #define ADTRG   18 // PB18
417         #define AD0     23 // PB27
418         #define AD1     24 // PB28
419         #define AD2     25 // PB29
420         #define AD3     26 // PB30
421
422 #elif CPU_ARM_SAM7S_LARGE
423         #define ADTRG   18 // PA8
424         #define AD0      0 // PA17
425         #define AD1      1 // PA18
426         #define AD2     15 // PA19
427         #define AD3     16 // PA20
428
429 #else
430         #error No ADC names of pins definition for selected ARM CPU
431
432 #endif
433 /*\}*/
434
435
436 /**
437  * Pin definition MII/RMII PHY interdace
438  */
439 #if CPU_ARM_SAM7X
440         #define PHY_TXCLK_BIT      BV(0)
441         #define PHY_TXEN_BIT       BV(1)
442         #define PHY_TXD0_BIT       BV(2)
443         #define PHY_TXD1_BIT       BV(3)
444         #define PHY_CRS_BIT        BV(4)
445         #define PHY_RXD0_BIT       BV(5)
446         #define PHY_RXD1_BIT       BV(6)
447         #define PHY_RXER_BIT       BV(7)
448         #define PHY_MDC_BIT        BV(8)
449         #define PHY_MDIO_BIT       BV(9)
450         #define PHY_TXD2_BIT       BV(10)
451         #define PHY_TXD3_BIT       BV(11)
452         #define PHY_TXER_BIT       BV(12)
453         #define PHY_RXD2_BIT       BV(13)
454         #define PHY_RXD3_BIT       BV(14)
455         #define PHY_RXDV_BIT       BV(15)
456         #define PHY_COL_BIT        BV(16)
457         #define PHY_RXCLK_BIT      BV(17)
458
459 #elif CPU_ARM_SAM7S_LARGE
460         /* No ethernet interface is present on this cpu */
461 #else
462         #error No MII/RMII PHY pins interface was define for select CPU.
463 #endif
464
465 #define PHY_MII_PINS   \
466         ( PHY_TXEN_BIT \
467         | PHY_TXD0_BIT \
468         | PHY_TXD1_BIT \
469         | PHY_CRS_BIT \
470         | PHY_RXD0_BIT \
471         | PHY_RXD1_BIT \
472         | PHY_RXER_BIT \
473         | PHY_MDC_BIT \
474         | PHY_MDIO_BIT \
475         | PHY_TXD2_BIT \
476         | PHY_TXD3_BIT \
477         | PHY_TXER_BIT \
478         | PHY_RXD2_BIT \
479         | PHY_RXD3_BIT \
480         | PHY_RXDV_BIT \
481         | PHY_COL_BIT \
482         | PHY_RXCLK_BIT)
483 // \}
484
485 #endif /* AT91SAM7_H */