1 /* 2 * Copyright (c) 2022 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include "common.h" 8 #include <zephyr/logging/log.h> 9 10 #define LOG_MODULE_NAME common 11 12 LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); 13 test_tick(bs_time_t HW_device_time)14void test_tick(bs_time_t HW_device_time) 15 { 16 if (bst_result != Passed) { 17 FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); 18 } 19 } 20 test_init(void)21void test_init(void) 22 { 23 bst_ticker_set_next_tick_absolute(WAIT_TIME); 24 bst_result = In_progress; 25 } 26 27 /* Call in init functions*/ device_sync_init(uint device_nbr)28void device_sync_init(uint device_nbr) 29 { 30 uint peer; 31 32 if (device_nbr == CENTRAL_ID) { 33 peer = PERIPHERAL_ID; 34 } else { 35 peer = CENTRAL_ID; 36 } 37 38 uint dev_nbrs[BACK_CHANNELS] = { peer }; 39 uint channel_nbrs[BACK_CHANNELS] = { 0 }; 40 const uint *ch = bs_open_back_channel(device_nbr, dev_nbrs, channel_nbrs, BACK_CHANNELS); 41 42 if (!ch) { 43 LOG_ERR("bs_open_back_channel failed!"); 44 } 45 } 46 47 /* Call it to make peer to proceed.*/ device_sync_send(void)48void device_sync_send(void) 49 { 50 uint8_t msg[1] = "S"; 51 52 bs_bc_send_msg(0, msg, sizeof(msg)); 53 } 54 55 /* Wait until peer send sync*/ device_sync_wait(void)56void device_sync_wait(void) 57 { 58 int size_msg_received = 0; 59 uint8_t msg; 60 61 while (!size_msg_received) { 62 size_msg_received = bs_bc_is_msg_received(0); 63 k_sleep(K_MSEC(1)); 64 } 65 66 bs_bc_receive_msg(0, &msg, size_msg_received); 67 } 68