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####
43 // Author(s): <knud.woehler@microplex.de>
46 //####DESCRIPTIONEND####
48 //===========================================================================*/
50 #include <pkgconf/hal.h>
51 #include <pkgconf/system.h>
52 #include CYGBLD_HAL_PLATFORM_H
54 #include <cyg/infra/cyg_type.h> // base types
55 #include <cyg/infra/cyg_trac.h> // tracing macros
56 #include <cyg/infra/cyg_ass.h> // assertion macros
58 #include <cyg/hal/hal_arch.h> // basic machine info
59 #include <cyg/hal/hal_intr.h> // interrupt macros
60 #include <cyg/hal/hal_io.h> // IO macros
61 #include <cyg/hal/hal_if.h> // Calling interface definitions
62 #include <cyg/hal/hal_diag.h>
63 #include <cyg/hal/drv_api.h> // cyg_drv_interrupt_acknowledge
64 #include <cyg/hal/hal_misc.h> // Helper functions
65 #include <cyg/hal/hal_pxa2x0.h> // Hardware definitions
68 //-----------------------------------------------------------------------------
71 cyg_int32 msec_timeout;
76 /*---------------------------------------------------------------------------*/
77 // PXA2X0 Serial Port (UARTx) for Debug
80 init_channel(channel_data_t* __ch_data)
82 cyg_uint8* base = __ch_data->base;
87 lcr = PXA2X0_UART_LCR_WLS0 | PXA2X0_UART_LCR_WLS1;
88 lcr |= PXA2X0_UART_LCR_DLAB;
89 HAL_WRITE_UINT8( base+PXA2X0_UART_LCR, lcr );
92 brd = PXA2X0_UART_BAUD_RATE_DIVISOR( __ch_data->baud_rate );
93 HAL_WRITE_UINT8( base+PXA2X0_UART_DLH, (brd >> 8) & 0xff );
94 HAL_WRITE_UINT8( base+PXA2X0_UART_DLL, brd & 0xff );
97 // DLAB = 0 to allow access to FIFOs
98 lcr &= ~PXA2X0_UART_LCR_DLAB;
99 HAL_WRITE_UINT8(base+PXA2X0_UART_LCR, lcr);
101 // Enable & clear FIFOs
102 // set Interrupt Trigger Level to be 1 byte
103 HAL_WRITE_UINT8(base+PXA2X0_UART_FCR,
104 (PXA2X0_UART_FCR_FCR0 | PXA2X0_UART_FCR_FCR1 | PXA2X0_UART_FCR_FCR2)); // Enable & clear FIFO
106 // Configure NRZ, disable DMA requests and enable UART
107 HAL_WRITE_UINT8(base+PXA2X0_UART_IER, PXA2X0_UART_IER_UUE);
111 cyg_hal_plf_serial_putc(void *__ch_data, char c)
113 cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
115 CYGARC_HAL_SAVE_GP();
118 HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
119 } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
121 HAL_WRITE_UINT8(base+PXA2X0_UART_THR, c);
124 HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
125 } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
127 CYGARC_HAL_RESTORE_GP();
131 cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
133 cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
136 HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
137 if ((lsr & PXA2X0_UART_LSR_DR) == 0)
140 HAL_READ_UINT8(base+PXA2X0_UART_RBR, *ch);
146 cyg_hal_plf_serial_getc(void* __ch_data)
149 CYGARC_HAL_SAVE_GP();
151 while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
153 CYGARC_HAL_RESTORE_GP();
157 static channel_data_t ser_channels[] = {
158 #if CYGHWR_HAL_ARM_PXA2X0_FFUART != 0
159 { (cyg_uint8*)PXA2X0_FFUART_BASE, 1000,
160 CYGNUM_HAL_INTERRUPT_FFUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
162 #if CYGHWR_HAL_ARM_PXA2X0_BTUART != 0
163 { (cyg_uint8*)PXA2X0_BTUART_BASE, 1000,
164 CYGNUM_HAL_INTERRUPT_BTUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
166 #if CYGHWR_HAL_ARM_PXA2X0_STUART != 0
167 { (cyg_uint8*)PXA2X0_STUART_BASE, 1000,
168 CYGNUM_HAL_INTERRUPT_STUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
173 cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
176 CYGARC_HAL_SAVE_GP();
179 cyg_hal_plf_serial_putc(__ch_data, *__buf++);
181 CYGARC_HAL_RESTORE_GP();
185 cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
187 CYGARC_HAL_SAVE_GP();
190 *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
192 CYGARC_HAL_RESTORE_GP();
196 cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
199 channel_data_t* chan = (channel_data_t*)__ch_data;
201 CYGARC_HAL_SAVE_GP();
203 delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
206 res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
207 if (res || 0 == delay_count--)
210 CYGACC_CALL_IF_DELAY_US(100);
213 CYGARC_HAL_RESTORE_GP();
218 cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
220 static int irq_state = 0;
221 channel_data_t* chan = (channel_data_t*)__ch_data;
226 CYGARC_HAL_SAVE_GP();
227 va_start(ap, __func);
230 case __COMMCTL_GETBAUD:
231 ret = chan->baud_rate;
233 case __COMMCTL_SETBAUD:
234 chan->baud_rate = va_arg(ap, cyg_int32);
235 // Should we verify this value here?
239 case __COMMCTL_IRQ_ENABLE:
240 HAL_INTERRUPT_UNMASK(chan->isr_vector);
241 HAL_INTERRUPT_SET_LEVEL(chan->isr_vector, 1);
242 HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
243 ier |= PXA2X0_UART_IER_RAVIE;
244 HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
247 case __COMMCTL_IRQ_DISABLE:
250 HAL_INTERRUPT_MASK(chan->isr_vector);
251 HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
252 ier &= ~PXA2X0_UART_IER_RAVIE;
253 HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
255 case __COMMCTL_DBG_ISR_VECTOR:
256 ret = chan->isr_vector;
258 case __COMMCTL_SET_TIMEOUT:
259 ret = chan->msec_timeout;
260 chan->msec_timeout = va_arg(ap, cyg_uint32);
266 CYGARC_HAL_RESTORE_GP();
271 cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
272 CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
274 channel_data_t* chan = (channel_data_t*)__ch_data;
277 CYGARC_HAL_SAVE_GP();
279 HAL_READ_UINT8(chan->base+PXA2X0_UART_IIR, iir);
280 iir &= PXA2X0_UART_IIR_ID_MASK;
285 HAL_READ_UINT8(chan->base+PXA2X0_UART_LSR, lsr);
286 if (lsr & PXA2X0_UART_LSR_DR) {
288 HAL_READ_UINT8(chan->base+PXA2X0_UART_RBR, c);
290 if( cyg_hal_is_break( &c , 1 ) )
294 // Acknowledge the interrupt
295 HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
296 res = CYG_ISR_HANDLED;
299 CYGARC_HAL_RESTORE_GP();
304 cyg_hal_plf_serial_init(void)
306 hal_virtual_comm_table_t* comm;
307 int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
311 #define NUMOF(x) (sizeof(x)/sizeof(x[0]))
312 for (i = 0; i < NUMOF(ser_channels); i++) {
313 init_channel(&ser_channels[i]);
314 CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
315 comm = CYGACC_CALL_IF_CONSOLE_PROCS();
316 CYGACC_COMM_IF_CH_DATA_SET(*comm, &ser_channels[i]);
317 CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
318 CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
319 CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
320 CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
321 CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
322 CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
323 CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
326 // Restore original console
327 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
331 cyg_hal_plf_comms_init(void)
333 static int initialized = 0;
340 cyg_hal_plf_serial_init();
343 /*---------------------------------------------------------------------------*/
344 /* End of hal_diag.c */