OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [v85x/] [ceb_v850/] [current/] [src/] [plf_misc.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.