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 RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling 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.

Committer:
tass
Date:
Thu Jan 28 15:12:00 2016 +0100
Revision:
155:a70f34550c34
Parent:
154:6c0e92a80c4a
Adding TCP flag for FIN.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 29:1a47b7151851 1 /*********************************************************************
tass 152:a3d286bf94e5 2 PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
tass 152:a3d286bf94e5 3 See LICENSE and COPYING for usage.
daniele 29:1a47b7151851 4
tass 152:a3d286bf94e5 5 *********************************************************************/
tass 152:a3d286bf94e5 6 #include "pico_defines.h"
tass picotcp@tass.be 149:5f4cb161cec3 7 #ifndef INCLUDE_PICO_CONFIG
tass picotcp@tass.be 149:5f4cb161cec3 8 #define INCLUDE_PICO_CONFIG
tass 152:a3d286bf94e5 9 #ifndef __KERNEL__
daniele 29:1a47b7151851 10 #include <stdint.h>
daniele 29:1a47b7151851 11 #include <stdlib.h>
daniele 29:1a47b7151851 12 #include <string.h>
tass 152:a3d286bf94e5 13 #else
tass 152:a3d286bf94e5 14 #include <linux/types.h>
tass 152:a3d286bf94e5 15 #endif
tass picotcp@tass.be 149:5f4cb161cec3 16
tass 152:a3d286bf94e5 17 #if defined __IAR_SYSTEMS_ICC__ || defined ATOP
tass picotcp@tass.be 149:5f4cb161cec3 18 # define PACKED_STRUCT_DEF __packed struct
tass 152:a3d286bf94e5 19 # define PEDANTIC_STRUCT_DEF __packed struct
tass 152:a3d286bf94e5 20 # define PACKED_UNION_DEF __packed union
tass 152:a3d286bf94e5 21 # define WEAK
tass 154:6c0e92a80c4a 22 #elif defined __WATCOMC__
tass 154:6c0e92a80c4a 23 # define PACKED_STRUCT_DEF _Packed struct
tass 154:6c0e92a80c4a 24 # define PEDANTIC_STRUCT_DEF struct
tass 154:6c0e92a80c4a 25 # define PACKED_UNION_DEF _Packed union
tass 154:6c0e92a80c4a 26 # define WEAK
tass picotcp@tass.be 149:5f4cb161cec3 27 #else
tass picotcp@tass.be 149:5f4cb161cec3 28 # define PACKED_STRUCT_DEF struct __attribute__((packed))
tass 152:a3d286bf94e5 29 # define PEDANTIC_STRUCT_DEF struct
tass 152:a3d286bf94e5 30 # define PACKED_UNION_DEF union /* Sane compilers do not require packed unions */
tass 152:a3d286bf94e5 31 # define WEAK __attribute__((weak))
tass 152:a3d286bf94e5 32 # ifdef __GNUC__
tass 152:a3d286bf94e5 33 # define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
tass 152:a3d286bf94e5 34 # if ((GCC_VERSION >= 40800))
tass 152:a3d286bf94e5 35 # define BYTESWAP_GCC
tass 152:a3d286bf94e5 36 # endif
tass 152:a3d286bf94e5 37 # endif
tass 152:a3d286bf94e5 38 #endif
tass 152:a3d286bf94e5 39
tass 152:a3d286bf94e5 40 #ifdef PICO_BIGENDIAN
tass 152:a3d286bf94e5 41
tass 152:a3d286bf94e5 42 # define PICO_IDETH_IPV4 0x0800
tass 152:a3d286bf94e5 43 # define PICO_IDETH_ARP 0x0806
tass 152:a3d286bf94e5 44 # define PICO_IDETH_IPV6 0x86DD
tass 152:a3d286bf94e5 45
tass 152:a3d286bf94e5 46 # define PICO_ARP_REQUEST 0x0001
tass 152:a3d286bf94e5 47 # define PICO_ARP_REPLY 0x0002
tass 152:a3d286bf94e5 48 # define PICO_ARP_HTYPE_ETH 0x0001
tass 152:a3d286bf94e5 49
tass 152:a3d286bf94e5 50 #define short_be(x) (x)
tass 152:a3d286bf94e5 51 #define long_be(x) (x)
tass 152:a3d286bf94e5 52 #define long_long_be(x) (x)
tass 152:a3d286bf94e5 53
tass 152:a3d286bf94e5 54 static inline uint16_t short_from(void *_p)
tass 152:a3d286bf94e5 55 {
tass 152:a3d286bf94e5 56 unsigned char *p = (unsigned char *)_p;
tass 152:a3d286bf94e5 57 uint16_t r, p0, p1;
tass 152:a3d286bf94e5 58 p0 = p[0];
tass 152:a3d286bf94e5 59 p1 = p[1];
tass 152:a3d286bf94e5 60 r = (p0 << 8) + p1;
tass 152:a3d286bf94e5 61 return r;
tass 152:a3d286bf94e5 62 }
tass 152:a3d286bf94e5 63
tass 152:a3d286bf94e5 64 static inline uint32_t long_from(void *_p)
tass 152:a3d286bf94e5 65 {
tass 152:a3d286bf94e5 66 unsigned char *p = (unsigned char *)_p;
tass 152:a3d286bf94e5 67 uint32_t r, p0, p1, p2, p3;
tass 152:a3d286bf94e5 68 p0 = p[0];
tass 152:a3d286bf94e5 69 p1 = p[1];
tass 152:a3d286bf94e5 70 p2 = p[2];
tass 152:a3d286bf94e5 71 p3 = p[3];
tass 152:a3d286bf94e5 72 r = (p0 << 24) + (p1 << 16) + (p2 << 8) + p3;
tass 152:a3d286bf94e5 73 return r;
tass 152:a3d286bf94e5 74 }
tass 152:a3d286bf94e5 75
tass 152:a3d286bf94e5 76 #else
tass 152:a3d286bf94e5 77
tass 152:a3d286bf94e5 78 static inline uint16_t short_from(void *_p)
tass 152:a3d286bf94e5 79 {
tass 152:a3d286bf94e5 80 unsigned char *p = (unsigned char *)_p;
tass 152:a3d286bf94e5 81 uint16_t r, _p0, _p1;
tass 152:a3d286bf94e5 82 _p0 = p[0];
tass 152:a3d286bf94e5 83 _p1 = p[1];
tass 152:a3d286bf94e5 84 r = (uint16_t)((_p1 << 8u) + _p0);
tass 152:a3d286bf94e5 85 return r;
tass 152:a3d286bf94e5 86 }
tass 152:a3d286bf94e5 87
tass 152:a3d286bf94e5 88 static inline uint32_t long_from(void *_p)
tass 152:a3d286bf94e5 89 {
tass 152:a3d286bf94e5 90 unsigned char *p = (unsigned char *)_p;
tass 152:a3d286bf94e5 91 uint32_t r, _p0, _p1, _p2, _p3;
tass 152:a3d286bf94e5 92 _p0 = p[0];
tass 152:a3d286bf94e5 93 _p1 = p[1];
tass 152:a3d286bf94e5 94 _p2 = p[2];
tass 152:a3d286bf94e5 95 _p3 = p[3];
tass 152:a3d286bf94e5 96 r = (_p3 << 24) + (_p2 << 16) + (_p1 << 8) + _p0;
tass 152:a3d286bf94e5 97 return r;
tass 152:a3d286bf94e5 98 }
tass 152:a3d286bf94e5 99
tass 152:a3d286bf94e5 100
tass 152:a3d286bf94e5 101 # define PICO_IDETH_IPV4 0x0008
tass 152:a3d286bf94e5 102 # define PICO_IDETH_ARP 0x0608
tass 152:a3d286bf94e5 103 # define PICO_IDETH_IPV6 0xDD86
tass 152:a3d286bf94e5 104
tass 152:a3d286bf94e5 105 # define PICO_ARP_REQUEST 0x0100
tass 152:a3d286bf94e5 106 # define PICO_ARP_REPLY 0x0200
tass 152:a3d286bf94e5 107 # define PICO_ARP_HTYPE_ETH 0x0100
tass 152:a3d286bf94e5 108
tass 152:a3d286bf94e5 109 # ifndef BYTESWAP_GCC
tass 152:a3d286bf94e5 110 static inline uint16_t short_be(uint16_t le)
tass 152:a3d286bf94e5 111 {
tass 152:a3d286bf94e5 112 return (uint16_t)(((le & 0xFFu) << 8) | ((le >> 8u) & 0xFFu));
tass 152:a3d286bf94e5 113 }
tass 152:a3d286bf94e5 114
tass 152:a3d286bf94e5 115 static inline uint32_t long_be(uint32_t le)
tass 152:a3d286bf94e5 116 {
tass 152:a3d286bf94e5 117 uint8_t *b = (uint8_t *)&le;
tass 152:a3d286bf94e5 118 uint32_t be = 0;
tass 152:a3d286bf94e5 119 uint32_t b0, b1, b2;
tass 152:a3d286bf94e5 120 b0 = b[0];
tass 152:a3d286bf94e5 121 b1 = b[1];
tass 152:a3d286bf94e5 122 b2 = b[2];
tass 152:a3d286bf94e5 123 be = b[3] + (b2 << 8) + (b1 << 16) + (b0 << 24);
tass 152:a3d286bf94e5 124 return be;
tass 152:a3d286bf94e5 125 }
tass 152:a3d286bf94e5 126 static inline uint64_t long_long_be(uint64_t le)
tass 152:a3d286bf94e5 127 {
tass 152:a3d286bf94e5 128 uint8_t *b = (uint8_t *)&le;
tass 152:a3d286bf94e5 129 uint64_t be = 0;
tass 152:a3d286bf94e5 130 uint64_t b0, b1, b2, b3, b4, b5, b6;
tass 152:a3d286bf94e5 131 b0 = b[0];
tass 152:a3d286bf94e5 132 b1 = b[1];
tass 152:a3d286bf94e5 133 b2 = b[2];
tass 152:a3d286bf94e5 134 b3 = b[3];
tass 152:a3d286bf94e5 135 b4 = b[4];
tass 152:a3d286bf94e5 136 b5 = b[5];
tass 152:a3d286bf94e5 137 b6 = b[6];
tass 152:a3d286bf94e5 138 be = b[7] + (b6 << 8) + (b5 << 16) + (b4 << 24) + (b3 << 32) + (b2 << 40) + (b1 << 48) + (b0 << 56);
tass 152:a3d286bf94e5 139 return be;
tass 152:a3d286bf94e5 140 }
tass 152:a3d286bf94e5 141 # else
tass 152:a3d286bf94e5 142 /*
tass 152:a3d286bf94e5 143 extern uint32_t __builtin_bswap32(uint32_t);
tass 152:a3d286bf94e5 144 extern uint16_t __builtin_bswap16(uint16_t);
tass 152:a3d286bf94e5 145 extern uint64_t __builtin_bswap64(uint64_t);
tass 152:a3d286bf94e5 146 */
tass 152:a3d286bf94e5 147
tass 152:a3d286bf94e5 148 static inline uint32_t long_be(uint32_t le)
tass 152:a3d286bf94e5 149 {
tass 152:a3d286bf94e5 150 return (uint32_t)__builtin_bswap32(le);
tass 152:a3d286bf94e5 151 }
tass 152:a3d286bf94e5 152
tass 152:a3d286bf94e5 153 static inline uint16_t short_be(uint16_t le)
tass 152:a3d286bf94e5 154 {
tass 152:a3d286bf94e5 155 return (uint16_t)__builtin_bswap16(le);
tass 152:a3d286bf94e5 156 }
tass 152:a3d286bf94e5 157
tass 152:a3d286bf94e5 158 static inline uint64_t long_long_be(uint64_t le)
tass 152:a3d286bf94e5 159 {
tass 152:a3d286bf94e5 160 return (uint64_t)__builtin_bswap64(le);
tass 152:a3d286bf94e5 161 }
tass 152:a3d286bf94e5 162
tass 152:a3d286bf94e5 163 # endif /* BYTESWAP_GCC */
tass 152:a3d286bf94e5 164 #endif
tass 152:a3d286bf94e5 165
tass 152:a3d286bf94e5 166
tass 152:a3d286bf94e5 167 /* Mockables */
tass 152:a3d286bf94e5 168 #if defined UNIT_TEST
tass 152:a3d286bf94e5 169 # define MOCKABLE __attribute__((weak))
tass 152:a3d286bf94e5 170 #else
tass 152:a3d286bf94e5 171 # define MOCKABLE
tass picotcp@tass.be 149:5f4cb161cec3 172 #endif
tass picotcp@tass.be 149:5f4cb161cec3 173
daniele 29:1a47b7151851 174 #include "pico_constants.h"
tass 152:a3d286bf94e5 175 #include "pico_mm.h"
daniele 29:1a47b7151851 176
tass 152:a3d286bf94e5 177 #define IGNORE_PARAMETER(x) ((void)x)
tass 152:a3d286bf94e5 178
tass 152:a3d286bf94e5 179 #define PICO_MEM_DEFAULT_SLAB_SIZE 1600
tass 152:a3d286bf94e5 180 #define PICO_MEM_PAGE_SIZE 4096
tass 152:a3d286bf94e5 181 #define PICO_MEM_PAGE_LIFETIME 100
tass 152:a3d286bf94e5 182 #define PICO_MIN_HEAP_SIZE 600
tass 152:a3d286bf94e5 183 #define PICO_MIN_SLAB_SIZE 1200
tass 152:a3d286bf94e5 184 #define PICO_MAX_SLAB_SIZE 1600
tass 152:a3d286bf94e5 185 #define PICO_MEM_MINIMUM_OBJECT_SIZE 4
tass 152:a3d286bf94e5 186
tass picotcp@tass.be 149:5f4cb161cec3 187
tass 152:a3d286bf94e5 188 /*** *** *** *** *** *** ***
tass 152:a3d286bf94e5 189 *** PLATFORM SPECIFIC ***
tass 152:a3d286bf94e5 190 *** *** *** *** *** *** ***/
tass 152:a3d286bf94e5 191 #if defined PICO_PORT_CUSTOM
tass 152:a3d286bf94e5 192 # include "pico_port.h"
tass 152:a3d286bf94e5 193 #elif defined CORTEX_M4_HARDFLOAT
tass 152:a3d286bf94e5 194 # include "arch/pico_cortex_m.h"
tass 152:a3d286bf94e5 195 #elif defined CORTEX_M4_SOFTFLOAT
tass 152:a3d286bf94e5 196 # include "arch/pico_cortex_m.h"
tass 152:a3d286bf94e5 197 #elif defined CORTEX_M3
tass 152:a3d286bf94e5 198 # include "arch/pico_cortex_m.h"
tass 152:a3d286bf94e5 199 #elif defined PIC24
tass 152:a3d286bf94e5 200 # include "arch/pico_pic24.h"
tass 152:a3d286bf94e5 201 #elif defined MSP430
tass 152:a3d286bf94e5 202 # include "arch/pico_msp430.h"
tass 152:a3d286bf94e5 203 #elif defined MBED_TEST
daniele 29:1a47b7151851 204 # include "arch/pico_mbed.h"
tass 152:a3d286bf94e5 205 #elif defined AVR
tass 152:a3d286bf94e5 206 # include "arch/pico_avr.h"
tass 152:a3d286bf94e5 207 #elif defined ARM9
tass 152:a3d286bf94e5 208 # include "arch/pico_arm9.h"
tass 152:a3d286bf94e5 209 #elif defined ESP8266
tass 152:a3d286bf94e5 210 # include "arch/pico_esp8266.h"
tass 152:a3d286bf94e5 211 #elif defined MT7681
tass 152:a3d286bf94e5 212 # include "arch/pico_generic_gcc.h"
tass 152:a3d286bf94e5 213 #elif defined FAULTY
tass 152:a3d286bf94e5 214 # include "../test/pico_faulty.h"
tass 152:a3d286bf94e5 215 #elif defined ARCHNONE
tass 152:a3d286bf94e5 216 # include "arch/pico_none.h"
tass 152:a3d286bf94e5 217 #elif defined GENERIC
tass 152:a3d286bf94e5 218 # include "arch/pico_generic_gcc.h"
tass 152:a3d286bf94e5 219 #elif defined __KERNEL__
tass 152:a3d286bf94e5 220 # include "arch/pico_linux.h"
tass 152:a3d286bf94e5 221 /* #elif defined ... */
tass 152:a3d286bf94e5 222 #else
tass 152:a3d286bf94e5 223 # include "arch/pico_posix.h"
tass 152:a3d286bf94e5 224 #endif
tass picotcp@tass.be 149:5f4cb161cec3 225
tass picotcp@tass.be 149:5f4cb161cec3 226 #ifdef PICO_SUPPORT_MM
tass picotcp@tass.be 149:5f4cb161cec3 227 #define PICO_ZALLOC(x) pico_mem_zalloc(x)
tass picotcp@tass.be 149:5f4cb161cec3 228 #define PICO_FREE(x) pico_mem_free(x)
tass picotcp@tass.be 149:5f4cb161cec3 229 #else
tass picotcp@tass.be 149:5f4cb161cec3 230 #define PICO_ZALLOC(x) pico_zalloc(x)
tass picotcp@tass.be 149:5f4cb161cec3 231 #define PICO_FREE(x) pico_free(x)
tass picotcp@tass.be 149:5f4cb161cec3 232 #endif /* PICO_SUPPORT_MM */
tass picotcp@tass.be 149:5f4cb161cec3 233
tass 152:a3d286bf94e5 234 #endif