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 <string.h> |
---|
24 | |
---|
25 | #include <rtems/libio.h> |
---|
26 | #include <rtems/libcsupport.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | |
---|
29 | #include <libcpu/powerpc-utility.h> |
---|
30 | |
---|
31 | #include <bsp.h> |
---|
32 | #include <bsp/bootcard.h> |
---|
33 | /* #include <bsp/irq-generic.h> |
---|
34 | #include <bsp/ppc_exc_bspsupp.h> */ |
---|
35 | |
---|
36 | #ifdef BSP_HAS_TQMMON |
---|
37 | /* |
---|
38 | * FIXME: TQ Monitor structure |
---|
39 | */ |
---|
40 | #endif /* BSP_HAS_TQMMON */ |
---|
41 | |
---|
42 | /* Configuration parameters for console driver, ... */ |
---|
43 | unsigned int BSP_bus_frequency; |
---|
44 | |
---|
45 | /* Configuration parameters for clock driver, ... */ |
---|
46 | uint32_t bsp_clicks_per_usec; /* for PIT driver: OSCCLK */ |
---|
47 | uint32_t bsp_clock_speed ; /* needed for PIT driver */ |
---|
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 | void BSP_panic( char *s) |
---|
57 | { |
---|
58 | rtems_interrupt_level level; |
---|
59 | |
---|
60 | rtems_interrupt_disable( level); |
---|
61 | |
---|
62 | printk( "%s PANIC %s\n", _RTEMS_version, s); |
---|
63 | |
---|
64 | while (1) { |
---|
65 | /* Do nothing */ |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void _BSP_Fatal_error( unsigned n) |
---|
70 | { |
---|
71 | rtems_interrupt_level level; |
---|
72 | |
---|
73 | rtems_interrupt_disable( level); |
---|
74 | |
---|
75 | printk( "%s PANIC ERROR %u\n", _RTEMS_version, n); |
---|
76 | |
---|
77 | while (1) { |
---|
78 | /* Do nothing */ |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | void bsp_pretasking_hook( void) |
---|
83 | { |
---|
84 | /* Do noting */ |
---|
85 | } |
---|
86 | |
---|
87 | const char *bsp_tqm_get_cib_string( const char *cib_id) |
---|
88 | { |
---|
89 | char srch_pattern[10] = ""; |
---|
90 | char *fnd_str; |
---|
91 | /* |
---|
92 | * create search pattern |
---|
93 | */ |
---|
94 | strcat(srch_pattern,"-"); |
---|
95 | strncat(srch_pattern, |
---|
96 | cib_id, |
---|
97 | sizeof(srch_pattern)-1-strlen(srch_pattern)); |
---|
98 | strncat(srch_pattern, |
---|
99 | " ", |
---|
100 | sizeof(srch_pattern)-1-strlen(srch_pattern)); |
---|
101 | /* |
---|
102 | * search for pattern in info block (CIB) |
---|
103 | */ |
---|
104 | fnd_str = strstr(TQM_CONF_INFO_BLOCK_ADDR,srch_pattern); |
---|
105 | |
---|
106 | if (fnd_str == NULL) { |
---|
107 | return NULL; |
---|
108 | } |
---|
109 | else { |
---|
110 | /* |
---|
111 | * found? then advance behind search pattern |
---|
112 | */ |
---|
113 | return fnd_str + strlen(srch_pattern); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | rtems_status_code bsp_tqm_get_cib_uint32( const char *cib_id, |
---|
118 | uint32_t *result) |
---|
119 | { |
---|
120 | const char *item_ptr; |
---|
121 | const char *end_ptr; |
---|
122 | item_ptr = bsp_tqm_get_cib_string(cib_id); |
---|
123 | if (item_ptr == NULL) { |
---|
124 | return RTEMS_INVALID_ID; |
---|
125 | } |
---|
126 | /* |
---|
127 | * convert string to uint32 |
---|
128 | */ |
---|
129 | *result = strtoul(item_ptr,&end_ptr,10); |
---|
130 | return RTEMS_SUCCESSFUL; |
---|
131 | } |
---|
132 | |
---|
133 | void bsp_get_work_area( void **work_area_start, size_t *work_area_size, void **heap_start, size_t *heap_size) |
---|
134 | { |
---|
135 | char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved); |
---|
136 | |
---|
137 | *work_area_start = bsp_work_area_start; |
---|
138 | *work_area_size = ram_end - bsp_work_area_start; |
---|
139 | *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; |
---|
140 | *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT; |
---|
141 | } |
---|
142 | |
---|
143 | void bsp_start( void) |
---|
144 | { |
---|
145 | ppc_cpu_id_t myCpu; |
---|
146 | ppc_cpu_revision_t myCpuRevision; |
---|
147 | |
---|
148 | uint32_t interrupt_stack_start = (uint32_t) bsp_interrupt_stack_start; |
---|
149 | uint32_t interrupt_stack_size = (uint32_t) bsp_interrupt_stack_size; |
---|
150 | |
---|
151 | /* |
---|
152 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function |
---|
153 | * store the result in global variables so that it can be used latter... |
---|
154 | */ |
---|
155 | myCpu = get_ppc_cpu_type(); |
---|
156 | myCpuRevision = get_ppc_cpu_revision(); |
---|
157 | |
---|
158 | /* |
---|
159 | * Enable instruction and data caches. Do not force writethrough mode. |
---|
160 | */ |
---|
161 | |
---|
162 | #if INSTRUCTION_CACHE_ENABLE |
---|
163 | rtems_cache_enable_instruction(); |
---|
164 | #endif |
---|
165 | |
---|
166 | #if DATA_CACHE_ENABLE |
---|
167 | rtems_cache_enable_data(); |
---|
168 | #endif |
---|
169 | |
---|
170 | /* |
---|
171 | * This is evaluated during runtime, so it should be ok to set it |
---|
172 | * before we initialize the drivers. |
---|
173 | */ |
---|
174 | |
---|
175 | /* Initialize some device driver parameters */ |
---|
176 | /* |
---|
177 | * get the (internal) bus frequency |
---|
178 | * NOTE: the external bus may be clocked at a lower speed |
---|
179 | * but this does not concern the internal units like PIT, |
---|
180 | * DEC, baudrate generator etc) |
---|
181 | */ |
---|
182 | if (RTEMS_SUCCESSFUL != |
---|
183 | bsp_tqm_get_cib_uint32("cu", |
---|
184 | &BSP_bus_frequency)) { |
---|
185 | BSP_panic("Cannot determine BUS frequency\n"); |
---|
186 | } |
---|
187 | |
---|
188 | bsp_clicks_per_usec = 0; /* force to zero to control |
---|
189 | * PIT clock driver from EXTCLK |
---|
190 | */ |
---|
191 | bsp_clock_speed = BSP_bus_frequency; |
---|
192 | bsp_timer_least_valid = 3; |
---|
193 | bsp_timer_average_overhead = 3; |
---|
194 | |
---|
195 | /* Initialize exception handler */ |
---|
196 | ppc_exc_initialize(PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
197 | interrupt_stack_start, |
---|
198 | interrupt_stack_size |
---|
199 | ); |
---|
200 | |
---|
201 | /* Initalize interrupt support */ |
---|
202 | if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) { |
---|
203 | BSP_panic("Cannot intitialize interrupt support\n"); |
---|
204 | } |
---|
205 | |
---|
206 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
207 | printk("Exit from bspstart\n"); |
---|
208 | #endif |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * @brief Idle thread body. |
---|
213 | * |
---|
214 | * Replaces the one in c/src/exec/score/src/threadidlebody.c |
---|
215 | * The MSR[POW] bit is set to put the CPU into the low power mode |
---|
216 | * defined in HID0. HID0 is set during starup in start.S. |
---|
217 | */ |
---|
218 | Thread _Thread_Idle_body( uint32_t ignored) |
---|
219 | { |
---|
220 | |
---|
221 | while (1) { |
---|
222 | asm volatile ( |
---|
223 | "mfmsr 3;" |
---|
224 | "oris 3, 3, 4;" |
---|
225 | "sync;" |
---|
226 | "mtmsr 3;" |
---|
227 | "isync;" |
---|
228 | "ori 3, 3, 0;" |
---|
229 | "ori 3, 3, 0" |
---|
230 | ); |
---|
231 | } |
---|
232 | |
---|
233 | return NULL; |
---|
234 | } |
---|