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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [cogent/] [v2_0/] [src/] [hal_diag.c] - Blame information for rev 773

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):    nickg, jskov
44
// Contributors: nickg, jskov
45
// Date:         1999-03-23
46
// Purpose:      HAL diagnostic output
47
// Description:  Implementations of HAL diagnostic output support.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//=============================================================================
52
 
53
#include <pkgconf/hal.h>
54
 
55
#include <cyg/hal/hal_diag.h>           // our header.
56
 
57
#include <cyg/infra/cyg_type.h>         // base types, externC
58
#include <cyg/hal/drv_api.h>            // CYG_ISR_HANDLED
59
#include <cyg/hal/hal_misc.h>           // Helper functions
60
#include <cyg/hal/hal_io.h>             // IO macros
61
#include <cyg/hal/hal_intr.h>           // Interrupt macros
62
 
63
#include <cyg/hal/hal_arch.h>           // SAVE/RESTORE GP
64
#include <cyg/hal/hal_if.h>             // Calling-if API
65
 
66
 
67
static void cyg_hal_plf_serial_init(void);
68
static void cyg_hal_plf_lcd_init(void);
69
 
70
void
71
cyg_hal_plf_comms_init(void)
72
{
73
    static int initialized = 0;
74
 
75
    if (initialized)
76
        return;
77
 
78
    initialized = 1;
79
 
80
    cyg_hal_plf_serial_init();
81
    cyg_hal_plf_lcd_init();
82
}
83
 
84
//=============================================================================
85
// Serial driver
86
//=============================================================================
87
 
88
//-----------------------------------------------------------------------------
89
// There are two serial ports.
90
#define CYG_DEV_SERIAL_BASE_A    0xe900047 // port A
91
#define CYG_DEV_SERIAL_BASE_B    0xe900007 // port B
92
 
93
//-----------------------------------------------------------------------------
94
// Default baud rate is 38400
95
#define CYG_DEV_SERIAL_RS232_T1_VALUE_B38400         0x00
96
#define CYG_DEV_SERIAL_RS232_T2_VALUE_B38400         0x06
97
 
98
//-----------------------------------------------------------------------------
99
// Define the serial registers. The Cogent board is equipped with a 16552
100
// serial chip.
101
#define CYG_DEV_SERIAL_RBR   0x00  // receiver buffer register, read, dlab = 0
102
#define CYG_DEV_SERIAL_THR   0x00 // transmitter holding register, write, dlab = 0
103
#define CYG_DEV_SERIAL_DLL   0x00 // divisor latch (LS), read/write, dlab = 1
104
#define CYG_DEV_SERIAL_IER   0x08 // interrupt enable register, read/write, dlab = 0
105
#define CYG_DEV_SERIAL_DLM   0x08 // divisor latch (MS), read/write, dlab = 1
106
#define CYG_DEV_SERIAL_IIR   0x10 // interrupt identification register, read, dlab = 0
107
#define CYG_DEV_SERIAL_FCR   0x10 // fifo control register, write, dlab = 0
108
#define CYG_DEV_SERIAL_AFR   0x10 // alternate function register, read/write, dlab = 1
109
#define CYG_DEV_SERIAL_LCR   0x18 // line control register, read/write
110
#define CYG_DEV_SERIAL_MCR   0x20
111
#define CYG_DEV_SERIAL_MCR_A 0x20
112
#define CYG_DEV_SERIAL_MCR_B 0x20
113
#define CYG_DEV_SERIAL_LSR   0x28 // line status register, read
114
#define CYG_DEV_SERIAL_MSR   0x30 // modem status register, read
115
#define CYG_DEV_SERIAL_SCR   0x38 // scratch pad register
116
 
117
// The interrupt enable register bits.
118
#define SIO_IER_ERDAI   0x01            // enable received data available irq
119
#define SIO_IER_ETHREI  0x02            // enable THR empty interrupt
120
#define SIO_IER_ELSI    0x04            // enable receiver line status irq
121
#define SIO_IER_EMSI    0x08            // enable modem status interrupt
122
 
123
// The interrupt identification register bits.
124
#define SIO_IIR_IP      0x01            // 0 if interrupt pending
125
#define SIO_IIR_ID_MASK 0x0e            // mask for interrupt ID bits
126
#define ISR_Tx  0x02
127
#define ISR_Rx  0x04
128
 
