1. Reduce the size of the heap memory 2. Change the TCP segment size 3. Disable UDP + DHCP + DNS 4. Change the configuration of the TCP/IP thread

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
aos
Date:
Thu Feb 13 17:57:50 2014 +0000
Revision:
16:f159c25d9261
Parent:
0:51ac1d130fd4
Update the heap memory size

Who changed what in which revision?

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