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