1 /* Copyright (c) 2023 Nordic Semiconductor ASA
2  * SPDX-License-Identifier: Apache-2.0
3  */
4 
5 #include <stdint.h>
6 
7 #include "common.h"
8 
9 #include "argparse.h"
10 #include "bs_pc_backchannel.h"
11 
backchannel_sync_send(uint channel,uint device_nbr)12 void backchannel_sync_send(uint channel, uint device_nbr)
13 {
14 	uint8_t sync_msg[BC_MSG_SIZE] = {get_device_nbr(), device_nbr}; /* src, dst */
15 
16 	bs_bc_send_msg(channel, sync_msg, ARRAY_SIZE(sync_msg));
17 }
18 
backchannel_sync_wait(uint channel,uint device_nbr)19 void backchannel_sync_wait(uint channel, uint device_nbr)
20 {
21 	uint8_t sync_msg[BC_MSG_SIZE];
22 
23 	LOG_DBG("Wait for %d on channel %d", device_nbr, channel);
24 
25 	while (true) {
26 		if (bs_bc_is_msg_received(channel) > 0) {
27 			bs_bc_receive_msg(channel, sync_msg, ARRAY_SIZE(sync_msg));
28 
29 			if (sync_msg[0] == device_nbr && sync_msg[1] == get_device_nbr()) {
30 				break;
31 			}
32 		}
33 
34 		k_msleep(1);
35 	}
36 
37 	LOG_DBG("Sync received");
38 }
39