Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32 #ifndef __LWIP_SYS_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_SYS_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #ifdef __cplusplus
hlipka 0:8b387bed54c2 38 extern "C" {
hlipka 0:8b387bed54c2 39 #endif
hlipka 0:8b387bed54c2 40
hlipka 0:8b387bed54c2 41 #if NO_SYS
hlipka 0:8b387bed54c2 42
hlipka 0:8b387bed54c2 43 /* For a totally minimal and standalone system, we provide null
hlipka 0:8b387bed54c2 44 definitions of the sys_ functions. */
hlipka 0:8b387bed54c2 45 typedef u8_t sys_sem_t;
hlipka 0:8b387bed54c2 46 typedef u8_t sys_mutex_t;
hlipka 0:8b387bed54c2 47 typedef u8_t sys_mbox_t;
hlipka 0:8b387bed54c2 48
hlipka 0:8b387bed54c2 49 #define sys_sem_new(s, c) ERR_OK
hlipka 0:8b387bed54c2 50 #define sys_sem_signal(s)
hlipka 0:8b387bed54c2 51 #define sys_sem_wait(s)
hlipka 0:8b387bed54c2 52 #define sys_arch_sem_wait(s,t)
hlipka 0:8b387bed54c2 53 #define sys_sem_free(s)
hlipka 0:8b387bed54c2 54 #define sys_mutex_new(mu) ERR_OK
hlipka 0:8b387bed54c2 55 #define sys_mutex_lock(mu)
hlipka 0:8b387bed54c2 56 #define sys_mutex_unlock(mu)
hlipka 0:8b387bed54c2 57 #define sys_mutex_free(mu)
hlipka 0:8b387bed54c2 58 #define sys_mbox_new(m, s) ERR_OK
hlipka 0:8b387bed54c2 59 #define sys_mbox_fetch(m,d)
hlipka 0:8b387bed54c2 60 #define sys_mbox_tryfetch(m,d)
hlipka 0:8b387bed54c2 61 #define sys_mbox_post(m,d)
hlipka 0:8b387bed54c2 62 #define sys_mbox_trypost(m,d)
hlipka 0:8b387bed54c2 63 #define sys_mbox_free(m)
hlipka 0:8b387bed54c2 64
hlipka 0:8b387bed54c2 65 #define sys_thread_new(n,t,a,s,p)
hlipka 0:8b387bed54c2 66
hlipka 0:8b387bed54c2 67 #define sys_msleep(t)
hlipka 0:8b387bed54c2 68
hlipka 0:8b387bed54c2 69 #else /* NO_SYS */
hlipka 0:8b387bed54c2 70
hlipka 0:8b387bed54c2 71 /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */
hlipka 0:8b387bed54c2 72 #define SYS_ARCH_TIMEOUT 0xffffffffUL
hlipka 0:8b387bed54c2 73
hlipka 0:8b387bed54c2 74 /** sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate.
hlipka 0:8b387bed54c2 75 * For now we use the same magic value, but we allow this to change in future.
hlipka 0:8b387bed54c2 76 */
hlipka 0:8b387bed54c2 77 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
hlipka 0:8b387bed54c2 78
hlipka 0:8b387bed54c2 79 #include "lwip/err.h"
hlipka 0:8b387bed54c2 80 #include "arch/sys_arch.h"
hlipka 0:8b387bed54c2 81
hlipka 0:8b387bed54c2 82 /** Function prototype for thread functions */
hlipka 0:8b387bed54c2 83 typedef void (*lwip_thread_fn)(void *arg);
hlipka 0:8b387bed54c2 84
hlipka 0:8b387bed54c2 85 /* Function prototypes for functions to be implemented by platform ports
hlipka 0:8b387bed54c2 86 (in sys_arch.c) */
hlipka 0:8b387bed54c2 87
hlipka 0:8b387bed54c2 88 /* Mutex functions: */
hlipka 0:8b387bed54c2 89
hlipka 0:8b387bed54c2 90 /** Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores
hlipka 0:8b387bed54c2 91 should be used instead */
hlipka 0:8b387bed54c2 92 #if LWIP_COMPAT_MUTEX
hlipka 0:8b387bed54c2 93 /* for old ports that don't have mutexes: define them to binary semaphores */
hlipka 0:8b387bed54c2 94 #define sys_mutex_t sys_sem_t
hlipka 0:8b387bed54c2 95 #define sys_mutex_new(mutex) sys_sem_new(mutex, 1)
hlipka 0:8b387bed54c2 96 #define sys_mutex_lock(mutex) sys_sem_wait(mutex)
hlipka 0:8b387bed54c2 97 #define sys_mutex_unlock(mutex) sys_sem_signal(mutex)
hlipka 0:8b387bed54c2 98 #define sys_mutex_free(mutex) sys_sem_free(mutex)
hlipka 0:8b387bed54c2 99 #define sys_mutex_valid(mutex) sys_sem_valid(mutex)
hlipka 0:8b387bed54c2 100 #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex)
hlipka 0:8b387bed54c2 101
hlipka 0:8b387bed54c2 102 #else /* LWIP_COMPAT_MUTEX */
hlipka 0:8b387bed54c2 103
hlipka 0:8b387bed54c2 104 /** Create a new mutex
hlipka 0:8b387bed54c2 105 * @param mutex pointer to the mutex to create
hlipka 0:8b387bed54c2 106 * @return a new mutex */
hlipka 0:8b387bed54c2 107 err_t sys_mutex_new(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 108 /** Lock a mutex
hlipka 0:8b387bed54c2 109 * @param mutex the mutex to lock */
hlipka 0:8b387bed54c2 110 void sys_mutex_lock(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 111 /** Unlock a mutex
hlipka 0:8b387bed54c2 112 * @param mutex the mutex to unlock */
hlipka 0:8b387bed54c2 113 void sys_mutex_unlock(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 114 /** Delete a semaphore
hlipka 0:8b387bed54c2 115 * @param mutex the mutex to delete */
hlipka 0:8b387bed54c2 116 void sys_mutex_free(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 117 #ifndef sys_mutex_valid
hlipka 0:8b387bed54c2 118 /** Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid */
hlipka 0:8b387bed54c2 119 int sys_mutex_valid(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 120 #endif
hlipka 0:8b387bed54c2 121 #ifndef sys_mutex_set_invalid
hlipka 0:8b387bed54c2 122 /** Set a mutex invalid so that sys_mutex_valid returns 0 */
hlipka 0:8b387bed54c2 123 void sys_mutex_set_invalid(sys_mutex_t *mutex);
hlipka 0:8b387bed54c2 124 #endif
hlipka 0:8b387bed54c2 125 #endif /* LWIP_COMPAT_MUTEX */
hlipka 0:8b387bed54c2 126
hlipka 0:8b387bed54c2 127 /* Semaphore functions: */
hlipka 0:8b387bed54c2 128
hlipka 0:8b387bed54c2 129 /** Create a new semaphore
hlipka 0:8b387bed54c2 130 * @param sem pointer to the semaphore to create
hlipka 0:8b387bed54c2 131 * @param count initial count of the semaphore
hlipka 0:8b387bed54c2 132 * @return ERR_OK if successful, another err_t otherwise */
hlipka 0:8b387bed54c2 133 err_t sys_sem_new(sys_sem_t *sem, u8_t count);
hlipka 0:8b387bed54c2 134 /** Signals a semaphore
hlipka 0:8b387bed54c2 135 * @param sem the semaphore to signal */
hlipka 0:8b387bed54c2 136 void sys_sem_signal(sys_sem_t *sem);
hlipka 0:8b387bed54c2 137 /** Wait for a semaphore for the specified timeout
hlipka 0:8b387bed54c2 138 * @param sem the semaphore to wait for
hlipka 0:8b387bed54c2 139 * @param timeout timeout in milliseconds to wait (0 = wait forever)
hlipka 0:8b387bed54c2 140 * @return time (in milliseconds) waited for the semaphore
hlipka 0:8b387bed54c2 141 * or SYS_ARCH_TIMEOUT on timeout */
hlipka 0:8b387bed54c2 142 u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout);
hlipka 0:8b387bed54c2 143 /** Delete a semaphore
hlipka 0:8b387bed54c2 144 * @param sem semaphore to delete */
hlipka 0:8b387bed54c2 145 void sys_sem_free(sys_sem_t *sem);
hlipka 0:8b387bed54c2 146 /** Wait for a semaphore - forever/no timeout */
hlipka 0:8b387bed54c2 147 #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
hlipka 0:8b387bed54c2 148 #ifndef sys_sem_valid
hlipka 0:8b387bed54c2 149 /** Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid */
hlipka 0:8b387bed54c2 150 int sys_sem_valid(sys_sem_t *sem);
hlipka 0:8b387bed54c2 151 #endif
hlipka 0:8b387bed54c2 152 #ifndef sys_sem_set_invalid
hlipka 0:8b387bed54c2 153 /** Set a semaphore invalid so that sys_sem_valid returns 0 */
hlipka 0:8b387bed54c2 154 void sys_sem_set_invalid(sys_sem_t *sem);
hlipka 0:8b387bed54c2 155 #endif
hlipka 0:8b387bed54c2 156
hlipka 0:8b387bed54c2 157 /* Time functions. */
hlipka 0:8b387bed54c2 158 #ifndef sys_msleep
hlipka 0:8b387bed54c2 159 void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
hlipka 0:8b387bed54c2 160 #endif
hlipka 0:8b387bed54c2 161
hlipka 0:8b387bed54c2 162 /* Mailbox functions. */
hlipka 0:8b387bed54c2 163
hlipka 0:8b387bed54c2 164 /** Create a new mbox of specified size
hlipka 0:8b387bed54c2 165 * @param mbox pointer to the mbox to create
hlipka 0:8b387bed54c2 166 * @param size (miminum) number of messages in this mbox
hlipka 0:8b387bed54c2 167 * @return ERR_OK if successful, another err_t otherwise */
hlipka 0:8b387bed54c2 168 err_t sys_mbox_new(sys_mbox_t *mbox, int size);
hlipka 0:8b387bed54c2 169 /** Post a message to an mbox - may not fail
hlipka 0:8b387bed54c2 170 * -> blocks if full, only used from tasks not from ISR
hlipka 0:8b387bed54c2 171 * @param mbox mbox to posts the message
hlipka 0:8b387bed54c2 172 * @param msg message to post (ATTENTION: can be NULL) */
hlipka 0:8b387bed54c2 173 void sys_mbox_post(sys_mbox_t *mbox, void *msg);
hlipka 0:8b387bed54c2 174 /** Try to post a message to an mbox - may fail if full or ISR
hlipka 0:8b387bed54c2 175 * @param mbox mbox to posts the message
hlipka 0:8b387bed54c2 176 * @param msg message to post (ATTENTION: can be NULL) */
hlipka 0:8b387bed54c2 177 err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg);
hlipka 0:8b387bed54c2 178 /** Wait for a new message to arrive in the mbox
hlipka 0:8b387bed54c2 179 * @param mbox mbox to get a message from
hlipka 0:8b387bed54c2 180 * @param msg pointer where the message is stored
hlipka 0:8b387bed54c2 181 * @param timeout maximum time (in milliseconds) to wait for a message
hlipka 0:8b387bed54c2 182 * @return time (in milliseconds) waited for a message, may be 0 if not waited
hlipka 0:8b387bed54c2 183 or SYS_ARCH_TIMEOUT on timeout
hlipka 0:8b387bed54c2 184 * The returned time has to be accurate to prevent timer jitter! */
hlipka 0:8b387bed54c2 185 u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout);
hlipka 0:8b387bed54c2 186 /* Allow port to override with a macro, e.g. special timout for sys_arch_mbox_fetch() */
hlipka 0:8b387bed54c2 187 #ifndef sys_arch_mbox_tryfetch
hlipka 0:8b387bed54c2 188 /** Wait for a new message to arrive in the mbox
hlipka 0:8b387bed54c2 189 * @param mbox mbox to get a message from
hlipka 0:8b387bed54c2 190 * @param msg pointer where the message is stored
hlipka 0:8b387bed54c2 191 * @param timeout maximum time (in milliseconds) to wait for a message
hlipka 0:8b387bed54c2 192 * @return 0 (milliseconds) if a message has been received
hlipka 0:8b387bed54c2 193 * or SYS_MBOX_EMPTY if the mailbox is empty */
hlipka 0:8b387bed54c2 194 u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg);
hlipka 0:8b387bed54c2 195 #endif
hlipka 0:8b387bed54c2 196 /** For now, we map straight to sys_arch implementation. */
hlipka 0:8b387bed54c2 197 #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
hlipka 0:8b387bed54c2 198 /** Delete an mbox
hlipka 0:8b387bed54c2 199 * @param mbox mbox to delete */
hlipka 0:8b387bed54c2 200 void sys_mbox_free(sys_mbox_t *mbox);
hlipka 0:8b387bed54c2 201 #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
hlipka 0:8b387bed54c2 202 #ifndef sys_mbox_valid
hlipka 0:8b387bed54c2 203 /** Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid */
hlipka 0:8b387bed54c2 204 int sys_mbox_valid(sys_mbox_t *mbox);
hlipka 0:8b387bed54c2 205 #endif
hlipka 0:8b387bed54c2 206 #ifndef sys_mbox_set_invalid
hlipka 0:8b387bed54c2 207 /** Set an mbox invalid so that sys_mbox_valid returns 0 */
hlipka 0:8b387bed54c2 208 void sys_mbox_set_invalid(sys_mbox_t *mbox);
hlipka 0:8b387bed54c2 209 #endif
hlipka 0:8b387bed54c2 210
hlipka 0:8b387bed54c2 211 /** The only thread function:
hlipka 0:8b387bed54c2 212 * Creates a new thread
hlipka 0:8b387bed54c2 213 * @param name human-readable name for the thread (used for debugging purposes)
hlipka 0:8b387bed54c2 214 * @param thread thread-function
hlipka 0:8b387bed54c2 215 * @param arg parameter passed to 'thread'
hlipka 0:8b387bed54c2 216 * @param stacksize stack size in bytes for the new thread (may be ignored by ports)
hlipka 0:8b387bed54c2 217 * @param prio priority of the new thread (may be ignored by ports) */
hlipka 0:8b387bed54c2 218 sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio);
hlipka 0:8b387bed54c2 219
hlipka 0:8b387bed54c2 220 #endif /* NO_SYS */
hlipka 0:8b387bed54c2 221
hlipka 0:8b387bed54c2 222 /* sys_init() must be called before anthing else. */
hlipka 0:8b387bed54c2 223 void sys_init(void);
hlipka 0:8b387bed54c2 224
hlipka 0:8b387bed54c2 225 #ifndef sys_jiffies
hlipka 0:8b387bed54c2 226 /** Ticks/jiffies since power up. */
hlipka 0:8b387bed54c2 227 u32_t sys_jiffies(void);
hlipka 0:8b387bed54c2 228 #endif
hlipka 0:8b387bed54c2 229
hlipka 0:8b387bed54c2 230 /** Returns the current time in milliseconds,
hlipka 0:8b387bed54c2 231 * may be the same as sys_jiffies or at least based on it. */
hlipka 0:8b387bed54c2 232 u32_t sys_now(void);
hlipka 0:8b387bed54c2 233
hlipka 0:8b387bed54c2 234 /* Critical Region Protection */
hlipka 0:8b387bed54c2 235 /* These functions must be implemented in the sys_arch.c file.
hlipka 0:8b387bed54c2 236 In some implementations they can provide a more light-weight protection
hlipka 0:8b387bed54c2 237 mechanism than using semaphores. Otherwise semaphores can be used for
hlipka 0:8b387bed54c2 238 implementation */
hlipka 0:8b387bed54c2 239 #ifndef SYS_ARCH_PROTECT
hlipka 0:8b387bed54c2 240 /** SYS_LIGHTWEIGHT_PROT
hlipka 0:8b387bed54c2 241 * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
hlipka 0:8b387bed54c2 242 * for certain critical regions during buffer allocation, deallocation and memory
hlipka 0:8b387bed54c2 243 * allocation and deallocation.
hlipka 0:8b387bed54c2 244 */
hlipka 0:8b387bed54c2 245 #if SYS_LIGHTWEIGHT_PROT
hlipka 0:8b387bed54c2 246
hlipka 0:8b387bed54c2 247 /** SYS_ARCH_DECL_PROTECT
hlipka 0:8b387bed54c2 248 * declare a protection variable. This macro will default to defining a variable of
hlipka 0:8b387bed54c2 249 * type sys_prot_t. If a particular port needs a different implementation, then
hlipka 0:8b387bed54c2 250 * this macro may be defined in sys_arch.h.
hlipka 0:8b387bed54c2 251 */
hlipka 0:8b387bed54c2 252 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
hlipka 0:8b387bed54c2 253 /** SYS_ARCH_PROTECT
hlipka 0:8b387bed54c2 254 * Perform a "fast" protect. This could be implemented by
hlipka 0:8b387bed54c2 255 * disabling interrupts for an embedded system or by using a semaphore or
hlipka 0:8b387bed54c2 256 * mutex. The implementation should allow calling SYS_ARCH_PROTECT when
hlipka 0:8b387bed54c2 257 * already protected. The old protection level is returned in the variable
hlipka 0:8b387bed54c2 258 * "lev". This macro will default to calling the sys_arch_protect() function
hlipka 0:8b387bed54c2 259 * which should be implemented in sys_arch.c. If a particular port needs a
hlipka 0:8b387bed54c2 260 * different implementation, then this macro may be defined in sys_arch.h
hlipka 0:8b387bed54c2 261 */
hlipka 0:8b387bed54c2 262 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
hlipka 0:8b387bed54c2 263 /** SYS_ARCH_UNPROTECT
hlipka 0:8b387bed54c2 264 * Perform a "fast" set of the protection level to "lev". This could be
hlipka 0:8b387bed54c2 265 * implemented by setting the interrupt level to "lev" within the MACRO or by
hlipka 0:8b387bed54c2 266 * using a semaphore or mutex. This macro will default to calling the
hlipka 0:8b387bed54c2 267 * sys_arch_unprotect() function which should be implemented in
hlipka 0:8b387bed54c2 268 * sys_arch.c. If a particular port needs a different implementation, then
hlipka 0:8b387bed54c2 269 * this macro may be defined in sys_arch.h
hlipka 0:8b387bed54c2 270 */
hlipka 0:8b387bed54c2 271 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
hlipka 0:8b387bed54c2 272 sys_prot_t sys_arch_protect(void);
hlipka 0:8b387bed54c2 273 void sys_arch_unprotect(sys_prot_t pval);
hlipka 0:8b387bed54c2 274
hlipka 0:8b387bed54c2 275 #else
hlipka 0:8b387bed54c2 276
hlipka 0:8b387bed54c2 277 #define SYS_ARCH_DECL_PROTECT(lev)
hlipka 0:8b387bed54c2 278 #define SYS_ARCH_PROTECT(lev)
hlipka 0:8b387bed54c2 279 #define SYS_ARCH_UNPROTECT(lev)
hlipka 0:8b387bed54c2 280
hlipka 0:8b387bed54c2 281 #endif /* SYS_LIGHTWEIGHT_PROT */
hlipka 0:8b387bed54c2 282
hlipka 0:8b387bed54c2 283 #endif /* SYS_ARCH_PROTECT */
hlipka 0:8b387bed54c2 284
hlipka 0:8b387bed54c2 285 /*
hlipka 0:8b387bed54c2 286 * Macros to set/get and increase/decrease variables in a thread-safe way.
hlipka 0:8b387bed54c2 287 * Use these for accessing variable that are used from more than one thread.
hlipka 0:8b387bed54c2 288 */
hlipka 0:8b387bed54c2 289
hlipka 0:8b387bed54c2 290 #ifndef SYS_ARCH_INC
hlipka 0:8b387bed54c2 291 #define SYS_ARCH_INC(var, val) do { \
hlipka 0:8b387bed54c2 292 SYS_ARCH_DECL_PROTECT(old_level); \
hlipka 0:8b387bed54c2 293 SYS_ARCH_PROTECT(old_level); \
hlipka 0:8b387bed54c2 294 var += val; \
hlipka 0:8b387bed54c2 295 SYS_ARCH_UNPROTECT(old_level); \
hlipka 0:8b387bed54c2 296 } while(0)
hlipka 0:8b387bed54c2 297 #endif /* SYS_ARCH_INC */
hlipka 0:8b387bed54c2 298
hlipka 0:8b387bed54c2 299 #ifndef SYS_ARCH_DEC
hlipka 0:8b387bed54c2 300 #define SYS_ARCH_DEC(var, val) do { \
hlipka 0:8b387bed54c2 301 SYS_ARCH_DECL_PROTECT(old_level); \
hlipka 0:8b387bed54c2 302 SYS_ARCH_PROTECT(old_level); \
hlipka 0:8b387bed54c2 303 var -= val; \
hlipka 0:8b387bed54c2 304 SYS_ARCH_UNPROTECT(old_level); \
hlipka 0:8b387bed54c2 305 } while(0)
hlipka 0:8b387bed54c2 306 #endif /* SYS_ARCH_DEC */
hlipka 0:8b387bed54c2 307
hlipka 0:8b387bed54c2 308 #ifndef SYS_ARCH_GET
hlipka 0:8b387bed54c2 309 #define SYS_ARCH_GET(var, ret) do { \
hlipka 0:8b387bed54c2 310 SYS_ARCH_DECL_PROTECT(old_level); \
hlipka 0:8b387bed54c2 311 SYS_ARCH_PROTECT(old_level); \
hlipka 0:8b387bed54c2 312 ret = var; \
hlipka 0:8b387bed54c2 313 SYS_ARCH_UNPROTECT(old_level); \
hlipka 0:8b387bed54c2 314 } while(0)
hlipka 0:8b387bed54c2 315 #endif /* SYS_ARCH_GET */
hlipka 0:8b387bed54c2 316
hlipka 0:8b387bed54c2 317 #ifndef SYS_ARCH_SET
hlipka 0:8b387bed54c2 318 #define SYS_ARCH_SET(var, val) do { \
hlipka 0:8b387bed54c2 319 SYS_ARCH_DECL_PROTECT(old_level); \
hlipka 0:8b387bed54c2 320 SYS_ARCH_PROTECT(old_level); \
hlipka 0:8b387bed54c2 321 var = val; \
hlipka 0:8b387bed54c2 322 SYS_ARCH_UNPROTECT(old_level); \
hlipka 0:8b387bed54c2 323 } while(0)
hlipka 0:8b387bed54c2 324 #endif /* SYS_ARCH_SET */
hlipka 0:8b387bed54c2 325
hlipka 0:8b387bed54c2 326
hlipka 0:8b387bed54c2 327 #ifdef __cplusplus
hlipka 0:8b387bed54c2 328 }
hlipka 0:8b387bed54c2 329 #endif
hlipka 0:8b387bed54c2 330
hlipka 0:8b387bed54c2 331 #endif /* __LWIP_SYS_H__ */