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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mips/] [ref4955/] [v2_0/] [src/] [hal_diag.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=============================================================================
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 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):   jskov
44
// Contributors:nickg, jskov
45
// Date:        2000-05-10
46
// Purpose:     HAL diagnostic output
47
// Description: Implementations of HAL diagnostic output support.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//=============================================================================
52
 
53
#include <pkgconf/hal.h>
54
 
55
#if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
56
 
57
#include <cyg/infra/cyg_type.h>         // base types
58
#include <cyg/infra/cyg_trac.h>         // tracing macros
59
#include <cyg/infra/cyg_ass.h>          // assertion macros
60
 
61
#include <cyg/hal/hal_arch.h>
62
#include <cyg/hal/hal_diag.h>
63
 
64
#include <cyg/hal/hal_intr.h>
65
#include <cyg/hal/hal_misc.h>           // Helper functions
66
 
67
#include <cyg/hal/hal_io.h>
68
 
69
#include <cyg/hal/hal_if.h>             // ROM calling interface
70
 
71
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
72
#include <cyg/hal/hal_stub.h>           // CYG_HAL_GDB_x_CRITICAL_IO_REGION
73
#endif
74
 
75
externC void cyg_hal_plf_serial_init_channel(void* __ch_data);
76
externC void cyg_hal_plf_serial_putc(void* __ch_data, cyg_uint8 __ch);
77
externC cyg_uint8 cyg_hal_plf_serial_getc(void* __ch_data);
78
 
79
//-----------------------------------------------------------------------------
80
// Hit the hardware directly. Either wrap in GDB O-packets, or write
81
// data raw to device.
82
 
83
// Decide when to wrap text output as GDB O-packets
84
#if (CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL \
85
     == CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL)
86
 
87
#if defined(CYGSEM_HAL_USE_ROM_MONITOR_GDB_stubs) \
88
    || defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
89
 
90
#define CYG_DIAG_GDB
91
 
92
#endif
93
 
94
#endif
95
 
96
//-----------------------------------------------------------------------------
97
// There are two serial ports. Hardwire to use one of them.
98
#define CYG_DEVICE_SERIAL_SCC1    0xb40003f8 // port 1
99
#define CYG_DEVICE_SERIAL_SCC2    0xb40002f8 // port 2
100
 
101
typedef struct {
102
    cyg_uint8* base;
103
    cyg_int32 msec_timeout;
104
    int isr_vector;
105
} channel_data_t;
106
 
107
#if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 0)
108
#define BASE ((cyg_uint8*)CYG_DEVICE_SERIAL_SCC1)
109
#else
110
#define BASE ((cyg_uint8*)CYG_DEVICE_SERIAL_SCC2)
111
#endif
112
 
113
static channel_data_t channel = { BASE, 0, 0};
114
 
115
#ifdef CYG_DIAG_GDB
116
 
117
void
118
hal_diag_write_char(char c)
119
{
120
    static char line[100];
121
    static int pos = 0;
122
 
123
    // No need to send CRs
124
    if( c == '\r' ) return;
125
 
126
    line[pos++] = c;
127
 
128
    if( c == '\n' || pos == sizeof(line) )
129
    {
130
        CYG_INTERRUPT_STATE old;
131
 
132
        // Disable interrupts. This prevents GDB trying to interrupt us
133
        // while we are in the middle of sending a packet. The serial
134
        // receive interrupt will be seen when we re-enable interrupts
135
        // later.
136
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
137
        CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
138
#else
139
        HAL_DISABLE_INTERRUPTS(old);
140
#endif
141
 
142
        while(1)
143
        {
144
            static char hex[] = "0123456789ABCDEF";
145
            cyg_uint8 csum = 0;
146
            int i;
147
            char c1;
148
 
149
            cyg_hal_plf_serial_putc(&channel, '$');
150
            cyg_hal_plf_serial_putc(&channel, 'O');
151
            csum += 'O';
152
            for( i = 0; i < pos; i++ )
153
            {
154
                char ch = line[i];
155
                char h = hex[(ch>>4)&0xF];
156
                char l = hex[ch&0xF];
157
                cyg_hal_plf_serial_putc(&channel, h);
158
                cyg_hal_plf_serial_putc(&channel, l);
159
                csum += h;
160
                csum += l;
161
            }
162
            cyg_hal_plf_serial_putc(&channel, '#');
163
            cyg_hal_plf_serial_putc(&channel, hex[(csum>>4)&0xF]);
164
            cyg_hal_plf_serial_putc(&channel, hex[csum&0xF]);
165
 
166
            c1 = cyg_hal_plf_serial_getc(&channel);
167
 
168
            if( c1 == '+' ) break;
169
        }
170
 
171
        pos = 0;
172
        // And re-enable interrupts
173
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
174
        CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
175
#else
176
        HAL_RESTORE_INTERRUPTS(old);
177
#endif
178
    }
179
}
180
 
181
void
182
hal_diag_read_char(char *c)
183
{
184
    *c = cyg_hal_plf_serial_getc(&channel);
185
}
186
 
187
#else // CYG_DIAG_GDB
188
 
189
// Hit the hardware directly, no GDB translation
190
 
191
void
192
hal_diag_read_char(char *c)
193
{
194
    *c = cyg_hal_plf_serial_getc(&channel);
195
}
196
 
197
void
198
hal_diag_write_char(char c)
199
{
200
    cyg_hal_plf_serial_putc(&channel, c);
201
}
202
 
203
 
204
#endif
205
 
206
// Reagardless whether encoding or not we alway initialize the device.
207
 
208
void
209
hal_diag_init(void)
210
{
211
    // Init serial device
212
    cyg_hal_plf_serial_init_channel((void*)&channel);
213
}
214
 
215
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
216
 
217
//-----------------------------------------------------------------------------
218
// End of hal_diag.c

powered by: WebSVN 2.1.0

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