int _slip_tx_cb(void *arg) { if (_SLIP_DEV(arg)->out_buf->avail > 0) { char c = (char)ringbuffer_get_one(_SLIP_DEV(arg)->out_buf); uart_write((uart_t)(_SLIP_DEV(arg)->uart), c); return 1; } return 0; }
static void *_slip(void *args) { gnrc_slip_dev_t *dev = _SLIP_DEV(args); msg_t msg, reply, msg_q[_SLIP_MSG_QUEUE_SIZE]; msg_init_queue(msg_q, _SLIP_MSG_QUEUE_SIZE); dev->slip_pid = thread_getpid(); gnrc_netif_add(dev->slip_pid); DEBUG("slip: SLIP runs on UART_%d\n", dev->uart); while (1) { DEBUG("slip: waiting for incoming messages\n"); msg_receive(&msg); switch (msg.type) { case _SLIP_MSG_TYPE: DEBUG("slip: incoming message of size %" PRIu32 " from UART_%d in buffer\n", msg.content.value, dev->uart); _slip_receive(dev, (size_t)msg.content.value); break; case GNRC_NETAPI_MSG_TYPE_SND: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SND received\n"); _slip_send(dev, (gnrc_pktsnip_t *)msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_GET: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_GET received\n"); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)_slip_get((gnrc_netapi_opt_t *)msg.content.ptr); msg_reply(&msg, &reply); break; case GNRC_NETAPI_MSG_TYPE_SET: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SET received\n"); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)(-ENOTSUP); DEBUG("slip: I don't support this but have to reply.\n"); msg_reply(&msg, &reply); break; } } /* should be never reached */ return NULL; }
/* UART callbacks */ static void _slip_rx_cb(void *arg, char data) { if (data == _SLIP_END) { msg_t msg; msg.type = _SLIP_MSG_TYPE; msg.content.value = _SLIP_DEV(arg)->in_bytes; msg_send_int(&msg, _SLIP_DEV(arg)->slip_pid); _SLIP_DEV(arg)->in_bytes = 0; } else if (_SLIP_DEV(arg)->in_esc) { _SLIP_DEV(arg)->in_esc = 0; switch (data) { case (_SLIP_END_ESC): if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, _SLIP_END) < 0) { _SLIP_DEV(arg)->in_bytes++; } break; case (_SLIP_ESC_ESC): if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, _SLIP_ESC) < 0) { _SLIP_DEV(arg)->in_bytes++; } break; default: break; } } else if (data == _SLIP_ESC) { _SLIP_DEV(arg)->in_esc = 1; } else { if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, data) < 0) { _SLIP_DEV(arg)->in_bytes++; } } }