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 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | #include <bsp.h> |
---|
16 | #include <at91rm9200.h> |
---|
17 | #include <at91rm9200_pmc.h> |
---|
18 | #include <at91rm9200_emac.h> |
---|
19 | |
---|
20 | /* Function prototypes */ |
---|
21 | extern void rtems_irq_mngt_init(void); |
---|
22 | void bsp_libc_init( void *, uint32_t, int ); |
---|
23 | static void fix_mac_addr(void); |
---|
24 | |
---|
25 | /* |
---|
26 | * bsp_start_default - BSP initialization function |
---|
27 | * |
---|
28 | * This function is called before RTEMS is initialized and used |
---|
29 | * adjust the kernel's configuration. |
---|
30 | * |
---|
31 | * This function also configures the CPU's memory protection unit. |
---|
32 | * |
---|
33 | * RESTRICTIONS/LIMITATIONS: |
---|
34 | * Since RTEMS is not configured, no RTEMS functions can be called. |
---|
35 | */ |
---|
36 | void bsp_start_default( void ) |
---|
37 | { |
---|
38 | /* disable interrupts */ |
---|
39 | AIC_CTL_REG(AIC_IDCR) = 0xffffffff; |
---|
40 | |
---|
41 | /* |
---|
42 | * Some versions of the bootloader have the MAC address |
---|
43 | * reversed. This fixes it, if necessary. |
---|
44 | */ |
---|
45 | fix_mac_addr(); |
---|
46 | |
---|
47 | /* |
---|
48 | * Init rtems exceptions management |
---|
49 | */ |
---|
50 | rtems_exception_init_mngt(); |
---|
51 | |
---|
52 | /* |
---|
53 | * Init rtems interrupt management |
---|
54 | */ |
---|
55 | rtems_irq_mngt_init(); |
---|
56 | |
---|
57 | } /* bsp_start */ |
---|
58 | |
---|
59 | /* |
---|
60 | * Some versions of the bootloader shipped with the CSB337 |
---|
61 | * reverse the MAC address. This function tests for that, |
---|
62 | * and fixes the MAC address. |
---|
63 | */ |
---|
64 | static void fix_mac_addr(void) |
---|
65 | { |
---|
66 | uint8_t addr[6]; |
---|
67 | |
---|
68 | /* Read the MAC address */ |
---|
69 | addr[0] = (EMAC_REG(EMAC_SA1L) >> 0) & 0xff; |
---|
70 | addr[1] = (EMAC_REG(EMAC_SA1L) >> 8) & 0xff; |
---|
71 | addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff; |
---|
72 | addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff; |
---|
73 | addr[4] = (EMAC_REG(EMAC_SA1H) >> 0) & 0xff; |
---|
74 | addr[5] = (EMAC_REG(EMAC_SA1H) >> 8) & 0xff; |
---|
75 | |
---|
76 | /* Check which 3 bytes have Cogent's OUI */ |
---|
77 | if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) { |
---|
78 | EMAC_REG(EMAC_SA1L) = ((addr[5] << 0) | |
---|
79 | (addr[4] << 8) | |
---|
80 | (addr[3] << 16) | |
---|
81 | (addr[2] << 24)); |
---|
82 | |
---|
83 | EMAC_REG(EMAC_SA1H) = ((addr[1] << 0) | |
---|
84 | (addr[0] << 8)); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /* |
---|
90 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
91 | * can override the actual bsp_start routine used. |
---|
92 | */ |
---|
93 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|