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_done(void);
88 uint32_t radio_has_disabled(void);
89 uint32_t radio_is_idle(void);
90 
91 void radio_crc_configure(uint32_t polynomial, uint32_t iv);
92 uint32_t radio_crc_is_valid(void);
93 
94 void *radio_pkt_empty_get(void);
95 void *radio_pkt_scratch_get(void);
96 void *radio_pkt_decrypt_get(void);
97 void *radio_pkt_big_ctrl_get(void);
98 
99 void radio_switch_complete_and_rx(uint8_t phy_rx);
100 void radio_switch_complete_and_tx(uint8_t phy_rx, uint8_t flags_rx, uint8_t phy_tx,
101 				  uint8_t flags_tx);
102 void radio_switch_complete_with_delay_compensation_and_tx(
103 	uint8_t phy_rx, uint8_t flags_rx, uint8_t phy_tx, uint8_t flags_tx,
104 	enum radio_end_evt_delay_state end_evt_delay_en);
105 void radio_switch_complete_and_b2b_tx(uint8_t phy_curr, uint8_t flags_curr,
106 				      uint8_t phy_next, uint8_t flags_next);
107 void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr,
108 				      uint8_t phy_next, uint8_t flags_next);
109 void radio_switch_complete_and_b2b_tx_disable(void);
110 void radio_switch_complete_and_b2b_rx_disable(void);
111 void radio_switch_complete_and_disable(void);
112 
113 uint8_t radio_phy_flags_rx_get(void);
114 
115 void radio_rssi_measure(void);
116 uint32_t radio_rssi_get(void);
117 void radio_rssi_status_reset(void);
118 uint32_t radio_rssi_is_ready(void);
119 
120 void radio_filter_configure(uint8_t bitmask_enable, uint8_t bitmask_addr_type,
121 			    uint8_t *bdaddr);
122 void radio_filter_disable(void);
123 void radio_filter_status_reset(void);
124 uint32_t radio_filter_has_match(void);
125 uint32_t radio_filter_match_get(void);
126 
127 void radio_bc_configure(uint32_t n);
128 void radio_bc_status_reset(void);
129 uint32_t radio_bc_has_match(void);
130 
131 void radio_tmr_status_reset(void);
132 void radio_tmr_tx_status_reset(void);
133 void radio_tmr_rx_status_reset(void);
134 void radio_tmr_tx_enable(void);
135 void radio_tmr_rx_enable(void);
136 void radio_tmr_tx_disable(void);
137 void radio_tmr_rx_disable(void);
138 void radio_tmr_tifs_set(uint32_t tifs);
139 uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder);
140 uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t tick);
141 uint32_t radio_tmr_start_us(uint8_t trx, uint32_t us);
142 uint32_t radio_tmr_start_now(uint8_t trx);
143 uint32_t radio_tmr_start_get(void);
144 void radio_tmr_stop(void);
145 void radio_tmr_hcto_configure(uint32_t hcto);
146 void radio_tmr_aa_capture(void);
147 uint32_t radio_tmr_aa_get(void);
148 void radio_tmr_aa_save(uint32_t aa);
149 uint32_t radio_tmr_aa_restore(void);
150 uint32_t radio_tmr_ready_get(void);
151 void radio_tmr_ready_save(uint32_t ready);
152 uint32_t radio_tmr_ready_restore(void);
153 void radio_tmr_end_capture(void);
154 uint32_t radio_tmr_end_get(void);
155 uint32_t radio_tmr_tifs_base_get(void);
156 void radio_tmr_sample(void);
157 uint32_t radio_tmr_sample_get(void);
158 
159 int radio_gpio_pa_lna_init(void);
160 void radio_gpio_pa_lna_deinit(void);
161 void radio_gpio_pa_setup(void);
162 void radio_gpio_lna_setup(void);
163 void radio_gpio_pdn_setup(void);
164 void radio_gpio_csn_setup(void);
165 void radio_gpio_lna_on(void);
166 void radio_gpio_lna_off(void);
167 void radio_gpio_pa_lna_enable(uint32_t trx_us);
168 void radio_gpio_pa_lna_disable(void);
169 
170 void *radio_ccm_rx_pkt_set(struct ccm *ccm, uint8_t phy, void *pkt);
171 void *radio_ccm_iso_rx_pkt_set(struct ccm *ccm, uint8_t phy, uint8_t pdu_type, void *pkt);
172 void *radio_ccm_tx_pkt_set(struct ccm *ccm, void *pkt);
173 void *radio_ccm_iso_tx_pkt_set(struct ccm *ccm, uint8_t pdu_type, void *pkt);
174 uint32_t radio_ccm_is_done(void);
175 uint32_t radio_ccm_mic_is_valid(void);
176 
177 void radio_ar_configure(uint32_t nirk, void *irk, uint8_t flags);
178 uint32_t radio_ar_match_get(void);
179 void radio_ar_status_reset(void);
180 uint32_t radio_ar_has_match(void);
181 uint8_t radio_ar_resolve(const uint8_t *addr);
182 
183 /* Enables CTE inline configuration to automatically setup sampling and
184  * switching according to CTEInfo in received PDU.
185  */
186 void radio_df_cte_inline_set_enabled(bool cte_info_in_s1);
187