Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed

Dependencies:   mbed

Committer:
pehrhovey
Date:
Sun Mar 14 00:54:12 2010 +0000
Revision:
0:a548a085de55

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pehrhovey 0:a548a085de55 1 /*
pehrhovey 0:a548a085de55 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
pehrhovey 0:a548a085de55 3 * All rights reserved.
pehrhovey 0:a548a085de55 4 *
pehrhovey 0:a548a085de55 5 * Redistribution and use in source and binary forms, with or without modification,
pehrhovey 0:a548a085de55 6 * are permitted provided that the following conditions are met:
pehrhovey 0:a548a085de55 7 *
pehrhovey 0:a548a085de55 8 * 1. Redistributions of source code must retain the above copyright notice,
pehrhovey 0:a548a085de55 9 * this list of conditions and the following disclaimer.
pehrhovey 0:a548a085de55 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
pehrhovey 0:a548a085de55 11 * this list of conditions and the following disclaimer in the documentation
pehrhovey 0:a548a085de55 12 * and/or other materials provided with the distribution.
pehrhovey 0:a548a085de55 13 * 3. The name of the author may not be used to endorse or promote products
pehrhovey 0:a548a085de55 14 * derived from this software without specific prior written permission.
pehrhovey 0:a548a085de55 15 *
pehrhovey 0:a548a085de55 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
pehrhovey 0:a548a085de55 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
pehrhovey 0:a548a085de55 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
pehrhovey 0:a548a085de55 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
pehrhovey 0:a548a085de55 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
pehrhovey 0:a548a085de55 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
pehrhovey 0:a548a085de55 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
pehrhovey 0:a548a085de55 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
pehrhovey 0:a548a085de55 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
pehrhovey 0:a548a085de55 25 * OF SUCH DAMAGE.
pehrhovey 0:a548a085de55 26 *
pehrhovey 0:a548a085de55 27 * This file is part of the lwIP TCP/IP stack.
pehrhovey 0:a548a085de55 28 *
pehrhovey 0:a548a085de55 29 * Author: Adam Dunkels <adam@sics.se>
pehrhovey 0:a548a085de55 30 *
pehrhovey 0:a548a085de55 31 */
pehrhovey 0:a548a085de55 32
pehrhovey 0:a548a085de55 33 #ifndef __LWIP_MEMP_H__
pehrhovey 0:a548a085de55 34 #define __LWIP_MEMP_H__
pehrhovey 0:a548a085de55 35
pehrhovey 0:a548a085de55 36 #include "lwip/opt.h"
pehrhovey 0:a548a085de55 37
pehrhovey 0:a548a085de55 38 #ifdef __cplusplus
pehrhovey 0:a548a085de55 39 extern "C" {
pehrhovey 0:a548a085de55 40 #endif
pehrhovey 0:a548a085de55 41
pehrhovey 0:a548a085de55 42 /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
pehrhovey 0:a548a085de55 43 typedef enum {
pehrhovey 0:a548a085de55 44 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
pehrhovey 0:a548a085de55 45 #include "lwip/memp_std.h"
pehrhovey 0:a548a085de55 46 MEMP_MAX
pehrhovey 0:a548a085de55 47 } memp_t;
pehrhovey 0:a548a085de55 48
pehrhovey 0:a548a085de55 49 #if MEM_USE_POOLS
pehrhovey 0:a548a085de55 50 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
pehrhovey 0:a548a085de55 51 typedef enum {
pehrhovey 0:a548a085de55 52 /* Get the first (via:
pehrhovey 0:a548a085de55 53 MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
pehrhovey 0:a548a085de55 54 MEMP_POOL_HELPER_FIRST = ((u8_t)
pehrhovey 0:a548a085de55 55 #define LWIP_MEMPOOL(name,num,size,desc)
pehrhovey 0:a548a085de55 56 #define LWIP_MALLOC_MEMPOOL_START 1
pehrhovey 0:a548a085de55 57 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
pehrhovey 0:a548a085de55 58 #define LWIP_MALLOC_MEMPOOL_END
pehrhovey 0:a548a085de55 59 #include "lwip/memp_std.h"
pehrhovey 0:a548a085de55 60 ) ,
pehrhovey 0:a548a085de55 61 /* Get the last (via:
pehrhovey 0:a548a085de55 62 MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
pehrhovey 0:a548a085de55 63 MEMP_POOL_HELPER_LAST = ((u8_t)
pehrhovey 0:a548a085de55 64 #define LWIP_MEMPOOL(name,num,size,desc)
pehrhovey 0:a548a085de55 65 #define LWIP_MALLOC_MEMPOOL_START
pehrhovey 0:a548a085de55 66 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
pehrhovey 0:a548a085de55 67 #define LWIP_MALLOC_MEMPOOL_END 1
pehrhovey 0:a548a085de55 68 #include "lwip/memp_std.h"
pehrhovey 0:a548a085de55 69 )
pehrhovey 0:a548a085de55 70 } memp_pool_helper_t;
pehrhovey 0:a548a085de55 71
pehrhovey 0:a548a085de55 72 /* The actual start and stop values are here (cast them over)
pehrhovey 0:a548a085de55 73 We use this helper type and these defines so we can avoid using const memp_t values */
pehrhovey 0:a548a085de55 74 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
pehrhovey 0:a548a085de55 75 #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST)
pehrhovey 0:a548a085de55 76 #endif /* MEM_USE_POOLS */
pehrhovey 0:a548a085de55 77
pehrhovey 0:a548a085de55 78 #if MEMP_MEM_MALLOC || MEM_USE_POOLS
pehrhovey 0:a548a085de55 79 extern const u16_t memp_sizes[MEMP_MAX];
pehrhovey 0:a548a085de55 80 #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
pehrhovey 0:a548a085de55 81
pehrhovey 0:a548a085de55 82 #if MEMP_MEM_MALLOC
pehrhovey 0:a548a085de55 83
pehrhovey 0:a548a085de55 84 #include "mem.h"
pehrhovey 0:a548a085de55 85
pehrhovey 0:a548a085de55 86 #define memp_init()
pehrhovey 0:a548a085de55 87 #define memp_malloc(type) mem_malloc(memp_sizes[type])
pehrhovey 0:a548a085de55 88 #define memp_free(type, mem) mem_free(mem)
pehrhovey 0:a548a085de55 89
pehrhovey 0:a548a085de55 90 #else /* MEMP_MEM_MALLOC */
pehrhovey 0:a548a085de55 91
pehrhovey 0:a548a085de55 92 #if MEM_USE_POOLS
pehrhovey 0:a548a085de55 93 /** This structure is used to save the pool one element came from. */
pehrhovey 0:a548a085de55 94 struct memp_malloc_helper
pehrhovey 0:a548a085de55 95 {
pehrhovey 0:a548a085de55 96 memp_t poolnr;
pehrhovey 0:a548a085de55 97 };
pehrhovey 0:a548a085de55 98 #endif /* MEM_USE_POOLS */
pehrhovey 0:a548a085de55 99
pehrhovey 0:a548a085de55 100 void memp_init(void);
pehrhovey 0:a548a085de55 101
pehrhovey 0:a548a085de55 102 #if MEMP_OVERFLOW_CHECK
pehrhovey 0:a548a085de55 103 void *memp_malloc_fn(memp_t type, const char* file, const int line);
pehrhovey 0:a548a085de55 104 #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
pehrhovey 0:a548a085de55 105 #else
pehrhovey 0:a548a085de55 106 void *memp_malloc(memp_t type);
pehrhovey 0:a548a085de55 107 #endif
pehrhovey 0:a548a085de55 108 void memp_free(memp_t type, void *mem);
pehrhovey 0:a548a085de55 109
pehrhovey 0:a548a085de55 110 #endif /* MEMP_MEM_MALLOC */
pehrhovey 0:a548a085de55 111
pehrhovey 0:a548a085de55 112 #ifdef __cplusplus
pehrhovey 0:a548a085de55 113 }
pehrhovey 0:a548a085de55 114 #endif
pehrhovey 0:a548a085de55 115
pehrhovey 0:a548a085de55 116 #endif /* __LWIP_MEMP_H__ */