1 //=============================================================================
5 // HAL diagnostic output code
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.
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.
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
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.
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.
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.
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####
44 // Contributors:hmt, jskov
46 // Purpose: HAL diagnostic output
47 // Description: Implementations of HAL diagnostic output support.
49 //####DESCRIPTIONEND####
51 //=============================================================================
53 #include <pkgconf/hal.h>
55 #include <cyg/infra/cyg_type.h> // base types
56 #include <cyg/infra/cyg_trac.h> // tracing macros
57 #include <cyg/infra/cyg_ass.h> // assertion macros
59 #include <cyg/hal/hal_io.h> // IO macros
60 #include <cyg/hal/hal_diag.h>
61 #include <cyg/hal/hal_intr.h> // Interrupt macros
63 #if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
64 #include <cyg/hal/hal_stub.h> // hal_output_gdb_string
67 #include <cyg/hal/ppc_regs.h>
68 #include <cyg/hal/quicc/quicc_smc1.h>
72 cyg_hal_plf_comms_init(void)
74 static int initialized = 0;
80 cyg_hal_plf_serial_init();
84 #if !defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG)
86 //-----------------------------------------------------------------------------
87 // Select default diag channel to use
89 //#define CYG_KERNEL_DIAG_ROMART
90 //#define CYG_KERNEL_DIAG_SERIAL
92 #if !defined(CYG_KERNEL_DIAG_SERIAL)
93 #define CYG_KERNEL_DIAG_SERIAL
96 #ifdef CYGDBG_DIAG_BUF
97 // Keep diag messages in a buffer for later [re]display
99 int enable_diag_uart = 1;
100 int enable_diag_buf = 1;
101 static char diag_buf[40960*4];
102 static int diag_buf_ptr = 0;
107 if (enable_diag_buf) {
108 diag_buf[diag_buf_ptr++] = c;
109 if (diag_buf_ptr == sizeof(diag_buf)) diag_buf_ptr--;
114 dump_diag_buf(int start, int len)
117 enable_diag_uart = 1;
119 if (len == 0) len = diag_buf_ptr;
120 diag_printf("\nDiag buf\n");
121 for (i = start; i < len; i++) {
122 hal_diag_write_char(diag_buf[i]);
125 #endif // CYGDBG_DIAG_BUF
128 //-----------------------------------------------------------------------------
129 // MBX board specific serial output; using GDB protocol by default:
132 #if defined(CYG_KERNEL_DIAG_SERIAL)
136 void hal_diag_init(void)
145 // init the actual serial port
146 cyg_hal_plf_serial_init_channel();
147 #ifdef CYGSEM_HAL_DIAG_MANGLER_GDB
148 #ifndef CYG_HAL_STARTUP_ROM
149 // We are talking to GDB; ack the "go" packet!
150 cyg_hal_plf_serial_putc(eppc, '+');
155 void hal_diag_write_char_serial( char c )
157 unsigned long __state;
158 HAL_DISABLE_INTERRUPTS(__state);
159 cyg_hal_plf_serial_putc(eppc, c);
160 HAL_RESTORE_INTERRUPTS(__state);
163 #if defined(CYG_HAL_STARTUP_ROM) || !defined(CYGDBG_HAL_DIAG_TO_DEBUG_CHAN)
164 void hal_diag_write_char(char c)
166 #ifdef CYGDBG_DIAG_BUF
168 if (!enable_diag_uart) return;
169 #endif // CYGDBG_DIAG_BUF
170 hal_diag_write_char_serial(c);
173 #else // RAM start so encode for GDB
175 void hal_diag_write_char(char c)
177 static char line[100];
180 #ifdef CYGDBG_DIAG_BUF
182 if (!enable_diag_uart) return;
183 #endif // CYGDBG_DIAG_BUF
185 // No need to send CRs
186 if( c == '\r' ) return;
190 if( c == '\n' || pos == sizeof(line) )
192 CYG_INTERRUPT_STATE old;
194 // Disable interrupts. This prevents GDB trying to interrupt us
195 // while we are in the middle of sending a packet. The serial
196 // receive interrupt will be seen when we re-enable interrupts
199 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
200 CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
202 HAL_DISABLE_INTERRUPTS(old);
207 static char hex[] = "0123456789ABCDEF";
211 hal_diag_write_char_serial('$');
212 hal_diag_write_char_serial('O');
214 for( i = 0; i < pos; i++ )
217 char h = hex[(ch>>4)&0xF];
218 char l = hex[ch&0xF];
219 hal_diag_write_char_serial(h);
220 hal_diag_write_char_serial(l);
224 hal_diag_write_char_serial('#');
225 hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
226 hal_diag_write_char_serial(hex[csum&0xF]);
228 #ifndef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
229 // only gobble characters if no interrupt handler to grab ^Cs
230 // is installed (which is exclusive with device driver use)
232 // Wait for the ACK character '+' from GDB here and handle
233 // receiving a ^C instead. This is the reason for this clause
235 c = cyg_hal_plf_serial_getc(eppc);
238 break; // a good acknowledge
241 // Ctrl-C: breakpoint.
246 // otherwise, loop round again
254 // And re-enable interrupts
255 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
256 CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
258 HAL_RESTORE_INTERRUPTS(old);
263 #endif // NOT def CYG_HAL_STARTUP_ROM
266 void hal_diag_read_char(char *c)
268 *c = cyg_hal_plf_serial_getc(eppc);
271 #endif // CYG_KERNEL_DIAG_SERIAL
273 #endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG