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.
CQueue.cpp
00001 /* 00002 * $Id: Queue.c 29 2011-06-11 14:53:08Z benoit $ 00003 * $Author: benoit $ 00004 * $Date: 2011-06-11 16:53:08 +0200 (sam., 11 juin 2011) $ 00005 * $Rev: 29 $ 00006 * 00007 * 00008 * 00009 * 00010 * 00011 */ 00012 00013 #include "CQueue.h" 00014 #include "Debug.h" 00015 #include <stdlib.h> 00016 #include <string.h> 00017 00018 00019 #define DEBUG_CURRENT_MODULE_NAME "Queue" 00020 #define DEBUG_CURRENT_MODULE_ID DEBUG_MODULE_QUEUE 00021 00022 00023 CQueue_t *CQueue_Alloc(int16_t size) 00024 { 00025 CQueue_t *queue; 00026 00027 queue = (CQueue_t *)malloc(sizeof(CQueue_t)); 00028 if (queue == NULL) 00029 { 00030 DEBUG_MODULE(DEBUG_LEVEL_WARNING, ("Not enough memory")); 00031 mbedNet_LastError = mbedNetResult_NotEnoughMemory; 00032 goto Exit; 00033 } 00034 memset(queue, 0, sizeof(CQueue_t)); 00035 00036 queue->size = size + 1; 00037 00038 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Allocated queue of %d items", queue->popIndex, queue->pushIndex, size)); 00039 00040 Exit: 00041 return queue; 00042 } 00043 00044 00045 int32_t CQueue_Push(CQueue_t *queue, void *entry) 00046 { 00047 int32_t result = 0; 00048 int16_t index; 00049 00050 if (queue->popIndex == ((queue->pushIndex + 1) % queue->size)) 00051 { 00052 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is full", queue->popIndex, queue->pushIndex)); 00053 result = -1; 00054 mbedNet_LastError = mbedNetResult_QueueFull; 00055 goto Exit; 00056 } 00057 00058 index = queue->pushIndex; 00059 queue->entries[index] = entry; 00060 index++; 00061 if (index == queue->size) index = 0; 00062 queue->pushIndex = index; 00063 00064 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Pushing one entry from queue", queue->popIndex, queue->pushIndex)); 00065 00066 Exit: 00067 return result; 00068 } 00069 00070 00071 int32_t CQueue_Pop(CQueue_t *queue, void **entry) 00072 { 00073 int32_t result = 0; 00074 int16_t index; 00075 00076 if (queue->popIndex == queue->pushIndex) 00077 { 00078 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is empty", queue->popIndex, queue->pushIndex)); 00079 result = -1; 00080 mbedNet_LastError = mbedNetResult_QueueEmpty; 00081 goto Exit; 00082 } 00083 00084 00085 index = queue->popIndex; 00086 *entry = queue->entries[index]; 00087 index++; 00088 if (index == queue->size) index = 0; 00089 queue->popIndex = index; 00090 00091 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Popping one entry from queue", queue->popIndex, queue->pushIndex)); 00092 00093 Exit: 00094 return result; 00095 } 00096 00097 00098 int32_t CQueue_Peek(CQueue_t *queue, void **entry) 00099 { 00100 int32_t result = 0; 00101 int16_t index; 00102 00103 if (queue->popIndex == queue->pushIndex) 00104 { 00105 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Queue is empty", queue->popIndex, queue->pushIndex)); 00106 result = -1; 00107 mbedNet_LastError = mbedNetResult_QueueEmpty; 00108 goto Exit; 00109 } 00110 00111 index = queue->popIndex; 00112 *entry = queue->entries[index]; 00113 00114 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Peeking first entry from queue", queue->popIndex, queue->pushIndex)); 00115 00116 Exit: 00117 return result; 00118 } 00119 00120 00121 int32_t CQueue_Free(CQueue_t *queue) 00122 { 00123 int32_t result = 0; 00124 00125 DEBUG_MODULE(DEBUG_LEVEL_INFO, ("%d-%d Free queue", queue->popIndex, queue->pushIndex)); 00126 free(queue); 00127 00128 return result; 00129 } 00130 00131 00132 Bool_t CQueue_IsEmpty(const CQueue_t *queue) 00133 { 00134 return (queue->popIndex == queue->pushIndex) ? True : False; 00135 } 00136 00137 00138 Bool_t CQueue_IsFull(const CQueue_t *queue) 00139 { 00140 return (queue->popIndex == ((queue->pushIndex + 1) % queue->size)) ? True : False; 00141 } 00142
Generated on Wed Jul 13 2022 06:09:33 by 1.7.2