Skip to content

Commit e8f404c

Browse files
authored
telink: tlx: apply tlx optimization to zephyr v3.7 (#491)
add config IEEE802154_TLX_OPTIMIZATION and modify radio reset functions based on de86a25 --------- Signed-off-by: Damien Ji <yinghao.ji@telink-semi.com>
1 parent ec917c3 commit e8f404c

File tree

3 files changed

+82
-21
lines changed

3 files changed

+82
-21
lines changed

drivers/ieee802154/Kconfig.tlx

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ config IEEE802154_TLX_DELAY_TRX_ACC
4848
Accuracy of the clock used for scheduling radio delayed operations (delayed transmission
4949
or delayed reception), in ppm.
5050

51+
config IEEE802154_TLX_OPTIMIZATION
52+
bool "Optimize 802.15.4 RF performance for TLX SoCs"
53+
default n
54+
help
55+
Improve RF performance in IEEE 802.15.4 communication on TLX SoCs.
56+
57+
5158
if IEEE802154_TLX_MAC_STATIC
5259

5360
config IEEE802154_TLX_MAC4

drivers/ieee802154/ieee802154_tlx.c

+68-20
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
#define DT_DRV_COMPAT telink_tlx_zb
88

9-
#if CONFIG_SOC_RISCV_TELINK_TL721X || CONFIG_SOC_RISCV_TELINK_TL321X
109
#include "rf_common.h"
11-
#endif
1210
#include "stimer.h"
1311
#include "tl_rf_power.h"
12+
#include "gpio.h"
13+
#include "plic.h"
14+
#include "clock.h"
1415

1516
#define LOG_MODULE_NAME ieee802154_tlx
1617
#if defined(CONFIG_IEEE802154_DRIVER_LOG_LEVEL)
@@ -59,19 +60,27 @@ static struct tlx_enh_ack_table enh_ack_table;
5960
/* mac keys data */
6061
static struct tlx_mac_keys mac_keys;
6162
#endif
62-
63+
#if CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION
64+
__attribute__((section(".bss"))) uint8_t rxpkt_buffer[TLX_TRX_LENGTH] = {0};
65+
__attribute__((section(".bss"))) uint8_t txpkt_buffer[TLX_TRX_LENGTH] = {0};
66+
#endif /* CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION */
6367
/* TLX data structure */
64-
static struct tlx_data data = {
68+
static struct tlx_data data = {
6569
#ifdef CONFIG_OPENTHREAD_FTD
6670
.src_match_table = &src_match_table,
6771
#endif /* CONFIG_OPENTHREAD_FTD */
6872
#ifdef CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT
6973
.enh_ack_table = &enh_ack_table,
7074
#endif /* CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT */
7175
#if !defined(CONFIG_OPENTHREAD_THREAD_VERSION_1_1)
72-
/* mac keys data */
76+
/* mac keys data */
7377
.mac_keys = &mac_keys,
7478
#endif
79+
80+
#if CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION
81+
.rx_buffer = rxpkt_buffer,
82+
.tx_buffer = txpkt_buffer,
83+
#endif /* CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION */
7584
};
7685

7786
#ifdef CONFIG_OPENTHREAD_FTD
@@ -627,14 +636,14 @@ static void ALWAYS_INLINE tlx_rf_rx_isr(const struct device *dev)
627636
struct tlx_data *tlx = dev->data;
628637
int status = -EINVAL;
629638
struct net_pkt *pkt = NULL;
639+
struct ieee802154_frame frame = {};
630640

631641
#if defined(CONFIG_NET_PKT_TIMESTAMP) && defined(CONFIG_NET_PKT_TXTIME)
632642
uint64_t rx_time = k_ticks_to_us_near64(k_uptime_ticks());
633643
#if CONFIG_SOC_RISCV_TELINK_TL321X
634644
uint32_t delta_time = (stimer_get_tick() - ZB_RADIO_TIMESTAMP_GET(tlx->rx_buffer)) /
635645
SYSTEM_TIMER_TICK_1US;
636-
#endif
637-
#if CONFIG_SOC_RISCV_TELINK_TL721X
646+
#elif CONFIG_SOC_RISCV_TELINK_TL721X
638647
uint32_t delta_time = (rf_bb_timer_get_tick() - ZB_RADIO_TIMESTAMP_GET(tlx->rx_buffer)) /
639648
BB_TIMER_TICK_1US;
640649
#endif
@@ -669,7 +678,6 @@ static void ALWAYS_INLINE tlx_rf_rx_isr(const struct device *dev)
669678
break;
670679
}
671680
uint8_t *payload = (tlx->rx_buffer + TLX_PAYLOAD_OFFSET);
672-
struct ieee802154_frame frame;
673681

674682
if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE) ||
675683
IS_ENABLED(CONFIG_NET_L2_OPENTHREAD)) {
@@ -813,6 +821,7 @@ static ALWAYS_INLINE void tlx_rf_tx_isr(const struct device *dev)
813821
{
814822
struct tlx_data *tlx = dev->data;
815823

824+
plic_interrupt_disable(IRQ_SYSTIMER);
816825
/* clear irq status */
817826
rf_clr_irq_status(FLD_RF_IRQ_TX);
818827

@@ -858,6 +867,7 @@ static int tlx_init(const struct device *dev)
858867
tlx->is_started = false;
859868
tlx->ack_handler_en = false;
860869
tlx->ack_sending = false;
870+
tlx->rf_mode_154 = false;
861871
tlx->current_channel = TLX_TX_CH_NOT_SET;
862872
tlx->current_dbm = TLX_TX_PWR_NOT_SET;
863873
#ifdef CONFIG_OPENTHREAD_FTD
@@ -934,8 +944,6 @@ static int tlx_set_channel(const struct device *dev, uint16_t channel)
934944
tlx->current_channel = channel;
935945
if (tlx->is_started) {
936946
rf_set_chn(TLX_LOGIC_CHANNEL_TO_PHYSICAL(channel));
937-
rf_set_txmode();
938-
rf_set_rxmode();
939947
}
940948
}
941949

@@ -987,6 +995,17 @@ static int tlx_set_txpower(const struct device *dev, int16_t dbm)
987995
}
988996

