1 /*
2  * Copyright (c) 2022 Demant
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _ISOAL_TEST_COMMON_H_
8 #define _ISOAL_TEST_COMMON_H_
9 
10 
11 #define TEST_RX_PDU_PAYLOAD_MAX      (40)
12 #define TEST_RX_PDU_SIZE             (TEST_RX_PDU_PAYLOAD_MAX + 2)
13 
14 #define TEST_RX_SDU_FRAG_PAYLOAD_MAX (100)
15 #define TEST_TX_PDU_PAYLOAD_MAX      (40)
16 
17 #define TEST_TX_PDU_SIZE             (TEST_TX_PDU_PAYLOAD_MAX + 2)
18 #define TEST_TX_SDU_FRAG_PAYLOAD_MAX (100)
19 
20 
21 #define LLID_TO_STR(llid) (llid == PDU_BIS_LLID_COMPLETE_END ? "COMPLETE_END" : \
22 	(llid == PDU_BIS_LLID_START_CONTINUE ? "START_CONT" : \
23 		(llid == PDU_BIS_LLID_FRAMED ? "FRAMED" : \
24 			(llid == PDU_BIS_LLID_CTRL ? "CTRL" : "?????"))))
25 
26 #define DU_ERR_TO_STR(err) (err == 1 ? "Bit Errors" : \
27 			(err == 2 ? "Data Lost" : \
28 			(err == 0 ? "OK" : "Undefined!")))
29 
30 #define STATE_TO_STR(s) (s == BT_ISO_SINGLE ? "SINGLE" : \
31 	(s == BT_ISO_START ? "START" : \
32 		(s == BT_ISO_CONT ? "CONT" : \
33 			(s == BT_ISO_END ? "END" : "???"))))
34 
35 #define ROLE_TO_STR(s) \
36 	((s) == ISOAL_ROLE_BROADCAST_SOURCE ? "Broadcast Source" : \
37 	 ((s) == ISOAL_ROLE_BROADCAST_SINK ? "Broadcast Sink" : \
38 	  ((s) == ISOAL_ROLE_PERIPHERAL ? "Peripheral" : \
39 	   ((s) == ISOAL_ROLE_CENTRAL ? "Central" : "Undefined"))))
40 
41 #define FSM_TO_STR(s) (s == ISOAL_START ? "START" : \
42 	(s == ISOAL_CONTINUE ? "CONTINUE" : \
43 		(s == ISOAL_ERR_SPOOL ? "ERR SPOOL" : "???")))
44 
45 #if defined(ISOAL_CONFIG_BUFFER_RX_SDUS_ENABLE)
46 #define COLLATED_RX_SDU_INFO(_non_buf, _buf) (_buf)
47 #else
48 #define COLLATED_RX_SDU_INFO(_non_buf, _buf) (_non_buf)
49 #endif /* ISOAL_CONFIG_BUFFER_RX_SDUS_ENABLE */
50 
51 /* Maximum PDU payload for given number of PDUs */
52 #define MAX_FRAMED_PDU_PAYLOAD(_pdus)                                                              \
53 	(TEST_TX_PDU_PAYLOAD_MAX * _pdus) -                                                        \
54 		((PDU_ISO_SEG_HDR_SIZE * _pdus) + PDU_ISO_SEG_TIMEOFFSET_SIZE)
55 
56 struct rx_pdu_meta_buffer {
57 	struct isoal_pdu_rx pdu_meta;
58 	struct node_rx_iso_meta meta;
59 	uint8_t pdu[TEST_RX_PDU_SIZE];
60 };
61 
62 struct rx_sdu_frag_buffer {
63 	uint16_t write_loc;
64 	uint8_t sdu[TEST_RX_SDU_FRAG_PAYLOAD_MAX];
65 };
66 
67 
68 struct tx_pdu_meta_buffer {
69 	struct node_tx_iso node_tx;
70 	union{
71 		struct pdu_iso pdu;
72 		uint8_t pdu_payload[TEST_TX_PDU_PAYLOAD_MAX];
73 	};
74 };
75 
76 struct tx_sdu_frag_buffer {
77 	struct isoal_sdu_tx sdu_tx;
78 	uint8_t sdu_payload[TEST_TX_SDU_FRAG_PAYLOAD_MAX];
79 };
80 
81 
82 extern void isoal_test_init_rx_pdu_buffer(struct rx_pdu_meta_buffer *buf);
83 extern void isoal_test_init_rx_sdu_buffer(struct rx_sdu_frag_buffer *buf);
84 extern void isoal_test_create_unframed_pdu(uint8_t llid, uint8_t *dataptr,
85 	uint8_t length, uint64_t payload_number, uint32_t timestamp,
86 	uint8_t  status, struct isoal_pdu_rx *pdu_meta);
87 extern uint16_t isoal_test_insert_segment(bool sc,
88 	bool cmplt, uint32_t time_offset, uint8_t *dataptr, uint8_t length,
89 	struct isoal_pdu_rx *pdu_meta);
90 extern void isoal_test_create_framed_pdu_base(uint64_t payload_number,
91 	uint32_t timestamp, uint8_t  status, struct isoal_pdu_rx *pdu_meta);
92 extern uint16_t isoal_test_add_framed_pdu_single(uint8_t *dataptr,
93 	uint8_t length, uint32_t time_offset, struct isoal_pdu_rx *pdu_meta);
94 extern uint16_t isoal_test_add_framed_pdu_start(uint8_t *dataptr,
95 	uint8_t length, uint32_t time_offset, struct isoal_pdu_rx *pdu_meta);
96 extern uint16_t isoal_test_add_framed_pdu_cont(uint8_t *dataptr,
97 	uint8_t length, struct isoal_pdu_rx *pdu_meta);
98 extern uint16_t isoal_test_add_framed_pdu_end(uint8_t *dataptr,
99 	uint8_t length, struct isoal_pdu_rx *pdu_meta);
100 extern void isoal_test_init_tx_pdu_buffer(struct tx_pdu_meta_buffer *buf);
101 extern void isoal_test_init_tx_sdu_buffer(struct tx_sdu_frag_buffer *buf);
102 extern void init_test_data_buffer(uint8_t *buf, uint16_t size);
103 
104 #endif /* _ISOAL_TEST_COMMON_H_ */
105