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.

include/pico_queue.h

Committer:
daniele
Date:
2013-06-06
Revision:
12:0c6fa180a6ec
Child:
24:8bff2b51ea3b

File content as of revision 12:0c6fa180a6ec:

/*********************************************************************
PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
See LICENSE and COPYING for usage.

*********************************************************************/
#ifndef _INCLUDE_PICO_QUEUE
#define _INCLUDE_PICO_QUEUE
#include <stdint.h>
#include "pico_config.h"
#include "pico_frame.h"

#ifndef NULL
#define NULL ((void *)0)
#endif

struct pico_queue {
  uint32_t frames;
  uint32_t size;
  uint32_t max_frames;
  uint32_t max_size;
  struct pico_frame *head;
  struct pico_frame *tail;
#ifdef PICO_SUPPORT_MUTEX
  void * mutex;
#endif
  uint8_t shared;
};

#ifdef PICO_SUPPORT_MUTEX
#define LOCK(x) {\
  if (x == NULL) \
    x = pico_mutex_init(); \
  pico_mutex_lock(x); \
}
#define UNLOCK(x) pico_mutex_unlock(x);

#else 
#define LOCK(x) do{}while(0)
#define UNLOCK(x) do{}while(0)
#endif

#ifdef PICO_SUPPORT_DEBUG_TOOLS
static void debug_q(struct pico_queue *q)
{
  struct pico_frame *p = q->head;
  dbg("%d: ", q->frames);
  while(p) {
    dbg("(%p)-->", p);
    p = p->next;
  }
  dbg("X\n");
}

#else

#define debug_q(x) do{}while(0)
#endif

static inline int pico_enqueue(struct pico_queue *q, struct pico_frame *p)
{
  if ((q->max_frames) && (q->max_frames <= q->frames))
    return -1;

  if ((q->max_size) && (q->max_size < (p->buffer_len + q->size)))
    return -1;

  if (q->shared)
    LOCK(q->mutex);

  p->next = NULL;
  if (!q->head) {
    q->head = p;
    q->tail = p;
    q->size = 0;
    q->frames = 0;
  } else {
    q->tail->next = p;
    q->tail = p;
  }
  q->size += p->buffer_len;
  q->frames++;
  debug_q(q);

  if (q->shared)
    UNLOCK(q->mutex);
  return q->size;
}

static inline struct pico_frame *pico_dequeue(struct pico_queue *q)
{
  struct pico_frame *p = q->head;
  if (q->frames < 1)
    return NULL;
  if (q->shared)
    LOCK(q->mutex);

  q->head = p->next;
  q->frames--;
  q->size -= p->buffer_len;
  if (q->head == NULL)
    q->tail = NULL;
  debug_q(q);
  p->next = NULL;
  if (q->shared)
    UNLOCK(q->mutex);
  return p;
}

static inline struct pico_frame *pico_queue_peek(struct pico_queue *q)
{
  struct pico_frame *p = q->head;
  if (q->frames < 1)
    return NULL;
  debug_q(q);
  return p;
}

static inline void pico_queue_empty(struct pico_queue *q)
{
  struct pico_frame *p = pico_dequeue(q);
  while(p) {
    pico_free(p);
    p = pico_dequeue(q);
  }
}

static inline void pico_queue_protect(struct pico_queue *q)
{
  q->shared = 1;
}

#endif