1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Use the timer instance ID, not NRF_TIMERx directly, so that it can be checked
8  * in radio_nrf5_ppi.h by the preprocessor.
9  */
10 #if defined(CONFIG_BT_CTLR_TIFS_HW)
11 #define EVENT_TIMER_ID 0
12 #define EVENT_TIMER    _CONCAT(NRF_TIMER, EVENT_TIMER_ID)
13 
14 /* Single timer feature not supported when using h/w tIFS switching */
15 #define HAL_RADIO_ISR_LATENCY_MAX_US 0U
16 
17 /* Wrapper for EVENTS_END event generated by Radio peripheral at the very end of the transmission
18  * or reception of a PDU on air. In case of regular PDU it is generated when last bit of CRC is
19  * received or transmitted.
20  */
21 #define HAL_RADIO_TRX_EVENTS_END    HAL_RADIO_EVENTS_END
22 #define HAL_NRF_RADIO_TRX_EVENT_END HAL_NRF_RADIO_EVENT_END
23 #define HAL_RADIO_IFS_EVENTS_END    HAL_RADIO_EVENTS_END
24 
25 /* Wrapper for RADIO_SHORTS mask connecting EVENTS_END to EVENTS_DISABLE.
26  * This is a default shortcut used to automatically disable Radio after end of PDU.
27  */
28 #define NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk HAL_RADIO_SHORTS_TRX_END_DISABLE_Msk
29 
30 #define HAL_EVENT_TIMER_TRX_CC_OFFSET          0
31 #define HAL_EVENT_TIMER_TRX_EVENT              NRF_TIMER_EVENT_COMPARE0
32 #define HAL_EVENT_TIMER_READY_TASK             NRF_TIMER_TASK_CAPTURE0
33 
34 #define HAL_EVENT_TIMER_HCTO_CC_OFFSET         1
35 #define HAL_EVENT_TIMER_HCTO_EVENT             NRF_TIMER_EVENT_COMPARE1
36 #define HAL_EVENT_TIMER_ADDRESS_TASK           NRF_TIMER_TASK_CAPTURE1
37 
38 #define HAL_EVENT_TIMER_TRX_END_CC_OFFSET      2
39 #define HAL_EVENT_TIMER_TRX_END_TASK           NRF_TIMER_TASK_CAPTURE2
40 
41 #define HAL_EVENT_TIMER_DEFERRED_TRX_CC_OFFSET 2
42 #define HAL_EVENT_TIMER_DEFERRED_TX_EVENT      NRF_TIMER_EVENT_COMPARE2
43 
44 #define HAL_EVENT_TIMER_SAMPLE_CC_OFFSET       3
45 #define HAL_EVENT_TIMER_SAMPLE_TASK            NRF_TIMER_TASK_CAPTURE3
46 
47 #define HAL_EVENT_TIMER_PA_LNA_CC_OFFSET       2
48 #define HAL_EVENT_TIMER_PA_LNA_PDN_CC_OFFSET   3
49 
50 #else /* !CONFIG_BT_CTLR_TIFS_HW */
51 #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER)
52 #define EVENT_TIMER_ID 4
53 #define EVENT_TIMER    _CONCAT(NRF_TIMER, EVENT_TIMER_ID)
54 
55 #define SW_SWITCH_TIMER EVENT_TIMER
56 
57 /* Radio ISR Latency to be considered with single timer used so that the PPI/
58  * DPPI is disabled in time when the timer is cleared on radio end, so that
59  * the timer compare should not trigger TXEN/RXEN immediately on radio end.
60  * This value will be used as minimum turnaround time in setting up Rx to Tx
61  * using radio_tmr_start_us under single timer use.
62  * The value of 80 us is used considering 150 us TIFS minus the maximum rx
63  * chain delay ~30 us, and minus the radio ramp up delay ~40 us.
64  */
65 #define HAL_RADIO_ISR_LATENCY_MAX_US 80U
66 
67 #define SW_SWITCH_TIMER_EVTS_COMP_BASE 4
68 
69 #if defined(CONFIG_BT_CTLR_PHY_CODED)
70 #define SW_SWITCH_TIMER_EVTS_COMP_S2_BASE 6
71 #endif /* !CONFIG_BT_CTLR_PHY_CODED */
72 
73 #if defined(CONFIG_BT_CTLR_DF)
74 #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE)
75 /* Allocate 2 adjacent channels for PHYEND delay compensation. Use the same channels as for
76  * PHY CODED S2. The CTEINLINE may not be enabled for PHY CODED so PHYEND event is generated
77  * at the same instant as END event. Hence the channels are used interchangeably.
78  * That saves from use of another timer.
79  */
80 #define SW_SWITCH_TIMER_EVTS_COMP_PHYEND_DELAY_COMPENSATION_BASE 6
81 #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */
82 
83 /* Wrapper for EVENTS_END event generated by Radio peripheral at the very end of the transmission
84  * or reception of a PDU on air. In case of regular PDU it is generated when last bit of CRC is
85  * received or transmitted.
86  *
87  * When direction finding is enabled a PDU may include Constant Tone Extension at its end. For PDU
88  * including CTE EVENTS_PHYEND event is generated at very end of a PDU. In case there is no CTE in
89  * a PDU the EVENTS_PHYEND event is generated in the same instant as EVENTS_END event.
90  */
91 #define HAL_RADIO_TRX_EVENTS_END    HAL_RADIO_EVENTS_PHYEND
92 #define HAL_NRF_RADIO_TRX_EVENT_END HAL_NRF_RADIO_EVENT_PHYEND
93 #define HAL_RADIO_IFS_EVENTS_END    HAL_RADIO_EVENTS_PHYEND
94 
95 /* Wrapper for RADIO_SHORTS mask connecting EVENTS_PHYEND to EVENTS_DISABLE.
96  * This is a mask for SOC that has Direction Finding Extension in a Radio peripheral.
97  * It enables shortcut for EVENTS_PHYEND event generated at very end to Radio EVENTS_DISABLE event.
98  * In case there is a CTE in a PDU then EVENTS_PHYEND event is generated after the CTE.
99  * If there is no CTE, it is generated in the same instant as EVENTS_END.
100  */
101 #define NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk HAL_RADIO_SHORTS_TRX_PHYEND_DISABLE_Msk
102 
103 /* Delay of EVENTS_PHYEND event on receive PDU without CTE included when CTEINLINE is enabled */
104 #define RADIO_EVENTS_PHYEND_DELAY_US 16
105 
106 #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX)
107 /* Delay of CCM TASKS_CRYPT start in number of bits for Radio Bit counter */
108 #define CCM_TASKS_CRYPT_DELAY_BITS 3
109 #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */
110 
111 #else /* !CONFIG_BT_CTLR_DF */
112 /* Wrapper for EVENTS_END event generated by Radio peripheral at the very end of the transmission
113  * or reception of a PDU on air. In case of regular PDU it is generated when last bit of CRC is
114  * received or transmitted.
115  */
116 #define HAL_RADIO_TRX_EVENTS_END    HAL_RADIO_EVENTS_END
117 #define HAL_NRF_RADIO_TRX_EVENT_END HAL_NRF_RADIO_EVENT_END
118 #define HAL_RADIO_IFS_EVENTS_END    HAL_RADIO_EVENTS_END
119 
120 /* Wrapper for RADIO_SHORTS mask connecting EVENTS_END to EVENTS_DISABLE.
121  * This is a default shortcut used to automatically disable Radio after end of PDU.
122  */
123 #define NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk HAL_RADIO_SHORTS_TRX_END_DISABLE_Msk
124 #endif /* !CONFIG_BT_CTLR_DF */
125 
126 #define HAL_EVENT_TIMER_TRX_CC_OFFSET          0
127 #define HAL_EVENT_TIMER_TRX_EVENT              NRF_TIMER_EVENT_COMPARE0
128 #define HAL_EVENT_TIMER_READY_TASK             NRF_TIMER_TASK_CAPTURE0
129 
130 #define HAL_EVENT_TIMER_HCTO_CC_OFFSET         1
131 #define HAL_EVENT_TIMER_HCTO_EVENT             NRF_TIMER_EVENT_COMPARE1
132 #define HAL_EVENT_TIMER_ADDRESS_TASK           NRF_TIMER_TASK_CAPTURE1
133 
134 #define HAL_EVENT_TIMER_TRX_END_CC_OFFSET      2
135 #define HAL_EVENT_TIMER_TRX_END_TASK           NRF_TIMER_TASK_CAPTURE2
136 
137 #define HAL_EVENT_TIMER_DEFERRED_TRX_CC_OFFSET 2
138 #define HAL_EVENT_TIMER_DEFERRED_TX_EVENT      NRF_TIMER_EVENT_COMPARE2
139 
140 #define HAL_EVENT_TIMER_SAMPLE_CC_OFFSET       3
141 #define HAL_EVENT_TIMER_SAMPLE_TASK            NRF_TIMER_TASK_CAPTURE3
142 
143 #define HAL_EVENT_TIMER_PA_LNA_CC_OFFSET       2
144 #define HAL_EVENT_TIMER_PA_LNA_PDN_CC_OFFSET   3
145 
146 #else /* !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */
147 #define EVENT_TIMER_ID 0
148 #define EVENT_TIMER    _CONCAT(NRF_TIMER, EVENT_TIMER_ID)
149 
150 #define SW_SWITCH_TIMER NRF_TIMER1
151 
152 /* When using dedicated timer used for tIFS switching, compensation to avoid
153  * spurious TXEN/RXEN due to timer being clear is not needed.
154  */
155 #define HAL_RADIO_ISR_LATENCY_MAX_US 0U
156 
157 #define SW_SWITCH_TIMER_EVTS_COMP_BASE 0
158 
159 #if defined(CONFIG_BT_CTLR_PHY_CODED)
160 #define SW_SWITCH_TIMER_EVTS_COMP_S2_BASE 2
161 #endif /* !CONFIG_BT_CTLR_PHY_CODED */
162 
163 #if defined(CONFIG_BT_CTLR_DF)
164 #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE)
165 /* Allocate 2 adjacent channels for PHYEND delay compensation. Use the same channels as for
166  * PHY CODED S2. The CTEINLINE may not be enabled for PHY CODED so PHYEND event is generated
167  * at the same instant as END event. Hence the channels are used interchangeably.
168  * That saves from use of another timer.
169  */
170 #define SW_SWITCH_TIMER_EVTS_COMP_PHYEND_DELAY_COMPENSATION_BASE 2
171 #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */
172 
173 /* Wrapper for EVENTS_END event generated by Radio peripheral at the very end of the transmission
174  * or reception of a PDU on air. In case of regular PDU it is generated when last bit of CRC is
175  * received or transmitted.
176  *
177  * When direction finding is enabled a PDU may include Constant Tone Extension at its end. For PDU
178  * including CTE EVENTS_PHYEND event is generated at very end of a PDU. In case there is no CTE in
179  * a PDU the EVENTS_PHYEND event is generated in the same instant as EVENTS_END event.
180  */
181 #define HAL_RADIO_TRX_EVENTS_END    HAL_RADIO_EVENTS_END
182 #define HAL_NRF_RADIO_TRX_EVENT_END HAL_NRF_RADIO_EVENT_END
183 #define HAL_RADIO_IFS_EVENTS_END    HAL_RADIO_EVENTS_PHYEND
184 
185 /* Wrapper for RADIO_SHORTS mask connecting EVENTS_PHYEND to EVENTS_DISABLE.
186  * This is a mask for SOC that has Direction Finding Extension in a Radio peripheral.
187  * It enables shortcut for EVENTS_PHYEND event generated at very end to Radio EVENTS_DISABLE event.
188  * In case there is a CTE in a PDU then EVENTS_PHYEND event is generated after the CTE.
189  * If there is no CTE, it is generated in the same instant as EVENTS_END.
190  */
191 #define NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk HAL_RADIO_SHORTS_TRX_PHYEND_DISABLE_Msk
192 
193 /* Delay of EVENTS_PHYEND event on receive PDU without CTE included when CTEINLINE is enabled */
194 #define RADIO_EVENTS_PHYEND_DELAY_US 16
195 
196 #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX)
197 /* Delay of CCM TASKS_CRYPT start in number of bits for Radio Bit counter */
198 #define CCM_TASKS_CRYPT_DELAY_BITS 3
199 #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */
200 
201 #else /* !CONFIG_BT_CTLR_DF */
202 /* Wrapper for EVENTS_END event generated by Radio peripheral at the very end of the transmission
203  * or reception of a PDU on air. In case of regular PDU it is generated when last bit of CRC is
204  * received or transmitted.
205  */
206 #define HAL_RADIO_TRX_EVENTS_END    HAL_RADIO_EVENTS_END
207 #define HAL_NRF_RADIO_TRX_EVENT_END HAL_NRF_RADIO_EVENT_END
208 #define HAL_RADIO_IFS_EVENTS_END    HAL_RADIO_EVENTS_END
209 
210 /* Wrapper for RADIO_SHORTS mask connecting EVENTS_END to EVENTS_DISABLE.
211  * This is a default shortcut used to automatically disable Radio after end of PDU.
212  */
213 #define NRF_RADIO_SHORTS_TRX_END_DISABLE_Msk HAL_RADIO_SHORTS_TRX_END_DISABLE_Msk
214 #endif /* !CONFIG_BT_CTLR_DF */
215 
216 #define HAL_EVENT_TIMER_TRX_CC_OFFSET          0
217 #define HAL_EVENT_TIMER_TRX_EVENT              NRF_TIMER_EVENT_COMPARE0
218 #define HAL_EVENT_TIMER_READY_TASK             NRF_TIMER_TASK_CAPTURE0
219 
220 #define HAL_EVENT_TIMER_HCTO_CC_OFFSET         1
221 #define HAL_EVENT_TIMER_HCTO_EVENT             NRF_TIMER_EVENT_COMPARE1
222 #define HAL_EVENT_TIMER_ADDRESS_TASK           NRF_TIMER_TASK_CAPTURE1
223 
224 #define HAL_EVENT_TIMER_TRX_END_CC_OFFSET      2
225 #define HAL_EVENT_TIMER_TRX_END_TASK           NRF_TIMER_TASK_CAPTURE2
226 
227 #define HAL_EVENT_TIMER_DEFERRED_TRX_CC_OFFSET 2
228 #define HAL_EVENT_TIMER_DEFERRED_TX_EVENT      NRF_TIMER_EVENT_COMPARE2
229 
230 #define HAL_EVENT_TIMER_SAMPLE_CC_OFFSET       3
231 #define HAL_EVENT_TIMER_SAMPLE_TASK            NRF_TIMER_TASK_CAPTURE3
232 
233 #define HAL_EVENT_TIMER_PA_LNA_CC_OFFSET       2
234 #define HAL_EVENT_TIMER_PA_LNA_PDN_CC_OFFSET   3
235 #endif /* !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */
236 #endif /* !CONFIG_BT_CTLR_TIFS_HW */
237