uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Mon Jun 30 16:00:08 2014 +0000
Revision:
3:a2715e9c7737
Parent:
0:685224d2f66d
backported from Contiki 2.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:685224d2f66d 1 /*
ban4jp 0:685224d2f66d 2 * Copyright (c) 2004, Swedish Institute of Computer Science.
ban4jp 0:685224d2f66d 3 * All rights reserved.
ban4jp 0:685224d2f66d 4 *
ban4jp 0:685224d2f66d 5 * Redistribution and use in source and binary forms, with or without
ban4jp 0:685224d2f66d 6 * modification, are permitted provided that the following conditions
ban4jp 0:685224d2f66d 7 * are met:
ban4jp 0:685224d2f66d 8 * 1. Redistributions of source code must retain the above copyright
ban4jp 0:685224d2f66d 9 * notice, this list of conditions and the following disclaimer.
ban4jp 0:685224d2f66d 10 * 2. Redistributions in binary form must reproduce the above copyright
ban4jp 0:685224d2f66d 11 * notice, this list of conditions and the following disclaimer in the
ban4jp 0:685224d2f66d 12 * documentation and/or other materials provided with the distribution.
ban4jp 0:685224d2f66d 13 * 3. Neither the name of the Institute nor the names of its contributors
ban4jp 0:685224d2f66d 14 * may be used to endorse or promote products derived from this software
ban4jp 0:685224d2f66d 15 * without specific prior written permission.
ban4jp 0:685224d2f66d 16 *
ban4jp 0:685224d2f66d 17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
ban4jp 0:685224d2f66d 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ban4jp 0:685224d2f66d 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ban4jp 0:685224d2f66d 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
ban4jp 0:685224d2f66d 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ban4jp 0:685224d2f66d 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ban4jp 0:685224d2f66d 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ban4jp 0:685224d2f66d 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ban4jp 0:685224d2f66d 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ban4jp 0:685224d2f66d 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ban4jp 0:685224d2f66d 27 * SUCH DAMAGE.
ban4jp 0:685224d2f66d 28 *
ban4jp 0:685224d2f66d 29 * This file is part of the uIP TCP/IP stack
ban4jp 0:685224d2f66d 30 *
ban4jp 0:685224d2f66d 31 * Author: Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 32 *
ban4jp 0:685224d2f66d 33 * $Id: memb.h,v 1.1 2006/06/12 08:21:43 adam Exp $
ban4jp 0:685224d2f66d 34 */
ban4jp 0:685224d2f66d 35
ban4jp 0:685224d2f66d 36 /**
ban4jp 0:685224d2f66d 37 * \defgroup memb Memory block management functions
ban4jp 0:685224d2f66d 38 *
ban4jp 0:685224d2f66d 39 * The memory block allocation routines provide a simple yet powerful
ban4jp 0:685224d2f66d 40 * set of functions for managing a set of memory blocks of fixed
ban4jp 0:685224d2f66d 41 * size. A set of memory blocks is statically declared with the
ban4jp 0:685224d2f66d 42 * MEMB() macro. Memory blocks are allocated from the declared
ban4jp 0:685224d2f66d 43 * memory by the memb_alloc() function, and are deallocated with the
ban4jp 0:685224d2f66d 44 * memb_free() function.
ban4jp 0:685224d2f66d 45 *
ban4jp 0:685224d2f66d 46 * \note Because of namespace clashes only one MEMB() can be
ban4jp 0:685224d2f66d 47 * declared per C module, and the name scope of a MEMB() memory
ban4jp 0:685224d2f66d 48 * block is local to each C module.
ban4jp 0:685224d2f66d 49 *
ban4jp 0:685224d2f66d 50 * The following example shows how to declare and use a memory block
ban4jp 0:685224d2f66d 51 * called "cmem" which has 8 chunks of memory with each memory chunk
ban4jp 0:685224d2f66d 52 * being 20 bytes large.
ban4jp 0:685224d2f66d 53 *
ban4jp 0:685224d2f66d 54 * @{
ban4jp 0:685224d2f66d 55 */
ban4jp 0:685224d2f66d 56
ban4jp 0:685224d2f66d 57
ban4jp 0:685224d2f66d 58 /**
ban4jp 0:685224d2f66d 59 * \file
ban4jp 0:685224d2f66d 60 * Memory block allocation routines.
ban4jp 0:685224d2f66d 61 * \author
ban4jp 0:685224d2f66d 62 * Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 63 *
ban4jp 0:685224d2f66d 64 */
ban4jp 0:685224d2f66d 65
ban4jp 0:685224d2f66d 66 #ifndef __MEMB_H__
ban4jp 0:685224d2f66d 67 #define __MEMB_H__
ban4jp 0:685224d2f66d 68
ban4jp 0:685224d2f66d 69 /*
ban4jp 0:685224d2f66d 70 * Here we define a C preprocessing macro for concatenating to
ban4jp 0:685224d2f66d 71 * strings. We need use two macros in order to allow concatenation of
ban4jp 0:685224d2f66d 72 * two #defined macros.
ban4jp 0:685224d2f66d 73 */
ban4jp 0:685224d2f66d 74 #define MEMB_CONCAT2(s1, s2) s1##s2
ban4jp 0:685224d2f66d 75 #define MEMB_CONCAT(s1, s2) MEMB_CONCAT2(s1, s2)
ban4jp 0:685224d2f66d 76
ban4jp 0:685224d2f66d 77 /**
ban4jp 0:685224d2f66d 78 * Declare a memory block.
ban4jp 0:685224d2f66d 79 *
ban4jp 0:685224d2f66d 80 * This macro is used to staticall declare a block of memory that can
ban4jp 0:685224d2f66d 81 * be used by the block allocation functions. The macro statically
ban4jp 0:685224d2f66d 82 * declares a C array with a size that matches the specified number of
ban4jp 0:685224d2f66d 83 * blocks and their individual sizes.
ban4jp 0:685224d2f66d 84 *
ban4jp 0:685224d2f66d 85 * Example:
ban4jp 0:685224d2f66d 86 \code
ban4jp 0:685224d2f66d 87 MEMB(connections, sizeof(struct connection), 16);
ban4jp 0:685224d2f66d 88 \endcode
ban4jp 0:685224d2f66d 89 *
ban4jp 0:685224d2f66d 90 * \param name The name of the memory block (later used with
ban4jp 0:685224d2f66d 91 * memb_init(), memb_alloc() and memb_free()).
ban4jp 0:685224d2f66d 92 *
ban4jp 0:685224d2f66d 93 * \param size The size of each memory chunk, in bytes.
ban4jp 0:685224d2f66d 94 *
ban4jp 0:685224d2f66d 95 * \param num The total number of memory chunks in the block.
ban4jp 0:685224d2f66d 96 *
ban4jp 0:685224d2f66d 97 */
ban4jp 0:685224d2f66d 98 #define MEMB(name, structure, num) \
ban4jp 0:685224d2f66d 99 static char MEMB_CONCAT(name,_memb_count)[num]; \
ban4jp 0:685224d2f66d 100 static structure MEMB_CONCAT(name,_memb_mem)[num]; \
ban4jp 0:685224d2f66d 101 static struct memb_blocks name = {sizeof(structure), num, \
ban4jp 0:685224d2f66d 102 MEMB_CONCAT(name,_memb_count), \
ban4jp 0:685224d2f66d 103 (void *)MEMB_CONCAT(name,_memb_mem)}
ban4jp 0:685224d2f66d 104
ban4jp 0:685224d2f66d 105 struct memb_blocks {
ban4jp 0:685224d2f66d 106 unsigned short size;
ban4jp 0:685224d2f66d 107 unsigned short num;
ban4jp 0:685224d2f66d 108 char *count;
ban4jp 0:685224d2f66d 109 void *mem;
ban4jp 0:685224d2f66d 110 };
ban4jp 0:685224d2f66d 111
ban4jp 0:685224d2f66d 112 /**
ban4jp 0:685224d2f66d 113 * Initialize a memory block that was declared with MEMB().
ban4jp 0:685224d2f66d 114 *
ban4jp 0:685224d2f66d 115 * \param m A memory block previosly declared with MEMB().
ban4jp 0:685224d2f66d 116 */
ban4jp 0:685224d2f66d 117 void memb_init(struct memb_blocks *m);
ban4jp 0:685224d2f66d 118
ban4jp 0:685224d2f66d 119 /**
ban4jp 0:685224d2f66d 120 * Allocate a memory block from a block of memory declared with MEMB().
ban4jp 0:685224d2f66d 121 *
ban4jp 0:685224d2f66d 122 * \param m A memory block previosly declared with MEMB().
ban4jp 0:685224d2f66d 123 */
ban4jp 0:685224d2f66d 124 void *memb_alloc(struct memb_blocks *m);
ban4jp 0:685224d2f66d 125
ban4jp 0:685224d2f66d 126 /**
ban4jp 0:685224d2f66d 127 * Deallocate a memory block from a memory block previously declared
ban4jp 0:685224d2f66d 128 * with MEMB().
ban4jp 0:685224d2f66d 129 *
ban4jp 0:685224d2f66d 130 * \param m m A memory block previosly declared with MEMB().
ban4jp 0:685224d2f66d 131 *
ban4jp 0:685224d2f66d 132 * \param ptr A pointer to the memory block that is to be deallocated.
ban4jp 0:685224d2f66d 133 *
ban4jp 0:685224d2f66d 134 * \return The new reference count for the memory block (should be 0
ban4jp 0:685224d2f66d 135 * if successfully deallocated) or -1 if the pointer "ptr" did not
ban4jp 0:685224d2f66d 136 * point to a legal memory block.
ban4jp 0:685224d2f66d 137 */
ban4jp 0:685224d2f66d 138 char memb_free(struct memb_blocks *m, void *ptr);
ban4jp 0:685224d2f66d 139
ban4jp 0:685224d2f66d 140 /** @} */
ban4jp 0:685224d2f66d 141
ban4jp 0:685224d2f66d 142 #endif /* __MEMB_H__ */