1 /*
2  * Common functions and helpers for L2CAP tests
3  *
4  * Copyright (c) 2022 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <stddef.h>
10 
11 #include <zephyr/types.h>
12 #include <zephyr/sys/util.h>
13 #include <zephyr/sys/byteorder.h>
14 
15 #include <zephyr/bluetooth/bluetooth.h>
16 #include <zephyr/bluetooth/hci.h>
17 #include <zephyr/bluetooth/l2cap.h>
18 #include "bs_types.h"
19 #include "bs_tracing.h"
20 #include "bstests.h"
21 #include "bs_pc_backchannel.h"
22 
23 #define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
24 #define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
25 #define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false)
26 #define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true)
27 #define WAIT_FOR_FLAG_SET(flag)		   \
28 	while (!(bool)atomic_get(&flag)) { \
29 		(void)k_sleep(K_MSEC(1));  \
30 	}
31 #define WAIT_FOR_FLAG_UNSET(flag)	  \
32 	while ((bool)atomic_get(&flag)) { \
33 		(void)k_sleep(K_MSEC(1)); \
34 	}
35 
36 
37 #define WAIT_TIME (60e6) /* 60 seconds*/
38 
39 #define FAIL(...)				       \
40 	do {					       \
41 		bst_result = Failed;		       \
42 		bs_trace_error_time_line(__VA_ARGS__); \
43 	} while (0)
44 
45 #define PASS(...)				    \
46 	do {					    \
47 		bst_result = Passed;		    \
48 		bs_trace_info_time(1, __VA_ARGS__); \
49 	} while (0)
50 
51 #define CENTRAL_ID 0
52 #define PERIPHERAL_ID 1
53 #define BACK_CHANNELS 1
54 
55 void test_init(void);
56 void test_tick(bs_time_t HW_device_time);
57 void device_sync_init(uint device_nbr);
58 void device_sync_send(void);
59 void device_sync_wait(void);
60