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 picotcp@tass.be
Date:
Thu Jan 16 14:46:07 2014 +0100
Revision:
134:cc4e6d2654d9
Parent:
124:a6ecd840c965
Update from masterbranch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 3:b4047e8a0123 1 /*********************************************************************
daniele 3:b4047e8a0123 2 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
daniele 3:b4047e8a0123 3 See LICENSE and COPYING for usage.
daniele 3:b4047e8a0123 4 Do not redistribute without a written permission by the Copyright
daniele 3:b4047e8a0123 5 holders.
daniele 3:b4047e8a0123 6
daniele 3:b4047e8a0123 7 Authors: Toon Peters, Maxime Vincent
daniele 3:b4047e8a0123 8 *********************************************************************/
daniele 3:b4047e8a0123 9 #include "mbed.h"
daniele 3:b4047e8a0123 10 extern "C" {
daniele 3:b4047e8a0123 11 #include "pico_device.h"
daniele 3:b4047e8a0123 12 #include "pico_dev_mbed.h"
daniele 3:b4047e8a0123 13 #include "pico_stack.h"
daniele 3:b4047e8a0123 14 #include "ethernet_api.h"
daniele 3:b4047e8a0123 15 }
daniele 3:b4047e8a0123 16
daniele 3:b4047e8a0123 17 struct pico_device_mbed {
daniele 3:b4047e8a0123 18 struct pico_device dev;
daniele 3:b4047e8a0123 19 int bytes_left_in_frame;
daniele 3:b4047e8a0123 20 };
daniele 3:b4047e8a0123 21
daniele 3:b4047e8a0123 22 #define ETH_MTU 1514
daniele 3:b4047e8a0123 23 uint8_t buf[ETH_MTU];
daniele 3:b4047e8a0123 24
daniele 3:b4047e8a0123 25 extern "C" {
daniele 3:b4047e8a0123 26
daniele 3:b4047e8a0123 27 static int pico_mbed_send(struct pico_device *dev, void *buf, int len)
daniele 3:b4047e8a0123 28 {
daniele 3:b4047e8a0123 29 int ret, sent;
daniele 3:b4047e8a0123 30
daniele 3:b4047e8a0123 31 if (len > ETH_MTU)
daniele 3:b4047e8a0123 32 return -1;
daniele 3:b4047e8a0123 33
daniele 3:b4047e8a0123 34 /* Write buf content to dev and return amount written */
daniele 3:b4047e8a0123 35 ret = ethernet_write((const char *)buf, len);
daniele 3:b4047e8a0123 36 sent = ethernet_send();
daniele 3:b4047e8a0123 37
tass 112:c4463e7a6a41 38 printf("ETH> sent %d bytes\r\n",ret);
daniele 3:b4047e8a0123 39 if (len != ret || sent != ret)
daniele 3:b4047e8a0123 40 return -1;
daniele 3:b4047e8a0123 41 else
daniele 3:b4047e8a0123 42 return ret;
daniele 3:b4047e8a0123 43 }
daniele 3:b4047e8a0123 44
daniele 3:b4047e8a0123 45 static int pico_mbed_poll(struct pico_device *dev, int loop_score)
daniele 3:b4047e8a0123 46 {
daniele 3:b4047e8a0123 47 int len;
tass picotcp@tass.be 134:cc4e6d2654d9 48
daniele 3:b4047e8a0123 49 while(loop_score > 0)
daniele 3:b4047e8a0123 50 {
daniele 3:b4047e8a0123 51 /* check for new frame(s) */
daniele 3:b4047e8a0123 52 len = (int) ethernet_receive();
tass picotcp@tass.be 134:cc4e6d2654d9 53
daniele 3:b4047e8a0123 54 /* return if no frame has arrived */
daniele 3:b4047e8a0123 55 if (!len)
daniele 3:b4047e8a0123 56 return loop_score;
tass picotcp@tass.be 134:cc4e6d2654d9 57
daniele 3:b4047e8a0123 58 /* read and process frame */
daniele 3:b4047e8a0123 59 len = ethernet_read((char*)buf, ETH_MTU);
tass 112:c4463e7a6a41 60 printf("ETH> recv %d bytes: %x:%x\r\n", len, buf[0],buf[1]);
daniele 3:b4047e8a0123 61 pico_stack_recv(dev, buf, len);
daniele 3:b4047e8a0123 62 loop_score--;
daniele 3:b4047e8a0123 63 }
daniele 3:b4047e8a0123 64 return loop_score;
daniele 3:b4047e8a0123 65 }
daniele 3:b4047e8a0123 66
daniele 3:b4047e8a0123 67 /* Public interface: create/destroy. */
daniele 3:b4047e8a0123 68 void pico_mbed_destroy(struct pico_device *dev)
daniele 3:b4047e8a0123 69 {
daniele 3:b4047e8a0123 70 ethernet_free();
daniele 3:b4047e8a0123 71 pico_device_destroy(dev);
daniele 3:b4047e8a0123 72 }
daniele 3:b4047e8a0123 73
daniele 3:b4047e8a0123 74 struct pico_device *pico_mbed_create(char *name)
daniele 3:b4047e8a0123 75 {
tass 124:a6ecd840c965 76 uint8_t mac[PICO_SIZE_ETH];
daniele 3:b4047e8a0123 77 struct pico_device_mbed *mb = (struct pico_device_mbed*) pico_zalloc(sizeof(struct pico_device_mbed));
daniele 3:b4047e8a0123 78
daniele 3:b4047e8a0123 79 if (!mb)
daniele 3:b4047e8a0123 80 return NULL;
daniele 3:b4047e8a0123 81
daniele 3:b4047e8a0123 82 ethernet_address((char *)mac);
tass 112:c4463e7a6a41 83 printf("ETH> Set MAC address to: %x:%x:%x:%x:%x:%x\r\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
daniele 3:b4047e8a0123 84
daniele 3:b4047e8a0123 85 if(0 != pico_device_init((struct pico_device *)mb, name, mac)) {
tass 112:c4463e7a6a41 86 printf ("ETH> Loop init failed.\n");
daniele 3:b4047e8a0123 87 //pico_loop_destroy(mb);
daniele 3:b4047e8a0123 88 return NULL;
daniele 3:b4047e8a0123 89 }
daniele 3:b4047e8a0123 90
daniele 3:b4047e8a0123 91 mb->dev.send = pico_mbed_send;
daniele 3:b4047e8a0123 92 mb->dev.poll = pico_mbed_poll;
daniele 3:b4047e8a0123 93 mb->dev.destroy = pico_mbed_destroy;
daniele 3:b4047e8a0123 94 mb->bytes_left_in_frame = 0;
daniele 3:b4047e8a0123 95
daniele 3:b4047e8a0123 96 if(0 != ethernet_init()) {
tass 112:c4463e7a6a41 97 printf("ETH> Failed to initialize hardware.\r\n");
daniele 3:b4047e8a0123 98 pico_device_destroy((struct pico_device *)mb);
daniele 3:b4047e8a0123 99 return NULL;
daniele 3:b4047e8a0123 100 }
daniele 3:b4047e8a0123 101
daniele 3:b4047e8a0123 102 // future work: make the mac address configurable
daniele 3:b4047e8a0123 103
tass 112:c4463e7a6a41 104 printf("ETH> Device %s created.\r\n", mb->dev.name);
daniele 3:b4047e8a0123 105
daniele 3:b4047e8a0123 106 return (struct pico_device *)mb;
daniele 3:b4047e8a0123 107 }
daniele 3:b4047e8a0123 108
daniele 3:b4047e8a0123 109 void pico_mbed_get_address(char *mac)
daniele 3:b4047e8a0123 110 {
daniele 3:b4047e8a0123 111 ethernet_address(mac);
daniele 3:b4047e8a0123 112 }
daniele 3:b4047e8a0123 113
tass picotcp@tass.be 134:cc4e6d2654d9 114 }