Free (GPLv2) TCP/IP stack developed by TASS Belgium

Dependents:   lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pico_dev_loop.c Source File

pico_dev_loop.c

00001 /*********************************************************************
00002    PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
00003    See LICENSE and COPYING for usage.
00004 
00005    Authors: Daniele Lacamera
00006  *********************************************************************/
00007 
00008 
00009 #include "pico_device.h"
00010 #include "pico_dev_loop.h"
00011 #include "pico_stack.h"
00012 
00013 
00014 #define LOOP_MTU 1500
00015 static uint8_t l_buf[LOOP_MTU];
00016 static int l_bufsize = 0;
00017 
00018 
00019 static int pico_loop_send(struct pico_device *dev, void *buf, int len)
00020 {
00021     IGNORE_PARAMETER(dev);
00022     if (len > LOOP_MTU)
00023         return 0;
00024 
00025     if (l_bufsize == 0) {
00026         memcpy(l_buf, buf, (size_t)len);
00027         l_bufsize += len;
00028         return len;
00029     }
00030 
00031     return 0;
00032 }
00033 
00034 static int pico_loop_poll(struct pico_device *dev, int loop_score)
00035 {
00036     if (loop_score <= 0)
00037         return 0;
00038 
00039     if (l_bufsize > 0) {
00040         pico_stack_recv(dev, l_buf, (uint32_t)l_bufsize);
00041         l_bufsize = 0;
00042         loop_score--;
00043     }
00044 
00045     return loop_score;
00046 }
00047 
00048 
00049 struct pico_device *pico_loop_create(void)
00050 {
00051     struct pico_device *loop = PICO_ZALLOC(sizeof(struct pico_device));
00052     if (!loop)
00053         return NULL;
00054 
00055     if( 0 != pico_device_init(loop, "loop", NULL)) {
00056         dbg ("Loop init failed.\n");
00057         pico_device_destroy(loop);
00058         return NULL;
00059     }
00060 
00061     loop->send = pico_loop_send;
00062     loop->poll = pico_loop_poll;
00063     dbg("Device %s created.\n", loop->name);
00064     return loop;
00065 }
00066