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