lwIP: operating system requirements
[bertos.git] / bertos / net / lwip / src / include / arch / sys_arch.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Luca Ottaviano <lottaviano@develer.com>
34  *
35  * \brief Emulation Layer for lwIP
36  */
37
38 #ifndef LWIP_SYS_ARCH_H
39 #define LWIP_SYS_ARCH_H
40
41 #include <arch/cc.h>
42
43 #include <kern/sem.h>
44 #include <kern/msg.h>
45 #include <kern/proc.h>
46
47 /****************************************************************************/
48
49 /*
50  * Generic mutex (binary semaphore) prototypes
51  *
52  * TODO: move this to a different place (i.e., bertos/kern/sem.h).
53  */
54 #include <cpu/byteorder.h> // cpu_atomic_xchg()
55 #include <cpu/types.h>
56
57 #include <struct/list.h>
58
59 #define MUTEX_UNLOCKED  1
60 #define MUTEX_LOCKED    (!MUTEX_UNLOCKED)
61
62 typedef struct Mutex
63 {
64         List wait_queue;
65         cpu_atomic_t count;
66 } Mutex;
67
68 void mutex_init(struct Mutex *s);
69 bool mutex_attempt(struct Mutex *s);
70 void mutex_obtain(struct Mutex *s);
71 void mutex_release(struct Mutex *s);
72
73 /****************************************************************************/
74
75 typedef Mutex *sys_sem_t;
76 typedef MsgPort *sys_mbox_t;
77 typedef struct Process *sys_thread_t;
78 // TODO: what does it mean?
79 typedef int sys_prot_t;
80
81 #define SYS_MBOX_NULL (sys_mbox_t)0
82 #define SYS_SEM_NULL  (sys_sem_t)0
83
84
85 EXTERN_C_BEGIN
86
87 void sys_init(void);
88
89 sys_sem_t sys_sem_new(u8_t count);
90 void sys_sem_free(sys_sem_t sem);
91 void sys_sem_signal(sys_sem_t sem);
92 u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);
93
94 sys_mbox_t sys_mbox_new(int);
95 void sys_mbox_free(sys_mbox_t mbox);
96 void sys_mbox_post(sys_mbox_t mbox, void *msg);
97 u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
98
99 struct sys_timeouts *sys_arch_timeouts(void);
100
101 EXTERN_C_END
102
103 #endif