NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Fri Jun 11 16:05:15 2010 +0000
Revision:
0:632c9925f013
Child:
5:dd63a1e02b1b

        

Who changed what in which revision?

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