Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sys.h
00001 /* 00002 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 #ifndef __LWIP_SYS_H__ 00033 #define __LWIP_SYS_H__ 00034 00035 #include "lwip/opt.h" 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #if NO_SYS 00042 00043 /* For a totally minimal and standalone system, we provide null 00044 definitions of the sys_ functions. */ 00045 typedef u8_t sys_sem_t; 00046 typedef u8_t sys_mbox_t; 00047 struct sys_timeo {u8_t dummy;}; 00048 00049 #define sys_init() 00050 #define sys_timeout(m,h,a) 00051 #define sys_untimeout(m,a) 00052 #define sys_sem_new(c) c 00053 #define sys_sem_signal(s) 00054 #define sys_sem_wait(s) 00055 #define sys_sem_wait_timeout(s,t) 00056 #define sys_arch_sem_wait(s,t) 00057 #define sys_sem_free(s) 00058 #define sys_mbox_new(s) 0 00059 #define sys_mbox_fetch(m,d) 00060 #define sys_mbox_tryfetch(m,d) 00061 #define sys_mbox_post(m,d) 00062 #define sys_mbox_trypost(m,d) 00063 #define sys_mbox_free(m) 00064 00065 #define sys_thread_new(n,t,a,s,p) 00066 00067 #else /* NO_SYS */ 00068 00069 /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */ 00070 #define SYS_ARCH_TIMEOUT 0xffffffffUL 00071 00072 /* sys_mbox_tryfetch returns SYS_MBOX_EMPTY if appropriate. 00073 * For now we use the same magic value, but we allow this to change in future. 00074 */ 00075 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT 00076 00077 #include "lwip/err.h" 00078 #include "arch/sys_arch.h" 00079 00080 typedef void (* sys_timeout_handler)(void *arg); 00081 00082 struct sys_timeo { 00083 struct sys_timeo *next; 00084 u32_t time; 00085 sys_timeout_handler h; 00086 void *arg; 00087 }; 00088 00089 struct sys_timeouts { 00090 struct sys_timeo *next; 00091 }; 00092 00093 /* sys_init() must be called before anthing else. */ 00094 void sys_init(void); 00095 00096 /* 00097 * sys_timeout(): 00098 * 00099 * Schedule a timeout a specified amount of milliseconds in the 00100 * future. When the timeout occurs, the specified timeout handler will 00101 * be called. The handler will be passed the "arg" argument when 00102 * called. 00103 * 00104 */ 00105 void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg); 00106 void sys_untimeout(sys_timeout_handler h, void *arg); 00107 struct sys_timeouts *sys_arch_timeouts(void); 00108 00109 /* Semaphore functions. */ 00110 sys_sem_t sys_sem_new(u8_t count); 00111 void sys_sem_signal(sys_sem_t sem); 00112 u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout); 00113 void sys_sem_free(sys_sem_t sem); 00114 void sys_sem_wait(sys_sem_t sem); 00115 int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout); 00116 00117 /* Time functions. */ 00118 #ifndef sys_msleep 00119 void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */ 00120 #endif 00121 #ifndef sys_jiffies 00122 u32_t sys_jiffies(void); /* since power up. */ 00123 #endif 00124 00125 /* Mailbox functions. */ 00126 sys_mbox_t sys_mbox_new(int size); 00127 void sys_mbox_post(sys_mbox_t mbox, void *msg); 00128 err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg); 00129 u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout); 00130 #ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */ 00131 u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg); 00132 #endif 00133 /* For now, we map straight to sys_arch implementation. */ 00134 #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg) 00135 void sys_mbox_free(sys_mbox_t mbox); 00136 void sys_mbox_fetch(sys_mbox_t mbox, void **msg); 00137 00138 /* Thread functions. */ 00139 sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio); 00140 00141 #endif /* NO_SYS */ 00142 00143 /** Returns the current time in milliseconds. */ 00144 u32_t sys_now(void); 00145 00146 /* Critical Region Protection */ 00147 /* These functions must be implemented in the sys_arch.c file. 00148 In some implementations they can provide a more light-weight protection 00149 mechanism than using semaphores. Otherwise semaphores can be used for 00150 implementation */ 00151 #ifndef SYS_ARCH_PROTECT 00152 /** SYS_LIGHTWEIGHT_PROT 00153 * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection 00154 * for certain critical regions during buffer allocation, deallocation and memory 00155 * allocation and deallocation. 00156 */ 00157 #if SYS_LIGHTWEIGHT_PROT 00158 00159 /** SYS_ARCH_DECL_PROTECT 00160 * declare a protection variable. This macro will default to defining a variable of 00161 * type sys_prot_t. If a particular port needs a different implementation, then 00162 * this macro may be defined in sys_arch.h. 00163 */ 00164 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev 00165 /** SYS_ARCH_PROTECT 00166 * Perform a "fast" protect. This could be implemented by 00167 * disabling interrupts for an embedded system or by using a semaphore or 00168 * mutex. The implementation should allow calling SYS_ARCH_PROTECT when 00169 * already protected. The old protection level is returned in the variable 00170 * "lev". This macro will default to calling the sys_arch_protect() function 00171 * which should be implemented in sys_arch.c. If a particular port needs a 00172 * different implementation, then this macro may be defined in sys_arch.h 00173 */ 00174 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect() 00175 /** SYS_ARCH_UNPROTECT 00176 * Perform a "fast" set of the protection level to "lev". This could be 00177 * implemented by setting the interrupt level to "lev" within the MACRO or by 00178 * using a semaphore or mutex. This macro will default to calling the 00179 * sys_arch_unprotect() function which should be implemented in 00180 * sys_arch.c. If a particular port needs a different implementation, then 00181 * this macro may be defined in sys_arch.h 00182 */ 00183 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev) 00184 sys_prot_t sys_arch_protect(void); 00185 void sys_arch_unprotect(sys_prot_t pval); 00186 00187 #else 00188 00189 #define SYS_ARCH_DECL_PROTECT(lev) 00190 #define SYS_ARCH_PROTECT(lev) 00191 #define SYS_ARCH_UNPROTECT(lev) 00192 00193 #endif /* SYS_LIGHTWEIGHT_PROT */ 00194 00195 #endif /* SYS_ARCH_PROTECT */ 00196 00197 /* 00198 * Macros to set/get and increase/decrease variables in a thread-safe way. 00199 * Use these for accessing variable that are used from more than one thread. 00200 */ 00201 00202 #ifndef SYS_ARCH_INC 00203 #define SYS_ARCH_INC(var, val) do { \ 00204 SYS_ARCH_DECL_PROTECT(old_level); \ 00205 SYS_ARCH_PROTECT(old_level); \ 00206 var += val; \ 00207 SYS_ARCH_UNPROTECT(old_level); \ 00208 } while(0) 00209 #endif /* SYS_ARCH_INC */ 00210 00211 #ifndef SYS_ARCH_DEC 00212 #define SYS_ARCH_DEC(var, val) do { \ 00213 SYS_ARCH_DECL_PROTECT(old_level); \ 00214 SYS_ARCH_PROTECT(old_level); \ 00215 var -= val; \ 00216 SYS_ARCH_UNPROTECT(old_level); \ 00217 } while(0) 00218 #endif /* SYS_ARCH_DEC */ 00219 00220 #ifndef SYS_ARCH_GET 00221 #define SYS_ARCH_GET(var, ret) do { \ 00222 SYS_ARCH_DECL_PROTECT(old_level); \ 00223 SYS_ARCH_PROTECT(old_level); \ 00224 ret = var; \ 00225 SYS_ARCH_UNPROTECT(old_level); \ 00226 } while(0) 00227 #endif /* SYS_ARCH_GET */ 00228 00229 #ifndef SYS_ARCH_SET 00230 #define SYS_ARCH_SET(var, val) do { \ 00231 SYS_ARCH_DECL_PROTECT(old_level); \ 00232 SYS_ARCH_PROTECT(old_level); \ 00233 var = val; \ 00234 SYS_ARCH_UNPROTECT(old_level); \ 00235 } while(0) 00236 #endif /* SYS_ARCH_SET */ 00237 00238 00239 #ifdef __cplusplus 00240 } 00241 #endif 00242 00243 #endif /* __LWIP_SYS_H__ */
Generated on Wed Jul 13 2022 07:13:44 by
1.7.2