129
// The line status register bits.
130
#define SIO_LSR_DR      0x01            // data ready
131
#define SIO_LSR_OE      0x02            // overrun error
132
#define SIO_LSR_PE      0x04            // parity error
133
#define SIO_LSR_FE      0x08            // framing error
134
#define SIO_LSR_BI      0x10            // break interrupt
135
#define SIO_LSR_THRE    0x20            // transmitter holding register empty
136
#define SIO_LSR_TEMT    0x40            // transmitter register empty
137
#define SIO_LSR_ERR     0x80            // any error condition
138
 
139
// The modem status register bits.
140
#define SIO_MSR_DCTS  0x01              // delta clear to send
141
#define SIO_MSR_DDSR  0x02              // delta data set ready
142
#define SIO_MSR_TERI  0x04              // trailing edge ring indicator
143
#define SIO_MSR_DDCD  0x08              // delta data carrier detect
144
#define SIO_MSR_CTS   0x10              // clear to send
145
#define SIO_MSR_DSR   0x20              // data set ready
146
#define SIO_MSR_RI    0x40              // ring indicator
147
#define SIO_MSR_DCD   0x80              // data carrier detect
148
 
149
// The line control register bits.
150
#define SIO_LCR_WLS0   0x01             // word length select bit 0
151
#define SIO_LCR_WLS1   0x02             // word length select bit 1
152
#define SIO_LCR_STB    0x04             // number of stop bits
153
#define SIO_LCR_PEN    0x08             // parity enable
154
#define SIO_LCR_EPS    0x10             // even parity select
155
#define SIO_LCR_SP     0x20             // stick parity
156
#define SIO_LCR_SB     0x40             // set break
157
#define SIO_LCR_DLAB   0x80             // divisor latch access bit
158
 
159
// The FIFO control register
160
#define SIO_FCR_FCR0   0x01             // enable xmit and rcvr fifos
161
#define SIO_FCR_FCR1   0x02             // clear RCVR FIFO
162
#define SIO_FCR_FCR2   0x04             // clear XMIT FIFO
163
 
164
 
165
//-----------------------------------------------------------------------------
166
typedef struct {
167
    cyg_uint8* base;
168
    cyg_int32 msec_timeout;
169
    int isr_vector;
170
} channel_data_t;
171
 
172
//-----------------------------------------------------------------------------
173
static void
174
init_serial_channel(channel_data_t* __ch_data)
175
{
176
    cyg_uint8* base = __ch_data->base;
177
    cyg_uint8 lcr;
178
 
179
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_IER, 0);
180
 
181
    // Disable and clear FIFOs (need to enable to clear).
182
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_FCR,
183
                    (SIO_FCR_FCR0 | SIO_FCR_FCR1 | SIO_FCR_FCR2));
184
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_FCR, 0);
185
 
186
    // 8-1-no parity.
187
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_LCR, SIO_LCR_WLS0 | SIO_LCR_WLS1);
188
 
189
    // Set speed to 38400.
190
    HAL_READ_UINT8(base+CYG_DEV_SERIAL_LCR, lcr);
191
    lcr |= SIO_LCR_DLAB;
192
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_LCR, lcr);
193
 
194
 
195
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_DLL,
196
                    CYG_DEV_SERIAL_RS232_T2_VALUE_B38400);
197
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_DLM,
198
                    CYG_DEV_SERIAL_RS232_T1_VALUE_B38400);
199
    lcr &= ~SIO_LCR_DLAB;
200
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_LCR, lcr);
201
 
202
    {
203
        // Special initialization for ST16C552 on CMA102
204
        cyg_uint8 mcr;
205
 
206
        HAL_READ_UINT8(base+CYG_DEV_SERIAL_MCR_A, mcr);
207
        mcr |= 8;
208
        HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_MCR_A, mcr);
209
 
210
        HAL_READ_UINT8(base+CYG_DEV_SERIAL_MCR_B, mcr);
211
        mcr |= 8;
212
        HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_MCR_B, mcr);
213
    }
214
 
215
    // Enable FIFOs (and clear them).
216
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_FCR,
217
                    (SIO_FCR_FCR0 | SIO_FCR_FCR1 | SIO_FCR_FCR2));
