[b759b04] | 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.OARcorp.com/rtems/license.html. |
---|
| 11 | * |
---|
| 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | #include <bsp.h> |
---|
| 16 | #include <rtems/libcsupport.h> |
---|
| 17 | #include <rtems/libio.h> |
---|
| 18 | #include <at91rm9200.h> |
---|
| 19 | #include <at91rm9200_pmc.h> |
---|
| 20 | #include <at91rm9200_emac.h> |
---|
| 21 | |
---|
| 22 | /* Global Variables */ |
---|
| 23 | extern void *_flash_size; |
---|
| 24 | extern void *_flash_base; |
---|
| 25 | extern void *_sdram_size; |
---|
| 26 | extern void *_sdram_base; |
---|
| 27 | extern void *_bss_free_start; |
---|
| 28 | |
---|
| 29 | unsigned long free_mem_start; |
---|
| 30 | unsigned long free_mem_end; |
---|
| 31 | |
---|
| 32 | rtems_configuration_table BSP_Configuration; |
---|
| 33 | rtems_cpu_table Cpu_table; |
---|
| 34 | char *rtems_progname = "RTEMS"; |
---|
| 35 | |
---|
| 36 | /* Function prototypes */ |
---|
| 37 | extern void rtems_irq_mngt_init(void); |
---|
[86ad4860] | 38 | void bsp_libc_init( void *, uint32_t, int ); |
---|
[b759b04] | 39 | void bsp_postdriver_hook(void); |
---|
| 40 | static void fix_mac_addr(); |
---|
| 41 | |
---|
| 42 | /**************************************************************************/ |
---|
| 43 | /* */ |
---|
| 44 | /* NAME: bsp_pretasking_hook - Function to setup system before startup */ |
---|
| 45 | /* */ |
---|
| 46 | /* DESCRIPTION: */ |
---|
| 47 | /* This function is called before drivers are initialized and used */ |
---|
| 48 | /* to setup libc and BSP extensions. */ |
---|
| 49 | /* */ |
---|
| 50 | /* RESTRICTIONS/LIMITATIONS: */ |
---|
| 51 | /* Since this function is setting up libc, it cannot use and libc */ |
---|
| 52 | /* functions. */ |
---|
| 53 | /* */ |
---|
| 54 | /**************************************************************************/ |
---|
| 55 | void bsp_pretasking_hook(void) |
---|
| 56 | { |
---|
[86ad4860] | 57 | uint32_t heap_start; |
---|
| 58 | uint32_t heap_size; |
---|
[b759b04] | 59 | |
---|
| 60 | /* |
---|
| 61 | * Set up the heap. |
---|
| 62 | */ |
---|
| 63 | heap_start = free_mem_start; |
---|
| 64 | heap_size = free_mem_end - free_mem_start; |
---|
| 65 | |
---|
| 66 | /* call rtems lib init - malloc stuff */ |
---|
| 67 | bsp_libc_init((void *)heap_start, heap_size, 0); |
---|
| 68 | |
---|
| 69 | #ifdef RTEMS_DEBUG |
---|
| 70 | |
---|
| 71 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
| 72 | |
---|
| 73 | #endif /* RTEMS_DEBUG */ |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | /**************************************************************************/ |
---|
| 79 | /* */ |
---|
| 80 | /* NAME: bsp_start_default - BSP initialization function */ |
---|
| 81 | /* */ |
---|
| 82 | /* DESCRIPTION: */ |
---|
| 83 | /* This function is called before RTEMS is initialized and used */ |
---|
| 84 | /* adjust the kernel's configuration. */ |
---|
| 85 | /* */ |
---|
| 86 | /* This function also configures the CPU's memory protection unit. */ |
---|
| 87 | /* */ |
---|
| 88 | /* RESTRICTIONS/LIMITATIONS: */ |
---|
| 89 | /* Since RTEMS is not configured, no RTEMS functions can be called. */ |
---|
| 90 | /* */ |
---|
| 91 | /**************************************************************************/ |
---|
| 92 | void bsp_start_default( void ) |
---|
| 93 | { |
---|
| 94 | /* disable interrupts */ |
---|
| 95 | AIC_CTL_REG(AIC_IDCR) = 0xffffffff; |
---|
| 96 | |
---|
| 97 | /* |
---|
| 98 | * Some versions of the bootloader have the MAC address |
---|
| 99 | * reversed. This fixes it, if necessary. |
---|
| 100 | */ |
---|
| 101 | fix_mac_addr(); |
---|
| 102 | |
---|
| 103 | /* tell RTEMS about the hooks we are using */ |
---|
| 104 | Cpu_table.pretasking_hook = bsp_pretasking_hook; |
---|
| 105 | Cpu_table.postdriver_hook = bsp_postdriver_hook; |
---|
| 106 | |
---|
| 107 | /* tell RTEMS to clear the workspace */ |
---|
| 108 | Cpu_table.do_zero_of_workspace = TRUE; |
---|
| 109 | |
---|
| 110 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
| 111 | BSP_Configuration.work_space_start = (void *)&_bss_free_start; |
---|
| 112 | |
---|
[86ad4860] | 113 | free_mem_start = ((uint32_t)&_bss_free_start + |
---|
[b759b04] | 114 | BSP_Configuration.work_space_size); |
---|
| 115 | |
---|
[86ad4860] | 116 | free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size); |
---|
[b759b04] | 117 | |
---|
| 118 | |
---|
| 119 | /* |
---|
| 120 | * Init rtems exceptions management |
---|
| 121 | */ |
---|
| 122 | rtems_exception_init_mngt(); |
---|
| 123 | |
---|
| 124 | /* |
---|
| 125 | * Init rtems interrupt management |
---|
| 126 | */ |
---|
| 127 | rtems_irq_mngt_init(); |
---|
| 128 | |
---|
| 129 | /* |
---|
| 130 | * The following information is very useful when debugging. |
---|
| 131 | */ |
---|
| 132 | #if 0 |
---|
| 133 | printk( "work_space_size = 0x%x\n\r", |
---|
| 134 | BSP_Configuration.work_space_size ); |
---|
| 135 | printk( "maximum_extensions = 0x%x\n\r", |
---|
| 136 | BSP_Configuration.maximum_extensions ); |
---|
| 137 | printk( "microseconds_per_tick = 0x%x\n\r", |
---|
| 138 | BSP_Configuration.microseconds_per_tick ); |
---|
| 139 | printk( "ticks_per_timeslice = 0x%x\n\r", |
---|
| 140 | BSP_Configuration.ticks_per_timeslice ); |
---|
| 141 | printk( "maximum_devices = 0x%x\n\r", |
---|
| 142 | BSP_Configuration.maximum_devices ); |
---|
| 143 | printk( "number_of_device_drivers = 0x%x\n\r", |
---|
| 144 | BSP_Configuration.number_of_device_drivers ); |
---|
| 145 | printk( "Device_driver_table = 0x%x\n\r", |
---|
| 146 | BSP_Configuration.Device_driver_table ); |
---|
| 147 | printk( "work_space_start = 0x%x\n\r", |
---|
| 148 | BSP_Configuration.work_space_start ); |
---|
| 149 | printk( "work_space_size = 0x%x\n\r", |
---|
| 150 | BSP_Configuration.work_space_size ); |
---|
| 151 | #endif |
---|
| 152 | } /* bsp_start */ |
---|
| 153 | |
---|
| 154 | /* |
---|
| 155 | * Some versions of the bootloader shipped with the CSB337 |
---|
| 156 | * reverse the MAC address. This function tests for that, |
---|
| 157 | * and fixes the MAC address. |
---|
| 158 | */ |
---|
| 159 | static void fix_mac_addr() |
---|
| 160 | { |
---|
| 161 | uint8_t addr[6]; |
---|
| 162 | |
---|
| 163 | /* Read the MAC address */ |
---|
| 164 | addr[0] = (EMAC_REG(EMAC_SA1L) >> 0) & 0xff; |
---|
| 165 | addr[1] = (EMAC_REG(EMAC_SA1L) >> 8) & 0xff; |
---|
| 166 | addr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff; |
---|
| 167 | addr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff; |
---|
| 168 | addr[4] = (EMAC_REG(EMAC_SA1H) >> 0) & 0xff; |
---|
| 169 | addr[5] = (EMAC_REG(EMAC_SA1H) >> 8) & 0xff; |
---|
| 170 | |
---|
| 171 | /* Check which 3 bytes have Cogent's OUI */ |
---|
| 172 | if ((addr[5] == 0x00) && (addr[4] == 0x23) && (addr[3] == 0x31)) { |
---|
| 173 | EMAC_REG(EMAC_SA1L) = ((addr[5] << 0) | |
---|
| 174 | (addr[4] << 8) | |
---|
| 175 | (addr[3] << 16) | |
---|
| 176 | (addr[2] << 24)); |
---|
| 177 | |
---|
| 178 | EMAC_REG(EMAC_SA1H) = ((addr[1] << 0) | |
---|
| 179 | (addr[0] << 8)); |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | /* |
---|
| 185 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
| 186 | * can override the actual bsp_start routine used. |
---|
| 187 | */ |
---|
| 188 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|
| 189 | |
---|
| 190 | /** |
---|
| 191 | * Reset the system. |
---|
| 192 | * |
---|
| 193 | * This functions enables the watchdog and waits for it to |
---|
| 194 | * fire, thus resetting the system. |
---|
| 195 | */ |
---|
| 196 | void bsp_reset(void) |
---|
| 197 | { |
---|
| 198 | rtems_interrupt_level level; |
---|
| 199 | |
---|
| 200 | _CPU_ISR_Disable(level); |
---|
| 201 | |
---|
| 202 | /* Enable the watchdog timer, then wait for the world to end. */ |
---|
| 203 | ST_REG(ST_WDMR) = ST_WDMR_RSTEN | 1; |
---|
| 204 | |
---|
| 205 | while(1); |
---|
| 206 | } |
---|