netdev_test.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universit├Ąt Berlin
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 
78 #ifndef NET_NETDEV_TEST_H
79 #define NET_NETDEV_TEST_H
80 
81 #include "mutex.h"
82 
83 #ifdef MODULE_NETDEV_IEEE802154
84 #include "net/netdev/ieee802154.h"
85 #endif
86 
87 #include "net/netdev.h"
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
102 typedef int (*netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist);
103 
118 typedef int (*netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len,
119  void *info);
120 
129 typedef int (*netdev_test_init_cb_t)(netdev_t *dev);
130 
136 typedef void (*netdev_test_isr_cb_t)(netdev_t *dev);
137 
148 typedef int (*netdev_test_get_cb_t)(netdev_t *dev, void *value,
149  size_t max_len);
150 
161 typedef int (*netdev_test_set_cb_t)(netdev_t *dev, const void *value,
162  size_t value_len);
163 
169 typedef struct {
174 #ifdef MODULE_NETDEV_IEEE802154
176 #else /* MODULE_NETDEV_IEEE802154 */
178 #endif /* MODULE_NETDEV_IEEE802154 */
179 
191  void *state;
194 } netdev_test_t;
195 
202 static inline void netdev_test_set_send_cb(netdev_test_t *dev,
203  netdev_test_send_cb_t send_cb)
204 {
205  mutex_lock(&dev->mutex);
206  dev->send_cb = send_cb;
207  mutex_unlock(&dev->mutex);
208 }
209 
216 static inline void netdev_test_set_recv_cb(netdev_test_t *dev,
217  netdev_test_recv_cb_t recv_cb)
218 {
219  mutex_lock(&dev->mutex);
220  dev->recv_cb = recv_cb;
221  mutex_unlock(&dev->mutex);
222 }
223 
230 static inline void netdev_test_set_init_cb(netdev_test_t *dev,
231  netdev_test_init_cb_t init_cb)
232 {
233  mutex_lock(&dev->mutex);
234  dev->init_cb = init_cb;
235  mutex_unlock(&dev->mutex);
236 }
237 
244 static inline void netdev_test_set_isr_cb(netdev_test_t *dev,
245  netdev_test_isr_cb_t isr_cb)
246 {
247  mutex_lock(&dev->mutex);
248  dev->isr_cb = isr_cb;
249  mutex_unlock(&dev->mutex);
250 }
251 
259 static inline void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt,
260  netdev_test_get_cb_t get_cb)
261 {
262  mutex_lock(&dev->mutex);
263  dev->get_cbs[opt] = get_cb;
264  mutex_unlock(&dev->mutex);
265 }
266 
274 static inline void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt,
275  netdev_test_set_cb_t set_cb)
276 {
277  mutex_lock(&dev->mutex);
278  dev->set_cbs[opt] = set_cb;
279  mutex_unlock(&dev->mutex);
280 }
281 
288 void netdev_test_setup(netdev_test_t *dev, void *state);
289 
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif /* NET_NETDEV_TEST_H */
302 
void * state
external state for the device
Definition: netdev_test.h:191
netdev_test_set_cb_t set_cbs[NETOPT_NUMOF]
callback to handle set command
Definition: netdev_test.h:190
static void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt, netdev_test_get_cb_t get_cb)
override get callback for a certain option type
Definition: netdev_test.h:259
Definitions low-level network driver interface.
netdev_t netdev
netdev fields
Definition: netdev_test.h:177
mutex_t mutex
mutex for the device
Definition: netdev_test.h:192
netdev_test_recv_cb_t recv_cb
callback to handle receive command
Definition: netdev_test.h:186
int(* netdev_test_get_cb_t)(netdev_t *dev, void *value, size_t max_len)
Callback type to handle get commands.
Definition: netdev_test.h:148
Device descriptor for netdev dummy test driver devices.
Definition: netdev_test.h:169
void netdev_test_reset(netdev_test_t *dev)
Resets all callbacks for the device to NULL.
netdev_test_get_cb_t get_cbs[NETOPT_NUMOF]
callback to handle get command
Definition: netdev_test.h:189
netdev_test_init_cb_t init_cb
callback to handle initialization events
Definition: netdev_test.h:187
static void netdev_test_set_init_cb(netdev_test_t *dev, netdev_test_init_cb_t init_cb)
override initialization callback
Definition: netdev_test.h:230
netdev_test_isr_cb_t isr_cb
callback to handle ISR events
Definition: netdev_test.h:188
netdev_test_send_cb_t send_cb
device specific fields
Definition: netdev_test.h:185
int(* netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist)
Callback type to handle send command.
Definition: netdev_test.h:102
static void netdev_test_set_send_cb(netdev_test_t *dev, netdev_test_send_cb_t send_cb)
override send callback
Definition: netdev_test.h:202
static void netdev_test_set_recv_cb(netdev_test_t *dev, netdev_test_recv_cb_t recv_cb)
override receive callback
Definition: netdev_test.h:216
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:42
Structure to hold driver state.
Definition: netdev.h:275
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
Definitions for netdev common IEEE 802.15.4 code.
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
Definition: mutex.h:111
maximum number of options defined here.
Definition: netopt.h:564
RIOT synchronization API.
int(* netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len, void *info)
Callback type to handle receive command.
Definition: netdev_test.h:118
void netdev_test_setup(netdev_test_t *dev, void *state)
Setup a given netdev dummy test driver device.
iolist structure definition
Definition: iolist.h:37
Mutex structure.
Definition: mutex.h:36
Extended structure to hold IEEE 802.15.4 driver state.
static void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt, netdev_test_set_cb_t set_cb)
override get callback for a certain option type
Definition: netdev_test.h:274
int(* netdev_test_init_cb_t)(netdev_t *dev)
Callback type to handle device initialization.
Definition: netdev_test.h:129
void(* netdev_test_isr_cb_t)(netdev_t *dev)
Callback type to handle user-space ISR events.
Definition: netdev_test.h:136
static void netdev_test_set_isr_cb(netdev_test_t *dev, netdev_test_isr_cb_t isr_cb)
override ISR event handler callback
Definition: netdev_test.h:244
int(* netdev_test_set_cb_t)(netdev_t *dev, const void *value, size_t value_len)
Callback type to handle set commands.
Definition: netdev_test.h:161