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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [integrator/] [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):     David A Rusling
43
// Contributors:  Philippe Robin
44
// Date:          November 7, 2000
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 <pkgconf/hal_arm_integrator.h> // board specifics
54
 
55
#include <cyg/infra/cyg_type.h>         // base types
56
#include <cyg/infra/cyg_trac.h>         // tracing macros
57
#include <cyg/infra/cyg_ass.h>          // assertion macros
58
 
59
#include <cyg/hal/hal_arch.h>           // basic machine info
60
#include <cyg/hal/hal_intr.h>           // interrupt macros
61
#include <cyg/hal/hal_io.h>             // IO macros
62
#include <cyg/hal/hal_if.h>             // interface API
63
#include <cyg/hal/hal_misc.h>           // Helper functions
64
#include <cyg/hal/hal_diag.h>
65
#include <cyg/hal/drv_api.h>
66
#include <cyg/hal/hal_integrator.h>        // Hardware definitions
67
 
68
 
69
/*---------------------------------------------------------------------------*/
70
void abcd(void);
71
 
72
/* Codes for ASCI characters 32-127 */
73
unsigned int char_codes[] = {
74
    0x0000, 0x2400, 0x0044, 0x7E12, 0x25DA, 0x4848, 0x2580, 0x0400,
75
    0x0072, 0x001E, 0x7F80, 0x2580, 0x4000, 0x0180, 0x0000, 0x4800,
76
    0x007E, 0x080C, 0x01B6, 0x011E, 0x01CC, 0x01DA, 0x01FA, 0x2802,
77
    0x01FE, 0x01CE, 0x2400, 0x4400, 0x1800, 0x0190, 0x4200, 0x01A6,
78
    0x217E, 0x01EE, 0x251E, 0x0072, 0x241E, 0x00F2, 0x00E2, 0x017A,
79
    0x01EC, 0x2412, 0x001C, 0x18E0, 0x0070, 0x0A6C, 0x126C, 0x007E,
80
    0x01E6, 0x107E, 0x11E6, 0x01DA, 0x2402, 0x007C, 0x4860, 0x506C,
81
    0x5A00, 0x2A00, 0x4812, 0x0072, 0x1200, 0x001E, 0x0046, 0x0010,
82
    0x0200, 0x01BE, 0x01F8, 0x01B0, 0x01BC, 0x01F6, 0x2980, 0x01DE,
83
    0x01E8, 0x2000, 0x001C, 0x3500, 0x2400, 0x21A8, 0x01A8, 0x01B8,
84
    0x01E6, 0x01CE, 0x01A0, 0x01DA, 0x00F0, 0x0038, 0x4020, 0x5028,
85
    0x5A00, 0x030C, 0x4190, 0x2480, 0x2400, 0x2500, 0x0640, 0x0000
86
};
87
 
88
/* Codes for hexadecimal characters */
89
unsigned int hex_codes[] = {
90
    0x007E, 0x080C, 0x01B6, 0x011E, 0x01CC, 0x01DA, 0x01FA, 0x2802,
91
    0x01FE, 0x01CE, 0x01EE, 0x01F8, 0x0072, 0x01BC, 0x00F2, 0x00E2
92
};
93
 
94
void hal_diag_alpha_led_char(char c1, char c2);
95
 
96
 
97
// AMBA uart access macros
98
#define GET_STATUS(p)           (IO_READ((p) + AMBA_UARTFR))
99
#define GET_CHAR(p)             (IO_READ((p) + AMBA_UARTDR))
100
#define PUT_CHAR(p, c)          (IO_WRITE(((p) + AMBA_UARTDR), (c)))
101
#define IO_READ(p)              ((*(volatile unsigned int *)(p)) & 0xFF)
102
#define IO_WRITE(p, c)          (*(unsigned int *)(p) = (c))
103
#define RX_DATA(s)              (((s) & AMBA_UARTFR_RXFE) == 0)
104
#define TX_READY(s)             (((s) & AMBA_UARTFR_TXFF) == 0)
105
#define TX_EMPTY(p)             ((GET_STATUS(p) & AMBA_UARTFR_TMSK) == 0)
106
#define RX_EMPTY(p)             ((GET_STATUS(p) & AMBA_UARTFR_RXFE) == 0)
107
// Define the serial registers.
108
 
