50 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
57 #define PRINTF(...) printf(__VA_ARGS__)
58 #define PUTCHAR(X) do { putchar(X); putchar('\n'); } while(0)
60 #define PRINTF(...) do {} while(0)
61 #define PUTCHAR(X) do {} while(0)
66 #define SLIP_ESC_END 0334
67 #define SLIP_ESC_ESC 0335
68 #define SLIP_NEUTRAL 0
69 #define SLIP_ESC_XON 0336
70 #define SLIP_ESC_XOFF 0337
71 #define XON ((unsigned char)17)
72 #define XOFF ((unsigned char)19)
73 #if UART_XONXOFF_FLOW_CTRL
74 volatile unsigned char xonxoff_state = XON;
77 PROCESS(slip_process,
"SLIP driver");
79 #include "dev/uart0.h"
80 #define STORE_UART_INTERRUPTS uart0_store_interrupts
81 #define RESTORE_UART_INTERRUPTS uart0_restore_interrupts
82 #define DISABLE_UART_INTERRUPTS uart0_disable_interrupts
83 #define ENABLE_UART_INTERRUPTS uart0_enable_interrupts
90 #define ATOMIC(blah) \
93 DISABLE_UART_INTERRUPTS(); \
96 ENABLE_UART_INTERRUPTS(); \
100 #define GLOBAL_ATOMIC(blah) \
102 MICRO_DISABLE_INTERRUPTS(); \
104 MICRO_ENABLE_INTERRUPTS(); \
108 #define SLIP_STATISTICS(statement)
110 uint16_t slip_drop_bytes, slip_overflow, slip_error_drop;
112 uint16_t slip_rubbish, slip_twopackets, slip_ip_drop;
113 unsigned long slip_received, slip_frames;
114 #define SLIP_STATISTICS(statement) statement
118 #ifdef SLIP_CONF_RX_BUFSIZE
119 #define RX_BUFSIZE SLIP_CONF_RX_BUFSIZE
121 #if RX_BUFSIZE < (UIP_BUFSIZE - UIP_LLH_LEN + 16)
122 #error "SLIP_CONF_RX_BUFSIZE too small for UIP_BUFSIZE"
126 #define RX_BUFSIZE (UIP_CONF_BUFFER_SIZE * 2)
135 static volatile uint16_t begin, end, end_counter;
136 static uint8_t
rxbuf[RX_BUFSIZE];
137 static volatile uint8_t is_dropping = 0;
138 static volatile uint8_t is_full = 0;
140 static void (*input_callback)(void) =
NULL;
148 slip_write_char(uint8_t c)
154 }
else if(c == SLIP_ESC) {
158 #if UART_XONXOFF_FLOW_CTRL
163 }
else if(c == XOFF) {
172 slip_write(
const void *_ptr,
int len)
174 const uint8_t *ptr = _ptr;
180 for(i = 0; i < len; ++i) {
203 if(i == UIP_TCPIP_HLEN) {
217 begin = end = end_counter = 0;
223 slip_poll_handler(uint8_t *outbuf, uint16_t blen)
230 if(end_counter == 0 && is_full == 0) {
233 for(len = 0, pos = begin, state = c = SLIP_NEUTRAL;
239 if(pos == RX_BUFSIZE) {
257 if(state == SLIP_ESC) {
258 outbuf[len++] = SLIP_END;
259 state = SLIP_NEUTRAL;
264 if(state == SLIP_ESC) {
265 outbuf[len++] = SLIP_ESC;
266 state = SLIP_NEUTRAL;
270 #if UART_XONXOFF_FLOW_CTRL
272 if(state == SLIP_ESC) {
274 state = SLIP_NEUTRAL;
279 if(state == SLIP_ESC) {
280 outbuf[len++] = XOFF;
281 state = SLIP_NEUTRAL;
288 state = SLIP_NEUTRAL;
306 SLIP_STATISTICS(slip_error_drop++);
308 PRINTF(
"SLIP: *** out of sync!\n");
311 if(end_counter > 0) {
331 PRINTF(
"SLIP: recv bytes %u frames RECV: %u. is_full %u, is_dropping %u.\n",
332 end_counter,
uip_len, is_full, is_dropping);
337 ENABLE_UART_INTERRUPTS();
344 #ifdef SLIP_CONF_TCPIP_INPUT
345 SLIP_CONF_TCPIP_INPUT();
363 static int in_frame = 0;
364 uint16_t next, next_next;
365 int error_return_code = is_full ? -1 : 0;
366 int success_return_code = is_full ? -1 : 1;
368 SLIP_STATISTICS(slip_received++);
370 #if UART_XONXOFF_FLOW_CTRL
371 if(c == XOFF || c == XON) {
384 SLIP_STATISTICS(slip_drop_bytes++);
389 return error_return_code;
392 if(!in_frame && c == SLIP_END) {
394 return error_return_code;
398 if(next >= RX_BUFSIZE) {
401 next_next = next + 1;
402 if(next_next >= RX_BUFSIZE) {
406 if(next_next == begin) {
409 DISABLE_UART_INTERRUPTS();
418 SLIP_STATISTICS(slip_overflow++);
421 DISABLE_UART_INTERRUPTS();
433 SLIP_STATISTICS(slip_frames++);
435 return success_return_code;
437 return error_return_code;
440 #if SLIP_BRIDGE_CONF_NO_PUTCHAR
uip_len
The length of the packet in the uip_buf buffer.
void process_poll(struct process *p)
Request a process to be polled.
uint8_t slip_send(void)
Send an IP packet from the uIP buffer with SLIP.
#define UIP_FW_OK
A non-error message that indicates that something went OK.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
void slip_arch_writeb(unsigned char c)
Copyright (c) 2014, Analog Devices, Inc.
#define UIP_LLH_LEN
The link level header length.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
uip_appdata
Pointer to the application data in the packet buffer.
int slip_input_byte(unsigned char c)
Input a SLIP byte.
#define ATOMIC(blah)
A block of code may be made atomic by wrapping it with this macro.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
void slip_set_input_callback(void(*c)(void))
Set a function to be called when there is activity on the SLIP interface; used for detecting if a nod...
#define NULL
The null pointer.
uIP packet forwarding header file.
Header file for the uIP TCP/IP stack.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
tcirc_buf rxbuf
The RX circular buffer, for storing characters from serial port.
#define PROCESS_BEGIN()
Define the beginning of a process.