40#define SLIP_ESC_END 0334
41#define SLIP_ESC_ESC 0335
43PROCESS(slip_process,
"SLIP driver");
45#if SLIP_CONF_WITH_STATS
46static uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
47#define SLIP_STATISTICS(statement) statement
49#define SLIP_STATISTICS(statement)
53#define RX_BUFSIZE (UIP_BUFSIZE + 16)
72static uint8_t state = STATE_TWOPACKETS;
73static uint16_t begin, next_free;
74static uint8_t rxbuf[RX_BUFSIZE];
75static uint16_t pkt_end;
77static void (*input_callback)(void) = NULL;
80slip_set_input_callback(
void (*c)(
void))
92slip_write(
const void *_ptr,
int len)
94 const uint8_t *ptr = _ptr;
98 slip_arch_writeb(SLIP_END);
100 for(i = 0; i < len; ++i) {
103 slip_arch_writeb(SLIP_ESC);
105 }
else if(c == SLIP_ESC) {
106 slip_arch_writeb(SLIP_ESC);
112 slip_arch_writeb(SLIP_END);
118 begin = next_free = pkt_end = 0;
123slip_poll_handler(uint8_t *outbuf, uint16_t blen)
129 if(begin != pkt_end) {
131 uint16_t cur_next_free;
135 if(begin < pkt_end) {
138 for(i = begin; i < pkt_end; ++i) {
144 if(rxbuf[i] == SLIP_ESC_ESC) {
145 outbuf[len] = SLIP_ESC;
147 }
else if(rxbuf[i] == SLIP_ESC_END) {
148 outbuf[len] = SLIP_END;
152 }
else if(rxbuf[i] == SLIP_ESC) {
155 outbuf[len] = rxbuf[i];
162 for(i = begin; i < RX_BUFSIZE; ++i) {
168 if(rxbuf[i] == SLIP_ESC_ESC) {
169 outbuf[len] = SLIP_ESC;
171 }
else if(rxbuf[i] == SLIP_ESC_END) {
172 outbuf[len] = SLIP_END;
176 }
else if(rxbuf[i] == SLIP_ESC) {
179 outbuf[len] = rxbuf[i];
183 for(i = 0; i < pkt_end; ++i) {
189 if(rxbuf[i] == SLIP_ESC_ESC) {
190 outbuf[len] = SLIP_ESC;
192 }
else if(rxbuf[i] == SLIP_ESC_END) {
193 outbuf[len] = SLIP_END;
197 }
else if(rxbuf[i] == SLIP_ESC) {
200 outbuf[len] = rxbuf[i];
207 pkt_end = pkt_end + 1;
208 if(pkt_end == RX_BUFSIZE) {
211 if(pkt_end != next_free) {
212 cur_next_free = next_free;
214 while(cur_ptr != cur_next_free) {
215 if(rxbuf[cur_ptr] == SLIP_END) {
216 uint16_t tmp_begin = pkt_end;
224 if(cur_ptr == RX_BUFSIZE) {
228 if(cur_ptr == cur_next_free) {
264slip_input_byte(
unsigned char c)
275 if(c != SLIP_ESC_END && c != SLIP_ESC_ESC) {
276 state = STATE_RUBBISH;
277 SLIP_STATISTICS(slip_rubbish++);
291 next_free = next_free + 1;
292 if(next_free == RX_BUFSIZE) {
295 if(next_free == begin) {
296 state = STATE_RUBBISH;
297 SLIP_STATISTICS(slip_overflow++);
309 if(cur_end != pkt_end) {
310 if(begin == pkt_end) {
313 SLIP_STATISTICS(slip_twopackets++);
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
void process_poll(struct process *p)
Request a process to be polled.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
Header file for the uIP TCP/IP stack.