Skip to content

Commit 8fa54b4

Browse files
jhirsirlubos
authored andcommitted
samples: dect_phy: dect_shell: mac: FT to FT bidir data transfer
Improved bidir FT/Beacon device to FT/Beacon device data sending when using associate/rach_tx commands. Jira: MOSH-632 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent e8130ab commit 8fa54b4

13 files changed

+202
-44
lines changed

samples/dect/dect_phy/dect_shell/README.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,92 @@ Example: starting of cluster beacon and sending RA data to it
932932
Stopping beacon.
933933
Beacon TX stopped, cause: User Initiated.
934934
935+
Example: two devices sending data to each other
936+
-----------------------------------------------
937+
938+
* FT/Beacon device 1 - Start periodic cluster beacon TX on default band 1 and on the first free channel:
939+
940+
.. code-block:: console
941+
942+
desh:~$ dect sett --reset
943+
desh:~$ dect sett -t 1
944+
desh:~$ dect mac beacon_start
945+
...
946+
Channel 1671 was chosen for the beacon.
947+
Beacon TX started.
948+
949+
* FT/Beacon device 2 - Scan the beacon from device 1:
950+
951+
.. code-block:: console
952+
953+
desh:~$ dect sett --reset
954+
desh:~$ dect sett -t 2
955+
desh:~$ dect mac beacon_scan -c 1671
956+
957+
* FT/Beacon device 2 - Start periodic cluster beacon TX on default band 1 and on the first free channel:
958+
959+
.. code-block:: console
960+
961+
desh:~$ dect mac beacon_start
962+
...
963+
Channel 1675 was chosen for the beacon.
964+
Beacon TX started.
965+
966+
* FT/Beacon device 1 - Scan the beacon from device 2 by using special force:
967+
968+
.. code-block:: console
969+
970+
desh:~$ dect mac beacon_scan -c 1675 -f
971+
972+
* FT/Beacon device 1 - Send association request to device 2:
973+
974+
.. code-block:: console
975+
976+
desh:~$ dect mac associate -t 2
977+
978+
979+
* FT/Beacon device 2 - Send association request to device 1:
980+
981+
.. code-block:: console
982+
983+
desh:~$ dect mac associate -t 1
984+
985+
* FT/Beacon device 1 - Send JSON-formatted periodic RA data in 10-second intervals with the current modem temperature to the device 2:
986+
987+
.. code-block:: console
988+
989+
desh:~$ dect mac rach_tx -t 2 -d "Data from device 1" -i 10 -j
990+
991+
* FT/Beacon device 2 - Send JSON-formatted periodic RA data in 10-second intervals with the current modem temperature to the device 1:
992+
993+
.. code-block:: console
994+
995+
desh:~$ dect mac rach_tx -t 1 -d "Data from device 2" -i 10 -j
996+
997+
* FT/Beacon devices 1 & 2 - Stop periodic RA data sending:
998+
999+
.. code-block:: console
1000+
1001+
desh:~$ dect mac rach_tx stop
1002+
1003+
* FT/Beacon device 1 - Send association release to the device 2:
1004+
1005+
.. code-block:: console
1006+
1007+
desh:~$ dect mac dissociate -t 2
1008+
1009+
* FT/Beacon device 2 - Send association release to the device 1:
1010+
1011+
.. code-block:: console
1012+
1013+
desh:~$ dect mac dissociate -t 1
1014+
1015+
* FT/Beacon devices 1 & 2 - Stop the beacon:
1016+
1017+
.. code-block:: console
1018+
1019+
desh:~$ dect mac beacon_stop
1020+
9351021
Running commands at bootup
9361022
==========================
9371023

samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,10 @@ bool dect_common_utils_32bit_network_id_validate(uint32_t network_id)
482482

483483
return ((0 != lsb_bits) && (0 != msb_bits));
484484
}
485+
486+
/**************************************************************************************************/
487+
488+
bool dect_common_utils_mdm_ticks_is_in_range(uint64_t time, uint64_t start, uint64_t end)
489+
{
490+
return (time >= start && time <= end);
491+
}

samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ int8_t dect_common_utils_harq_tx_next_redundancy_version_get(uint8_t current_red
9090

9191
bool dect_common_utils_32bit_network_id_validate(uint32_t network_id);
9292

93+
/******************************************************************************/
94+
95+
bool dect_common_utils_mdm_ticks_is_in_range(uint64_t time, uint64_t start, uint64_t end);
96+
9397
#endif /* DECT_COMMON_UTILS_H */

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ int dect_phy_ctrl_modem_temperature_get(void)
790790

791791
/**************************************************************************************************/
792792

793-
bool dect_phy_ctrl_rx_is_on_going(void)
793+
bool dect_phy_ctrl_rx_is_ongoing(void)
794794
{
795795
return ctrl_data.rx_cmd_on_going;
796796
}

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void dect_phy_ctrl_status_get_n_print(void);
4646

4747
int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params, bool restart);
4848
void dect_phy_ctrl_rx_stop(void);
49-
bool dect_phy_ctrl_rx_is_on_going(void);
49+
bool dect_phy_ctrl_rx_is_ongoing(void);
5050

