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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [serial/] [v2_0/] [include/] [serial.h] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_SERIAL_H
2
#define CYGONCE_SERIAL_H
3
// ====================================================================
4
//
5
//      serial.h
6
//
7
//      Device I/O 
8
//
9
// ====================================================================
10
//####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
// ====================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   gthomas
46
// Contributors:        gthomas
47
// Date:        1999-02-04
48
// Purpose:     Internal interfaces for serial I/O drivers
49
// Description:
50
//
51
//####DESCRIPTIONEND####
52
//
53
// ====================================================================
54
 
55
// Serial I/O interfaces
56
 
57
#include <pkgconf/system.h>
58
#include <pkgconf/io_serial.h>
59
 
60
#include <cyg/infra/cyg_type.h>
61
#include <cyg/io/io.h>
62
#include <cyg/io/serialio.h>
63
#include <cyg/hal/drv_api.h>
64
 
65
#ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT
66
#include <cyg/fileio/fileio.h>
67
#endif
68
 
69
typedef struct serial_channel serial_channel;
70
typedef struct serial_funs serial_funs;
71
 
72
// The block transfer request functions may fail for one of two
73
// reasons. It's important for the caller to know which.
74
typedef enum {
75
    CYG_RCV_OK,
76
    CYG_RCV_FULL,
77
    CYG_RCV_DISABLED
78
} rcv_req_reply_t;
79
 
80
typedef enum {
81
    CYG_XMT_OK,
82
    CYG_XMT_EMPTY,
83
    CYG_XMT_DISABLED
84
} xmt_req_reply_t;
85
 
86
// Pointers into upper-level driver which interrupt handlers need
87
typedef struct {
88
    // Initialize the channel
89
    void (*serial_init)(serial_channel *chan);
90
    // Cause an additional character to be output if one is available
91
    void (*xmt_char)(serial_channel *chan);
92
    // Consume an input character
93
    void (*rcv_char)(serial_channel *chan, unsigned char c);
94
#if CYGINT_IO_SERIAL_BLOCK_TRANSFER
95
    // Request space for input characters
96
    rcv_req_reply_t (*data_rcv_req)(serial_channel *chan, int avail,
97
                                    int* space_avail, unsigned char** space);
98
    // Receive operation completed
99
    void (*data_rcv_done)(serial_channel *chan, int chars_rcvd);
100
    // Request characters for transmission
101
    xmt_req_reply_t (*data_xmt_req)(serial_channel *chan, int space,
102
                                    int* chars_avail, unsigned char** chars);
103
    // Transmit operation completed
104
    void (*data_xmt_done)(serial_channel *chan, int chars_sent);
105
#endif
106
#if defined(CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS)
107
    void (*indicate_status)(serial_channel *chan, cyg_serial_line_status_t *s );
108
#endif
109
} serial_callbacks_t;
110
 
111
#if CYGINT_IO_SERIAL_BLOCK_TRANSFER
112
# ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
113
#  define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char, _data_rcv_req, _data_rcv_done, _data_xmt_req, _data_xmt_done, _indicate_status)  \
114
serial_callbacks_t _l = {                               \
115
    _init,                                              \
116
    _xmt_char,                                          \
117
    _rcv_char,                                          \
118
    _data_rcv_req,                                      \
119
    _data_rcv_done,                                     \
120
    _data_xmt_req,                                      \
121
    _data_xmt_done,                                     \
122
    _indicate_status                                    \
123
};
124
# else
125
#  define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char, _data_rcv_req, _data_rcv_done, _data_xmt_req, _data_xmt_done)  \
126
serial_callbacks_t _l = {                               \
127
    _init,                                              \
128
    _xmt_char,                                          \
129
    _rcv_char,                                          \
130
    _data_rcv_req,                                      \
131
    _data_rcv_done,                                     \
132
    _data_xmt_req,                                      \
133
    _data_xmt_done                                      \
134
};
135
# endif
136
#else
137
# ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
138
#  define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char,_indicate_status)  \
139
serial_callbacks_t _l = {                               \
140
    _init,                                              \
141
    _xmt_char,                                          \
142
    _rcv_char,                                          \
143
    _indicate_status                                    \
144
};
145
# else
146
#  define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char)  \
147
serial_callbacks_t _l = {                               \
148
    _init,                                              \
149
    _xmt_char,                                          \
150
    _rcv_char                                           \
151
};
152
# endif
153
#endif
154
 
155
extern serial_callbacks_t cyg_io_serial_callbacks;
156
 
