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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [xscale/] [pxa2x0/] [current/] [src/] [hal_diag.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*=============================================================================
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 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):   <knud.woehler@microplex.de>
43
// Date:        2002-09-03
44
//
45
//####DESCRIPTIONEND####
46
//
47
//===========================================================================*/
48
 
49
#include <pkgconf/hal.h>
50
#include <pkgconf/system.h>
51
#include CYGBLD_HAL_PLATFORM_H
52
 
53
#include <cyg/infra/cyg_type.h>         // base types
54
#include <cyg/infra/cyg_trac.h>         // tracing macros
55
#include <cyg/infra/cyg_ass.h>          // assertion macros
56
 
57
#include <cyg/hal/hal_arch.h>           // basic machine info
58
#include <cyg/hal/hal_intr.h>           // interrupt macros
59
#include <cyg/hal/hal_io.h>             // IO macros
60
#include <cyg/hal/hal_if.h>             // Calling interface definitions
61
#include <cyg/hal/hal_diag.h>
62
#include <cyg/hal/drv_api.h>            // cyg_drv_interrupt_acknowledge
63
#include <cyg/hal/hal_misc.h>           // Helper functions
64
#include <cyg/hal/hal_pxa2x0.h>         // Hardware definitions
65
 
66
 
67
//-----------------------------------------------------------------------------
68
typedef struct {
69
    cyg_uint8* base;
70
    cyg_int32 msec_timeout;
71
    int isr_vector;
72
    int baud_rate;
73
} channel_data_t;
74
 
75
/*---------------------------------------------------------------------------*/
76
// PXA2X0 Serial Port (UARTx) for Debug
77
 
78
static void
79
init_channel(channel_data_t* __ch_data)
80
{
81
        cyg_uint8* base = __ch_data->base;
82
        cyg_uint8 lcr;
83
    cyg_uint32 brd;
84
 
85
        // 8-1-no parity.
86
        lcr = PXA2X0_UART_LCR_WLS0 | PXA2X0_UART_LCR_WLS1;
87
        lcr |= PXA2X0_UART_LCR_DLAB;
88
        HAL_WRITE_UINT8( base+PXA2X0_UART_LCR, lcr );
89
 
90
        //      Setup divisor
91
    brd = PXA2X0_UART_BAUD_RATE_DIVISOR( __ch_data->baud_rate );
92
    HAL_WRITE_UINT8( base+PXA2X0_UART_DLH, (brd >> 8) & 0xff );
93
    HAL_WRITE_UINT8( base+PXA2X0_UART_DLL, brd & 0xff );
94
 
95
 
96
        //      DLAB = 0 to allow access to FIFOs
97
    lcr &= ~PXA2X0_UART_LCR_DLAB;
98
    HAL_WRITE_UINT8(base+PXA2X0_UART_LCR, lcr);
99
 
100
        //  Enable & clear FIFOs
101
        //  set Interrupt Trigger Level to be 1 byte
102
        HAL_WRITE_UINT8(base+PXA2X0_UART_FCR,
103
                (PXA2X0_UART_FCR_FCR0 | PXA2X0_UART_FCR_FCR1 | PXA2X0_UART_FCR_FCR2));  // Enable & clear FIFO
104
 
105
        //      Configure NRZ, disable DMA requests and enable UART
106
        HAL_WRITE_UINT8(base+PXA2X0_UART_IER, PXA2X0_UART_IER_UUE);
107
}
108
 
109
static void
110
cyg_hal_plf_serial_putc(void *__ch_data, char c)
111
{
112
        cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
113
        cyg_uint8 lsr;
114
        CYGARC_HAL_SAVE_GP();
115
 
116
        do {
117
                HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
118
        } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
119
 
120
        HAL_WRITE_UINT8(base+PXA2X0_UART_THR, c);
121
 
122
        do {
123
                HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
124
        } while ((lsr & PXA2X0_UART_LSR_THRE) == 0);
125
 
126
        CYGARC_HAL_RESTORE_GP();
127
}
128
 
129
static cyg_bool
130
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
131
{
132
        cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
133
        cyg_uint8 lsr;
134
 
135
        HAL_READ_UINT8(base+PXA2X0_UART_LSR, lsr);
136
        if ((lsr & PXA2X0_UART_LSR_DR) == 0)
137
                return false;
138
 
139
        HAL_READ_UINT8(base+PXA2X0_UART_RBR, *ch);
140
 
141
        return true;
142
}
143
 
144
static cyg_uint8
145
cyg_hal_plf_serial_getc(void* __ch_data)
146
{
147
    cyg_uint8 ch;
148
    CYGARC_HAL_SAVE_GP();
149
 
150
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
151
 
152
    CYGARC_HAL_RESTORE_GP();
153
    return ch;
154
}
155
 
