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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [mpc8xxx/] [current/] [src/] [quicc2_diag.c] - Blame information for rev 867

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

Line No. Rev Author Line
1 786 skrzyp
//=============================================================================
2
//
3
//      quicc2_diag.c
4
//
5
//      HAL diagnostic I/O support routines for MPC8xxx/QUICC2
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, 2003 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):   hmt
43
// Contributors:hmt, gthomas
44
// Date:        1999-06-08
45
// Purpose:     HAL diagnostics I/O support
46
// Description: 
47
//
48
//####DESCRIPTIONEND####
49
//
50
//=============================================================================
51
 
52
#include <pkgconf/hal.h>
53
#include <cyg/hal/hal_mem.h>            // HAL memory definitions
54
#include <cyg/infra/cyg_type.h>
55
#include <cyg/hal/hal_if.h>             // hal_if_init
56
#include <cyg/hal/hal_io.h>             // hal_if_init
57
#include <cyg/hal/hal_misc.h>           // cyg_hal_is_break
58
 
59
#include <cyg/hal/drv_api.h>            // CYG_ISR_HANDLED
60
#include <cyg/hal/hal_intr.h>
61
#include <cyg/hal/hal_cache.h>
62
#include <cyg/hal/mpc8xxx.h>            // Needed for IMMR structure
63
 
64
#define PORT_IS_SMC 1
65
#define PORT_IS_SCC 0
66
 
67
#define NUM(t) sizeof(t)/sizeof(t[0])
68
 
69
struct port_info {
70
    short                             Txnum;   // Number of Tx buffers
71
    short                             Rxnum;   // Number of Rx buffers
72
    short                             intnum;  // Interrupt bit
73
    short                             is_smc;  // 1 => SMC, 0=> SCC
74
    int                               cpm_page;
75
    int                               timeout; // Timeout in msec
76
    int                               pram;    // [Pointer] to PRAM data
77
    int                               regs;    // [Pointer] to control registers
78
    int                               brg;     // Baud rate generator
79
    volatile struct cp_bufdesc *next_rxbd;
80
    int                               irq_state;// Interrupt state
81
    int                               init;    // Has port been initialized?
82
};
83
 
84
static struct port_info ports[] = {
85
#if CYGNUM_HAL_MPC8XXX_SMC1 > 0
86
    { 1, 4, CYGNUM_HAL_INTERRUPT_SMC1, PORT_IS_SMC, SMC1_PAGE_SUBBLOCK, 1000,
87
      DPRAM_SMC1_OFFSET,
88
      (int)&((t_PQ2IMM *)0)->smc_regs[SMC1],
89
      (int)&((t_PQ2IMM *)0)->brgs_brgc7
90
    },
91
#endif
92
#if CYGNUM_HAL_MPC8XXX_SCC1 > 0
93
    { 1, 4, CYGNUM_HAL_INTERRUPT_SCC1, PORT_IS_SCC, SCC1_PAGE_SUBBLOCK, 1000,
94
      (int)&((t_PQ2IMM *)0)->pram.serials.scc_pram[SCC1],
95
      (int)&((t_PQ2IMM *)0)->scc_regs[SCC1],
96
      (int)&((t_PQ2IMM *)0)->brgs_brgc1
97
    },
98
#endif
99
};
100
 
101
// For Baud Rate Calculation, see MPC8260 PowerQUICC II User's Manual
102
// 16.3 UART Baud Rate Examples, page 16-5.
103
#define UART_BIT_RATE(n) \
104
    ((((int)(((CYGHWR_HAL_POWERPC_CPM_SPEED*2)*1000000)/16))/(n * 16))-1)
105
#define UART_BAUD_RATE CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD
106
 
107
 
108
// Function prototypes
109
static cyg_uint8 cyg_hal_plf_serial_getc(void* __ch_data);
110
static cyg_bool  cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch);
111
static cyg_bool  cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch);
112
static void      cyg_hal_plf_serial_putc(void* __ch_data, cyg_uint8 ch);
113
static void      cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
114
                                          cyg_uint32 __len);