109
//-----------------------------------------------------------------------------
110
typedef struct {
111
    cyg_uint8* base;
112
    cyg_int32 msec_timeout;
113
    int isr_vector;
114
} channel_data_t;
115
 
116
//-----------------------------------------------------------------------------
117
 
118
#if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD == 9600)
119
#define ARM_INTEGRATOR_BAUD_DIVISOR     ARM_BAUD_9600
120
#elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD == 19200)
121
#define ARM_INTEGRATOR_BAUD_DIVISOR     ARM_BAUD_9600
122
#elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD == 38400)
123
#define ARM_INTEGRATOR_BAUD_DIVISOR     ARM_BAUD_38400
124
#elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD == 57600)
125
#define ARM_INTEGRATOR_BAUD_DIVISOR     ARM_BAUD_57600
126
#elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD == 115200)
127
#define ARM_INTEGRATOR_BAUD_DIVISOR     ARM_BAUD_115200
128
#endif
129
 
130
static void
131
cyg_hal_plf_serial_init_channel(void* __ch_data)
132
{
133
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
134
 
135
    // first, disable everything
136
    IO_WRITE(base + AMBA_UARTCR, 0x0);
137
 
138
    // Set baud rate CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD
139
    IO_WRITE(base + AMBA_UARTLCR_M, ((ARM_INTEGRATOR_BAUD_DIVISOR & 0xf00) >> 8));
140
    IO_WRITE(base + AMBA_UARTLCR_L, (ARM_INTEGRATOR_BAUD_DIVISOR & 0xff));
141
 
142
    // ----------v----------v----------v----------v----------
143
    // NOTE: MUST BE WRITTEN LAST (AFTER UARTLCR_M & UARTLCR_L)
144
    // ----------^----------^----------^----------^----------
145
    // set the UART to be 8 bits, 1 stop bit, no parity, fifo enabled
146
    IO_WRITE(base + AMBA_UARTLCR_H, (AMBA_UARTLCR_H_WLEN_8 | AMBA_UARTLCR_H_FEN));
147
 
148
    // finally, enable the uart
149
    IO_WRITE(base + AMBA_UARTCR, AMBA_UARTCR_UARTEN);
150
 
151
}
152
 
153
void
154
cyg_hal_plf_serial_putc(void *__ch_data, char c)
155
{
156
    channel_data_t* chan = (channel_data_t*)__ch_data;
157
    cyg_uint8* base = chan->base;
158
    cyg_uint32 status;
159
    CYGARC_HAL_SAVE_GP();
160
 
161
    do {
162
      status = GET_STATUS(base);
163
    } while (!TX_READY(status));        // wait until ready
164
 
165
    PUT_CHAR(base, c);
166
 
167
    if (c == '\n') {
168
      do {
169
        status = GET_STATUS(base);
170
      } while (!TX_READY(status));      // wait until ready
171
 
172
      PUT_CHAR(base, '\r');
173
    }
174
 
175
    CYGARC_HAL_RESTORE_GP();
176
}
177
 
178
static cyg_bool
179
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
180
{
181
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
182
    cyg_uint32 status ;
183
    long timeout = 100;  // A long time...
184
 
185
    do {
186
      status = GET_STATUS(base);
187
      if (--timeout == 0) return false ;
188
    } while (!RX_DATA(status)); // wait until ready
189
 
190
    *ch = GET_CHAR(base);
191
 
192
    return true;
193
}
194
 
