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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [mbx/] [current/] [src/] [hal_diag.c] - Blame information for rev 867

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):   hmt
43
// Contributors:hmt, jskov
44
// Date:        1999-06-08
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_io.h>             // IO macros
59
#include <cyg/hal/hal_diag.h>
60
#include <cyg/hal/hal_intr.h>           // Interrupt macros
61
 
62
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
63
#include <cyg/hal/hal_stub.h>           // hal_output_gdb_string
64
#endif
65
 
66
#include <cyg/hal/ppc_regs.h>
67
#include <cyg/hal/quicc/quicc_smc1.h>
68
 
69
 
70
void
71
cyg_hal_plf_comms_init(void)
72
{
73
    static int initialized = 0;
74
 
75
    if (initialized)
76
        return;
77
    initialized = 1;
78
 
79
    cyg_hal_plf_serial_init();
80
}
81
 
82
 
83
#if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
84
 
85
//-----------------------------------------------------------------------------
86
// Select default diag channel to use
87
 
88
//#define CYG_KERNEL_DIAG_ROMART
89
//#define CYG_KERNEL_DIAG_SERIAL
90
 
91
#if !defined(CYG_KERNEL_DIAG_SERIAL)
92
#define CYG_KERNEL_DIAG_SERIAL
93
#endif
94
 
95
#ifdef CYGDBG_DIAG_BUF
96
// Keep diag messages in a buffer for later [re]display
97
 
98
int enable_diag_uart = 1;
99
int enable_diag_buf = 1;
100
static char diag_buf[40960*4];
101
static int  diag_buf_ptr = 0;
102
 
103
static void
104
diag_putc(char c)
105
{
106
    if (enable_diag_buf) {
107
        diag_buf[diag_buf_ptr++] = c;
108
        if (diag_buf_ptr == sizeof(diag_buf)) diag_buf_ptr--;
109
    }
110
}
111
 
112
void
113
dump_diag_buf(int start, int len)
114
{
115
    int i;
116
    enable_diag_uart = 1;
117
    enable_diag_buf = 0;
118
    if (len == 0) len = diag_buf_ptr;
119
    diag_printf("\nDiag buf\n");
120
    for (i = start;  i < len;  i++) {
121
        hal_diag_write_char(diag_buf[i]);
122
    }
123
}
124
#endif // CYGDBG_DIAG_BUF
125
 
126
 
127
//-----------------------------------------------------------------------------
128
// MBX board specific serial output; using GDB protocol by default:
129
 
130
 
131
#if defined(CYG_KERNEL_DIAG_SERIAL)
132
 
133
EPPC *eppc;
134
 
135
void hal_diag_init(void)
136
{
137
    static int init = 0;
138
    if (init) return;
139
    init++;
140
 
141
    // hardwired base
142
    eppc = eppc_base();
143
 
144
    // init the actual serial port
145
    cyg_hal_plf_serial_init_channel();
146
#ifdef CYGSEM_HAL_DIAG_MANGLER_GDB
147
#ifndef CYG_HAL_STARTUP_ROM
148
    // We are talking to GDB; ack the "go" packet!
149
    cyg_hal_plf_serial_putc(eppc, '+');
150
#endif
151
#endif
152
}
153
 
154
void hal_diag_write_char_serial( char c )
155
{
156
    unsigned long __state;
157
    HAL_DISABLE_INTERRUPTS(__state);
158
    cyg_hal_plf_serial_putc(eppc, c);
159
    HAL_RESTORE_INTERRUPTS(__state);
160
}
161
 
162
#if defined(CYG_HAL_STARTUP_ROM) || !defined(CYGDBG_HAL_DIAG_TO_DEBUG_CHAN)
163
void hal_diag_write_char(char c)
164
{
165
#ifdef CYGDBG_DIAG_BUF
166
    diag_putc(c);
167
    if (!enable_diag_uart) return;
168
#endif // CYGDBG_DIAG_BUF
169
    hal_diag_write_char_serial(c);
170
}
171
 
172
#else // RAM start so encode for GDB
173
 
174
void hal_diag_write_char(char c)
175
{
176
    static char line[100];
177
    static int pos = 0;
178
 
179
#ifdef CYGDBG_DIAG_BUF
180
    diag_putc(c);
181
    if (!enable_diag_uart) return;
182
#endif // CYGDBG_DIAG_BUF
183
 
184
    // No need to send CRs
185
    if( c == '\r' ) return;
186
 
187
    line[pos++] = c;
188
 
189
    if( c == '\n' || pos == sizeof(line) )
190
    {
191
        CYG_INTERRUPT_STATE old;
192
 
193
        // Disable interrupts. This prevents GDB trying to interrupt us
194
        // while we are in the middle of sending a packet. The serial
195
        // receive interrupt will be seen when we re-enable interrupts
196
        // later.
197
 
198
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
199
        CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
200
#else
201
        HAL_DISABLE_INTERRUPTS(old);
202
#endif
203
 
204
        while(1)
205
        {
206
            static char hex[] = "0123456789ABCDEF";
207
            cyg_uint8 csum = 0;
208
            int i;
209
 
210
            hal_diag_write_char_serial('$');
211
            hal_diag_write_char_serial('O');
212
            csum += 'O';
213
            for( i = 0; i < pos; i++ )
214
            {
215
                char ch = line[i];
216
                char h = hex[(ch>>4)&0xF];
217
                char l = hex[ch&0xF];
218
                hal_diag_write_char_serial(h);
219
                hal_diag_write_char_serial(l);
220
                csum += h;
221
                csum += l;
222
            }
223
            hal_diag_write_char_serial('#');
224
            hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
225
            hal_diag_write_char_serial(hex[csum&0xF]);
226
 
227
#ifndef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
228
            // only gobble characters if no interrupt handler to grab ^Cs
229
            // is installed (which is exclusive with device driver use)
230
 
231
            // Wait for the ACK character '+' from GDB here and handle
232
            // receiving a ^C instead.  This is the reason for this clause
233
            // being a loop.
234
            c = cyg_hal_plf_serial_getc(eppc);
235
 
236
            if( c == '+' )
237
                break;              // a good acknowledge
238
#if 0
239
            if( c1 == 3 ) {
240
                // Ctrl-C: breakpoint.
241
                breakpoint();
242
                break;
243
            }
244
#endif
245
            // otherwise, loop round again
246
#else
247
            break;
248
#endif
249
        }
250
 
251
        pos = 0;
252
 
253
        // And re-enable interrupts
254
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
255
        CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
256
#else
257
        HAL_RESTORE_INTERRUPTS(old);
258
#endif
259
 
260
    }
261
}
262
#endif // NOT def CYG_HAL_STARTUP_ROM
263
 
264
 
265
void hal_diag_read_char(char *c)
266
{
267
    *c = cyg_hal_plf_serial_getc(eppc);
268
}
269
 
270
#endif // CYG_KERNEL_DIAG_SERIAL
271
 
272
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
273
 
274
// EOF hal_diag.c

powered by: WebSVN 2.1.0

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