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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [stb/] [current/] [src/] [hal_diag.c] - Blame information for rev 811

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*=============================================================================
2
//
3
//      hal_diag.c
4
//
5
//      HAL diagnostic output code
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
44
// Date:        1998-03-02
45
// Purpose:     HAL diagnostic output
46
// Description: Implementations of HAL diagnostic output support.
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
 
54
#include <cyg/infra/cyg_type.h>          // base types
55
#include <cyg/infra/cyg_trac.h>         // tracing macros
56
#include <cyg/infra/cyg_ass.h>          // assertion macros
57
 
58
#include <cyg/hal/hal_diag.h>
59
#include <cyg/hal/hal_intr.h>
60
#include <cyg/hal/hal_misc.h>
61
 
62
/*---------------------------------------------------------------------------*/
63
/* Select default diag channel to use                                        */
64
 
65
//#define CYG_KERNEL_DIAG_ROMART
66
//#define CYG_KERNEL_DIAG_SERIAL0
67
//#define CYG_KERNEL_DIAG_SERIAL1
68
//#define CYG_KERNEL_DIAG_SERIAL2
69
//#define CYG_KERNEL_DIAG_BUFFER
70
//#define CYG_KERNEL_DIAG_GDB
71
 
72
#if !defined(CYG_KERNEL_DIAG_SERIAL0) && \
73
    !defined(CYG_KERNEL_DIAG_SERIAL1) && \
74
    !defined(CYG_KERNEL_DIAG_SERIAL2) && \
75
    !defined(CYG_KERNEL_DIAG_ROMART)
76
 
77
#if defined(CYGSEM_HAL_USE_ROM_MONITOR_GDB_stubs)
78
 
79
#define CYG_KERNEL_DIAG_SERIAL0
80
#define CYG_KERNEL_DIAG_GDB
81
 
82
#else
83
 
84
#define CYG_KERNEL_DIAG_SERIAL0
85
 
86
#endif
87
 
88
#endif
89
 
90
//#define CYG_HAL_MN10300_STB_SERIAL2
91
 
92
/*---------------------------------------------------------------------------*/
93
// MN10300 Serial line
94
 
95
#if defined(CYG_HAL_MN10300_STB_SERIAL0) || defined(CYG_KERNEL_DIAG_SERIAL0)
96
 
97
// We use serial0 on AM33
98
#define SERIAL0_CR       ((volatile cyg_uint16 *)0xd4002000)
99
#define SERIAL0_ICR      ((volatile cyg_uint8 *) 0xd4002004)
100
#define SERIAL0_TXR      ((volatile cyg_uint8 *) 0xd4002008)
101
#define SERIAL0_RXR      ((volatile cyg_uint8 *) 0xd4002009)
102
#define SERIAL0_SR       ((volatile cyg_uint16 *)0xd400200c)
103
 
104
// Timer 2 provides baud rate divisor
105
#define TIMER0_MD       ((volatile cyg_uint8 *)0xd4003002)
106
#define TIMER0_BR       ((volatile cyg_uint8 *)0xd4003012)
107
#define TIMER0_CR       ((volatile cyg_uint8 *)0xd4003022)
108
 
109
// Timer 0 provides a prescaler for lower baud rates
110
#define HW_TIMER0_MD       ((volatile cyg_uint8 *)0xd4003000)
111
#define HW_TIMER0_BR       ((volatile cyg_uint8 *)0xd4003010)
112
#define HW_TIMER0_CR       ((volatile cyg_uint8 *)0xd4003020)
113
 
114
#define SIO_LSTAT_TRDY  0x20
115
#define SIO_LSTAT_RRDY  0x10
116
 
117
#define SERIAL_CR_TXE   0x8000
118
 
