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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [pxa2x0/] [v2_0/] [src/] [hal_diag.c] - Blame information for rev 526

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

Line No. Rev Author Line
1 27 unneback
/*=============================================================================
2
//
3
//      hal_diag.c
4
//
5
//      HAL 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 Red Hat, 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 version.
16
//
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
20
// for more details.
21
//
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.
25
//
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.
32
//
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.
35
//
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####
42
//
43
// Author(s):   <knud.woehler@microplex.de>
44
// Date:        2002-09-03
45
//
46
//####DESCRIPTIONEND####
47
//
48
//===========================================================================*/
49
 
50
#include <pkgconf/hal.h>
51
#include <pkgconf/system.h>
52
#include CYGBLD_HAL_PLATFORM_H
53
 
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
57
 
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
66
 
67
 
68
//-----------------------------------------------------------------------------
69
typedef struct {
70
    cyg_uint8* base;
71
    cyg_int32 msec_timeout;
72
    int isr_vector;
73
    int baud_rate;
74
} channel_data_t;
75
 
76
/*---------------------------------------------------------------------------*/
77
// PXA2X0 Serial Port (UARTx) for Debug
78
 
79
static void
80
init_channel(channel_data_t* __ch_data)
81
{
82
        cyg_uint8* base = __ch_data->base;
83
        cyg_uint8 lcr;
84
    cyg_uint32 brd;
85
 
86
        // 8-1-no parity.
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 );
90
 
91
        //      Setup divisor
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 );
95
 
96
 
97
        //      DLAB = 0 to allow access to FIFOs
98
    lcr &= ~PXA2X0_UART_LCR_DLAB;
99
    HAL_WRITE_UINT8(base+PXA2X0_UART_LCR, lcr);
100
 
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
105
 
106
        //      Configure NRZ, disable DMA requests and enable UART
107
        HAL_WRITE_UINT8(base+PXA2X0_UART_IER, PXA2X0_UART_IER_UUE);
108
}
109
 
110
static void
111
cyg_hal_plf_serial_putc(void *__ch_data, char c)
112
{
113
        cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
114
        cyg_uint8 lsr;
115
        CYGARC_HAL_SAVE_GP();
116
 
117
        do {
118
                HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
119
        } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
120
 
121
        HAL_WRITE_UINT8(base+PXA2X0_UART_THR, c);
122
 
123
        do {
124
                HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
125
        } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
126
 
127
        CYGARC_HAL_RESTORE_GP();
128
}
129
 
130
static cyg_bool
131
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
132
{
133
        cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
134
        cyg_uint8 lsr;
135
 
136
        HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
137
        if ((lsr & PXA2X0_UART_LSR_DR) == 0)
138
                return false;
139
 
140
        HAL_READ_UINT8(base+PXA2X0_UART_RBR, *ch);
141
 
142
        return true;
143
}
144
 
145
static cyg_uint8
146
cyg_hal_plf_serial_getc(void* __ch_data)
147
{
148
    cyg_uint8 ch;
149
    CYGARC_HAL_SAVE_GP();
150
 
151
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
152
 
153
    CYGARC_HAL_RESTORE_GP();
154
    return ch;
155
}
156
 
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 },
161
#endif
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 },
165
#endif
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 },
169
#endif
170
};
171
 
172
static void
173
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
174
                         cyg_uint32 __len)
175
{
176
    CYGARC_HAL_SAVE_GP();
177
 
178
    while(__len-- > 0)
179
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
180
 
181
    CYGARC_HAL_RESTORE_GP();
182
}
183
 
184
static void
185
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
186
{
187
    CYGARC_HAL_SAVE_GP();
188
 
189
    while(__len-- > 0)
190
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
191
 
192
    CYGARC_HAL_RESTORE_GP();
193
}
194
 
195
cyg_bool
196
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
197
{
198
    int delay_count;
199
    channel_data_t* chan = (channel_data_t*)__ch_data;
200
    cyg_bool res;
201
    CYGARC_HAL_SAVE_GP();
202
 
203
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
204
 
205
    for(;;) {
206
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
207
        if (res || 0 == delay_count--)
208
            break;
209
 
210
        CYGACC_CALL_IF_DELAY_US(100);
211
    }
212
 
213
    CYGARC_HAL_RESTORE_GP();
214
    return res;
215
}
216
 
217
static int
218
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
219
{
220
    static int irq_state = 0;
221
    channel_data_t* chan = (channel_data_t*)__ch_data;
222
    int ret = -1;
223
    cyg_uint8 ier;
224
        va_list ap;
225
 
226
    CYGARC_HAL_SAVE_GP();
227
    va_start(ap, __func);
228
 
229
    switch (__func) {
230
    case __COMMCTL_GETBAUD:
231
        ret = chan->baud_rate;
232
        break;
233
    case __COMMCTL_SETBAUD:
234
        chan->baud_rate = va_arg(ap, cyg_int32);
235
        // Should we verify this value here?
236
        init_channel(chan);
237
        ret = 0;
238
        break;
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);
245
        irq_state = 1;
246
        break;
247
    case __COMMCTL_IRQ_DISABLE:
248
        ret = irq_state;
249
        irq_state = 0;
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);
254
        break;
255
    case __COMMCTL_DBG_ISR_VECTOR:
256
        ret = chan->isr_vector;
257
        break;
258
    case __COMMCTL_SET_TIMEOUT:
259
        ret = chan->msec_timeout;
260
        chan->msec_timeout = va_arg(ap, cyg_uint32);
261
        break;
262
    default:
263
        break;
264
    }
265
    va_end(ap);
266
    CYGARC_HAL_RESTORE_GP();
267
    return ret;
268
}
269
 
270
static int
271
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
272
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
273
{
274
    channel_data_t* chan = (channel_data_t*)__ch_data;
275
    cyg_uint8 iir;
276
    int res = 0;
277
    CYGARC_HAL_SAVE_GP();
278
 
279
    HAL_READ_UINT8(chan->base+PXA2X0_UART_IIR, iir);
280
    iir &= PXA2X0_UART_IIR_ID_MASK;
281
 
282
    *__ctrlc = 0;
283
    if ( iir == 0x04 ) {
284
        cyg_uint8 c, lsr;
285
        HAL_READ_UINT8(chan->base+PXA2X0_UART_LSR, lsr);
286
        if (lsr & PXA2X0_UART_LSR_DR) {
287
 
288
            HAL_READ_UINT8(chan->base+PXA2X0_UART_RBR, c);
289
 
290
            if( cyg_hal_is_break( &c , 1 ) )
291
                *__ctrlc = 1;
292
        }
293
 
294
        // Acknowledge the interrupt
295
        HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
296
        res = CYG_ISR_HANDLED;
297
    }
298
 
299
    CYGARC_HAL_RESTORE_GP();
300
    return res;
301
}
302
 
303
static void
304
cyg_hal_plf_serial_init(void)
305
{
306
    hal_virtual_comm_table_t* comm;
307
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
308
    int i;
309
 
310
    // Init channels
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);
324
    }
325
 
326
    // Restore original console
327
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
328
}
329
 
330
void
331
cyg_hal_plf_comms_init(void)
332
{
333
    static int initialized = 0;
334
 
335
    if (initialized)
336
        return;
337
 
338
    initialized = 1;
339
 
340
    cyg_hal_plf_serial_init();
341
}
342
 
343
/*---------------------------------------------------------------------------*/
344
/* End of hal_diag.c */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.