source: rtems/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspstart.c @ 0e27119

4.11
Last change on this file since 0e27119 was 0e27119, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 11, 2012 at 8:52:18 PM

Use proper 3 line form of license text

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup tqm8xx
5 *
6 * @brief Source for BSP startup code.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <stdlib.h>
23
24#include <rtems.h>
25
26#include <libcpu/powerpc-utility.h>
27
28#include <bsp.h>
29#include <bsp/vectors.h>
30#include <bsp/bootcard.h>
31#include <bsp/irq-generic.h>
32
33#ifdef BSP_HAS_TQMMON
34/*
35 * FIXME: TQ Monitor structure
36 */
37#endif /* BSP_HAS_TQMMON */
38
39/* Configuration parameters for console driver, ... */
40uint32_t BSP_bus_frequency;
41
42/* Configuration parameter for clock driver */
43uint32_t bsp_time_base_frequency;
44
45/* Legacy */
46uint32_t bsp_clicks_per_usec; /* for PIT driver: OSCCLK */
47
48/* for timer: */
49uint32_t   bsp_timer_average_overhead; /* Average overhead of timer in ticks */
50uint32_t   bsp_timer_least_valid;      /* Least valid number from timer      */
51bool       bsp_timer_internal_clock;   /* TRUE, when timer runs with CPU clk */
52/*
53 *  Use the shared implementations of the following routines.
54 *  Look in rtems/c/src/lib/libbsp/shared/bsplibc.c.
55 */
56extern void cpu_init( void);
57
58void BSP_panic( char *s)
59{
60  rtems_interrupt_level level;
61
62  rtems_interrupt_disable( level);
63
64  printk( "%s PANIC %s\n", _RTEMS_version, s);
65
66  while (1) {
67    /* Do nothing */
68  }
69}
70
71void _BSP_Fatal_error( unsigned n)
72{
73  rtems_interrupt_level level;
74
75  rtems_interrupt_disable( level);
76
77  printk( "%s PANIC ERROR %u\n", _RTEMS_version, n);
78
79  while (1) {
80    /* Do nothing */
81  }
82}
83
84const char *bsp_tqm_get_cib_string( const char *cib_id)
85{
86  char srch_pattern[10] = "";
87  char *fnd_str;
88  /*
89   * create search pattern
90   */
91  strcat(srch_pattern,"-");
92  strncat(srch_pattern,
93          cib_id,
94          sizeof(srch_pattern)-1-strlen(srch_pattern));
95  strncat(srch_pattern,
96          " ",
97          sizeof(srch_pattern)-1-strlen(srch_pattern));
98  /*
99   * search for pattern in info block (CIB)
100   */
101  fnd_str = strstr((const char *)TQM_CONF_INFO_BLOCK_ADDR,srch_pattern);
102
103  if (fnd_str == NULL) {
104    return NULL;
105  }
106  else {
107    /*
108     * found? then advance behind search pattern
109     */
110    return fnd_str + strlen(srch_pattern);
111  }
112}
113
114rtems_status_code  bsp_tqm_get_cib_uint32( const char *cib_id,
115                                           uint32_t   *result)
116{
117  const char *item_ptr;
118  char *end_ptr;
119  item_ptr = bsp_tqm_get_cib_string(cib_id);
120  if (item_ptr == NULL) {
121    return RTEMS_INVALID_ID;
122  }
123  /*
124   * convert string to uint32
125   */
126  *result = strtoul(item_ptr,&end_ptr,10);
127  return RTEMS_SUCCESSFUL;
128}
129
130void bsp_start( void)
131{
132  rtems_status_code sc = RTEMS_SUCCESSFUL;
133  ppc_cpu_id_t myCpu;
134  ppc_cpu_revision_t myCpuRevision;
135
136  uintptr_t interrupt_stack_start = (uintptr_t) bsp_interrupt_stack_start;
137  uintptr_t interrupt_stack_size = (uintptr_t) bsp_interrupt_stack_size;
138
139  /*
140   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
141   * store the result in global variables so that it can be used latter...
142   */
143  myCpu = get_ppc_cpu_type();
144  myCpuRevision = get_ppc_cpu_revision();
145
146  /* Basic CPU initialization */
147  cpu_init();
148
149  /*
150   * Enable instruction and data caches. Do not force writethrough mode.
151   */
152
153#if BSP_INSTRUCTION_CACHE_ENABLED
154  rtems_cache_enable_instruction();
155#endif
156
157#if BSP_DATA_CACHE_ENABLED
158  rtems_cache_enable_data();
159#endif
160
161  /*
162   * This is evaluated during runtime, so it should be ok to set it
163   * before we initialize the drivers.
164   */
165
166  /* Initialize some device driver parameters */
167  /*
168   * get the (internal) bus frequency
169   * NOTE: the external bus may be clocked at a lower speed
170   * but this does not concern the internal units like PIT,
171   * DEC, baudrate generator etc)
172   */
173  if (RTEMS_SUCCESSFUL !=
174      bsp_tqm_get_cib_uint32("cu",
175                             &BSP_bus_frequency)) {
176    BSP_panic("Cannot determine BUS frequency\n");
177  }
178
179  bsp_time_base_frequency = BSP_bus_frequency / 16;
180  bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
181  bsp_timer_least_valid = 3;
182  bsp_timer_average_overhead = 3;
183
184  /* Initialize exception handler */
185  sc = ppc_exc_initialize(
186    PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
187    interrupt_stack_start,
188    interrupt_stack_size
189  );
190  if (sc != RTEMS_SUCCESSFUL) {
191    BSP_panic("cannot initialize exceptions");
192  }
193
194  /* Initalize interrupt support */
195  sc = bsp_interrupt_initialize();
196  if (sc != RTEMS_SUCCESSFUL) {
197    BSP_panic("cannot intitialize interrupts");
198  }
199
200#ifdef SHOW_MORE_INIT_SETTINGS
201  printk("Exit from bspstart\n");
202#endif
203}
Note: See TracBrowser for help on using the repository browser.