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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [synth/] [arch/] [v2_0/] [src/] [synth_diag.c] - Blame information for rev 197

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

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//
3
//      synth_diag.c
4
//
5
//      Synthetic target diagnostic output code
6
//
7
//=============================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2002 Bart Veer
12
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19
// 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 along
24
// with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
//
27
// As a special exception, if other files instantiate templates or use macros
28
// or inline functions from this file, or you compile this file and link it
29
// with other works to produce a work based on this file, this file does not
30
// by itself cause the resulting work to be covered by the GNU General Public
31
// License. However the source code for this file must still be made available
32
// in accordance with section (3) of the GNU General Public License.
33
//
34
// This exception does not invalidate any other reasons why a work based on
35
// this file might be covered by the GNU General Public License.
36
//
37
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38
// at http://sources.redhat.com/ecos/ecos-license/
39
// -------------------------------------------
40
//####ECOSGPLCOPYRIGHTEND####
41
//=============================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):   proven
45
// Contributors:proven, bartv
46
// Date:        1998-10-05
47
// Purpose:     HAL diagnostic output
48
// Description: Implementations of HAL diagnostic output support.
49
//
50
//              There are two possible ways of performing I/O. The first
51
//              involves simply writing to stdout. This is robust, but
52
//              has some disadvantages such as the output getting mixed up
53
//              with gdb output. The second involves sending the data on
54
//              to the auxiliary, less robust but much more flexible.
55
//
56
//              Similarly, input can be handled by reading from stdin or
57
//              by a suitable device in the auxiliary.
58
//
59
//####DESCRIPTIONEND####
60
//
61
//=============================================================================
62
 
63
#include <cyg/infra/cyg_type.h>
64
#include <cyg/hal/hal_diag.h>
65
#include <cyg/hal/hal_io.h>
66
#include <cyg/infra/cyg_ass.h>
67
 
68
//-----------------------------------------------------------------------------
69
// If the auxiliary exists, hal_diag_init() will try to contact it and
70
// instantiate a console device. Subsequent console writes will be
71
// redirected to that device, as long as the auxiliary is up and running.
72
// If the auxiliary is not being used or has exited, console writes
73
// will instead go to stdout.
74
//
75
// This code also contains an implementation of hal_diag_read_char()
76
// which is probably not very useful. Currently it works by reading
77
// from stdin, but no attempt is made to set the tty into raw mode
78
// or anything like that. 
79
 
80
static int auxiliary_console_id = -1;
81
 
82
void hal_diag_init( void )
83
{
84
    if (synth_auxiliary_running) {
85
        auxiliary_console_id = synth_auxiliary_instantiate("hal/synth/arch", SYNTH_MAKESTRING(CYGPKG_HAL_SYNTH), "console",
86
                                                      (const char*) 0, (const char*) 0);
87
    }
88
}
89
 
90
// Output a single character.
91
//
92
// The calling code will output one character at a time. Output
93
// involves at least one system call, and this is expensive for
94
// a single character (especially when used in conjunction with
95
// I/O intensive facilities like unbuffered tracing). Therefore
96
// this code will buffer lines up to 128 characters before
97
// doing the I/O.
98
//
99
// NOTE: one problem is that there is no support for flushing buffers
100
// at this level. Therefore if say C library stdio ends up mapped to
101
// HAL diagnostics I/O then functions like fflush() and setvbuf() will
102
// not behave the way they should. There is no simple workaround at
103
// this level, the required information is not available.
104
 
105
void hal_diag_write_char(char c)
106
{
107
    static int  diag_index = 0;
108
    static unsigned char diag_buffer[128];
109
 
110
    CYG_ASSERT(diag_index < 128, "Diagnostic buffer overflow");
111
 
112
    diag_buffer[diag_index++] = (unsigned char) c;
113
    if (('\n' == c) || (128 == diag_index)) {
114
        if ((-1 != auxiliary_console_id) && synth_auxiliary_running) {
115
            synth_auxiliary_xchgmsg(auxiliary_console_id, 0, 0, 0, diag_buffer, diag_index, (int *) 0, (unsigned char*) 0, (int *)0, 0);
116
            diag_index = 0;
117
        } else {
118
            int     written;
119
            char*   next    = diag_buffer;
120
 
121
            while (diag_index > 0) {
122
                written = cyg_hal_sys_write(1, next, diag_index);
123
                if (written > 0) {
124
                    diag_index -= written;
125
                    next       += written;
126
                } else if ((-CYG_HAL_SYS_EINTR != written) && (-CYG_HAL_SYS_EAGAIN != written)) {
127
                    CYG_FAIL("Unexpected error writing to stdout.");
128
                    diag_index = 0;
129
                    break;
130
                }
131
            }
132
            CYG_ASSERT(0 == diag_index, "All data should have been written out");
133
            diag_index = 0;
134
            cyg_hal_sys_fdatasync(1);
135
        }
136
    }
137
}
138
 
139
// Diagnostic input. It is not clear that this is actually useful,
140
// input would normally go to gdb rather than to the application. If
141
// keyboard input really is required then that should be handled via a
142
// suitable device driver interacting with the auxiliary, not at the
143
// HAL level. The read syscall will get woken up by the itimer alarm,
144
// but we don't want to stop reading if that's the case
145
 
146
void hal_diag_read_char(char *c)
147
{
148
    int rc;
149
    do {
150
        rc = cyg_hal_sys_read(0, c, 1);
151
    } while ((-CYG_HAL_SYS_EINTR == rc) || (-CYG_HAL_SYS_EAGAIN == rc));
152
}
153
 
154
//-----------------------------------------------------------------------------
155
// 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.