]> git.sur5r.net Git - freertos/blob - Demo/Common/ethernet/lwIP/include/lwip/sys.h
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@82 1d2547de-c912-0410-9cb9...
[freertos] / Demo / Common / ethernet / lwIP / include / lwip / sys.h
1 /*\r
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.\r
3  * All rights reserved. \r
4  * \r
5  * Redistribution and use in source and binary forms, with or without modification, \r
6  * are permitted provided that the following conditions are met:\r
7  *\r
8  * 1. Redistributions of source code must retain the above copyright notice,\r
9  *    this list of conditions and the following disclaimer.\r
10  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
11  *    this list of conditions and the following disclaimer in the documentation\r
12  *    and/or other materials provided with the distribution.\r
13  * 3. The name of the author may not be used to endorse or promote products\r
14  *    derived from this software without specific prior written permission. \r
15  *\r
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \r
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT \r
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \r
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT \r
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \r
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY \r
25  * OF SUCH DAMAGE.\r
26  *\r
27  * This file is part of the lwIP TCP/IP stack.\r
28  * \r
29  * Author: Adam Dunkels <adam@sics.se>\r
30  *\r
31  */\r
32 #ifndef __LWIP_SYS_H__\r
33 #define __LWIP_SYS_H__\r
34 \r
35 #include "arch/cc.h"\r
36 \r
37 #include "lwip/opt.h"\r
38 \r
39 \r
40 #if NO_SYS\r
41 \r
42 /* For a totally minimal and standalone system, we provide null\r
43    definitions of the sys_ functions. */\r
44 typedef u8_t sys_sem_t;\r
45 typedef u8_t sys_mbox_t;\r
46 struct sys_timeo {u8_t dummy;};\r
47 \r
48 #define sys_init()\r
49 #define sys_timeout(m,h,a)\r
50 #define sys_untimeout(m,a)\r
51 #define sys_sem_new(c) c\r
52 #define sys_sem_signal(s)\r
53 #define sys_sem_wait(s)\r
54 #define sys_sem_free(s)\r
55 #define sys_mbox_new() 0\r
56 #define sys_mbox_fetch(m,d)\r
57 #define sys_mbox_post(m,d)\r
58 #define sys_mbox_free(m)\r
59 \r
60 #define sys_thread_new(t,a,p)\r
61 \r
62 #else /* NO_SYS */\r
63 \r
64 #include "arch/sys_arch.h"\r
65 \r
66 /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */\r
67 #define SYS_ARCH_TIMEOUT 0xffffffff\r
68 \r
69 typedef void (* sys_timeout_handler)(void *arg);\r
70 \r
71 struct sys_timeo {\r
72   struct sys_timeo *next;\r
73   u32_t time;\r
74   sys_timeout_handler h;\r
75   void *arg;\r
76 };\r
77 \r
78 struct sys_timeouts {\r
79   struct sys_timeo *next;\r
80 };\r
81 \r
82 /* sys_init() must be called before anthing else. */\r
83 void sys_init(void);\r
84 \r
85 /*\r
86  * sys_timeout():\r
87  *\r
88  * Schedule a timeout a specified amount of milliseconds in the\r
89  * future. When the timeout occurs, the specified timeout handler will\r
90  * be called. The handler will be passed the "arg" argument when\r
91  * called.\r
92  *\r
93  */\r
94 void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);\r
95 void sys_untimeout(sys_timeout_handler h, void *arg);\r
96 struct sys_timeouts *sys_arch_timeouts(void);\r
97 \r
98 /* Semaphore functions. */\r
99 sys_sem_t sys_sem_new(u8_t count);\r
100 void sys_sem_signal(sys_sem_t sem);\r
101 u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);\r
102 void sys_sem_free(sys_sem_t sem);\r
103 void sys_sem_wait(sys_sem_t sem);\r
104 int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout);\r
105 \r
106 /* Time functions. */\r
107 #ifndef sys_msleep\r
108 void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */\r
109 #endif\r
110 #ifndef sys_jiffies\r
111 u32_t sys_jiffies(void); /* since power up. */\r
112 #endif\r
113 \r
114 /* Mailbox functions. */\r
115 sys_mbox_t sys_mbox_new(void);\r
116 void sys_mbox_post(sys_mbox_t mbox, void *msg);\r
117 u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);\r
118 void sys_mbox_free(sys_mbox_t mbox);\r
119 void sys_mbox_fetch(sys_mbox_t mbox, void **msg);\r
120 \r
121 \r
122 /* Thread functions. */\r
123 sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio);\r
124 \r
125 /* The following functions are used only in Unix code, and\r
126    can be omitted when porting the stack. */\r
127 /* Returns the current time in microseconds. */\r
128 unsigned long sys_now(void);\r
129 \r
130 #endif /* NO_SYS */\r
131 \r
132 /* Critical Region Protection */\r
133 /* These functions must be implemented in the sys_arch.c file.\r
134    In some implementations they can provide a more light-weight protection\r
135    mechanism than using semaphores. Otherwise semaphores can be used for\r
136    implementation */\r
137 #ifndef SYS_ARCH_PROTECT\r
138 /** SYS_LIGHTWEIGHT_PROT\r
139  * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection\r
140  * for certain critical regions during buffer allocation, deallocation and memory\r
141  * allocation and deallocation.\r
142  */\r
143 #if SYS_LIGHTWEIGHT_PROT\r
144 \r
145 /** SYS_ARCH_DECL_PROTECT\r
146  * declare a protection variable. This macro will default to defining a variable of\r
147  * type sys_prot_t. If a particular port needs a different implementation, then\r
148  * this macro may be defined in sys_arch.h.\r
149  */\r
150 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev\r
151 /** SYS_ARCH_PROTECT\r
152  * Perform a "fast" protect. This could be implemented by\r
153  * disabling interrupts for an embedded system or by using a semaphore or\r
154  * mutex. The implementation should allow calling SYS_ARCH_PROTECT when\r
155  * already protected. The old protection level is returned in the variable\r
156  * "lev". This macro will default to calling the sys_arch_protect() function\r
157  * which should be implemented in sys_arch.c. If a particular port needs a\r
158  * different implementation, then this macro may be defined in sys_arch.h\r
159  */\r
160 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()\r
161 /** SYS_ARCH_UNPROTECT\r
162  * Perform a "fast" set of the protection level to "lev". This could be\r
163  * implemented by setting the interrupt level to "lev" within the MACRO or by\r
164  * using a semaphore or mutex.  This macro will default to calling the\r
165  * sys_arch_unprotect() function which should be implemented in\r
166  * sys_arch.c. If a particular port needs a different implementation, then\r
167  * this macro may be defined in sys_arch.h\r
168  */\r
169 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)\r
170 sys_prot_t sys_arch_protect(void);\r
171 void sys_arch_unprotect(sys_prot_t pval);\r
172 \r
173 #else\r
174 \r
175 #define SYS_ARCH_DECL_PROTECT(lev)\r
176 #define SYS_ARCH_PROTECT(lev)\r
177 #define SYS_ARCH_UNPROTECT(lev)\r
178 \r
179 #endif /* SYS_LIGHTWEIGHT_PROT */\r
180 \r
181 #endif /* SYS_ARCH_PROTECT */\r
182 \r
183 #endif /* __LWIP_SYS_H__ */\r