156
static channel_data_t ser_channels[] = {
157
#if CYGHWR_HAL_ARM_PXA2X0_FFUART != 0
158
    { (cyg_uint8*)PXA2X0_FFUART_BASE, 1000,
159
      CYGNUM_HAL_INTERRUPT_FFUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
160
#endif
161
#if CYGHWR_HAL_ARM_PXA2X0_BTUART != 0
162
    { (cyg_uint8*)PXA2X0_BTUART_BASE, 1000,
163
      CYGNUM_HAL_INTERRUPT_BTUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
164
#endif
165
#if CYGHWR_HAL_ARM_PXA2X0_STUART != 0
166
    { (cyg_uint8*)PXA2X0_STUART_BASE, 1000,
167
      CYGNUM_HAL_INTERRUPT_STUART, CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD },
168
#endif
169
};
170
 
171
static void
172
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
173
                         cyg_uint32 __len)
174
{
175
    CYGARC_HAL_SAVE_GP();
176
 
177
    while(__len-- > 0)
178
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
179
 
180
    CYGARC_HAL_RESTORE_GP();
181
}
182
 
183
static void
184
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
185
{
186
    CYGARC_HAL_SAVE_GP();
187
 
188
    while(__len-- > 0)
189
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
190
 
191
    CYGARC_HAL_RESTORE_GP();
192
}
193
 
194
cyg_bool
195
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
196
{
197
    int delay_count;
198
    channel_data_t* chan = (channel_data_t*)__ch_data;
199
    cyg_bool res;
200
    CYGARC_HAL_SAVE_GP();
201
 
202
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
203
 
204
    for(;;) {
205
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
206
        if (res || 0 == delay_count--)
207
            break;
208
 
209
        CYGACC_CALL_IF_DELAY_US(100);
210
    }
211
 
212
    CYGARC_HAL_RESTORE_GP();
213
    return res;
214
}
215
 
216
static int
217
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
218
{
219
    static int irq_state = 0;
220
    channel_data_t* chan = (channel_data_t*)__ch_data;
221
    int ret = -1;
222
    cyg_uint8 ier;
223
        va_list ap;
224
 
225
    CYGARC_HAL_SAVE_GP();
226
    va_start(ap, __func);
227
 
228
    switch (__func) {
229
    case __COMMCTL_GETBAUD:
230
        ret = chan->baud_rate;
231
        break;
232
    case __COMMCTL_SETBAUD:
233
        chan->baud_rate = va_arg(ap, cyg_int32);
234
        // Should we verify this value here?
235
        init_channel(chan);
236
        ret = 0;
237
        break;
238
    case __COMMCTL_IRQ_ENABLE:
239
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
240
        HAL_INTERRUPT_SET_LEVEL(chan->isr_vector, 1);
241
        HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
242
        ier |= PXA2X0_UART_IER_RAVIE;
243
        HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
244
        irq_state = 1;
245
        break;
246
    case __COMMCTL_IRQ_DISABLE:
247
        ret = irq_state;
248
        irq_state = 0;
249
        HAL_INTERRUPT_MASK(chan->isr_vector);
250
        HAL_READ_UINT8(chan->base+PXA2X0_UART_IER, ier);
251
        ier &= ~PXA2X0_UART_IER_RAVIE;
252
        HAL_WRITE_UINT8(chan->base+PXA2X0_UART_IER, ier);
253
        break;
254
    case __COMMCTL_DBG_ISR_VECTOR:
255
        ret = chan->isr_vector;
256
        break;
257
    case __COMMCTL_SET_TIMEOUT:
258
        ret = chan->msec_timeout;
259
        chan->msec_timeout = va_arg(ap, cyg_uint32);
260
        break;
261
    default:
262
        break;
263
    }
264
    va_end(ap);
265
    CYGARC_HAL_RESTORE_GP();
266
    return ret;
267
}
268
 
269
static int
270
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
271
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
272
{
273
    channel_data_t* chan = (channel_data_t*)__ch_data;
274
    cyg_uint8 iir;
275
    int res = 0;
276
    CYGARC_HAL_SAVE_GP();
277
 
278
    HAL_READ_UINT8(chan->base+PXA2X0_UART_IIR, iir);
279
    iir &= PXA2X0_UART_IIR_ID_MASK;
280
 
281
    *__ctrlc = 0;
282
    if ( iir == 0x04 ) {
283
        cyg_uint8 c, lsr;
284
        HAL_READ_UINT8(chan->base+PXA2X0_UART_LSR, lsr);
285
        if (lsr & PXA2X0_UART_LSR_DR) {
286
 
287
            HAL_READ_UINT8(chan->base+PXA2X0_UART_RBR, c);
288
 
289
            if( cyg_hal_is_break( &c , 1 ) )
290
                *__ctrlc = 1;
291
        }
292
 
293
        // Acknowledge the interrupt
294
        HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
295
        res = CYG_ISR_HANDLED;
296
    }
297
 
298
    CYGARC_HAL_RESTORE_GP();
299
    return res;
300
}
301
 
302
static void
303
cyg_hal_plf_serial_init(void)
304
{
305
    hal_virtual_comm_table_t* comm;
306
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
307
    int i;
308
 
309
    // Init channels
310
#define NUMOF(x) (sizeof(x)/sizeof(x[0]))
311
    for (i = 0;  i < NUMOF(ser_channels);  i++) {
312
        init_channel(&ser_channels[i]);
313
        CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
314
        comm = CYGACC_CALL_IF_CONSOLE_PROCS();
315
        CYGACC_COMM_IF_CH_DATA_SET(*comm, &ser_channels[i]);
316
        CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
317
        CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
318
        CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
319
        CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
320
        CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
321
        CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
322
        CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
323
    }
324
 
325
    // Restore original console
326
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
327
}
328
 
329
void
330
cyg_hal_plf_comms_init(void)
331
{
332
    static int initialized = 0;
333
 
334
    if (initialized)
335
        return;
336
 
337
    initialized = 1;
338
 
339
    cyg_hal_plf_serial_init();
340
}
341
 
342
/*---------------------------------------------------------------------------*/
343
/* 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.