218
}
219
 
220
static cyg_bool
221
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
222
{
223
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
224
    cyg_uint8 lsr;
225
 
226
    HAL_READ_UINT8(base+CYG_DEV_SERIAL_LSR, lsr);
227
    if ((lsr & SIO_LSR_DR) == 0)
228
        return false;
229
 
230
    HAL_READ_UINT8(base+CYG_DEV_SERIAL_RBR, *ch);
231
 
232
    return true;
233
}
234
 
235
 
236
cyg_uint8
237
cyg_hal_plf_serial_getc(void* __ch_data)
238
{
239
    cyg_uint8 ch;
240
    CYGARC_HAL_SAVE_GP();
241
 
242
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
243
 
244
    CYGARC_HAL_RESTORE_GP();
245
    return ch;
246
}
247
 
248
void
249
cyg_hal_plf_serial_putc(void* __ch_data, cyg_uint8 c)
250
{
251
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
252
    cyg_uint8 lsr;
253
    CYGARC_HAL_SAVE_GP();
254
 
255
    do {
256
        HAL_READ_UINT8(base+CYG_DEV_SERIAL_LSR, lsr);
257
    } while ((lsr & SIO_LSR_THRE) == 0);
258
 
259
    HAL_WRITE_UINT8(base+CYG_DEV_SERIAL_THR, c);
260
 
261
    // Hang around until the character has been safely sent.
262
    do {
263
        HAL_READ_UINT8(base+CYG_DEV_SERIAL_LSR, lsr);
264
    } while ((lsr & SIO_LSR_THRE) == 0);
265
 
266
    CYGARC_HAL_RESTORE_GP();
267
}
268
 
269
static channel_data_t channels[2] = {
270
    { (cyg_uint8*)CYG_DEV_SERIAL_BASE_A, 1000, CYGNUM_HAL_INTERRUPT_SIU_IRQ1},
271
    { (cyg_uint8*)CYG_DEV_SERIAL_BASE_B, 1000, CYGNUM_HAL_INTERRUPT_SIU_IRQ1}
272
};
273
 
274
static void
275
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
276
                         cyg_uint32 __len)
277
{
278
    CYGARC_HAL_SAVE_GP();
279
 
280
    while(__len-- > 0)
281
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
282
 
283
    CYGARC_HAL_RESTORE_GP();
284
}
285
 
286
static void
287
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
288
{
289
    CYGARC_HAL_SAVE_GP();
290
 
291
    while(__len-- > 0)
292
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
293
 
294
    CYGARC_HAL_RESTORE_GP();
295
}
296
 
297
cyg_bool
298
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
299
{
300
    int delay_count;
301
    channel_data_t* chan = (channel_data_t*)__ch_data;
302
    cyg_bool res;
303
    CYGARC_HAL_SAVE_GP();
304
 
305
    delay_count = chan->msec_timeout * 10; // delay in .1 ms steps
306
    for(;;) {
307
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
308
        if (res || 0 == delay_count--)
309
            break;
310
 
311
        CYGACC_CALL_IF_DELAY_US(100);
312
    }
313
 
314
    CYGARC_HAL_RESTORE_GP();
315
    return res;
316
}
317
 
318
static int
319
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
320
{
321
    static int irq_state = 0;
322
    channel_data_t* chan = (channel_data_t*)__ch_data;
323
    cyg_uint8 ier;
324
    int ret = 0;
325
    CYGARC_HAL_SAVE_GP();
326
 
327
    switch (__func) {
328
    case __COMMCTL_IRQ_ENABLE:
329
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
330
        HAL_INTERRUPT_SET_LEVEL(chan->isr_vector, 1);
331
        HAL_READ_UINT8(chan->base+CYG_DEV_SERIAL_IER, ier);
332
        ier |= SIO_IER_ERDAI;
333
        HAL_WRITE_UINT8(chan->base+CYG_DEV_SERIAL_IER, ier);
334
        irq_state = 1;
335
        break;
336
    case __COMMCTL_IRQ_DISABLE:
337
        ret = irq_state;
338
        irq_state = 0;
339
        HAL_INTERRUPT_MASK(chan->isr_vector);
340
        HAL_READ_UINT8(chan->base+CYG_DEV_SERIAL_IER, ier);
341
        ier &= ~SIO_IER_ERDAI;
342
        HAL_WRITE_UINT8(chan->base+CYG_DEV_SERIAL_IER, ier);
343
        break;
344
    case __COMMCTL_DBG_ISR_VECTOR:
345
        ret = chan->isr_vector;
346
        break;
347
    case __COMMCTL_SET_TIMEOUT:
348
    {
349
        va_list ap;
350
 
351
        va_start(ap, __func);
352
 
353
        ret = chan->msec_timeout;
354
        chan->msec_timeout = va_arg(ap, cyg_uint32);
355
 
356
        va_end(ap);
357
    }
358
    default:
359
        break;
360
    }
361
    CYGARC_HAL_RESTORE_GP();
362
    return ret;
363
}
364
 
