[3c6fe2e] | 1 | /* bsp_start() |
---|
| 2 | * |
---|
| 3 | * This routine starts the application. It includes application, |
---|
| 4 | * board, and monitor specific initialization and configuration. |
---|
| 5 | * The generic CPU dependent initialization has been performed |
---|
| 6 | * before this routine is invoked. |
---|
| 7 | * |
---|
| 8 | * INPUT: NONE |
---|
| 9 | * |
---|
| 10 | * OUTPUT: NONE |
---|
| 11 | * |
---|
| 12 | * Author: Thomas Doerfler <td@imd.m.isar.de> |
---|
| 13 | * IMD Ingenieurbuero fuer Microcomputertechnik |
---|
| 14 | * |
---|
| 15 | * COPYRIGHT (c) 1998 by IMD |
---|
| 16 | * |
---|
| 17 | * Changes from IMD are covered by the original distributions terms. |
---|
| 18 | * This file has been derived from the papyrus BSP: |
---|
| 19 | * |
---|
| 20 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
| 21 | * |
---|
| 22 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
| 23 | * |
---|
| 24 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 25 | * without any express or implied warranty: |
---|
| 26 | * permission to use, copy, modify, and distribute this file |
---|
| 27 | * for any purpose is hereby granted without fee, provided that |
---|
| 28 | * the above copyright notice and this notice appears in all |
---|
| 29 | * copies, and that the name of i-cubed limited not be used in |
---|
| 30 | * advertising or publicity pertaining to distribution of the |
---|
| 31 | * software without specific, written prior permission. |
---|
| 32 | * i-cubed limited makes no representations about the suitability |
---|
| 33 | * of this software for any purpose. |
---|
| 34 | * |
---|
| 35 | * Modifications for spooling console driver and control of memory layout |
---|
| 36 | * with linker command file by |
---|
| 37 | * Thomas Doerfler <td@imd.m.isar.de> |
---|
| 38 | * for these modifications: |
---|
| 39 | * COPYRIGHT (c) 1997 by IMD, Puchheim, Germany. |
---|
| 40 | * |
---|
| 41 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 42 | * without any express or implied warranty: |
---|
| 43 | * permission to use, copy, modify, and distribute this file |
---|
| 44 | * for any purpose is hereby granted without fee, provided that |
---|
| 45 | * the above copyright notice and this notice appears in all |
---|
| 46 | * copies. IMD makes no representations about the suitability |
---|
| 47 | * of this software for any purpose. |
---|
| 48 | * |
---|
| 49 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c: |
---|
| 50 | * |
---|
| 51 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 52 | * On-Line Applications Research Corporation (OAR). |
---|
| 53 | * |
---|
| 54 | * Modifications for PPC405GP by Dennis Ehlin |
---|
| 55 | * |
---|
| 56 | * Further modified for the PPC405EX Haleakala board by |
---|
| 57 | * Michael Hamel ADInstruments Ltd May 2008 |
---|
| 58 | * |
---|
| 59 | * $Id$ |
---|
| 60 | */ |
---|
| 61 | #include <string.h> |
---|
| 62 | #include <fcntl.h> |
---|
| 63 | |
---|
| 64 | #include <bsp.h> |
---|
| 65 | #include <bsp/uart.h> |
---|
| 66 | #include <rtems/libio.h> |
---|
| 67 | #include <rtems/libcsupport.h> |
---|
| 68 | #include <bsp/irq.h> |
---|
| 69 | #include <rtems/bspIo.h> |
---|
| 70 | #include <libcpu/cpuIdent.h> |
---|
| 71 | #include <rtems/powerpc/powerpc.h> |
---|
[574fb67] | 72 | #include <bsp/ppc_exc_bspsupp.h> |
---|
[3c6fe2e] | 73 | #include <ppc4xx/ppc405gp.h> |
---|
| 74 | #include <ppc4xx/ppc405ex.h> |
---|
| 75 | |
---|
| 76 | #include <stdio.h> |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | * Driver configuration parameters |
---|
| 80 | */ |
---|
| 81 | |
---|
| 82 | /* Expected by clock.c */ |
---|
| 83 | uint32_t bsp_clicks_per_usec; |
---|
| 84 | boolean bsp_timer_internal_clock; /* TRUE, when timer runs with CPU clk */ |
---|
| 85 | uint32_t bsp_timer_least_valid; |
---|
| 86 | uint32_t bsp_timer_average_overhead; |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | /* Initialize whatever libc we are using |
---|
| 90 | * called from postdriver hook |
---|
| 91 | */ |
---|
| 92 | |
---|
| 93 | void bsp_postdriver_hook(void); |
---|
| 94 | void bsp_libc_init( void *, uint32_t, int ); |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * |
---|
| 98 | * bsp_predriver_hook |
---|
| 99 | * |
---|
| 100 | * Before drivers are setup. |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | void bsp_predriver_hook(void) |
---|
| 104 | { |
---|
| 105 | |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /* |
---|
| 109 | * Function: bsp_pretasking_hook |
---|
| 110 | * Created: 95/03/10 |
---|
| 111 | * |
---|
| 112 | * Description: |
---|
| 113 | * BSP pretasking hook. Called just before drivers are initialized. |
---|
| 114 | * Used to setup libc and install any BSP extensions. |
---|
| 115 | * |
---|
| 116 | * NOTES: |
---|
| 117 | * Must not use libc (to do io) from here, since drivers are |
---|
| 118 | * not yet initialized. |
---|
| 119 | * |
---|
| 120 | */ |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | extern uint8_t _RAMEnd; /* Defined in linkcmds */ |
---|
| 124 | |
---|
| 125 | void bsp_pretasking_hook(void) |
---|
| 126 | /* Initialise libc with the address and size of the heap, which runs |
---|
| 127 | from the end of the RTEMS workspace to the top of RAM */ |
---|
| 128 | { |
---|
| 129 | uint32_t heap_start; |
---|
| 130 | |
---|
| 131 | heap_start = ( (uint32_t)Configuration.work_space_start + |
---|
| 132 | rtems_configuration_get_work_space_size() ); |
---|
| 133 | |
---|
| 134 | bsp_libc_init((void *)heap_start, (uint32_t)(&_RAMEnd) - heap_start, 0); |
---|
| 135 | |
---|
| 136 | #ifdef RTEMS_DEBUG |
---|
| 137 | rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); |
---|
| 138 | #endif |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /*-------------------- Haleakala-specific UART setup -------------------------*/ |
---|
| 142 | |
---|
| 143 | static void |
---|
| 144 | EarlyUARTInit(int baudRate) |
---|
| 145 | { |
---|
| 146 | uint8_t* up = (uint8_t*)(BSP_UART_IOBASE_COM1); |
---|
| 147 | int divider = BSP_UART_BAUD_BASE / baudRate; |
---|
| 148 | up[LCR] = DLAB; /* Access DLM/DLL */ |
---|
| 149 | up[DLL] = divider & 0x0FF; |
---|
| 150 | up[DLM] = divider >> 8; |
---|
| 151 | up[LCR] = CHR_8_BITS; |
---|
| 152 | up[MCR] = DTR | RTS; |
---|
| 153 | up[FCR] = FIFO_EN | XMIT_RESET | RCV_RESET; |
---|
| 154 | up[THR] = '+'; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | static void |
---|
[378bea5] | 159 | InitUARTClock(void) |
---|
[3c6fe2e] | 160 | { |
---|
| 161 | uint32_t reg; |
---|
| 162 | mfsdr(SDR0_UART0,reg); |
---|
| 163 | reg &= ~0x008000FF; |
---|
| 164 | reg |= 0x00800001; /* Ext clock, div 1 */ |
---|
| 165 | mtsdr(SDR0_UART0,reg); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | void GPIO_AlternateSelect(int bitnum, int source) |
---|
| 169 | /* PPC405EX: select a GPIO function for the specified pin */ |
---|
| 170 | { |
---|
| 171 | int shift; |
---|
| 172 | unsigned long value, mask; |
---|
| 173 | GPIORegisters* gpioPtr = (GPIORegisters*)(GPIOAddress); |
---|
| 174 | |
---|
| 175 | shift = (31 - bitnum) & 0xF; |
---|
| 176 | value = (source & 3) << (shift*2); |
---|
| 177 | mask = 3 << (shift*2); |
---|
| 178 | if (bitnum <= 15) { |
---|
| 179 | gpioPtr->OSRL = (gpioPtr->OSRL & ~mask) | value; |
---|
| 180 | gpioPtr->TSRL = (gpioPtr->TSRL & ~mask) | value; |
---|
| 181 | } else { |
---|
| 182 | gpioPtr->OSRH = (gpioPtr->OSRH & ~mask) | value; |
---|
| 183 | gpioPtr->TSRH = (gpioPtr->TSRH & ~mask) | value; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
[378bea5] | 187 | void Init_FPGA(void) |
---|
[3c6fe2e] | 188 | { |
---|
| 189 | /* Have to write to the FPGA to enable the UART drivers */ |
---|
| 190 | /* Have to enable CS2 as an output in GPIO to get the FPGA working */ |
---|
| 191 | mtebc(EBC0_B2CR,0xF0018000); /* Set up CS2 at 0xF0000000 */ |
---|
| 192 | mtebc(EBC0_B2AP,0x9400C800); |
---|
| 193 | GPIO_AlternateSelect(9,1); /* GPIO9 = PerCS2 */ |
---|
| 194 | { |
---|
| 195 | unsigned long *fpgaPtr = (unsigned long*)(0xF0000000); |
---|
| 196 | unsigned long n; |
---|
| 197 | n = *(fpgaPtr); |
---|
| 198 | n &= ~0x00100; /* User LEDs on */ |
---|
| 199 | n |= 0x30000; /* UART 0 and 1 transcievers on! */ |
---|
| 200 | *fpgaPtr = n; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /*===================================================================*/ |
---|
| 205 | |
---|
| 206 | static void |
---|
| 207 | DirectUARTWrite(const char c) |
---|
| 208 | { |
---|
| 209 | uint8_t* up = (uint8_t*)(BSP_UART_IOBASE_COM1); |
---|
| 210 | while ((up[LSR] & THRE) == 0) { ; } |
---|
| 211 | up[THR] = c; |
---|
| 212 | if (c=='\n') |
---|
| 213 | DirectUARTWrite('\r'); |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | /* We will provide our own printk output function as it may get used early */ |
---|
| 217 | BSP_output_char_function_type BSP_output_char = DirectUARTWrite; |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | /*===================================================================*/ |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * bsp_start |
---|
| 225 | * |
---|
| 226 | * This routine does the bulk of the system initialization. |
---|
| 227 | */ |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | void bsp_start( void ) |
---|
| 231 | { |
---|
[574fb67] | 232 | LINKER_SYMBOL(intrStack_start); |
---|
| 233 | LINKER_SYMBOL(intrStack_size); |
---|
[3c6fe2e] | 234 | ppc_cpu_id_t myCpu; |
---|
| 235 | ppc_cpu_revision_t myCpuRevision; |
---|
| 236 | |
---|
| 237 | /* Get the UART clock initialized first in case we call printk */ |
---|
| 238 | |
---|
| 239 | InitUARTClock(); |
---|
| 240 | Init_FPGA(); |
---|
| 241 | EarlyUARTInit(115200); |
---|
| 242 | |
---|
| 243 | /* |
---|
| 244 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() |
---|
| 245 | * function store the result in global variables |
---|
| 246 | * so that it can be used later... |
---|
| 247 | */ |
---|
| 248 | myCpu = get_ppc_cpu_type(); |
---|
| 249 | myCpuRevision = get_ppc_cpu_revision(); |
---|
| 250 | |
---|
| 251 | /* |
---|
| 252 | * initialize the device driver parameters |
---|
| 253 | */ |
---|
| 254 | |
---|
| 255 | /* Set globals visible to clock.c */ |
---|
| 256 | bsp_clicks_per_usec = 400; /* timebase register ticks/microsecond = CPU Clk in MHz */ |
---|
| 257 | bsp_timer_internal_clock = TRUE; |
---|
| 258 | bsp_timer_average_overhead = 2; |
---|
| 259 | bsp_timer_least_valid = 3; |
---|
| 260 | |
---|
| 261 | /* |
---|
| 262 | * Initialize default raw exception handlers. |
---|
| 263 | */ |
---|
[574fb67] | 264 | ppc_exc_initialize( |
---|
| 265 | PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
| 266 | (uint32_t) intrStack_start, |
---|
| 267 | (uint32_t) intrStack_size); |
---|
[3c6fe2e] | 268 | |
---|
| 269 | /* |
---|
| 270 | * Install our own set of exception vectors |
---|
| 271 | */ |
---|
| 272 | BSP_rtems_irq_mng_init(0); |
---|
| 273 | |
---|
| 274 | /* |
---|
| 275 | * Allocate the memory for the RTEMS Work Space. This can come from |
---|
| 276 | * a variety of places: hard coded address, malloc'ed from outside |
---|
| 277 | * RTEMS world (e.g. simulator or primitive memory manager), or (as |
---|
| 278 | * typically done by stock BSPs) by subtracting the required amount |
---|
| 279 | * of work space from the last physical address on the CPU board. |
---|
| 280 | */ |
---|
| 281 | /* In this case we allocate space at an address defined in linkcmds |
---|
| 282 | which points to a block above the stack and below the heap */ |
---|
| 283 | { |
---|
| 284 | extern uint8_t _WorkspaceStart; |
---|
| 285 | Configuration.work_space_start = &_WorkspaceStart; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | void BSP_ask_for_reset(void) |
---|
| 291 | { |
---|
| 292 | printk("system stopped, press RESET"); |
---|
| 293 | while(1) {}; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | void BSP_panic(char *s) |
---|
| 297 | { |
---|
| 298 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
| 299 | BSP_ask_for_reset(); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | void _BSP_Fatal_error(unsigned int v) |
---|
| 303 | { |
---|
| 304 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
| 305 | BSP_ask_for_reset(); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | |
---|