1 /*
2  * Copyright (c) 2016 Nordic Semiconductor ASA
3  * Copyright (c) 2016 Vinayak Kariappa Chettimada
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 /* Set of macros related with Radio packet configuration flags */
9 /* PDU type, 2 bit field*/
10 #define RADIO_PKT_CONF_PDU_TYPE_POS (0U)
11 #define RADIO_PKT_CONF_PDU_TYPE_MSK (BIT_MASK(2U))
12 #define RADIO_PKT_CONF_PDU_TYPE_AC  (0U)
13 #define RADIO_PKT_CONF_PDU_TYPE_DC  (1U)
14 #define RADIO_PKT_CONF_PDU_TYPE_BIS (2U)
15 #define RADIO_PKT_CONF_PDU_TYPE_CIS (3U)
16 /* PHY type, three bit field */
17 #define RADIO_PKT_CONF_PHY_POS      (2U)
18 #define RADIO_PKT_CONF_PHY_MSK      (BIT_MASK(3U))
19 #define RADIO_PKT_CONF_PHY_LEGACY   (0U)
20 #define RADIO_PKT_CONF_PHY_1M       (BIT(0U))
21 #define RADIO_PKT_CONF_PHY_2M       (BIT(1U))
22 #define RADIO_PKT_CONF_PHY_CODED    (BIT(2U))
23 /* CTE enabled, 1 bit field */
24 #define RADIO_PKT_CONF_CTE_POS      (5U)
25 #define RADIO_PKT_CONF_CTE_MSK      (BIT_MASK(1U))
26 #define RADIO_PKT_CONF_CTE_DISABLED (0U)
27 #define RADIO_PKT_CONF_CTE_ENABLED  (1U)
28 
29 /* Macro to define length of the BLE packet length field in bits */
30 #define RADIO_PKT_CONF_LENGTH_8BIT (8U)
31 #define RADIO_PKT_CONF_LENGTH_5BIT (5U)
32 
33 /* Macro to define length of the BLE packet S1 field in bits */
34 #define RADIO_PKT_CONF_S1_8BIT (8U)
35 
36 /* Helper macro to create bitfield with PDU type only*/
37 #define RADIO_PKT_CONF_PDU_TYPE(phy) ((uint8_t)((phy) << RADIO_PKT_CONF_PDU_TYPE_POS))
38 /* Helper macro to get PDU type from radio packet configuration bitfield */
39 #define RADIO_PKT_CONF_PDU_TYPE_GET(flags)                                                         \
40 	((uint8_t)(((flags) >> RADIO_PKT_CONF_PDU_TYPE_POS) & RADIO_PKT_CONF_PDU_TYPE_MSK))
41 /* Helper macro to create bitfield with PHY type only */
42 #define RADIO_PKT_CONF_PHY(phy) ((uint8_t)((phy) << RADIO_PKT_CONF_PHY_POS))
43 /* Helper macro to get PHY type from radio packet configuration bitfield */
44 #define RADIO_PKT_CONF_PHY_GET(flags)                                                              \
45 	((uint8_t)((((flags) >> RADIO_PKT_CONF_PHY_POS)) & RADIO_PKT_CONF_PHY_MSK))
46 /* Helper macro to create bitfield with CTE type only */
47 #define RADIO_PKT_CONF_CTE(phy) ((uint8_t)((phy) << RADIO_PKT_CONF_CTE_POS))
48 /* Helper macro to get CTE enable field value from radio packet configuration bitfield */
49 #define RADIO_PKT_CONF_CTE_GET(flags)                                                              \
50 	((uint8_t)((((flags) >> RADIO_PKT_CONF_CTE_POS)) & RADIO_PKT_CONF_CTE_MSK))
51 /* Helper macro to create a radio packet configure bitfield */
52 #define RADIO_PKT_CONF_FLAGS(pdu, phy, cte)                                                        \
53 	(RADIO_PKT_CONF_PDU_TYPE((pdu)) | RADIO_PKT_CONF_PHY((phy)) | RADIO_PKT_CONF_CTE((cte)))
54 
55 enum radio_end_evt_delay_state { END_EVT_DELAY_DISABLED, END_EVT_DELAY_ENABLED };
56 
57 typedef void (*radio_isr_cb_t) (void *param);
58 
59 void isr_radio(void);
60 void radio_isr_set(radio_isr_cb_t cb, void *param);
61 
62 void radio_setup(void);
63 void radio_reset(void);
64 void radio_stop(void);
65 void radio_phy_set(uint8_t phy, uint8_t flags);
66 void radio_tx_power_set(int8_t power);
67 void radio_tx_power_max_set(void);
68 int8_t radio_tx_power_min_get(void);
69 int8_t radio_tx_power_max_get(void);
70 int8_t radio_tx_power_floor(int8_t power);
71 void radio_freq_chan_set(uint32_t chan);
72 void radio_whiten_iv_set(uint32_t iv);
73 void radio_aa_set(const uint8_t *aa);
74 void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags);
75 void radio_pkt_rx_set(void *rx_packet);
76 void radio_pkt_tx_set(void *tx_packet);
77 uint32_t radio_tx_ready_delay_get(uint8_t phy, uint8_t flags);
78 uint32_t radio_tx_chain_delay_get(uint8_t phy, uint8_t flags);
79 uint32_t radio_rx_ready_delay_get(uint8_t phy, uint8_t flags);
80 uint32_t radio_rx_chain_delay_get(uint8_t phy, uint8_t flags);
81 void radio_rx_enable(void);
82 void radio_tx_enable(void);
83 void radio_disable(void);
84 
85 void radio_status_reset(void);
86 uint32_t radio_is_ready(void);
87 uint32_t radio_is_address(void);
88 uint32_t radio_is_done(void);
89 uint32_t radio_is_tx_done(void);
90 uint32_t radio_has_disabled(void);
91 uint32_t radio_is_idle(void);
92 
93 void radio_crc_configure(uint32_t polynomial, uint32_t iv);
94 uint32_t radio_crc_is_valid(void);
95 
96 void *radio_pkt_empty_get(void);
97 void *radio_pkt_scratch_get(void);
98 void *radio_pkt_decrypt_get(void);
99 void *radio_pkt_big_ctrl_get(void);
100 
101 void radio_switch_complete_and_rx(uint8_t phy_rx);
102 void radio_switch_complete_and_tx(uint8_t phy_rx, uint8_t flags_rx, uint8_t phy_tx,
103 				  uint8_t flags_tx);
104 void radio_switch_complete_with_delay_compensation_and_tx(
105 	uint8_t phy_rx, uint8_t flags_rx, uint8_t phy_tx, uint8_t flags_tx,
106 	enum radio_end_evt_delay_state end_evt_delay_en);
107 void radio_switch_complete_and_b2b_tx(uint8_t phy_curr, uint8_t flags_curr,
108 				      uint8_t phy_next, uint8_t flags_next);
109 void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr,
110 				      uint8_t phy_next, uint8_t flags_next);
111 void radio_switch_complete_and_b2b_tx_disable(void);
112 void radio_switch_complete_and_b2b_rx_disable(void);
113 void radio_switch_complete_and_disable(void);
114 
115 uint8_t radio_phy_flags_rx_get(void);
116 
117 void radio_rssi_measure(void);
118 uint32_t radio_rssi_get(void);
119 void radio_rssi_status_reset(void);
120 uint32_t radio_rssi_is_ready(void);
121 
122 void radio_filter_configure(uint8_t bitmask_enable, uint8_t bitmask_addr_type,
123 			    uint8_t *bdaddr);
124 void radio_filter_disable(void);
125 void radio_filter_status_reset(void);
126 uint32_t radio_filter_has_match(void);
127 uint32_t radio_filter_match_get(void);
128 
129 void radio_bc_configure(uint32_t n);
130 void radio_bc_status_reset(void);
131 uint32_t radio_bc_has_match(void);
132 
133 void isr_radio_tmr(void);
134 uint32_t radio_tmr_isr_set(uint32_t start_us, radio_isr_cb_t cb, void *param);
135 
136 void radio_tmr_status_reset(void);
137 void radio_tmr_tx_status_reset(void);
138 void radio_tmr_rx_status_reset(void);
139 void radio_tmr_tx_enable(void);
140 void radio_tmr_rx_enable(void);
141 void radio_tmr_tx_disable(void);
142 void radio_tmr_rx_disable(void);
143 void radio_tmr_tifs_set(uint32_t tifs);
144 uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder);
145 uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t ticks_start);
146 uint32_t radio_tmr_start_us(uint8_t trx, uint32_t us);
147 uint32_t radio_tmr_start_now(uint8_t trx);
148 uint32_t radio_tmr_start_get(void);
149 void radio_tmr_stop(void);
150 void radio_tmr_hcto_configure(uint32_t hcto);
151 void radio_tmr_aa_capture(void);
152 uint32_t radio_tmr_aa_get(void);
153 void radio_tmr_aa_save(uint32_t aa);
154 uint32_t radio_tmr_aa_restore(void);
155 uint32_t radio_tmr_ready_get(void);
156 void radio_tmr_ready_save(uint32_t ready);
157 uint32_t radio_tmr_ready_restore(void);
158 void radio_tmr_end_capture(void);
159 uint32_t radio_tmr_end_get(void);
160 uint32_t radio_tmr_tifs_base_get(void);
161 void radio_tmr_sample(void);
162 uint32_t radio_tmr_sample_get(void);
163 
164 int radio_gpio_pa_lna_init(void);
165 void radio_gpio_pa_lna_deinit(void);
166 void radio_gpio_pa_setup(void);
167 void radio_gpio_lna_setup(void);
168 void radio_gpio_pdn_setup(void);
169 void radio_gpio_lna_on(void);
170 void radio_gpio_lna_off(void);
171 void radio_gpio_pa_lna_enable(uint32_t trx_us);
172 void radio_gpio_pa_lna_disable(void);
173 
174 void *radio_ccm_rx_pkt_set(struct ccm *ccm, uint8_t phy, void *pkt);
175 void *radio_ccm_iso_rx_pkt_set(struct ccm *ccm, uint8_t phy, uint8_t pdu_type, void *pkt);
176 void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt);
177 void *radio_ccm_iso_tx_pkt_set(struct ccm *ccm, uint8_t pdu_type, void *pkt);
178 uint32_t radio_ccm_is_done(void);
179 uint32_t radio_ccm_mic_is_valid(void);
180 
181 void radio_ar_configure(uint32_t nirk, void *irk, uint8_t flags);
182 uint32_t radio_ar_match_get(void);
183 void radio_ar_status_reset(void);
184 uint32_t radio_ar_has_match(void);
185 uint8_t radio_ar_resolve(const uint8_t *addr);
186 
187 /* Enables CTE inline configuration to automatically setup sampling and
188  * switching according to CTEInfo in received PDU.
189  */
190 void radio_df_cte_inline_set_enabled(bool cte_info_in_s1);
191