49 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) 56 #define PRINTF(...) printf(__VA_ARGS__) 57 #define PUTCHAR(X) do { putchar(X); putchar('\n'); } while(0) 59 #define PRINTF(...) do {} while(0) 60 #define PUTCHAR(X) do {} while(0) 65 #define SLIP_ESC_END 0334 66 #define SLIP_ESC_ESC 0335 67 #define SLIP_NEUTRAL 0 68 #define SLIP_ESC_XON 0336 69 #define SLIP_ESC_XOFF 0337 70 #define XON ((unsigned char)17) 71 #define XOFF ((unsigned char)19) 72 #if UART_XONXOFF_FLOW_CTRL 73 volatile unsigned char xonxoff_state = XON;
76 PROCESS(slip_process,
"SLIP driver");
78 #include "dev/uart0.h" 79 #define STORE_UART_INTERRUPTS uart0_store_interrupts 80 #define RESTORE_UART_INTERRUPTS uart0_restore_interrupts 81 #define DISABLE_UART_INTERRUPTS uart0_disable_interrupts 82 #define ENABLE_UART_INTERRUPTS uart0_enable_interrupts 89 #define ATOMIC(blah) \ 92 DISABLE_UART_INTERRUPTS(); \ 95 ENABLE_UART_INTERRUPTS(); \ 99 #define GLOBAL_ATOMIC(blah) \ 101 MICRO_DISABLE_INTERRUPTS(); \ 103 MICRO_ENABLE_INTERRUPTS(); \ 107 #define SLIP_STATISTICS(statement) 109 uint16_t slip_drop_bytes, slip_overflow, slip_error_drop;
111 uint16_t slip_rubbish, slip_twopackets, slip_ip_drop;
112 unsigned long slip_received, slip_frames;
113 #define SLIP_STATISTICS(statement) statement 117 #ifdef SLIP_CONF_RX_BUFSIZE 118 #define RX_BUFSIZE SLIP_CONF_RX_BUFSIZE 120 #if RX_BUFSIZE < (UIP_BUFSIZE - UIP_LLH_LEN + 16) 121 #error "SLIP_CONF_RX_BUFSIZE too small for UIP_BUFSIZE" 125 #define RX_BUFSIZE (UIP_CONF_BUFFER_SIZE * 2) 134 static volatile uint16_t begin, end, end_counter;
135 static uint8_t rxbuf[RX_BUFSIZE];
136 static volatile uint8_t is_dropping = 0;
137 static volatile uint8_t is_full = 0;
139 static void (*input_callback)(void) = NULL;
147 slip_write_char(uint8_t c)
153 }
else if(c == SLIP_ESC) {
157 #if UART_XONXOFF_FLOW_CTRL 162 }
else if(c == XOFF) {
173 const uint8_t *ptr = _ptr;
179 for(i = 0; i < len; ++i) {
209 begin = end = end_counter = 0;
215 slip_poll_handler(uint8_t *outbuf, uint16_t blen)
222 if(end_counter == 0 && is_full == 0) {
225 for(len = 0, pos = begin, state = c = SLIP_NEUTRAL;
231 if(pos == RX_BUFSIZE) {
249 if(state == SLIP_ESC) {
250 outbuf[len++] = SLIP_END;
251 state = SLIP_NEUTRAL;
256 if(state == SLIP_ESC) {
257 outbuf[len++] = SLIP_ESC;
258 state = SLIP_NEUTRAL;
262 #if UART_XONXOFF_FLOW_CTRL 264 if(state == SLIP_ESC) {
266 state = SLIP_NEUTRAL;
271 if(state == SLIP_ESC) {
272 outbuf[len++] = XOFF;
273 state = SLIP_NEUTRAL;
280 state = SLIP_NEUTRAL;
298 SLIP_STATISTICS(slip_error_drop++);
300 PRINTF(
"SLIP: *** out of sync!\n");
303 if(end_counter > 0) {
323 PRINTF(
"SLIP: recv bytes %u frames RECV: %u. is_full %u, is_dropping %u.\n",
324 end_counter,
uip_len, is_full, is_dropping);
329 ENABLE_UART_INTERRUPTS();
336 #ifdef SLIP_CONF_TCPIP_INPUT 337 SLIP_CONF_TCPIP_INPUT();
355 static int in_frame = 0;
356 uint16_t next, next_next;
357 int error_return_code = is_full ? -1 : 0;
358 int success_return_code = is_full ? -1 : 1;
360 SLIP_STATISTICS(slip_received++);
362 #if UART_XONXOFF_FLOW_CTRL 363 if(c == XOFF || c == XON) {
376 SLIP_STATISTICS(slip_drop_bytes++);
381 return error_return_code;
384 if(!in_frame && c == SLIP_END) {
386 return error_return_code;
390 if(next >= RX_BUFSIZE) {
393 next_next = next + 1;
394 if(next_next >= RX_BUFSIZE) {
398 if(next_next == begin) {
401 DISABLE_UART_INTERRUPTS();
410 SLIP_STATISTICS(slip_overflow++);
413 DISABLE_UART_INTERRUPTS();
425 SLIP_STATISTICS(slip_frames++);
427 return success_return_code;
429 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_LLH_LEN
The link level header length.
#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.