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

at86rf2xx: avoid explicit cast to netdev

This commit is contained in:
Jose Alamos 2021-06-21 16:32:16 +02:00
parent 650be4fdaf
commit 72d71f1ac4
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
4 changed files with 76 additions and 35 deletions

View File

@ -283,7 +283,7 @@ size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
void at86rf2xx_tx_exec(at86rf2xx_t *dev)
{
netdev_t *netdev = (netdev_t *)dev;
netdev_t *netdev = &dev->netdev.netdev;
#if AT86RF2XX_HAVE_RETRIES
dev->tx_retries = -1;

View File

@ -74,7 +74,9 @@ static void _irq_handler(void *arg)
static int _init(netdev_t *netdev)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
#if defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
at86rfmega_dev = netdev;
@ -114,7 +116,9 @@ static int _init(netdev_t *netdev)
static int _send(netdev_t *netdev, const iolist_t *iolist)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
size_t len = 0;
at86rf2xx_tx_prepare(dev);
@ -143,7 +147,9 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
uint8_t phr;
size_t pkt_len;
@ -305,7 +311,9 @@ netopt_state_t _get_state(at86rf2xx_t *dev)
static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
if (netdev == NULL) {
return -ENODEV;
@ -378,8 +386,9 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
int res;
if (((res = netdev_ieee802154_get((netdev_ieee802154_t *)netdev, opt, val,
max_len)) >= 0) || (res != -ENOTSUP)) {
if (((res = netdev_ieee802154_get(container_of(netdev, netdev_ieee802154_t, netdev),
opt, val, max_len)) >= 0)
|| (res != -ENOTSUP)) {
return res;
}
@ -470,7 +479,9 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
if (dev == NULL) {
return -ENODEV;
}
@ -640,7 +651,8 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
}
if (res == -ENOTSUP) {
res = netdev_ieee802154_set((netdev_ieee802154_t *)netdev, opt, val, len);
res = netdev_ieee802154_set(container_of(netdev, netdev_ieee802154_t, netdev),
opt, val, len);
}
return res;
@ -697,7 +709,9 @@ static void _isr_send_complete(at86rf2xx_t *dev, uint8_t trac_status)
static inline void _isr_recv_complete(netdev_t *netdev)
{
at86rf2xx_t *dev = (at86rf2xx_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
if (!netdev->event_callback) {
return;
}
@ -719,7 +733,9 @@ static inline void _isr_recv_complete(netdev_t *netdev)
static void _isr(netdev_t *netdev)
{
at86rf2xx_t *dev = (at86rf2xx_t *) netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
uint8_t irq_mask;
uint8_t state;
uint8_t trac_status;
@ -799,7 +815,9 @@ ISR(TRX24_TX_START_vect){
/* __enter_isr(); is not necessary as there is nothing which causes a
* thread_yield and the interrupt can not be interrupted by an other ISR */
at86rf2xx_t *dev = (at86rf2xx_t *) at86rfmega_dev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->tx_retries++;
}
@ -817,7 +835,10 @@ ISR(TRX24_PLL_LOCK_vect, ISR_BLOCK)
avr8_enter_isr();
DEBUG("TRX24_PLL_LOCK\n");
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__PLL_LOCK;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__PLL_LOCK;
avr8_exit_isr();
}
@ -834,7 +855,10 @@ ISR(TRX24_PLL_UNLOCK_vect, ISR_BLOCK)
avr8_enter_isr();
DEBUG("TRX24_PLL_UNLOCK\n");
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__PLL_UNLOCK;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__PLL_UNLOCK;
avr8_exit_isr();
}
@ -854,7 +878,10 @@ ISR(TRX24_RX_START_vect, ISR_BLOCK)
uint8_t status = *AT86RF2XX_REG__TRX_STATE & AT86RF2XX_TRX_STATUS_MASK__TRX_STATUS;
DEBUG("TRX24_RX_START 0x%x\n", status);
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__RX_START;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__RX_START;
/* Call upper layer to process valid PHR */
netdev_trigger_event_isr(at86rfmega_dev);
@ -876,7 +903,10 @@ ISR(TRX24_RX_END_vect, ISR_BLOCK)
uint8_t status = *AT86RF2XX_REG__TRX_STATE & AT86RF2XX_TRX_STATUS_MASK__TRX_STATUS;
DEBUG("TRX24_RX_END 0x%x\n", status);
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__RX_END;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__RX_END;
/* Call upper layer to process received data */
netdev_trigger_event_isr(at86rfmega_dev);
@ -895,7 +925,10 @@ ISR(TRX24_CCA_ED_DONE_vect, ISR_BLOCK)
avr8_enter_isr();
DEBUG("TRX24_CCA_ED_DONE\n");
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__CCA_ED_DONE;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__CCA_ED_DONE;
avr8_exit_isr();
}
@ -913,7 +946,10 @@ ISR(TRX24_XAH_AMI_vect, ISR_BLOCK)
avr8_enter_isr();
DEBUG("TRX24_XAH_AMI\n");
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__AMI;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__AMI;
avr8_exit_isr();
}
@ -929,7 +965,9 @@ ISR(TRX24_TX_END_vect, ISR_BLOCK)
{
avr8_enter_isr();
at86rf2xx_t *dev = (at86rf2xx_t *) at86rfmega_dev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
uint8_t status = *AT86RF2XX_REG__TRX_STATE & AT86RF2XX_TRX_STATUS_MASK__TRX_STATUS;
DEBUG("TRX24_TX_END 0x%x\n", status);
@ -959,7 +997,10 @@ ISR(TRX24_AWAKE_vect, ISR_BLOCK)
DEBUG("TRX24_AWAKE\n");
((at86rf2xx_t *)at86rfmega_dev)->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__AWAKE;
netdev_ieee802154_t *netdev_ieee802154 = container_of(at86rfmega_dev,
netdev_ieee802154_t, netdev);
at86rf2xx_t *dev = container_of(netdev_ieee802154, at86rf2xx_t, netdev);
dev->irq_status |= AT86RF2XX_IRQ_STATUS_MASK__AWAKE;
/* Call upper layer to process transceiver wakeup finished */
netdev_trigger_event_isr(at86rfmega_dev);

View File

@ -35,7 +35,7 @@ static int send(int iface, le_uint16_t dst_pan, uint8_t *dst_addr,
int ifconfig_list(int idx)
{
int res;
netdev_ieee802154_t *dev = (netdev_ieee802154_t *)(&devs[idx]);
netdev_ieee802154_t *dev = &devs[idx].netdev;
int (*get)(netdev_t *, netopt_t, void *, size_t) = dev->netdev.driver->get;
netopt_enable_t enable_val;
@ -47,21 +47,21 @@ int ifconfig_list(int idx)
print_addr(dev->long_addr, IEEE802154_LONG_ADDRESS_LEN);
printf(", PAN: 0x%04x", dev->pan);
res = get((netdev_t *)dev, NETOPT_ADDR_LEN, &u16_val, sizeof(u16_val));
res = get(&dev->netdev, NETOPT_ADDR_LEN, &u16_val, sizeof(u16_val));
if (res < 0) {
puts("(err)");
return 1;
}
printf("\n Address length: %u", (unsigned)u16_val);
res = get((netdev_t *)dev, NETOPT_SRC_LEN, &u16_val, sizeof(u16_val));
res = get(&dev->netdev, NETOPT_SRC_LEN, &u16_val, sizeof(u16_val));
if (res < 0) {
puts("(err)");
return 1;
}
printf(", Source address length: %u", (unsigned)u16_val);
res = get((netdev_t *)dev, NETOPT_MAX_PDU_SIZE, &u16_val,
res = get(&dev->netdev, NETOPT_MAX_PDU_SIZE, &u16_val,
sizeof(u16_val));
if (res < 0) {
puts("(err)");
@ -70,20 +70,20 @@ int ifconfig_list(int idx)
printf(", Max.Payload: %u", (unsigned)u16_val);
printf("\n Channel: %u", dev->chan);
res = get((netdev_t *)dev, NETOPT_CHANNEL_PAGE, &u16_val, sizeof(u16_val));
res = get(&dev->netdev, NETOPT_CHANNEL_PAGE, &u16_val, sizeof(u16_val));
if (res < 0) {
puts("(err)");
return 1;
}
printf(", Ch.page: %u", (unsigned)u16_val);
res = get((netdev_t *)dev, NETOPT_TX_POWER, &u16_val, sizeof(u16_val));
res = get(&dev->netdev, NETOPT_TX_POWER, &u16_val, sizeof(u16_val));
if (res < 0) {
puts("(err)");
return 1;
}
printf(", TXPower: %d dBm", (int)u16_val);
res = get((netdev_t *)dev, NETOPT_IS_WIRED, &u16_val, sizeof(u16_val));
res = get(&dev->netdev, NETOPT_IS_WIRED, &u16_val, sizeof(u16_val));
if (res < 0) {
puts(", wireless");
}
@ -92,27 +92,27 @@ int ifconfig_list(int idx)
}
printf(" ");
res = get((netdev_t *)dev, NETOPT_PRELOADING, &enable_val,
res = get(&dev->netdev, NETOPT_PRELOADING, &enable_val,
sizeof(netopt_enable_t));
if ((res > 0) && (enable_val == NETOPT_ENABLE)) {
printf(" PRELOAD");
}
res = get((netdev_t *)dev, NETOPT_AUTOACK, &enable_val,
res = get(&dev->netdev, NETOPT_AUTOACK, &enable_val,
sizeof(netopt_enable_t));
if ((res > 0) && (enable_val == NETOPT_ENABLE)) {
printf(" AUTOACK");
}
res = get((netdev_t *)dev, NETOPT_RAWMODE, &enable_val,
res = get(&dev->netdev, NETOPT_RAWMODE, &enable_val,
sizeof(netopt_enable_t));
if ((res > 0) && (enable_val == NETOPT_ENABLE)) {
printf(" RAW");
}
res = get((netdev_t *)dev, NETOPT_AUTOCCA, &enable_val,
res = get(&dev->netdev, NETOPT_AUTOCCA, &enable_val,
sizeof(netopt_enable_t));
if ((res > 0) && (enable_val == NETOPT_ENABLE)) {
printf(" AUTOCCA");
}
res = get((netdev_t *)dev, NETOPT_CSMA, &enable_val,
res = get(&dev->netdev, NETOPT_CSMA, &enable_val,
sizeof(netopt_enable_t));
if ((res > 0) && (enable_val == NETOPT_ENABLE)) {
printf(" CSMA");
@ -258,7 +258,7 @@ static int send(int iface, le_uint16_t dst_pan, uint8_t *dst, size_t dst_len,
.iol_len = strlen(data)
};
dev = (netdev_ieee802154_t *)&devs[iface];
dev = &devs[iface].netdev;
flags = (uint8_t)(dev->flags & NETDEV_IEEE802154_SEND_MASK);
flags |= IEEE802154_FCF_TYPE_DATA;
src_pan = byteorder_btols(byteorder_htons(dev->pan));
@ -288,7 +288,7 @@ static int send(int iface, le_uint16_t dst_pan, uint8_t *dst, size_t dst_len,
.iol_len = (size_t)res
};
res = dev->netdev.driver->send((netdev_t *)dev, &iol_hdr);
res = dev->netdev.driver->send(&dev->netdev, &iol_hdr);
if (res < 0) {
puts("txtsnd: Error on sending");
return 1;

View File

@ -93,7 +93,7 @@ int main(void)
for (unsigned i = 0; i < AT86RF2XX_NUM; i++) {
netopt_enable_t en = NETOPT_ENABLE;
const at86rf2xx_params_t *p = &at86rf2xx_params[i];
netdev_t *dev = (netdev_t *)(&devs[i]);
netdev_t *dev = &devs[i].netdev.netdev;
printf("Initializing AT86RF2xx radio at SPI_%d\n", p->spi);
at86rf2xx_setup(&devs[i], p, i);