115
static void      cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len);
116
static void      cyg_hal_plf_smcx_init_channel(struct port_info *info, int page);
117
static void      cyg_hal_plf_sccx_init_channel(struct port_info *info, int page);
118
static int       cyg_hal_plf_smcx_isr(void *__ch_data, int* __ctrlc,
119
                                      CYG_ADDRWORD __vector, CYG_ADDRWORD __data);
120
static int       cyg_hal_plf_sccx_isr(void *__ch_data, int* __ctrlc,
121
                                      CYG_ADDRWORD __vector, CYG_ADDRWORD __data);
122
static int       cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...);
123
 
124
static int
125
cyg_hal_plf_sccx_isr(void *__ch_data, int* __ctrlc,
126
                     CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
127
{
128
    struct port_info *info = (struct port_info *)__ch_data;
129
    volatile struct scc_regs_8260 *regs = (volatile struct scc_regs_8260*)((char *)IMM + info->regs);
130
    volatile t_Scc_Pram *pram = (volatile t_Scc_Pram *)((char *)IMM + info->pram);
131
    char ch;
132
    int res = 0;
133
    volatile struct cp_bufdesc *bd;
134
 
135
    *__ctrlc = 0;
136
    if (regs->scce & SCCE_Rx) {
137
        regs->scce = SMCE_Rx;
138
 
139
        /* rx buffer descriptors */
140
        bd = info->next_rxbd;
141
 
142
        if ((bd->ctrl & _BD_CTL_Ready) == 0) {
143
 
144
            // then there be a character waiting
145
            ch = bd->buffer[0];
146
            bd->length = 1;
147
            bd->ctrl   |= _BD_CTL_Ready | _BD_CTL_Int;
148
            if (bd->ctrl & _BD_CTL_Wrap) {
149
                bd = (struct cp_bufdesc *)((char *)IMM + pram->rbase);
150
            } else {
151
                bd++;
152
            }
153
            info->next_rxbd = bd;
154
 
155
            if( cyg_hal_is_break( &ch , 1 ) )
156
                *__ctrlc = 1;
157
        }
158
 
159
        // Interrupt handled. Acknowledge it.
160
        HAL_INTERRUPT_ACKNOWLEDGE(info->intnum);
161
        res = CYG_ISR_HANDLED;
162
    }
163
    return res;
164
}
165
 
166
static int
167
cyg_hal_plf_smcx_isr(void *__ch_data, int* __ctrlc,
168
                     CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
169
{
170
    struct port_info *info = (struct port_info *)__ch_data;
171
    volatile struct smc_regs_8260 *regs = (volatile struct smc_regs_8260*)((char *)IMM + info->regs);
172
    t_Smc_Pram *pram = (t_Smc_Pram *)((char *)IMM + info->pram);
173
    char ch;
174
    int res = 0;
175
    volatile struct cp_bufdesc *bd;
176
 
177
    *__ctrlc = 0;
178
    if (regs->smc_smce & SMCE_Rx) {
179
        regs->smc_smce = SMCE_Rx;
180
 
181
        /* rx buffer descriptors */
182
        bd = info->next_rxbd;
183
 
184
        if ((bd->ctrl & _BD_CTL_Ready) == 0) {
185
 
186
            // then there be a character waiting
187
            ch = bd->buffer[0];
188
            bd->length = 1;
189
            bd->ctrl   |= _BD_CTL_Ready | _BD_CTL_Int;
190
            if (bd->ctrl & _BD_CTL_Wrap) {
191
                bd = (struct cp_bufdesc *)((char *)IMM + pram->rbase);
192
            } else {
193
                bd++;
194
            }
195
            info->next_rxbd = bd;
196
 
197
            if( cyg_hal_is_break( &ch , 1 ) )
198
                *__ctrlc = 1;
199
        }
200
 
201
        // Interrupt handled. Acknowledge it.
202
        HAL_INTERRUPT_ACKNOWLEDGE(info->intnum);
203
        res = CYG_ISR_HANDLED;
204
    }
205
    return res;
206
}
207
 
208
/* Early initialization of comm channels.
209
 */
210
void
211
cyg_hal_plf_serial_init(void)
212
{
213
    hal_virtual_comm_table_t* comm;
214
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
215
    int chan = 0;
216
    struct port_info *port;
217
    static int init = 0;
218
 
219
    if (init) return;
220
    init++;
221
 
222
    // Setup procs in the vector table    
223
    for (port = ports, chan = 0;  chan < NUM(ports);  chan++, port++) {
224
        CYGACC_CALL_IF_SET_CONSOLE_COMM(chan);
225
        comm = CYGACC_CALL_IF_CONSOLE_PROCS();
226
        CYGACC_COMM_IF_CH_DATA_SET(*comm, port);
227
        CYGACC_COMM_IF_WRITE_SET(*comm, cyg_hal_plf_serial_write);
228
        CYGACC_COMM_IF_READ_SET(*comm, cyg_hal_plf_serial_read);
229
        CYGACC_COMM_IF_PUTC_SET(*comm, cyg_hal_plf_serial_putc);
230
        CYGACC_COMM_IF_GETC_SET(*comm, cyg_hal_plf_serial_getc);
231
        CYGACC_COMM_IF_CONTROL_SET(*comm, cyg_hal_plf_serial_control);
232
        CYGACC_COMM_IF_GETC_TIMEOUT_SET(*comm, cyg_hal_plf_serial_getc_timeout);
233
        if (port->is_smc) {
234
            cyg_hal_plf_smcx_init_channel(port, port->cpm_page);
235
            CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_smcx_isr);
236
        } else {
237
            cyg_hal_plf_sccx_init_channel(port, port->cpm_page);
238
            CYGACC_COMM_IF_DBG_ISR_SET(*comm, cyg_hal_plf_sccx_isr);
239
        }
240
    }
241
 
242
    // Restore original console
243
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
244
}
245
 
246
static void
247
cyg_hal_plf_sccx_init_channel(struct port_info *info, int cpm_page)
248
{
249
    unsigned int rxbase, txbase;
250
    int i;
251
    struct cp_bufdesc *rxbd, *txbd;
252
    volatile struct scc_regs_8260 *regs = (volatile struct scc_regs_8260*)((char *)IMM + info->regs);
253
    volatile t_Scc_Pram *pram = (volatile t_Scc_Pram *)((char *)IMM + info->pram);
254
 
255
    if (info->init) return;
256
    info->init = 1;
257
 
258
    // Make sure device is stopped
259
    regs->gsmr_l &= DISABLE_TX_RX;
260
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
261
    IMM->cpm_cpcr = cpm_page |
262
        CPCR_STOP_TX |
263
        CPCR_FLG;             /* ISSUE COMMAND */
264
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
265
 
266
    // Allocate buffer descriptors + buffers (adjacent to descriptors)
267
    rxbase = _mpc8xxx_allocBd(sizeof(struct cp_bufdesc)*info->Rxnum + info->Rxnum);
268
    txbase = _mpc8xxx_allocBd(sizeof(struct cp_bufdesc)*info->Txnum + info->Txnum);
269
 
270
    // setup RX buffer descriptors 
271
    rxbd = (struct cp_bufdesc *)((char *)IMM + rxbase);
272
    info->next_rxbd = rxbd;
273
    for (i = 0;  i < info->Rxnum;  i++) {
274
        rxbd->length = 0;
275
        rxbd->buffer = ((char *)IMM + (rxbase+(info->Rxnum*sizeof(struct cp_bufdesc))))+i;
276
        rxbd->ctrl   = _BD_CTL_Ready | _BD_CTL_Int;
277
        rxbd++;
278
    }
279
    rxbd--;
280
    rxbd->ctrl   |= _BD_CTL_Wrap;
281
 
282
    // setup TX buffer descriptor
283
    txbd = (struct cp_bufdesc *)((char *)IMM + txbase);
284
    txbd->length = 1;
285
    txbd->buffer = ((char *)IMM + (txbase+(info->Txnum*sizeof(struct cp_bufdesc))));
286
    txbd->ctrl   = _BD_CTL_Wrap;
287
 
288
    // Set the baud rate generator.  Note: on the MPC8xxx, 
289
    // there are a number of BRGs, but the usage/layout is
290
    // somewhat restricted, so we rely on a fixed mapping.
291
    // See the setup in the platform init code for details.
292
    *(unsigned long *)((char *)IMM + info->brg) = 0x00010000 | (UART_BIT_RATE(UART_BAUD_RATE) << 1);
293
 
294
    // Rx, Tx function codes (used for access)
295
    pram->rfcr = 0x18;
296
    pram->tfcr = 0x18;
297
    regs->psmr = 0xB000;
298
 
299
    // Pointers to Rx & Tx buffer descriptor rings
300
    pram->rbase = rxbase;
301
    pram->tbase = txbase;
302
 
303
    // Max receive buffer length
304
    pram->mrblr = 1;
305
 
306
    // Mode register for 8N1
307
    regs->gsmr_h = 0x00000060;
308
    regs->gsmr_l = 0x00028004;
309
 
310
    // Clear events
311
    regs->scce = ALL_ONES;
312
    regs->sccm = SCCE_Rx;
313
 
314
    // Init channel
315
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
316
    IMM->cpm_cpcr = cpm_page |
317
        CPCR_INIT_TX_RX_PARAMS |
318
        CPCR_FLG;                 /* ISSUE COMMAND */
319
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
320
 
321
    /*-------------------------------------------------------------*/
322
    /* Set the ENT/ENR bits in the GSMR -- Enable Transmit/Receive */
323
    /*-------------------------------------------------------------*/
324
 
325
    regs->gsmr_l |= GSMR_L1_ENT | GSMR_L1_ENR;
326
#if defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT) \
327
    || defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
328
    // Fill out the control Character Table.  Make the first entry 
329
    // an end of table line. 
330
    // cc[0] = 0x4003 ==> reject if char = 0x3, write to RCCR
331
    pram->SpecificProtocol.u.cc[0] = 0x4003;
332
    {
333
        int i;
334
        for (i = 0; i < 8; i++){
335
            pram->SpecificProtocol.u.cc[i] = 0x8000;
336
        }
337
    }
338
 
339
    pram->SpecificProtocol.u.rccm  = 0xc000;
340
#endif
341
}
342
 
343
static void
344
cyg_hal_plf_smcx_init_channel(struct port_info *info, int cpm_page)
345
{
346
    unsigned int rxbase, txbase;
347
    int i;
348
    struct cp_bufdesc *rxbd, *txbd;
349
    volatile struct smc_regs_8260 *regs = (volatile struct smc_regs_8260*)((char *)IMM + info->regs);
350
    t_Smc_Pram *uart_pram = (t_Smc_Pram *)((char *)IMM + info->pram);
351
 
352
    if (info->init) return;
353
    info->init = 1;
354
 
355
    // Make sure device is stopped
356
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
357
    IMM->cpm_cpcr = cpm_page |
358
        CPCR_STOP_TX |
359
        CPCR_FLG;             /* ISSUE COMMAND */
360
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
361
 
362
    // Allocate buffer descriptors + buffers (adjacent to descriptors)
363
    rxbase = _mpc8xxx_allocBd(sizeof(struct cp_bufdesc)*info->Rxnum + info->Rxnum);
364
    txbase = _mpc8xxx_allocBd(sizeof(struct cp_bufdesc)*info->Txnum + info->Txnum);
365
 
366
    // setup RX buffer descriptors 
367
    rxbd = (struct cp_bufdesc *)((char *)IMM + rxbase);
368
    info->next_rxbd = rxbd;
369
    for (i = 0;  i < info->Rxnum;  i++) {
370
        rxbd->length = 0;
371
        rxbd->buffer = ((char *)IMM + (rxbase+(info->Rxnum*sizeof(struct cp_bufdesc))))+i;
372
        rxbd->ctrl   = _BD_CTL_Ready | _BD_CTL_Int;
373
        rxbd++;
374
    }
375
    rxbd--;
376
    rxbd->ctrl   |= _BD_CTL_Wrap;
377
 
378
    // setup TX buffer descriptor
379
    txbd = (struct cp_bufdesc *)((char *)IMM + txbase);
380
    txbd->length = 1;
381
    txbd->buffer = ((char *)IMM + (txbase+(info->Txnum*sizeof(struct cp_bufdesc))));
382
    txbd->ctrl   = _BD_CTL_Wrap;
383
 
384
    // Set the baud rate generator.  Note: on the MPC8xxx, 
385
    // there are a number of BRGs, but the usage/layout is
386
    // somewhat restricted, so we rely on a fixed mapping.
387
    // See the setup in the platform init code for details.
388
    *(unsigned long *)((char *)IMM + info->brg) = 0x00010000 | (UART_BIT_RATE(UART_BAUD_RATE) << 1);
389
 
390
    // Rx, Tx function codes (used for access)
391
    uart_pram->rfcr = 0x18;
392
    uart_pram->tfcr = 0x18;
393
 
394
    // Pointers to Rx & Tx buffer descriptor rings
395
    uart_pram->rbase = rxbase;
396
    uart_pram->tbase = txbase;
397
 
398
    // Max receive buffer length
399
    uart_pram->mrblr = 1;
400
 
401
    // Mode register for 8N1
402
    regs->smc_smcmr = 0x4823;
403
 
404
    // Clear events
405
    regs->smc_smce = 0xFF;
406
    regs->smc_smcm = SMCE_Rx;
407
 
408
    // Init channel
409
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
410
    IMM->cpm_cpcr = cpm_page |
411
        CPCR_INIT_TX_RX_PARAMS |
412
        CPCR_FLG;                 /* ISSUE COMMAND */
413
    while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD);
414
}
415
 
