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:
152:a3d286bf94e5
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 Belgium NV 131:4758606c9316 3 See LICENSE and COPYING for usage.
daniele 29:1a47b7151851 4
TASS Belgium NV 131:4758606c9316 5 *********************************************************************/
tass picotcp@tass.be 149:5f4cb161cec3 6 #ifndef INCLUDE_PICO_QUEUE
tass picotcp@tass.be 149:5f4cb161cec3 7 #define INCLUDE_PICO_QUEUE
daniele 29:1a47b7151851 8 #include "pico_config.h"
daniele 29:1a47b7151851 9 #include "pico_frame.h"
daniele 29:1a47b7151851 10
daniele 29:1a47b7151851 11 #define Q_LIMIT 0
daniele 29:1a47b7151851 12
daniele 29:1a47b7151851 13 #ifndef NULL
daniele 29:1a47b7151851 14 #define NULL ((void *)0)
daniele 29:1a47b7151851 15 #endif
daniele 29:1a47b7151851 16
tass 152:a3d286bf94e5 17 void *pico_mutex_init(void);
tass 152:a3d286bf94e5 18 void pico_mutex_deinit(void *mutex);
tass 152:a3d286bf94e5 19 void pico_mutex_lock(void *mutex);
tass 152:a3d286bf94e5 20 int pico_mutex_lock_timeout(void *mutex, int timeout);
tass 152:a3d286bf94e5 21 void pico_mutex_unlock(void *mutex);
tass 152:a3d286bf94e5 22 void pico_mutex_unlock_ISR(void *mutex);
tass 152:a3d286bf94e5 23
daniele 29:1a47b7151851 24 struct pico_queue {
TASS Belgium NV 131:4758606c9316 25 uint32_t frames;
TASS Belgium NV 131:4758606c9316 26 uint32_t size;
TASS Belgium NV 131:4758606c9316 27 uint32_t max_frames;
TASS Belgium NV 131:4758606c9316 28 uint32_t max_size;
TASS Belgium NV 131:4758606c9316 29 struct pico_frame *head;
TASS Belgium NV 131:4758606c9316 30 struct pico_frame *tail;
daniele 29:1a47b7151851 31 #ifdef PICO_SUPPORT_MUTEX
TASS Belgium NV 131:4758606c9316 32 void *mutex;
daniele 29:1a47b7151851 33 #endif
TASS Belgium NV 131:4758606c9316 34 uint8_t shared;
TASS Belgium NV 131:4758606c9316 35 uint16_t overhead;
daniele 29:1a47b7151851 36 };
daniele 29:1a47b7151851 37
daniele 29:1a47b7151851 38 #ifdef PICO_SUPPORT_MUTEX
tass picotcp@tass.be 149:5f4cb161cec3 39 #define PICOTCP_MUTEX_LOCK(x) { \
TASS Belgium NV 131:4758606c9316 40 if (x == NULL) \
TASS Belgium NV 131:4758606c9316 41 x = pico_mutex_init(); \
TASS Belgium NV 131:4758606c9316 42 pico_mutex_lock(x); \
daniele 29:1a47b7151851 43 }
tass picotcp@tass.be 149:5f4cb161cec3 44 #define PICOTCP_MUTEX_UNLOCK(x) pico_mutex_unlock(x)
tass 152:a3d286bf94e5 45 #define PICOTCP_MUTEX_DEL(x) pico_mutex_deinit(x)
daniele 29:1a47b7151851 46
TASS Belgium NV 131:4758606c9316 47 #else
tass picotcp@tass.be 149:5f4cb161cec3 48 #define PICOTCP_MUTEX_LOCK(x) do {} while(0)
tass picotcp@tass.be 149:5f4cb161cec3 49 #define PICOTCP_MUTEX_UNLOCK(x) do {} while(0)
tass 152:a3d286bf94e5 50 #define PICOTCP_MUTEX_DEL(x) do {} while(0)
daniele 29:1a47b7151851 51 #endif
daniele 29:1a47b7151851 52
daniele 29:1a47b7151851 53 #ifdef PICO_SUPPORT_DEBUG_TOOLS
daniele 29:1a47b7151851 54 static void debug_q(struct pico_queue *q)
daniele 29:1a47b7151851 55 {
TASS Belgium NV 131:4758606c9316 56 struct pico_frame *p = q->head;
TASS Belgium NV 131:4758606c9316 57 dbg("%d: ", q->frames);
TASS Belgium NV 131:4758606c9316 58 while(p) {
TASS Belgium NV 131:4758606c9316 59 dbg("(%p)-->", p);
TASS Belgium NV 131:4758606c9316 60 p = p->next;
TASS Belgium NV 131:4758606c9316 61 }
TASS Belgium NV 131:4758606c9316 62 dbg("X\n");
daniele 29:1a47b7151851 63 }
daniele 29:1a47b7151851 64
daniele 29:1a47b7151851 65 #else
daniele 29:1a47b7151851 66
TASS Belgium NV 131:4758606c9316 67 #define debug_q(x) do {} while(0)
daniele 29:1a47b7151851 68 #endif
daniele 29:1a47b7151851 69
tass 70:cd218dd180e5 70 static inline int32_t pico_enqueue(struct pico_queue *q, struct pico_frame *p)
daniele 29:1a47b7151851 71 {
TASS Belgium NV 131:4758606c9316 72 if ((q->max_frames) && (q->max_frames <= q->frames))
TASS Belgium NV 131:4758606c9316 73 return -1;
TASS Belgium NV 131:4758606c9316 74
tass 152:a3d286bf94e5 75 #if (Q_LIMIT != 0)
tass 152:a3d286bf94e5 76 if ((Q_LIMIT < p->buffer_len + q->size))
TASS Belgium NV 131:4758606c9316 77 return -1;
daniele 29:1a47b7151851 78
tass 152:a3d286bf94e5 79 #endif
tass 152:a3d286bf94e5 80
TASS Belgium NV 131:4758606c9316 81 if ((q->max_size) && (q->max_size < (p->buffer_len + q->size)))
TASS Belgium NV 131:4758606c9316 82 return -1;
TASS Belgium NV 131:4758606c9316 83
TASS Belgium NV 131:4758606c9316 84 if (q->shared)
tass picotcp@tass.be 149:5f4cb161cec3 85 PICOTCP_MUTEX_LOCK(q->mutex);
daniele 29:1a47b7151851 86
TASS Belgium NV 131:4758606c9316 87 p->next = NULL;
TASS Belgium NV 131:4758606c9316 88 if (!q->head) {
TASS Belgium NV 131:4758606c9316 89 q->head = p;
TASS Belgium NV 131:4758606c9316 90 q->tail = p;
TASS Belgium NV 131:4758606c9316 91 q->size = 0;
TASS Belgium NV 131:4758606c9316 92 q->frames = 0;
TASS Belgium NV 131:4758606c9316 93 } else {
TASS Belgium NV 131:4758606c9316 94 q->tail->next = p;
TASS Belgium NV 131:4758606c9316 95 q->tail = p;
TASS Belgium NV 131:4758606c9316 96 }
daniele 29:1a47b7151851 97
TASS Belgium NV 131:4758606c9316 98 q->size += p->buffer_len + q->overhead;
TASS Belgium NV 131:4758606c9316 99 q->frames++;
TASS Belgium NV 131:4758606c9316 100 debug_q(q);
TASS Belgium NV 131:4758606c9316 101
TASS Belgium NV 131:4758606c9316 102 if (q->shared)
tass picotcp@tass.be 149:5f4cb161cec3 103 PICOTCP_MUTEX_UNLOCK(q->mutex);
TASS Belgium NV 131:4758606c9316 104
TASS Belgium NV 131:4758606c9316 105 return (int32_t)q->size;
daniele 29:1a47b7151851 106 }
daniele 29:1a47b7151851 107
daniele 29:1a47b7151851 108 static inline struct pico_frame *pico_dequeue(struct pico_queue *q)
daniele 29:1a47b7151851 109 {
TASS Belgium NV 131:4758606c9316 110 struct pico_frame *p = q->head;
tass picotcp@tass.be 149:5f4cb161cec3 111 if (!p)
tass picotcp@tass.be 149:5f4cb161cec3 112 return NULL;
tass picotcp@tass.be 149:5f4cb161cec3 113
TASS Belgium NV 131:4758606c9316 114 if (q->frames < 1)
TASS Belgium NV 131:4758606c9316 115 return NULL;
TASS Belgium NV 131:4758606c9316 116
TASS Belgium NV 131:4758606c9316 117 if (q->shared)
tass picotcp@tass.be 149:5f4cb161cec3 118 PICOTCP_MUTEX_LOCK(q->mutex);
daniele 29:1a47b7151851 119
TASS Belgium NV 131:4758606c9316 120 q->head = p->next;
TASS Belgium NV 131:4758606c9316 121 q->frames--;
TASS Belgium NV 131:4758606c9316 122 q->size -= p->buffer_len - q->overhead;
TASS Belgium NV 131:4758606c9316 123 if (q->head == NULL)
TASS Belgium NV 131:4758606c9316 124 q->tail = NULL;
TASS Belgium NV 131:4758606c9316 125
TASS Belgium NV 131:4758606c9316 126 debug_q(q);
tass picotcp@tass.be 149:5f4cb161cec3 127
TASS Belgium NV 131:4758606c9316 128 p->next = NULL;
TASS Belgium NV 131:4758606c9316 129 if (q->shared)
tass picotcp@tass.be 149:5f4cb161cec3 130 PICOTCP_MUTEX_UNLOCK(q->mutex);
TASS Belgium NV 131:4758606c9316 131
TASS Belgium NV 131:4758606c9316 132 return p;
daniele 29:1a47b7151851 133 }
daniele 29:1a47b7151851 134
daniele 29:1a47b7151851 135 static inline struct pico_frame *pico_queue_peek(struct pico_queue *q)
daniele 29:1a47b7151851 136 {
TASS Belgium NV 131:4758606c9316 137 struct pico_frame *p = q->head;
TASS Belgium NV 131:4758606c9316 138 if (q->frames < 1)
TASS Belgium NV 131:4758606c9316 139 return NULL;
TASS Belgium NV 131:4758606c9316 140
TASS Belgium NV 131:4758606c9316 141 debug_q(q);
TASS Belgium NV 131:4758606c9316 142 return p;
daniele 29:1a47b7151851 143 }
daniele 29:1a47b7151851 144
tass 152:a3d286bf94e5 145 static inline void pico_queue_deinit(struct pico_queue *q)
tass 152:a3d286bf94e5 146 {
tass 152:a3d286bf94e5 147 if (q->shared) {
tass 152:a3d286bf94e5 148 PICOTCP_MUTEX_DEL(q->mutex);
tass 152:a3d286bf94e5 149 }
tass 152:a3d286bf94e5 150 }
tass 152:a3d286bf94e5 151
daniele 29:1a47b7151851 152 static inline void pico_queue_empty(struct pico_queue *q)
daniele 29:1a47b7151851 153 {
TASS Belgium NV 131:4758606c9316 154 struct pico_frame *p = pico_dequeue(q);
TASS Belgium NV 131:4758606c9316 155 while(p) {
tass 152:a3d286bf94e5 156 pico_frame_discard(p);
TASS Belgium NV 131:4758606c9316 157 p = pico_dequeue(q);
TASS Belgium NV 131:4758606c9316 158 }
daniele 29:1a47b7151851 159 }
daniele 29:1a47b7151851 160
daniele 29:1a47b7151851 161 static inline void pico_queue_protect(struct pico_queue *q)
daniele 29:1a47b7151851 162 {
TASS Belgium NV 131:4758606c9316 163 q->shared = 1;
daniele 29:1a47b7151851 164 }
daniele 29:1a47b7151851 165
daniele 29:1a47b7151851 166 #endif