From 7898908c9d6f34053995e39a2c210a8b3090fd78 Mon Sep 17 00:00:00 2001 From: Zhuang Hang Date: Tue, 31 Dec 2024 10:57:43 +0800 Subject: [PATCH] feat(802.15.4): add api for set/get ack timeout --- .../hal/include/hal/ieee802154_common_ll.h | 10 ++++++++++ components/ieee802154/esp_ieee802154.c | 16 ++++++++++++++++ components/ieee802154/include/esp_ieee802154.h | 11 +++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/components/hal/include/hal/ieee802154_common_ll.h b/components/hal/include/hal/ieee802154_common_ll.h index 865b53cf5c..1fe732f2c4 100644 --- a/components/hal/include/hal/ieee802154_common_ll.h +++ b/components/hal/include/hal/ieee802154_common_ll.h @@ -277,6 +277,16 @@ static inline void ieee802154_ll_set_power(uint8_t power) IEEE802154.txpower.power = power; } +static inline void ieee802154_ll_set_ack_timeout(uint32_t timeout) +{ + IEEE802154.ack_timeout.timeout = timeout; +} + +static inline uint32_t ieee802154_ll_get_ack_timeout(void) +{ + return IEEE802154.ack_timeout.timeout; +} + static inline void ieee802154_ll_set_multipan_panid(ieee802154_ll_multipan_index_t index, uint16_t panid) { IEEE802154.conf.multipan_mask |= BIT(index); diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 76cdcfb6f7..7cbee090bb 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -184,6 +184,22 @@ esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask) #else +esp_err_t esp_ieee802154_set_ack_timeout(uint32_t timeout) +{ + // Divide by 16 and round it up. + uint32_t target_reg_value = (timeout + 15) / 16; + if((timeout % 16) != 0) { + ESP_LOGW(IEEE802154_TAG, "Ack timeout should be a multiple of 16, input %"PRIu32", will be replaced by %"PRIu32"", timeout, (target_reg_value * 16)); + } + ieee802154_ll_set_ack_timeout(target_reg_value); + return ESP_OK; +} + +uint32_t esp_ieee802154_get_ack_timeout(void) +{ + return ieee802154_ll_get_ack_timeout() * 16; +} + uint16_t esp_ieee802154_get_panid(void) { return ieee802154_ll_get_multipan_panid(ESP_IEEE802154_MULTIPAN_0); diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index 5ad7998d79..21529f00e9 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -150,8 +150,8 @@ esp_err_t esp_ieee802154_transmit(const uint8_t *frame, bool cca); /** * @brief Set the time to wait for the ack frame. * - * @param[in] timeout The time to wait for the ack frame, in symbol unit (16 us). - * Default: 0x006C, Range: 0x0000 - 0xFFFF. + * @param[in] timeout The time to wait for the ack frame, in us. + * It Should be a multiple of 16. The default value is 1728 us (108 * 16). * * @return * - ESP_OK on success. @@ -159,6 +159,13 @@ esp_err_t esp_ieee802154_transmit(const uint8_t *frame, bool cca); */ esp_err_t esp_ieee802154_set_ack_timeout(uint32_t timeout); +/** + * @brief Get the time to wait for the ack frame. + * + * @return The time to wait for the ack frame, in us. + */ +uint32_t esp_ieee802154_get_ack_timeout(void); + /** * @brief Get the device PAN ID. *