Michael Fischler / Mbed 2 deprecated Contest_Winner

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 18:01:31 2011 +0000
Revision:
1:5a7cce9994a3
Parent:
0:d9266031f832

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mafischl 0:d9266031f832 1 /*
mafischl 0:d9266031f832 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mafischl 0:d9266031f832 3 * All rights reserved.
mafischl 0:d9266031f832 4 *
mafischl 0:d9266031f832 5 * Redistribution and use in source and binary forms, with or without modification,
mafischl 0:d9266031f832 6 * are permitted provided that the following conditions are met:
mafischl 0:d9266031f832 7 *
mafischl 0:d9266031f832 8 * 1. Redistributions of source code must retain the above copyright notice,
mafischl 0:d9266031f832 9 * this list of conditions and the following disclaimer.
mafischl 0:d9266031f832 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mafischl 0:d9266031f832 11 * this list of conditions and the following disclaimer in the documentation
mafischl 0:d9266031f832 12 * and/or other materials provided with the distribution.
mafischl 0:d9266031f832 13 * 3. The name of the author may not be used to endorse or promote products
mafischl 0:d9266031f832 14 * derived from this software without specific prior written permission.
mafischl 0:d9266031f832 15 *
mafischl 0:d9266031f832 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mafischl 0:d9266031f832 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mafischl 0:d9266031f832 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mafischl 0:d9266031f832 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mafischl 0:d9266031f832 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mafischl 0:d9266031f832 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mafischl 0:d9266031f832 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mafischl 0:d9266031f832 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mafischl 0:d9266031f832 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mafischl 0:d9266031f832 25 * OF SUCH DAMAGE.
mafischl 0:d9266031f832 26 *
mafischl 0:d9266031f832 27 * This file is part of the lwIP TCP/IP stack.
mafischl 0:d9266031f832 28 *
mafischl 0:d9266031f832 29 * Author: Adam Dunkels <adam@sics.se>
mafischl 0:d9266031f832 30 *
mafischl 0:d9266031f832 31 */
mafischl 0:d9266031f832 32 #ifndef __LWIP_TCPIP_H__
mafischl 0:d9266031f832 33 #define __LWIP_TCPIP_H__
mafischl 0:d9266031f832 34
mafischl 0:d9266031f832 35 #include "lwip/opt.h"
mafischl 0:d9266031f832 36
mafischl 0:d9266031f832 37 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
mafischl 0:d9266031f832 38
mafischl 0:d9266031f832 39 #include "lwip/api_msg.h"
mafischl 0:d9266031f832 40 #include "lwip/netifapi.h"
mafischl 0:d9266031f832 41 #include "lwip/pbuf.h"
mafischl 0:d9266031f832 42 #include "lwip/api.h"
mafischl 0:d9266031f832 43 #include "lwip/sys.h"
mafischl 0:d9266031f832 44 #include "lwip/timers.h"
mafischl 0:d9266031f832 45 #include "lwip/netif.h"
mafischl 0:d9266031f832 46
mafischl 0:d9266031f832 47 #ifdef __cplusplus
mafischl 0:d9266031f832 48 extern "C" {
mafischl 0:d9266031f832 49 #endif
mafischl 0:d9266031f832 50
mafischl 0:d9266031f832 51 /** Define this to something that triggers a watchdog. This is called from
mafischl 0:d9266031f832 52 * tcpip_thread after processing a message. */
mafischl 0:d9266031f832 53 #ifndef LWIP_TCPIP_THREAD_ALIVE
mafischl 0:d9266031f832 54 #define LWIP_TCPIP_THREAD_ALIVE()
mafischl 0:d9266031f832 55 #endif
mafischl 0:d9266031f832 56
mafischl 0:d9266031f832 57 #if LWIP_TCPIP_CORE_LOCKING
mafischl 0:d9266031f832 58 /** The global semaphore to lock the stack. */
mafischl 0:d9266031f832 59 extern sys_mutex_t lock_tcpip_core;
mafischl 0:d9266031f832 60 #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
mafischl 0:d9266031f832 61 #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
mafischl 0:d9266031f832 62 #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
mafischl 0:d9266031f832 63 #define TCPIP_APIMSG_ACK(m)
mafischl 0:d9266031f832 64 #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
mafischl 0:d9266031f832 65 #define TCPIP_NETIFAPI_ACK(m)
mafischl 0:d9266031f832 66 #else /* LWIP_TCPIP_CORE_LOCKING */
mafischl 0:d9266031f832 67 #define LOCK_TCPIP_CORE()
mafischl 0:d9266031f832 68 #define UNLOCK_TCPIP_CORE()
mafischl 0:d9266031f832 69 #define TCPIP_APIMSG(m) tcpip_apimsg(m)
mafischl 0:d9266031f832 70 #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed)
mafischl 0:d9266031f832 71 #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
mafischl 0:d9266031f832 72 #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
mafischl 0:d9266031f832 73 #endif /* LWIP_TCPIP_CORE_LOCKING */
mafischl 0:d9266031f832 74
mafischl 0:d9266031f832 75 /** Function prototype for the init_done function passed to tcpip_init */
mafischl 0:d9266031f832 76 typedef void (*tcpip_init_done_fn)(void *arg);
mafischl 0:d9266031f832 77 /** Function prototype for functions passed to tcpip_callback() */
mafischl 0:d9266031f832 78 typedef void (*tcpip_callback_fn)(void *ctx);
mafischl 0:d9266031f832 79
mafischl 0:d9266031f832 80 void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
mafischl 0:d9266031f832 81
mafischl 0:d9266031f832 82 #if LWIP_NETCONN
mafischl 0:d9266031f832 83 err_t tcpip_apimsg(struct api_msg *apimsg);
mafischl 0:d9266031f832 84 #if LWIP_TCPIP_CORE_LOCKING
mafischl 0:d9266031f832 85 err_t tcpip_apimsg_lock(struct api_msg *apimsg);
mafischl 0:d9266031f832 86 #endif /* LWIP_TCPIP_CORE_LOCKING */
mafischl 0:d9266031f832 87 #endif /* LWIP_NETCONN */
mafischl 0:d9266031f832 88
mafischl 0:d9266031f832 89 err_t tcpip_input(struct pbuf *p, struct netif *inp);
mafischl 0:d9266031f832 90
mafischl 0:d9266031f832 91 #if LWIP_NETIF_API
mafischl 0:d9266031f832 92 err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
mafischl 0:d9266031f832 93 #if LWIP_TCPIP_CORE_LOCKING
mafischl 0:d9266031f832 94 err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
mafischl 0:d9266031f832 95 #endif /* LWIP_TCPIP_CORE_LOCKING */
mafischl 0:d9266031f832 96 #endif /* LWIP_NETIF_API */
mafischl 0:d9266031f832 97
mafischl 0:d9266031f832 98 err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block);
mafischl 0:d9266031f832 99 #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
mafischl 0:d9266031f832 100
mafischl 0:d9266031f832 101 /* free pbufs or heap memory from another context without blocking */
mafischl 0:d9266031f832 102 err_t pbuf_free_callback(struct pbuf *p);
mafischl 0:d9266031f832 103 err_t mem_free_callback(void *m);
mafischl 0:d9266031f832 104
mafischl 0:d9266031f832 105 #if LWIP_TCPIP_TIMEOUT
mafischl 0:d9266031f832 106 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
mafischl 0:d9266031f832 107 err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
mafischl 0:d9266031f832 108 #endif /* LWIP_TCPIP_TIMEOUT */
mafischl 0:d9266031f832 109
mafischl 0:d9266031f832 110 enum tcpip_msg_type {
mafischl 0:d9266031f832 111 #if LWIP_NETCONN
mafischl 0:d9266031f832 112 TCPIP_MSG_API,
mafischl 0:d9266031f832 113 #endif /* LWIP_NETCONN */
mafischl 0:d9266031f832 114 TCPIP_MSG_INPKT,
mafischl 0:d9266031f832 115 #if LWIP_NETIF_API
mafischl 0:d9266031f832 116 TCPIP_MSG_NETIFAPI,
mafischl 0:d9266031f832 117 #endif /* LWIP_NETIF_API */
mafischl 0:d9266031f832 118 #if LWIP_TCPIP_TIMEOUT
mafischl 0:d9266031f832 119 TCPIP_MSG_TIMEOUT,
mafischl 0:d9266031f832 120 TCPIP_MSG_UNTIMEOUT,
mafischl 0:d9266031f832 121 #endif /* LWIP_TCPIP_TIMEOUT */
mafischl 0:d9266031f832 122 TCPIP_MSG_CALLBACK
mafischl 0:d9266031f832 123 };
mafischl 0:d9266031f832 124
mafischl 0:d9266031f832 125 struct tcpip_msg {
mafischl 0:d9266031f832 126 enum tcpip_msg_type type;
mafischl 0:d9266031f832 127 sys_sem_t *sem;
mafischl 0:d9266031f832 128 union {
mafischl 0:d9266031f832 129 #if LWIP_NETCONN
mafischl 0:d9266031f832 130 struct api_msg *apimsg;
mafischl 0:d9266031f832 131 #endif /* LWIP_NETCONN */
mafischl 0:d9266031f832 132 #if LWIP_NETIF_API
mafischl 0:d9266031f832 133 struct netifapi_msg *netifapimsg;
mafischl 0:d9266031f832 134 #endif /* LWIP_NETIF_API */
mafischl 0:d9266031f832 135 struct {
mafischl 0:d9266031f832 136 struct pbuf *p;
mafischl 0:d9266031f832 137 struct netif *netif;
mafischl 0:d9266031f832 138 } inp;
mafischl 0:d9266031f832 139 struct {
mafischl 0:d9266031f832 140 tcpip_callback_fn function;
mafischl 0:d9266031f832 141 void *ctx;
mafischl 0:d9266031f832 142 } cb;
mafischl 0:d9266031f832 143 #if LWIP_TCPIP_TIMEOUT
mafischl 0:d9266031f832 144 struct {
mafischl 0:d9266031f832 145 u32_t msecs;
mafischl 0:d9266031f832 146 sys_timeout_handler h;
mafischl 0:d9266031f832 147 void *arg;
mafischl 0:d9266031f832 148 } tmo;
mafischl 0:d9266031f832 149 #endif /* LWIP_TCPIP_TIMEOUT */
mafischl 0:d9266031f832 150 } msg;
mafischl 0:d9266031f832 151 };
mafischl 0:d9266031f832 152
mafischl 0:d9266031f832 153 #ifdef __cplusplus
mafischl 0:d9266031f832 154 }
mafischl 0:d9266031f832 155 #endif
mafischl 0:d9266031f832 156
mafischl 0:d9266031f832 157 #endif /* !NO_SYS */
mafischl 0:d9266031f832 158
mafischl 0:d9266031f832 159 #endif /* __LWIP_TCPIP_H__ */