source: rtems/c/src/lib/libbsp/powerpc/haleakala/startup/bspstart.c @ b1e8a58

4.115
Last change on this file since b1e8a58 was b1e8a58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/12 at 08:57:55

bsps/powerpc: Exception initialization error is fatal

  • Property mode set to 100644
File size: 6.4 KB
Line 
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#include <string.h>
60#include <fcntl.h>
61
62#include <bsp.h>
63#include <bsp/uart.h>
64#include <bsp/irq.h>
65#include <libcpu/powerpc-utility.h>
66#include <bsp/vectors.h>
67#include <ppc4xx/ppc405gp.h>
68#include <ppc4xx/ppc405ex.h>
69
70#include <stdio.h>
71
72LINKER_SYMBOL(intrStack_start);
73LINKER_SYMBOL(intrStack_size);
74/*
75 *  Driver configuration parameters
76 */
77
78/* Expected by clock.c */
79uint32_t    bsp_clicks_per_usec;
80bool        bsp_timer_internal_clock;   /* true, when timer runs with CPU clk */
81uint32_t    bsp_timer_least_valid;
82uint32_t    bsp_timer_average_overhead;
83
84/*-------------------- Haleakala-specific UART setup -------------------------*/
85
86static void
87EarlyUARTInit(int baudRate)
88{
89  volatile uint8_t* up = (uint8_t*)(BSP_UART_IOBASE_COM1);
90  int divider = BSP_UART_BAUD_BASE / baudRate;
91  up[LCR] = DLAB;    /* Access DLM/DLL */
92  up[DLL] = divider & 0x0FF;
93  up[DLM] = divider >> 8;
94  up[LCR] = CHR_8_BITS;
95  up[MCR] = DTR | RTS;
96  up[FCR] = FIFO_EN | XMIT_RESET | RCV_RESET;
97  up[THR] = '+';
98}
99
100
101static void
102InitUARTClock(void)
103{
104  uint32_t reg;
105  mfsdr(SDR0_UART0,reg);
106  reg &= ~0x008000FF;
107  reg |= 0x00800001;    /* Ext clock, div 1 */
108  mtsdr(SDR0_UART0,reg);
109}
110
111void GPIO_AlternateSelect(int bitnum, int source)
112/* PPC405EX: select a GPIO function for the specified pin */
113{
114  int shift;
115  unsigned long value, mask;
116  GPIORegisters* gpioPtr = (GPIORegisters*)(GPIOAddress);
117
118  shift = (31 - bitnum) & 0xF;
119  value = (source & 3) << (shift*2);
120  mask  = 3 << (shift*2);
121  if (bitnum <= 15) {
122    gpioPtr->OSRL = (gpioPtr->OSRL & ~mask) | value;
123    gpioPtr->TSRL = (gpioPtr->TSRL & ~mask) | value;
124  } else {
125    gpioPtr->OSRH = (gpioPtr->OSRH & ~mask) | value;
126    gpioPtr->TSRH = (gpioPtr->TSRH & ~mask) | value;
127  }
128}
129
130void Init_FPGA(void)
131{
132  /* Have to write to the FPGA to enable the UART drivers */
133  /* Have to enable CS2 as an output in GPIO to get the FPGA working */
134  mtebc(EBC0_B2CR,0xF0018000);  /* Set up CS2 at 0xF0000000 */
135  mtebc(EBC0_B2AP,0x9400C800);
136  GPIO_AlternateSelect(9,1);    /* GPIO9 = PerCS2 */
137  {
138    unsigned long *fpgaPtr = (unsigned long*)(0xF0000000);
139    unsigned long n;
140    n = *(fpgaPtr);
141    n &= ~0x00100;    /* User LEDs on */
142    n |=  0x30000;    /* UART 0 and 1 transcievers on! */
143    *fpgaPtr = n;
144  }
145}
146
147/*===================================================================*/
148
149static void
150DirectUARTWrite(const char c)
151{
152  volatile uint8_t* up = (uint8_t*)(BSP_UART_IOBASE_COM1);
153  while ((up[LSR] & THRE) == 0) { ; }
154  up[THR] = c;
155  if (c=='\n')
156    DirectUARTWrite('\r');
157}
158
159/* We will provide our own printk output function as it may get used early */
160BSP_output_char_function_type     BSP_output_char = DirectUARTWrite;
161BSP_polling_getchar_function_type BSP_poll_char = NULL;
162
163/*===================================================================*/
164
165
166/*
167 *  bsp_start
168 *
169 *  This routine does the bulk of the system initialization.
170 */
171void bsp_start( void )
172{
173  ppc_cpu_id_t myCpu;
174  ppc_cpu_revision_t myCpuRevision;
175
176  /* Get the UART clock initialized first in case we call printk */
177
178  InitUARTClock();
179  Init_FPGA();
180  EarlyUARTInit(115200);
181
182  /*
183   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
184   * function store the result in global variables
185   * so that it can be used later...
186   */
187  myCpu       = get_ppc_cpu_type();
188  myCpuRevision = get_ppc_cpu_revision();
189
190  /*
191   *  initialize the device driver parameters
192   */
193
194  /* Set globals visible to clock.c */
195  /* timebase register ticks/microsecond = CPU Clk in MHz */
196  bsp_clicks_per_usec = 400;
197
198  bsp_timer_internal_clock  = TRUE;
199  bsp_timer_average_overhead = 2;
200  bsp_timer_least_valid = 3;
201
202  /*
203   * Initialize default raw exception handlers.
204   */
205  ppc_exc_initialize(
206    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
207    (uintptr_t) intrStack_start,
208    (uintptr_t) intrStack_size
209  );
210
211  /*
212   * Install our own set of exception vectors
213   */
214  BSP_rtems_irq_mng_init(0);
215}
216
217void BSP_ask_for_reset(void)
218{
219  printk("system stopped, press RESET");
220  while(1) {};
221}
222
223void BSP_panic(char *s)
224{
225  printk("%s PANIC %s\n",_RTEMS_version, s);
226  BSP_ask_for_reset();
227}
228
229void _BSP_Fatal_error(unsigned int v)
230{
231  printk("%s PANIC ERROR %x\n",_RTEMS_version, v);
232  BSP_ask_for_reset();
233}
Note: See TracBrowser for help on using the repository browser.