1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

kw2xrf: avoid explicit cast to netdev

This commit is contained in:
Jose Alamos 2021-06-21 16:40:38 +02:00
parent b1c86a9ae3
commit 8cc28a29e1
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
2 changed files with 31 additions and 18 deletions

View File

@ -56,7 +56,7 @@ static void kw2xrf_set_address(kw2xrf_t *dev)
void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params)
{
netdev_t *netdev = (netdev_t *)dev;
netdev_t *netdev = &dev->netdev.netdev;
netdev->driver = &kw2xrf_driver;
/* initialize device descriptor */

View File

@ -55,8 +55,9 @@ static void _isr(netdev_t *netdev);
static void _irq_handler(void *arg)
{
netdev_t *netdev = (netdev_t *) arg;
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_t *netdev = arg;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
thread_flags_set(dev->thread, KW2XRF_THREAD_FLAG_ISR);
@ -69,7 +70,8 @@ static void _irq_handler(void *arg)
static int _init(netdev_t *netdev)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
dev->thread = thread_get_active();
@ -119,7 +121,7 @@ static void kw2xrf_wait_idle(kw2xrf_t *dev)
while (1) {
/* TX in progress */
/* Handle any outstanding IRQ first */
_isr((netdev_t *)dev);
_isr(&dev->netdev.netdev);
/* _isr() will switch the transceiver back to idle after
* handling the TX complete IRQ */
if (kw2xrf_can_switch_to_idle(dev)) {
@ -136,7 +138,8 @@ static void kw2xrf_wait_idle(kw2xrf_t *dev)
static int _send(netdev_t *netdev, const iolist_t *iolist)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t *pkt_buf = &(dev->buf[1]);
size_t len = 0;
@ -178,7 +181,8 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
size_t pkt_len = 0;
/* get size of the received packet */
@ -241,7 +245,8 @@ static netopt_state_t _get_state(kw2xrf_t *dev)
int _get(netdev_t *netdev, netopt_t opt, void *value, size_t len)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
if (dev == NULL) {
return -ENODEV;
@ -364,12 +369,14 @@ int _get(netdev_t *netdev, netopt_t opt, void *value, size_t len)
break;
}
return netdev_ieee802154_get((netdev_ieee802154_t *)netdev, opt, value, len);
return netdev_ieee802154_get(container_of(netdev, netdev_ieee802154_t, netdev),
opt, value, len);
}
static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
int res = -ENOTSUP;
if (dev == NULL) {
@ -523,8 +530,8 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len)
}
if (res == -ENOTSUP) {
res = netdev_ieee802154_set((netdev_ieee802154_t *)netdev, opt,
value, len);
res = netdev_ieee802154_set(container_of(netdev, netdev_ieee802154_t, netdev),
opt, value, len);
}
return res;
@ -532,7 +539,8 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len)
static void _isr_event_seq_r(netdev_t *netdev, uint8_t *dregs)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t irqsts1 = 0;
if (dregs[MKW2XDM_IRQSTS1] & MKW2XDM_IRQSTS1_RXWTRMRKIRQ) {
@ -568,7 +576,8 @@ static void _isr_event_seq_r(netdev_t *netdev, uint8_t *dregs)
static void _isr_event_seq_t(netdev_t *netdev, uint8_t *dregs)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t irqsts1 = 0;
if (dregs[MKW2XDM_IRQSTS1] & MKW2XDM_IRQSTS1_TXIRQ) {
@ -603,7 +612,8 @@ static void _isr_event_seq_t(netdev_t *netdev, uint8_t *dregs)
/* Standalone CCA */
static void _isr_event_seq_cca(netdev_t *netdev, uint8_t *dregs)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t irqsts1 = 0;
if ((dregs[MKW2XDM_IRQSTS1] & MKW2XDM_IRQSTS1_CCAIRQ) &&
@ -623,7 +633,8 @@ static void _isr_event_seq_cca(netdev_t *netdev, uint8_t *dregs)
static void _isr_event_seq_tr(netdev_t *netdev, uint8_t *dregs)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t irqsts1 = 0;
if (dregs[MKW2XDM_IRQSTS1] & MKW2XDM_IRQSTS1_TXIRQ) {
@ -689,7 +700,8 @@ static void _isr_event_seq_tr(netdev_t *netdev, uint8_t *dregs)
static void _isr_event_seq_ccca(netdev_t *netdev, uint8_t *dregs)
{
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
uint8_t irqsts1 = 0;
if ((dregs[MKW2XDM_IRQSTS1] & MKW2XDM_IRQSTS1_CCAIRQ) &&
@ -712,7 +724,8 @@ static void _isr_event_seq_ccca(netdev_t *netdev, uint8_t *dregs)
static void _isr(netdev_t *netdev)
{
uint8_t dregs[MKW2XDM_PHY_CTRL4 + 1];
kw2xrf_t *dev = (kw2xrf_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
kw2xrf_t *dev = container_of(netdev_ieee802154, kw2xrf_t, netdev);
if (!spinning_for_irq) {
num_irqs_handled = num_irqs_queued;
}