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