365
static int
366
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
367
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
368
{
369
    channel_data_t* chan = (channel_data_t*)__ch_data;
370
    cyg_uint8 _iir;
371
    int res = 0;
372
    CYGARC_HAL_SAVE_GP();
373
 
374
    HAL_READ_UINT8(chan->base+CYG_DEV_SERIAL_IIR, _iir);
375
    _iir &= SIO_IIR_ID_MASK;
376
 
377
    *__ctrlc = 0;
378
    if ( ISR_Rx == _iir ) {
379
        cyg_uint8 c, lsr;
380
        HAL_READ_UINT8(chan->base+CYG_DEV_SERIAL_LSR, lsr);
381
        if (lsr & SIO_LSR_DR) {
382
 
383
            HAL_READ_UINT8(chan->base+CYG_DEV_SERIAL_RBR, c);
384
 
385
            if( cyg_hal_is_break( &c , 1 ) )
386
                *__ctrlc = 1;
387
        }
388
 
389
        // Acknowledge the interrupt
390
        HAL_INTERRUPT_ACKNOWLEDGE(chan->isr_vector);
391
        res = CYG_ISR_HANDLED;
392
    }
393
 
394
    CYGARC_HAL_RESTORE_GP();
395
    return res;
396
}
397
 
398
static void
399
cyg_hal_plf_serial_init(void)
400
{
401
    hal_virtual_comm_table_t* comm;
402
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
403
 
404
    // Disable interrupts.
405
    HAL_INTERRUPT_MASK(channels[0].isr_vector);
406
    HAL_INTERRUPT_MASK(channels[1].isr_vector);
407
 
408
    // Init channels
409
    init_serial_channel(&channels[0]);
410
    init_serial_channel(&channels[1]);
411
 
412
    // Setup procs in the vector table
413
 
414
    // Set channel 0
415
    CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
416
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
417
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &channels[0]);
418
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
419
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
420
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
421
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
422
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
423
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
424
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
425
 
426
    // Set channel 1
427
    CYGACC_CALL_IF_SET_CONSOLE_COMM(1);
428
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
429
    CYGACC_COMM_IF_CH_DATA_SET(*comm, &channels[1]);
430
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
431
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
432
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
433
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
434
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
435
    CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_serial_isr);
436
    CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
437
 
438
    // Restore original console
439
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
440
}
441
 
442
 
443
//=============================================================================
444
// LCD driver
445
//=============================================================================
446
 
447
// The LCD driver is only used by the new vector code. Cannot be used
448
// by the old compatibility cruft.
449
 
450
// FEMA 162B 16 character x 2 line LCD
451
// base addresses and register offsets *
452
 
453
#define MBD_BASE 0
454
 
455
#define LCD_BASE                (MBD_BASE + 0xEB00007)
456
 
457
#define LCD_DATA                0x00 // read/write lcd data
458
#define LCD_STAT                0x08 // read lcd busy status
459
#define LCD_CMD                 0x08 // write lcd command
460
 
461
// status register bit definitions
462
#define LCD_STAT_BUSY   0x80    // 1 = display busy
463
#define LCD_STAT_ADD    0x7F    // bits 0-6 return current display address
464
 
