32 #ifndef __LWIP_SYS_H__
33 #define __LWIP_SYS_H__
37 #include "eagle_soc.h"
47 typedef u8_t sys_sem_t;
48 typedef u8_t sys_mutex_t;
49 typedef u8_t sys_mbox_t;
51 #define sys_sem_new(s, c) ERR_OK
52 #define sys_sem_signal(s)
53 #define sys_sem_wait(s)
54 #define sys_arch_sem_wait(s,t)
55 #define sys_sem_free(s)
56 #define sys_mutex_new(mu) ERR_OK
57 #define sys_mutex_lock(mu)
58 #define sys_mutex_unlock(mu)
59 #define sys_mutex_free(mu)
60 #define sys_mbox_new(m, s) ERR_OK
61 #define sys_mbox_fetch(m,d)
62 #define sys_mbox_tryfetch(m,d)
63 #define sys_mbox_post(m,d)
64 #define sys_mbox_trypost(m,d)
65 #define sys_mbox_free(m)
67 #define sys_thread_new(n,t,a,s,p)
74 #define SYS_ARCH_TIMEOUT 0xffffffffUL
79 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
82 #include "arch/sys_arch.h"
85 typedef void (*lwip_thread_fn)(
void *arg);
96 #define sys_mutex_t sys_sem_t
97 #define sys_mutex_new(mutex) sys_sem_new(mutex, 1)
98 #define sys_mutex_lock(mutex) sys_sem_wait(mutex)
99 #define sys_mutex_unlock(mutex) sys_sem_signal(mutex)
100 #define sys_mutex_free(mutex) sys_sem_free(mutex)
101 #define sys_mutex_valid(mutex) sys_sem_valid(mutex)
102 #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex)
109 err_t sys_mutex_new(sys_mutex_t *mutex);
112 void sys_mutex_lock(sys_mutex_t *mutex);
115 void sys_mutex_unlock(sys_mutex_t *mutex);
118 void sys_mutex_free(sys_mutex_t *mutex);
119 #ifndef sys_mutex_valid
121 int sys_mutex_valid(sys_mutex_t *mutex);
123 #ifndef sys_mutex_set_invalid
125 void sys_mutex_set_invalid(sys_mutex_t *mutex);
135 err_t sys_sem_new(sys_sem_t *sem, u8_t count);
138 void sys_sem_signal(sys_sem_t *sem);
144 u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout);
147 void sys_sem_free(sys_sem_t *sem);
149 #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
150 #ifndef sys_sem_valid
152 int sys_sem_valid(sys_sem_t *sem);
154 #ifndef sys_sem_set_invalid
156 void sys_sem_set_invalid(sys_sem_t *sem);
161 void sys_msleep(u32_t ms);
170 err_t sys_mbox_new(sys_mbox_t *mbox,
int size);
175 void sys_mbox_post(sys_mbox_t *mbox,
void *msg);
179 err_t sys_mbox_trypost(sys_mbox_t *mbox,
void *msg);
187 u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox,
void **msg, u32_t timeout);
189 #ifndef sys_arch_mbox_tryfetch
196 u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox,
void **msg);
199 #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
202 void sys_mbox_free(sys_mbox_t *mbox);
203 #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
204 #ifndef sys_mbox_valid
206 int sys_mbox_valid(sys_mbox_t *mbox);
208 #ifndef sys_mbox_set_invalid
210 void sys_mbox_set_invalid(sys_mbox_t *mbox);
220 sys_thread_t sys_thread_new(
const char *name, lwip_thread_fn thread,
void *arg,
int stacksize,
int prio);
225 void sys_init(
void)ICACHE_FLASH_ATTR;
229 u32_t sys_jiffies(
void)ICACHE_FLASH_ATTR;
234 static inline u32_t sys_now(
void) ICACHE_FLASH_ATTR;
235 static inline u32_t sys_now(
void)
237 return NOW()/(TIMER_CLK_FREQ/1000);
245 #ifndef SYS_ARCH_PROTECT
251 #if SYS_LIGHTWEIGHT_PROT
258 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
268 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
277 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
278 sys_prot_t sys_arch_protect(
void)ICACHE_FLASH_ATTR;
279 void sys_arch_unprotect(sys_prot_t pval)ICACHE_FLASH_ATTR;
283 #define SYS_ARCH_DECL_PROTECT(lev)
284 #define SYS_ARCH_PROTECT(lev) lev = os_intr_lock() //fix by ives at 2014.3.24
285 #define SYS_ARCH_UNPROTECT(lev) lev = os_intr_unlock()
297 #define SYS_ARCH_INC(var, val) do { \
298 SYS_ARCH_DECL_PROTECT(old_level); \
299 SYS_ARCH_PROTECT(old_level); \
301 SYS_ARCH_UNPROTECT(old_level); \
306 #define SYS_ARCH_DEC(var, val) do { \
307 SYS_ARCH_DECL_PROTECT(old_level); \
308 SYS_ARCH_PROTECT(old_level); \
310 SYS_ARCH_UNPROTECT(old_level); \
315 #define SYS_ARCH_GET(var, ret) do { \
316 SYS_ARCH_DECL_PROTECT(old_level); \
317 SYS_ARCH_PROTECT(old_level); \
319 SYS_ARCH_UNPROTECT(old_level); \
324 #define SYS_ARCH_SET(var, val) do { \
325 SYS_ARCH_DECL_PROTECT(old_level); \
326 SYS_ARCH_PROTECT(old_level); \
328 SYS_ARCH_UNPROTECT(old_level); \