119
void hal_diag_init_serial0(void)
120
{
121
#if 1    
122
    // 99 translates to 38400 baud.
123
    *TIMER0_BR = 99;
124
    // Timer0 sourced from IOCLK
125
    *TIMER0_MD = 0x80;
126
#else
127
    // 1 and 198 translate into 9800 baud
128
    *TIMER0_BR = 1;
129
    *TIMER0_MD = 0x84;          // source = timer 0 overflow
130
    *HW_TIMER0_BR = 198;        // timer 0 base register
131
    *HW_TIMER0_CR = 0x80;       // source from ioclk
132
#endif
133
 
134
    // No interrupts for now.
135
    *SERIAL0_ICR = 0x00;
136
 
137
    // Source from timer 1, 8bit chars, enable tx and rx
138
    *SERIAL0_CR = 0xc085;
139
}
140
 
141
void hal_diag_write_char_serial0(char c)
142
{
143
    register volatile cyg_uint16 *volatile tty_status = SERIAL0_SR;
144
    register volatile cyg_uint8 *volatile tty_tx = SERIAL0_TXR;
145
 
146
    while( (*tty_status & SIO_LSTAT_TRDY) != 0 ) continue;
147
 
148
    *tty_tx = c;
149
}
150
 
151
void hal_diag_drain_serial0(void)
152
{
153
    register volatile cyg_uint16 *volatile tty_status = SERIAL0_SR;
154
 
155
    while( (*tty_status & SIO_LSTAT_TRDY) != 0 ) continue;
156
}
157
 
158
void hal_diag_read_char_serial0(char *c)
159
{
160
    register volatile cyg_uint16 *volatile tty_status = SERIAL0_SR;
161
    register volatile cyg_uint8 *volatile tty_rx = SERIAL0_RXR;
162
 
163
    while( (*tty_status & SIO_LSTAT_RRDY) == 0 ) continue;
164
 
165
    *c = *tty_rx;
166
 
167
    // We must ack the interrupt caused by that read to avoid
168
    // confusing the GDB stub ROM.
169
    HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_INTERRUPT_SERIAL_0_RX );
170
}
171
 
172
#if defined(CYG_KERNEL_DIAG_SERIAL0)
173
 
174
#define hal_diag_init_serial hal_diag_init_serial0
175
#define hal_diag_write_char_serial hal_diag_write_char_serial0
176
#define hal_diag_drain_serial hal_diag_drain_serial0
177
#define hal_diag_read_char_serial hal_diag_read_char_serial0
178
 
179
#endif
180
 
181
#endif
182
 
183
/*---------------------------------------------------------------------------*/
184
// MN10300 Serial line
185
 
186
#if defined(CYG_HAL_MN10300_STB_SERIAL1) || defined(CYG_KERNEL_DIAG_SERIAL1)
187
 
188
// We use serial1 on MN103002
189
#define SERIAL1_CR       ((volatile cyg_uint16 *)0xd4002010)
190
#define SERIAL1_ICR      ((volatile cyg_uint8 *) 0xd4002014)
191
#define SERIAL1_TXR      ((volatile cyg_uint8 *) 0xd4002018)
192
#define SERIAL1_RXR      ((volatile cyg_uint8 *) 0xd4002019)
193
#define SERIAL1_SR       ((volatile cyg_uint16 *)0xd400201c)
194
 
195
// Timer 1 provided baud rate divisor
196
#define TIMER1_MD       ((volatile cyg_uint8 *)0xd4003001)
197
#define TIMER1_BR       ((volatile cyg_uint8 *)0xd4003011)
198
#define TIMER1_CR       ((volatile cyg_uint8 *)0xd4003021)
199
 
200
// Timer 0 provides a prescaler for lower baud rates
201
#define HW_TIMER0_MD       ((volatile cyg_uint8 *)0xd4003000)
202
#define HW_TIMER0_BR       ((volatile cyg_uint8 *)0xd4003010)
203
#define HW_TIMER0_CR       ((volatile cyg_uint8 *)0xd4003020)
204
 
205
#define SIO1_LSTAT_TRDY  0x20
206
#define SIO1_LSTAT_RRDY  0x10
207
 
