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

4.11
Last change on this file since f7513a0 was f7513a0, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 9, 2012 at 2:45:12 PM

bsps: Remove unused bsp_libc_init() prototype

  • 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);
27static void fix_mac_addr(void);
28void bsp_usart_init(void);
29
30/*
31 * bsp_start_default - BSP initialization function
32 *
33 * This function is called before RTEMS is initialized and used
34 * adjust the kernel's configuration.
35 *
36 * This function also configures the CPU's memory protection unit.
37 *
38 * RESTRICTIONS/LIMITATIONS:
39 *   Since RTEMS is not configured, no RTEMS functions can be called.
40 */
41void bsp_start_default( void )
42{
43  /* disable interrupts */
44  AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
45
46  /*
47   * Some versions of the bootloader have the MAC address
48   * reversed. This fixes it, if necessary.
49   */
50  fix_mac_addr();
51
52  /*
53   * Init rtems PIO configuration for USARTs
54   */
55  bsp_usart_init(); 
56
57  /*
58   * Init rtems exceptions management
59   */
60  rtems_exception_init_mngt();
61
62  /*
63   * Init rtems interrupt management
64   */
65  if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
66    _CPU_Fatal_halt(0xe);
67  }
68
69} /* bsp_start */
70
71/*
72 * Some versions of the bootloader shipped with the CSB337
73 * reverse the MAC address. This function tests for that,
74 * and fixes the MAC address.
75 */
76static void fix_mac_addr(void)
77{
78  uint8_t addr[6];
79
80  /* Read the MAC address */
81  addr[0] = (EMAC_REG(EMAC_SA1L) >>  0) & 0xff;
82  addr[1] = (EMAC_REG(EMAC_SA1L) >>  8) & 0xff;
83  addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff;
84  addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff;
85  addr[4] = (EMAC_REG(EMAC_SA1H) >>  0) & 0xff;
86  addr[5] = (EMAC_REG(EMAC_SA1H) >>  8) & 0xff;
87
88  /* Check which 3 bytes have Cogent's OUI */
89  if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) {
90      EMAC_REG(EMAC_SA1L) = ((addr[5] <<  0) |
91                             (addr[4] <<  8) |
92                             (addr[3] << 16) |
93                             (addr[2] << 24));
94
95      EMAC_REG(EMAC_SA1H) = ((addr[1] <<  0) |
96                             (addr[0] <<  8));
97  }
98}
99
100/*
101 *
102 * NAME: bsp_usart_init - Function to setup the PIO in USART mode
103 *       before startup
104 *
105 * DESCRIPTION:
106 *   This function is called before usart driver is initialized and is
107 *   used to setup the proper mode of PIO operation for USART.
108 *
109 * NOTES:
110 *   The initialization could be done smarter by programming only the
111 *   bits you need to program for each USART when the port is ENABLED.
112 *
113 */
114void bsp_usart_init(void)
115{
116  /*
117   * Configure shared pins for USARTs.
118   * Disables the PIO from controlling the corresponding pin.
119   */
120  PIOA_REG(PIO_PDR) |= ( BIT5  |   /* USART3 TXD3  */
121                         BIT6  |   /* USART3 RXD3  */
122                         BIT17 |   /* USART0 TXD0  */
123                         BIT18 |   /* USART0 RXD0  */
124                         BIT22 |   /* USART2 RXD2  */
125                         BIT23 );  /* USART2 TXD2  */
126
127  PIOB_REG(PIO_PDR) |= ( BIT20 |   /* USART1 TXD1  */
128                         BIT21 );  /* USART1 RXD1  */
129
130  /**** PIO Controller A - Pins you want in mode B ****/
131  PIOA_REG(PIO_BSR) |=  ( BIT5 |   /* USART3 TXD3  */ /* add */
132                          BIT6 );  /* USART3 RXD3  */ 
133  PIOA_REG(PIO_ASR) &= ~( BIT5 |   /* USART3 TXD3  */
134                          BIT6 );  /* USART3 RXD3  */
135
136  /**** PIO Controller A - Pins you want in mode A ****/
137  PIOA_REG(PIO_ASR) |=  ( BIT17 |   /* USART0 TXD0  */
138                          BIT18 |   /* USART0 RXD0  */
139                          BIT22 |   /* USART2 RXD2  */
140                          BIT23 );  /* USART2 TXD2  */
141  PIOA_REG(PIO_BSR) &= ~( BIT17 |   /* USART0 TXD0  */ /* add */
142                          BIT18 |   /* USART0 RXD0  */
143                          BIT22 |   /* USART2 RXD2  */
144                          BIT23 );  /* USART2 TXD2  */
145
146  /**** PIO Controller B - Pins you want in mode A ****/
147  PIOB_REG(PIO_ASR) |=  ( BIT20 |   /* USART1 TXD1  */
148                          BIT21 );  /* USART1 RXD1  */
149  PIOB_REG(PIO_BSR) &= ~( BIT20 |   /* USART1 TXD1  */
150                          BIT21 );  /* USART1 RXD1  */
151
152  /**** PIO Controller B - Pins you want in mode B ****/
153  /**** none ****/
154
155  /* Enable the clock to the USARTs */
156  PMC_REG(PMC_PCER) |= ( PMC_PCR_PID_US0 |   /* USART 0 Peripheral Clock */
157                         PMC_PCR_PID_US1 |   /* USART 1 Peripheral Clock */
158                         PMC_PCR_PID_US2 |   /* USART 2 Peripheral Clock */ 
159                         PMC_PCR_PID_US3 );  /* USART 3 Peripheral Clock */
160} 
161
162/*
163 *  By making this a weak alias for bsp_start_default, a brave soul
164 *  can override the actual bsp_start routine used.
165 */
166void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default")));
Note: See TracBrowser for help on using the repository browser.