2626#include "dect_phy_mac_pdu.h"
2727#include "dect_phy_mac_nbr.h"
2828#include "dect_phy_mac_nbr_bg_scan.h"
29+ #include "dect_phy_mac_cluster_beacon.h"
2930#include "dect_phy_mac.h"
3031#include "dect_phy_mac_client.h"
3132
@@ -43,7 +44,7 @@ struct dect_phy_mac_client_association_data {
4344 uint32_t target_long_rd_id ;
4445
4546 uint32_t bg_scan_phy_handle ;
46- bool bg_scan_on_going ;
47+ bool bg_scan_ongoing ;
4748
4849 struct dect_phy_mac_nbr_info_list_item * target_nbr ;
4950 struct k_work_delayable association_resp_wait_work ;
@@ -176,6 +177,15 @@ static uint64_t dect_phy_mac_client_next_rach_tx_time_get(
176177 if (beacon_interval_ms < 0 ) {
177178 return 0 ;
178179 }
180+ bool our_beacon_is_running = dect_phy_mac_cluster_beacon_is_running ();
181+
182+ if (our_beacon_is_running ) {
183+ /* If our beacon is running, send beyond the window to get the priority over others.
184+ * This adds more delay to TX but is more reliable to avoid scheduling collisions.
185+ */
186+ first_possible_tx += MS_TO_MODEM_TICKS (DECT_PHY_API_SCHEDULER_OP_TIME_WINDOW_MS );
187+ }
188+
179189 beacon_interval_mdm_ticks = MS_TO_MODEM_TICKS (beacon_interval_ms );
180190
181191 /* We are sending after next beacon and ... */
@@ -206,6 +216,21 @@ static uint64_t dect_phy_mac_client_next_rach_tx_time_get(
206216 if (client_data .last_tx_time_mdm_ticks > first_possible_tx ) {
207217 first_possible_tx = client_data .last_tx_time_mdm_ticks + 1 ;
208218 }
219+
220+ /* ... and try to avoid collisions with our own beacon TX: */
221+ uint64_t next_our_beacon_frame_time = 0 ;
222+
223+ if (dect_phy_mac_cluster_beacon_is_running ()) {
224+ next_our_beacon_frame_time =
225+ dect_phy_mac_cluster_beacon_last_tx_frame_time_get ();
226+ uint32_t our_beacon_interval_mdm_ticks =
227+ MS_TO_MODEM_TICKS (DECT_PHY_MAC_CLUSTER_BEACON_INTERVAL_MS );
228+
229+ while (next_our_beacon_frame_time < first_possible_tx ) {
230+ next_our_beacon_frame_time += our_beacon_interval_mdm_ticks ;
231+ }
232+ }
233+
209234 /* ...and in 1st RA (if not associated). Additionally, to get RX really on target:
210235 * delay TX by 2 subslots.
211236 */
@@ -220,6 +245,14 @@ static uint64_t dect_phy_mac_client_next_rach_tx_time_get(
220245 while (ra_start_mdm_ticks < first_possible_tx &&
221246 ra_start_mdm_ticks < last_valid_rach_rx_frame_time ) {
222247 ra_start_mdm_ticks += ra_interval_mdm_ticks ;
248+ if (next_our_beacon_frame_time && dect_common_utils_mdm_ticks_is_in_range (
249+ ra_start_mdm_ticks ,
250+ next_our_beacon_frame_time ,
251+ next_our_beacon_frame_time +
252+ (DECT_RADIO_FRAME_DURATION_IN_MODEM_TICKS /
253+ 2 ))) {
254+ ra_start_mdm_ticks += ra_interval_mdm_ticks ;
255+ }
223256 }
224257
225258 return ra_start_mdm_ticks ;
@@ -367,7 +400,7 @@ static int dect_phy_mac_client_rach_tx(struct dect_phy_mac_nbr_info_list_item *t
367400 memcpy (& sched_list_item -> sched_config .tx .phy_header .type_2 , & phy_header .type_2 ,
368401 sizeof (phy_header .type_2 ));
369402
370- sched_list_item -> priority = DECT_PRIORITY1_TX ;
403+ sched_list_item -> priority = DECT_PRIORITY0_FORCE_TX ;
371404 sched_list_item -> phy_op_handle = DECT_PHY_MAC_CLIENT_RA_TX_HANDLE ;
372405
373406 if (params -> interval_secs ) {
@@ -578,7 +611,7 @@ static int dect_phy_mac_client_associate_msg_send(
578611 memcpy (& sched_list_item -> sched_config .tx .phy_header .type_2 , & phy_header .type_2 ,
579612 sizeof (phy_header .type_2 ));
580613
581- sched_list_item -> priority = DECT_PRIORITY1_TX ;
614+ sched_list_item -> priority = DECT_PRIORITY0_FORCE_TX ;
582615 sched_list_item -> phy_op_handle = DECT_PHY_MAC_CLIENT_ASSOCIATION_TX_HANDLE ;
583616
584617 /* Add tx operation to scheduler list */
@@ -671,7 +704,7 @@ static void dect_phy_mac_client_association_data_init(void)
671704 client_data .associations [i ].bg_scan_phy_handle =
672705 DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN + i ;
673706 client_data .associations [i ].target_nbr = NULL ;
674- client_data .associations [i ].bg_scan_on_going = false;
707+ client_data .associations [i ].bg_scan_ongoing = false;
675708 }
676709}
677710
@@ -686,7 +719,7 @@ static struct dect_phy_mac_client_association_data *dect_phy_mac_client_associat
686719 return NULL ;
687720}
688721
689- static void dect_phy_mac_client_associate_resp_wait_worker (struct k_work * work_item )
722+ static void dect_phy_mac_client_associate_resp_timeout_worker (struct k_work * work_item )
690723{
691724 struct k_work_delayable * delayable_work = k_work_delayable_from_work (work_item );
692725 struct dect_phy_mac_client_association_data * association_data =
@@ -701,7 +734,7 @@ static void dect_phy_mac_client_associate_resp_wait_worker(struct k_work *work_i
701734 association_data -> target_nbr = NULL ;
702735 association_data -> state = DECT_PHY_MAC_CLIENT_ASSOCIATION_STATE_DISASSOCIATED ;
703736 dect_phy_mac_nbr_bg_scan_stop (association_data -> bg_scan_phy_handle );
704- association_data -> bg_scan_on_going = false;
737+ association_data -> bg_scan_ongoing = false;
705738
706739 desh_warn ("Association response timeout: not associated with device long RD ID %d" ,
707740 association_data -> target_long_rd_id );
@@ -737,7 +770,7 @@ int dect_phy_mac_client_associate(struct dect_phy_mac_nbr_info_list_item *target
737770
738771 k_work_init_delayable (
739772 & association_data -> association_resp_wait_work ,
740- dect_phy_mac_client_associate_resp_wait_worker );
773+ dect_phy_mac_client_associate_resp_timeout_worker );
741774
742775 /* Start worker for waiting association response */
743776 k_work_schedule_for_queue (& dect_phy_ctrl_work_q ,
@@ -769,7 +802,7 @@ void dect_phy_mac_client_nbr_scan_completed_cb(
769802 (__func__ ), info -> target_long_rd_id ,
770803 DECT_PHY_MAC_NBR_BG_SCAN_MAX_UNREACHABLE_TIME_MS );
771804 }
772- association_data -> bg_scan_on_going = false;
805+ association_data -> bg_scan_ongoing = false;
773806}
774807
775808void dect_phy_mac_client_associate_resp_handle (
@@ -797,14 +830,14 @@ void dect_phy_mac_client_associate_resp_handle(
797830 bg_scan_params .target_long_rd_id = association_data -> target_long_rd_id ;
798831 bg_scan_params .phy_op_handle = association_data -> bg_scan_phy_handle ;
799832
800- if (association_data -> bg_scan_on_going ) {
833+ if (association_data -> bg_scan_ongoing ) {
801834 dect_phy_mac_nbr_bg_scan_stop (association_data -> bg_scan_phy_handle );
802835 }
803836
804837 if (dect_phy_mac_nbr_bg_scan_start (& bg_scan_params )) {
805838 desh_warn ("(%s): dect_phy_mac_nbr_bg_scan_start failed" , (__func__ ));
806839 } else {
807- association_data -> bg_scan_on_going = true;
840+ association_data -> bg_scan_ongoing = true;
808841 }
809842}
810843
@@ -1020,7 +1053,7 @@ int dect_phy_mac_client_dissociate(struct dect_phy_mac_nbr_info_list_item *targe
10201053 k_work_cancel_delayable (& association_data -> association_resp_wait_work );
10211054
10221055 dect_phy_mac_nbr_bg_scan_stop (association_data -> bg_scan_phy_handle );
1023- association_data -> bg_scan_on_going = false;
1056+ association_data -> bg_scan_ongoing = false;
10241057
10251058 association_data -> state = DECT_PHY_MAC_CLIENT_ASSOCIATION_STATE_DISASSOCIATED ;
10261059 association_data -> target_nbr = NULL ;
0 commit comments