465
// command register definitions
466
#define LCD_CMD_RST             0x01    // clear entire display and reset display address
467
#define LCD_CMD_HOME            0x02    // reset display address and reset any shifting
468
#define LCD_CMD_ECL             0x04    // move cursor left one position on next data write
469
#define LCD_CMD_ESL             0x05    // shift display left one position on next data write
470
#define LCD_CMD_ECR             0x06    // move cursor right one position on next data write
471
#define LCD_CMD_ESR             0x07    // shift display right one position on next data write
472
#define LCD_CMD_DOFF            0x08    // display off, cursor off, blinking off
473
#define LCD_CMD_BL              0x09    // blink character at current cursor position
474
#define LCD_CMD_CUR             0x0A    // enable cursor on
475
#define LCD_CMD_DON             0x0C    // turn display on
476
#define LCD_CMD_CL              0x10    // move cursor left one position
477
#define LCD_CMD_SL              0x14    // shift display left one position
478
#define LCD_CMD_CR              0x18    // move cursor right one position
479
#define LCD_CMD_SR              0x1C    // shift display right one position
480
#define LCD_CMD_MODE            0x38    // sets 8 bits, 2 lines, 5x7 characters
481
#define LCD_CMD_ACG             0x40    // bits 0-5 sets the character generator address
482
#define LCD_CMD_ADD             0x80    // bits 0-6 sets the display data address to line 1 +
483
 
484
// LCD status values
485
#define LCD_OK                  0x00
486
#define LCD_ERR                 0x01
487
 
488
#define LCD_LINE0       0x00
489
#define LCD_LINE1       0x40
490
 
491
#define LCD_LINE_LENGTH 16
492
 
493
static char lcd_line0[LCD_LINE_LENGTH+1];
494
static char lcd_line1[LCD_LINE_LENGTH+1];
495
static char *lcd_line[2] = { lcd_line0, lcd_line1 };
496
static int lcd_curline = 0;
497
static int lcd_linepos = 0;
498
 
499
 
500
static void lcd_dis(int add, char *s, cyg_uint8* base);
501
 
502
static void
503
init_lcd_channel(cyg_uint8* base)
504
{
505
    cyg_uint8 stat;
506
    int i;
507
 
508
    // wait for not busy
509
    // Note: It seems that the LCD isn't quite ready to process commands
510
    // when it clears the BUSY flag. Reading the status address an extra
511
    // time seems to give it enough breathing room.
512
    do { HAL_READ_UINT8(base+LCD_STAT, stat); } while (stat & LCD_STAT_BUSY);
513
    HAL_READ_UINT8(base+LCD_STAT, stat);
514
 
515
    // configure the lcd for 8 bits/char, 2 lines
516
    // and 5x7 dot matrix
517
    HAL_WRITE_UINT8(base+LCD_CMD, LCD_CMD_MODE);
518
 
519
    // wait for not busy
520
    do { HAL_READ_UINT8(base+LCD_STAT, stat); } while (stat & LCD_STAT_BUSY);
521
    HAL_READ_UINT8(base+LCD_STAT, stat);
522
 
523
    // turn the LCD display on
524
    HAL_WRITE_UINT8(base+LCD_CMD, LCD_CMD_DON);
525
 
526
    lcd_curline = 0;
527
    lcd_linepos = 0;
528
 
529
    for( i = 0; i < LCD_LINE_LENGTH; i++ )
530
        lcd_line[0][i] = lcd_line[1][i] = ' ';
531
 
532
    lcd_line[0][LCD_LINE_LENGTH] = lcd_line[1][LCD_LINE_LENGTH] = 0;
533
 
534
    lcd_dis(LCD_LINE0, lcd_line[0], base);
535
    lcd_dis(LCD_LINE1, lcd_line[1], base);
536
}
537
 
538
// this routine writes the string to the LCD
539
// display after setting the address to add
540
static void
541
lcd_dis(int add, char *s, cyg_uint8* base)
542
{
543
    cyg_uint8 stat;
544
    int i;
545
 
546
    // wait for not busy (see Note in hal_diag_init above)
547
    do { HAL_READ_UINT8(base+LCD_STAT, stat); } while (stat & LCD_STAT_BUSY);
548
    HAL_READ_UINT8(base+LCD_STAT, stat);
549
 
550
    // write the address
551
    HAL_WRITE_UINT8(base+LCD_CMD, (LCD_CMD_ADD + add));
552
 
553
    // write the string out to the display stopping when we reach 0
554
    for (i = 0; *s != '\0'; i++)
555
    {
556
        // wait for not busy
557
        do { HAL_READ_UINT8(base+LCD_STAT, stat); } while (stat & LCD_STAT_BUSY);
558
        HAL_READ_UINT8(base+LCD_STAT, stat);
559
 
560
        // write the data
561
        HAL_WRITE_UINT8(base+LCD_DATA, *s++);
562
    }
563
}
564
 
