source: rtems/c/src/lib/libbsp/powerpc/virtex5/startup/bspstart.c @ 24bf11e

4.115
Last change on this file since 24bf11e was 24bf11e, checked in by Sebastian Huber <sebastian.huber@…>, on 02/12/14 at 09:31:38

score: Add CPU counter support

Add a CPU counter interface to allow access to a free-running counter.
It is useful to measure short time intervals. This can be used for
example to enable profiling of critical low-level functions.

Add two busy wait functions rtems_counter_delay_ticks() and
rtems_counter_delay_nanoseconds() implemented via the CPU counter.

  • Property mode set to 100644
File size: 8.1 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 *  Modifications for Virtex5 by Richard Claus <claus@slac.stanford.edu>
56 */
57#include <rtems.h>
58#include <rtems/config.h>
59#include <rtems/bspIo.h>
60#include <rtems/counter.h>
61#include <rtems/libio.h>
62#include <rtems/libcsupport.h>
63
64#include <libcpu/cpuIdent.h>
65#include <libcpu/spr.h>
66
67#include <bsp.h>
68#include <bsp/vectors.h>
69#include <bsp/bootcard.h>
70#include <bsp/irq.h>
71
72#include <string.h>
73#include <fcntl.h>
74
75#define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1))
76
77#define DO_UP_ALIGN(x,a)   DO_DOWN_ALIGN(((x) + (a) - 1 ),a)
78
79#define CPU_DOWN_ALIGN(x)  DO_DOWN_ALIGN(x, CPU_ALIGNMENT)
80#define CPU_UP_ALIGN(x)    DO_UP_ALIGN(x, CPU_ALIGNMENT)
81
82
83/* Defined in linkcmds linker script */
84LINKER_SYMBOL(RamBase);
85LINKER_SYMBOL(RamSize);
86LINKER_SYMBOL(__bsp_ram_start);
87LINKER_SYMBOL(__bsp_ram_end);
88LINKER_SYMBOL(__rtems_end);
89LINKER_SYMBOL(_stack);
90LINKER_SYMBOL(StackSize);
91LINKER_SYMBOL(__stack_base);
92LINKER_SYMBOL(WorkAreaBase);
93LINKER_SYMBOL(MsgAreaBase);
94LINKER_SYMBOL(MsgAreaSize);
95LINKER_SYMBOL(__phy_ram_end);
96LINKER_SYMBOL(bsp_exc_vector_base);
97
98
99/* Expected by clock.c */
100uint32_t    bsp_clicks_per_usec;
101bool        bsp_timer_internal_clock;   /* true, when timer runs with CPU clk */
102uint32_t    bsp_timer_least_valid;
103uint32_t    bsp_timer_average_overhead;
104
105/*
106 * Bus Frequency
107 */
108unsigned int BSP_bus_frequency;
109/*
110 * processor clock frequency
111 */
112unsigned int BSP_processor_frequency;
113
114/*
115 * Time base divisior (bus freq / TB clock)
116 */
117unsigned int BSP_time_base_divisor;
118
119/*
120 * Provide weak aliases so that RTEMS distribution builds
121 */
122static void _noopfun(void) {}
123
124
125void app_bsp_start(void)
126__attribute__(( weak, alias("_noopfun") ));
127
128void app_bsp_pretasking_hook(void)
129__attribute__(( weak, alias("_noopfun") ));
130
131void app_bsp_predriver_hook(void)
132__attribute__(( weak, alias("_noopfun") ));
133
134
135static char* bspMsgBuffer = (char*)MsgAreaBase;
136
137static void __bsp_outchar_to_memory(char c)
138{
139  static char* msgBuffer = (char*)MsgAreaBase;
140  *msgBuffer++ = c;
141  if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
142  *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
143}
144
145
146void BSP_ask_for_reset(void)
147{
148  printk("\nSystem stopped, issue RESET");
149
150  for(;;);
151}
152
153
154void BSP_panic(char *s)
155{
156  __attribute__((unused)) rtems_interrupt_level level;
157
158  rtems_interrupt_disable(level);
159
160  printk("\n%s PANIC %s\n", rtems_get_version_string(), s);
161
162  BSP_ask_for_reset();
163}
164
165
166void _BSP_Fatal_error(unsigned int v)
167{
168  __attribute__((unused)) rtems_interrupt_level level;
169
170  rtems_interrupt_disable(level);
171
172  printk("\n%s FATAL ERROR %x\n", rtems_get_version_string(), v);
173
174  BSP_ask_for_reset();
175}
176
177
178/*===================================================================*/
179
180/*
181 *  BSP start routine.  Called by boot_card().
182 *
183 *  This routine does the bulk of the system initialization.
184 */
185void bsp_start(void)
186{
187  uintptr_t          intrStackStart;
188  uintptr_t          intrStackSize;
189
190  ppc_cpu_id_t       myCpu;
191  ppc_cpu_revision_t myCpuRevision;
192
193  /* Set the character output function;  The application may override this */
194  BSP_output_char = __bsp_outchar_to_memory;
195
196  printk("RTEMS %s\n", rtems_get_version_string());
197
198  /*
199   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
200   * function stores the result in global variables so that it can be used later...
201   */
202  myCpu         = get_ppc_cpu_type();
203  myCpuRevision = get_ppc_cpu_revision();
204  printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
205         myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
206
207  /*
208   *  Initialize the device driver parameters
209   */
210
211  /* For mpc6xx clock driver: */
212  BSP_bus_frequency       = 465000000;
213  BSP_processor_frequency = 465000000;  /* Measured with a DPM 440 2012/8/13 */
214  BSP_time_base_divisor   = 1000;
215
216  /* Timebase register ticks/microsecond;  The application may override these */
217  bsp_clicks_per_usec        = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
218  rtems_counter_initialize_converter(
219    BSP_bus_frequency / (BSP_time_base_divisor / 1000)
220  );
221  bsp_timer_internal_clock   = true;
222  bsp_timer_average_overhead = 2;
223  bsp_timer_least_valid      = 3;
224
225  /*
226   * Initialize the interrupt related settings.
227   */
228  intrStackStart = CPU_UP_ALIGN((uint32_t)__bsp_ram_start);
229  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
230
231  ppc_exc_initialize(PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
232                     intrStackStart,
233                     intrStackSize);
234
235  /* Let the user know what parameters we were compiled with */
236  printk("                  Base/Start     End         Size\n"
237         "RAM:              0x%08x              0x%x\n"
238         "RTEMS:                        0x%08x\n"
239         "Interrupt Stack:  0x%08x              0x%x\n"
240         "Stack:            0x%08x  0x%08x  0x%x\n"
241         "Workspace:        0x%08x  0x%08x\n"
242         "MsgArea:          0x%08x              0x%x\n"
243         "Physical RAM                  0x%08x\n",
244         (uint32_t)RamBase,                               (uint32_t)RamSize,
245         (uint32_t)__rtems_end,
246         intrStackStart,                                  intrStackSize,
247         (uint32_t)__stack_base, (uint32_t)_stack,        (uint32_t)StackSize,
248         (uint32_t)WorkAreaBase, (uint32_t)__bsp_ram_end,
249         (uint32_t)MsgAreaBase,                           (uint32_t)MsgAreaSize,
250         (uint32_t)__phy_ram_end);
251
252  /*
253   * Initialize RTEMS IRQ system
254   */
255  BSP_rtems_irq_mngt_init(0);
256
257  /* Continue with application-specific initialization */
258  app_bsp_start();
259}
260
261
262/*
263 *  BSP pretasking hook.  Called just before drivers are initialized.
264 *  Used to setup libc and install any BSP extensions.
265 *
266 *  Must not use libc (to do io) from here, since drivers are not yet
267 *  initialized.
268 */
269
270void bsp_pretasking_hook(void)
271{
272  app_bsp_pretasking_hook();
273}
274
275
276/*
277 *  BSP predriver hook.  Called by boot_card() just before drivers are
278 *  initialized.  Clear out any stale interrupts here.
279 */
280void bsp_predriver_hook(void)
281{
282  app_bsp_predriver_hook();
283}
Note: See TracBrowser for help on using the repository browser.