A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
trunk/Core/lwIP/include/lwip/sys.h@0:5e1631496985, 2012-05-08 (annotated)
- Committer:
- root@mbed.org
- Date:
- Tue May 08 15:32:10 2012 +0100
- Revision:
- 0:5e1631496985
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
root@mbed.org | 0:5e1631496985 | 1 | /* |
root@mbed.org | 0:5e1631496985 | 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
root@mbed.org | 0:5e1631496985 | 3 | * All rights reserved. |
root@mbed.org | 0:5e1631496985 | 4 | * |
root@mbed.org | 0:5e1631496985 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
root@mbed.org | 0:5e1631496985 | 6 | * are permitted provided that the following conditions are met: |
root@mbed.org | 0:5e1631496985 | 7 | * |
root@mbed.org | 0:5e1631496985 | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
root@mbed.org | 0:5e1631496985 | 9 | * this list of conditions and the following disclaimer. |
root@mbed.org | 0:5e1631496985 | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
root@mbed.org | 0:5e1631496985 | 11 | * this list of conditions and the following disclaimer in the documentation |
root@mbed.org | 0:5e1631496985 | 12 | * and/or other materials provided with the distribution. |
root@mbed.org | 0:5e1631496985 | 13 | * 3. The name of the author may not be used to endorse or promote products |
root@mbed.org | 0:5e1631496985 | 14 | * derived from this software without specific prior written permission. |
root@mbed.org | 0:5e1631496985 | 15 | * |
root@mbed.org | 0:5e1631496985 | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
root@mbed.org | 0:5e1631496985 | 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
root@mbed.org | 0:5e1631496985 | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
root@mbed.org | 0:5e1631496985 | 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
root@mbed.org | 0:5e1631496985 | 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
root@mbed.org | 0:5e1631496985 | 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
root@mbed.org | 0:5e1631496985 | 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
root@mbed.org | 0:5e1631496985 | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
root@mbed.org | 0:5e1631496985 | 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
root@mbed.org | 0:5e1631496985 | 25 | * OF SUCH DAMAGE. |
root@mbed.org | 0:5e1631496985 | 26 | * |
root@mbed.org | 0:5e1631496985 | 27 | * This file is part of the lwIP TCP/IP stack. |
root@mbed.org | 0:5e1631496985 | 28 | * |
root@mbed.org | 0:5e1631496985 | 29 | * Author: Adam Dunkels <adam@sics.se> |
root@mbed.org | 0:5e1631496985 | 30 | * |
root@mbed.org | 0:5e1631496985 | 31 | */ |
root@mbed.org | 0:5e1631496985 | 32 | #ifndef __LWIP_SYS_H__ |
root@mbed.org | 0:5e1631496985 | 33 | #define __LWIP_SYS_H__ |
root@mbed.org | 0:5e1631496985 | 34 | |
root@mbed.org | 0:5e1631496985 | 35 | #include "lwip/opt.h" |
root@mbed.org | 0:5e1631496985 | 36 | |
root@mbed.org | 0:5e1631496985 | 37 | #ifdef __cplusplus |
root@mbed.org | 0:5e1631496985 | 38 | extern "C" { |
root@mbed.org | 0:5e1631496985 | 39 | #endif |
root@mbed.org | 0:5e1631496985 | 40 | |
root@mbed.org | 0:5e1631496985 | 41 | #if NO_SYS |
root@mbed.org | 0:5e1631496985 | 42 | |
root@mbed.org | 0:5e1631496985 | 43 | /* For a totally minimal and standalone system, we provide null |
root@mbed.org | 0:5e1631496985 | 44 | definitions of the sys_ functions. */ |
root@mbed.org | 0:5e1631496985 | 45 | typedef u8_t sys_sem_t; |
root@mbed.org | 0:5e1631496985 | 46 | typedef u8_t sys_mbox_t; |
root@mbed.org | 0:5e1631496985 | 47 | struct sys_timeo {u8_t dummy;}; |
root@mbed.org | 0:5e1631496985 | 48 | |
root@mbed.org | 0:5e1631496985 | 49 | #define sys_init() |
root@mbed.org | 0:5e1631496985 | 50 | #define sys_timeout(m,h,a) |
root@mbed.org | 0:5e1631496985 | 51 | #define sys_untimeout(m,a) |
root@mbed.org | 0:5e1631496985 | 52 | #define sys_sem_new(c) c |
root@mbed.org | 0:5e1631496985 | 53 | #define sys_sem_signal(s) |
root@mbed.org | 0:5e1631496985 | 54 | #define sys_sem_wait(s) |
root@mbed.org | 0:5e1631496985 | 55 | #define sys_sem_wait_timeout(s,t) |
root@mbed.org | 0:5e1631496985 | 56 | #define sys_arch_sem_wait(s,t) |
root@mbed.org | 0:5e1631496985 | 57 | #define sys_sem_free(s) |
root@mbed.org | 0:5e1631496985 | 58 | #define sys_mbox_new(s) 0 |
root@mbed.org | 0:5e1631496985 | 59 | #define sys_mbox_fetch(m,d) |
root@mbed.org | 0:5e1631496985 | 60 | #define sys_mbox_tryfetch(m,d) |
root@mbed.org | 0:5e1631496985 | 61 | #define sys_mbox_post(m,d) |
root@mbed.org | 0:5e1631496985 | 62 | #define sys_mbox_trypost(m,d) |
root@mbed.org | 0:5e1631496985 | 63 | #define sys_mbox_free(m) |
root@mbed.org | 0:5e1631496985 | 64 | |
root@mbed.org | 0:5e1631496985 | 65 | #define sys_thread_new(n,t,a,s,p) |
root@mbed.org | 0:5e1631496985 | 66 | |
root@mbed.org | 0:5e1631496985 | 67 | #else /* NO_SYS */ |
root@mbed.org | 0:5e1631496985 | 68 | |
root@mbed.org | 0:5e1631496985 | 69 | /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */ |
root@mbed.org | 0:5e1631496985 | 70 | #define SYS_ARCH_TIMEOUT 0xffffffffUL |
root@mbed.org | 0:5e1631496985 | 71 | |
root@mbed.org | 0:5e1631496985 | 72 | /* sys_mbox_tryfetch returns SYS_MBOX_EMPTY if appropriate. |
root@mbed.org | 0:5e1631496985 | 73 | * For now we use the same magic value, but we allow this to change in future. |
root@mbed.org | 0:5e1631496985 | 74 | */ |
root@mbed.org | 0:5e1631496985 | 75 | #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT |
root@mbed.org | 0:5e1631496985 | 76 | |
root@mbed.org | 0:5e1631496985 | 77 | #include "lwip/err.h" |
root@mbed.org | 0:5e1631496985 | 78 | #include "arch/sys_arch.h" |
root@mbed.org | 0:5e1631496985 | 79 | |
root@mbed.org | 0:5e1631496985 | 80 | typedef void (* sys_timeout_handler)(void *arg); |
root@mbed.org | 0:5e1631496985 | 81 | |
root@mbed.org | 0:5e1631496985 | 82 | struct sys_timeo { |
root@mbed.org | 0:5e1631496985 | 83 | struct sys_timeo *next; |
root@mbed.org | 0:5e1631496985 | 84 | u32_t time; |
root@mbed.org | 0:5e1631496985 | 85 | sys_timeout_handler h; |
root@mbed.org | 0:5e1631496985 | 86 | void *arg; |
root@mbed.org | 0:5e1631496985 | 87 | }; |
root@mbed.org | 0:5e1631496985 | 88 | |
root@mbed.org | 0:5e1631496985 | 89 | struct sys_timeouts { |
root@mbed.org | 0:5e1631496985 | 90 | struct sys_timeo *next; |
root@mbed.org | 0:5e1631496985 | 91 | }; |
root@mbed.org | 0:5e1631496985 | 92 | |
root@mbed.org | 0:5e1631496985 | 93 | /* sys_init() must be called before anthing else. */ |
root@mbed.org | 0:5e1631496985 | 94 | void sys_init(void); |
root@mbed.org | 0:5e1631496985 | 95 | |
root@mbed.org | 0:5e1631496985 | 96 | /* |
root@mbed.org | 0:5e1631496985 | 97 | * sys_timeout(): |
root@mbed.org | 0:5e1631496985 | 98 | * |
root@mbed.org | 0:5e1631496985 | 99 | * Schedule a timeout a specified amount of milliseconds in the |
root@mbed.org | 0:5e1631496985 | 100 | * future. When the timeout occurs, the specified timeout handler will |
root@mbed.org | 0:5e1631496985 | 101 | * be called. The handler will be passed the "arg" argument when |
root@mbed.org | 0:5e1631496985 | 102 | * called. |
root@mbed.org | 0:5e1631496985 | 103 | * |
root@mbed.org | 0:5e1631496985 | 104 | */ |
root@mbed.org | 0:5e1631496985 | 105 | void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg); |
root@mbed.org | 0:5e1631496985 | 106 | void sys_untimeout(sys_timeout_handler h, void *arg); |
root@mbed.org | 0:5e1631496985 | 107 | struct sys_timeouts *sys_arch_timeouts(void); |
root@mbed.org | 0:5e1631496985 | 108 | |
root@mbed.org | 0:5e1631496985 | 109 | /* Semaphore functions. */ |
root@mbed.org | 0:5e1631496985 | 110 | sys_sem_t sys_sem_new(u8_t count); |
root@mbed.org | 0:5e1631496985 | 111 | void sys_sem_signal(sys_sem_t sem); |
root@mbed.org | 0:5e1631496985 | 112 | u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout); |
root@mbed.org | 0:5e1631496985 | 113 | void sys_sem_free(sys_sem_t sem); |
root@mbed.org | 0:5e1631496985 | 114 | void sys_sem_wait(sys_sem_t sem); |
root@mbed.org | 0:5e1631496985 | 115 | int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout); |
root@mbed.org | 0:5e1631496985 | 116 | |
root@mbed.org | 0:5e1631496985 | 117 | /* Time functions. */ |
root@mbed.org | 0:5e1631496985 | 118 | #ifndef sys_msleep |
root@mbed.org | 0:5e1631496985 | 119 | void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */ |
root@mbed.org | 0:5e1631496985 | 120 | #endif |
root@mbed.org | 0:5e1631496985 | 121 | #ifndef sys_jiffies |
root@mbed.org | 0:5e1631496985 | 122 | u32_t sys_jiffies(void); /* since power up. */ |
root@mbed.org | 0:5e1631496985 | 123 | #endif |
root@mbed.org | 0:5e1631496985 | 124 | |
root@mbed.org | 0:5e1631496985 | 125 | /* Mailbox functions. */ |
root@mbed.org | 0:5e1631496985 | 126 | sys_mbox_t sys_mbox_new(int size); |
root@mbed.org | 0:5e1631496985 | 127 | void sys_mbox_post(sys_mbox_t mbox, void *msg); |
root@mbed.org | 0:5e1631496985 | 128 | err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg); |
root@mbed.org | 0:5e1631496985 | 129 | u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout); |
root@mbed.org | 0:5e1631496985 | 130 | #ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */ |
root@mbed.org | 0:5e1631496985 | 131 | u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg); |
root@mbed.org | 0:5e1631496985 | 132 | #endif |
root@mbed.org | 0:5e1631496985 | 133 | /* For now, we map straight to sys_arch implementation. */ |
root@mbed.org | 0:5e1631496985 | 134 | #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg) |
root@mbed.org | 0:5e1631496985 | 135 | void sys_mbox_free(sys_mbox_t mbox); |
root@mbed.org | 0:5e1631496985 | 136 | void sys_mbox_fetch(sys_mbox_t mbox, void **msg); |
root@mbed.org | 0:5e1631496985 | 137 | |
root@mbed.org | 0:5e1631496985 | 138 | /* Thread functions. */ |
root@mbed.org | 0:5e1631496985 | 139 | sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio); |
root@mbed.org | 0:5e1631496985 | 140 | |
root@mbed.org | 0:5e1631496985 | 141 | #endif /* NO_SYS */ |
root@mbed.org | 0:5e1631496985 | 142 | |
root@mbed.org | 0:5e1631496985 | 143 | /** Returns the current time in milliseconds. */ |
root@mbed.org | 0:5e1631496985 | 144 | u32_t sys_now(void); |
root@mbed.org | 0:5e1631496985 | 145 | |
root@mbed.org | 0:5e1631496985 | 146 | /* Critical Region Protection */ |
root@mbed.org | 0:5e1631496985 | 147 | /* These functions must be implemented in the sys_arch.c file. |
root@mbed.org | 0:5e1631496985 | 148 | In some implementations they can provide a more light-weight protection |
root@mbed.org | 0:5e1631496985 | 149 | mechanism than using semaphores. Otherwise semaphores can be used for |
root@mbed.org | 0:5e1631496985 | 150 | implementation */ |
root@mbed.org | 0:5e1631496985 | 151 | #ifndef SYS_ARCH_PROTECT |
root@mbed.org | 0:5e1631496985 | 152 | /** SYS_LIGHTWEIGHT_PROT |
root@mbed.org | 0:5e1631496985 | 153 | * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection |
root@mbed.org | 0:5e1631496985 | 154 | * for certain critical regions during buffer allocation, deallocation and memory |
root@mbed.org | 0:5e1631496985 | 155 | * allocation and deallocation. |
root@mbed.org | 0:5e1631496985 | 156 | */ |
root@mbed.org | 0:5e1631496985 | 157 | #if SYS_LIGHTWEIGHT_PROT |
root@mbed.org | 0:5e1631496985 | 158 | |
root@mbed.org | 0:5e1631496985 | 159 | /** SYS_ARCH_DECL_PROTECT |
root@mbed.org | 0:5e1631496985 | 160 | * declare a protection variable. This macro will default to defining a variable of |
root@mbed.org | 0:5e1631496985 | 161 | * type sys_prot_t. If a particular port needs a different implementation, then |
root@mbed.org | 0:5e1631496985 | 162 | * this macro may be defined in sys_arch.h. |
root@mbed.org | 0:5e1631496985 | 163 | */ |
root@mbed.org | 0:5e1631496985 | 164 | #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev |
root@mbed.org | 0:5e1631496985 | 165 | /** SYS_ARCH_PROTECT |
root@mbed.org | 0:5e1631496985 | 166 | * Perform a "fast" protect. This could be implemented by |
root@mbed.org | 0:5e1631496985 | 167 | * disabling interrupts for an embedded system or by using a semaphore or |
root@mbed.org | 0:5e1631496985 | 168 | * mutex. The implementation should allow calling SYS_ARCH_PROTECT when |
root@mbed.org | 0:5e1631496985 | 169 | * already protected. The old protection level is returned in the variable |
root@mbed.org | 0:5e1631496985 | 170 | * "lev". This macro will default to calling the sys_arch_protect() function |
root@mbed.org | 0:5e1631496985 | 171 | * which should be implemented in sys_arch.c. If a particular port needs a |
root@mbed.org | 0:5e1631496985 | 172 | * different implementation, then this macro may be defined in sys_arch.h |
root@mbed.org | 0:5e1631496985 | 173 | */ |
root@mbed.org | 0:5e1631496985 | 174 | #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect() |
root@mbed.org | 0:5e1631496985 | 175 | /** SYS_ARCH_UNPROTECT |
root@mbed.org | 0:5e1631496985 | 176 | * Perform a "fast" set of the protection level to "lev". This could be |
root@mbed.org | 0:5e1631496985 | 177 | * implemented by setting the interrupt level to "lev" within the MACRO or by |
root@mbed.org | 0:5e1631496985 | 178 | * using a semaphore or mutex. This macro will default to calling the |
root@mbed.org | 0:5e1631496985 | 179 | * sys_arch_unprotect() function which should be implemented in |
root@mbed.org | 0:5e1631496985 | 180 | * sys_arch.c. If a particular port needs a different implementation, then |
root@mbed.org | 0:5e1631496985 | 181 | * this macro may be defined in sys_arch.h |
root@mbed.org | 0:5e1631496985 | 182 | */ |
root@mbed.org | 0:5e1631496985 | 183 | #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev) |
root@mbed.org | 0:5e1631496985 | 184 | sys_prot_t sys_arch_protect(void); |
root@mbed.org | 0:5e1631496985 | 185 | void sys_arch_unprotect(sys_prot_t pval); |
root@mbed.org | 0:5e1631496985 | 186 | |
root@mbed.org | 0:5e1631496985 | 187 | #else |
root@mbed.org | 0:5e1631496985 | 188 | |
root@mbed.org | 0:5e1631496985 | 189 | #define SYS_ARCH_DECL_PROTECT(lev) |
root@mbed.org | 0:5e1631496985 | 190 | #define SYS_ARCH_PROTECT(lev) |
root@mbed.org | 0:5e1631496985 | 191 | #define SYS_ARCH_UNPROTECT(lev) |
root@mbed.org | 0:5e1631496985 | 192 | |
root@mbed.org | 0:5e1631496985 | 193 | #endif /* SYS_LIGHTWEIGHT_PROT */ |
root@mbed.org | 0:5e1631496985 | 194 | |
root@mbed.org | 0:5e1631496985 | 195 | #endif /* SYS_ARCH_PROTECT */ |
root@mbed.org | 0:5e1631496985 | 196 | |
root@mbed.org | 0:5e1631496985 | 197 | /* |
root@mbed.org | 0:5e1631496985 | 198 | * Macros to set/get and increase/decrease variables in a thread-safe way. |
root@mbed.org | 0:5e1631496985 | 199 | * Use these for accessing variable that are used from more than one thread. |
root@mbed.org | 0:5e1631496985 | 200 | */ |
root@mbed.org | 0:5e1631496985 | 201 | |
root@mbed.org | 0:5e1631496985 | 202 | #ifndef SYS_ARCH_INC |
root@mbed.org | 0:5e1631496985 | 203 | #define SYS_ARCH_INC(var, val) do { \ |
root@mbed.org | 0:5e1631496985 | 204 | SYS_ARCH_DECL_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 205 | SYS_ARCH_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 206 | var += val; \ |
root@mbed.org | 0:5e1631496985 | 207 | SYS_ARCH_UNPROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 208 | } while(0) |
root@mbed.org | 0:5e1631496985 | 209 | #endif /* SYS_ARCH_INC */ |
root@mbed.org | 0:5e1631496985 | 210 | |
root@mbed.org | 0:5e1631496985 | 211 | #ifndef SYS_ARCH_DEC |
root@mbed.org | 0:5e1631496985 | 212 | #define SYS_ARCH_DEC(var, val) do { \ |
root@mbed.org | 0:5e1631496985 | 213 | SYS_ARCH_DECL_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 214 | SYS_ARCH_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 215 | var -= val; \ |
root@mbed.org | 0:5e1631496985 | 216 | SYS_ARCH_UNPROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 217 | } while(0) |
root@mbed.org | 0:5e1631496985 | 218 | #endif /* SYS_ARCH_DEC */ |
root@mbed.org | 0:5e1631496985 | 219 | |
root@mbed.org | 0:5e1631496985 | 220 | #ifndef SYS_ARCH_GET |
root@mbed.org | 0:5e1631496985 | 221 | #define SYS_ARCH_GET(var, ret) do { \ |
root@mbed.org | 0:5e1631496985 | 222 | SYS_ARCH_DECL_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 223 | SYS_ARCH_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 224 | ret = var; \ |
root@mbed.org | 0:5e1631496985 | 225 | SYS_ARCH_UNPROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 226 | } while(0) |
root@mbed.org | 0:5e1631496985 | 227 | #endif /* SYS_ARCH_GET */ |
root@mbed.org | 0:5e1631496985 | 228 | |
root@mbed.org | 0:5e1631496985 | 229 | #ifndef SYS_ARCH_SET |
root@mbed.org | 0:5e1631496985 | 230 | #define SYS_ARCH_SET(var, val) do { \ |
root@mbed.org | 0:5e1631496985 | 231 | SYS_ARCH_DECL_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 232 | SYS_ARCH_PROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 233 | var = val; \ |
root@mbed.org | 0:5e1631496985 | 234 | SYS_ARCH_UNPROTECT(old_level); \ |
root@mbed.org | 0:5e1631496985 | 235 | } while(0) |
root@mbed.org | 0:5e1631496985 | 236 | #endif /* SYS_ARCH_SET */ |
root@mbed.org | 0:5e1631496985 | 237 | |
root@mbed.org | 0:5e1631496985 | 238 | |
root@mbed.org | 0:5e1631496985 | 239 | #ifdef __cplusplus |
root@mbed.org | 0:5e1631496985 | 240 | } |
root@mbed.org | 0:5e1631496985 | 241 | #endif |
root@mbed.org | 0:5e1631496985 | 242 | |
root@mbed.org | 0:5e1631496985 | 243 | #endif /* __LWIP_SYS_H__ */ |