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

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • 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
17#include <bsp.h>
18#include <bsp/irq-generic.h>
19#include <at91rm9200.h>
20#include <at91rm9200_pmc.h>
21#include <at91rm9200_emac.h>
22#include <at91rm9200_gpio.h>
23#include <at91rm9200_usart.h>
24
25/* Function prototypes */
26extern void rtems_exception_init_mngt(void);
27void bsp_libc_init( void *, uint32_t, int );
28static void fix_mac_addr(void);
29void bsp_usart_init(void);
30
31/*
32 * bsp_start_default - BSP initialization function
33 *
34 * This function is called before RTEMS is initialized and used
35 * adjust the kernel's configuration.
36 *
37 * This function also configures the CPU's memory protection unit.
38 *
39 * RESTRICTIONS/LIMITATIONS:
40 *   Since RTEMS is not configured, no RTEMS functions can be called.
41 */
42void bsp_start_default( void )
43{
44  /* disable interrupts */
45  AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
46
47  /*
48   * Some versions of the bootloader have the MAC address
49   * reversed. This fixes it, if necessary.
50   */
51  fix_mac_addr();
52
53  /*
54   * Init rtems PIO configuration for USARTs
55   */
56  bsp_usart_init();
57
58  /*
59   * Init rtems exceptions management
60   */
61  rtems_exception_init_mngt();
62
63  /*
64   * Init rtems interrupt management
65   */
66  if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
67    _CPU_Fatal_halt(0xe);
68  }
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.