Michiel Berckvens / Mbed 2 deprecated ProjectHTTP

Dependencies:   DS1307 TextLCD mbed

Committer:
Michielber
Date:
Thu Dec 04 10:36:40 2014 +0000
Revision:
0:f615d151a72c
Berckvens Michiel & Basteyns Jonas 4/12/2014

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michielber 0:f615d151a72c 1 /**
Michielber 0:f615d151a72c 2 * @file
Michielber 0:f615d151a72c 3 * SLIP Interface
Michielber 0:f615d151a72c 4 *
Michielber 0:f615d151a72c 5 */
Michielber 0:f615d151a72c 6
Michielber 0:f615d151a72c 7 /*
Michielber 0:f615d151a72c 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
Michielber 0:f615d151a72c 9 * All rights reserved.
Michielber 0:f615d151a72c 10 *
Michielber 0:f615d151a72c 11 * Redistribution and use in source and binary forms, with or without
Michielber 0:f615d151a72c 12 * modification, are permitted provided that the following conditions
Michielber 0:f615d151a72c 13 * are met:
Michielber 0:f615d151a72c 14 * 1. Redistributions of source code must retain the above copyright
Michielber 0:f615d151a72c 15 * notice, this list of conditions and the following disclaimer.
Michielber 0:f615d151a72c 16 * 2. Redistributions in binary form must reproduce the above copyright
Michielber 0:f615d151a72c 17 * notice, this list of conditions and the following disclaimer in the
Michielber 0:f615d151a72c 18 * documentation and/or other materials provided with the distribution.
Michielber 0:f615d151a72c 19 * 3. Neither the name of the Institute nor the names of its contributors
Michielber 0:f615d151a72c 20 * may be used to endorse or promote products derived from this software
Michielber 0:f615d151a72c 21 * without specific prior written permission.
Michielber 0:f615d151a72c 22 *
Michielber 0:f615d151a72c 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
Michielber 0:f615d151a72c 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Michielber 0:f615d151a72c 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Michielber 0:f615d151a72c 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
Michielber 0:f615d151a72c 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Michielber 0:f615d151a72c 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Michielber 0:f615d151a72c 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Michielber 0:f615d151a72c 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Michielber 0:f615d151a72c 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Michielber 0:f615d151a72c 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Michielber 0:f615d151a72c 33 * SUCH DAMAGE.
Michielber 0:f615d151a72c 34 *
Michielber 0:f615d151a72c 35 * This file is built upon the file: src/arch/rtxc/netif/sioslip.c
Michielber 0:f615d151a72c 36 *
Michielber 0:f615d151a72c 37 * Author: Magnus Ivarsson <magnus.ivarsson(at)volvo.com>
Michielber 0:f615d151a72c 38 */
Michielber 0:f615d151a72c 39
Michielber 0:f615d151a72c 40 /*
Michielber 0:f615d151a72c 41 * This is an arch independent SLIP netif. The specific serial hooks must be
Michielber 0:f615d151a72c 42 * provided by another file. They are sio_open, sio_read/sio_tryread and sio_send
Michielber 0:f615d151a72c 43 */
Michielber 0:f615d151a72c 44
Michielber 0:f615d151a72c 45 #include "netif/slipif.h"
Michielber 0:f615d151a72c 46 #include "lwip/opt.h"
Michielber 0:f615d151a72c 47
Michielber 0:f615d151a72c 48 #if LWIP_HAVE_SLIPIF
Michielber 0:f615d151a72c 49
Michielber 0:f615d151a72c 50 #include "lwip/def.h"
Michielber 0:f615d151a72c 51 #include "lwip/pbuf.h"
Michielber 0:f615d151a72c 52 #include "lwip/sys.h"
Michielber 0:f615d151a72c 53 #include "lwip/stats.h"
Michielber 0:f615d151a72c 54 #include "lwip/snmp.h"
Michielber 0:f615d151a72c 55 #include "lwip/sio.h"
Michielber 0:f615d151a72c 56
Michielber 0:f615d151a72c 57 #define SLIP_BLOCK 1
Michielber 0:f615d151a72c 58 #define SLIP_DONTBLOCK 0
Michielber 0:f615d151a72c 59
Michielber 0:f615d151a72c 60 #define SLIP_END 0300 /* 0xC0 */
Michielber 0:f615d151a72c 61 #define SLIP_ESC 0333 /* 0xDB */
Michielber 0:f615d151a72c 62 #define SLIP_ESC_END 0334 /* 0xDC */
Michielber 0:f615d151a72c 63 #define SLIP_ESC_ESC 0335 /* 0xDD */
Michielber 0:f615d151a72c 64
Michielber 0:f615d151a72c 65 #define SLIP_MAX_SIZE 1500
Michielber 0:f615d151a72c 66
Michielber 0:f615d151a72c 67 enum slipif_recv_state {
Michielber 0:f615d151a72c 68 SLIP_RECV_NORMAL,
Michielber 0:f615d151a72c 69 SLIP_RECV_ESCAPE,
Michielber 0:f615d151a72c 70 };
Michielber 0:f615d151a72c 71
Michielber 0:f615d151a72c 72 struct slipif_priv {
Michielber 0:f615d151a72c 73 sio_fd_t sd;
Michielber 0:f615d151a72c 74 /* q is the whole pbuf chain for a packet, p is the current pbuf in the chain */
Michielber 0:f615d151a72c 75 struct pbuf *p, *q;
Michielber 0:f615d151a72c 76 enum slipif_recv_state state;
Michielber 0:f615d151a72c 77 u16_t i, recved;
Michielber 0:f615d151a72c 78 };
Michielber 0:f615d151a72c 79
Michielber 0:f615d151a72c 80 /**
Michielber 0:f615d151a72c 81 * Send a pbuf doing the necessary SLIP encapsulation
Michielber 0:f615d151a72c 82 *
Michielber 0:f615d151a72c 83 * Uses the serial layer's sio_send()
Michielber 0:f615d151a72c 84 *
Michielber 0:f615d151a72c 85 * @param netif the lwip network interface structure for this slipif
Michielber 0:f615d151a72c 86 * @param p the pbuf chaing packet to send
Michielber 0:f615d151a72c 87 * @param ipaddr the ip address to send the packet to (not used for slipif)
Michielber 0:f615d151a72c 88 * @return always returns ERR_OK since the serial layer does not provide return values
Michielber 0:f615d151a72c 89 */
Michielber 0:f615d151a72c 90 err_t
Michielber 0:f615d151a72c 91 slipif_output(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
Michielber 0:f615d151a72c 92 {
Michielber 0:f615d151a72c 93 struct slipif_priv *priv;
Michielber 0:f615d151a72c 94 struct pbuf *q;
Michielber 0:f615d151a72c 95 u16_t i;
Michielber 0:f615d151a72c 96 u8_t c;
Michielber 0:f615d151a72c 97
Michielber 0:f615d151a72c 98 LWIP_ASSERT("netif != NULL", (netif != NULL));
Michielber 0:f615d151a72c 99 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
Michielber 0:f615d151a72c 100 LWIP_ASSERT("p != NULL", (p != NULL));
Michielber 0:f615d151a72c 101
Michielber 0:f615d151a72c 102 LWIP_UNUSED_ARG(ipaddr);
Michielber 0:f615d151a72c 103
Michielber 0:f615d151a72c 104 priv = netif->state;
Michielber 0:f615d151a72c 105
Michielber 0:f615d151a72c 106 /* Send pbuf out on the serial I/O device. */
Michielber 0:f615d151a72c 107 sio_send(SLIP_END, priv->sd);
Michielber 0:f615d151a72c 108
Michielber 0:f615d151a72c 109 for (q = p; q != NULL; q = q->next) {
Michielber 0:f615d151a72c 110 for (i = 0; i < q->len; i++) {
Michielber 0:f615d151a72c 111 c = ((u8_t *)q->payload)[i];
Michielber 0:f615d151a72c 112 switch (c) {
Michielber 0:f615d151a72c 113 case SLIP_END:
Michielber 0:f615d151a72c 114 sio_send(SLIP_ESC, priv->sd);
Michielber 0:f615d151a72c 115 sio_send(SLIP_ESC_END, priv->sd);
Michielber 0:f615d151a72c 116 break;
Michielber 0:f615d151a72c 117 case SLIP_ESC:
Michielber 0:f615d151a72c 118 sio_send(SLIP_ESC, priv->sd);
Michielber 0:f615d151a72c 119 sio_send(SLIP_ESC_ESC, priv->sd);
Michielber 0:f615d151a72c 120 break;
Michielber 0:f615d151a72c 121 default:
Michielber 0:f615d151a72c 122 sio_send(c, priv->sd);
Michielber 0:f615d151a72c 123 break;
Michielber 0:f615d151a72c 124 }
Michielber 0:f615d151a72c 125 }
Michielber 0:f615d151a72c 126 }
Michielber 0:f615d151a72c 127 sio_send(SLIP_END, priv->sd);
Michielber 0:f615d151a72c 128 return ERR_OK;
Michielber 0:f615d151a72c 129 }
Michielber 0:f615d151a72c 130
Michielber 0:f615d151a72c 131 /**
Michielber 0:f615d151a72c 132 * Static function for easy use of blockig or non-blocking
Michielber 0:f615d151a72c 133 * sio_read
Michielber 0:f615d151a72c 134 *
Michielber 0:f615d151a72c 135 * @param fd serial device handle
Michielber 0:f615d151a72c 136 * @param data pointer to data buffer for receiving
Michielber 0:f615d151a72c 137 * @param len maximum length (in bytes) of data to receive
Michielber 0:f615d151a72c 138 * @param block if 1, call sio_read; if 0, call sio_tryread
Michielber 0:f615d151a72c 139 * @return return value of sio_read of sio_tryread
Michielber 0:f615d151a72c 140 */
Michielber 0:f615d151a72c 141 static u32_t
Michielber 0:f615d151a72c 142 slip_sio_read(sio_fd_t fd, u8_t* data, u32_t len, u8_t block)
Michielber 0:f615d151a72c 143 {
Michielber 0:f615d151a72c 144 if (block) {
Michielber 0:f615d151a72c 145 return sio_read(fd, data, len);
Michielber 0:f615d151a72c 146 } else {
Michielber 0:f615d151a72c 147 return sio_tryread(fd, data, len);
Michielber 0:f615d151a72c 148 }
Michielber 0:f615d151a72c 149 }
Michielber 0:f615d151a72c 150
Michielber 0:f615d151a72c 151 /**
Michielber 0:f615d151a72c 152 * Handle the incoming SLIP stream character by character
Michielber 0:f615d151a72c 153 *
Michielber 0:f615d151a72c 154 * Poll the serial layer by calling sio_read() or sio_tryread().
Michielber 0:f615d151a72c 155 *
Michielber 0:f615d151a72c 156 * @param netif the lwip network interface structure for this slipif
Michielber 0:f615d151a72c 157 * @param block if 1, block until data is received; if 0, return when all data
Michielber 0:f615d151a72c 158 * from the buffer is received (multiple calls to this function will
Michielber 0:f615d151a72c 159 * return a complete packet, NULL is returned before - used for polling)
Michielber 0:f615d151a72c 160 * @return The IP packet when SLIP_END is received
Michielber 0:f615d151a72c 161 */
Michielber 0:f615d151a72c 162 static struct pbuf *
Michielber 0:f615d151a72c 163 slipif_input(struct netif *netif, u8_t block)
Michielber 0:f615d151a72c 164 {
Michielber 0:f615d151a72c 165 struct slipif_priv *priv;
Michielber 0:f615d151a72c 166 u8_t c;
Michielber 0:f615d151a72c 167 struct pbuf *t;
Michielber 0:f615d151a72c 168
Michielber 0:f615d151a72c 169 LWIP_ASSERT("netif != NULL", (netif != NULL));
Michielber 0:f615d151a72c 170 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
Michielber 0:f615d151a72c 171
Michielber 0:f615d151a72c 172 priv = netif->state;
Michielber 0:f615d151a72c 173
Michielber 0:f615d151a72c 174 while (slip_sio_read(priv->sd, &c, 1, block) > 0) {
Michielber 0:f615d151a72c 175 switch (priv->state) {
Michielber 0:f615d151a72c 176 case SLIP_RECV_NORMAL:
Michielber 0:f615d151a72c 177 switch (c) {
Michielber 0:f615d151a72c 178 case SLIP_END:
Michielber 0:f615d151a72c 179 if (priv->recved > 0) {
Michielber 0:f615d151a72c 180 /* Received whole packet. */
Michielber 0:f615d151a72c 181 /* Trim the pbuf to the size of the received packet. */
Michielber 0:f615d151a72c 182 pbuf_realloc(priv->q, priv->recved);
Michielber 0:f615d151a72c 183
Michielber 0:f615d151a72c 184 LINK_STATS_INC(link.recv);
Michielber 0:f615d151a72c 185
Michielber 0:f615d151a72c 186 LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
Michielber 0:f615d151a72c 187 t = priv->q;
Michielber 0:f615d151a72c 188 priv->p = priv->q = NULL;
Michielber 0:f615d151a72c 189 priv->i = priv->recved = 0;
Michielber 0:f615d151a72c 190 return t;
Michielber 0:f615d151a72c 191 }
Michielber 0:f615d151a72c 192 continue;
Michielber 0:f615d151a72c 193 case SLIP_ESC:
Michielber 0:f615d151a72c 194 priv->state = SLIP_RECV_ESCAPE;
Michielber 0:f615d151a72c 195 continue;
Michielber 0:f615d151a72c 196 }
Michielber 0:f615d151a72c 197 break;
Michielber 0:f615d151a72c 198 case SLIP_RECV_ESCAPE:
Michielber 0:f615d151a72c 199 switch (c) {
Michielber 0:f615d151a72c 200 case SLIP_ESC_END:
Michielber 0:f615d151a72c 201 c = SLIP_END;
Michielber 0:f615d151a72c 202 break;
Michielber 0:f615d151a72c 203 case SLIP_ESC_ESC:
Michielber 0:f615d151a72c 204 c = SLIP_ESC;
Michielber 0:f615d151a72c 205 break;
Michielber 0:f615d151a72c 206 }
Michielber 0:f615d151a72c 207 priv->state = SLIP_RECV_NORMAL;
Michielber 0:f615d151a72c 208 /* FALLTHROUGH */
Michielber 0:f615d151a72c 209 }
Michielber 0:f615d151a72c 210
Michielber 0:f615d151a72c 211 /* byte received, packet not yet completely received */
Michielber 0:f615d151a72c 212 if (priv->p == NULL) {
Michielber 0:f615d151a72c 213 /* allocate a new pbuf */
Michielber 0:f615d151a72c 214 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
Michielber 0:f615d151a72c 215 priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN), PBUF_POOL);
Michielber 0:f615d151a72c 216
Michielber 0:f615d151a72c 217 if (priv->p == NULL) {
Michielber 0:f615d151a72c 218 LINK_STATS_INC(link.drop);
Michielber 0:f615d151a72c 219 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
Michielber 0:f615d151a72c 220 /* don't process any further since we got no pbuf to receive to */
Michielber 0:f615d151a72c 221 break;
Michielber 0:f615d151a72c 222 }
Michielber 0:f615d151a72c 223
Michielber 0:f615d151a72c 224 if (priv->q != NULL) {
Michielber 0:f615d151a72c 225 /* 'chain' the pbuf to the existing chain */
Michielber 0:f615d151a72c 226 pbuf_cat(priv->q, priv->p);
Michielber 0:f615d151a72c 227 } else {
Michielber 0:f615d151a72c 228 /* p is the first pbuf in the chain */
Michielber 0:f615d151a72c 229 priv->q = priv->p;
Michielber 0:f615d151a72c 230 }
Michielber 0:f615d151a72c 231 }
Michielber 0:f615d151a72c 232
Michielber 0:f615d151a72c 233 /* this automatically drops bytes if > SLIP_MAX_SIZE */
Michielber 0:f615d151a72c 234 if ((priv->p != NULL) && (priv->recved <= SLIP_MAX_SIZE)) {
Michielber 0:f615d151a72c 235 ((u8_t *)priv->p->payload)[priv->i] = c;
Michielber 0:f615d151a72c 236 priv->recved++;
Michielber 0:f615d151a72c 237 priv->i++;
Michielber 0:f615d151a72c 238 if (priv->i >= priv->p->len) {
Michielber 0:f615d151a72c 239 /* on to the next pbuf */
Michielber 0:f615d151a72c 240 priv->i = 0;
Michielber 0:f615d151a72c 241 if (priv->p->next != NULL && priv->p->next->len > 0) {
Michielber 0:f615d151a72c 242 /* p is a chain, on to the next in the chain */
Michielber 0:f615d151a72c 243 priv->p = priv->p->next;
Michielber 0:f615d151a72c 244 } else {
Michielber 0:f615d151a72c 245 /* p is a single pbuf, set it to NULL so next time a new
Michielber 0:f615d151a72c 246 * pbuf is allocated */
Michielber 0:f615d151a72c 247 priv->p = NULL;
Michielber 0:f615d151a72c 248 }
Michielber 0:f615d151a72c 249 }
Michielber 0:f615d151a72c 250 }
Michielber 0:f615d151a72c 251 }
Michielber 0:f615d151a72c 252
Michielber 0:f615d151a72c 253 return NULL;
Michielber 0:f615d151a72c 254 }
Michielber 0:f615d151a72c 255
Michielber 0:f615d151a72c 256 #if !NO_SYS
Michielber 0:f615d151a72c 257 /**
Michielber 0:f615d151a72c 258 * The SLIP input thread.
Michielber 0:f615d151a72c 259 *
Michielber 0:f615d151a72c 260 * Feed the IP layer with incoming packets
Michielber 0:f615d151a72c 261 *
Michielber 0:f615d151a72c 262 * @param nf the lwip network interface structure for this slipif
Michielber 0:f615d151a72c 263 */
Michielber 0:f615d151a72c 264 static void
Michielber 0:f615d151a72c 265 slipif_loop_thread(void *nf)
Michielber 0:f615d151a72c 266 {
Michielber 0:f615d151a72c 267 struct pbuf *p;
Michielber 0:f615d151a72c 268 struct netif *netif = (struct netif *)nf;
Michielber 0:f615d151a72c 269
Michielber 0:f615d151a72c 270 while (1) {
Michielber 0:f615d151a72c 271 p = slipif_input(netif, SLIP_BLOCK);
Michielber 0:f615d151a72c 272 if (p != NULL) {
Michielber 0:f615d151a72c 273 if (netif->input(p, netif) != ERR_OK) {
Michielber 0:f615d151a72c 274 pbuf_free(p);
Michielber 0:f615d151a72c 275 p = NULL;
Michielber 0:f615d151a72c 276 }
Michielber 0:f615d151a72c 277 }
Michielber 0:f615d151a72c 278 }
Michielber 0:f615d151a72c 279 }
Michielber 0:f615d151a72c 280 #endif /* !NO_SYS */
Michielber 0:f615d151a72c 281
Michielber 0:f615d151a72c 282 /**
Michielber 0:f615d151a72c 283 * SLIP netif initialization
Michielber 0:f615d151a72c 284 *
Michielber 0:f615d151a72c 285 * Call the arch specific sio_open and remember
Michielber 0:f615d151a72c 286 * the opened device in the state field of the netif.
Michielber 0:f615d151a72c 287 *
Michielber 0:f615d151a72c 288 * @param netif the lwip network interface structure for this slipif
Michielber 0:f615d151a72c 289 * @return ERR_OK if serial line could be opened,
Michielber 0:f615d151a72c 290 * ERR_MEM if no memory could be allocated,
Michielber 0:f615d151a72c 291 * ERR_IF is serial line couldn't be opened
Michielber 0:f615d151a72c 292 *
Michielber 0:f615d151a72c 293 * @note netif->num must contain the number of the serial port to open
Michielber 0:f615d151a72c 294 * (0 by default)
Michielber 0:f615d151a72c 295 */
Michielber 0:f615d151a72c 296 err_t
Michielber 0:f615d151a72c 297 slipif_init(struct netif *netif)
Michielber 0:f615d151a72c 298 {
Michielber 0:f615d151a72c 299 struct slipif_priv *priv;
Michielber 0:f615d151a72c 300
Michielber 0:f615d151a72c 301 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));
Michielber 0:f615d151a72c 302
Michielber 0:f615d151a72c 303 /* Allocate private data */
Michielber 0:f615d151a72c 304 priv = mem_malloc(sizeof(struct slipif_priv));
Michielber 0:f615d151a72c 305 if (!priv) {
Michielber 0:f615d151a72c 306 return ERR_MEM;
Michielber 0:f615d151a72c 307 }
Michielber 0:f615d151a72c 308
Michielber 0:f615d151a72c 309 netif->name[0] = 's';
Michielber 0:f615d151a72c 310 netif->name[1] = 'l';
Michielber 0:f615d151a72c 311 netif->output = slipif_output;
Michielber 0:f615d151a72c 312 netif->mtu = SLIP_MAX_SIZE;
Michielber 0:f615d151a72c 313 netif->flags |= NETIF_FLAG_POINTTOPOINT;
Michielber 0:f615d151a72c 314
Michielber 0:f615d151a72c 315 /* Try to open the serial port (netif->num contains the port number). */
Michielber 0:f615d151a72c 316 priv->sd = sio_open(netif->num);
Michielber 0:f615d151a72c 317 if (!priv->sd) {
Michielber 0:f615d151a72c 318 /* Opening the serial port failed. */
Michielber 0:f615d151a72c 319 mem_free(priv);
Michielber 0:f615d151a72c 320 return ERR_IF;
Michielber 0:f615d151a72c 321 }
Michielber 0:f615d151a72c 322
Michielber 0:f615d151a72c 323 /* Initialize private data */
Michielber 0:f615d151a72c 324 priv->p = NULL;
Michielber 0:f615d151a72c 325 priv->q = NULL;
Michielber 0:f615d151a72c 326 priv->state = SLIP_RECV_NORMAL;
Michielber 0:f615d151a72c 327 priv->i = 0;
Michielber 0:f615d151a72c 328 priv->recved = 0;
Michielber 0:f615d151a72c 329
Michielber 0:f615d151a72c 330 netif->state = priv;
Michielber 0:f615d151a72c 331
Michielber 0:f615d151a72c 332 /* initialize the snmp variables and counters inside the struct netif
Michielber 0:f615d151a72c 333 * ifSpeed: no assumption can be made without knowing more about the
Michielber 0:f615d151a72c 334 * serial line!
Michielber 0:f615d151a72c 335 */
Michielber 0:f615d151a72c 336 NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);
Michielber 0:f615d151a72c 337
Michielber 0:f615d151a72c 338 /* Create a thread to poll the serial line. */
Michielber 0:f615d151a72c 339 sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
Michielber 0:f615d151a72c 340 SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
Michielber 0:f615d151a72c 341 return ERR_OK;
Michielber 0:f615d151a72c 342 }
Michielber 0:f615d151a72c 343
Michielber 0:f615d151a72c 344 /**
Michielber 0:f615d151a72c 345 * Polls the serial device and feeds the IP layer with incoming packets.
Michielber 0:f615d151a72c 346 *
Michielber 0:f615d151a72c 347 * @param netif The lwip network interface structure for this slipif
Michielber 0:f615d151a72c 348 */
Michielber 0:f615d151a72c 349 void
Michielber 0:f615d151a72c 350 slipif_poll(struct netif *netif)
Michielber 0:f615d151a72c 351 {
Michielber 0:f615d151a72c 352 struct pbuf *p;
Michielber 0:f615d151a72c 353 struct slipif_priv *priv;
Michielber 0:f615d151a72c 354
Michielber 0:f615d151a72c 355 LWIP_ASSERT("netif != NULL", (netif != NULL));
Michielber 0:f615d151a72c 356 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
Michielber 0:f615d151a72c 357
Michielber 0:f615d151a72c 358 priv = netif->state;
Michielber 0:f615d151a72c 359
Michielber 0:f615d151a72c 360 while ((p = slipif_input(netif, SLIP_DONTBLOCK)) != NULL) {
Michielber 0:f615d151a72c 361 if (netif->input(p, netif) != ERR_OK) {
Michielber 0:f615d151a72c 362 pbuf_free(p);
Michielber 0:f615d151a72c 363 }
Michielber 0:f615d151a72c 364 }
Michielber 0:f615d151a72c 365 }
Michielber 0:f615d151a72c 366
Michielber 0:f615d151a72c 367 #endif /* LWIP_HAVE_SLIPIF */