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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [serial/] [sh/] [sci/] [current/] [src/] [sh_sci_serial.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      io/serial/sh/sh_sci_serial.c
4
//
5
//      SH Serial SCI I/O Interface Module (interrupt driven)
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):   jskov
43
// Contributors:gthomas, jskov
44
// Date:        1999-05-24
45
// Purpose:     SH Serial I/O module (interrupt driven version)
46
// Description: 
47
//
48
// Note: Since interrupt sources from the same SCI channel share the same
49
//       interrupt level, there is no risk of races when altering the
50
//       channel's control register from ISRs and DSRs. However, when 
51
//       altering the control register from user-level code, interrupts
52
//       must be disabled while the register is being accessed.
53
//
54
// FIXME: Receiving in polled mode prevents duplex transfers from working for
55
//        some reason.
56
//####DESCRIPTIONEND####
57
//==========================================================================
58
 
59
#include <pkgconf/io_serial.h>
60
#include <pkgconf/io.h>
61
 
62
// FIXME: This is necessary since the SCIF driver may be overriding
63
// CYGDAT_IO_SERIAL_DEVICE_HEADER. Need a better way to include two
64
// different drivers.
65
#include <pkgconf/io_serial_sh_sci.h>
66
 
67
#include <cyg/io/io.h>
68
#include <cyg/hal/hal_intr.h>
69
#include <cyg/io/devtab.h>
70
#include <cyg/infra/diag.h>
71
#include <cyg/io/serial.h>
72
 
73
#include <cyg/hal/sh_regs.h>
74
 
75
// Only compile driver if an inline file with driver details was selected.
76
#ifdef CYGDAT_IO_SERIAL_SH_SCI_INL
77
 
78
// Find the SCI controller register layout from the SCI0 definitions
79
#if defined(CYGARC_REG_SCI_SCSMR0)
80
# define SCI_SCSMR                (CYGARC_REG_SCI_SCSMR0-CYGARC_REG_SCI_SCSMR0) // serial mode register
81
# define SCI_SCBRR                (CYGARC_REG_SCI_SCBRR0-CYGARC_REG_SCI_SCSMR0) // bit rate register
82
# define SCI_SCSCR                (CYGARC_REG_SCI_SCSCR0-CYGARC_REG_SCI_SCSMR0) // serial control register
83
# define SCI_SCTDR                (CYGARC_REG_SCI_SCTDR0-CYGARC_REG_SCI_SCSMR0) // transmit data register
84
# define SCI_SCSSR                (CYGARC_REG_SCI_SCSSR0-CYGARC_REG_SCI_SCSMR0) // serial status register
85
# define SCI_SCRDR                (CYGARC_REG_SCI_SCRDR0-CYGARC_REG_SCI_SCSMR0) // receive data register
86
# define SCI_SCSPTR               (CYGARC_REG_SCI_SCSPTR0-CYGARC_REG_SCI_SCSMR0)// serial port register
87
#elif defined(CYGARC_REG_SCI_SCSMR)
88
# define SCI_SCSMR                (CYGARC_REG_SCI_SCSMR-CYGARC_REG_SCI_SCSMR) // serial mode register
89
# define SCI_SCBRR                (CYGARC_REG_SCI_SCBRR-CYGARC_REG_SCI_SCSMR) // bit rate register
90
# define SCI_SCSCR                (CYGARC_REG_SCI_SCSCR-CYGARC_REG_SCI_SCSMR) // serial control register
91
# define SCI_SCTDR                (CYGARC_REG_SCI_SCTDR-CYGARC_REG_SCI_SCSMR) // transmit data register
92
# define SCI_SCSSR                (CYGARC_REG_SCI_SCSSR-CYGARC_REG_SCI_SCSMR) // serial status register
93
# define SCI_SCRDR                (CYGARC_REG_SCI_SCRDR-CYGARC_REG_SCI_SCSMR) // receive data register
94
# define SCI_SCSPTR               (CYGARC_REG_SCI_SCSPTR-CYGARC_REG_SCI_SCSMR) // serial port register
95
#else
96
# error "Missing register offsets"
97
#endif
98
 