416
static void
417
cyg_hal_plf_serial_putc(void* __ch_data, cyg_uint8 ch)
418
{
419
    volatile struct cp_bufdesc *bd;
420
    struct port_info *info = (struct port_info *)__ch_data;
421
    volatile t_Scc_Pram *uart_pram = (volatile t_Scc_Pram *)((char *)IMM + info->pram);
422
    int cache_state;
423
 
424
    /* tx buffer descriptor */
425
    bd = (struct cp_bufdesc *)((char *)IMM + uart_pram->tbptr);
426
    while (bd->ctrl & _BD_CTL_Ready) ;  // Wait for buffer free
427
    if (bd->ctrl & _BD_CTL_Int) {
428
        // This buffer has just completed interrupt output.  Reset bits
429
        bd->ctrl &= ~_BD_CTL_Int;
430
    }
431
    bd->length = 1;
432
    bd->buffer[0] = ch;
433
 
434
    // Flush cache if necessary - buffer may be in cacheable memory
435
    HAL_DCACHE_IS_ENABLED(cache_state);
436
    if (cache_state) {
437
      HAL_DCACHE_FLUSH(bd->buffer, 1);
438
    }
439
 
440
    bd->ctrl      |= _BD_CTL_Ready;
441
    while (bd->ctrl & _BD_CTL_Ready) ;  // Wait for buffer free
442
}
443
 
