1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "common.h" 8 #include "argparse.h" 9 test_tick(bs_time_t HW_device_time)10void test_tick(bs_time_t HW_device_time) 11 { 12 if (bst_result != Passed) { 13 FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); 14 } 15 } 16 test_init(void)17void test_init(void) 18 { 19 bst_ticker_set_next_tick_absolute(WAIT_TIME); 20 bst_result = In_progress; 21 } 22 23 #define CHANNEL_ID 0 24 #define MSG_SIZE 1 25 backchannel_init(void)26void backchannel_init(void) 27 { 28 uint device_number = get_device_nbr(); 29 uint peer_number = device_number ^ 1; 30 uint device_numbers[] = { peer_number }; 31 uint channel_numbers[] = { CHANNEL_ID }; 32 uint *ch; 33 34 ch = bs_open_back_channel(device_number, device_numbers, channel_numbers, 35 ARRAY_SIZE(channel_numbers)); 36 if (!ch) { 37 FAIL("Unable to open backchannel\n"); 38 } 39 } 40 backchannel_sync_send(void)41void backchannel_sync_send(void) 42 { 43 uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; 44 45 printk("Sending sync\n"); 46 bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); 47 } 48 backchannel_sync_wait(void)49void backchannel_sync_wait(void) 50 { 51 uint8_t sync_msg[MSG_SIZE]; 52 53 while (true) { 54 if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { 55 bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); 56 if (sync_msg[0] != get_device_nbr()) { 57 /* Received a message from another device, exit */ 58 break; 59 } 60 } 61 62 k_sleep(K_MSEC(1)); 63 } 64 65 printk("Sync received\n"); 66 } 67