1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// plf_misc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL platform miscellaneous functions
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): nickg
|
44 |
|
|
// Contributors: nickg, gthomas, jlarmour
|
45 |
|
|
// Date: 2000-03-10
|
46 |
|
|
// Purpose: HAL miscellaneous functions
|
47 |
|
|
// Description: This file contains miscellaneous functions provided by the
|
48 |
|
|
// HAL.
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//========================================================================*/
|
53 |
|
|
|
54 |
|
|
#include <pkgconf/hal.h>
|
55 |
|
|
|
56 |
|
|
#include <cyg/infra/cyg_type.h> // Base types
|
57 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
58 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
59 |
|
|
|
60 |
|
|
#include <cyg/hal/hal_arch.h> // architectural definitions
|
61 |
|
|
|
62 |
|
|
#include <cyg/hal/hal_intr.h> // Interrupt handling
|
63 |
|
|
#include <cyg/hal/v850_common.h> // Hardware definitions
|
64 |
|
|
|
65 |
|
|
#include <cyg/hal/hal_if.h> // ROM monitor interfaces
|
66 |
|
|
|
67 |
|
|
#include <cyg/infra/diag.h> // diag_printf
|
68 |
|
|
|
69 |
|
|
extern void show_hex4(unsigned long val);
|
70 |
|
|
extern void show_hex1(unsigned long val);
|
71 |
|
|
extern void show_8bit_reg(void *addr);
|
72 |
|
|
extern void show_led(int p);
|
73 |
|
|
|
74 |
|
|
void
|
75 |
|
|
cyg_hal_platform_hardware_init(void)
|
76 |
|
|
{
|
77 |
|
|
hal_if_init(); // Initialize GDB[ROM]/eCos interfaces
|
78 |
|
|
show_led(' ');
|
79 |
|
|
show_led(' ');
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
void
|
83 |
|
|
show_hex4(unsigned long val)
|
84 |
|
|
{
|
85 |
|
|
show_hex1(val>>24);
|
86 |
|
|
show_hex1(val>>16);
|
87 |
|
|
show_hex1(val>>8);
|
88 |
|
|
show_hex1(val);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void
|
92 |
|
|
show_hex1(unsigned long val)
|
93 |
|
|
{
|
94 |
|
|
static char *hex = "0123456789ABCDEF";
|
95 |
|
|
show_led(hex[(val & 0xF0) >> 4]);
|
96 |
|
|
show_led(hex[val & 0x0F]);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
void
|
100 |
|
|
show_8bit_reg(void *addr)
|
101 |
|
|
{
|
102 |
|
|
unsigned char *reg = (unsigned char *)addr;
|
103 |
|
|
unsigned char val = *reg;
|
104 |
|
|
show_led(' ');
|
105 |
|
|
show_hex4((unsigned long)reg);
|
106 |
|
|
show_led('=');
|
107 |
|
|
show_hex1((unsigned long)val);
|
108 |
|
|
show_led('/');
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
#define SEG_0 0x00
|
112 |
|
|
#define SEG_A 0x01
|
113 |
|
|
#define SEG_B 0x02
|
114 |
|
|
#define SEG_C 0x04
|
115 |
|
|
#define SEG_D 0x08
|
116 |
|
|
#define SEG_E 0x10
|
117 |
|
|
#define SEG_F 0x20
|
118 |
|
|
#define SEG_G 0x40
|
119 |
|
|
#define SEG_H 0x80
|
120 |
|
|
#define LED(a,b,c,d,e,f,g,h) SEG_##a|SEG_##b|SEG_##c|SEG_##d|SEG_##e|SEG_##f|SEG_##g|SEG_##h
|
121 |
|
|
|
122 |
|
|
static unsigned char led_bits[] = {
|
123 |
|
|
LED(H,0,0,0,0,0,0,0), // 0x20
|
124 |
|
|
0x30, // 0x21 !
|
125 |
|
|
0x00, // 0x22 @
|
126 |
|
|
0x00, // 0x23
|
127 |
|
|
0x00, // 0x24
|
128 |
|
|
0x00, // 0x25
|
129 |
|
|
0x00, // 0x26
|
130 |
|
|
0x00, // 0x27
|
131 |
|
|
0x00, // 0x28
|
132 |
|
|
0x00, // 0x29
|
133 |
|
|
0x00, // 0x2A
|
134 |
|
|
0x00, // 0x2B
|
135 |
|
|
0x00, // 0x2C
|
136 |
|
|
0x00, // 0x2D
|
137 |
|
|
0x00, // 0x2E
|
138 |
|
|
LED(E,G,B,0,0,0,0,0), // 0x2F
|
139 |
|
|
LED(A,B,C,D,E,F,0,0), // 0x30
|
140 |
|
|
LED(0,B,C,0,0,0,0,0), // 0x31
|
141 |
|
|
LED(A,B,G,E,D,0,0,0), // 0x32
|
142 |
|
|
LED(A,B,G,C,D,0,0,0), // 0x33
|
143 |
|
|
LED(F,G,B,C,0,0,0,0), // 0x34
|
144 |
|
|
LED(A,F,G,C,D,0,0,0), // 0x35
|
145 |
|
|
LED(A,F,G,C,D,E,0,0), // 0x36
|
146 |
|
|
LED(A,B,C,0,0,0,0,0), // 0x37
|
147 |
|
|
LED(A,B,C,D,E,F,G,0), // 0x38
|
148 |
|
|
LED(A,F,G,B,C,0,0,0), // 0x39
|
149 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x3A
|
150 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x3B
|
151 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x3C
|
152 |
|
|
LED(D,G,0,0,0,0,0,0), // 0x3D - =
|
153 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x3E
|
154 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x3F
|
155 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x40
|
156 |
|
|
LED(A,F,G,B,E,C,0,0), // 0x41 - A
|
157 |
|
|
LED(F,G,E,D,C,0,0,0), // 0x42 - B
|
158 |
|
|
LED(A,F,E,D,0,0,0,0), // 0x43 - C
|
159 |
|
|
LED(B,G,E,D,C,0,0,0), // 0x44 - D
|
160 |
|
|
LED(A,F,G,E,D,0,0,0), // 0x45 - E
|
161 |
|
|
LED(A,F,G,E,0,0,0,0), // 0x46 - F
|
162 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x47
|
163 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x48
|
164 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x49
|
165 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4A
|
166 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4B
|
167 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4C
|
168 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4D
|
169 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4E
|
170 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x4F
|
171 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x50
|
172 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x51
|
173 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x52
|
174 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x53
|
175 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x54
|
176 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x55
|
177 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x56
|
178 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x57
|
179 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x58
|
180 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x59
|
181 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5A
|
182 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5B
|
183 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5C
|
184 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5D
|
185 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5E
|
186 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x5F
|
187 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x60
|
188 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x61
|
189 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x62
|
190 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x63
|
191 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x64
|
192 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x65
|
193 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x66
|
194 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x67
|
195 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x68
|
196 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x69
|
197 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6A
|
198 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6B
|
199 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6C
|
200 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6D
|
201 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6E
|
202 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x6F
|
203 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x70
|
204 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x71
|
205 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x72
|
206 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x73
|
207 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x74
|
208 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x75
|
209 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x76
|
210 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x77
|
211 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x78
|
212 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x79
|
213 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x7A
|
214 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x7B
|
215 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x7C
|
216 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x7D
|
217 |
|
|
LED(A,0,0,0,0,0,0,0), // 0x7E - ~
|
218 |
|
|
LED(0,0,0,0,0,0,0,0), // 0x7F
|
219 |
|
|
};
|
220 |
|
|
|
221 |
|
|
#define DELAY 10000
|
222 |
|
|
|
223 |
|
|
void
|
224 |
|
|
show_led(int p)
|
225 |
|
|
{
|
226 |
|
|
volatile unsigned char *led = (volatile unsigned char *)0xFFFFF014;
|
227 |
|
|
int j;
|
228 |
|
|
for (j = 0; j < DELAY; j++) {
|
229 |
|
|
*led = led_bits[p-0x20];
|
230 |
|
|
}
|
231 |
|
|
for (j = 0; j < DELAY*3; j++) {
|
232 |
|
|
*led = 0;
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
void
|
237 |
|
|
FAIL(char *m)
|
238 |
|
|
{
|
239 |
|
|
static char *fail_reason;
|
240 |
|
|
fail_reason = m;
|
241 |
|
|
#if 0
|
242 |
|
|
while (1) {
|
243 |
|
|
show_led('~');
|
244 |
|
|
show_hex4(m);
|
245 |
|
|
show_led('/');
|
246 |
|
|
}
|
247 |
|
|
#else
|
248 |
|
|
diag_printf("FAIL: %s\n", m);
|
249 |
|
|
#endif
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
void
|
253 |
|
|
ALERT(char *m)
|
254 |
|
|
{
|
255 |
|
|
static char *alert_reason;
|
256 |
|
|
alert_reason = m;
|
257 |
|
|
#if 0
|
258 |
|
|
show_led('~');
|
259 |
|
|
show_led('~');
|
260 |
|
|
show_hex4(m);
|
261 |
|
|
show_led('/');
|
262 |
|
|
#else
|
263 |
|
|
diag_printf("ALERT: %s\n", m);
|
264 |
|
|
#endif
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
//
|
268 |
|
|
// Clock support, using 16 bit timer TM1
|
269 |
|
|
//
|
270 |
|
|
|
271 |
|
|
CYG_WORD32 cyg_hal_clock_period;
|
272 |
|
|
|
273 |
|
|
void
|
274 |
|
|
hal_clock_initialize(cyg_int32 period)
|
275 |
|
|
{
|
276 |
|
|
volatile unsigned char *tmc = (volatile unsigned char *)V850_REG_TMC1;
|
277 |
|
|
volatile unsigned char *crc = (volatile unsigned char *)V850_REG_CRC1;
|
278 |
|
|
volatile unsigned char *prm = (volatile unsigned char *)V850_REG_PRM10;
|
279 |
|
|
volatile unsigned short *cmp0 = (volatile unsigned short *)V850_REG_CR10;
|
280 |
|
|
volatile unsigned short *cmp1 = (volatile unsigned short *)V850_REG_CR11;
|
281 |
|
|
*tmc = 0x00; // Halt timer
|
282 |
|
|
*crc = 0x00; // Select simple compare mode
|
283 |
|
|
*prm = 0x01; // System clock / 4
|
284 |
|
|
*cmp0 = period;
|
285 |
|
|
*cmp1 = period;
|
286 |
|
|
*tmc = 0x0C; // Continuous, reset mode (interval timer)
|
287 |
|
|
cyg_hal_clock_period = period;
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
void
|
291 |
|
|
hal_clock_reset(int vector, cyg_uint32 period)
|
292 |
|
|
{
|
293 |
|
|
hal_clock_initialize(period);
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
//
|
297 |
|
|
// Return the number of clock "ticks" since last interrupt
|
298 |
|
|
//
|
299 |
|
|
cyg_uint32 hal_clock_read(void)
|
300 |
|
|
{
|
301 |
|
|
volatile unsigned short *timer = (volatile unsigned short *)V850_REG_TM1;
|
302 |
|
|
return (cyg_uint32)*timer;
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
extern void _hal_thread_load_context(HAL_SavedRegisters **to)
|
307 |
|
|
CYGBLD_ATTRIB_NORET;
|
308 |
|
|
extern void _hal_thread_switch_context(HAL_SavedRegisters **to, HAL_SavedRegisters **from);
|
309 |
|
|
|
310 |
|
|
void hal_thread_load_context(CYG_ADDRESS to)
|
311 |
|
|
{
|
312 |
|
|
HAL_SavedRegisters **new_context = (HAL_SavedRegisters **)to;
|
313 |
|
|
#if 0
|
314 |
|
|
diag_printf("Load context: %x\n", *new_context);
|
315 |
|
|
show_regs(*new_context);
|
316 |
|
|
#endif
|
317 |
|
|
_hal_thread_load_context(new_context);
|
318 |
|
|
}
|
319 |
|
|
|
320 |
|
|
void hal_thread_switch_context(CYG_ADDRESS to, CYG_ADDRESS from)
|
321 |
|
|
{
|
322 |
|
|
HAL_SavedRegisters **old_context = (HAL_SavedRegisters **)from;
|
323 |
|
|
HAL_SavedRegisters **new_context = (HAL_SavedRegisters **)to;
|
324 |
|
|
#if 0
|
325 |
|
|
diag_printf("Switch context - old: %x, new: %x\n", *old_context, *new_context);
|
326 |
|
|
show_regs(*new_context);
|
327 |
|
|
#endif
|
328 |
|
|
_hal_thread_switch_context(new_context, old_context);
|
329 |
|
|
}
|
330 |
|
|
|