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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [fr30/] [mb91301/] [current/] [src/] [hal_diag.c] - Blame information for rev 817

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):   larsi
43
// Contributors:larsi
44
// Date:        2006-07-26
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_arch.h>
59
#include <cyg/hal/hal_diag.h>
60
 
61
#include <cyg/hal/hal_intr.h>
62
 
63
#include <cyg/hal/hal_io.h>
64
 
65
#include <cyg/hal/hal_misc.h>
66
/*---------------------------------------------------------------------------*/
67
 
68
//#define CYG_KERNEL_DIAG_LCD
69
#define CYG_KERNEL_DIAG_SERIAL0 // For ROM start but see immediately below:
70
 
71
#if defined(CYGSEM_HAL_USE_ROM_MONITOR_CygMon)
72
#undef CYG_KERNEL_DIAG_SERIAL0
73
#undef CYG_KERNEL_DIAG_LCD
74
#define CYG_KERNEL_DIAG_CYGMON
75
#define CYG_KERNEL_DIAG_GDB
76
 
77
#endif
78
 
79
/*---------------------------------------------------------------------------*/
80
 
81
#if defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON)
82
 
83
/*---------------------------------------------------------------------------*/
84
// LED diag function
85
/*
86
void hal_diag_init_led(){
87
// we only init the first 4 leds here
88
        asm volatile(
89
        "ldi:8  #0xf,   r4;\n"
90
        "ldi:20 #CYG_HAL_FR30_MB91360_DDRJ,     r5;\n"
91
        "stb    r4,     @r5;\n"
92
        "ldi:20 #CYG_HAL_FR30_MB91360_PFRJ, r5;\n"
93
        "stb    r4,     @r5;\n"
94
        : : :"r4", "r5"
95
    );
96
}
97
*/
98
// static cyg_uint8 leds = 0;
99
 
100
void hal_diag_init(void){
101
 
102
    // PJ2(SCK0) & PJ1(SOT0) output, PJ0(SIN0) input
103
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_DDRJ, 0x6);
104
    // PJ2(SCK0) & PJ1(SOT0) & PJ0(SIN0) to peripheral operation
105
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_PFRJ, 0x7);
106
 
107
    // set up U-Timer
108
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_UTIMC0, 0x02);
109
    // 115200 bps
110
    HAL_WRITE_UINT16(CYG_HAL_FR30_MB91301_UTIMR0, 0x7);
111
 
112
    // setup UART
113
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_SCR0, 0x13);
114
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_SMR0, 0x30);
115
}
116
 
117
 
118
void hal_diag_led(cyg_uint8 leds)
119
{
120
 
121
    HAL_WRITE_UINT8(CYG_HAL_FR30_MB91301_PDRG, leds);
122
 
123
}
124
 
125
/*---------------------------------------------------------------------------*/
126
 
127
void hal_diag_write_char_serial0( char c)
128
{
129
    cyg_uint8 ssr;
130
 
131
    do
132
    {
133
        HAL_READ_UINT8( CYG_HAL_FR30_MB91301_SSR0 , ssr );
134
    } while (!(ssr & BIT3));
135
 
136
    HAL_WRITE_UINT8( CYG_HAL_FR30_MB91301_SODR0, c );
137
 
138
}
139
 
140
void hal_diag_write_hex_serial0(unsigned int c)
141
{
142
    unsigned char chr;
143
    int i;
144
 
145
    hal_diag_write_char_serial0('0');
146
    hal_diag_write_char_serial0('x');
147
 
148
    for(i = 28; i >= 0; i = i - 4)
149
    {
150
        chr = (c >> i) & 0xf;
151
        if (chr >= 10) chr = chr + 55;   /* for A-F */
152
        else  chr = chr + 48;  /* for 0-9 */
153
        hal_diag_write_char_serial0(chr);
154
    }
155
    hal_diag_write_char_serial0('\n');
156
    hal_diag_write_char_serial0('\r');
157
}
158
 
159
 
160
void hal_diag_drain(void)
161
{
162
    cyg_uint8 ssr;
163
 
164
        do
165
    {
166
        HAL_READ_UINT8( CYG_HAL_FR30_MB91301_SSR0 , ssr );
167
    } while (!(ssr & BIT3));
168
}
169
 
