From 9313172f840b7ccbc57605bcafbf4b678f295849 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Mon, 7 Nov 2016 10:44:17 +0100 Subject: [PATCH] drivers: ieee802154: Let's timeout on cc2520 tx Looks like getting an SFD interruption is not 100% reliable, so let's just use a semaphore with a timeout on it instead of using device_sync* routines. Change-Id: I4e4115c7b939c95d7e75fbb33664d411e0a6e8cc Signed-off-by: Tomasz Bursztyka --- drivers/ieee802154/ieee802154_cc2520.c | 7 +++---- drivers/ieee802154/ieee802154_cc2520.h | 2 +- drivers/ieee802154/ieee802154_cc2520_legacy.c | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/ieee802154/ieee802154_cc2520.c b/drivers/ieee802154/ieee802154_cc2520.c index 07b97e13866..b8fe41c1d24 100644 --- a/drivers/ieee802154/ieee802154_cc2520.c +++ b/drivers/ieee802154/ieee802154_cc2520.c @@ -338,7 +338,7 @@ static inline void sfd_int_handler(struct device *port, if (atomic_get(&cc2520->tx) == 1) { atomic_set(&cc2520->tx, 0); - device_sync_call_complete(&cc2520->tx_sync); + nano_isr_sem_give(&cc2520->tx_sync); } } @@ -831,6 +831,7 @@ static int cc2520_tx(struct device *dev, struct net_buf *buf) /* 1 retry is allowed here */ do { atomic_set(&cc2520->tx, 1); + nano_sem_init(&cc2520->tx_sync); if (!instruct_stxoncca(&cc2520->spi)) { SYS_LOG_ERR(" Cannot start transmission\n"); @@ -838,8 +839,7 @@ static int cc2520_tx(struct device *dev, struct net_buf *buf) } /* _cc2520_print_exceptions(cc2520); */ - - device_sync_call_wait(&cc2520->tx_sync); + nano_sem_take(&cc2520->tx_sync, MSEC(10)); retry--; status = verify_tx_done(cc2520); @@ -994,7 +994,6 @@ static int cc2520_init(struct device *dev) { struct cc2520_context *cc2520 = dev->driver_data; - device_sync_call_init(&cc2520->tx_sync); atomic_set(&cc2520->tx, 0); nano_sem_init(&cc2520->rx_lock); diff --git a/drivers/ieee802154/ieee802154_cc2520.h b/drivers/ieee802154/ieee802154_cc2520.h index 908c2e8cbba..38554d34753 100644 --- a/drivers/ieee802154/ieee802154_cc2520.h +++ b/drivers/ieee802154/ieee802154_cc2520.h @@ -49,7 +49,7 @@ struct cc2520_context { struct cc2520_spi spi; uint8_t mac_addr[8]; /************TX************/ - device_sync_call_t tx_sync; + struct nano_sem tx_sync; atomic_t tx; /************RX************/ char __stack cc2520_rx_stack[CONFIG_CC2520_RX_STACK_SIZE]; diff --git a/drivers/ieee802154/ieee802154_cc2520_legacy.c b/drivers/ieee802154/ieee802154_cc2520_legacy.c index 4fae424291e..34c5db7938b 100644 --- a/drivers/ieee802154/ieee802154_cc2520_legacy.c +++ b/drivers/ieee802154/ieee802154_cc2520_legacy.c @@ -346,7 +346,7 @@ static inline void sfd_int_handler(struct device *port, if (atomic_get(&cc2520->tx) == 1) { atomic_set(&cc2520->tx, 0); - device_sync_call_complete(&cc2520->tx_sync); + nano_isr_sem_give(&cc2520->tx_sync); } } @@ -794,6 +794,7 @@ static inline int cc2520_tx(struct device *dev, struct net_buf *buf) /* 1 retry is allowed here */ do { atomic_set(&cc2520->tx, 1); + nano_sem_init(&cc2520->tx_sync); if (!instruct_stxoncca(&cc2520->spi)) { SYS_LOG_DBG("%s: Cannot start transmission\n", __func__); @@ -801,8 +802,7 @@ static inline int cc2520_tx(struct device *dev, struct net_buf *buf) } /* _cc2520_print_exceptions(cc2520); */ - - device_sync_call_wait(&cc2520->tx_sync); + nano_sem_take(&cc2520->tx_sync, MSEC(10)); retry--; status = verify_tx_done(cc2520); @@ -1135,7 +1135,6 @@ int cc2520_init(struct device *dev) dev->driver_api = NULL; - device_sync_call_init(&cc2520->tx_sync); atomic_set(&cc2520->tx, 0); nano_sem_init(&cc2520->rx_lock);