Rewrite from scratch a TCP/IP stack for mbed. So far the following parts are usable: Drivers: - EMAC driver (from CMSIS 2.0) Protocols: - Ethernet protocol - ARP over ethernet for IPv4 - IPv4 over Ethernet - ICMPv4 over IPv4 - UDPv4 over IPv4 APIs: - Sockets for UDPv4 The structure of this stack is designed to be very modular. Each protocol can register one or more protocol to handle its payload, and in each protocol, an API can be hooked (like Sockets for example). This is an early release.

Revision:
0:19f5f51584de
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Queue.c	Sun Jun 12 11:23:03 2011 +0000
@@ -0,0 +1,142 @@
+/*
+ * $Id: Queue.c 29 2011-06-11 14:53:08Z benoit $
+ * $Author: benoit $
+ * $Date: 2011-06-11 16:53:08 +0200 (sam., 11 juin 2011) $
+ * $Rev: 29 $
+ * 
+ * 
+ * 
+ * 
+ * 
+ */
+ 
+#include "Queue.h"
+#include "Debug.h"
+#include <stdlib.h>
+#include <string.h>
+
+
+#define    DEBUG_CURRENT_MODULE_NAME    "Queue"
+#define    DEBUG_CURRENT_MODULE_ID        DEBUG_MODULE_QUEUE
+
+
+Queue_t *Queue_Alloc(int16_t size)
+{
+    Queue_t        *queue;
+    
+    queue = (Queue_t *)malloc(sizeof(Queue_t));
+    if (queue == NULL)
+    {
+        DEBUG_MODULE(DEBUG_LEVEL_WARNING, ("Not enough memory"));
+        mbedNet_LastError = mbedNetResult_NotEnoughMemory;
+        goto Exit;
+    }
+    memset(queue, 0, sizeof(Queue_t));
+    
+    queue->size = size + 1;
+    
+    DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Allocated queue of %d items", queue->popIndex, queue->pushIndex, size));
+    
+Exit:
+    return queue;
+}
+
+
+int32_t Queue_Push(Queue_t *queue, void *entry)
+{
+    int32_t        result = 0;
+    int16_t        index;
+    
+    if (queue->popIndex == ((queue->pushIndex + 1) % queue->size))
+    {
+        DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is full", queue->popIndex, queue->pushIndex));
+        result = -1;
+        mbedNet_LastError = mbedNetResult_QueueFull;
+        goto Exit;
+    }
+    
+    index = queue->pushIndex;
+    queue->entries[index] = entry;
+    index++;
+    if (index == queue->size) index = 0;
+    queue->pushIndex = index;
+    
+    DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Pushing one entry from queue", queue->popIndex, queue->pushIndex));
+    
+Exit:
+    return result;
+}
+
+
+int32_t Queue_Pop(Queue_t *queue, void **entry)
+{
+    int32_t        result = 0;
+    int16_t        index;
+    
+    if (queue->popIndex == queue->pushIndex)
+    {
+        DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is empty", queue->popIndex, queue->pushIndex));
+        result = -1;
+        mbedNet_LastError = mbedNetResult_QueueEmpty;
+        goto Exit;
+    }
+    
+
+    index = queue->popIndex;
+    *entry = queue->entries[index];
+    index++;
+    if (index == queue->size) index = 0;
+    queue->popIndex = index;
+
+    DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Popping one entry from queue", queue->popIndex, queue->pushIndex));
+        
+Exit:
+    return result;
+}
+
+
+int32_t Queue_Peek(Queue_t *queue, void **entry)
+{
+    int32_t        result = 0;
+    int16_t        index;
+    
+    if (queue->popIndex == queue->pushIndex)
+    {
+        DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is empty", queue->popIndex, queue->pushIndex));
+        result = -1;
+        mbedNet_LastError = mbedNetResult_QueueEmpty;
+        goto Exit;
+    }
+    
+    index = queue->popIndex;
+    *entry = queue->entries[index];
+
+    DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Peeking first entry from queue", queue->popIndex, queue->pushIndex));
+        
+Exit:
+    return result;
+}
+
+
+int32_t Queue_Free(Queue_t *queue)
+{
+    int32_t        result = 0;
+    
+    DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Free queue", queue->popIndex, queue->pushIndex));
+    free(queue);
+    
+    return result;
+}
+
+
+Bool_t Queue_IsEmpty(const Queue_t *queue)
+{
+    return (queue->popIndex == queue->pushIndex) ? True : False;
+}
+
+
+Bool_t Queue_IsFull(const Queue_t *queue)
+{
+    return (queue->popIndex == ((queue->pushIndex + 1) % queue->size)) ? True : False;
+}
+