444
static cyg_bool
445
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
446
{
447
    volatile struct cp_bufdesc *bd;
448
    struct port_info *info = (struct port_info *)__ch_data;
449
    volatile t_Scc_Pram *uart_pram = (volatile t_Scc_Pram *)((char *)IMM + info->pram);
450
    int cache_state;
451
 
452
    /* rx buffer descriptor */
453
    bd = info->next_rxbd;
454
 
455
    if (bd->ctrl & _BD_CTL_Ready)
456
        return false;
457
 
458
    *ch = bd->buffer[0];
459
 
460
    bd->length = 0;
461
    bd->buffer[0] = '\0';
462
    bd->ctrl |= _BD_CTL_Ready;
463
    if (bd->ctrl & _BD_CTL_Wrap) {
464
        bd = (struct cp_bufdesc *)((char *)IMM + uart_pram->rbase);
465
    } else {
466
        bd++;
467
    }
468
    info->next_rxbd = bd;
469
 
470
    // Note: the MPC8xxx does not seem to snoop/invalidate the data cache properly!
471
    HAL_DCACHE_IS_ENABLED(cache_state);
472
    if (cache_state) {
473
        HAL_DCACHE_INVALIDATE(bd->buffer, uart_pram->mrblr);  // Make sure no stale data
474
    }
475
 
476
    return true;
477
}
478
 
