55 #define PRINTF(...) printf(__VA_ARGS__) 56 #define PUTCHAR(X) do { putchar(X); putchar('\n'); } while(0) 58 #define PRINTF(...) do {} while(0) 59 #define PUTCHAR(X) do {} while(0) 64 #define SLIP_ESC_END 0334 65 #define SLIP_ESC_ESC 0335 66 #define SLIP_NEUTRAL 0 67 #define SLIP_ESC_XON 0336 68 #define SLIP_ESC_XOFF 0337 69 #define XON ((unsigned char)17) 70 #define XOFF ((unsigned char)19) 71 #if UART_XONXOFF_FLOW_CTRL 72 volatile unsigned char xonxoff_state = XON;
75 PROCESS(slip_process,
"SLIP driver");
77 #include "dev/uart0.h" 78 #define STORE_UART_INTERRUPTS uart0_store_interrupts 79 #define RESTORE_UART_INTERRUPTS uart0_restore_interrupts 80 #define DISABLE_UART_INTERRUPTS uart0_disable_interrupts 81 #define ENABLE_UART_INTERRUPTS uart0_enable_interrupts 88 #define ATOMIC(blah) \ 91 DISABLE_UART_INTERRUPTS(); \ 94 ENABLE_UART_INTERRUPTS(); \ 98 #define GLOBAL_ATOMIC(blah) \ 100 MICRO_DISABLE_INTERRUPTS(); \ 102 MICRO_ENABLE_INTERRUPTS(); \ 106 #define SLIP_STATISTICS(statement) 108 uint16_t slip_drop_bytes, slip_overflow, slip_error_drop;
110 uint16_t slip_rubbish, slip_twopackets, slip_ip_drop;
111 unsigned long slip_received, slip_frames;
112 #define SLIP_STATISTICS(statement) statement 116 #ifdef SLIP_CONF_RX_BUFSIZE 117 #define RX_BUFSIZE SLIP_CONF_RX_BUFSIZE 119 #if RX_BUFSIZE < (UIP_BUFSIZE + 16) 120 #error "SLIP_CONF_RX_BUFSIZE too small for UIP_BUFSIZE" 124 #define RX_BUFSIZE (UIP_CONF_BUFFER_SIZE * 2) 133 static volatile uint16_t begin, end, end_counter;
134 static uint8_t rxbuf[RX_BUFSIZE];
135 static volatile uint8_t is_dropping = 0;
136 static volatile uint8_t is_full = 0;
138 static void (*input_callback)(void) = NULL;
146 slip_write_char(uint8_t c)
152 }
else if(c == SLIP_ESC) {
156 #if UART_XONXOFF_FLOW_CTRL 161 }
else if(c == XOFF) {
172 const uint8_t *ptr = _ptr;
178 for(i = 0; i < len; ++i) {
208 begin = end = end_counter = 0;
214 slip_poll_handler(uint8_t *outbuf, uint16_t blen)
221 if(end_counter == 0 && is_full == 0) {
224 for(len = 0, pos = begin, state = c = SLIP_NEUTRAL;
230 if(pos == RX_BUFSIZE) {
248 if(state == SLIP_ESC) {
249 outbuf[len++] = SLIP_END;
250 state = SLIP_NEUTRAL;
255 if(state == SLIP_ESC) {
256 outbuf[len++] = SLIP_ESC;
257 state = SLIP_NEUTRAL;
261 #if UART_XONXOFF_FLOW_CTRL 263 if(state == SLIP_ESC) {
265 state = SLIP_NEUTRAL;
270 if(state == SLIP_ESC) {
271 outbuf[len++] = XOFF;
272 state = SLIP_NEUTRAL;
279 state = SLIP_NEUTRAL;
297 SLIP_STATISTICS(slip_error_drop++);
299 PRINTF(
"SLIP: *** out of sync!\n");
302 if(end_counter > 0) {
321 PRINTF(
"SLIP: recv bytes %u frames RECV: %u. is_full %u, is_dropping %u.\n",
322 end_counter,
uip_len, is_full, is_dropping);
327 ENABLE_UART_INTERRUPTS();
334 #ifdef SLIP_CONF_TCPIP_INPUT 335 SLIP_CONF_TCPIP_INPUT();
353 static int in_frame = 0;
354 uint16_t next, next_next;
355 int error_return_code = is_full ? -1 : 0;
356 int success_return_code = is_full ? -1 : 1;
358 SLIP_STATISTICS(slip_received++);
360 #if UART_XONXOFF_FLOW_CTRL 361 if(c == XOFF || c == XON) {
374 SLIP_STATISTICS(slip_drop_bytes++);
379 return error_return_code;
382 if(!in_frame && c == SLIP_END) {
384 return error_return_code;
388 if(next >= RX_BUFSIZE) {
391 next_next = next + 1;
392 if(next_next >= RX_BUFSIZE) {
396 if(next_next == begin) {
399 DISABLE_UART_INTERRUPTS();
408 SLIP_STATISTICS(slip_overflow++);
411 DISABLE_UART_INTERRUPTS();
423 SLIP_STATISTICS(slip_frames++);
425 return success_return_code;
427 return error_return_code;
#define PROCESS(name, strname)
Declare a process.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
void slip_arch_writeb(unsigned char c)
Write a single byte over SLIP.
void process_poll(struct process *p)
Request a process to be polled.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
Header file for the uIP TCP/IP stack.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.