6
6
7
7
#define DT_DRV_COMPAT telink_tlx_zb
8
8
9
- #if CONFIG_SOC_RISCV_TELINK_TL721X || CONFIG_SOC_RISCV_TELINK_TL321X
10
9
#include "rf_common.h"
11
- #endif
12
10
#include "stimer.h"
13
11
#include "tl_rf_power.h"
12
+ #include "gpio.h"
13
+ #include "plic.h"
14
+ #include "clock.h"
14
15
15
16
#define LOG_MODULE_NAME ieee802154_tlx
16
17
#if defined(CONFIG_IEEE802154_DRIVER_LOG_LEVEL )
@@ -59,19 +60,27 @@ static struct tlx_enh_ack_table enh_ack_table;
59
60
/* mac keys data */
60
61
static struct tlx_mac_keys mac_keys ;
61
62
#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 */
63
67
/* TLX data structure */
64
- static struct tlx_data data = {
68
+ static struct tlx_data data = {
65
69
#ifdef CONFIG_OPENTHREAD_FTD
66
70
.src_match_table = & src_match_table ,
67
71
#endif /* CONFIG_OPENTHREAD_FTD */
68
72
#ifdef CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT
69
73
.enh_ack_table = & enh_ack_table ,
70
74
#endif /* CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT */
71
75
#if !defined (CONFIG_OPENTHREAD_THREAD_VERSION_1_1 )
72
- /* mac keys data */
76
+ /* mac keys data */
73
77
.mac_keys = & mac_keys ,
74
78
#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 */
75
84
};
76
85
77
86
#ifdef CONFIG_OPENTHREAD_FTD
@@ -627,14 +636,14 @@ static void ALWAYS_INLINE tlx_rf_rx_isr(const struct device *dev)
627
636
struct tlx_data * tlx = dev -> data ;
628
637
int status = - EINVAL ;
629
638
struct net_pkt * pkt = NULL ;
639
+ struct ieee802154_frame frame = {};
630
640
631
641
#if defined(CONFIG_NET_PKT_TIMESTAMP ) && defined(CONFIG_NET_PKT_TXTIME )
632
642
uint64_t rx_time = k_ticks_to_us_near64 (k_uptime_ticks ());
633
643
#if CONFIG_SOC_RISCV_TELINK_TL321X
634
644
uint32_t delta_time = (stimer_get_tick () - ZB_RADIO_TIMESTAMP_GET (tlx -> rx_buffer )) /
635
645
SYSTEM_TIMER_TICK_1US ;
636
- #endif
637
- #if CONFIG_SOC_RISCV_TELINK_TL721X
646
+ #elif CONFIG_SOC_RISCV_TELINK_TL721X
638
647
uint32_t delta_time = (rf_bb_timer_get_tick () - ZB_RADIO_TIMESTAMP_GET (tlx -> rx_buffer )) /
639
648
BB_TIMER_TICK_1US ;
640
649
#endif
@@ -669,7 +678,6 @@ static void ALWAYS_INLINE tlx_rf_rx_isr(const struct device *dev)
669
678
break ;
670
679
}
671
680
uint8_t * payload = (tlx -> rx_buffer + TLX_PAYLOAD_OFFSET );
672
- struct ieee802154_frame frame ;
673
681
674
682
if (IS_ENABLED (CONFIG_IEEE802154_RAW_MODE ) ||
675
683
IS_ENABLED (CONFIG_NET_L2_OPENTHREAD )) {
@@ -813,6 +821,7 @@ static ALWAYS_INLINE void tlx_rf_tx_isr(const struct device *dev)
813
821
{
814
822
struct tlx_data * tlx = dev -> data ;
815
823
824
+ plic_interrupt_disable (IRQ_SYSTIMER );
816
825
/* clear irq status */
817
826
rf_clr_irq_status (FLD_RF_IRQ_TX );
818
827
@@ -858,6 +867,7 @@ static int tlx_init(const struct device *dev)
858
867
tlx -> is_started = false;
859
868
tlx -> ack_handler_en = false;
860
869
tlx -> ack_sending = false;
870
+ tlx -> rf_mode_154 = false;
861
871
tlx -> current_channel = TLX_TX_CH_NOT_SET ;
862
872
tlx -> current_dbm = TLX_TX_PWR_NOT_SET ;
863
873
#ifdef CONFIG_OPENTHREAD_FTD
@@ -934,8 +944,6 @@ static int tlx_set_channel(const struct device *dev, uint16_t channel)
934
944
tlx -> current_channel = channel ;
935
945
if (tlx -> is_started ) {
936
946
rf_set_chn (TLX_LOGIC_CHANNEL_TO_PHYSICAL (channel ));
937
- rf_set_txmode ();
938
- rf_set_rxmode ();
939
947
}
940
948
}
941
949
@@ -987,6 +995,17 @@ static int tlx_set_txpower(const struct device *dev, int16_t dbm)
987
995
}
988
996
989
997
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
990
1009
991
1010
/* API implementation: start */
992
1011
static int tlx_start (const struct device * dev )
@@ -1007,6 +1026,11 @@ static int tlx_start(const struct device *dev)
1007
1026
ske_dig_en ();
1008
1027
#endif
1009
1028
#endif
1029
+ if (tlx -> rf_mode_154 == false) {
1030
+ rf_baseband_reset ();
1031
+ rf_reset_dma ();
1032
+ tlx -> rf_mode_154 = true;
1033
+ }
1010
1034
rf_mode_init ();
1011
1035
rf_set_zigbee_250K_mode ();
1012
1036
tlx_rf_zigbee_250K_mode = true;
@@ -1021,8 +1045,6 @@ static int tlx_start(const struct device *dev)
1021
1045
}
1022
1046
rf_set_irq_mask (FLD_RF_IRQ_RX | FLD_RF_IRQ_TX );
1023
1047
riscv_plic_irq_enable (DT_INST_IRQN (0 ));
1024
- rf_set_txmode ();
1025
- rf_set_rxmode ();
1026
1048
tlx -> is_started = true;
1027
1049
}
1028
1050
@@ -1044,11 +1066,11 @@ static int tlx_stop(const struct device *dev)
1044
1066
riscv_plic_irq_disable (DT_INST_IRQN (0 ));
1045
1067
rf_set_tx_rx_off ();
1046
1068
#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 */
1051
1070
rf_radio_reset ();
1071
+ #if CONFIG_SOC_RISCV_TELINK_TL321X || CONFIG_SOC_RISCV_TELINK_TL721X
1072
+ rf_reset_dma ();
1073
+ rf_baseband_reset ();
1052
1074
#endif
1053
1075
tlx_rf_zigbee_250K_mode = false;
1054
1076
#endif /* CONFIG_PM_DEVICE */
@@ -1276,8 +1298,19 @@ static int tlx_tx(const struct device *dev,
1276
1298
if (tlx -> event_handler ) {
1277
1299
tlx -> event_handler (dev , IEEE802154_EVENT_TX_STARTED , (void * )frag );
1278
1300
}
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 */
1281
1314
if (k_sem_take (& tlx -> tx_wait , K_MSEC (TLX_TX_WAIT_TIME_MS )) != 0 ) {
1282
1315
rf_set_rxmode ();
1283
1316
status = - EIO ;
@@ -1288,8 +1321,23 @@ static int tlx_tx(const struct device *dev,
1288
1321
IEEE802154_FRAME_FCF_ACK_REQ_ON ) {
1289
1322
tlx -> ack_sn = frag -> data [IEEE802154_FRAME_LENGTH_FCF ];
1290
1323
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
+ }
1293
1341
}
1294
1342
tlx -> ack_handler_en = false;
1295
1343
}
0 commit comments