170
void hal_diag_read_char_serial0(char *c)
171
{
172
    cyg_uint8 ssr;
173
 
174
    do
175
    {
176
        HAL_READ_UINT8( CYG_HAL_FR30_MB91301_SSR0 , ssr );
177
    } while (!(ssr & BIT4));
178
 
179
    HAL_READ_UINT8( CYG_HAL_FR30_MB91301_SIDR0, *c );
180
 
181
}
182
 
183
 
184
#if defined(CYG_KERNEL_DIAG_CYGMON)
185
void hal_diag_dumb_write_char(char c)
186
#else
187
void hal_diag_write_char(char c)
188
#endif
189
{
190
#ifdef CYG_KERNEL_DIAG_GDB
191
    static char line[100];
192
    static int pos = 0;
193
//    register volatile cyg_uint16 *volatile tty_status = SERIAL1_SR;    
194
 
195
    // No need to send CRs
196
    if( c == '\r' ) return;
197
 
198
    line[pos++] = c;
199
 
200
    if( c == '\n' || pos == sizeof(line) )
201
    {
202
 
203
        // Disable interrupts. This prevents GDB trying to interrupt us
204
        // while we are in the middle of sending a packet. The serial
205
        // receive interrupt will be seen when we re-enable interrupts
206
        // later.
207
        CYG_INTERRUPT_STATE oldstate;
208
        HAL_DISABLE_INTERRUPTS(oldstate);
209
 
210
        while(1)
211
        {
212
            static char hex[] = "0123456789ABCDEF";
213
            cyg_uint8 csum = 0;
214
            int i;
215
            char c1;
216
 
217
            hal_diag_write_char_serial0('$');
218
            hal_diag_write_char_serial0('O');
219
            csum += 'O';
220
            for( i = 0; i < pos; i++ )
221
            {
222
                char ch = line[i];
223
                char h = hex[(ch>>4)&0xF];
224
                char l = hex[ch&0xF];
225
                hal_diag_write_char_serial0(h);
226
                hal_diag_write_char_serial0(l);
227
                csum += h;
228
                csum += l;
229
            }
230
            hal_diag_write_char_serial0('#');
231
            hal_diag_write_char_serial0(hex[(csum>>4)&0xF]);
232
            hal_diag_write_char_serial0(hex[csum&0xF]);
233
 
234
            hal_diag_read_char_serial0( &c1 );
235
 
236
            if( c1 == '+' ) break;
237
 
238
            {
239
                extern void cyg_hal_user_break(CYG_ADDRWORD *regs);
240
                extern cyg_bool cyg_hal_is_break(char *buf, int size);
241
                if( cyg_hal_is_break( &c1 , 1 ) )
242
                    cyg_hal_user_break( NULL );
243
            }
244
 
245
            break;
246
        }
247
 
248
        pos = 0;
249
 
250
        // Wait for all data from serial line to drain
251
        // and clear ready-to-send indication.
252
        hal_diag_drain_serial0();
253
 
254
        // And re-enable interrupts
255
        HAL_RESTORE_INTERRUPTS( oldstate );
256
 
257
    }
258
#else
259
    hal_diag_write_char_serial0(c);
260
#endif    
261
}
262
 
263
 
264
void hal_diag_read_char(char *c)
265
{
266
    for(;;)
267
    {
268
#if defined(CYG_KERNEL_DIAG_GDB) && defined(CYGSEM_HAL_USE_ROM_MONITOR)
269
 
270
        typedef void rom_read_fn(char *c);
271
        rom_read_fn *fn = ((rom_read_fn **)0x80000100)[62];
272
 
273
        fn(c);
274
 
275
#else    
276
        hal_diag_read_char_serial0(c);
277
 
278
#endif    
279
 
280
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
281
        if( *c == 3 )
282
        {
283
            // Ctrl-C: breakpoint.
284
            extern void breakpoint(void);
285
            breakpoint();
286
            continue;
287
        }
288
#elif defined(CYGSEM_HAL_USE_ROM_MONITOR)
289
        if( *c == 3 )
290
        {
291
            // Ctrl-C: breakpoint.
292
 
293
//                HAL_BREAKPOINT(_breakinst);
294
            typedef void bpt_fn(void);
295
            bpt_fn *bfn = ((bpt_fn **)0x80000100)[61];
296
 
297
            bfn();
298
            continue;
299
        }
300
#endif
301
 
302
        break;
303
    }
304
}
305
 
306
#endif // defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON)
307
 
308
 
309
#if defined(CYG_KERNEL_DIAG_CYGMON) // only
310
 
