• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __LWIP_ARCH_SYS_ARCH_H__
2 #define __LWIP_ARCH_SYS_ARCH_H__
3 
4 #include <stddef.h>
5 #include "arch/cc.h"
6 #include <thread.h>
7 #include <mbox.h>
8 
9 typedef struct semaphore *sys_sem_t;
10 typedef struct mailbox   *sys_mbox_t;
11 typedef struct thread    *sys_thread_t;
12 
sys_sem_signal(sys_sem_t * sem)13 static inline void sys_sem_signal(sys_sem_t *sem)
14 {
15     if (!!sem)
16 	sem_up(*sem);
17 }
18 
19 #define sys_now ms_timer
20 
21 #define SYS_MBOX_NULL	NULL
22 #define SYS_SEM_NULL	NULL
23 
24 extern void __compile_time_error(void);
25 
26 #define SYS_ARCH_OP(var, val, inc, add)					\
27 do {									\
28     if (__builtin_constant_p(val) && (val) == 1) {			\
29 	switch (sizeof(var)) {						\
30 	case 1:								\
31 	    asm volatile(inc "b %0" : "+m" (var));			\
32 	    break;							\
33 	case 2:								\
34 	    asm volatile(inc "w %0" : "+m" (var));			\
35 	    break;							\
36 	case 4:								\
37 	    asm volatile(inc "l %0" : "+m" (var));			\
38 	    break;							\
39 	default:							\
40 	    __compile_time_error();					\
41 	    break;							\
42 	}								\
43     } else {								\
44 	switch (sizeof(var)) {						\
45 	case 1:								\
46 	    asm volatile(add "b %1,%0" : "+m" (var) : "ri" (val));	\
47 	    break;							\
48 	case 2:								\
49 	    asm volatile(add "w %1,%0" : "+m" (var) : "ri" (val));	\
50 	    break;							\
51 	case 4:								\
52 	    asm volatile(add "l %1,%0" : "+m" (var) : "ri" (val));	\
53 	    break;							\
54 	default:							\
55 	    __compile_time_error();					\
56 	    break;							\
57 	}								\
58     }									\
59 } while (0)
60 
sys_arch_timeouts(void)61 static inline struct sys_timeouts *sys_arch_timeouts(void)
62 {
63     return (struct sys_timeouts *)&current()->pvt;
64 }
65 
66 #define SYS_ARCH_INC(var, val) SYS_ARCH_OP(var, val, "inc", "add")
67 #define SYS_ARCH_DEC(var, val) SYS_ARCH_OP(var, val, "dec", "sub")
68 
69 #define SYS_ARCH_GET(var, ret)					\
70     do {						 	\
71         volatile __typeof__(var) * const __varp = &(var);	\
72     	ret = *__varp;						\
73     } while (0)
74 
75 #define SYS_ARCH_SET(var, val)					\
76     do {						 	\
77         volatile __typeof__(var) * const __varp = &(var);	\
78     	*__varp = val;						\
79     } while (0)
80 
81 #define SYS_ARCH_DECL_PROTECT(VAR) irq_state_t VAR
82 #define SYS_ARCH_PROTECT(VAR) VAR = irq_save()
83 #define SYS_ARCH_UNPROTECT(VAR) irq_restore(VAR)
84 
85 #endif /* __LWIP_ARCH_SYS_ARCH_H__ */
86