99
static short select_word_length[] = {
100
    -1,
101
    -1,
102
    CYGARC_REG_SCI_SCSMR_CHR,               // 7 bits
103
 
104
};
105
 
106
static short select_stop_bits[] = {
107
    -1,
108
    0,                                  // 1 stop bit
109
    -1,
110
    CYGARC_REG_SCI_SCSMR_STOP               // 2 stop bits
111
};
112
 
113
static short select_parity[] = {
114
    0,                                  // No parity
115
    CYGARC_REG_SCI_SCSMR_PE,                // Even parity
116
    CYGARC_REG_SCI_SCSMR_PE|CYGARC_REG_SCI_SCSMR_OE, // Odd parity
117
    -1,
118
    -1
119
};
120
 
121
static unsigned short select_baud[] = {
122
    0,    // Unused
123
    CYGARC_SCBRR_CKSx(50)<<8 | CYGARC_SCBRR_N(50),
124
    CYGARC_SCBRR_CKSx(75)<<8 | CYGARC_SCBRR_N(75),
125
    CYGARC_SCBRR_CKSx(110)<<8 | CYGARC_SCBRR_N(110),
126
    CYGARC_SCBRR_CKSx(134)<<8 | CYGARC_SCBRR_N(134),
127
    CYGARC_SCBRR_CKSx(150)<<8 | CYGARC_SCBRR_N(150),
128
    CYGARC_SCBRR_CKSx(200)<<8 | CYGARC_SCBRR_N(200),
129
    CYGARC_SCBRR_CKSx(300)<<8 | CYGARC_SCBRR_N(300),
130
    CYGARC_SCBRR_CKSx(600)<<8 | CYGARC_SCBRR_N(600),
131
    CYGARC_SCBRR_CKSx(1200)<<8 | CYGARC_SCBRR_N(1200),
132
    CYGARC_SCBRR_CKSx(1800)<<8 | CYGARC_SCBRR_N(1800),
133
    CYGARC_SCBRR_CKSx(2400)<<8 | CYGARC_SCBRR_N(2400),
134
    CYGARC_SCBRR_CKSx(3600)<<8 | CYGARC_SCBRR_N(3600),
135
    CYGARC_SCBRR_CKSx(4800)<<8 | CYGARC_SCBRR_N(4800),
136
    CYGARC_SCBRR_CKSx(7200)<<8 | CYGARC_SCBRR_N(7200),
137
    CYGARC_SCBRR_CKSx(9600)<<8 | CYGARC_SCBRR_N(9600),
138
    CYGARC_SCBRR_CKSx(14400)<<8 | CYGARC_SCBRR_N(14400),
139
    CYGARC_SCBRR_CKSx(19200)<<8 | CYGARC_SCBRR_N(19200),
140
    CYGARC_SCBRR_CKSx(38400)<<8 | CYGARC_SCBRR_N(38400),
141
    CYGARC_SCBRR_CKSx(57600)<<8 | CYGARC_SCBRR_N(57600),
142
    CYGARC_SCBRR_CKSx(115200)<<8 | CYGARC_SCBRR_N(115200),
143
    CYGARC_SCBRR_CKSx(230400)<<8 | CYGARC_SCBRR_N(230400)
144
};
145
 
146
 
147
typedef struct sh_sci_info {
148
    CYG_ADDRWORD   data;                // Pointer to data register
149
 
150
    CYG_WORD       er_int_num,          // Error interrupt number
151
                   rx_int_num,          // Receive interrupt number
152
                   tx_int_num;          // Transmit interrupt number
153
 
154
    CYG_ADDRWORD   ctrl_base;           // Base address of SCI controller
155
 
156
    cyg_interrupt  serial_er_interrupt,
157
                   serial_rx_interrupt,
158
                   serial_tx_interrupt;
159
    cyg_handle_t   serial_er_interrupt_handle,
160
                   serial_rx_interrupt_handle,
161
                   serial_tx_interrupt_handle;
162
 
163
    bool           tx_enabled;
164
} sh_sci_info;
165
 
