1 /*
2 * Copyright (c) 2021 - 2025, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef NRFX_GRTC_H__
35 #define NRFX_GRTC_H__
36
37 #include <nrfx.h>
38 #include <haly/nrfy_grtc.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45 * @defgroup nrfx_grtc GRTC driver
46 * @{
47 * @ingroup nrf_grtc
48 * @brief Global Real Timer Counter (GRTC) peripheral driver.
49 */
50
51 /**
52 * @brief GRTC driver instance compare handler type.
53 *
54 * @param[in] id Channel ID.
55 * @param[in] cc_value Compare value.
56 * @param[in] p_context User context.
57 */
58 typedef void (*nrfx_grtc_cc_handler_t)(int32_t id, uint64_t cc_value, void * p_context);
59
60 #if NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
61 /**
62 * @brief GRTC driver instance SYSCOUNTER valid handler type.
63 *
64 * @param[in] p_context User context.
65 */
66 typedef void (*nrfx_grtc_syscountervalid_handler_t)(void * p_context);
67 #endif //NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
68
69 #if NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
70 /**
71 * @brief GRTC driver instance RTCOMPARESYNC handler type.
72 *
73 * @param[in] p_context User context.
74 */
75 typedef void (*nrfx_grtc_rtcomparesync_handler_t)(void * p_context);
76 #endif // NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
77
78 /** @brief GRTC capture/compare channel description structure. */
79 typedef struct
80 {
81 nrfx_grtc_cc_handler_t handler; /**< User handler. */
82 void * p_context; /**< User context. */
83 uint8_t channel; /**< Capture/compare channel number. */
84 } nrfx_grtc_channel_t;
85
86 #if NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
87 /** @brief GRTC RTCOUNTER handler data structure. */
88 typedef struct
89 {
90 nrfx_grtc_cc_handler_t handler; /**< User handler. */
91 void * p_context; /**< User context. */
92 } nrfx_grtc_rtcounter_handler_data_t;
93 #endif // NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
94
95 #if NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
96 /** @brief GRTC action types. */
97 typedef enum
98 {
99 NRFX_GRTC_ACTION_START = NRF_GRTC_TASK_START, /**< Start the GRTC. */
100 NRFX_GRTC_ACTION_STOP = NRF_GRTC_TASK_STOP, /**< Stop the GRTC. */
101 NRFX_GRTC_ACTION_CLEAR = NRF_GRTC_TASK_CLEAR, /**< Clear the GRTC. */
102 } nrfx_grtc_action_t;
103
104 /** @brief GRTC SYSCOUNTER sleep configuration structure. */
105 typedef struct
106 {
107 uint32_t timeout; /**< Delay in LFCLK cycles after the condition allowing SYSCOUNTER to go to sleep is met. */
108 uint32_t waketime; /**< Number of LFCLK cycles to wakeup the SYSCOUNTER before the wake-up event occured. */
109 bool auto_mode; /**< Enable automatic mode, which keeps the SYSCOUNTER active when any of the local CPUs is active. */
110 } nrfx_grtc_sleep_config_t;
111
112 /**
113 * @brief GRTC sleep default configuration.
114 *
115 * This configuration sets up GRTC with the following options:
116 * - sleep timeout: 5 LFCLK cycles
117 * - wake time: 4 LFCLK cycles
118 * - automatic mode: true
119 */
120 #define NRFX_GRTC_SLEEP_DEFAULT_CONFIG \
121 { \
122 .timeout = 5, \
123 .waketime = 4, \
124 .auto_mode = true \
125 }
126 #endif // NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
127
128 /** @brief GRTC compare event relative references. */
129 typedef enum
130 {
131 NRFX_GRTC_CC_RELATIVE_SYSCOUNTER = NRF_GRTC_CC_ADD_REFERENCE_SYSCOUNTER, /**< The SYSCOUNTER content will be used as the reference. */
132 NRFX_GRTC_CC_RELATIVE_COMPARE = NRF_GRTC_CC_ADD_REFERENCE_CC, /**< The corresponding compare register content will be used as the reference. */
133 } nrfx_grtc_cc_relative_reference_t;
134
135 #if NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
136 /**
137 * @brief Function for configuring the SYSCOUNTER sleep feature.
138 *
139 * @param[in] p_sleep_cfg Pointer to the configuration sleep structure.
140 *
141 * @retval NRFX_SUCCESS The procedure was successful.
142 * @retval NRFX_ERROR_NOT_SUPPORTED The sleep feature is not supported.
143 */
144 nrfx_err_t nrfx_grtc_sleep_configure(nrfx_grtc_sleep_config_t const * p_sleep_cfg);
145
146 /**
147 * @brief Function for getting the SYSCOUNTER sleep configuration.
148 *
149 * @param[out] p_sleep_cfg Pointer to the structure to be filled with sleep configuration.
150 *
151 * @retval NRFX_SUCCESS The procedure was successful.
152 * @retval NRFX_ERROR_NOT_SUPPORTED The sleep feature is not supported.
153 */
154 nrfx_err_t nrfx_grtc_sleep_configuration_get(nrfx_grtc_sleep_config_t * p_sleep_cfg);
155 #endif // NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
156
157 /**
158 * @brief Function for allocating the GRTC capture/compare channel.
159 *
160 * @note Function is thread safe as it uses @ref nrfx_flag32_alloc.
161 * @note Routines that allocate and free the GRTC channels are independent
162 * from the rest of the driver. In particular, the driver does not need
163 * to be initialized when this function is called.
164 *
165 * @param[out] p_channel Pointer to the capture/compare channel.
166 *
167 * @retval NRFX_SUCCESS Allocation was successful.
168 * @retval NRFX_ERROR_NO_MEM No resource available.
169 */
170 nrfx_err_t nrfx_grtc_channel_alloc(uint8_t * p_channel);
171
172 /**
173 * @brief Function for freeing the GRTC capture/compare channel.
174 *
175 * @note Function is thread safe as it uses @ref nrfx_flag32_free.
176 * @note Routines that allocate and free the GRTC channels are independent
177 * from the rest of the driver. In particular, the driver does not need
178 * to be initialized when this function is called.
179 * @note This function also mark specified channel as unused by the driver.
180 *
181 * @param[in] channel Allocated channel to be freed.
182 *
183 * @retval NRFX_SUCCESS Allocation was successful.
184 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
185 * @retval NRFX_ERROR_INVALID_PARAM Channel is not allocated.
186 */
187 nrfx_err_t nrfx_grtc_channel_free(uint8_t channel);
188
189 /**
190 * @brief Function for checking whether the specified channel is used by the driver.
191 *
192 * @note Channels marked as used cannot be utilized by external API.
193 *
194 * @param[in] channel Channel to be checked.
195 *
196 * @retval true Channel is used by the driver.
197 * @retval false Channel is not used by the driver.
198 */
199 bool nrfx_grtc_is_channel_used(uint8_t channel);
200
201 /**
202 * @brief Function for initializing the GRTC.
203 *
204 * @param[in] interrupt_priority Interrupt priority.
205 *
206 * @retval NRFX_SUCCESS Initialization was successful.
207 * @retval NRFX_ERROR_ALREADY The driver is already initialized.
208 * @retval NRFX_ERROR_INVALID_STATE The driver is already initialized.
209 * Deprecated - use @ref NRFX_ERROR_ALREADY instead.
210 * @retval NRFX_ERROR_INTERNAL No valid channel configuration provided.
211 */
212 nrfx_err_t nrfx_grtc_init(uint8_t interrupt_priority);
213
214 #if NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
215 /**
216 * @brief Function for disabling the RTCOUNTER CC channel.
217 *
218 * @retval NRFX_SUCCESS The procedure was successful.
219 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is running and the operation is not allowed.
220 * @retval NRFX_ERROR_TIMEOUT RTCOUNTER compare interrupt is pending.
221 */
222 nrfx_err_t nrfx_grtc_rtcounter_cc_disable(void);
223
224 /**
225 * @brief Function for enabling the RTCOMPARESYNC interrupt.
226 *
227 * @param[in] handler Handler provided by the user. May be NULL.
228 * @param[in] p_context User context.
229 */
230 void nrfx_grtc_rtcomparesync_int_enable(nrfx_grtc_rtcomparesync_handler_t handler,
231 void * p_context);
232
233 /** @brief Function for disabling the RTCOMPARESYNC interrupt. */
234 void nrfx_grtc_rtcomparesync_int_disable(void);
235
236 /**
237 * @brief Function for setting the absolute compare value for the RTCOUNTER.
238 *
239 * @param[in] handler_data Pointer to the handler data instance structure.
240 * @param[in] val Absolute value to be set in the compare register.
241 * @param[in] enable_irq True if interrupt is to be enabled, false otherwise.
242 * @param[in] sync True if the internal synchronization mechanism shall be used,
243 * false otherwise.
244 *
245 * @retval NRFX_SUCCESS The procedure was successful.
246 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is running and the operation is not allowed.
247 */
248 nrfx_err_t nrfx_grtc_rtcounter_cc_absolute_set(nrfx_grtc_rtcounter_handler_data_t * handler_data,
249 uint64_t val,
250 bool enable_irq,
251 bool sync);
252
253 /**
254 * @brief Function for enabling the RTCOUNTER compare interrupt.
255 *
256 * @param[in] sync True if the internal synchronization mechanism shall be used,
257 * false otherwise.
258 */
259 void nrfx_grtc_rtcounter_cc_int_enable(bool sync);
260
261 /** @brief Function for disabling the RTCOUNTER compare interrupt. */
262 void nrfx_grtc_rtcounter_cc_int_disable(void);
263 #endif // NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
264
265 #if NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
266 #if NRFY_GRTC_HAS_SYSCOUNTERVALID || defined(__NRFX_DOXYGEN__)
267 /**
268 * @brief Function for enabling the SYSCOUNTERVALID interrupt.
269 *
270 * @param[in] handler Handler provided by the user. May be NULL.
271 * @param[in] p_context User context.
272 */
273 void nrfx_grtc_syscountervalid_int_enable(nrfx_grtc_syscountervalid_handler_t handler,
274 void * p_context);
275
276 /** @brief Function for disabling the SYSCOUNTERVALID interrupt. */
277 void nrfx_grtc_syscountervalid_int_disable(void);
278 #endif // NRFY_GRTC_HAS_SYSCOUNTERVALID || defined(__NRFX_DOXYGEN__)
279
280 /**
281 * @brief Function for starting the 1 MHz SYSCOUNTER.
282 *
283 * @note This function automatically allocates and marks as used the special-purpose main
284 * capture/compare channel. It is available only for GRTC manager.
285 *
286 * @note Use auxiliary structure of type @ref nrfx_grtc_channel_t when working with SYSCOUNTER.
287 *
288 * @param[in] busy_wait True if wait for synchronization operation is to be performed,
289 * false otherwise.
290 * @param[out] p_main_cc_channel Pointer to the main capture/compare channel.
291 *
292 * @retval NRFX_SUCCESS Starting was successful.
293 * @retval NRFX_ERROR_NO_MEM No resource available to allocate main channel.
294 * @retval NRFX_ERROR_ALREADY The GRTC is already running.
295 * @retval NRFX_ERROR_TIMEOUT The SYSCOUNTER failed to start due to a timeout.
296 */
297
298 nrfx_err_t nrfx_grtc_syscounter_start(bool busy_wait, uint8_t * p_main_cc_channel);
299
300 /**
301 * @brief Function for performing an action for the GRTC.
302 *
303 * @param[in] action Action to be performed.
304 *
305 * @retval NRFX_SUCCESS Starting was successful.
306 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is running and the operation is not allowed.
307 */
308 nrfx_err_t nrfx_grtc_action_perform(nrfx_grtc_action_t action);
309 #endif // NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__)
310
311 /**
312 * @brief Function for uninitializing the GRTC.
313 *
314 * @note This function automatically frees all channels used by the driver.
315 * It also marks these channels as unused
316 */
317 void nrfx_grtc_uninit(void);
318
319 /**
320 * @brief Function for checking if the GRTC driver is initialized.
321 *
322 * @retval true Driver is already initialized.
323 * @retval false Driver is not initialized.
324 */
325 bool nrfx_grtc_init_check(void);
326
327 /**
328 * @brief Function for disabling the SYSCOUNTER CC channel.
329 *
330 * @note This function marks the specified @p channel as unused.
331 *
332 * @param[in] channel Channel to be disabled.
333 *
334 * @retval NRFX_SUCCESS The procedure was successful.
335 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
336 * @retval NRFX_ERROR_INVALID_PARAM The specified @p channel is either not allocated or
337 * marked as unused.
338 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
339 * @retval NRFX_ERROR_TIMEOUT SYSCOUNTER compare interrupt is pending on the requested
340 * channel.
341 */
342 nrfx_err_t nrfx_grtc_syscounter_cc_disable(uint8_t channel);
343
344 /**
345 * @brief Function for setting the absolute compare value for the SYSCOUNTER.
346 *
347 * @note This function marks the specified @p channel as used.
348 *
349 * @param[in] p_chan_data Pointer to the channel data instance structure.
350 * @param[in] val Absolute value to be set in the compare register.
351 * @param[in] enable_irq True if interrupt is to be enabled, false otherwise.
352 *
353 * @retval NRFX_SUCCESS The procedure was successful.
354 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
355 * @retval NRFX_ERROR_INVALID_PARAM Channel is not allocated.
356 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
357 */
358 nrfx_err_t nrfx_grtc_syscounter_cc_absolute_set(nrfx_grtc_channel_t * p_chan_data,
359 uint64_t val,
360 bool enable_irq);
361
362 /**
363 * @brief Function for setting the relative compare value for the SYSCOUNTER.
364 *
365 * @note This function marks the specified @p channel as used.
366 *
367 * @param[in] p_chan_data Pointer to the channel data instance structure.
368 * @param[in] val Relative value to be set in the compare register.
369 * @param[in] enable_irq True if interrupt is to be enabled, false otherwise.
370 * @param[in] reference Reference type to be used.
371 *
372 * @retval NRFX_SUCCESS The procedure was successful.
373 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
374 * @retval NRFX_ERROR_INVALID_PARAM Channel is not allocated.
375 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
376 */
377 nrfx_err_t nrfx_grtc_syscounter_cc_relative_set(nrfx_grtc_channel_t * p_chan_data,
378 uint32_t val,
379 bool enable_irq,
380 nrfx_grtc_cc_relative_reference_t reference);
381
382 /**
383 * @brief Function for disabling the SYSCOUNTER compare interrupt.
384 *
385 * @param[in] channel Compare channel number.
386 *
387 * @retval NRFX_SUCCESS The procedure was successful.
388 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
389 * @retval NRFX_ERROR_INVALID_PARAM The specified @p channel is either not allocated or
390 * marked as unused.
391 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
392 */
393 nrfx_err_t nrfx_grtc_syscounter_cc_int_disable(uint8_t channel);
394
395 /**
396 * @brief Function for enabling the SYSCOUNTER compare interrupt.
397 *
398 * @note This function marks the specified @p channel as used.
399 *
400 * @param[in] channel Compare channel number.
401 *
402 * @retval NRFX_SUCCESS The procedure was successful.
403 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
404 * @retval NRFX_ERROR_INVALID_PARAM Channel is not allocated.
405 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
406 */
407 nrfx_err_t nrfx_grtc_syscounter_cc_int_enable(uint8_t channel);
408
409 /**
410 * @brief Function for checking whether the SYSCOUNTER compare interrupt is enabled for
411 * the specified channel.
412 *
413 * @param[in] channel Compare channel number.
414 *
415 * @retval true The interrupt is enabled for the specified channel.
416 * @retval false The interrupt is disabled for the specified channel.
417 */
418 bool nrfx_grtc_syscounter_cc_int_enable_check(uint8_t channel);
419
420 /**
421 * @brief Function for triggering the SYSCOUNTER capture task
422 *
423 * @note This function marks the specified @p channel as used.
424 *
425 * @param[in] channel Capture channel number.
426 *
427 * @retval NRFX_SUCCESS The procedure was successful.
428 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
429 * @retval NRFX_ERROR_INVALID_PARAM Channel is not allocated.
430 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
431 */
432 nrfx_err_t nrfx_grtc_syscounter_capture(uint8_t channel);
433
434 /**
435 * @brief Function for reading the GRTC capture/compare register for the specified @p channel.
436 *
437 * @param[in] channel Capture channel number.
438 * @param[out] p_val Pointer to the variable where the result is to be stored.
439 *
440 * @retval NRFX_SUCCESS The procedure was successful.
441 * @retval NRFX_ERROR_FORBIDDEN The domain is not allowed to use specified @p channel.
442 * @retval NRFX_ERROR_INVALID_PARAM The specified @p channel is either not allocated or
443 * marked as unused.
444 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
445 */
446 nrfx_err_t nrfx_grtc_syscounter_cc_value_read(uint8_t channel, uint64_t * p_val);
447
448
449 /**
450 * @brief Function for checking whether the SYSCOUNTER is in ready state.
451 *
452 * @note When the SYSCOUNTER is not ready its value may be corrupted.
453 *
454 * @retval true The SYSCOUNTER is in ready state.
455 * @retval false The SYSCOUNTER is not in ready state.
456 */
457 bool nrfx_grtc_ready_check(void);
458
459 /**
460 * @brief Function for checking the current request for the SYSCOUNTER state.
461 *
462 * @retval true The SYSCOUNTER is requested to be enabled.
463 * @retval false The SYSCOUNTER is requested to be disabled.
464 */
465 bool nrfx_grtc_active_request_check(void);
466
467 /**
468 * @brief Function for requesting the SYSCOUNTER state.
469 *
470 * @note By using this function any domain can prevent SYSCOUNTER from going to sleep state.
471 *
472 * @param[in] active True if SYSCOUNTER is to be always kept active, false otherwise.
473 */
474 void nrfx_grtc_active_request_set(bool active);
475
476 /**
477 * @brief Function for reading the GRTC SYSCOUNTER value.
478 *
479 * @param[out] p_counter p_counter Pointer to the variable to be filled with the SYSCOUNTER value.
480 *
481 * @retval NRFX_SUCCESS The procedure was successful.
482 * @retval NRFX_ERROR_INTERNAL The SYSCOUNTER (1 MHz) is not running.
483 */
484 nrfx_err_t nrfx_grtc_syscounter_get(uint64_t * p_counter);
485
486 /**
487 * @brief Function for retrieving the address of the specified GRTC task.
488 *
489 * @param[in] task GRTC task.
490 *
491 * @return Task address.
492 */
493 NRFX_STATIC_INLINE uint32_t nrfx_grtc_task_address_get(nrf_grtc_task_t task);
494
495 /**
496 * @brief Function for retrieving the address of the specified GRTC event.
497 *
498 * @param[in] event GRTC event.
499 *
500 * @return Event address.
501 */
502 NRFX_STATIC_INLINE uint32_t nrfx_grtc_event_address_get(nrf_grtc_event_t event);
503
504 /**
505 * @brief Function for retrieving the address of the capture task for the specified channel.
506 *
507 * @param[in] channel Capture channel number.
508 *
509 * @return Task address.
510 */
511 NRFX_STATIC_INLINE uint32_t nrfx_grtc_capture_task_address_get(uint8_t channel);
512
513 /**
514 * @brief Function for retrieving the address of the capture task for the specified channel.
515 *
516 * @param[in] channel Compare channel number.
517 *
518 * @return Event address.
519 */
520 NRFX_STATIC_INLINE uint32_t nrfx_grtc_event_compare_address_get(uint8_t channel);
521
522 /**
523 * @brief Function for checking whether the specified capture/compare channel is enabled.
524 *
525 * @param[in] channel Channel to be checked.
526 *
527 * @retval true Channel is enabled.
528 * @retval false Channel is disabled.
529 */
530 NRFX_STATIC_INLINE bool nrfx_grtc_sys_counter_cc_enable_check(uint8_t channel);
531
532 /**
533 * @brief Function for retrieving the state of the compare GRTC event.
534 *
535 * @param[in] channel Compare channel of the corresponding event to be checked.
536 *
537 * @retval true The event has been generated.
538 * @retval false The event has not been generated.
539 */
540 NRFX_STATIC_INLINE bool nrfx_grtc_syscounter_compare_event_check(uint8_t channel);
541
542 #if NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
543 /**
544 * @brief Function for reading the GRTC RTCOUNTER value.
545 *
546 * @return RTCOUNTER (32 kHz) value.
547 */
548 NRFX_STATIC_INLINE uint64_t nrfx_grtc_rtcounter_get(void);
549 #endif // NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__)
550
551 #if NRFY_GRTC_HAS_CLKSEL || defined(__NRFX_DOXYGEN__)
552 /**
553 * @brief Function for setting the clock source for the GRTC low-frequency clock.
554 *
555 * @param[in] clk_src Selected clock source.
556 */
557 NRFX_STATIC_INLINE void nrfx_grtc_clock_source_set(nrf_grtc_clksel_t clk_src);
558 #endif // NRFY_GRTC_HAS_CLKSEL
559
560 #ifndef NRFX_DECLARE_ONLY
561
nrfx_grtc_task_address_get(nrf_grtc_task_t task)562 NRFX_STATIC_INLINE uint32_t nrfx_grtc_task_address_get(nrf_grtc_task_t task)
563 {
564 return nrfy_grtc_task_address_get(NRF_GRTC, task);
565 }
566
nrfx_grtc_event_address_get(nrf_grtc_event_t event)567 NRFX_STATIC_INLINE uint32_t nrfx_grtc_event_address_get(nrf_grtc_event_t event)
568 {
569 return nrfy_grtc_event_address_get(NRF_GRTC, event);
570 }
571
nrfx_grtc_capture_task_address_get(uint8_t channel)572 NRFX_STATIC_INLINE uint32_t nrfx_grtc_capture_task_address_get(uint8_t channel)
573 {
574 return nrfy_grtc_task_address_get(NRF_GRTC, nrfy_grtc_sys_counter_capture_task_get(channel));
575 }
576
nrfx_grtc_event_compare_address_get(uint8_t channel)577 NRFX_STATIC_INLINE uint32_t nrfx_grtc_event_compare_address_get(uint8_t channel)
578 {
579 return nrfy_grtc_event_address_get(NRF_GRTC, nrfy_grtc_sys_counter_compare_event_get(channel));
580 }
581
nrfx_grtc_sys_counter_cc_enable_check(uint8_t channel)582 NRFX_STATIC_INLINE bool nrfx_grtc_sys_counter_cc_enable_check(uint8_t channel)
583 {
584 NRFX_ASSERT(channel < NRF_GRTC_SYSCOUNTER_CC_COUNT);
585 return nrfy_grtc_sys_counter_cc_enable_check(NRF_GRTC, channel);
586 }
587
nrfx_grtc_syscounter_compare_event_check(uint8_t channel)588 NRFX_STATIC_INLINE bool nrfx_grtc_syscounter_compare_event_check(uint8_t channel)
589 {
590 return nrfy_grtc_sys_counter_compare_event_check(NRF_GRTC, channel);
591 }
592
593 #if NRF_GRTC_HAS_RTCOUNTER
nrfx_grtc_rtcounter_get(void)594 NRFX_STATIC_INLINE uint64_t nrfx_grtc_rtcounter_get(void)
595 {
596 return nrfy_grtc_rt_counter_get(NRF_GRTC);
597 }
598 #endif // NRF_GRTC_HAS_RTCOUNTER
599
600 #if NRFY_GRTC_HAS_CLKSEL
nrfx_grtc_clock_source_set(nrf_grtc_clksel_t clk_src)601 NRFX_STATIC_INLINE void nrfx_grtc_clock_source_set(nrf_grtc_clksel_t clk_src)
602 {
603 nrfy_grtc_clksel_set(NRF_GRTC, clk_src);
604 }
605 #endif // NRFY_GRTC_HAS_CLKSEL
606 #endif // NRFX_DECLARE_ONLY
607
608 /** @} */
609
610 void nrfx_grtc_irq_handler(void);
611
612 #ifdef __cplusplus
613 }
614 #endif
615
616 #endif // NRFX_GRTC_H__
617