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