166
static bool sh_serial_init(struct cyg_devtab_entry *tab);
167
static bool sh_serial_putc(serial_channel *chan, unsigned char c);
168
static Cyg_ErrNo sh_serial_lookup(struct cyg_devtab_entry **tab,
169
                                   struct cyg_devtab_entry *sub_tab,
170
                                   const char *name);
171
static unsigned char sh_serial_getc(serial_channel *chan);
172
static Cyg_ErrNo sh_serial_set_config(serial_channel *chan, cyg_uint32 key,
173
                                      const void *xbuf, cyg_uint32 *len);
174
static void sh_serial_start_xmit(serial_channel *chan);
175
static void sh_serial_stop_xmit(serial_channel *chan);
176
 
177
static cyg_uint32 sh_serial_tx_ISR(cyg_vector_t vector, cyg_addrword_t data);
178
static void       sh_serial_tx_DSR(cyg_vector_t vector, cyg_ucount32 count,
179
                                   cyg_addrword_t data);
180
static cyg_uint32 sh_serial_rx_ISR(cyg_vector_t vector, cyg_addrword_t data);
181
static void       sh_serial_rx_DSR(cyg_vector_t vector, cyg_ucount32 count,
182
                                   cyg_addrword_t data);
183
static cyg_uint32 sh_serial_er_ISR(cyg_vector_t vector, cyg_addrword_t data);
184
static void       sh_serial_er_DSR(cyg_vector_t vector, cyg_ucount32 count,
185
                                   cyg_addrword_t data);
186
 
187
static SERIAL_FUNS(sh_serial_funs,
188
                   sh_serial_putc,
189
                   sh_serial_getc,
190
                   sh_serial_set_config,
191
                   sh_serial_start_xmit,
192
                   sh_serial_stop_xmit
193
    );
194
 
195
#include CYGDAT_IO_SERIAL_SH_SCI_INL
196
 
197
// Internal function to actually configure the hardware to desired baud rate,
198
// etc.
199
static bool
200
sh_serial_config_port(serial_channel *chan, cyg_serial_info_t *new_config,
201
                      bool init)
202
{
203
    cyg_uint16 baud_divisor = select_baud[new_config->baud];
204
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
205
    cyg_uint8 _scr, _smr;
206
 
207
    // Check configuration request
208
    if ((-1 == select_word_length[(new_config->word_length -
209
                                  CYGNUM_SERIAL_WORD_LENGTH_5)])
210
        || -1 == select_stop_bits[new_config->stop]
211
        || -1 == select_parity[new_config->parity]
212
        || baud_divisor == 0)
213
        return false;
214
 
215
    // Disable SCI interrupts while changing hardware
216
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
217
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, 0);
218
 
219
    // Set databits, stopbits and parity.
220
    _smr = select_word_length[(new_config->word_length -
221
                               CYGNUM_SERIAL_WORD_LENGTH_5)] |
222
        select_stop_bits[new_config->stop] |
223
        select_parity[new_config->parity];
224
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSMR, _smr);
225
 
226
    // Set baud rate.
227
    _smr &= ~CYGARC_REG_SCI_SCSMR_CKSx_MASK;
228
    _smr |= baud_divisor >> 8;
229
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSMR, _smr);
230
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCBRR, baud_divisor & 0xff);
231
 
232
    // Clear the status register.
233
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSSR, 0);
234
 
235
    if (init) {
236
        // Always enable transmitter and receiver.
237
        _scr = CYGARC_REG_SCI_SCSCR_TE | CYGARC_REG_SCI_SCSCR_RE;
238
 
239
        if (chan->out_cbuf.len != 0)
240
            _scr |= CYGARC_REG_SCI_SCSCR_TIE; // enable tx interrupts
241
 
242
        if (chan->in_cbuf.len != 0)
243
            _scr |= CYGARC_REG_SCI_SCSCR_RIE; // enable rx interrupts
244
    }