565
void
566
cyg_hal_plf_lcd_putc(void* __ch_data, cyg_uint8 c)
567
{
568
    cyg_uint8* base = (cyg_uint8*)__ch_data;
569
    unsigned long __state;
570
    int i;
571
    CYGARC_HAL_SAVE_GP();
572
 
573
    // ignore CR
574
    if( c == '\r' ) return;
575
 
576
    HAL_DISABLE_INTERRUPTS(__state);
577
    if( c == '\n' )
578
    {
579
        lcd_dis(LCD_LINE0, &lcd_line[lcd_curline^1][0], base);
580
        lcd_dis(LCD_LINE1, &lcd_line[lcd_curline][0], base);
581
 
582
        // Do a line feed
583
        lcd_curline ^= 1;
584
        lcd_linepos = 0;
585
 
586
        for( i = 0; i < LCD_LINE_LENGTH; i++ )
587
            lcd_line[lcd_curline][i] = ' ';
588
 
589
        HAL_RESTORE_INTERRUPTS(__state);
590
        return;
591
    }
592
 
593
    // Only allow to be output if there is room on the LCD line
594
    if( lcd_linepos < LCD_LINE_LENGTH )
595
        lcd_line[lcd_curline][lcd_linepos++] = c;
596
 
597
    HAL_RESTORE_INTERRUPTS(__state);
598
}
599
 
600
cyg_uint8
601
cyg_hal_plf_lcd_getc(void* __ch_data)
602
{
603
    return 0;
604
}
605
 
606
static void
607
cyg_hal_plf_lcd_write(void* __ch_data, const cyg_uint8* __buf,
608
                         cyg_uint32 __len)
609
{
610
    CYGARC_HAL_SAVE_GP();
611
 
612
    while(__len-- > 0)
613
        cyg_hal_plf_lcd_putc(__ch_data, *__buf++);
614
 
615
    CYGARC_HAL_RESTORE_GP();
616
}
617
 
618
static void
619
cyg_hal_plf_lcd_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
620
{
621
    CYGARC_HAL_SAVE_GP();
622
 
623
    while(__len-- > 0)
624
        *__buf++ = cyg_hal_plf_lcd_getc(__ch_data);
625
 
626
    CYGARC_HAL_RESTORE_GP();
627
}
628
 
629
static int
630
cyg_hal_plf_lcd_control(void *__ch_data, __comm_control_cmd_t __func, ...)
631
{
632
    // Do nothing (yet).
633
    return 0;
634
}
635
 
636
static void
637
cyg_hal_plf_lcd_init(void)
638
{
639
    hal_virtual_comm_table_t* comm;
640
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
641
 
642
    // Init channel
643
    init_lcd_channel((cyg_uint8*)LCD_BASE);
644
 
645
    // Setup procs in the vector table
646
 
647
    // Set channel 2
648
    CYGACC_CALL_IF_SET_CONSOLE_COMM(2);
649
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
650
    CYGACC_COMM_IF_CH_DATA_SET(*comm, LCD_BASE);
651
    CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_lcd_write);
652
    CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_lcd_read);
653
    CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_lcd_putc);
654
    CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_lcd_getc);
655
    CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_lcd_control);
656
 
657
    // Restore original console
658
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
659
}
660
 
661
//=============================================================================
662
// Compatibility with older stubs
663
//=============================================================================
664
 
665
#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
666
 
667
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
668
#include <cyg/hal/hal_stub.h>           // CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION
669
#endif
670
 
671
//-----------------------------------------------------------------------------
672
// Assumption: all diagnostic output must be GDB packetized unless
673
// this is a configuration for a stand-alone ROM system.
674
#if defined(CYG_HAL_STARTUP_ROM) && !defined(CYGSEM_HAL_ROM_MONITOR)
675
# define HAL_DIAG_USES_HARDWARE
676
#endif
677
 
