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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [xscale/] [iq80321/] [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):   nickg, gthomas
43
// Contributors:nickg, gthomas, msalter
44
// Date:        1998-03-02
45
// Purpose:     HAL diagnostic output
46
// Description: Implementations of HAL diagnostic output support.
47
//
48
//####DESCRIPTIONEND####
49
//
50
//===========================================================================*/
51
 
52
#include <pkgconf/hal.h>
53
#include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
54
#include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
55
 
56
#include <cyg/infra/cyg_type.h>         // base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
 
60
#include <cyg/hal/hal_arch.h>           // basic machine info
61
#include <cyg/hal/hal_intr.h>           // interrupt macros
62
#include <cyg/hal/hal_io.h>             // IO macros
63
#include <cyg/hal/hal_diag.h>
64
#include <cyg/hal/drv_api.h>
65
#include <cyg/hal/hal_if.h>             // interface API
66
#include <cyg/hal/hal_misc.h>           // Helper functions
67
#include <cyg/hal/iq80321.h>            // platform definitions
68
 
69
/*---------------------------------------------------------------------------*/
70
/* From serial_16550.h */
71
 
72
//-----------------------------------------------------------------------------
73
// Based on 1.8432 MHz xtal
74
 
75
struct baud_config {
76
    cyg_int32 baud_rate;
77
    cyg_uint8 msb;
78
    cyg_uint8 lsb;
79
};
80
 
81
struct baud_config baud_conf[] = {
82
    {9600,   0x00, 0x0c},
83
    {19200,  0x00, 0x06},
84
    {38400,  0x00, 0x03},
85
    {57600,  0x00, 0x02},
86
    {115200, 0x00, 0x01}};
87
 
88
// Define the serial registers.
89
#define CYG_DEV_RBR   0x00 // receiver buffer register, read, dlab = 0
90
#define CYG_DEV_THR   0x00 // transmitter holding register, write, dlab = 0
91
#define CYG_DEV_DLL   0x00 // divisor latch (LS), read/write, dlab = 1
92
#define CYG_DEV_IER   0x01 // interrupt enable register, read/write, dlab = 0
93
#define CYG_DEV_DLM   0x01 // divisor latch (MS), read/write, dlab = 1
94
#define CYG_DEV_IIR   0x02 // interrupt identification register, read, dlab = 0
95
#define CYG_DEV_FCR   0x02 // fifo control register, write, dlab = 0
96
#define CYG_DEV_LCR   0x03 // line control register, write
97
#define CYG_DEV_MCR   0x04 // modem control register, write
98
#define CYG_DEV_LSR   0x05 // line status register, read
99
#define CYG_DEV_MSR   0x06 // modem status register, read
100
#define CYG_DEV_SCR   0x07 // scratch pad register
101
 
102
// Interrupt Enable Register
103
#define SIO_IER_RCV 0x01
104
#define SIO_IER_XMT 0x02
105
#define SIO_IER_LS  0x04
106
#define SIO_IER_MS  0x08
107
 
108
// The line status register bits.
109
#define SIO_LSR_DR      0x01            // data ready
110
#define SIO_LSR_OE      0x02            // overrun error
111
#define SIO_LSR_PE      0x04            // parity error
112
#define SIO_LSR_FE      0x08            // framing error
113
#define SIO_LSR_BI      0x10            // break interrupt
114
#define SIO_LSR_THRE    0x20            // transmitter holding register empty
115
#define SIO_LSR_TEMT    0x40            // transmitter register empty
116
#define SIO_LSR_ERR     0x80            // any error condition
117
 
118
// The modem status register bits.
119
#define SIO_MSR_DCTS  0x01              // delta clear to send
120
#define SIO_MSR_DDSR  0x02              // delta data set ready
121
#define SIO_MSR_TERI  0x04              // trailing edge ring indicator
122
#define SIO_MSR_DDCD  0x08              // delta data carrier detect
123
#define SIO_MSR_CTS   0x10              // clear to send
124
#define SIO_MSR_DSR   0x20              // data set ready
125
#define SIO_MSR_RI    0x40              // ring indicator
126
#define SIO_MSR_DCD   0x80              // data carrier detect
127
 
128
// The line control register bits.
129
#define SIO_LCR_WLS0   0x01             // word length select bit 0
130
#define SIO_LCR_WLS1   0x02             // word length select bit 1
131
#define SIO_LCR_STB    0x04             // number of stop bits
132
#define SIO_LCR_PEN    0x08             // parity enable
133
#define SIO_LCR_EPS    0x10             // even parity select
134
#define SIO_LCR_SP     0x20             // stick parity
135
#define SIO_LCR_SB     0x40             // set break
136
#define SIO_LCR_DLAB   0x80             // divisor latch access bit
137
 
