@@ -52,10 +52,9 @@ extern "C" {
52
52
* @brief GRTC driver instance compare handler type.
53
53
*
54
54
* @param[in] id Channel ID.
55
- * @param[in] cc_value Compare value.
56
55
* @param[in] p_context User context.
57
56
*/
58
- typedef void (* nrfx_grtc_cc_handler_t )(int32_t id , uint64_t cc_value , void * p_context );
57
+ typedef void (* nrfx_grtc_cc_handler_t )(int32_t id , void * p_context );
59
58
60
59
#if NRFY_GRTC_HAS_EXTENDED || defined(__NRFX_DOXYGEN__ )
61
60
/**
@@ -158,6 +157,7 @@ nrfx_err_t nrfx_grtc_sleep_configuration_get(nrfx_grtc_sleep_config_t * p_sleep_
158
157
* @brief Function for allocating the GRTC capture/compare channel.
159
158
*
160
159
* @note Function is thread safe as it uses @ref nrfx_flag32_alloc.
160
+ * @note This function marks the specified @p channel as used.
161
161
* @note Routines that allocate and free the GRTC channels are independent
162
162
* from the rest of the driver. In particular, the driver does not need
163
163
* to be initialized when this function is called.
@@ -169,6 +169,25 @@ nrfx_err_t nrfx_grtc_sleep_configuration_get(nrfx_grtc_sleep_config_t * p_sleep_
169
169
*/
170
170
nrfx_err_t nrfx_grtc_channel_alloc (uint8_t * p_channel );
171
171
172
+ /**
173
+ * @brief Function for allocating the GRTC capture/compare channel for callback
174
+ *
175
+ * Function gets callback which shall be used for that channel. Since channel will
176
+ * be used with callback, interrupt is enabled for that channel.
177
+ *
178
+ * @note Function is thread safe as it uses @ref nrfx_flag32_alloc.
179
+ *
180
+ * @param[out] p_channel Pointer to the capture/compare channel.
181
+ * @param[in] handler User handler called when channel expires.
182
+ * @param[in] p_context Context passed to the callback.
183
+ *
184
+ * @retval NRFX_SUCCESS Allocation was successful.
185
+ * @retval NRFX_ERROR_NO_MEM No resource available.
186
+ */
187
+ nrfx_err_t nrfx_grtc_channel_cb_alloc (uint8_t * p_channel ,
188
+ nrfx_grtc_cc_handler_t handler ,
189
+ void * p_context );
190
+
172
191
/**
173
192
* @brief Function for freeing the GRTC capture/compare channel.
174
193
*
@@ -281,22 +300,27 @@ void nrfx_grtc_syscountervalid_int_disable(void);
281
300
* @brief Function for starting the 1 MHz SYSCOUNTER.
282
301
*
283
302
* @note This function automatically allocates and marks as used the special-purpose main
284
- * capture/compare channel. It is available only for GRTC manager.
303
+ * capture/compare channel. Interrupt for that channel is enabled.
304
+ * It is available only for GRTC manager.
285
305
*
286
306
* @note Use auxiliary structure of type @ref nrfx_grtc_channel_t when working with SYSCOUNTER.
287
307
*
288
308
* @param[in] busy_wait True if wait for synchronization operation is to be performed,
289
309
* false otherwise.
290
310
* @param[out] p_main_cc_channel Pointer to the main capture/compare channel.
311
+ * @param[in] handler Handler.
312
+ * @param[in] p_context User context passed to the callback.
291
313
*
292
314
* @retval NRFX_SUCCESS Starting was successful.
293
315
* @retval NRFX_ERROR_NO_MEM No resource available to allocate main channel.
294
316
* @retval NRFX_ERROR_ALREADY The GRTC is already running.
295
317
* @retval NRFX_ERROR_TIMEOUT The SYSCOUNTER failed to start due to a timeout.
296
318
*/
297
319
298
- nrfx_err_t nrfx_grtc_syscounter_start (bool busy_wait , uint8_t * p_main_cc_channel );
299
-
320
+ nrfx_err_t nrfx_grtc_syscounter_start (bool busy_wait ,
321
+ uint8_t * p_main_cc_channel ,
322
+ nrfx_grtc_cc_handler_t handler ,
323
+ void * p_context );
300
324
/**
301
325
* @brief Function for performing an action for the GRTC.
302
326
*
@@ -359,6 +383,22 @@ nrfx_err_t nrfx_grtc_syscounter_cc_absolute_set(nrfx_grtc_channel_t * p_chan_dat
359
383
uint64_t val ,
360
384
bool enable_irq );
361
385
386
+ /**
387
+ * @brief Function for setting the absolute compare value for the SYSCOUNTER.
388
+ *
389
+ * Function must be called with interrupts locked. If %p safe_setting is true then
390
+ * it means that previous CC for that channel did not yet expired and it
391
+ * was set to a value earlier than %p val so there is a chance that it will
392
+ * expire during setting the new value. In that case compare event may be misinterpreted.
393
+ * Slower but safe procedure is used in that case. If %p safe_setting is false then
394
+ * function just sets new CC value.
395
+ *
396
+ * @param[in] channel Channel.
397
+ * @param[in] val Absolute value to be set in the compare register.
398
+ * @param[in] safe_setting Use safe procedure if true or just set CC to a new value if false.
399
+ */
400
+ void nrfx_grtc_syscounter_cc_abs_set (uint8_t channel , uint64_t val , bool safe_setting );
401
+
362
402
/**
363
403
* @brief Function for setting the relative compare value for the SYSCOUNTER.
364
404
*
@@ -379,6 +419,22 @@ nrfx_err_t nrfx_grtc_syscounter_cc_relative_set(nrfx_grtc_channel_t *
379
419
bool enable_irq ,
380
420
nrfx_grtc_cc_relative_reference_t reference );
381
421
422
+ /**
423
+ * @brief Function for setting the relative compare value for the SYSCOUNTER.
424
+ *
425
+ * Function just sets CCADD value and does not attempt to enable or disable the interrupt.
426
+ * It assumes that expected channel configuration is done prior to that call.
427
+ * Function assumes that previously used CC value has already expired so new value
428
+ * can be safely set without a risk of spurious CC expiration.
429
+ *
430
+ * @param[in] channel Channel.
431
+ * @param[in] val Relative value to be set in the CCADD register.
432
+ * @param[in] reference Reference. Current counter value or current CC value.
433
+ */
434
+ void nrfx_grtc_syscounter_cc_rel_set (uint8_t channel ,
435
+ uint32_t val ,
436
+ nrfx_grtc_cc_relative_reference_t reference );
437
+
382
438
/**
383
439
* @brief Function for disabling the SYSCOUNTER compare interrupt.
384
440
*
@@ -539,6 +595,15 @@ NRFX_STATIC_INLINE bool nrfx_grtc_sys_counter_cc_enable_check(uint8_t channel);
539
595
*/
540
596
NRFX_STATIC_INLINE bool nrfx_grtc_syscounter_compare_event_check (uint8_t channel );
541
597
598
+ /**
599
+ * @brief Function for retrieving CC value.
600
+ *
601
+ * @param[in] channel Compare channel.
602
+ *
603
+ * @return Value read from CC register.
604
+ */
605
+ NRFX_STATIC_INLINE uint64_t nrfx_grtc_sys_counter_cc_get (uint8_t channel );
606
+
542
607
#if NRF_GRTC_HAS_RTCOUNTER || defined(__NRFX_DOXYGEN__ )
543
608
/**
544
609
* @brief Function for reading the GRTC RTCOUNTER value.
@@ -590,6 +655,11 @@ NRFX_STATIC_INLINE bool nrfx_grtc_syscounter_compare_event_check(uint8_t channel
590
655
return nrfy_grtc_sys_counter_compare_event_check (NRF_GRTC , channel );
591
656
}
592
657
658
+ NRFX_STATIC_INLINE uint64_t nrfx_grtc_sys_counter_cc_get (uint8_t channel )
659
+ {
660
+ return nrfy_grtc_sys_counter_cc_get (NRF_GRTC , channel );
661
+ }
662
+
593
663
#if NRF_GRTC_HAS_RTCOUNTER
594
664
NRFX_STATIC_INLINE uint64_t nrfx_grtc_rtcounter_get (void )
595
665
{
0 commit comments