678
#if (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 0)
679
# define __BASE ((cyg_uint8*)CYG_DEV_SERIAL_BASE_A)
680
#elif (CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL == 1)
681
# define __BASE ((cyg_uint8*)CYG_DEV_SERIAL_BASE_B)
682
#else
683
# error "Cannot use LCD"
684
#endif
685
 
686
static channel_data_t channel = { __BASE, 0, 0};
687
 
688
#ifdef HAL_DIAG_USES_HARDWARE
689
 
690
void hal_diag_init(void)
691
{
692
    init_serial_channel(&channel);
693
}
694
 
695
void hal_diag_write_char(char __c)
696
{
697
    cyg_hal_plf_serial_putc(&channel, __c);
698
}
699
 
700
void hal_diag_read_char(char *c)
701
{
702
    *c = cyg_hal_plf_serial_getc(&channel);
703
}
704
 
705
#else  // ifdef HAL_DIAG_USES_HARDWARE
706
 
707
// Initialize diag port
708
void
709
hal_diag_init(void)
710
{
711
    // Init devices
712
    init_serial_channel(&channel);
713
}
714
 
715
void
716
hal_diag_write_char_serial( char c )
717
{
718
    unsigned long __state;
719
    HAL_DISABLE_INTERRUPTS(__state);
720
    cyg_hal_plf_serial_putc(&channel, c);
721
    HAL_RESTORE_INTERRUPTS(__state);
722
}
723
 
724
void
725
hal_diag_read_char(char *c)
726
{
727
    *c = cyg_hal_plf_serial_getc(&channel);
728
}
729
 
730
void
731
hal_diag_write_char(char c)
732
{
733
 
734
    static char line[100];
735
    static int pos = 0;
736
 
737
    // No need to send CRs
738
    if( c == '\r' ) return;
739
 
740
    line[pos++] = c;
741
 
742
    if( c == '\n' || pos == sizeof(line) )
743
    {
744
        CYG_INTERRUPT_STATE old;
745
 
746
        // Disable interrupts. This prevents GDB trying to interrupt us
747
        // while we are in the middle of sending a packet. The serial
748
        // receive interrupt will be seen when we re-enable interrupts
749
        // later.
750
 
751
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
752
        CYG_HAL_GDB_ENTER_CRITICAL_IO_REGION(old);
753
#else
754
        HAL_DISABLE_INTERRUPTS(old);
755
#endif
756
 
757
        while(1)
758
        {
759
            char c1;
760
            static char hex[] = "0123456789ABCDEF";
761
            cyg_uint8 csum = 0;
762
            int i;
763
 
764
            hal_diag_write_char_serial('$');
765
            hal_diag_write_char_serial('O');
766
            csum += 'O';
767
            for( i = 0; i < pos; i++ )
768
            {
769
                char ch = line[i];
770
                char h = hex[(ch>>4)&0xF];
771
                char l = hex[ch&0xF];
772
                hal_diag_write_char_serial(h);
773
                hal_diag_write_char_serial(l);
774
                csum += h;
775
                csum += l;
776
            }
777
            hal_diag_write_char_serial('#');
778
            hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
779
            hal_diag_write_char_serial(hex[csum&0xF]);
780
 
781
            // Wait for the ACK character '+' from GDB here and handle
782
            // receiving a ^C instead.
783
            hal_diag_read_char(&c1);
784
 
785
            if( c1 == '+' )
786
                break;              // a good acknowledge
787
 
788
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
789
            if( 3 == c1 ) {
790
                // Ctrl-C: breakpoint.
791
                cyg_hal_gdb_interrupt(
792
                    (target_register_t)__builtin_return_address(0));
793
                break;
794
            }
795
#endif
796
            // otherwise, loop round again
797
        }
798
 
799
        pos = 0;
800
 
801
        // And re-enable interrupts
802
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
803
        CYG_HAL_GDB_LEAVE_CRITICAL_IO_REGION(old);
804
#else
805
        HAL_RESTORE_INTERRUPTS(old);
806
#endif
807
 
808
    }
809
}
810
 
811
#endif  // ifdef HAL_DIAG_USES_HARDWARE
812
 
813
#endif // CYGSEM_HAL_VIRTUAL_VECTOR_DIAG
814
 
815
//-----------------------------------------------------------------------------
816
// 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.