157
typedef struct {
158
    unsigned char           *data;
159
    volatile int             put;
160
    volatile int             get;
161
    int                      len;
162
    volatile int             nb;          // count of bytes currently in buffer
163
    int                      low_water;   // For tx: min space in buffer before restart
164
                                          // For rx: max buffer used before flow unthrottled
165
#ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
166
    int                      high_water;  // For tx: unused
167
                                          // For rx: min buffer used before throttle
168
#endif
169
    cyg_drv_cond_t           wait;
170
    cyg_drv_mutex_t          lock;
171
    bool                     waiting;
172
#ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
173
    bool                     blocking;
174
#endif
175
    volatile bool            abort;       // Set by an outsider to kill processing
176
    volatile cyg_int32       pending;     // This many bytes waiting to be sent
177
#ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT    
178
    struct CYG_SELINFO_TAG   selinfo;     // select info
179
#endif
180
 
181
#ifdef CYGDBG_USE_ASSERTS
182
#ifdef CYGINT_IO_SERIAL_BLOCK_TRANSFER
183
    bool                     block_mode_xfer_running;
184
#endif // CYGINT_IO_SERIAL_BLOCK_TRANSFER
185
#endif // CYGDBG_USE_ASSERTS
186
} cbuf_t;
187
 
188
#define CBUF_INIT(_data, _len) \
189
   {_data, 0, 0, _len}
190
 
191
#ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
192
typedef struct {
193
    cyg_uint32 flags;
194
#ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE
195
    cyg_uint8  xchar;
196
#endif
197
} flow_desc_t;
198
#endif
199
 
200
// Private data which describes this channel
201
struct serial_channel {
202
    serial_funs        *funs;
203
    serial_callbacks_t *callbacks;
204
    void               *dev_priv;  // Whatever is needed by actual device routines
205
    cyg_serial_info_t   config;    // Current configuration
206
    bool                init;
207
    cbuf_t              out_cbuf;
208
    cbuf_t              in_cbuf;
209
#ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
210
    flow_desc_t         flow_desc;
211
#endif
212
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
213
    cyg_serial_line_status_callback_fn_t status_callback;
214
    CYG_ADDRWORD             status_callback_priv;
215
#endif
216
};
217
 
218
// Flow descriptor flag values
219
#define CYG_SERIAL_FLOW_OUT_THROTTLED     (1<<0)
220
#define CYG_SERIAL_FLOW_IN_THROTTLED      (1<<1)
221
 
222
// Initialization macro for serial channel
223
#define SERIAL_CHANNEL(_l,                                              \
224
                       _funs,                                           \
225
                       _dev_priv,                                       \
226
                       _baud, _stop, _parity, _word_length, _flags)     \
227
serial_channel _l = {                                                   \
228
    &_funs,                                                             \
229
    &cyg_io_serial_callbacks,                                           \
230
    &(_dev_priv),                                                       \
231
    CYG_SERIAL_INFO_INIT(_baud, _stop, _parity, _word_length, _flags),  \
232
};
233
 
234
#define SERIAL_CHANNEL_USING_INTERRUPTS(_l,                             \
235
                       _funs,                                           \
236
                       _dev_priv,                                       \
237
                       _baud, _stop, _parity, _word_length, _flags,     \
238
                       _out_buf, _out_buflen,                           \
239
                       _in_buf, _in_buflen)                             \
240
serial_channel _l = {                                                   \
241
    &_funs,                                                             \
242
    &cyg_io_serial_callbacks,                                           \
243
    &(_dev_priv),                                                       \
244
    CYG_SERIAL_INFO_INIT(_baud, _stop, _parity, _word_length, _flags),  \
245
    false,                                                              \
246
    CBUF_INIT(_out_buf, _out_buflen),                                   \
247
    CBUF_INIT(_in_buf, _in_buflen)                                      \
248
};
249
 
250
// Low level interface functions
251
struct serial_funs {
252
    // Send one character to the output device, return true if consumed
253
    bool (*putc)(serial_channel *priv, unsigned char c);
254
    // Fetch one character from the device
255
    unsigned char (*getc)(serial_channel *priv);
256
    // Change hardware configuration (baud rate, etc)
257
    Cyg_ErrNo (*set_config)(serial_channel *priv, cyg_uint32 key, const void *xbuf,
258
                            cyg_uint32 *len);
259
    // Enable the transmit channel and turn on transmit interrupts
260
    void (*start_xmit)(serial_channel *priv);
261
    // Disable the transmit channel and turn transmit interrupts off
262
    void (*stop_xmit)(serial_channel *priv);
263
};
264
 
265
#define SERIAL_FUNS(_l,_putc,_getc,_set_config,_start_xmit,_stop_xmit)  \
266
serial_funs _l = {                                                      \
267
  _putc,                                                                \
268
  _getc,                                                                \
269
  _set_config,                                                          \
270
  _start_xmit,                                                          \
271
  _stop_xmit                                                            \
272
};
273
 
274
extern cyg_devio_table_t cyg_io_serial_devio;
275
 
276
#endif // CYGONCE_SERIAL_H

powered by: WebSVN 2.1.0

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