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