195
cyg_uint8
196
cyg_hal_plf_serial_getc(void* __ch_data)
197
{
198
    cyg_uint8 ch;
199
    CYGARC_HAL_SAVE_GP();
200
 
201
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
202
 
203
    CYGARC_HAL_RESTORE_GP();
204
    return ch;
205
}
206
 
207
#if defined(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG) \
208
    || defined(CYGPRI_HAL_IMPLEMENTS_IF_SERVICES)
209
 
210
static channel_data_t integrator_ser_channels[2] = {
211
    { (cyg_uint8*)0x16000000, 1000, CYGNUM_HAL_INTERRUPT_UARTINT0 },
212
    { (cyg_uint8*)0x17000000, 1000, CYGNUM_HAL_INTERRUPT_UARTINT1 }
213
};
214
 
215
static void
216
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
217
                         cyg_uint32 __len)
218
{
219
    CYGARC_HAL_SAVE_GP();
220
 
221
    while(__len-- > 0)
222
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
223
 
224
    CYGARC_HAL_RESTORE_GP();
225
}
226
 
227
static void
228
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
229
{
230
    CYGARC_HAL_SAVE_GP();
231
 
232
    while(__len-- > 0)
233
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
234
 
235
    CYGARC_HAL_RESTORE_GP();
236
}
237
 
238
cyg_bool
239
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
240
{
241
    int delay_count;
242
    channel_data_t* chan = (channel_data_t*)__ch_data;
243
    cyg_bool res;
244
    CYGARC_HAL_SAVE_GP();
245
 
246
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
247
 
248
    for(;;) {
249
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
250
        if (res || 0 == delay_count--)
251
            break;
252
 
253
        CYGACC_CALL_IF_DELAY_US(100);
254
    }
255
 
256
    CYGARC_HAL_RESTORE_GP();
257
    return res;
258
}
259
 
260
static int
261
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
262
{
263
    static int irq_state = 0;
264
    channel_data_t* chan = (channel_data_t*)__ch_data;
265
    int ret = 0;
266
    cyg_uint8 status;
267
    CYGARC_HAL_SAVE_GP();
268
 
269
    switch (__func) {
270
    case __COMMCTL_IRQ_ENABLE:
271
        irq_state = 1;
272
        // Ensure that only Receive ints are generated.
273
        status = IO_READ(chan->base + AMBA_UARTCR);
274
 
275
        status |= (AMBA_UARTCR_RTIE | AMBA_UARTCR_RIE);
276
        HAL_WRITE_UINT32(chan->base + AMBA_UARTCR, status);
277
 
278
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
279
        break;
280
    case __COMMCTL_IRQ_DISABLE:
281
        ret = irq_state;
282
        irq_state = 0;
283
 
284
        status = IO_READ(chan->base + AMBA_UARTCR);
285
        status &= ~(AMBA_UARTCR_RTIE | AMBA_UARTCR_TIE | AMBA_UARTCR_RIE | AMBA_UARTCR_MSIE);
286
        HAL_WRITE_UINT32(chan->base + AMBA_UARTCR, status);
287
 
288
        HAL_INTERRUPT_MASK(chan->isr_vector);
289
        break;
290
    case __COMMCTL_DBG_ISR_VECTOR:
291
        ret = chan->isr_vector;
292
        break;
293
    case __COMMCTL_SET_TIMEOUT:
294
    {
295
        va_list ap;
296
 
297
        va_start(ap, __func);
298
 
299
        ret = chan->msec_timeout;
300
        chan->msec_timeout = va_arg(ap, cyg_uint32);
301
 
302
        va_end(ap);
303
    }
304
    default:
305
        break;
306
    }
307
    CYGARC_HAL_RESTORE_GP();
308
    return ret;
309
}
310
 
