sys_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef ARCH_SYS_ARCH_H
22 #define ARCH_SYS_ARCH_H
23 
24 #include <stdbool.h>
25 #include <stdint.h>
26 
27 #include "cib.h"
28 #include "sched.h"
29 #include "mbox.h"
30 #include "mutex.h"
31 #include "random.h"
32 #include "sema.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
41 /* prefer mutexes rather than binary semaphores */
42 #define LWIP_COMPAT_MUTEX (0)
43 
50 #define SYS_ARCH_PROTECT(x) mutex_lock(&x)
51 #define SYS_ARCH_UNPROTECT(x) mutex_unlock(&x)
52 #define SYS_ARCH_DECL_PROTECT(x) mutex_t x = MUTEX_INIT
53 
59 typedef sema_t sys_sem_t;
61 static inline bool sys_sem_valid(sys_sem_t *sem)
62 {
63  return sem != NULL;
64 }
65 
66 #define sys_sem_valid(sem) (sys_sem_valid(sem))
67 
68 #define sys_sem_set_invalid(sem)
69 
77 static inline bool sys_mutex_valid(sys_mutex_t *mutex)
78 {
79  return mutex != NULL;
80 }
81 
82 #define sys_mutex_valid(mutex) (sys_mutex_valid(mutex))
83 #define sys_mutex_set_invalid(mutex)
84 
91 #define SYS_MBOX_SIZE (8)
92 
96 typedef struct {
98  msg_t msgs[SYS_MBOX_SIZE];
99 } sys_mbox_t;
100 
101 static inline bool sys_mbox_valid(sys_mbox_t *mbox)
102 {
103  return (mbox != NULL) && (mbox->mbox.cib.mask != 0);
104 }
105 
106 static inline void sys_mbox_set_invalid(sys_mbox_t *mbox)
107 {
108  if (mbox != NULL) {
109  mbox->mbox.cib.mask = 0;
110  }
111 }
112 
113 #define sys_mbox_valid(mbox) (sys_mbox_valid(mbox))
114 #define sys_mbox_set_invalid(mbox) (sys_mbox_set_invalid(mbox))
115 
119 #ifdef MODULE_RANDOM
120 
123 #define LWIP_RAND() (random_uint32())
124 #endif
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif /* ARCH_SYS_ARCH_H */
131 
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
sys_mutex_t
mutex_t sys_mutex_t
Platform specific mutex type.
Definition: sys_arch.h:75
sys_sem_t
sema_t sys_sem_t
Platform specific semaphore type.
Definition: sys_arch.h:59
sched.h
Scheduler API definition.
random.h
Common interface to the software PRNG.
cib_t::mask
unsigned int mask
Size of buffer -1, i.e.
Definition: cib.h:37
sema.h
Semaphore definitions.
mbox_t
Mailbox struct definition.
Definition: mbox.h:41
mbox.h
Mailbox API.
sys_mbox_t::mbox
mbox_t mbox
RIOT mbox.
Definition: sys_arch.h:97
sys_mbox_t
Platform specific mailbox type.
Definition: sys_arch.h:96
cib.h
Circular integer buffer interface.
mutex.h
Mutex for thread synchronization.
sema_t
A Semaphore.
Definition: sema.h:63
msg_t
Describes a message object which can be sent between threads.
Definition: msg.h:185
sys_thread_t
kernel_pid_t sys_thread_t
Platform specific thread type.
Definition: sys_arch.h:117
mbox_t::cib
cib_t cib
cib for msg array
Definition: mbox.h:44
mutex_t
Mutex structure.
Definition: mutex.h:120