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 Dec 05 08:31:32 2013 +0000
Revision:
128:ae39e6e81531
Parent:
123:dd26752a4538
Child:
142:35da43068894
updated repo to work with uint64 tick.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 29:1a47b7151851 1 /*********************************************************************
daniele 29:1a47b7151851 2 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
daniele 29:1a47b7151851 3 See LICENSE and COPYING for usage.
daniele 29:1a47b7151851 4 Do not redistribute without a written permission by the Copyright
daniele 29:1a47b7151851 5 holders.
daniele 29:1a47b7151851 6
daniele 29:1a47b7151851 7 File: pico_mbed.h
daniele 29:1a47b7151851 8 Author: Toon Peters
daniele 29:1a47b7151851 9 *********************************************************************/
daniele 29:1a47b7151851 10
daniele 29:1a47b7151851 11 #ifndef PICO_SUPPORT_MBED
daniele 29:1a47b7151851 12 #define PICO_SUPPORT_MBED
daniele 29:1a47b7151851 13 #include <stdio.h>
daniele 29:1a47b7151851 14 //#include "mbed.h"
daniele 29:1a47b7151851 15 //#include "serial_api.h"
daniele 29:1a47b7151851 16
tass 119:58b4b9252a6f 17 //#define TIME_PRESCALE
tass 119:58b4b9252a6f 18 //#define PICO_MEASURE_STACK
tass 119:58b4b9252a6f 19 //#define MEMORY_MEASURE
daniele 29:1a47b7151851 20 /*
daniele 29:1a47b7151851 21 Debug needs initialization:
daniele 29:1a47b7151851 22 * void serial_init (serial_t *obj, PinName tx, PinName rx);
daniele 29:1a47b7151851 23 * void serial_baud (serial_t *obj, int baudrate);
daniele 29:1a47b7151851 24 * void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
daniele 29:1a47b7151851 25 */
daniele 29:1a47b7151851 26
daniele 29:1a47b7151851 27 #define dbg(...)
tass 89:49ca05d9a19e 28
tass 89:49ca05d9a19e 29 #ifdef PICO_MEASURE_STACK
tass 89:49ca05d9a19e 30
tass 89:49ca05d9a19e 31 extern int freeStack;
tass 89:49ca05d9a19e 32 #define STACK_TOTAL_WORDS 1000u
tass 89:49ca05d9a19e 33 #define STACK_PATTERN (0xC0CAC01A)
tass 89:49ca05d9a19e 34
tass 89:49ca05d9a19e 35 void stack_fill_pattern(void *ptr);
tass 89:49ca05d9a19e 36 void stack_count_free_words(void *ptr);
tass 89:49ca05d9a19e 37 int stack_get_free_words(void);
tass 123:dd26752a4538 38 #else
tass 123:dd26752a4538 39 #define stack_fill_pattern(...) do{}while(0)
tass 123:dd26752a4538 40 #define stack_count_free_words(...) do{}while(0)
tass 123:dd26752a4538 41 #define stack_get_free_words() (0)
tass 89:49ca05d9a19e 42 #endif
tass 89:49ca05d9a19e 43
daniele 29:1a47b7151851 44 #ifdef MEMORY_MEASURE // in case, comment out the two defines above me.
daniele 29:1a47b7151851 45 extern uint32_t max_mem;
daniele 29:1a47b7151851 46 extern uint32_t cur_mem;
daniele 29:1a47b7151851 47
daniele 29:1a47b7151851 48 static inline void * pico_zalloc(int x)
daniele 29:1a47b7151851 49 {
daniele 29:1a47b7151851 50 uint32_t *ptr;
daniele 29:1a47b7151851 51 if ((cur_mem + x )> (10 * 1024))
daniele 29:1a47b7151851 52 return NULL;
daniele 29:1a47b7151851 53
daniele 29:1a47b7151851 54 ptr = (uint32_t *)calloc(x + 4, 1);
daniele 29:1a47b7151851 55 *ptr = (uint32_t)x;
daniele 29:1a47b7151851 56 cur_mem += x;
daniele 29:1a47b7151851 57 if (cur_mem > max_mem) {
daniele 29:1a47b7151851 58 max_mem = cur_mem;
tass 89:49ca05d9a19e 59 // printf("max mem: %lu\n", max_mem);
daniele 29:1a47b7151851 60 }
daniele 29:1a47b7151851 61 return (void*)(ptr + 1);
daniele 29:1a47b7151851 62 }
daniele 29:1a47b7151851 63
daniele 29:1a47b7151851 64 static inline void pico_free(void *x)
daniele 29:1a47b7151851 65 {
daniele 29:1a47b7151851 66 uint32_t *ptr = (uint32_t*)(((uint8_t *)x) - 4);
daniele 29:1a47b7151851 67 cur_mem -= *ptr;
daniele 29:1a47b7151851 68 free(ptr);
daniele 29:1a47b7151851 69 }
tass 113:f2f9b678d3fe 70 #else
tass 113:f2f9b678d3fe 71
tass 113:f2f9b678d3fe 72 #define pico_zalloc(x) calloc(x, 1)
tass 113:f2f9b678d3fe 73 #define pico_free(x) free(x)
tass 113:f2f9b678d3fe 74
daniele 29:1a47b7151851 75 #endif
daniele 29:1a47b7151851 76
daniele 29:1a47b7151851 77 #define PICO_SUPPORT_MUTEX
daniele 29:1a47b7151851 78 extern void *pico_mutex_init(void);
daniele 29:1a47b7151851 79 extern void pico_mutex_lock(void*);
daniele 29:1a47b7151851 80 extern void pico_mutex_unlock(void*);
daniele 29:1a47b7151851 81
daniele 29:1a47b7151851 82 extern uint32_t os_time;
tass 128:ae39e6e81531 83 extern uint64_t local_time;
tass 128:ae39e6e81531 84 extern uint32_t last_os_time;
daniele 3:b4047e8a0123 85
tass 83:d4e1dcd97346 86 #ifdef TIME_PRESCALE
tass 83:d4e1dcd97346 87 extern int32_t prescale_time;
tass 83:d4e1dcd97346 88 #endif
tass 87:d45bc027b06d 89 extern uint32_t os_time;
tass 87:d45bc027b06d 90
tass 128:ae39e6e81531 91 #define UPDATE_LOCAL_TIME() do{local_time=local_time+(os_time-last_os_time);last_os_time=os_time;}while(0)
daniele 29:1a47b7151851 92
tass 128:ae39e6e81531 93 static inline uint64_t PICO_TIME(void)
daniele 29:1a47b7151851 94 {
tass 128:ae39e6e81531 95 UPDATE_LOCAL_TIME();
tass 83:d4e1dcd97346 96 #ifdef TIME_PRESCALE
tass 128:ae39e6e81531 97 return (prescale_time < 0) ? (uint64_t)(local_time / 1000 << (-prescale_time)) : \
tass 128:ae39e6e81531 98 (uint64_t)(local_time / 1000 >> prescale_time);
tass 83:d4e1dcd97346 99 #else
tass 128:ae39e6e81531 100 return (uint64_t)(local_time / 1000);
tass 83:d4e1dcd97346 101 #endif
daniele 29:1a47b7151851 102 }
daniele 29:1a47b7151851 103
tass 128:ae39e6e81531 104 static inline uint64_t PICO_TIME_MS(void)
daniele 29:1a47b7151851 105 {
tass 128:ae39e6e81531 106 UPDATE_LOCAL_TIME();
tass 83:d4e1dcd97346 107 #ifdef TIME_PRESCALE
tass 128:ae39e6e81531 108 return (prescale_time < 0) ? (uint64_t)(local_time << (-prescale_time)) : \
tass 128:ae39e6e81531 109 (uint64_t)(local_time >> prescale_time);
tass 83:d4e1dcd97346 110 #else
tass 128:ae39e6e81531 111 return (uint64_t)local_time;
tass 83:d4e1dcd97346 112 #endif
daniele 29:1a47b7151851 113 }
daniele 29:1a47b7151851 114
daniele 29:1a47b7151851 115 static inline void PICO_IDLE(void)
daniele 29:1a47b7151851 116 {
daniele 29:1a47b7151851 117 // TODO needs implementation
daniele 29:1a47b7151851 118 }
daniele 29:1a47b7151851 119 /*
daniele 29:1a47b7151851 120 static inline void PICO_DEBUG(const char * formatter, ... )
daniele 29:1a47b7151851 121 {
daniele 29:1a47b7151851 122 char buffer[256];
daniele 29:1a47b7151851 123 char *ptr;
daniele 29:1a47b7151851 124 va_list args;
daniele 29:1a47b7151851 125 va_start(args, formatter);
daniele 29:1a47b7151851 126 vsnprintf(buffer, 256, formatter, args);
daniele 29:1a47b7151851 127 ptr = buffer;
daniele 29:1a47b7151851 128 while(*ptr != '\0')
daniele 29:1a47b7151851 129 serial_putc(serial_t *obj, (int) (*(ptr++)));
daniele 29:1a47b7151851 130 va_end(args);
daniele 29:1a47b7151851 131 //TODO implement serial_t
daniele 29:1a47b7151851 132 }*/
daniele 29:1a47b7151851 133
daniele 29:1a47b7151851 134 #endif