311
/* This code has been imported from the BSP module. The definitions have
312
 * been left as-is, even though there was scope for doing more, to avoid
313
 * too much drift from the original sources
314
 */
315
 
316
struct bsp_comm_procs {
317
    void *ch_data;
318
    void (*__write)(void *ch_data, const char *buf, int len);
319
    int  (*__read)(void *ch_data, char *buf, int len);
320
    void (*__putc)(void *ch_data, char ch);
321
    int  (*__getc)(void *ch_data);
322
    int  (*__control)(void *ch_data, int func, ...);
323
};
324
 
325
// This is pointed to by entry BSP_NOTVEC_BSP_COMM_PROCS:
326
typedef struct {
327
    int  version;       /* version number for future expansion */
328
    void *__ictrl_table;
329
    void *__exc_table;
330
    void *__dbg_vector;
331
    void *__kill_vector;
332
    struct bsp_comm_procs *__console_procs;
333
    struct bsp_comm_procs *__debug_procs;
334
    void *__flush_dcache;
335
    void *__flush_icache;
336
    void *__cpu_data;
337
    void *__board_data;
338
    void *__sysinfo;
339
    int  (*__set_debug_comm)(int __comm_id);
340
    int  (*__set_console_comm)(int __comm_id);
341
    int  (*__set_serial_baud)(int __comm_id, int baud);
342
    void *__dbg_data;
343
    void (*__reset)(void);
344
    int  __console_interrupt_flag;
345
} bsp_shared_t;
346
 
347
/*
348
 * Core Exception vectors.
349
 */
350
#define BSP_EXC_INT         0
351
#define BSP_EXC_TLBMOD      1
352
#define BSP_EXC_TLBL        2
353
#define BSP_EXC_TLBS        3
354
#define BSP_EXC_ADEL        4
355
#define BSP_EXC_ADES        5
356
#define BSP_EXC_IBE         6
357
#define BSP_EXC_DBE         7
358
#define BSP_EXC_SYSCALL     8
359
#define BSP_EXC_BREAK       9
360
#define BSP_EXC_ILL        10
361
#define BSP_EXC_CPU        11
362
#define BSP_EXC_OV         12
363
#define BSP_EXC_TRAP       13
364
#define BSP_EXC_VCEI       14
365
#define BSP_EXC_FPE        15
366
#define BSP_EXC_RSV16      16
367
#define BSP_EXC_RSV17      17
368
#define BSP_EXC_RSV18      18
369
#define BSP_EXC_RSV19      19
370
#define BSP_EXC_RSV20      20
371
#define BSP_EXC_RSV21      21
372
#define BSP_EXC_RSV22      22
373
#define BSP_EXC_WATCH      23
374
#define BSP_EXC_RSV24      24
375
#define BSP_EXC_RSV25      25
376
#define BSP_EXC_RSV26      26
377
#define BSP_EXC_RSV27      27
378
#define BSP_EXC_RSV28      28
379
#define BSP_EXC_RSV29      29
380
#define BSP_EXC_RSV30      30
381
#define BSP_EXC_VCED       31
382
/* tx39 debug exception */
383
#define BSP_EXC_DEBUG      32
384
#define BSP_EXC_TLB        33
385
#define BSP_EXC_NMI        34
386
/*
387
 * Hack for eCos on tx39 to set an async breakpoint.
388
 */
389
#define BSP_VEC_BP_HOOK    35
390
 
391
#define BSP_EXC_XTLB       36
392
#define BSP_EXC_CACHE      37
393
 
394
#define BSP_MAX_EXCEPTIONS 38
395
 
396
/*
397
 * Another hack for tx39 eCos compatibility.
398
 */
399
#if defined(__CPU_R3900__)
400
#define BSP_VEC_MT_DEBUG   15
401
#else
402
#define BSP_VEC_MT_DEBUG   38
403
#endif
404
 
405
#define BSP_VEC_STUB_ENTRY 39
406
#define BSP_VEC_BSPDATA    40
407
#define BSP_VEC_MAGIC      41
408
#define BSP_VEC_IRQ_CHECK  42
409
 
410
#define BSP_VEC_PAD        43
411
#define NUM_VTAB_ENTRIES   44
412
 
413
 
414
#define BSP_MAGIC_VAL      0x55aa4321
415
 
416
#define SYS_interrupt 1000
417
 
418
// These vectors should be called with:
419
//
420
//  k0 - Exception Number
421
 
