mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
netdev_test: avoid explicit cast to netdev
This commit is contained in:
parent
d33008483e
commit
b483d1f809
@ -46,7 +46,7 @@
|
|||||||
* ipv6_addr_t dst = IPV6_ADDR_UNSPECIFIED;
|
* ipv6_addr_t dst = IPV6_ADDR_UNSPECIFIED;
|
||||||
*
|
*
|
||||||
* netdev_test_setup(&dev, NULL);
|
* netdev_test_setup(&dev, NULL);
|
||||||
* dev->driver->init((netdev_t *)&dev)
|
* dev->driver->init(&dev->netdev->netdev)
|
||||||
* // initialize stack and connect `dev` to it
|
* // initialize stack and connect `dev` to it
|
||||||
* // ...
|
* // ...
|
||||||
* mutex_lock(&wait);
|
* mutex_lock(&wait);
|
||||||
@ -80,10 +80,7 @@
|
|||||||
|
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
|
|
||||||
#ifdef MODULE_NETDEV_IEEE802154
|
|
||||||
#include "net/netdev/ieee802154.h"
|
#include "net/netdev/ieee802154.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "net/netdev.h"
|
#include "net/netdev.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -33,7 +33,8 @@ void netdev_test_reset(netdev_test_t *dev)
|
|||||||
|
|
||||||
static int _send(netdev_t *netdev, const iolist_t *iolist)
|
static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
int res = -EINVAL;
|
int res = -EINVAL;
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
@ -46,7 +47,8 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
|||||||
|
|
||||||
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
int res = (buf == NULL) ? 0 : len; /* assume everything would be fine */
|
int res = (buf == NULL) ? 0 : len; /* assume everything would be fine */
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
@ -63,7 +65,8 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
|||||||
|
|
||||||
static int _init(netdev_t *netdev)
|
static int _init(netdev_t *netdev)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
int res = 0; /* assume everything would be fine */
|
int res = 0; /* assume everything would be fine */
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
@ -76,7 +79,8 @@ static int _init(netdev_t *netdev)
|
|||||||
|
|
||||||
static void _isr(netdev_t *netdev)
|
static void _isr(netdev_t *netdev)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
if (dev->isr_cb != NULL) {
|
if (dev->isr_cb != NULL) {
|
||||||
@ -90,7 +94,8 @@ static void _isr(netdev_t *netdev)
|
|||||||
|
|
||||||
static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
|
static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
int res = -ENOTSUP; /* option assumed to be not supported */
|
int res = -ENOTSUP; /* option assumed to be not supported */
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
@ -103,7 +108,8 @@ static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
|
|||||||
|
|
||||||
static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t value_len)
|
static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t value_len)
|
||||||
{
|
{
|
||||||
netdev_test_t *dev = (netdev_test_t *)netdev;
|
netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev),
|
||||||
|
netdev_test_t, netdev);
|
||||||
int res = -ENOTSUP; /* option assumed to be not supported */
|
int res = -ENOTSUP; /* option assumed to be not supported */
|
||||||
|
|
||||||
mutex_lock(&dev->mutex);
|
mutex_lock(&dev->mutex);
|
||||||
@ -125,9 +131,7 @@ static const netdev_driver_t _driver = {
|
|||||||
|
|
||||||
void netdev_test_setup(netdev_test_t *dev, void *state)
|
void netdev_test_setup(netdev_test_t *dev, void *state)
|
||||||
{
|
{
|
||||||
netdev_t *netdev = (netdev_t *)dev;
|
dev->netdev.netdev.driver = &_driver;
|
||||||
|
|
||||||
netdev->driver = &_driver;
|
|
||||||
dev->state = state;
|
dev->state = state;
|
||||||
mutex_init(&dev->mutex);
|
mutex_init(&dev->mutex);
|
||||||
netdev_test_reset(dev);
|
netdev_test_reset(dev);
|
||||||
|
@ -138,7 +138,7 @@ static int test_receive(void)
|
|||||||
thread_getpid());
|
thread_getpid());
|
||||||
msg_t msg;
|
msg_t msg;
|
||||||
|
|
||||||
if (_dev.netdev.event_callback == NULL) {
|
if (_dev.netdev.netdev.event_callback == NULL) {
|
||||||
puts("Device's event_callback not set");
|
puts("Device's event_callback not set");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ static int test_receive(void)
|
|||||||
/* register for GNRC_NETTYPE_UNDEF */
|
/* register for GNRC_NETTYPE_UNDEF */
|
||||||
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &me);
|
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &me);
|
||||||
/* fire ISR event */
|
/* fire ISR event */
|
||||||
netdev_trigger_event_isr((netdev_t *)&_dev.netdev);
|
netdev_trigger_event_isr(&_dev.netdev.netdev);
|
||||||
/* wait for packet from MAC layer*/
|
/* wait for packet from MAC layer*/
|
||||||
msg_receive(&msg);
|
msg_receive(&msg);
|
||||||
/* check message */
|
/* check message */
|
||||||
@ -261,7 +261,7 @@ int main(void)
|
|||||||
netdev_test_set_get_cb(&_dev, NETOPT_ADDRESS, _dev_get_addr);
|
netdev_test_set_get_cb(&_dev, NETOPT_ADDRESS, _dev_get_addr);
|
||||||
netdev_test_set_set_cb(&_dev, NETOPT_ADDRESS, _dev_set_addr);
|
netdev_test_set_set_cb(&_dev, NETOPT_ADDRESS, _dev_set_addr);
|
||||||
gnrc_netif_ethernet_create(&_netif, _mac_stack, _MAC_STACKSIZE, _MAC_PRIO,
|
gnrc_netif_ethernet_create(&_netif, _mac_stack, _MAC_STACKSIZE, _MAC_PRIO,
|
||||||
"netdev_test", (netdev_t *)&_dev);
|
"netdev_test", &_dev.netdev.netdev);
|
||||||
_mac_pid = _netif.pid;
|
_mac_pid = _netif.pid;
|
||||||
|
|
||||||
/* test execution */
|
/* test execution */
|
||||||
|
Loading…
Reference in New Issue
Block a user