208
#define SERIAL_CR_TXE   0x8000
209
 
210
void hal_diag_init_serial1(void)
211
{
212
#if 1    
213
    // 99 translates to 38400 baud.
214
    *TIMER1_BR = 99;
215
 
216
    // Timer1 sourced from IOCLK
217
    *TIMER1_MD = 0x80;
218
 
219
#else
220
 
221
    // 1 and 198 translate into 9800 baud
222
    *TIMER1_BR = 1;
223
    *TIMER1_MD = 0x84;          // source = timer 0 overflow
224
    *HW_TIMER0_BR = 198;        // timer 0 base register
225
    *HW_TIMER0_CR = 0x80;       // source from ioclk
226
#endif
227
 
228
    // No interrupts for now.
229
    *SERIAL1_ICR = 0x00;
230
 
231
    // Source from timer 1, 8bit chars, enable tx and rx
232
    *SERIAL1_CR = 0xc084;
233
}
234
 
235
void hal_diag_write_char_serial1(char c)
236
{
237
    register volatile cyg_uint16 *volatile tty_status = SERIAL1_SR;
238
    register volatile cyg_uint8 *volatile tty_tx = SERIAL1_TXR;
239
 
240
    while( (*tty_status & SIO1_LSTAT_TRDY) != 0 ) continue;
241
 
242
    *tty_tx = c;
243
}
244
 
245
void hal_diag_drain_serial1(void)
246
{
247
    register volatile cyg_uint16 *volatile tty_status = SERIAL1_SR;
248
 
249
    while( (*tty_status & SIO1_LSTAT_TRDY) != 0 ) continue;
250
}
251
 
252
void hal_diag_read_char_serial1(char *c)
253
{
254
    register volatile cyg_uint16 *volatile tty_status = SERIAL1_SR;
255
    register volatile cyg_uint8 *volatile tty_rx = SERIAL1_RXR;
256
 
257
    while( (*tty_status & SIO1_LSTAT_RRDY) == 0 ) continue;
258
 
259
    *c = *tty_rx;
260
 
261
    // We must ack the interrupt caused by that read to avoid
262
    // confusing the GDB stub ROM.
263
    HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_INTERRUPT_SERIAL_1_RX );
264
}
265
 
266
#if defined(CYG_KERNEL_DIAG_SERIAL1)
267
 
268
#define hal_diag_init_serial hal_diag_init_serial1
269
#define hal_diag_write_char_serial hal_diag_write_char_serial1
270
#define hal_diag_drain_serial hal_diag_drain_serial1
271
#define hal_diag_read_char_serial hal_diag_read_char_serial1
272
 
273
#endif
274
 
275
#endif
276
 
277
/*---------------------------------------------------------------------------*/
278
 
279
#if defined(CYG_HAL_MN10300_STB_SERIAL2) || defined(CYG_KERNEL_DIAG_SERIAL2)
280
 
281
// We use serial2 on MN103002
282
#define SERIAL2_CR       ((volatile cyg_uint16 *)0xd4002020)
283
#define SERIAL2_ICR      ((volatile cyg_uint8 *) 0xd4002024)
284
#define SERIAL2_TXR      ((volatile cyg_uint8 *) 0xd4002028)
285
#define SERIAL2_RXR      ((volatile cyg_uint8 *) 0xd4002029)
286
#define SERIAL2_SR       ((volatile cyg_uint8 *) 0xd400202c)
287
#define SERIAL2_TR       ((volatile cyg_uint8 *) 0xd400202d)
288
 
289
// Timer 3 provides baud rate divisor
290
#define TIMER2_MD       ((volatile cyg_uint8 *)0xd4003003)
291
#define TIMER2_BR       ((volatile cyg_uint8 *)0xd4003013)
292
#define TIMER2_CR       ((volatile cyg_uint8 *)0xd4003023)
293
 
