counter: Update counter API in order to provide more flexibility

This commit introduces new top_value setting configuration structure
with flag for controlling resetting of the counter during change of
top value.

Such change allows for #12068 implementation on hardware which
does not provide alarms.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
This commit is contained in:
Piotr Zięcik 2019-03-21 16:31:16 +01:00 committed by Carles Cufí
commit 69406e0f9c
14 changed files with 248 additions and 125 deletions

View file

@ -133,20 +133,27 @@ static int mcux_rtc_cancel_alarm(struct device *dev, u8_t chan_id)
return 0;
}
static int mcux_rtc_set_top_value(struct device *dev, u32_t ticks,
counter_top_callback_t callback,
void *user_data)
static int mcux_rtc_set_top_value(struct device *dev,
const struct counter_top_cfg *cfg)
{
const struct counter_config_info *info = dev->config->config_info;
const struct mcux_rtc_config *config =
CONTAINER_OF(info, struct mcux_rtc_config, info);
struct mcux_rtc_data *data = dev->driver_data;
if (ticks != info->max_top_value) {
LOG_ERR("Wrap can only be set to 0x%x", info->max_top_value);
if (cfg->ticks != info->max_top_value) {
LOG_ERR("Wrap can only be set to 0x%x.", info->max_top_value);
return -ENOTSUP;
}
data->top_callback = callback;
data->top_user_data = user_data;
if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) {
RTC_StopTimer(config->base);
config->base->TSR = 0;
RTC_StartTimer(config->base);
}
data->top_callback = cfg->callback;
data->top_user_data = cfg->user_data;
return 0;
}