989997
volatile bool tlx_rf_zigbee_250K_mode;
998+
#if defined CONFIG_IEEE802154_TLX_OPTIMIZATION && CONFIG_IEEE802154_TLX_OPTIMIZATION
999+
extern bool isThreadCommissioned;
1000+
1001+
_attribute_ram_code_sec_ void stimer_rf_handler(const void *param)
1002+
{
1003+
(void)param;
1004+
if (stimer_get_irq_status(FLD_SYSTEM_IRQ)) {
1005+
stimer_clr_irq_status(FLD_SYSTEM_IRQ);
1006+
}
1007+
}
1008+
#endif
9901009

9911010
/* API implementation: start */
9921011
static int tlx_start(const struct device *dev)
@@ -1007,6 +1026,11 @@ static int tlx_start(const struct device *dev)
10071026
ske_dig_en();
10081027
#endif
10091028
#endif
1029+
if (tlx->rf_mode_154 == false) {
1030+
rf_baseband_reset();
1031+
rf_reset_dma();
1032+
tlx->rf_mode_154 = true;
1033+
}
10101034
rf_mode_init();
10111035
rf_set_zigbee_250K_mode();
10121036
tlx_rf_zigbee_250K_mode = true;
@@ -1021,8 +1045,6 @@ static int tlx_start(const struct device *dev)
10211045
}
10221046
rf_set_irq_mask(FLD_RF_IRQ_RX | FLD_RF_IRQ_TX);
10231047
riscv_plic_irq_enable(DT_INST_IRQN(0));
1024-
rf_set_txmode();
1025-
rf_set_rxmode();
10261048
tlx->is_started = true;
10271049
}
10281050