294
#define SIO2_LSTAT_TRDY  0x20
295
#define SIO2_LSTAT_RRDY  0x10
296
 
297
void hal_diag_init_serial2(void)
298
{
299
#if 0
300
    {
301
        int i,j;
302
        for( j = 1; j < 255; j++ )
303
        {
304
            for(i = 1; i < 127; i++)
305
            {
306
                *TIMER2_BR = j;
307
                *SERIAL2_TR = i;
308
 
309
                // Timer2 sourced from IOCLK
310
                *TIMER2_MD = 0x80;
311
 
312
                // No interrupts for now.
313
                *SERIAL2_ICR = 0x00;
314
 
315
                // Source from timer 2, 8bit chars, enable tx and rx
316
                *SERIAL2_CR = 0xc081;
317
 
318
                diag_printf("\r\n<%03d,%03d>1234567890abcdefgh<%03d,%03d>\r\n",j,i,j,i);
319
            }
320
        }
321
    }
322
#endif
323
 
324
    // 7 and 102 translate to 38400 baud.
325
    // The AM33 documentation says that these values should be 7 and 113.
326
    // I have no explanation as to why there is such a discrepancy between the
327
    // documentation and the hardware.
328
 
329
    *TIMER2_BR = 7;
330
    *SERIAL2_TR = 102;
331
 
332
    // Timer2 sourced from IOCLK
333
    *TIMER2_MD = 0x80;
334
 
335
    // No interrupts for now.
336
    *SERIAL2_ICR = 0x00;
337
 
338
    // Source from timer 3, 8bit chars, enable tx and rx
339
    *SERIAL2_CR = 0xc083;
340
 
341
}
342
 
343
void hal_diag_write_char_serial2(char c)
344
{
345
    register volatile cyg_uint8 *volatile tty_status = SERIAL2_SR;
346
    register volatile cyg_uint8 *volatile tty_tx = SERIAL2_TXR;
347
 
348
    while( (*tty_status & SIO2_LSTAT_TRDY) != 0 ) continue;
349
 
350
    *tty_tx = c;
351
}
352
 
353
void hal_diag_drain_serial2(void)
354
{
355
    register volatile cyg_uint8 *volatile tty_status = SERIAL2_SR;
356
 
357
    while( (*tty_status & SIO2_LSTAT_TRDY) != 0 ) continue;
358
}
359
 
360
void hal_diag_read_char_serial2(char *c)
361
{
362
    register volatile cyg_uint8 *volatile tty_status = SERIAL2_SR;
363
    register volatile cyg_uint8 *volatile tty_rx = SERIAL2_RXR;
364
 
365
    while( (*tty_status & SIO2_LSTAT_RRDY) == 0 ) continue;
366
 
367
    *c = *tty_rx;
368
 
369
    // We must ack the interrupt caused by that read to avoid
370
    // confusing the GDB stub ROM.
371
    HAL_INTERRUPT_ACKNOWLEDGE( CYGNUM_HAL_INTERRUPT_SERIAL_2_RX );
372
 
373
 
374
}
375
 
376
#if defined(CYG_KERNEL_DIAG_SERIAL2)
377
 
378
#define hal_diag_init_serial hal_diag_init_serial2
379
#define hal_diag_write_char_serial hal_diag_write_char_serial2
380
#define hal_diag_drain_serial hal_diag_drain_serial2
381
#define hal_diag_read_char_serial hal_diag_read_char_serial2
382
 
383
#endif
384
 
385
#endif
386
 
387
/*---------------------------------------------------------------------------*/
388
 
389
 
390
#if defined(CYG_KERNEL_DIAG_BUFFER)
391
 
392
char hal_diag_buffer[10000];
393
int hal_diag_buffer_pos;
394
 
395
void hal_diag_init_buffer(void)
396
{
397
    hal_diag_buffer_pos = 0;
398
}
399
 
