aboutsummaryrefslogtreecommitdiffstats
path: root/core/lwip/src/include/arch/sys_arch.h
blob: 867cf314606b68fa4835306bbd2bcaaebdd31795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef __LWIP_ARCH_SYS_ARCH_H__
#define __LWIP_ARCH_SYS_ARCH_H__

#include <stddef.h>
#include "arch/cc.h"
#include "thread.h"
#include "mbox.h"

typedef struct semaphore *sys_sem_t;
typedef struct mailbox   *sys_mbox_t;
typedef struct thread    *sys_thread_t;

#define sys_sem_signal(x) sem_up(x)

#define SYS_MBOX_NULL	NULL
#define SYS_SEM_NULL	NULL

static inline sys_thread_t sys_thread_new(char *name, void (*thread)(void *),
					  void *arg, int stacksize, int prio)
{
    return start_thread(name, stacksize, prio, thread, arg);
}

extern void __compile_time_error(void);

#define SYS_ARCH_OP(var, val, inc, add)					\
do {									\
    if (__builtin_constant_p(val) && (val) == 1) {			\
	switch (sizeof(var)) {						\
	case 1:								\
	    asm volatile(inc "b %0" : "+m" (var));			\
	    break;							\
	case 2:								\
	    asm volatile(inc "w %0" : "+m" (var));			\
	    break;							\
	case 4:								\
	    asm volatile(inc "l %0" : "+m" (var));			\
	    break;							\
	default:							\
	    __compile_time_error();					\
	    break;							\
	}								\
    } else {								\
	switch (sizeof(var)) {						\
	case 1:								\
	    asm volatile(add "b %1,%0" : "+m" (var) : "ri" (val));	\
	    break;							\
	case 2:								\
	    asm volatile(add "w %1,%0" : "+m" (var) : "ri" (val));	\
	    break;							\
	case 4:								\
	    asm volatile(add "l %1,%0" : "+m" (var) : "ri" (val));	\
	    break;							\
	default:							\
	    __compile_time_error();					\
	    break;							\
	}								\
    }									\
} while (0)

static inline struct sys_timeouts *sys_arch_timeouts(void)
{
    return (struct sys_timeouts *)&current()->pvt;
}

#define SYS_ARCH_INC(var, val) SYS_ARCH_OP(var, val, "inc", "add")
#define SYS_ARCH_DEC(var, val) SYS_ARCH_OP(var, val, "dec", "sub")

#define SYS_ARCH_GET(var, ret)					\
    do {						 	\
        volatile __typeof__(var) * const __varp = &(var);	\
    	ret = *__varp;						\
    } while (0)

#define SYS_ARCH_SET(var, val)					\
    do {						 	\
        volatile __typeof__(var) * const __varp = &(var);	\
    	*__varp = val;						\
    } while (0)

#endif /* __LWIP_ARCH_SYS_ARCH_H__ */