@@ -1044,11 +1066,11 @@ static int tlx_stop(const struct device *dev)
10441066
riscv_plic_irq_disable(DT_INST_IRQN(0));
10451067
rf_set_tx_rx_off();
10461068
#ifdef CONFIG_PM_DEVICE
1047-
#if CONFIG_SOC_RISCV_TELINK_TL321X
1048-
rf_baseband_reset();
1049-
rf_reset_dma();
1050-
#elif CONFIG_SOC_RISCV_TELINK_TL721X
1069+
/* Reset Radio */
10511070
rf_radio_reset();
1071+
#if CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL721X
1072+
rf_reset_dma();
1073+
rf_baseband_reset();
10521074
#endif
10531075
tlx_rf_zigbee_250K_mode = false;
10541076
#endif /* CONFIG_PM_DEVICE */
@@ -1276,8 +1298,19 @@ static int tlx_tx(const struct device *dev,
12761298
if (tlx->event_handler) {
12771299
tlx->event_handler(dev, IEEE802154_EVENT_TX_STARTED, (void *)frag);
12781300
}
1279-
1280-
/* wait for tx done */
1301+
#if defined CONFIG_IEEE802154_TLX_OPTIMIZATION && CONFIG_IEEE802154_TLX_OPTIMIZATION
1302+
if (isThreadCommissioned == true) {
1303+
irq_connect_dynamic(IRQ_SYSTIMER + CONFIG_2ND_LVL_ISR_TBL_OFFSET, 2,
1304+
stimer_rf_handler, 0, 0);
1305+
plic_interrupt_disable(IRQ_SYSTIMER);
1306+
stimer_set_irq_capture(stimer_get_tick() +
1307+
TLX_ACK_WAIT_TIME_MS * SYSTEM_TIMER_TICK_1MS);
1308+
stimer_clr_irq_status(FLD_SYSTEM_IRQ);
1309+
stimer_set_irq_mask(FLD_SYSTEM_IRQ_MASK);
1310+
plic_interrupt_enable(IRQ_SYSTIMER);
1311+
core_entry_wfi_mode();
1312+
}
1313+
#endif /* CONFIG_IEEE802154_TLX_OPTIMIZATION */
12811314
if (k_sem_take(&tlx->tx_wait, K_MSEC(TLX_TX_WAIT_TIME_MS)) != 0) {
12821315
rf_set_rxmode();
12831316
status = -EIO;
@@ -1288,8 +1321,23 @@ static int tlx_tx(const struct device *dev,
12881321
IEEE802154_FRAME_FCF_ACK_REQ_ON) {
12891322
tlx->ack_sn = frag->data[IEEE802154_FRAME_LENGTH_FCF];
12901323
tlx->ack_handler_en = true;
1291-
if (k_sem_take(&tlx->ack_wait, K_MSEC(TLX_ACK_WAIT_TIME_MS)) != 0) {
1292-
status = -ENOMSG;
1324+
#if defined CONFIG_IEEE802154_TLX_OPTIMIZATION && CONFIG_IEEE802154_TLX_OPTIMIZATION
1325+
if (isThreadCommissioned == true) {
1326+
plic_interrupt_disable(IRQ_SYSTIMER);
1327+
stimer_clr_irq_status(FLD_SYSTEM_IRQ);
1328+
stimer_set_irq_capture(stimer_get_tick() +
1329+
TLX_ACK_WAIT_TIME_MS * SYSTEM_TIMER_TICK_1MS);
1330+
plic_interrupt_enable(IRQ_SYSTIMER);
1331+
core_entry_wfi_mode();
1332+
if (k_sem_take(&tlx->ack_wait, K_MSEC(0)) != 0) {
1333+
status = -ENOMSG;
1334+
}
1335+
} else
1336+
#endif /* CONFIG_IEEE802154_TLX_OPTIMIZATION */
1337+
{
1338+
if (k_sem_take(&tlx->ack_wait, K_MSEC(TLX_ACK_WAIT_TIME_MS)) != 0) {
1339+
status = -ENOMSG;
1340+
}
12931341
}
12941342
tlx->ack_handler_en = false;
12951343
}

drivers/ieee802154/ieee802154_tlx.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* Timeouts */
1111
#define TLX_TX_WAIT_TIME_MS (10)
12-
#define TLX_ACK_WAIT_TIME_MS (10)
12+
#define TLX_ACK_WAIT_TIME_MS (5)
1313

1414
/* Received data parsing */
1515
#ifndef IEEE802154_FRAME_LENGTH_PANID
@@ -93,8 +93,13 @@ struct tlx_mac_keys {
9393
/* data structure */
9494
struct tlx_data {
9595
uint8_t mac_addr[IEEE802154_FRAME_LENGTH_ADDR_EXT];
96+
#if CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION
97+
uint8_t *rx_buffer;
98+
uint8_t *tx_buffer;
99+
#else
96100
uint8_t rx_buffer[TLX_TRX_LENGTH] __aligned(4);
97101
uint8_t tx_buffer[TLX_TRX_LENGTH] __aligned(4);
102+
#endif /* CONFIG_SOC_SERIES_RISCV_TELINK_TLX_RETENTION */
98103
struct net_if *iface;
99104
struct k_sem tx_wait;
100105
struct k_sem ack_wait;
@@ -103,6 +108,7 @@ struct tlx_data {
103108
uint8_t filter_ieee_addr[IEEE802154_FRAME_LENGTH_ADDR_EXT];
104109
volatile bool is_started;
105110
volatile bool ack_handler_en;
111+
volatile bool rf_mode_154;
106112
volatile uint8_t ack_sn;
107113
uint16_t current_channel;
108114
int16_t current_dbm;

0 commit comments

Comments
 (0)