Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PicoTCP by
pico_dev_loop.c
00001 /********************************************************************* 00002 PicoTCP. Copyright (c) 2012 TASS Belgium NV. 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 if (len > LOOP_MTU) 00022 return 0; 00023 00024 if (l_bufsize == 0) { 00025 memcpy(l_buf, buf, len); 00026 l_bufsize+=len; 00027 return len; 00028 } 00029 return 0; 00030 } 00031 00032 static int pico_loop_poll(struct pico_device *dev, int loop_score) 00033 { 00034 if (loop_score <= 0) 00035 return 0; 00036 00037 if (l_bufsize > 0) { 00038 pico_stack_recv(dev, l_buf, l_bufsize); 00039 l_bufsize = 0; 00040 loop_score--; 00041 } 00042 return loop_score; 00043 } 00044 00045 /* Public interface: create/destroy. */ 00046 00047 void pico_loop_destroy(struct pico_device *dev) 00048 { 00049 } 00050 00051 struct pico_device *pico_loop_create(void) 00052 { 00053 struct pico_device *loop = pico_zalloc(sizeof(struct pico_device)); 00054 if (!loop) 00055 return NULL; 00056 00057 if( 0 != pico_device_init((struct pico_device *)loop, "loop", NULL)) { 00058 dbg ("Loop init failed.\n"); 00059 pico_loop_destroy((struct pico_device *)loop); 00060 return NULL; 00061 } 00062 loop->send = pico_loop_send; 00063 loop->poll = pico_loop_poll; 00064 loop->destroy = pico_loop_destroy; 00065 dbg("Device %s created.\n", loop->name); 00066 return (struct pico_device *)loop; 00067 } 00068
Generated on Thu Jul 14 2022 08:24:58 by
 1.7.2
 1.7.2 
    