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: Socket/bsd/stack_endpoint.cpp
- Revision:
- 27:26c168f5aa97
- Parent:
- 26:dc3e7f96338f
--- a/Socket/bsd/stack_endpoint.cpp Sat Jun 15 18:38:26 2013 +0000 +++ b/Socket/bsd/stack_endpoint.cpp Sun Jun 16 02:31:38 2013 +0000 @@ -19,7 +19,7 @@ Mutex *PicoTcpLock; Queue<void,10> *PicoTcpEvents; - +static struct stack_endpoint *ep_accepting; static Thread * serverThread = NULL; #define pt_proxy_dbg(...) @@ -57,8 +57,13 @@ { struct stack_endpoint *ep = (struct stack_endpoint *)s->priv; if (!ep) { - printf("WAKEUP: no socket :(\n"); - return; + if (ep_accepting != NULL) { + printf("Delivering %02x to accepting socket...\n", ev); + ep = ep_accepting; + } else { + printf("WAKEUP: socket not found! ev=%04x\n", ev); + return; + } } ep->revents |= ev; @@ -86,6 +91,7 @@ printf("Error opening socket!\n"); } else { ep->s->priv = ep; + printf("Added socket (open)\n"); ep->queue = new Queue<void,1>(); } PicoTcpLock->unlock(); @@ -122,6 +128,10 @@ int ret; PicoTcpLock->lock(); ret = pico_socket_listen(ep->s, queue); + ep_accepting = (struct stack_endpoint *) pico_zalloc(sizeof(struct stack_endpoint)); + ep_accepting->queue = new Queue<void,1>(); + if (!ep_accepting) + ret = -1; PicoTcpLock->unlock(); return ret; } @@ -150,19 +160,28 @@ struct stack_endpoint *picotcp_accept(struct stack_endpoint *ep, struct sockaddr *_cli_addr, socklen_t *len) { int retval; - struct stack_endpoint *aep = (struct stack_endpoint *) pico_zalloc(sizeof(struct stack_endpoint)); + struct stack_endpoint *aep = ep_accepting; struct sockaddr_in *cli_addr = (struct sockaddr_in *)_cli_addr; + ep_accepting = (struct stack_endpoint *) pico_zalloc(sizeof(struct stack_endpoint)); + if (ep_accepting) + ep_accepting->queue = new Queue<void,1>(); + + if (!aep) return aep; + PicoTcpLock->lock(); ep->events = PICO_SOCK_EV_CONN | PICO_SOCK_EV_ERR; __critical_select(ep, osWaitForever); if (ep->revents & PICO_SOCK_EV_CONN) { + printf("Calling Accept\n"); aep->s = pico_socket_accept(ep->s, (struct pico_ip4 *)(&cli_addr->sin_addr.s_addr), &cli_addr->sin_port); + printf("Accept returned\n"); + aep->s->priv = aep; ep->revents &= (~PICO_SOCK_EV_CONN); aep->revents |= PICO_SOCK_EV_WR; - aep->s->priv = aep; - aep->queue = new Queue<void,1>(); + printf("Added socket (accept)\n"); + *len = sizeof(struct sockaddr_in); ptsock_dbg("Established. sock state: %x\n", aep->s->state); } else { @@ -223,10 +242,15 @@ PicoTcpLock->lock(); while (tot_len < len) { retval = pico_socket_read(ep->s, ((uint8_t *)buf) + tot_len , len - tot_len); - if (retval <= 0) { - ep->revents &= ~PICO_SOCK_EV_RD; + if (retval == 0) { + if (tot_len < len) + ep->revents &= ~PICO_SOCK_EV_RD; break; } + if (retval < 0) { + tot_len = -1; + break; + } tot_len += retval; } PicoTcpLock->unlock(); @@ -242,14 +266,21 @@ PicoTcpLock->lock(); while (tot_len < len) { retval = pico_socket_write(ep->s, ((uint8_t *)buf) + tot_len , len - tot_len); - if (retval <= 0) { - ep->revents &= ~PICO_SOCK_EV_WR; + retval = pico_socket_read(ep->s, ((uint8_t *)buf) + tot_len , len - tot_len); + if (retval == 0) { + if (tot_len < len) + ep->revents &= ~PICO_SOCK_EV_RD; break; } + if (retval < 0) { + tot_len = -1; + break; + } tot_len += retval; - picotcp_async_interrupt(); + } PicoTcpLock->unlock(); + picotcp_async_interrupt(NULL); return tot_len; } @@ -289,11 +320,27 @@ { (void)arg; int ret = 0; + struct pico_device *dev; while(1) { - PicoTcpEvents->get(2); - if (PicoTcpLock->trylock()) { + + osEvent evt = PicoTcpEvents->get(2); + + if (evt.status == osEventMessage) { + dev = (struct pico_device *)evt.value.p; + } else { + dev = NULL; + } + + if (dev && dev->dsr){ + PicoTcpLock->lock(); + dev->dsr(dev, 200); pico_stack_tick(); PicoTcpLock->unlock(); + } else { + if (PicoTcpLock->trylock()) { + pico_stack_tick(); + PicoTcpLock->unlock(); + } } } } @@ -314,7 +361,7 @@ picotcp_start(); } -int picotcp_async_interrupt(void) +int picotcp_async_interrupt(void *arg) { - PicoTcpEvents->put((void *)0); -} \ No newline at end of file + PicoTcpEvents->put(arg); +}