source: rtems/c/src/lib/libbsp/arm/csb337/startup/bspstart.c @ c193baad

4.104.11
Last change on this file since c193baad was c193baad, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Apr 9, 2010 at 8:24:57 PM

unify irq data types and code, merge s3c2400/s3c2410 support

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Cogent CSB337 - AT91RM9200 Startup Code
3 *
4 *  Copyright (c) 2004 by Cogent Computer Systems
5 *  Written by Jay Monkman <jtm@lopingdog.com>
6 *
7 *  Modified by Joel Sherill
8 *  from OAR Corporation and
9 *  Fernando Nicodemos <fgnicodemos@terra.com.br>
10 *  from NCB - Sistemas Embarcados Ltda. (Brazil)
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#include <bsp.h>
20#include <at91rm9200.h>
21#include <at91rm9200_pmc.h>
22#include <at91rm9200_emac.h>
23#include <at91rm9200_gpio.h>
24#include <at91rm9200_usart.h>
25
26/* Function prototypes */
27extern void rtems_irq_mngt_init(void);
28extern void rtems_exception_init_mngt(void);
29void bsp_libc_init( void *, uint32_t, int );
30static void fix_mac_addr(void);
31void bsp_usart_init(void);
32
33/*
34 * bsp_start_default - BSP initialization function
35 *
36 * This function is called before RTEMS is initialized and used
37 * adjust the kernel's configuration.
38 *
39 * This function also configures the CPU's memory protection unit.
40 *
41 * RESTRICTIONS/LIMITATIONS:
42 *   Since RTEMS is not configured, no RTEMS functions can be called.
43 */
44void bsp_start_default( void )
45{
46  /* disable interrupts */
47  AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
48
49  /*
50   * Some versions of the bootloader have the MAC address
51   * reversed. This fixes it, if necessary.
52   */
53  fix_mac_addr();
54
55  /*
56   * Init rtems PIO configuration for USARTs
57   */
58  bsp_usart_init(); 
59
60  /*
61   * Init rtems exceptions management
62   */
63  rtems_exception_init_mngt();
64
65  /*
66   * Init rtems interrupt management
67   */
68  rtems_irq_mngt_init();
69
70} /* bsp_start */
71
72/*
73 * Some versions of the bootloader shipped with the CSB337
74 * reverse the MAC address. This function tests for that,
75 * and fixes the MAC address.
76 */
77static void fix_mac_addr(void)
78{
79  uint8_t addr[6];
80
81  /* Read the MAC address */
82  addr[0] = (EMAC_REG(EMAC_SA1L) >>  0) & 0xff;
83  addr[1] = (EMAC_REG(EMAC_SA1L) >>  8) & 0xff;
84  addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff;
85  addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff;
86  addr[4] = (EMAC_REG(EMAC_SA1H) >>  0) & 0xff;
87  addr[5] = (EMAC_REG(EMAC_SA1H) >>  8) & 0xff;
88
89  /* Check which 3 bytes have Cogent's OUI */
90  if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) {
91      EMAC_REG(EMAC_SA1L) = ((addr[5] <<  0) |
92                             (addr[4] <<  8) |
93                             (addr[3] << 16) |
94                             (addr[2] << 24));
95
96      EMAC_REG(EMAC_SA1H) = ((addr[1] <<  0) |
97                             (addr[0] <<  8));
98  }
99}
100
101/*
102 *
103 * NAME: bsp_usart_init - Function to setup the PIO in USART mode
104 *       before startup
105 *
106 * DESCRIPTION:
107 *   This function is called before usart driver is initialized and is
108 *   used to setup the proper mode of PIO operation for USART.
109 *
110 * NOTES:
111 *   The initialization could be done smarter by programming only the
112 *   bits you need to program for each USART when the port is ENABLED.
113 *
114 */
115void bsp_usart_init(void)
116{
117  /*
118   * Configure shared pins for USARTs.
119   * Disables the PIO from controlling the corresponding pin.
120   */
121  PIOA_REG(PIO_PDR) |= ( BIT5  |   /* USART3 TXD3  */
122                         BIT6  |   /* USART3 RXD3  */
123                         BIT17 |   /* USART0 TXD0  */
124                         BIT18 |   /* USART0 RXD0  */
125                         BIT22 |   /* USART2 RXD2  */
126                         BIT23 );  /* USART2 TXD2  */
127
128  PIOB_REG(PIO_PDR) |= ( BIT20 |   /* USART1 TXD1  */
129                         BIT21 );  /* USART1 RXD1  */
130
131  /**** PIO Controller A - Pins you want in mode B ****/
132  PIOA_REG(PIO_BSR) |=  ( BIT5 |   /* USART3 TXD3  */ /* add */
133                          BIT6 );  /* USART3 RXD3  */ 
134  PIOA_REG(PIO_ASR) &= ~( BIT5 |   /* USART3 TXD3  */
135                          BIT6 );  /* USART3 RXD3  */
136
137  /**** PIO Controller A - Pins you want in mode A ****/
138  PIOA_REG(PIO_ASR) |=  ( BIT17 |   /* USART0 TXD0  */
139                          BIT18 |   /* USART0 RXD0  */
140                          BIT22 |   /* USART2 RXD2  */
141                          BIT23 );  /* USART2 TXD2  */
142  PIOA_REG(PIO_BSR) &= ~( BIT17 |   /* USART0 TXD0  */ /* add */
143                          BIT18 |   /* USART0 RXD0  */
144                          BIT22 |   /* USART2 RXD2  */
145                          BIT23 );  /* USART2 TXD2  */
146
147  /**** PIO Controller B - Pins you want in mode A ****/
148  PIOB_REG(PIO_ASR) |=  ( BIT20 |   /* USART1 TXD1  */
149                          BIT21 );  /* USART1 RXD1  */
150  PIOB_REG(PIO_BSR) &= ~( BIT20 |   /* USART1 TXD1  */
151                          BIT21 );  /* USART1 RXD1  */
152
153  /**** PIO Controller B - Pins you want in mode B ****/
154  /**** none ****/
155
156  /* Enable the clock to the USARTs */
157  PMC_REG(PMC_PCER) |= ( PMC_PCR_PID_US0 |   /* USART 0 Peripheral Clock */
158                         PMC_PCR_PID_US1 |   /* USART 1 Peripheral Clock */
159                         PMC_PCR_PID_US2 |   /* USART 2 Peripheral Clock */ 
160                         PMC_PCR_PID_US3 );  /* USART 3 Peripheral Clock */
161} 
162
163/*
164 *  By making this a weak alias for bsp_start_default, a brave soul
165 *  can override the actual bsp_start routine used.
166 */
167void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.