1 |
786 |
skrzyp |
//=============================================================================
|
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) 1998, 1999, 2000, 2001, 2002, 2009 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): proven
|
43 |
|
|
// Contributors:proven, bartv
|
44 |
|
|
// Date: 1998-10-05
|
45 |
|
|
// Purpose: HAL diagnostic output
|
46 |
|
|
// Description: Implementations of HAL diagnostic output support.
|
47 |
|
|
//
|
48 |
|
|
// There are two possible ways of performing I/O. The first
|
49 |
|
|
// involves simply writing to stdout. This is robust, but
|
50 |
|
|
// has some disadvantages such as the output getting mixed up
|
51 |
|
|
// with gdb output. The second involves sending the data on
|
52 |
|
|
// to the auxiliary, less robust but much more flexible.
|
53 |
|
|
//
|
54 |
|
|
// Similarly, input can be handled by reading from stdin or
|
55 |
|
|
// by a suitable device in the auxiliary.
|
56 |
|
|
//
|
57 |
|
|
//####DESCRIPTIONEND####
|
58 |
|
|
//
|
59 |
|
|
//=============================================================================
|
60 |
|
|
|
61 |
|
|
#include <cyg/infra/cyg_type.h>
|
62 |
|
|
#include <cyg/hal/hal_diag.h>
|
63 |
|
|
#include <cyg/hal/hal_io.h>
|
64 |
|
|
#include <cyg/hal/hal_intr.h>
|
65 |
|
|
#include <cyg/infra/cyg_ass.h>
|
66 |
|
|
|
67 |
|
|
//-----------------------------------------------------------------------------
|
68 |
|
|
// If the auxiliary exists, hal_diag_init() will try to contact it and
|
69 |
|
|
// instantiate a console device. Subsequent console writes will be
|
70 |
|
|
// redirected to that device, as long as the auxiliary is up and running.
|
71 |
|
|
// If the auxiliary is not being used or has exited, console writes
|
72 |
|
|
// will instead go to stdout.
|
73 |
|
|
//
|
74 |
|
|
// This code also contains an implementation of hal_diag_read_char()
|
75 |
|
|
// which is probably not very useful. Currently it works by reading
|
76 |
|
|
// from stdin, but no attempt is made to set the tty into raw mode
|
77 |
|
|
// or anything like that.
|
78 |
|
|
|
79 |
|
|
static int auxiliary_console_id = -1;
|
80 |
|
|
|
81 |
|
|
void hal_diag_init( void )
|
82 |
|
|
{
|
83 |
|
|
if (synth_auxiliary_running) {
|
84 |
|
|
auxiliary_console_id = synth_auxiliary_instantiate("hal/synth/arch", SYNTH_MAKESTRING(CYGPKG_HAL_SYNTH), "console",
|
85 |
|
|
(const char*) 0, (const char*) 0);
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
// Output a single character.
|
90 |
|
|
//
|
91 |
|
|
// The calling code will output one character at a time. Output
|
92 |
|
|
// involves at least one system call, and this is expensive for
|
93 |
|
|
// a single character (especially when used in conjunction with
|
94 |
|
|
// I/O intensive facilities like unbuffered tracing). Therefore
|
95 |
|
|
// this code will buffer lines up to 128 characters before
|
96 |
|
|
// doing the I/O.
|
97 |
|
|
//
|
98 |
|
|
// NOTE: one problem is that there is no support for flushing buffers
|
99 |
|
|
// at this level. Therefore if say C library stdio ends up mapped to
|
100 |
|
|
// HAL diagnostics I/O then functions like fflush() and setvbuf() will
|
101 |
|
|
// not behave the way they should. There is no simple workaround at
|
102 |
|
|
// this level, the required information is not available.
|
103 |
|
|
|
104 |
|
|
void hal_diag_write_char(char c)
|
105 |
|
|
{
|
106 |
|
|
static int diag_index = 0;
|
107 |
|
|
static unsigned char diag_buffer[128];
|
108 |
|
|
int ints_state;
|
109 |
|
|
|
110 |
|
|
CYG_ASSERT(diag_index < 128, "Diagnostic buffer overflow");
|
111 |
|
|
HAL_DISABLE_INTERRUPTS(ints_state);
|
112 |
|
|
|
113 |
|
|
diag_buffer[diag_index++] = (unsigned char) c;
|
114 |
|
|
if (('\n' == c) || (128 == diag_index)) {
|
115 |
|
|
if ((-1 != auxiliary_console_id) && synth_auxiliary_running) {
|
116 |
|
|
synth_auxiliary_xchgmsg(auxiliary_console_id, 0, 0, 0, diag_buffer, diag_index, (int *) 0, (unsigned char*) 0, (int *)0, 0);
|
117 |
|
|
diag_index = 0;
|
118 |
|
|
} else {
|
119 |
|
|
int written;
|
120 |
|
|
unsigned char* next = diag_buffer;
|
121 |
|
|
|
122 |
|
|
while (diag_index > 0) {
|
123 |
|
|
written = cyg_hal_sys_write(1, next, diag_index);
|
124 |
|
|
if (written > 0) {
|
125 |
|
|
diag_index -= written;
|
126 |
|
|
next += written;
|
127 |
|
|
} else if ((-CYG_HAL_SYS_EINTR != written) && (-CYG_HAL_SYS_EAGAIN != written)) {
|
128 |
|
|
CYG_FAIL("Unexpected error writing to stdout.");
|
129 |
|
|
diag_index = 0;
|
130 |
|
|
break;
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
CYG_ASSERT(0 == diag_index, "All data should have been written out");
|
134 |
|
|
diag_index = 0;
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
HAL_RESTORE_INTERRUPTS(ints_state);
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
// Diagnostic input. It is not clear that this is actually useful,
|
141 |
|
|
// input would normally go to gdb rather than to the application. If
|
142 |
|
|
// keyboard input really is required then that should be handled via a
|
143 |
|
|
// suitable device driver interacting with the auxiliary, not at the
|
144 |
|
|
// HAL level. The read syscall will get woken up by the itimer alarm,
|
145 |
|
|
// but we don't want to stop reading if that's the case
|
146 |
|
|
|
147 |
|
|
void hal_diag_read_char(char *c)
|
148 |
|
|
{
|
149 |
|
|
int rc;
|
150 |
|
|
do {
|
151 |
|
|
rc = cyg_hal_sys_read(0, c, 1);
|
152 |
|
|
} while ((-CYG_HAL_SYS_EINTR == rc) || (-CYG_HAL_SYS_EAGAIN == rc));
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
//-----------------------------------------------------------------------------
|
156 |
|
|
// End of hal_diag.c
|