5151
int dect_phy_ctrl_time_query(void);
5252

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct dect_phy_common_op_event_msgq_item {
191191
#define DECT_PHY_MAC_CLIENT_ASSOCIATION_RX_HANDLE 1004
192192
#define DECT_PHY_MAC_CLIENT_ASSOCIATION_REL_TX_HANDLE 1005
193193
#define DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN 1006
194-
/* Following handles DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN + DECT_PHY_MAC_MAX_NEIGBORS
194+
/* Following handles from DECT_PHY_MAC_CLIENT_ASSOCIATED_BG_SCAN + 1 to DECT_PHY_MAC_MAX_NEIGBORS
195195
* are reserved for associated bg scannings.
196196
*/
197197

samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,24 @@ bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params)
357357
}
358358

359359
/* Print only if:
360+
* - beacon tx ongoing and we have announced RA resources.
360361
* - client is associating/associated with the target device and
361362
* the received message is not a beacon from target
362363
* - beacon scan / rx cmd is ongoing
363-
* - beacon tx ongoing and we have announced RA resources.
364364
*/
365-
if (dect_phy_mac_client_associated_by_target_short_rd_id(
366-
rcv_params->last_received_pcc_transmitter_short_rd_id) &&
367-
type_header.type != DECT_PHY_MAC_HEADER_TYPE_BEACON) {
365+
if (dect_phy_mac_cluster_beacon_is_running()) {
368366
print = true;
369367
}
370-
if (dect_phy_ctrl_rx_is_on_going()) {
368+
369+
if (dect_phy_mac_client_associated_by_target_short_rd_id(
370+
rcv_params->last_received_pcc_transmitter_short_rd_id)) {
371371
print = true;
372+
if (type_header.type == DECT_PHY_MAC_HEADER_TYPE_BEACON) {
373+
print = false;
374+
}
372375
}
373-
if (dect_phy_mac_cluster_beacon_is_running()) {
376+
377+
if (dect_phy_ctrl_rx_is_ongoing()) {
374378
print = true;
375379
}
376380

samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_client.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
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

775808
void 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;

samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static struct dect_phy_mac_cluster_beacon_data {
4040

4141
dect_phy_mac_cluster_beacon_t last_cluster_beacon_msg;
4242
dect_phy_mac_random_access_resource_ie_t last_rach_ie;
43+
uint64_t last_tx_frame_time;
4344

4445
struct dect_phy_mac_beacon_start_params start_params;
4546
} beacon_data;
@@ -272,6 +273,19 @@ void dect_phy_mac_ctrl_cluster_beacon_phy_api_direct_rssi_cb(
272273
}
273274
}
274275

276+
static void dect_phy_mac_cluster_beacon_to_mdm_cb(
277+
struct dect_phy_common_op_completed_params *params, uint64_t frame_time)
278+
{
279+
if (params->status == NRF_MODEM_DECT_PHY_SUCCESS) {
280+
beacon_data.last_tx_frame_time = frame_time;
281+
}
282+
}
283+
284+
uint64_t dect_phy_mac_cluster_beacon_last_tx_frame_time_get(void)
285+
{
286+
return beacon_data.last_tx_frame_time;
287+
}
288+
275289
int dect_phy_mac_cluster_beacon_tx_start(struct dect_phy_mac_beacon_start_params *params)
276290
{
277291

@@ -367,6 +381,7 @@ int dect_phy_mac_cluster_beacon_tx_start(struct dect_phy_mac_beacon_start_params
367381
current_settings->common.transmitter_id;
368382
sched_list_item_conf->address_info.receiver_long_rd_id = DECT_LONG_RD_ID_BROADCAST;
369383

384+
sched_list_item_conf->cb_op_to_mdm = dect_phy_mac_cluster_beacon_to_mdm_cb;
370385
sched_list_item_conf->cb_op_completed = NULL;
371386

372387
sched_list_item_conf->channel = params->beacon_channel;

samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void dect_phy_mac_ctrl_cluster_beacon_phy_api_direct_rssi_cb(
3939

4040
bool dect_phy_mac_cluster_beacon_is_running(void);
4141

42+
uint64_t dect_phy_mac_cluster_beacon_last_tx_frame_time_get(void);
43+
4244
/******************************************************************************/
4345

4446
void dect_phy_mac_cluster_beacon_association_req_handle(

0 commit comments

Comments
 (0)