400
void hal_diag_write_char_buffer(char c)
401
{
402
    hal_diag_buffer[hal_diag_buffer_pos++] = c;
403
    if (hal_diag_buffer_pos >= sizeof(hal_diag_buffer) )
404
        hal_diag_buffer_pos = 0;
405
}
406
 
407
void hal_diag_drain_buffer(void)
408
{
409
}
410
 
411
void hal_diag_read_char_buffer(char *c)
412
{
413
    *c = '\n';
414
}
415
 
416
#define hal_diag_init_serial hal_diag_init_buffer
417
#define hal_diag_write_char_serial hal_diag_write_char_buffer
418
#define hal_diag_drain_serial hal_diag_drain_buffer
419
#define hal_diag_read_char_serial hal_diag_read_char_buffer
420
 
421
#endif
422
 
423
 
424
/*---------------------------------------------------------------------------*/
425
 
426
void hal_diag_init(void)
427
{
428
    hal_diag_init_serial();
429
}
430
 
431
void hal_diag_write_char(char c)
432
{
433
#ifdef CYG_KERNEL_DIAG_GDB
434
 
435
    static char line[100];
436
    static int pos = 0;
437
 
438
    // No need to send CRs
439
    if( c == '\r' ) return;
440
 
441
    line[pos++] = c;
442
 
443
    if( c == '\n' || pos == sizeof(line) )
444
    {
445
        // Disable interrupts. This prevents GDB trying to interrupt us
446
        // while we are in the middle of sending a packet. The serial
447
        // receive interrupt will be seen when we re-enable interrupts
448
        // later.
449
 
450
        CYG_INTERRUPT_STATE oldstate;
451
        CYG_BYTE wdcr;
452
        HAL_DISABLE_INTERRUPTS(oldstate);
453
 
454
        // Beacuse of problems with NT on the testfarm, we also have
455
        // to disable the watchdog here. This only matters in the
456
        // watchdog tests. And yes, this sends my irony meter off the
457
        // scale too.
458
 
459
        HAL_READ_UINT8( 0xC0001002, wdcr );
460
        HAL_WRITE_UINT8( 0xC0001002, wdcr&0x3F );
461
 
462
        while(1)
463
        {
464
            static char hex[] = "0123456789ABCDEF";
465
            cyg_uint8 csum = 0;
466
            int i;
467
 
468
            hal_diag_write_char_serial('$');
469
            hal_diag_write_char_serial('O');
470
            csum += 'O';
471
            for( i = 0; i < pos; i++ )
472
            {
473
                char ch = line[i];
474
                char h = hex[(ch>>4)&0xF];
475
                char l = hex[ch&0xF];
476
                hal_diag_write_char_serial(h);
477
                hal_diag_write_char_serial(l);
478
                csum += h;
479
                csum += l;
480
            }
481
            hal_diag_write_char_serial('#');
482
            hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
483
            hal_diag_write_char_serial(hex[csum&0xF]);
484
 
485
 
486
            {
487
                char c1;
488
 
489
                hal_diag_read_char_serial( &c1 );
490
 
491
                if( c1 == '+' ) break;
492
 
493
 
494
                if( cyg_hal_is_break( &c1, 1 ) )
495
                    cyg_hal_user_break( NULL );
496
 
497
            }
498
        }
499
 
500
        pos = 0;
501
 
502
        // Wait for tx buffer to drain
503
        hal_diag_drain_serial();
504
 
505
        // And re-enable interrupts
506
        HAL_RESTORE_INTERRUPTS(oldstate);
507
        HAL_WRITE_UINT8( 0xC0001002, wdcr );
508
    }
509
 
510
#else
511
    hal_diag_write_char_serial(c);
512
#endif    
513
}
514
 
515
 
516
 
517
 
518
void hal_diag_read_char(char *c)
519
{
520
    hal_diag_read_char_serial(c);
521
}
522
 
523
 
524
/*---------------------------------------------------------------------------*/
525
/* End of hal_diag.c */

powered by: WebSVN 2.1.0

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