From 2a6f04dd16b6076877218b57e2b286f90a22cbad Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 1 Jun 2013 22:08:04 +0200 Subject: [PATCH] use lwip memp pools for allocating coap_queue_t --- lwippools.h | 13 +++++++++++++ net.c | 23 +++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 lwippools.h diff --git a/lwippools.h b/lwippools.h new file mode 100644 index 00000000..39c3f0d7 --- /dev/null +++ b/lwippools.h @@ -0,0 +1,13 @@ +/** Memory pool definitions for the libcoap when used with lwIP (which has its + * own mechanism for quickly allocating chunks of data with known sizes). Has + * to be findable by lwIP (ie. an #include must either directly + * include this or include something more generic which includes this), and + * MEMP_USE_CUSTOM_POOLS has to be set in lwipopts.h. */ + +#include + +#ifndef MEMP_NUM_COAPNODE +#define MEMP_NUM_COAPNODE 4 +#endif + +LWIP_MEMPOOL(COAP_NODE, MEMP_NUM_COAPNODE, sizeof(coap_queue_t), "COAP_NODE") diff --git a/net.c b/net.c index 595e52fe..f1f6d6b3 100644 --- a/net.c +++ b/net.c @@ -40,9 +40,7 @@ #include "encode.h" #include "net.h" -#if defined(WITH_POSIX) || defined(WITH_LWIP) - -/* FIXME: in lwip, we'll use pbufs later */ +#if defined(WITH_POSIX) time_t clock_offset; @@ -55,7 +53,24 @@ static inline void coap_free_node(coap_queue_t *node) { coap_free(node); } -#endif /* WITH_POSIX || WITH_LWIP */ +#endif /* WITH_POSIX */ +#ifdef WITH_LWIP + +#include + +time_t clock_offset; /* FIXME timing is currently ignored */ + +static inline coap_queue_t * +coap_malloc_node() { + return (coap_queue_t *)memp_malloc(MEMP_COAP_NODE); +} + +static inline void +coap_free_node(coap_queue_t *node) { + memp_free(MEMP_COAP_NODE, node); +} + +#endif /* WITH_LWIP */ #ifdef WITH_CONTIKI # ifndef DEBUG # define DEBUG DEBUG_PRINT