311
static int
312
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
313
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
314
{
315
    int res = 0;
316
    channel_data_t* chan = (channel_data_t*)__ch_data;
317
    char c;
318
    cyg_uint32 status;
319
    CYGARC_HAL_SAVE_GP();
320
 
321
    cyg_drv_interrupt_acknowledge(chan->isr_vector);
322
 
323
    *__ctrlc = 0;
324
    status = GET_STATUS(chan->base);
325
 
326
    if ( RX_DATA(status) ) {
327
        c = GET_CHAR(chan->base);
328
 
329
        if( cyg_hal_is_break( &c , 1 ) )
330
            *__ctrlc = 1;
331
 
332
        res = CYG_ISR_HANDLED;
333
    }
334
 
335
    CYGARC_HAL_RESTORE_GP();
336
    return res;
337
}
338
 
339
static void
340
cyg_hal_plf_serial_init(void)
341
{
342
    hal_virtual_comm_table_t* comm;
343
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
344
 
345
    // Disable interrupts.
346
    HAL_INTERRUPT_MASK(integrator_ser_channels[0].isr_vector);
347
    HAL_INTERRUPT_MASK(integrator_ser_channels[1].isr_vector);
348
 
349
    // Init channels
350
    cyg_hal_plf_serial_init_channel(&integrator_ser_channels[0]);
351
    cyg_hal_plf_serial_init_channel(&integrator_ser_channels[1]);
352
 
353
    // Setup procs in the vector table
354
 
355
    // Set channel 0
356
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
357
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
358
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &integrator_ser_channels[0]);
359
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
360
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
361
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
362
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
363
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
364
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
365
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
366
 
367
    // Set channel 1
368
    CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
369
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
370
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &integrator_ser_channels[1]);
371
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
372
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
373
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
374
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
375
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
376
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
377
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
378
 
379
    // Restore original console
380
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
381
 
382
 
383
}
384
 
385
void
386
cyg_hal_plf_comms_init(void)
387
{
388
    static int initialized = 0;
389
 
390
    if (initialized)
391
        return;
392
 
393
    initialized = 1;
394
 
395
    cyg_hal_plf_serial_init();
396
 
397
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT2
398
    cyg_hal_gdb_isr_attach();   // FIXME, hack to get CTRLC working
399
#endif 
400
}
401
 
402
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG || CYGPRI_HAL_IMPLEMENTS_IF_SERVICES
403
 
404
/*---------------------------------------------------------------------------*/
405
 
406
#ifdef CYGHWR_HAL_ARM_INTEGRATOR_DIAG_LEDS
407
 
408
void
409
hal_diag_led(int n)
410
{
411
    volatile unsigned int *leds = (unsigned int *)INTEGRATOR_DBG_LEDS ;
412
 
413
    *leds |= (n & 0xF) ;
414
}
415
void
416
hal_diag_alpha_led(unsigned int val)
417
{
418
  volatile unsigned int *led = (unsigned int *)INTEGRATOR_DBG_BASE;
419
 
420
  while (*led & 0x01) ;
421
 
422
  *led = val;
423
}
424
 
425
void
426
hal_diag_alpha_led_char(char c1, char c2)
427
{
428
  volatile unsigned int *led = (unsigned int *)INTEGRATOR_DBG_BASE;
429
  unsigned int current;
430
 
431
  current = *led;
432
  if (c1) {
433
    if (c1 < 32 || c1 > 127) c1=32;
434
    if (c1 >= 'a' && c1 < 'z') c1 -= 32;
435
 
436
    current &= ~(0x00007FFE << 14);
437
    current |= (char_codes[c1-32] << 14);
438
    }
439
 
440
    if (c2) {
441
        if (c2 < 32 || c2 > 127) c2 = 32;
442
        if (c2 >= 'a' && c2 <= 'z') c2 -= 32;
443
 
444
        current &= ~(0x00007FFE);
445
        current |= char_codes[c2-32];
446
    }
447
 
448
    hal_diag_alpha_led(current);
449
 
450
}
451
 
452
#endif // CYGHWR_HAL_ARM_INTEGRATOR_DIAG_LEDS
453
 
454
/*---------------------------------------------------------------------------*/
455
/* 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.