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, ... */ |
---|
40 | uint32_t BSP_bus_frequency; |
---|
41 | |
---|
42 | /* Configuration parameter for clock driver */ |
---|
43 | uint32_t bsp_time_base_frequency; |
---|
44 | |
---|
45 | /* Legacy */ |
---|
46 | uint32_t bsp_clicks_per_usec; /* for PIT driver: OSCCLK */ |
---|
47 | |
---|
48 | /* for timer: */ |
---|
49 | uint32_t bsp_timer_average_overhead; /* Average overhead of timer in ticks */ |
---|
50 | uint32_t bsp_timer_least_valid; /* Least valid number from timer */ |
---|
51 | bool 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 | */ |
---|
56 | extern void cpu_init( void); |
---|
57 | |
---|
58 | void 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 | |
---|
71 | void _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 | |
---|
84 | const 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 | |
---|
114 | rtems_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 | |
---|
130 | void bsp_start( void) |
---|
131 | { |
---|
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 | ppc_exc_initialize( |
---|
185 | PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
186 | interrupt_stack_start, |
---|
187 | interrupt_stack_size |
---|
188 | ); |
---|
189 | |
---|
190 | /* Initalize interrupt support */ |
---|
191 | bsp_interrupt_initialize(); |
---|
192 | |
---|
193 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
194 | printk("Exit from bspstart\n"); |
---|
195 | #endif |
---|
196 | } |
---|