@@ -216,6 +216,10 @@ typedef int (*counter_api_get_value)(const struct device *dev,
216
216
typedef int (* counter_api_get_value_64 )(const struct device * dev ,
217
217
uint64_t * ticks );
218
218
typedef int (* counter_api_reset )(const struct device * dev );
219
+ typedef int (* counter_api_set_value )(const struct device * dev ,
220
+ uint32_t ticks );
221
+ typedef int (* counter_api_set_value_64 )(const struct device * dev ,
222
+ uint64_t ticks );
219
223
typedef int (* counter_api_set_alarm )(const struct device * dev ,
220
224
uint8_t chan_id ,
221
225
const struct counter_alarm_cfg * alarm_cfg );
@@ -238,6 +242,8 @@ __subsystem struct counter_driver_api {
238
242
counter_api_get_value get_value ;
239
243
counter_api_get_value_64 get_value_64 ;
240
244
counter_api_reset reset ;
245
+ counter_api_set_value set_value ;
246
+ counter_api_set_value_64 set_value_64 ;
241
247
counter_api_set_alarm set_alarm ;
242
248
counter_api_cancel_alarm cancel_alarm ;
243
249
counter_api_set_top_value set_top_value ;
@@ -454,6 +460,53 @@ static inline int z_impl_counter_reset(const struct device *dev)
454
460
return api -> reset (dev );
455
461
}
456
462
463
+ /**
464
+ * @brief Set current counter value.
465
+ * @param dev Pointer to the device structure for the driver instance.
466
+ * @param ticks Tick value to set
467
+ *
468
+ * @retval 0 If successful.
469
+ * @retval Negative error code on failure getting the counter value
470
+ */
471
+ __syscall int counter_set_value (const struct device * dev , uint32_t ticks );
472
+
473
+ static inline int z_impl_counter_set_value (const struct device * dev ,
474
+ uint32_t ticks )
475
+ {
476
+ const struct counter_driver_api * api =
477
+ (struct counter_driver_api * )dev -> api ;
478
+
479
+ if (!api -> set_value ) {
480
+ return - ENOSYS ;
481
+ }
482
+
483
+ return api -> set_value (dev , ticks );
484
+ }
485
+
486
+ /**
487
+ * @brief Set current counter 64-bit value.
488
+ * @param dev Pointer to the device structure for the driver instance.
489
+ * @param ticks Tick value to set
490
+ *
491
+ * @retval 0 If successful.
492
+ * @retval Negative error code on failure getting the counter value
493
+ */
494
+ __syscall int counter_set_value_64 (const struct device * dev , uint64_t ticks );
495
+
496
+ static inline int z_impl_counter_set_value_64 (const struct device * dev ,
497
+ uint64_t ticks )
498
+ {
499
+ const struct counter_driver_api * api =
500
+ (struct counter_driver_api * )dev -> api ;
501
+
502
+ if (!api -> set_value_64 ) {
503
+ return - ENOSYS ;
504
+ }
505
+
506
+ return api -> set_value_64 (dev , ticks );
507
+ }
508
+
509
+
457
510
/**
458
511
* @brief Set a single shot alarm on a channel.
459
512
*
0 commit comments