SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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