138
// Modem Control Register
139
#define SIO_MCR_DTR 0x01
140
#define SIO_MCR_RTS 0x02
141
 
142
 
143
//-----------------------------------------------------------------------------
144
typedef struct {
145
    cyg_uint8* base;
146
    cyg_int32 msec_timeout;
147
    int isr_vector;
148
    cyg_int32 baud_rate;
149
} channel_data_t;
150
 
151
 
152
//-----------------------------------------------------------------------------
153
 
154
static int
155
set_baud( channel_data_t *chan )
156
{
157
    cyg_uint8* base = chan->base;
158
    cyg_uint8 i;
159
 
160
    for (i=0; i<(sizeof(baud_conf)/sizeof(baud_conf[0])); i++)
161
    {
162
        if (chan->baud_rate == baud_conf[i].baud_rate) {
163
            cyg_uint8 lcr;
164
            HAL_READ_UINT8(base+CYG_DEV_LCR, lcr);
165
            HAL_WRITE_UINT8(base+CYG_DEV_LCR, lcr|SIO_LCR_DLAB);
166
            HAL_WRITE_UINT8(base+CYG_DEV_DLL, baud_conf[i].lsb);
167
            HAL_WRITE_UINT8(base+CYG_DEV_DLM, baud_conf[i].msb);
168
            HAL_WRITE_UINT8(base+CYG_DEV_LCR, lcr);
169
            return 1;
170
        }
171
    }
172
    return -1;
173
}
174
 
175
static void
176
cyg_hal_plf_serial_init_channel(void* __ch_data)
177
{
178
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
179
    channel_data_t* chan = (channel_data_t*)__ch_data;
180
 
181
    // 8-1-no parity.
182
    HAL_WRITE_UINT8(base+CYG_DEV_LCR, SIO_LCR_WLS0 | SIO_LCR_WLS1);
183
    chan->baud_rate = CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD;
184
    set_baud( chan );
185
    HAL_WRITE_UINT8(base+CYG_DEV_FCR, 0x07);  // Enable & clear FIFO
186
}
187
 
188
void
189
cyg_hal_plf_serial_putc(void *__ch_data, char c)
190
{
191
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
192
    cyg_uint8 lsr;
193
    CYGARC_HAL_SAVE_GP();
194
 
195
    do {
196
       HAL_READ_UINT8(base+CYG_DEV_LSR, lsr);
197
    } while ((lsr & SIO_LSR_THRE) == 0);
198
 
199
    HAL_WRITE_UINT8(base+CYG_DEV_THR, c);
200
 
201
    CYGARC_HAL_RESTORE_GP();
202
}
203
 
204
static cyg_bool
205
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
206
{
207
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
208
    cyg_uint8 lsr;
209
 
210
    HAL_READ_UINT8(base+CYG_DEV_LSR, lsr);
211
    if ((lsr & SIO_LSR_DR) == 0)
212
        return false;
213
 
214
    HAL_READ_UINT8(base+CYG_DEV_RBR, *ch);
215
 
216
    return true;
217
}
218
 
219
cyg_uint8
220
cyg_hal_plf_serial_getc(void* __ch_data)
221
{
222
    cyg_uint8 ch;
223
    CYGARC_HAL_SAVE_GP();
224
 
225
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
226
 
227
    CYGARC_HAL_RESTORE_GP();
228
    return ch;
229
}
230
 
231
static channel_data_t plf_ser_channels[1] = {
232
    { (cyg_uint8*)IQ80321_UART_ADDR, 1000, CYGNUM_HAL_INTERRUPT_UART }
233
};
234
 
235
static void
236
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
237
                         cyg_uint32 __len)
238
{
239
    CYGARC_HAL_SAVE_GP();
240
 
241
    while(__len-- > 0)
242
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
243
 
244
    CYGARC_HAL_RESTORE_GP();
245
}
246
 
247
static void
248
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
249
{
250
    CYGARC_HAL_SAVE_GP();
251
 
252
    while(__len-- > 0)
253
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
254
 
255
    CYGARC_HAL_RESTORE_GP();
256
}
257
 
258
cyg_bool
259
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
260
{
261
    int delay_count;
262
    channel_data_t* chan = (channel_data_t*)__ch_data;
263
    cyg_bool res;
264
    CYGARC_HAL_SAVE_GP();
265
 
266
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
267
 
268
    for(;;) {
269
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
270
        if (res || 0 == delay_count--)
271
            break;
272
 
273
        CYGACC_CALL_IF_DELAY_US(100);
274
    }
275
 
276
    CYGARC_HAL_RESTORE_GP();
277
    return res;
278
}
279
 