245
 
246
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
247
 
248
    if (new_config != &chan->config) {
249
        chan->config = *new_config;
250
    }
251
    return true;
252
}
253
 
254
// Function to initialize the device.  Called at bootstrap time.
255
static bool
256
sh_serial_init(struct cyg_devtab_entry *tab)
257
{
258
    serial_channel *chan = (serial_channel *)tab->priv;
259
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
260
#ifdef CYGDBG_IO_INIT
261
    diag_printf("SH SERIAL init - dev: %x.%d\n",
262
                sh_chan->data, sh_chan->rx_int_num);
263
#endif
264
    // Really only required for interrupt driven devices
265
    (chan->callbacks->serial_init)(chan);
266
 
267
    if (chan->out_cbuf.len != 0) {
268
        cyg_drv_interrupt_create(sh_chan->tx_int_num,
269
                                 3,
270
                                 (cyg_addrword_t)chan, // Data item passed to interrupt handler
271
                                 sh_serial_tx_ISR,
272
                                 sh_serial_tx_DSR,
273
                                 &sh_chan->serial_tx_interrupt_handle,
274
                                 &sh_chan->serial_tx_interrupt);
275
        cyg_drv_interrupt_attach(sh_chan->serial_tx_interrupt_handle);
276
        cyg_drv_interrupt_unmask(sh_chan->tx_int_num);
277
        sh_chan->tx_enabled = false;
278
    }
279
    if (chan->in_cbuf.len != 0) {
280
        // Receive interrupt
281
        cyg_drv_interrupt_create(sh_chan->rx_int_num,
282
                                 3,
283
                                 (cyg_addrword_t)chan, // Data item passed to interrupt handler
284
                                 sh_serial_rx_ISR,
285
                                 sh_serial_rx_DSR,
286
                                 &sh_chan->serial_rx_interrupt_handle,
287
                                 &sh_chan->serial_rx_interrupt);
288
        cyg_drv_interrupt_attach(sh_chan->serial_rx_interrupt_handle);
289
        // Receive error interrupt
290
        cyg_drv_interrupt_create(sh_chan->er_int_num,
291
                                 3,
292
                                 (cyg_addrword_t)chan, // Data item passed to interrupt handler
293
                                 sh_serial_er_ISR,
294
                                 sh_serial_er_DSR,
295
                                 &sh_chan->serial_er_interrupt_handle,
296
                                 &sh_chan->serial_er_interrupt);
297
        cyg_drv_interrupt_attach(sh_chan->serial_er_interrupt_handle);
298
        // This unmasks both interrupt sources.
299
        cyg_drv_interrupt_unmask(sh_chan->rx_int_num);
300
    }
301
    sh_serial_config_port(chan, &chan->config, true);
302
    return true;
303
}
304
 
305
// This routine is called when the device is "looked" up (i.e. attached)
306
static Cyg_ErrNo
307
sh_serial_lookup(struct cyg_devtab_entry **tab,
308
                  struct cyg_devtab_entry *sub_tab,
309
                  const char *name)
310
{
311
    serial_channel *chan = (serial_channel *)(*tab)->priv;
312
 
313
    // Really only required for interrupt driven devices
314
    (chan->callbacks->serial_init)(chan);
315
    return ENOERR;
316
}
317
 
318
// Send a character to the device output buffer.
319
// Return 'true' if character is sent to device
320
static bool
321
sh_serial_putc(serial_channel *chan, unsigned char c)
322
{
323
    cyg_uint8 _ssr;
324
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
325
 
326
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSSR, _ssr);
327
    if (_ssr & CYGARC_REG_SCI_SCSSR_TDRE) {
328
// Transmit buffer is empty
329
        HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCTDR, c);
330
        // Clear empty flag.
331
        HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSSR,
332
                        CYGARC_REG_SCI_SCSSR_CLEARMASK & ~CYGARC_REG_SCI_SCSSR_TDRE);
333
        return true;