422
#define CYGMON_VECTOR_TABLE_BASE 0x80000100
423
#define CYGMON_VECTOR_TABLE ((CYG_ADDRESS *)CYGMON_VECTOR_TABLE_BASE)
424
 
425
#if 0 // UNUSED
426
static int
427
hal_bsp_set_debug_comm(int arg)
428
{
429
    bsp_shared_t *shared;
430
 
431
    shared = (bsp_shared_t *)
432
        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
433
 
434
    if (0 != shared->__set_debug_comm) {
435
        return (*(shared->__set_debug_comm))(arg);
436
    }
437
    return 0;
438
}
439
 
440
static int
441
hal_bsp_set_console_comm(int arg)
442
{
443
    bsp_shared_t *shared;
444
 
445
    shared = (bsp_shared_t *)
446
        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
447
 
448
    if (0 != shared->__set_console_comm) {
449
        return (*(shared->__set_console_comm))(arg);
450
    }
451
    return 0;
452
}
453
#endif // 0 UNUSED
454
 
455
static void bsp_trap(int trap_num);
456
 
457
static int
458
hal_bsp_console_write(const void *p, int len)
459
{
460
    bsp_shared_t *shared;
461
    struct bsp_comm_procs *com;
462
    int  magic;
463
 
464
    /*hal_bsp_set_console_comm(0);*/
465
 
466
    /* If this is not a BSP-based CygMon, return 0 */
467
    magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
468
    if (magic != BSP_MAGIC_VAL)
469
        return 0;
470
 
471
    shared = (bsp_shared_t *)
472
        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
473
 
474
    com = shared->__console_procs;
475
 
476
    if (0 != com) {
477
        shared->__console_interrupt_flag = 0;
478
        com->__write(com->ch_data, p, len);
479
        if (shared->__console_interrupt_flag) {
480
            /* debug interrupt; stop here */
481
            bsp_trap(SYS_interrupt);
482
        }
483
 
484
        return 1;
485
    }
486
    return 0;
487
}
488
 
489
static void
490
bsp_trap(int trap_num)
491
{
492
    asm("syscall\n");
493
}
494
 
495
 
496
static void
497
hal_dumb_serial_write(const char *p, int len)
498
{
499
    int i;
500
    for ( i = 0 ; i < len; i++ ) {
501
        hal_diag_dumb_write_char(p[i]);
502
    }
503
}
504
/*
505
void hal_diag_write_char(char c)
506
{
507
    static char line[100];
508
    static int pos = 0;
509
 
510
    // No need to send CRs
511
    if( c == '\r' ) return;
512
 
513
    line[pos++] = c;
514
 
515
    if( c == '\n' || pos == sizeof(line) ) {
516
        CYG_INTERRUPT_STATE old;
517
 
518
        // Disable interrupts. This prevents GDB trying to interrupt us
519
        // while we are in the middle of sending a packet. The serial
520
        // receive interrupt will be seen when we re-enable interrupts
521
        // later.
522
 
523
        HAL_DISABLE_INTERRUPTS(old);
524
 
525
        if ( ! hal_bsp_console_write( line, pos ) )
526
            // then there is no function registered, just spew it out serial
527
            hal_dumb_serial_write( line, pos );
528
 
529
        pos = 0;
530
 
531
        // And re-enable interrupts
532
        HAL_RESTORE_INTERRUPTS(old);
533
 
534
    }
535
}*/
536
 
537
int
538
hal_diag_irq_check(int vector)
539
{
540
    typedef int irq_check_fn(int irq_nr);
541
    irq_check_fn *fn = (irq_check_fn *)(CYGMON_VECTOR_TABLE[ BSP_VEC_IRQ_CHECK ]);
542
    int  magic;
543
 
544
 
545
    /* If this is not a BSP-based CygMon, return 0 */
546
    magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
547
    if (magic != BSP_MAGIC_VAL)
548
        return 0;
549
 
550
#if defined(CYGPKG_HAL_MIPS_TX3904)
551
    /* convert vector to BSP irq number */
552
    if (vector == 16)
553
        vector = 2;
554
    else
555
        vector += 3;
556
#endif
557
 
558
    return fn(vector);
559
}
560
 
561
#endif // defined(CYG_KERNEL_DIAG_CYGMON) *only*
562
 
563
 
564
/*---------------------------------------------------------------------------*/
565
/* 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.