280
static int
281
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
282
{
283
    static int irq_state = 0;
284
    channel_data_t* chan = (channel_data_t*)__ch_data;
285
    int ret = 0;
286
    CYGARC_HAL_SAVE_GP();
287
 
288
    switch (__func) {
289
    case __COMMCTL_IRQ_ENABLE:
290
        irq_state = 1;
291
 
292
        HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, SIO_IER_RCV);
293
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
294
        break;
295
    case __COMMCTL_IRQ_DISABLE:
296
        ret = irq_state;
297
        irq_state = 0;
298
 
299
        HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, 0);
300
        HAL_INTERRUPT_MASK(chan->isr_vector);
301
        break;
302
    case __COMMCTL_DBG_ISR_VECTOR:
303
        ret = chan->isr_vector;
304
        break;
305
    case __COMMCTL_SET_TIMEOUT:
306
    {
307
        va_list ap;
308
 
309
        va_start(ap, __func);
310
 
311
        ret = chan->msec_timeout;
312
        chan->msec_timeout = va_arg(ap, cyg_uint32);
313
 
314
        va_end(ap);
315
    }
316
    case __COMMCTL_GETBAUD:
317
        ret = chan->baud_rate;
318
        break;
319
    case __COMMCTL_SETBAUD:
320
    {
321
        va_list ap;
322
        va_start(ap, __func);
323
        chan->baud_rate = va_arg(ap, cyg_int32);
324
        va_end(ap);
325
        ret = set_baud(chan);
326
        break;
327
    }
328
    default:
329
        break;
330
    }
331
    CYGARC_HAL_RESTORE_GP();
332
    return ret;
333
}
334
 
335
static int
336
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
337
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
338
{
339
    int res = 0;
340
    channel_data_t* chan = (channel_data_t*)__ch_data;
341
    char c;
342
    cyg_uint8 lsr;
343
    CYGARC_HAL_SAVE_GP();
344
 
345
    cyg_drv_interrupt_acknowledge(chan->isr_vector);
346
 
347
    *__ctrlc = 0;
348
    HAL_READ_UINT8(chan->base+CYG_DEV_LSR, lsr);
349
    if ( (lsr & SIO_LSR_DR) != 0 ) {
350
 
351
        HAL_READ_UINT8(chan->base+CYG_DEV_RBR, c);
352
        if( cyg_hal_is_break( &c , 1 ) )
353
            *__ctrlc = 1;
354
 
355
        res = CYG_ISR_HANDLED;
356
    }
357
 
358
    CYGARC_HAL_RESTORE_GP();
359
    return res;
360
}
361
 
362
static void
363
cyg_hal_plf_serial_init(void)
364
{
365
    hal_virtual_comm_table_t* comm;
366
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
367
 
368
    // Disable interrupts.
369
    HAL_INTERRUPT_MASK(plf_ser_channels[0].isr_vector);
370
 
371
    // Init channels
372
    cyg_hal_plf_serial_init_channel(&plf_ser_channels[0]);
373
 
374
    // Setup procs in the vector table
375
 
376
    // Set channel 0
377
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
378
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
379
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &plf_ser_channels[0]);
380
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
381
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
382
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
383
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
384
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
385
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
386
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
387
 
388
    // Restore original console
389
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
390
}
391
 
392
void
393
cyg_hal_plf_comms_init(void)
394
{
395
    static int initialized = 0;
396
 
397
    if (initialized)
398
        return;
399
 
400
    initialized = 1;
401
 
402
    cyg_hal_plf_serial_init();
403
}
404
 
405
/*---------------------------------------------------------------------------*/
406
 
407
cyg_uint8 cyg_hal_led_segment[16] = {
408
    DISPLAY_0, DISPLAY_1, DISPLAY_2, DISPLAY_3,
409
    DISPLAY_4, DISPLAY_5, DISPLAY_6, DISPLAY_7,
410
    DISPLAY_8, DISPLAY_9, DISPLAY_A, DISPLAY_B,
411
    DISPLAY_C, DISPLAY_D, DISPLAY_E, DISPLAY_F };
412
 
413
void
414
hal_diag_led(int n)
415
{
416
    HAL_WRITE_UINT8(DISPLAY_RIGHT, cyg_hal_led_segment[n & 0x0f]);
417
}
418
 
419
/*---------------------------------------------------------------------------*/
420
/* End of hal_diag.c */

powered by: WebSVN 2.1.0

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