Skip to content

Commit 355d904

Browse files
rruuaanngkartben
authored andcommitted
drivers: counter: Add counter_reset function
Add a counter_reset function to the counter subsystem to reset the counter value to zero. Introduce a reset interface at the driver layer to implement the counter_reset function. Signed-off-by: James Roy <[email protected]>
1 parent a65e93a commit 355d904

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

include/zephyr/drivers/counter.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ typedef int (*counter_api_get_value)(const struct device *dev,
215215
uint32_t *ticks);
216216
typedef int (*counter_api_get_value_64)(const struct device *dev,
217217
uint64_t *ticks);
218+
typedef int (*counter_api_reset)(const struct device *dev);
218219
typedef int (*counter_api_set_alarm)(const struct device *dev,
219220
uint8_t chan_id,
220221
const struct counter_alarm_cfg *alarm_cfg);
@@ -236,6 +237,7 @@ __subsystem struct counter_driver_api {
236237
counter_api_stop stop;
237238
counter_api_get_value get_value;
238239
counter_api_get_value_64 get_value_64;
240+
counter_api_reset reset;
239241
counter_api_set_alarm set_alarm;
240242
counter_api_cancel_alarm cancel_alarm;
241243
counter_api_set_top_value set_top_value;
@@ -431,6 +433,27 @@ static inline int z_impl_counter_get_value_64(const struct device *dev,
431433
return api->get_value_64(dev, ticks);
432434
}
433435

436+
/**
437+
* @brief Reset the counter to the initial value.
438+
* @param dev Pointer to the device structure for the driver instance.
439+
*
440+
* @retval 0 If successful.
441+
* @retval -errno Negative error code on failure resetting the counter value.
442+
*/
443+
__syscall int counter_reset(const struct device *dev);
444+
445+
static inline int z_impl_counter_reset(const struct device *dev)
446+
{
447+
const struct counter_driver_api *api =
448+
(struct counter_driver_api *)dev->api;
449+
450+
if (!api->reset) {
451+
return -ENOSYS;
452+
}
453+
454+
return api->reset(dev);
455+
}
456+
434457
/**
435458
* @brief Set a single shot alarm on a channel.
436459
*

0 commit comments

Comments
 (0)