479
static cyg_uint8
480
cyg_hal_plf_serial_getc(void* __ch_data)
481
{
482
    cyg_uint8 ch;
483
    while(!cyg_hal_plf_serial_getc_nonblock(__ch_data, &ch));
484
    return ch;
485
}
486
 
487
static void
488
cyg_hal_plf_serial_write(void* __ch_data, const cyg_uint8* __buf,
489
                         cyg_uint32 __len)
490
{
491
    while(__len-- > 0)
492
        cyg_hal_plf_serial_putc(__ch_data, *__buf++);
493
}
494
 
495
static void
496
cyg_hal_plf_serial_read(void* __ch_data, cyg_uint8* __buf, cyg_uint32 __len)
497
{
498
    while(__len-- > 0)
499
        *__buf++ = cyg_hal_plf_serial_getc(__ch_data);
500
}
501
 
502
cyg_int32 msec_timeout = 1000;
503
 
504
static cyg_bool
505
cyg_hal_plf_serial_getc_timeout(void* __ch_data, cyg_uint8* ch)
506
{
507
    int delay_count = msec_timeout * 10; // delay in .1 ms steps
508
    cyg_bool res;
509
 
510
    for(;;) {
511
        res = cyg_hal_plf_serial_getc_nonblock(__ch_data, ch);
512
        if (res || 0 == delay_count--)
513
            break;
514
 
515
        CYGACC_CALL_IF_DELAY_US(100);
516
    }
517
    return res;
518
}
519
 
520
static int
521
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
522
{
523
    int ret = 0;
524
    struct port_info *info = (struct port_info *)__ch_data;
525
 
526
    switch (__func) {
527
    case __COMMCTL_IRQ_ENABLE:
528
        HAL_INTERRUPT_UNMASK(info->intnum);
529
        info->irq_state = 1;
530
        break;
531
    case __COMMCTL_IRQ_DISABLE:
532
        ret = info->irq_state;
533
        info->irq_state = 0;
534
        HAL_INTERRUPT_MASK(info->intnum);
535
        break;
536
    case __COMMCTL_DBG_ISR_VECTOR:
537
        ret = info->intnum;
538
        break;
539
    case __COMMCTL_SET_TIMEOUT:
540
    {
541
        va_list ap;
542
        va_start(ap, __func);
543
 
544
        ret = msec_timeout;
545
        msec_timeout = va_arg(ap, cyg_uint32);
546
 
547
        va_end(ap);
548
    }
549
    default:
550
        break;
551
    }
552
    return ret;
553
}
554
 
555
// EOF hal_aux.c

powered by: WebSVN 2.1.0

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