334
    } else {
335
// No space
336
        return false;
337
    }
338
}
339
 
340
// Fetch a character from the device input buffer, waiting if necessary
341
static unsigned char
342
sh_serial_getc(serial_channel *chan)
343
{
344
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
345
    unsigned char c;
346
    cyg_uint8 _ssr;
347
 
348
    do {
349
        HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSSR, _ssr);
350
    } while ((_ssr & CYGARC_REG_SCI_SCSSR_RDRF) == 0);
351
 
352
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCRDR, c);
353
 
354
    // Clear buffer full flag.
355
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSSR,
356
                    CYGARC_REG_SCI_SCSSR_CLEARMASK & ~CYGARC_REG_SCI_SCSSR_RDRF);
357
 
358
    return c;
359
}
360
 
361
// Set up the device characteristics; baud rate, etc.
362
static Cyg_ErrNo
363
sh_serial_set_config(serial_channel *chan, cyg_uint32 key,
364
                     const void *xbuf, cyg_uint32 *len)
365
{
366
    switch (key) {
367
    case CYG_IO_SET_CONFIG_SERIAL_INFO:
368
      {
369
        cyg_serial_info_t *config = (cyg_serial_info_t *)xbuf;
370
        if ( *len < sizeof(cyg_serial_info_t) ) {
371
            return -EINVAL;
372
        }
373
        *len = sizeof(cyg_serial_info_t);
374
        if ( true != sh_serial_config_port(chan, config, false) )
375
            return -EINVAL;
376
      }
377
      break;
378
    default:
379
        return -EINVAL;
380
    }
381
    return ENOERR;
382
}
383
 
384
// Enable the transmitter on the device
385
static void
386
sh_serial_start_xmit(serial_channel *chan)
387
{
388
    cyg_uint8 _scr;
389
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
390
 
391
    sh_chan->tx_enabled = true;
392
 
393
    // Mask the interrupts (all sources of the unit) while changing
394
    // the CR since a rx interrupt in the middle of this would result
395
    // in a bad CR state.
396
    cyg_drv_interrupt_mask(sh_chan->rx_int_num);
397
 
398
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
399
    _scr |= CYGARC_REG_SCI_SCSCR_TIE;       // Enable xmit interrupt
400
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
401
 
402
    cyg_drv_interrupt_unmask(sh_chan->rx_int_num);
403
}
404
 
405
// Disable the transmitter on the device
406
static void
407
sh_serial_stop_xmit(serial_channel *chan)
408
{
409
    cyg_uint8 _scr;
410
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
411
 
412
    sh_chan->tx_enabled = false;
413
 
414
    // Mask the interrupts (all sources of the unit) while changing
415
    // the CR since a rx interrupt in the middle of this would result
416
    // in a bad CR state.
417
    cyg_drv_interrupt_mask(sh_chan->rx_int_num);
418
 
419
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
420
    _scr &= ~CYGARC_REG_SCI_SCSCR_TIE;      // Disable xmit interrupt
421
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
422
 
423
    cyg_drv_interrupt_unmask(sh_chan->rx_int_num);
424
}
425
 
426
// Serial I/O - low level tx interrupt handler (ISR)
427
static cyg_uint32
428
sh_serial_tx_ISR(cyg_vector_t vector, cyg_addrword_t data)
429
{
430
    serial_channel *chan = (serial_channel *)data;
431
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
432
    cyg_uint8 _scr;
433
 
434
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
435
    _scr &= ~CYGARC_REG_SCI_SCSCR_TIE;      // mask out tx interrupts
436
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
437
 
438
    return CYG_ISR_CALL_DSR;  // Cause DSR to be run
439
}
440
 
441
// Serial I/O - high level tx interrupt handler (DSR)
442
static void
443
sh_serial_tx_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
444
{
445
    serial_channel *chan = (serial_channel *)data;
446
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
447
 
448
    (chan->callbacks->xmt_char)(chan);
449
 
450
    if (sh_chan->tx_enabled) {
451
        cyg_uint8 _scr;
452
 
453
        HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
454
        _scr |= CYGARC_REG_SCI_SCSCR_TIE;       // unmask tx interrupts
455
        HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
456
    }
457
}
458
 
