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
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
Diff: stack/pico_frame.c
- Revision:
- 149:5f4cb161cec3
- Parent:
- 137:a1c8bfa9d691
- Child:
- 152:a3d286bf94e5
--- a/stack/pico_frame.c Tue Mar 11 15:34:51 2014 +0100 +++ b/stack/pico_frame.c Wed Apr 09 14:31:41 2014 +0200 @@ -18,16 +18,19 @@ /** frame alloc/dealloc/copy **/ void pico_frame_discard(struct pico_frame *f) { + if (!f) + return; + (*f->usage_count)--; if (*f->usage_count <= 0) { - pico_free(f->usage_count); + PICO_FREE(f->usage_count); #ifdef PICO_SUPPORT_DEBUG_MEMORY dbg("Discarded buffer @%p, caller: %p\n", f->buffer, __builtin_return_address(3)); dbg("DEBUG MEMORY: %d frames in use.\n", --n_frames_allocated); #endif - pico_free(f->buffer); + PICO_FREE(f->buffer); if (f->info) - pico_free(f->info); + PICO_FREE(f->info); } #ifdef PICO_SUPPORT_DEBUG_MEMORY @@ -35,12 +38,12 @@ dbg("Removed frame @%p(copy), usage count now: %d\n", f, *f->usage_count); } #endif - pico_free(f); + PICO_FREE(f); } struct pico_frame *pico_frame_copy(struct pico_frame *f) { - struct pico_frame *new = pico_zalloc(sizeof(struct pico_frame)); + struct pico_frame *new = PICO_ZALLOC(sizeof(struct pico_frame)); if (!new) return NULL; @@ -54,22 +57,28 @@ } -struct pico_frame *pico_frame_alloc(uint32_t size) +static struct pico_frame *pico_frame_do_alloc(uint32_t size, int zerocopy) { - struct pico_frame *p = pico_zalloc(sizeof(struct pico_frame)); + struct pico_frame *p = PICO_ZALLOC(sizeof(struct pico_frame)); if (!p) return NULL; - p->buffer = pico_zalloc(size); - if (!p->buffer) { - pico_free(p); - return NULL; + if (!zerocopy) { + p->buffer = PICO_ZALLOC(size); + if (!p->buffer) { + PICO_FREE(p); + return NULL; + } + } else { + p->buffer = NULL; } - p->usage_count = pico_zalloc(sizeof(uint32_t)); + p->usage_count = PICO_ZALLOC(sizeof(uint32_t)); if (!p->usage_count) { - pico_free(p->buffer); - pico_free(p); + if (p->buffer) + PICO_FREE(p->buffer); + + PICO_FREE(p); return NULL; } @@ -87,6 +96,26 @@ return p; } +struct pico_frame *pico_frame_alloc(uint32_t size) +{ + return pico_frame_do_alloc(size, 0); +} + +struct pico_frame *pico_frame_alloc_skeleton(uint32_t size) +{ + return pico_frame_do_alloc(size, 1); +} + +int pico_frame_skeleton_set_buffer(struct pico_frame *f, void *buf) +{ + if (!buf) + return -1; + + f->buffer = (uint8_t *) buf; + f->start = f->buffer; + return 0; +} + struct pico_frame *pico_frame_deepcopy(struct pico_frame *f) { struct pico_frame *new = pico_frame_alloc(f->buffer_len); @@ -132,13 +161,11 @@ uint32_t sum = 0; uint32_t i = 0; - for(i = 0; i < len; i++) { - if (i % 2) { - sum += buf[i]; - } else { - tmp = buf[i]; - sum += (tmp << 8); - } + for(i = 0; i < len; i += 2u) { + tmp = buf[i]; + sum += (tmp << 8lu); + if (len > (i + 1)) + sum += buf[i + 1]; } while (sum >> 16) { /* a second carry is possible! */ sum = (sum & 0x0000FFFF) + (sum >> 16); @@ -150,30 +177,21 @@ { uint8_t *b1 = (uint8_t *) inbuf1; uint8_t *b2 = (uint8_t *) inbuf2; - uint16_t tmp = 0; + uint32_t tmp = 0; uint32_t sum = 0; - uint32_t i = 0, j = 0; - - for(i = 0; i < len1; i++) { - if (j % 2) { - sum += b1[i]; - } else { - tmp = b1[i]; - sum = sum + (uint32_t)(tmp << 8); - } + uint32_t i = 0; - j++; + for(i = 0; i < len1; i += 2u) { + tmp = b1[i]; + sum += (tmp << 8lu); + if (len1 > (i + 1)) + sum += b1[i + 1]; } - j = 0; /* j has to be reset if len1 is odd */ - for(i = 0; i < len2; i++) { - if (j % 2) { - sum += b2[i]; - } else { - tmp = b2[i]; - sum = sum + (uint32_t)(tmp << 8); - } - - j++; + for(i = 0; i < len2; i += 2u) { + tmp = b2[i]; + sum += (tmp << 8lu); + if (len2 > (i + 1)) + sum += b2[i + 1]; } while (sum >> 16) { /* a second carry is possible! */ sum = (sum & 0x0000FFFF) + (sum >> 16);