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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [src/] [ecos/] [sio.c] - Blame information for rev 865

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      sio.c
4
//
5
//      Serial operations for SLIP, PPP etc.
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2008, 2009 Free Software Foundation
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
//####ECOSGPLCOPYRIGHTEND####
37
//==========================================================================
38
//#####DESCRIPTIONBEGIN####
39
//
40
// Author(s):    Simon Kallweit
41
// Contributors:
42
// Date:         2008-12-01
43
// Purpose:
44
// Description:  Serial operations for SLIP, PPP etc.
45
//
46
//####DESCRIPTIONEND####
47
//
48
//==========================================================================
49
 
50
#include <pkgconf/net_lwip.h>
51
 
52
#include "lwip.h"
53
#include "lwip/opt.h"
54
#include "lwip/def.h"
55
#include "lwip/sys.h"
56
#include "lwip/netif.h"
57
#include "lwip/sio.h"
58
 
59
#include <cyg/error/codes.h>
60
#include <cyg/io/io.h>
61
#include <cyg/io/serialio.h>
62
#include <cyg/io/config_keys.h>
63
#include <cyg/infra/cyg_ass.h>
64
#include <cyg/infra/diag.h>
65
 
66
 
67
/*
68
 * Opens a serial device for communication.
69
 */
70
sio_fd_t sio_open(u8_t devnum)
71
{
72
    Cyg_ErrNo ret;
73
    cyg_io_handle_t handle;
74
    char *dev;
75
 
76
#ifdef CYGDBG_LWIP_DEBUG_SIO
77
    diag_printf("sio_open(devnum=%d)\n", devnum);
78
#endif
79
 
80
    switch (devnum) {
81
#ifdef CYGPKG_LWIP_SLIP
82
    case SIO_DEV_SLIPIF:
83
        dev = CYGDAT_LWIP_SLIPIF_DEV;
84
        break;
85
#endif
86
#ifdef CYGFUN_LWIP_PPPOS_SUPPORT
87
    case SIO_DEV_PPPOS:
88
        dev = CYGDAT_LWIP_PPPOS_DEV;
89
        break;
90
#endif
91
    default:
92
        // Unknown serial io device
93
        return NULL;
94
        break;
95
    }
96
 
97
    ret = cyg_io_lookup(dev, &handle);
98
    if (ret != ENOERR)
99
        return NULL;
100
 
101
    return handle;
102
}
103
 
104
/*
105
 * Sends a single character to the serial device.
106
 */
107
void sio_send(u8_t c, sio_fd_t fd)
108
{
109
    cyg_uint32 len = 1;
110
 
111
#ifdef CYGDBG_LWIP_DEBUG_SIO
112
    diag_printf("sio_send(c=0x%02x,fd=%p)\n", c, fd);
113
#endif
114
 
115
        cyg_io_write((cyg_io_handle_t) fd, &c, &len);
116
}
117
 
118
/*
119
 * Receives a single character from the serial device.
120
 */
121
u8_t sio_recv(sio_fd_t fd)
122
{
123
    cyg_uint32 len = 1;
124
    char c;
125
 
126
#ifdef CYGDBG_LWIP_DEBUG_SIO
127
    diag_printf("sio_recv(fd=%p)\n", fd);
128
#endif
129
 
130
        cyg_io_read((cyg_io_handle_t) fd, &c, &len);
131
 
132
#ifdef CYGDBG_LWIP_DEBUG_SIO
133
    diag_printf("sio_recv: %02X\n", (cyg_uint8) c);
134
#endif
135
 
136
        return c;
137
}
138
 
139
/*
140
 * Reads from the serial device.
141
 */
142
u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
143
{
144
    Cyg_ErrNo ret;
145
 
146
#ifdef CYGDBG_LWIP_DEBUG_SIO
147
    diag_printf("sio_read(fd=%p,data=%p,len=%lu:)\n", fd, data, len);
148
#endif
149
 
150
    ret = cyg_io_read((cyg_io_handle_t) fd, data, (cyg_uint32 *) &len);
151
    if (ret != ENOERR)
152
        return 0;
153
 
154
#ifdef CYGDBG_LWIP_DEBUG_SIO
155
    diag_printf("sio_read: ");
156
    diag_dump_buf(data, len);
157
#endif
158
 
159
    return len;
160
}
161
 
162
/*
163
 * Tries to read from the serial device. Same as sio_read but returns
164
 * immediately if no data is available and never blocks.
165
 */
166
u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
167
{
168
    Cyg_ErrNo ret;
169
    cyg_serial_buf_info_t info;
170
    cyg_uint32 l;
171
 
172
#ifdef CYGDBG_LWIP_DEBUG_SIO
173
    diag_printf("sio_tryread(fd=%p,data=%p,len=%lu:)\n", fd, data, len);
174
#endif
175
 
176
    // Check how many bytes there are to read
177
    l = sizeof(info);
178
    ret = cyg_io_get_config((cyg_io_handle_t) fd, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO, &info, &l);
179
    if (ret != ENOERR)
180
        return 0;
181
    l = info.rx_count;
182
    if (l < 1)
183
        return 0;
184
    if (l > len)
185
        l = len;
186
 
187
    ret = cyg_io_read((cyg_io_handle_t) fd, data, &l);
188
    if (ret != ENOERR)
189
        return 0;
190
 
191
#ifdef CYGDBG_LWIP_DEBUG_SIO
192
   diag_printf("sio_tryread: ");
193
   diag_dump_buf(data, len);
194
#endif
195
 
196
   return l;
197
}
198
 
199
/*
200
 * Writes to the serial device.
201
 */
202
u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len)
203
{
204
    Cyg_ErrNo ret;
205
    cyg_uint32 count = 0;
206
    cyg_uint32 chunk;
207
 
208
#ifdef CYGDBG_LWIP_DEBUG_SIO
209
    diag_printf("sio_write(fd=%p,data=%p,len=%lu:)\n", fd, data, len);
210
    diag_printf("sio_write: ");
211
    diag_dump_buf(data, len);
212
#endif
213
 
214
    while (count < len) {
215
        chunk = len - count;
216
        ret = cyg_io_write((cyg_io_handle_t) fd, data, &chunk);
217
        if (ret != ENOERR)
218
            break;
219
        data += chunk;
220
        count += chunk;
221
    }
222
 
223
        return count;
224
}
225
 
226
/*
227
 * Aborts a blocking sio_read() call.
228
 */
229
void sio_read_abort(sio_fd_t fd)
230
{
231
    cyg_uint32 l = 0;
232
 
233
#ifdef CYGDBG_LWIP_DEBUG_SIO
234
    diag_printf("sio_read_abort(fd=%p)\n", fd);
235
#endif
236
 
237
   cyg_io_set_config((cyg_io_handle_t) fd, CYG_IO_GET_CONFIG_SERIAL_ABORT, NULL, &l);
238
}

powered by: WebSVN 2.1.0

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