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