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

4.104.115
Last change on this file since e5764ee was 7b25525, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/09 at 22:00:36

2009-11-30 Fernando Nicodemos <fgnicodemos@…>

  • Makefile.am, preinstall.am, console/fbcons.c, console/font8x16.h, console/sed1356.c, console/uarts.c, include/sed1356.h, startup/bspstart.c, startup/linkcmds.csb337, startup/linkcmds.csb637, startup/memmap.c, startup/umonsupp.c: Update to match development version.
  • Property mode set to 100644
File size: 5.1 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);
28void bsp_libc_init( void *, uint32_t, int );
29static void fix_mac_addr(void);
30void bsp_usart_init(void);
31
32/*
33 * bsp_start_default - BSP initialization function
34 *
35 * This function is called before RTEMS is initialized and used
36 * adjust the kernel's configuration.
37 *
38 * This function also configures the CPU's memory protection unit.
39 *
40 * RESTRICTIONS/LIMITATIONS:
41 *   Since RTEMS is not configured, no RTEMS functions can be called.
42 */
43void bsp_start_default( void )
44{
45  /* disable interrupts */
46  AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
47
48  /*
49   * Some versions of the bootloader have the MAC address
50   * reversed. This fixes it, if necessary.
51   */
52  fix_mac_addr();
53
54  /*
55   * Init rtems PIO configuration for USARTs
56   */
57  bsp_usart_init();
58
59  /*
60   * Init rtems exceptions management
61   */
62  rtems_exception_init_mngt();
63
64  /*
65   * Init rtems interrupt management
66   */
67  rtems_irq_mngt_init();
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.