User | Revision | Line number | New contents of line |
mbed714 |
0:d616ece2d859
|
1
|
/*
|
mbed714 |
0:d616ece2d859
|
2
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
mbed714 |
0:d616ece2d859
|
3
|
* All rights reserved.
|
mbed714 |
0:d616ece2d859
|
4
|
*
|
mbed714 |
0:d616ece2d859
|
5
|
* Redistribution and use in source and binary forms, with or without modification,
|
mbed714 |
0:d616ece2d859
|
6
|
* are permitted provided that the following conditions are met:
|
mbed714 |
0:d616ece2d859
|
7
|
*
|
mbed714 |
0:d616ece2d859
|
8
|
* 1. Redistributions of source code must retain the above copyright notice,
|
mbed714 |
0:d616ece2d859
|
9
|
* this list of conditions and the following disclaimer.
|
mbed714 |
0:d616ece2d859
|
10
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
mbed714 |
0:d616ece2d859
|
11
|
* this list of conditions and the following disclaimer in the documentation
|
mbed714 |
0:d616ece2d859
|
12
|
* and/or other materials provided with the distribution.
|
mbed714 |
0:d616ece2d859
|
13
|
* 3. The name of the author may not be used to endorse or promote products
|
mbed714 |
0:d616ece2d859
|
14
|
* derived from this software without specific prior written permission.
|
mbed714 |
0:d616ece2d859
|
15
|
*
|
mbed714 |
0:d616ece2d859
|
16
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
mbed714 |
0:d616ece2d859
|
17
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
mbed714 |
0:d616ece2d859
|
18
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
mbed714 |
0:d616ece2d859
|
19
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
mbed714 |
0:d616ece2d859
|
20
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
mbed714 |
0:d616ece2d859
|
21
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
mbed714 |
0:d616ece2d859
|
22
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
mbed714 |
0:d616ece2d859
|
23
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
mbed714 |
0:d616ece2d859
|
24
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
mbed714 |
0:d616ece2d859
|
25
|
* OF SUCH DAMAGE.
|
mbed714 |
0:d616ece2d859
|
26
|
*
|
mbed714 |
0:d616ece2d859
|
27
|
* This file is part of the lwIP TCP/IP stack.
|
mbed714 |
0:d616ece2d859
|
28
|
*/
|
mbed714 |
0:d616ece2d859
|
29
|
|
mbed714 |
0:d616ece2d859
|
30
|
/*
|
mbed714 |
0:d616ece2d859
|
31
|
* This is the interface to the platform specific serial IO module
|
mbed714 |
0:d616ece2d859
|
32
|
* It needs to be implemented by those platforms which need SLIP or PPP
|
mbed714 |
0:d616ece2d859
|
33
|
*/
|
mbed714 |
0:d616ece2d859
|
34
|
|
mbed714 |
0:d616ece2d859
|
35
|
#ifndef __SIO_H__
|
mbed714 |
0:d616ece2d859
|
36
|
#define __SIO_H__
|
mbed714 |
0:d616ece2d859
|
37
|
|
mbed714 |
0:d616ece2d859
|
38
|
#include "lwip/arch.h"
|
mbed714 |
0:d616ece2d859
|
39
|
|
mbed714 |
0:d616ece2d859
|
40
|
#ifdef __cplusplus
|
mbed714 |
0:d616ece2d859
|
41
|
extern "C" {
|
mbed714 |
0:d616ece2d859
|
42
|
#endif
|
mbed714 |
0:d616ece2d859
|
43
|
|
mbed714 |
0:d616ece2d859
|
44
|
/* If you want to define sio_fd_t elsewhere or differently,
|
mbed714 |
0:d616ece2d859
|
45
|
define this in your cc.h file. */
|
mbed714 |
0:d616ece2d859
|
46
|
#ifndef __sio_fd_t_defined
|
mbed714 |
0:d616ece2d859
|
47
|
typedef void * sio_fd_t;
|
mbed714 |
0:d616ece2d859
|
48
|
#endif
|
mbed714 |
0:d616ece2d859
|
49
|
|
mbed714 |
0:d616ece2d859
|
50
|
/* The following functions can be defined to something else in your cc.h file
|
mbed714 |
0:d616ece2d859
|
51
|
or be implemented in your custom sio.c file. */
|
mbed714 |
0:d616ece2d859
|
52
|
|
mbed714 |
0:d616ece2d859
|
53
|
#ifndef sio_open
|
mbed714 |
0:d616ece2d859
|
54
|
/**
|
mbed714 |
0:d616ece2d859
|
55
|
* Opens a serial device for communication.
|
mbed714 |
0:d616ece2d859
|
56
|
*
|
mbed714 |
0:d616ece2d859
|
57
|
* @param devnum device number
|
mbed714 |
0:d616ece2d859
|
58
|
* @return handle to serial device if successful, NULL otherwise
|
mbed714 |
0:d616ece2d859
|
59
|
*/
|
mbed714 |
0:d616ece2d859
|
60
|
sio_fd_t sio_open(u8_t devnum);
|
mbed714 |
0:d616ece2d859
|
61
|
#endif
|
mbed714 |
0:d616ece2d859
|
62
|
|
mbed714 |
0:d616ece2d859
|
63
|
#ifndef sio_send
|
mbed714 |
0:d616ece2d859
|
64
|
/**
|
mbed714 |
0:d616ece2d859
|
65
|
* Sends a single character to the serial device.
|
mbed714 |
0:d616ece2d859
|
66
|
*
|
mbed714 |
0:d616ece2d859
|
67
|
* @param c character to send
|
mbed714 |
0:d616ece2d859
|
68
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
69
|
*
|
mbed714 |
0:d616ece2d859
|
70
|
* @note This function will block until the character can be sent.
|
mbed714 |
0:d616ece2d859
|
71
|
*/
|
mbed714 |
0:d616ece2d859
|
72
|
void sio_send(u8_t c, sio_fd_t fd);
|
mbed714 |
0:d616ece2d859
|
73
|
#endif
|
mbed714 |
0:d616ece2d859
|
74
|
|
mbed714 |
0:d616ece2d859
|
75
|
#ifndef sio_recv
|
mbed714 |
0:d616ece2d859
|
76
|
/**
|
mbed714 |
0:d616ece2d859
|
77
|
* Receives a single character from the serial device.
|
mbed714 |
0:d616ece2d859
|
78
|
*
|
mbed714 |
0:d616ece2d859
|
79
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
80
|
*
|
mbed714 |
0:d616ece2d859
|
81
|
* @note This function will block until a character is received.
|
mbed714 |
0:d616ece2d859
|
82
|
*/
|
mbed714 |
0:d616ece2d859
|
83
|
u8_t sio_recv(sio_fd_t fd);
|
mbed714 |
0:d616ece2d859
|
84
|
#endif
|
mbed714 |
0:d616ece2d859
|
85
|
|
mbed714 |
0:d616ece2d859
|
86
|
#ifndef sio_read
|
mbed714 |
0:d616ece2d859
|
87
|
/**
|
mbed714 |
0:d616ece2d859
|
88
|
* Reads from the serial device.
|
mbed714 |
0:d616ece2d859
|
89
|
*
|
mbed714 |
0:d616ece2d859
|
90
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
91
|
* @param data pointer to data buffer for receiving
|
mbed714 |
0:d616ece2d859
|
92
|
* @param len maximum length (in bytes) of data to receive
|
mbed714 |
0:d616ece2d859
|
93
|
* @return number of bytes actually received - may be 0 if aborted by sio_read_abort
|
mbed714 |
0:d616ece2d859
|
94
|
*
|
mbed714 |
0:d616ece2d859
|
95
|
* @note This function will block until data can be received. The blocking
|
mbed714 |
0:d616ece2d859
|
96
|
* can be cancelled by calling sio_read_abort().
|
mbed714 |
0:d616ece2d859
|
97
|
*/
|
mbed714 |
0:d616ece2d859
|
98
|
u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len);
|
mbed714 |
0:d616ece2d859
|
99
|
#endif
|
mbed714 |
0:d616ece2d859
|
100
|
|
mbed714 |
0:d616ece2d859
|
101
|
#ifndef sio_tryread
|
mbed714 |
0:d616ece2d859
|
102
|
/**
|
mbed714 |
0:d616ece2d859
|
103
|
* Tries to read from the serial device. Same as sio_read but returns
|
mbed714 |
0:d616ece2d859
|
104
|
* immediately if no data is available and never blocks.
|
mbed714 |
0:d616ece2d859
|
105
|
*
|
mbed714 |
0:d616ece2d859
|
106
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
107
|
* @param data pointer to data buffer for receiving
|
mbed714 |
0:d616ece2d859
|
108
|
* @param len maximum length (in bytes) of data to receive
|
mbed714 |
0:d616ece2d859
|
109
|
* @return number of bytes actually received
|
mbed714 |
0:d616ece2d859
|
110
|
*/
|
mbed714 |
0:d616ece2d859
|
111
|
u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len);
|
mbed714 |
0:d616ece2d859
|
112
|
#endif
|
mbed714 |
0:d616ece2d859
|
113
|
|
mbed714 |
0:d616ece2d859
|
114
|
#ifndef sio_write
|
mbed714 |
0:d616ece2d859
|
115
|
/**
|
mbed714 |
0:d616ece2d859
|
116
|
* Writes to the serial device.
|
mbed714 |
0:d616ece2d859
|
117
|
*
|
mbed714 |
0:d616ece2d859
|
118
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
119
|
* @param data pointer to data to send
|
mbed714 |
0:d616ece2d859
|
120
|
* @param len length (in bytes) of data to send
|
mbed714 |
0:d616ece2d859
|
121
|
* @return number of bytes actually sent
|
mbed714 |
0:d616ece2d859
|
122
|
*
|
mbed714 |
0:d616ece2d859
|
123
|
* @note This function will block until all data can be sent.
|
mbed714 |
0:d616ece2d859
|
124
|
*/
|
mbed714 |
0:d616ece2d859
|
125
|
u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len);
|
mbed714 |
0:d616ece2d859
|
126
|
#endif
|
mbed714 |
0:d616ece2d859
|
127
|
|
mbed714 |
0:d616ece2d859
|
128
|
#ifndef sio_read_abort
|
mbed714 |
0:d616ece2d859
|
129
|
/**
|
mbed714 |
0:d616ece2d859
|
130
|
* Aborts a blocking sio_read() call.
|
mbed714 |
0:d616ece2d859
|
131
|
*
|
mbed714 |
0:d616ece2d859
|
132
|
* @param fd serial device handle
|
mbed714 |
0:d616ece2d859
|
133
|
*/
|
mbed714 |
0:d616ece2d859
|
134
|
void sio_read_abort(sio_fd_t fd);
|
mbed714 |
0:d616ece2d859
|
135
|
#endif
|
mbed714 |
0:d616ece2d859
|
136
|
|
mbed714 |
0:d616ece2d859
|
137
|
#ifdef __cplusplus
|
mbed714 |
0:d616ece2d859
|
138
|
}
|
mbed714 |
0:d616ece2d859
|
139
|
#endif
|
mbed714 |
0:d616ece2d859
|
140
|
|
mbed714 |
0:d616ece2d859
|
141
|
#endif /* __SIO_H__ */
|