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 //===========================================================================*/
42 #include <pkgconf/hal.h>
43 #include <pkgconf/system.h>
44 #include CYGBLD_HAL_PLATFORM_H
46 #include <cyg/infra/cyg_type.h> // base types
47 #include <cyg/infra/cyg_trac.h> // tracing macros
48 #include <cyg/infra/cyg_ass.h> // assertion macros
50 #include <cyg/hal/hal_arch.h> // basic machine info
51 #include <cyg/hal/hal_intr.h> // interrupt macros
52 #include <cyg/hal/hal_io.h> // IO macros
53 #include <cyg/hal/hal_if.h> // Calling interface definitions
54 #include <cyg/hal/hal_diag.h>
55 #include <cyg/hal/drv_api.h> // cyg_drv_interrupt_acknowledge
56 #include <cyg/hal/hal_misc.h> // Helper functions
57 #include <cyg/hal/hal_soc.h> // Hardware definitions
59 #define MX21_UART_RFDIV 2 /* Ref Clock Divisor */
60 #define MX21_UART_REFFREQ (MX21_PERCLK1 / MX21_UART_RFDIV)
63 * UART Control Register 0 Bit Fields.
65 #define EUartUCR1_ADEN (1 << 15) // Auto dectect interrupt
66 #define EUartUCR1_ADBR (1 << 14) // Auto detect baud rate
67 #define EUartUCR1_TRDYEN (1 << 13) // Transmitter ready interrupt enable
68 #define EUartUCR1_IDEN (1 << 12) // Idle condition interrupt
69 #define EUartUCR1_RRDYEN (1 << 9) // Recv ready interrupt enable
70 #define EUartUCR1_RDMAEN (1 << 8) // Recv ready DMA enable
71 #define EUartUCR1_IREN (1 << 7) // Infrared interface enable
72 #define EUartUCR1_TXMPTYEN (1 << 6) // Transimitter empty interrupt enable
73 #define EUartUCR1_RTSDEN (1 << 5) // RTS delta interrupt enable
74 #define EUartUCR1_SNDBRK (1 << 4) // Send break
75 #define EUartUCR1_TDMAEN (1 << 3) // Transmitter ready DMA enable
76 #define EUartUCR1_DOZE (1 << 1) // Doze
77 #define EUartUCR1_UARTEN (1 << 0) // UART enabled
78 #define EUartUCR2_ESCI (1 << 15) // Escape seq interrupt enable
79 #define EUartUCR2_IRTS (1 << 14) // Ignore RTS pin
80 #define EUartUCR2_CTSC (1 << 13) // CTS pin control
81 #define EUartUCR2_CTS (1 << 12) // Clear to send
82 #define EUartUCR2_ESCEN (1 << 11) // Escape enable
83 #define EUartUCR2_PREN (1 << 8) // Parity enable
84 #define EUartUCR2_PROE (1 << 7) // Parity odd/even
85 #define EUartUCR2_STPB (1 << 6) // Stop
86 #define EUartUCR2_WS (1 << 5) // Word size
87 #define EUartUCR2_RTSEN (1 << 4) // Request to send interrupt enable
88 #define EUartUCR2_ATEN (1 << 3) // Aging timer enable
89 #define EUartUCR2_TXEN (1 << 2) // Transmitter enabled
90 #define EUartUCR2_RXEN (1 << 1) // Receiver enabled
91 #define EUartUCR2_SRST_ (1 << 0) // SW reset
92 #define EUartUCR3_PARERREN (1 << 12) // Parity enable
93 #define EUartUCR3_FRAERREN (1 << 11) // Frame error interrupt enable
94 #define EUartUCR3_ADNIMP (1 << 7) // Autobaud detection not improved
95 #define EUartUCR3_RXDSEN (1 << 6) // Receive status interrupt enable
96 #define EUartUCR3_AIRINTEN (1 << 5) // Async IR wake interrupt enable
97 #define EUartUCR3_AWAKEN (1 << 4) // Async wake interrupt enable
98 #define EUartUCR3_RXDMUXSEL (1 << 2) // RXD muxed input selected
99 #define EUartUCR3_INVT (1 << 1) // Inverted Infrared transmission
100 #define EUartUCR3_ACIEN (1 << 0) // Autobaud counter interrupt enable
101 #define EUartUCR4_CTSTL_32 (32 << 10) // CTS trigger level (32 chars)
102 #define EUartUCR4_INVR (1 << 9) // Inverted infrared reception
103 #define EUartUCR4_ENIRI (1 << 8) // Serial infrared interrupt enable
104 #define EUartUCR4_WKEN (1 << 7) // Wake interrupt enable
105 #define EUartUCR4_IRSC (1 << 5) // IR special case
106 #define EUartUCR4_LPBYP (1 << 4) // Low power bypass
107 #define EUartUCR4_TCEN (1 << 3) // Transmit complete interrupt enable
108 #define EUartUCR4_BKEN (1 << 2) // Break condition interrupt enable
109 #define EUartUCR4_OREN (1 << 1) // Receiver overrun interrupt enable
110 #define EUartUCR4_DREN (1 << 0) // Recv data ready interrupt enable
111 #define EUartUFCR_RXTL_SHF 0 // Receiver trigger level shift
112 #define EUartUFCR_RFDIV_1 (5 << 7) // Reference freq divider (div 1)
113 #define EUartUFCR_RFDIV_2 (4 << 7) // Reference freq divider (div 2)
114 #define EUartUFCR_RFDIV_3 (3 << 7) // Reference freq divider (div 3)
115 #define EUartUFCR_RFDIV_4 (2 << 7) // Reference freq divider (div 4)
116 #define EUartUFCR_RFDIV_5 (1 << 7) // Reference freq divider (div 5)
117 #define EUartUFCR_RFDIV_6 (0 << 7) // Reference freq divider (div 6)
118 #define EUartUFCR_RFDIV_7 (6 << 7) // Reference freq divider (div 7)
119 #define EUartUFCR_TXTL_SHF 10 // Transmitter trigger level shift
120 #define EUartUSR1_PARITYERR (1 << 15) // Parity error interrupt flag
121 #define EUartUSR1_RTSS (1 << 14) // RTS pin status
122 #define EUartUSR1_TRDY (1 << 13) // Transmitter ready interrupt/dma flag
123 #define EUartUSR1_RTSD (1 << 12) // RTS delta
124 #define EUartUSR1_ESCF (1 << 11) // Escape seq interrupt flag
125 #define EUartUSR1_FRAMERR (1 << 10) // Frame error interrupt flag
126 #define EUartUSR1_RRDY (1 << 9) // Receiver ready interrupt/dma flag
127 #define EUartUSR1_AGTIM (1 << 8) // Aging timeout interrupt status
128 #define EUartUSR1_RXDS (1 << 6) // Receiver idle interrupt flag
129 #define EUartUSR1_AIRINT (1 << 5) // Async IR wake interrupt flag
130 #define EUartUSR1_AWAKE (1 << 4) // Aysnc wake interrupt flag
131 #define EUartUSR2_ADET (1 << 15) // Auto baud rate detect complete
132 #define EUartUSR2_TXFE (1 << 14) // Transmit buffer FIFO empty
133 #define EUartUSR2_IDLE (1 << 12) // Idle condition
134 #define EUartUSR2_ACST (1 << 11) // Autobaud counter stopped
135 #define EUartUSR2_IRINT (1 << 8) // Serial infrared interrupt flag
136 #define EUartUSR2_WAKE (1 << 7) // Wake
137 #define EUartUSR2_RTSF (1 << 4) // RTS edge interrupt flag
138 #define EUartUSR2_TXDC (1 << 3) // Transmitter complete
139 #define EUartUSR2_BRCD (1 << 2) // Break condition
140 #define EUartUSR2_ORE (1 << 1) // Overrun error
141 #define EUartUSR2_RDR (1 << 0) // Recv data ready
142 #define EUartUTS_FRCPERR (1 << 13) // Force parity error
143 #define EUartUTS_LOOP (1 << 12) // Loop tx and rx
144 #define EUartUTS_TXEMPTY (1 << 6) // TxFIFO empty
145 #define EUartUTS_RXEMPTY (1 << 5) // RxFIFO empty
146 #define EUartUTS_TXFULL (1 << 4) // TxFIFO full
147 #define EUartUTS_RXFULL (1 << 3) // RxFIFO full
148 #define EUartUTS_SOFTRST (1 << 0) // Software reset
150 void cyg_hal_plf_serial_init(void);
154 cyg_hal_plf_comms_init(void)
156 static int initialized = 0;
163 cyg_hal_plf_serial_init();
167 //=============================================================================
168 // MXC Serial Port (UARTx) for Debug
169 //=============================================================================
172 volatile cyg_uint32 urxd[16];
173 volatile cyg_uint32 utxd[16];
174 volatile cyg_uint32 ucr1;
175 volatile cyg_uint32 ucr2;
176 volatile cyg_uint32 ucr3;
177 volatile cyg_uint32 ucr4;
178 volatile cyg_uint32 ufcr;
179 volatile cyg_uint32 usr1;
180 volatile cyg_uint32 usr2;
181 volatile cyg_uint32 uesc;
182 volatile cyg_uint32 utim;
183 volatile cyg_uint32 ubir;
184 volatile cyg_uint32 ubmr;
185 volatile cyg_uint32 ubrc;
186 volatile cyg_uint32 onems;
187 volatile cyg_uint32 uts;
191 volatile struct mxc_serial* base;
192 cyg_int32 msec_timeout;
197 static channel_data_t channels[] = {
198 #if CYGHWR_HAL_ARM_SOC_UART1 != 0
199 {(volatile struct mxc_serial*)MX21_UART1_BASE, 1000,
200 CYGNUM_HAL_INTERRUPT_UART1, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
202 #if CYGHWR_HAL_ARM_SOC_UART2 != 0
203 {(volatile struct mxc_serial*)MX21_UART2_BASE, 1000,
204 CYGNUM_HAL_INTERRUPT_UART2, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
206 #if CYGHWR_HAL_ARM_SOC_UART3 != 0
207 {(volatile struct mxc_serial*)MX21_UART3_BASE, 1000,
208 CYGNUM_HAL_INTERRUPT_UART3, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
210 #if CYGHWR_HAL_ARM_SOC_UART4 != 0
211 {(volatile struct mxc_serial*)MX21_UART4_BASE, 1000,
212 CYGNUM_HAL_INTERRUPT_UART4, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
216 /*---------------------------------------------------------------------------*/
218 static void init_serial_channel(channel_data_t* __ch_data)
220 volatile struct mxc_serial* base = __ch_data->base;
222 /* Wait for UART to finish transmitting */
223 while (!(base->uts & EUartUTS_TXEMPTY));
226 base->ucr1 &= ~EUartUCR1_UARTEN;
228 /* Set to default POR state */
229 base->ucr1 = 0x00000000;
230 base->ucr2 = 0x00000000;
231 base->ucr3 = 0x00000004;
232 base->ucr4 = 0x00008000;
233 base->ufcr = 0x00000801;
234 base->uesc = 0x0000002B;
235 base->utim = 0x00000000;
236 base->ubir = 0x00000000;
237 base->ubmr = 0x00000000;
238 base->onems = 0x00000000;
239 base->uts = 0x00000000;
241 /* Configure FIFOs */
242 base->ufcr = (1 << EUartUFCR_RXTL_SHF) | EUartUFCR_RFDIV_2
243 | (2 << EUartUFCR_TXTL_SHF);
245 /* Setup One MS timer */
246 base->onems = (MX21_UART_REFFREQ / 1000);
248 /* Set the numerator value minus one of the BRM ratio */
249 base->ubir = (__ch_data->baud_rate / 100) - 1;
251 /* Set the denominator value minus one of the BRM ratio */
252 base->ubmr = ((MX21_UART_REFFREQ / 1600) - 1);
255 base->ucr2 &= ~EUartUCR2_PREN;
256 base->ucr2 |= EUartUCR2_WS;
257 base->ucr2 &= ~EUartUCR2_STPB;
260 base->ucr2 |= EUartUCR2_IRTS;
263 base->ucr1 |= EUartUCR1_UARTEN;
266 base->ucr2 |= EUartUCR2_SRST_ | EUartUCR2_RXEN | EUartUCR2_TXEN;
268 /* Clear status flags */
269 base->usr2 |= EUartUSR2_ADET |
278 /* Clear status flags */
279 base->usr1 |= EUartUSR1_PARITYERR |
287 static void stop_serial_channel(channel_data_t* __ch_data)
289 volatile struct mxc_serial* base = __ch_data->base;
291 /* Wait for UART to finish transmitting */
292 while (!(base->uts & EUartUTS_TXEMPTY));
295 base->ucr1 &= ~EUartUCR1_UARTEN;
298 void cyg_hal_plf_serial_putc(void *__ch_data, char c)
300 volatile struct mxc_serial* base = ((channel_data_t*)__ch_data)->base;
301 CYGARC_HAL_SAVE_GP();
303 // Wait for Tx FIFO not full
304 while (base->uts & EUartUTS_TXFULL)
308 CYGARC_HAL_RESTORE_GP();
311 static cyg_bool cyg_hal_plf_serial_getc_nonblock(void* __ch_data,
314 volatile struct mxc_serial* base = ((channel_data_t*)__ch_data)->base;
316 // If receive fifo is empty, return false
317 if (base->uts & EUartUTS_RXEMPTY)
320 *ch = (char)base->urxd[0];
325 cyg_uint8 cyg_hal_plf_serial_getc(void* __ch_data)
328 CYGARC_HAL_SAVE_GP();
330 while (!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
332 CYGARC_HAL_RESTORE_GP();
336 static void cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
339 CYGARC_HAL_SAVE_GP();
342 cyg_hal_plf_serial_putc(__ch_data, *__buf++);
344 CYGARC_HAL_RESTORE_GP();
347 static void cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf,
350 CYGARC_HAL_SAVE_GP();
353 *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
355 CYGARC_HAL_RESTORE_GP();
358 cyg_bool cyg_hal_plf_serial_getc_timeout(void* __ch_data,
362 channel_data_t* chan = (channel_data_t*)__ch_data;
364 CYGARC_HAL_SAVE_GP();
366 delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
369 res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
370 if (res || 0 == delay_count--)
373 CYGACC_CALL_IF_DELAY_US(100);
376 CYGARC_HAL_RESTORE_GP();
380 static int cyg_hal_plf_serial_control(void *__ch_data,
381 __comm_control_cmd_t __func, ...)
383 static int irq_state = 0;
384 channel_data_t* chan = (channel_data_t*)__ch_data;
388 CYGARC_HAL_SAVE_GP();
389 va_start(ap, __func);
392 case __COMMCTL_GETBAUD:
393 ret = chan->baud_rate;
395 case __COMMCTL_SETBAUD:
396 chan->baud_rate = va_arg(ap, cyg_int32);
397 // Should we verify this value here?
398 init_serial_channel(chan);
401 case __COMMCTL_IRQ_ENABLE:
404 chan->base->ucr1 |= EUartUCR1_RRDYEN;
406 HAL_INTERRUPT_UNMASK(chan->isr_vector);
408 case __COMMCTL_IRQ_DISABLE:
412 chan->base->ucr1 &= ~EUartUCR1_RRDYEN;
414 HAL_INTERRUPT_MASK(chan->isr_vector);
416 case __COMMCTL_DBG_ISR_VECTOR:
417 ret = chan->isr_vector;
419 case __COMMCTL_SET_TIMEOUT:
420 ret = chan->msec_timeout;
421 chan->msec_timeout = va_arg(ap, cyg_uint32);
427 CYGARC_HAL_RESTORE_GP();
431 static int cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
432 CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
435 channel_data_t* chan = (channel_data_t*)__ch_data;
438 CYGARC_HAL_SAVE_GP();
440 cyg_drv_interrupt_acknowledge(chan->isr_vector);
443 if (!(chan->base->uts & EUartUTS_RXEMPTY)) {
444 c = (char)chan->base->urxd[0];
446 if (cyg_hal_is_break( &c , 1 ))
449 res = CYG_ISR_HANDLED;
452 CYGARC_HAL_RESTORE_GP();
456 void cyg_hal_plf_serial_init(void)
458 hal_virtual_comm_table_t* comm;
459 int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
464 #define NUMOF(x) (sizeof(x)/sizeof(x[0]))
465 for (i = 0; i < NUMOF(channels); i++) {
466 init_serial_channel(&channels[i]);
467 CYGACC_CALL_IF_SET_CONSOLE_COMM(i+2);
468 comm = CYGACC_CALL_IF_CONSOLE_PROCS();
469 CYGACC_COMM_IF_CH_DATA_SET(*comm, &channels[i]);
470 CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
471 CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
472 CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
473 CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
474 CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
475 CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
476 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
478 cyg_hal_plf_serial_putc(&channels[i], '+');
481 cyg_hal_plf_serial_putc(&channels[i], '+');
484 // Restore original console
485 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
488 void cyg_hal_plf_serial_stop(void)
493 #define NUMOF(x) (sizeof(x)/sizeof(x[0]))
494 for (i = 0; i < NUMOF(channels); i++) {
495 stop_serial_channel(&channels[i]);
499 //=============================================================================
500 // Compatibility with older stubs
501 //=============================================================================
503 #ifndef CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
505 #include <cyg/hal/hal_stub.h> // cyg_hal_gdb_interrupt
507 #if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 2)
508 #define __BASE ((void*)MX21_UART1_BASE)
509 #define CYGHWR_HAL_GDB_PORT_VECTOR CYGNUM_HAL_INTERRUPT_UART1
510 #elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 3)
511 #define __BASE ((void*)MX21_UART2_BASE)
512 #define CYGHWR_HAL_GDB_PORT_VECTOR CYGNUM_HAL_INTERRUPT_UART2
513 #elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 4)
514 #define __BASE ((void*)MX21_UART3_BASE)
515 #define CYGHWR_HAL_GDB_PORT_VECTOR CYGNUM_HAL_INTERRUPT_UART3
516 #elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 5)
517 #define __BASE ((void*)MX21_UART4_BASE)
518 #define CYGHWR_HAL_GDB_PORT_VECTOR CYGNUM_HAL_INTERRUPT_UART4
523 #ifdef CYGSEM_HAL_ROM_MONITOR
524 #define CYG_HAL_STARTUP_ROM
525 #define CYG_HAL_STARTUP_ROMRAM
526 #undef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
529 #if (defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)) && !defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
530 #define HAL_DIAG_USES_HARDWARE
531 #elif !defined(CYGDBG_HAL_DIAG_TO_DEBUG_CHAN)
532 #define HAL_DIAG_USES_HARDWARE
533 #elif CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL != CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL
534 #define HAL_DIAG_USES_HARDWARE
537 static channel_data_t channel = {
538 (volatile struct mxc_serial*)__BASE, 0, CYGHWR_HAL_GDB_PORT_VECTOR
541 #ifdef HAL_DIAG_USES_HARDWARE
543 void hal_diag_init(void)
546 char *msg = "\n\rARM eCos\n\r";
551 init_serial_channel(&channel);
553 while (*msg) hal_diag_write_char(*msg++);
557 #ifndef CYG_HAL_STARTUP_ROM
558 #define DIAG_BUFSIZE 2048
559 static char diag_buffer[DIAG_BUFSIZE];
560 static int diag_bp = 0;
564 void hal_diag_write_char(char c)
567 #ifndef CYG_HAL_STARTUP_ROM
568 diag_buffer[diag_bp++] = c;
569 if (diag_bp == sizeof(diag_buffer)) diag_bp = 0;
572 cyg_hal_plf_serial_putc(&channel, c);
575 void hal_diag_read_char(char *c)
577 *c = cyg_hal_plf_serial_getc(&channel);
580 #else // not HAL_DIAG_USES_HARDWARE - it uses GDB protocol
582 void hal_diag_read_char(char *c)
584 *c = cyg_hal_plf_serial_getc(&channel);
587 void hal_diag_write_char(char c)
589 static char line[100];
592 // FIXME: Some LED blinking might be nice right here.
594 // No need to send CRs
595 if( c == '\r' ) return;
599 if (c == '\n' || pos == sizeof(line)) {
600 CYG_INTERRUPT_STATE old;
602 // Disable interrupts. This prevents GDB trying to interrupt us
603 // while we are in the middle of sending a packet. The serial
604 // receive interrupt will be seen when we re-enable interrupts
607 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
608 CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
610 HAL_DISABLE_INTERRUPTS(old);
614 static char hex[] = "0123456789ABCDEF";
617 #ifndef CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
620 cyg_hal_plf_serial_putc(&channel, '$');
621 cyg_hal_plf_serial_putc(&channel, 'O');
623 for(i = 0; i < pos; i++) {
625 char h = hex[(ch>>4)&0xF];
626 char l = hex[ch&0xF];
627 cyg_hal_plf_serial_putc(&channel, h);
628 cyg_hal_plf_serial_putc(&channel, l);
632 cyg_hal_plf_serial_putc(&channel, '#');
633 cyg_hal_plf_serial_putc(&channel, hex[(csum>>4)&0xF]);
634 cyg_hal_plf_serial_putc(&channel, hex[csum&0xF]);
636 #ifdef CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
640 #else // not CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT Ie. usually...
642 // Wait for the ACK character '+' from GDB here and handle
643 // receiving a ^C instead. This is the reason for this clause
645 c1 = cyg_hal_plf_serial_getc(&channel);
648 break; // a good acknowledge
650 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
651 cyg_drv_interrupt_acknowledge(CYGHWR_HAL_GDB_PORT_VECTOR);
653 // Ctrl-C: breakpoint.
654 cyg_hal_gdb_interrupt(
655 (target_register_t)__builtin_return_address(0) );
658 #endif // CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
660 #endif // ! CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
661 // otherwise, loop round again
666 // And re-enable interrupts
667 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
668 CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
670 HAL_RESTORE_INTERRUPTS(old);
679 #endif // !CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
681 /*---------------------------------------------------------------------------*/
682 /* End of hal_diag.c */