UbixOS V2 2.0

sys.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 */
31
32 #ifndef NET_HDR_SYS_H
33 #define NET_HDR_SYS_H
34
35 #include <net/opt.h>
36 #include <net/arch/sys_arch.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #if NO_SYS
43
44 #else /* NO_SYS */
45
47 #define SYS_ARCH_TIMEOUT 0xffffffffUL
48
52 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
53
54 #include "net/err.h"
55 #include "net/arch/sys_arch.h"
56
58 typedef void (*lwip_thread_fn)(void *arg);
59
60 /* Function prototypes for functions to be implemented by platform ports
61 (in sys_arch.c) */
62
63 /* Mutex functions: */
64
67 #ifndef LWIP_COMPAT_MUTEX
68 #define LWIP_COMPAT_MUTEX 0
69 #endif
70
71 #if LWIP_COMPAT_MUTEX
72 /* for old ports that don't have mutexes: define them to binary semaphores */
73 #define sys_mutex_t sys_sem_t
74 #define sys_mutex_new(mutex) sys_sem_new(mutex, 1)
75 #define sys_mutex_lock(mutex) sys_sem_wait(mutex)
76 #define sys_mutex_unlock(mutex) sys_sem_signal(mutex)
77 #define sys_mutex_free(mutex) sys_sem_free(mutex)
78 #define sys_mutex_valid(mutex) sys_sem_valid(mutex)
79 #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex)
80
81 #else /* LWIP_COMPAT_MUTEX */
82
91 err_t sys_mutex_new(sys_mutex_t *mutex);
97 void sys_mutex_lock(sys_mutex_t *mutex);
103 void sys_mutex_unlock(sys_mutex_t *mutex);
109 void sys_mutex_free(sys_mutex_t *mutex);
110 #ifndef sys_mutex_valid
111
115 int sys_mutex_valid(sys_mutex_t *mutex);
116 #endif
117 #ifndef sys_mutex_set_invalid
118
122 void sys_mutex_set_invalid(sys_mutex_t *mutex);
123 #endif
124 #endif /* LWIP_COMPAT_MUTEX */
125
126 /* Semaphore functions: */
127
135 err_t sys_sem_new(sys_sem_t **sem, u8_t count);
141 void sys_sem_signal(struct sys_sem **s);
150 uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout);
156 void sys_sem_free(sys_sem_t **sem);
158 #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
159 #ifndef sys_sem_valid
160
164 int sys_sem_valid(struct sys_sem **s);
165 #endif
166 #ifndef sys_sem_set_invalid
167
171 void sys_sem_set_invalid(struct sys_sem **s);
172 #endif
173 #ifndef sys_sem_valid_val
174
177 #define sys_sem_valid_val(sem) sys_sem_valid(&(sem))
178 #endif
179 #ifndef sys_sem_set_invalid_val
180
183 #define sys_sem_set_invalid_val(sem) sys_sem_set_invalid(&(sem))
184 #endif
185
186 #ifndef sys_msleep
187
191 void sys_msleep(u32_t ms); /* only has a (close to) 1 ms resolution. */
192 #endif
193
194 /* Mailbox functions. */
195
203 err_t sys_mbox_new(struct sys_mbox **mb, int size);
211 void sys_mbox_post(struct sys_mbox **mb, void *msg);
218 err_t sys_mbox_trypost(struct sys_mbox **mb, void *msg);
229 uint32_t sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, uint32_t timeout);
230 /* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */
231 #ifndef sys_arch_mbox_tryfetch
232
240 uint32_t sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg);
241 #endif
242
245 #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
246
251 void sys_mbox_free(struct sys_mbox **mb);
252 #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
253 #ifndef sys_mbox_valid
254
258 int sys_mbox_valid(struct sys_mbox **mb);
259 #endif
260 #ifndef sys_mbox_set_invalid
261
265 void sys_mbox_set_invalid(struct sys_mbox **mb);
266 #endif
267 #ifndef sys_mbox_valid_val
268
271 #define sys_mbox_valid_val(mbox) sys_mbox_valid(&(mbox))
272 #endif
273 #ifndef sys_mbox_set_invalid_val
274
277 #define sys_mbox_set_invalid_val(mbox) sys_mbox_set_invalid(&(mbox))
278 #endif
279
280
291 sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio);
292
293 #endif /* NO_SYS */
294
295 /* sys_init() must be called before anything else. */
296 void sys_init(void);
297
298 #ifndef sys_jiffies
299
302 u32_t sys_jiffies(void);
303 #endif
304
310 u32_t sys_now(void);
311
312 /* Critical Region Protection */
313 /* These functions must be implemented in the sys_arch.c file.
314 In some implementations they can provide a more light-weight protection
315 mechanism than using semaphores. Otherwise semaphores can be used for
316 implementation */
317 #ifndef SYS_ARCH_PROTECT
318
323 #if SYS_LIGHTWEIGHT_PROT
324
332 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
333
344 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
345
355 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
356 sys_prot_t sys_arch_protect(void);
357 void sys_arch_unprotect(sys_prot_t pval);
358
359 #else
360
361 #define SYS_ARCH_DECL_PROTECT(lev)
362 #define SYS_ARCH_PROTECT(lev)
363 #define SYS_ARCH_UNPROTECT(lev)
364
365 #endif /* SYS_LIGHTWEIGHT_PROT */
366
367 #endif /* SYS_ARCH_PROTECT */
368
369 /*
370 * Macros to set/get and increase/decrease variables in a thread-safe way.
371 * Use these for accessing variable that are used from more than one thread.
372 */
373
374 #ifndef SYS_ARCH_INC
375 #define SYS_ARCH_INC(var, val) do { \
376 SYS_ARCH_DECL_PROTECT(old_level); \
377 SYS_ARCH_PROTECT(old_level); \
378 var += val; \
379 SYS_ARCH_UNPROTECT(old_level); \
380 } while(0)
381 #endif /* SYS_ARCH_INC */
382
383 #ifndef SYS_ARCH_DEC
384 #define SYS_ARCH_DEC(var, val) do { \
385 SYS_ARCH_DECL_PROTECT(old_level); \
386 SYS_ARCH_PROTECT(old_level); \
387 var -= val; \
388 SYS_ARCH_UNPROTECT(old_level); \
389 } while(0)
390 #endif /* SYS_ARCH_DEC */
391
392 #ifndef SYS_ARCH_GET
393 #define SYS_ARCH_GET(var, ret) do { \
394 SYS_ARCH_DECL_PROTECT(old_level); \
395 SYS_ARCH_PROTECT(old_level); \
396 ret = var; \
397 SYS_ARCH_UNPROTECT(old_level); \
398 } while(0)
399 #endif /* SYS_ARCH_GET */
400
401 #ifndef SYS_ARCH_SET
402 #define SYS_ARCH_SET(var, val) do { \
403 SYS_ARCH_DECL_PROTECT(old_level); \
404 SYS_ARCH_PROTECT(old_level); \
405 var = val; \
406 SYS_ARCH_UNPROTECT(old_level); \
407 } while(0)
408 #endif /* SYS_ARCH_SET */
409
410
411 #ifdef __cplusplus
412 }
413 #endif
414
415 #endif /* NET_HDR_SYS_H */
opt.h
sys_init
void sys_init(void)
Definition: sys_arch.c:32
sys_sem_set_invalid
void sys_sem_set_invalid(struct sys_sem **s)
Definition: sys_arch.c:140
sys_mbox_free
void sys_mbox_free(struct sys_mbox **mb)
Definition: sys_arch.c:194
sys_sem_new
err_t sys_sem_new(sys_sem_t **sem, u8_t count)
Definition: sys_arch.c:52
sys_arch_mbox_tryfetch
uint32_t sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg)
Definition: sys_arch.c:336
sys_sem_free
void sys_sem_free(sys_sem_t **sem)
Definition: sys_arch.c:75
sys_sem_valid
int sys_sem_valid(struct sys_sem **s)
Definition: sys_arch.c:132
sys_arch_sem_wait
uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout)
Definition: sys_arch.c:105
thread
Definition: thread.h:40
u32_t
uint32_t u32_t
Definition: arch.h:126
sys_thread
Definition: sys_arch.h:43
sys_jiffies
u32_t sys_jiffies(void)
sys_arch.h
sys_thread_new
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:379
sys_mbox_post
void sys_mbox_post(struct sys_mbox **mb, void *msg)
Definition: sys_arch.c:215
sys_mutex_free
void sys_mutex_free(sys_mutex_t *mutex)
Definition: sys_arch.c:149
sys_mutex_lock
void sys_mutex_lock(sys_mutex_t *mutex)
Definition: sys_arch.c:153
sys_sem
Definition: sem.h:36
sys_msleep
void sys_msleep(u32_t ms)
Definition: sys.c:93
lwip_thread_fn
void(* lwip_thread_fn)(void *arg)
Definition: sys.h:58
sys_now
u32_t sys_now(void)
Definition: sys_arch.c:497
sys_sem_signal
void sys_sem_signal(struct sys_sem **s)
Definition: sys_arch.c:89
u8_t
uint8_t u8_t
Definition: arch.h:122
err.h
mutex
struct ubthread_mutex_list * mutex
Definition: ubthread.c:43
uint32_t
__uint32_t uint32_t
Definition: types.h:46
sys_mbox_valid
int sys_mbox_valid(struct sys_mbox **mb)
Definition: sys_arch.c:367
sys_mutex_new
err_t sys_mutex_new(sys_mutex_t *mutex)
Definition: sys_arch.c:144
sys_arch_mbox_fetch
uint32_t sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, uint32_t timeout)
Definition: sys_arch.c:287
sys_mbox_set_invalid
void sys_mbox_set_invalid(struct sys_mbox **mb)
Definition: sys_arch.c:375
sys_mutex_unlock
void sys_mutex_unlock(sys_mutex_t *mutex)
Definition: sys_arch.c:157
err_t
s8_t err_t
Definition: err.h:57
sys_mutex_set_invalid
void sys_mutex_set_invalid(sys_mutex_t *mutex)
name
const char * name
Definition: pci.c:37
sys_mutex_valid
int sys_mutex_valid(sys_mutex_t *mutex)
sys_mbox_new
err_t sys_mbox_new(struct sys_mbox **mb, int size)
Definition: sys_arch.c:161
sys_mbox_trypost
err_t sys_mbox_trypost(struct sys_mbox **mb, void *msg)
Definition: sys_arch.c:251
sys_mutex
Definition: sys_arch.h:16
sys_mbox
Definition: sys_arch.h:22