1 /*
2  * Copyright (c) 2017 Oticon A/S
3  * Copyright (c) 2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * This file includes the RADIO event & signals functionality
8  * That is, when a signal is generated:
9  *   Setting the EVENTS registers
10  *   Sending the signal to the PPI
11  *   Generating the corresponding interrupts
12  *   Calling tasks if the corresponding shortcuts are enabled
13  *
14  * There should not be any logic beyond that here.
15  */
16 
17 #include "NRF_RADIO.h"
18 #include "NRF_PPI.h"
19 #include "irq_ctrl.h"
20 #include "bs_tracing.h"
21 
22 extern uint32_t NRF_RADIO_INTEN; //interrupt enable
23 extern void nrf_radio_fake_task_TRXEN_TIFS();
24 
nrf_radio_signal_READY()25 void nrf_radio_signal_READY(){
26   NRF_RADIO_regs.EVENTS_READY = 1;
27   nrf_ppi_event(RADIO_EVENTS_READY);
28 
29   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_READY_START_Msk ) {
30     nrf_radio_tasks_START();
31   }
32   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_READY_EDSTART_Msk ) {
33     nrf_radio_tasks_EDSTART();
34   }
35 
36   if ( NRF_RADIO_INTEN & RADIO_INTENSET_READY_Msk ){
37     hw_irq_ctrl_set_irq(RADIO_IRQn);
38   }
39 }
40 
nrf_radio_signal_ADDRESS()41 void nrf_radio_signal_ADDRESS(){
42   NRF_RADIO_regs.EVENTS_ADDRESS = 1;
43   nrf_ppi_event(RADIO_EVENTS_ADDRESS);
44 
45   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_ADDRESS_RSSISTART_Msk ) {
46     nrf_radio_tasks_RSSISTART();
47   }
48   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_ADDRESS_BCSTART_Msk ) {
49     nrf_radio_tasks_BCSTART();
50   }
51 
52   if ( NRF_RADIO_INTEN & RADIO_INTENSET_ADDRESS_Msk ){
53     hw_irq_ctrl_set_irq(RADIO_IRQn);
54   }
55 }
56 
nrf_radio_signal_PAYLOAD()57 void nrf_radio_signal_PAYLOAD(){
58   NRF_RADIO_regs.EVENTS_PAYLOAD = 1;
59   nrf_ppi_event(RADIO_EVENTS_PAYLOAD);
60 
61   if ( NRF_RADIO_INTEN & RADIO_INTENSET_PAYLOAD_Msk ){
62     hw_irq_ctrl_set_irq(RADIO_IRQn);
63   }
64 }
65 
nrf_radio_signal_END()66 void nrf_radio_signal_END(){
67   NRF_RADIO_regs.EVENTS_END = 1;
68   nrf_ppi_event(RADIO_EVENTS_END);
69 
70   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_END_DISABLE_Msk ) {
71     nrf_radio_tasks_DISABLE();
72   }
73   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_END_START_Msk ) {
74     nrf_radio_tasks_START();
75   }
76 
77   if ( NRF_RADIO_INTEN & RADIO_INTENSET_END_Msk ) {
78     hw_irq_ctrl_set_irq(RADIO_IRQn);
79   }
80 }
81 
nrf_radio_signal_DISABLED()82 void nrf_radio_signal_DISABLED(){
83   NRF_RADIO_regs.EVENTS_DISABLED = 1;
84   nrf_ppi_event(RADIO_EVENTS_DISABLED);
85 
86   //These 2 are fake shortcuts meant to start a HW timer for the TIFS
87   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_DISABLED_TXEN_Msk ) {
88     nrf_radio_fake_task_TRXEN_TIFS();
89   }
90   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_DISABLED_RXEN_Msk ) {
91     nrf_radio_fake_task_TRXEN_TIFS();
92   }
93 
94   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_DISABLED_RSSISTOP_Msk ) {
95     nrf_radio_tasks_RSSISTOP();
96   }
97 
98   if ( NRF_RADIO_INTEN & RADIO_INTENSET_DISABLED_Msk ) {
99     hw_irq_ctrl_set_irq(RADIO_IRQn);
100   }
101 }
102 
nrf_radio_signal_DEVMATCH()103 void nrf_radio_signal_DEVMATCH() {
104   NRF_RADIO_regs.EVENTS_DEVMATCH = 1;
105   nrf_ppi_event(RADIO_EVENTS_DEVMATCH);
106 
107   if (NRF_RADIO_INTEN & RADIO_INTENSET_DEVMATCH_Msk) {
108     hw_irq_ctrl_set_irq(RADIO_IRQn);
109   }
110 }
111 
nrf_radio_signal_DEVMISS()112 void nrf_radio_signal_DEVMISS() {
113   NRF_RADIO_regs.EVENTS_DEVMISS = 1;
114   nrf_ppi_event(RADIO_EVENTS_DEVMISS);
115 
116   if (NRF_RADIO_INTEN & RADIO_INTENSET_DEVMISS_Msk) {
117     hw_irq_ctrl_set_irq(RADIO_IRQn);
118   }
119 }
120 
nrf_radio_signal_RSSIEND()121 void nrf_radio_signal_RSSIEND(){
122   NRF_RADIO_regs.EVENTS_RSSIEND = 1;
123   nrf_ppi_event(RADIO_EVENTS_RSSIEND);
124 
125   if ( NRF_RADIO_INTEN & RADIO_INTENSET_RSSIEND_Msk ){
126     hw_irq_ctrl_set_irq(RADIO_IRQn);
127   }
128 }
129 
nrf_radio_signal_BCMATCH()130 void nrf_radio_signal_BCMATCH() {
131   NRF_RADIO_regs.EVENTS_BCMATCH = 1;
132   nrf_ppi_event(RADIO_EVENTS_BCMATCH);
133 
134   if (NRF_RADIO_INTEN & RADIO_INTENSET_BCMATCH_Msk) {
135     hw_irq_ctrl_set_irq(RADIO_IRQn);
136   }
137 }
138 
nrf_radio_signal_CRCOK()139 void nrf_radio_signal_CRCOK(){
140   NRF_RADIO_regs.EVENTS_CRCOK = 1;
141   nrf_ppi_event(RADIO_EVENTS_CRCOK);
142 
143   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CRCOK_Msk ) {
144     hw_irq_ctrl_set_irq(RADIO_IRQn);
145   }
146 }
147 
nrf_radio_signal_CRCERROR()148 void nrf_radio_signal_CRCERROR(){
149   NRF_RADIO_regs.EVENTS_CRCERROR = 1;
150   nrf_ppi_event(RADIO_EVENTS_CRCERROR);
151 
152   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CRCERROR_Msk ) {
153     hw_irq_ctrl_set_irq(RADIO_IRQn);
154   }
155 }
156 
nrf_radio_signal_FRAMESTART()157 void nrf_radio_signal_FRAMESTART(){
158   NRF_RADIO_regs.EVENTS_FRAMESTART = 1;
159   nrf_ppi_event(RADIO_EVENTS_FRAMESTART);
160 
161   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_FRAMESTART_BCSTART_Msk ) {
162     nrf_radio_tasks_BCSTART();
163   }
164 
165   if ( NRF_RADIO_INTEN & RADIO_INTENSET_FRAMESTART_Msk ) {
166     hw_irq_ctrl_set_irq(RADIO_IRQn);
167   }
168 }
169 
nrf_radio_signal_EDEND()170 void nrf_radio_signal_EDEND(){
171   NRF_RADIO_regs.EVENTS_EDEND = 1;
172   nrf_ppi_event(RADIO_EVENTS_EDEND);
173 
174   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_EDEND_DISABLE_Msk ) {
175     nrf_radio_tasks_DISABLE();
176   }
177 
178   if ( NRF_RADIO_INTEN & RADIO_INTENSET_EDEND_Msk ) {
179     hw_irq_ctrl_set_irq(RADIO_IRQn);
180   }
181 }
182 
nrf_radio_signal_EDSTOPPED()183 void nrf_radio_signal_EDSTOPPED(){
184   NRF_RADIO_regs.EVENTS_EDSTOPPED = 1;
185   nrf_ppi_event(RADIO_EVENTS_EDSTOPPED);
186 
187   if ( NRF_RADIO_INTEN & RADIO_INTENSET_EDSTOPPED_Msk ) {
188     hw_irq_ctrl_set_irq(RADIO_IRQn);
189   }
190 }
191 
nrf_radio_signal_CCAIDLE()192 void nrf_radio_signal_CCAIDLE(){
193   NRF_RADIO_regs.EVENTS_CCAIDLE = 1;
194   nrf_ppi_event(RADIO_EVENTS_CCAIDLE);
195 
196   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_CCAIDLE_STOP_Msk ) {
197     nrf_radio_tasks_STOP();
198   }
199   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_CCAIDLE_TXEN_Msk ) {
200     nrf_radio_tasks_TXEN();
201   }
202 
203   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CCAIDLE_Msk ) {
204     hw_irq_ctrl_set_irq(RADIO_IRQn);
205   }
206 }
207 
nrf_radio_signal_CCABUSY()208 void nrf_radio_signal_CCABUSY(){
209   NRF_RADIO_regs.EVENTS_CCABUSY = 1;
210   nrf_ppi_event(RADIO_EVENTS_CCABUSY);
211 
212   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_CCABUSY_DISABLE_Msk ) {
213     nrf_radio_tasks_DISABLE();
214   }
215 
216   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CCABUSY_Msk ) {
217     hw_irq_ctrl_set_irq(RADIO_IRQn);
218   }
219 }
220 
nrf_radio_signal_CCASTOPPED()221 void nrf_radio_signal_CCASTOPPED(){
222   NRF_RADIO_regs.EVENTS_CCASTOPPED = 1;
223   nrf_ppi_event(RADIO_EVENTS_CCASTOPPED);
224 
225   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CCASTOPPED_Msk ) {
226     hw_irq_ctrl_set_irq(RADIO_IRQn);
227   }
228 }
229 
nrf_radio_signal_RATEBOOST()230 void nrf_radio_signal_RATEBOOST(){
231   NRF_RADIO_regs.EVENTS_RATEBOOST = 1;
232   nrf_ppi_event(RADIO_EVENTS_RATEBOOST);
233 
234   if ( NRF_RADIO_INTEN & RADIO_INTENSET_RATEBOOST_Msk ) {
235     hw_irq_ctrl_set_irq(RADIO_IRQn);
236   }
237 }
238 
nrf_radio_signal_TXREADY()239 void nrf_radio_signal_TXREADY(){
240   NRF_RADIO_regs.EVENTS_TXREADY = 1;
241   nrf_ppi_event(RADIO_EVENTS_TXREADY);
242 
243   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_TXREADY_START_Msk ) {
244     nrf_radio_tasks_START();
245   }
246 
247   if ( NRF_RADIO_INTEN & RADIO_INTENSET_TXREADY_Msk ){
248     hw_irq_ctrl_set_irq(RADIO_IRQn);
249   }
250 }
251 
nrf_radio_signal_RXREADY()252 void nrf_radio_signal_RXREADY(){
253   NRF_RADIO_regs.EVENTS_RXREADY = 1;
254   nrf_ppi_event(RADIO_EVENTS_RXREADY);
255 
256   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_RXREADY_START_Msk ) {
257     nrf_radio_tasks_START();
258   }
259   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_RXREADY_CCASTART_Msk ) {
260     nrf_radio_tasks_CCASTART();
261   }
262 
263   if ( NRF_RADIO_INTEN & RADIO_INTENSET_RXREADY_Msk ){
264     hw_irq_ctrl_set_irq(RADIO_IRQn);
265   }
266 }
267 
nrf_radio_signal_MHRMATCH()268 void nrf_radio_signal_MHRMATCH(){
269   NRF_RADIO_regs.EVENTS_MHRMATCH = 1;
270   nrf_ppi_event(RADIO_EVENTS_MHRMATCH);
271 
272   if ( NRF_RADIO_INTEN & RADIO_INTENSET_MHRMATCH_Msk ){
273     hw_irq_ctrl_set_irq(RADIO_IRQn);
274   }
275 }
276 
nrf_radio_signal_SYNC()277 void nrf_radio_signal_SYNC() {
278   NRF_RADIO_regs.EVENTS_SYNC = 1;
279   nrf_ppi_event(RADIO_EVENTS_SYNC);
280 
281   if (NRF_RADIO_INTEN & RADIO_INTENSET_SYNC_Msk) {
282     hw_irq_ctrl_set_irq(RADIO_IRQn);
283   }
284 }
285 
nrf_radio_signal_PHYEND()286 void nrf_radio_signal_PHYEND(){
287   NRF_RADIO_regs.EVENTS_PHYEND = 1;
288   nrf_ppi_event(RADIO_EVENTS_PHYEND);
289 
290   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_PHYEND_DISABLE_Msk ) {
291     nrf_radio_tasks_DISABLE();
292   }
293   if ( NRF_RADIO_regs.SHORTS & RADIO_SHORTS_PHYEND_START_Msk ) {
294     nrf_radio_tasks_START();
295   }
296 
297   if ( NRF_RADIO_INTEN & RADIO_INTENSET_PHYEND_Msk ) {
298     hw_irq_ctrl_set_irq(RADIO_IRQn);
299   }
300 }
301 
nrf_radio_signal_CTEPRESENT()302 void nrf_radio_signal_CTEPRESENT(){
303   NRF_RADIO_regs.EVENTS_CTEPRESENT = 1;
304   nrf_ppi_event(RADIO_EVENTS_CTEPRESENT);
305 
306   if ( NRF_RADIO_INTEN & RADIO_INTENSET_CTEPRESENT_Msk ) {
307     hw_irq_ctrl_set_irq(RADIO_IRQn);
308   }
309 }
310