459
// Serial I/O - low level RX interrupt handler (ISR)
460
static cyg_uint32
461
sh_serial_rx_ISR(cyg_vector_t vector, cyg_addrword_t data)
462
{
463
    serial_channel *chan = (serial_channel *)data;
464
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
465
    cyg_uint8 _scr;
466
 
467
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
468
    _scr &= ~CYGARC_REG_SCI_SCSCR_RIE;      // mask rx interrupts
469
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
470
    return CYG_ISR_CALL_DSR;  // Cause DSR to be run
471
}
472
 
473
// Serial I/O - high level rx interrupt handler (DSR)
474
static void
475
sh_serial_rx_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
476
{
477
    serial_channel *chan = (serial_channel *)data;
478
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
479
    cyg_uint8 _ssr, _scr;
480
 
481
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSSR, _ssr);
482
    if (_ssr & CYGARC_REG_SCI_SCSSR_RDRF) {
483
        cyg_uint8 _c;
484
        HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCRDR, _c);
485
        // Clear buffer full flag.
486
        HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSSR,
487
                        CYGARC_REG_SCI_SCSSR_CLEARMASK & ~CYGARC_REG_SCI_SCSSR_RDRF);
488
 
489
        (chan->callbacks->rcv_char)(chan, _c);
490
    }
491
 
492
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
493
    _scr |= CYGARC_REG_SCI_SCSCR_RIE;       // unmask rx interrupts
494
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
495
}
496
 
497
static volatile int sh_serial_error_orer = 0;
498
static volatile int sh_serial_error_fer = 0;
499
static volatile int sh_serial_error_per = 0;
500
 
501
// Serial I/O - low level error interrupt handler (ISR)
502
static cyg_uint32
503
sh_serial_er_ISR(cyg_vector_t vector, cyg_addrword_t data)
504
{
505
    serial_channel *chan = (serial_channel *)data;
506
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
507
    cyg_uint8 _scr;
508
 
509
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
510
    _scr &= ~CYGARC_REG_SCI_SCSCR_RIE;      // mask rx interrupts
511
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
512
    return CYG_ISR_CALL_DSR;            // Cause DSR to be run
513
}
514
 
515
// Serial I/O - high level error interrupt handler (DSR)
516
static void
517
sh_serial_er_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
518
{
519
    serial_channel *chan = (serial_channel *)data;
520
    sh_sci_info *sh_chan = (sh_sci_info *)chan->dev_priv;
521
    cyg_uint8 _ssr, _ssr2, _scr;
522
 
523
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSSR, _ssr);
524
    _ssr2 = CYGARC_REG_SCI_SCSSR_CLEARMASK;
525
 
526
    if (_ssr & CYGARC_REG_SCI_SCSSR_ORER) {
527
        _ssr2 &= ~CYGARC_REG_SCI_SCSSR_ORER;
528
        sh_serial_error_orer++;
529
    }
530
    if (_ssr & CYGARC_REG_SCI_SCSSR_FER) {
531
        _ssr2 &= ~CYGARC_REG_SCI_SCSSR_FER;
532
        sh_serial_error_fer++;
533
    }
534
    if (_ssr & CYGARC_REG_SCI_SCSSR_PER) {
535
        _ssr2 &= ~CYGARC_REG_SCI_SCSSR_PER;
536
        sh_serial_error_per++;
537
    }
538
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSSR, _ssr2);
539
 
540
    HAL_READ_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
541
    _scr |= CYGARC_REG_SCI_SCSCR_RIE;       // unmask rx interrupts
542
    HAL_WRITE_UINT8(sh_chan->ctrl_base+SCI_SCSCR, _scr);
543
}
544
 
545
#endif // ifdef CYGDAT_IO_SERIAL_SH_SCI_INL

powered by: WebSVN 2.1.0

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