Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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