drivers: counter: Add error checking to MCUX CTImer
Improve the error checking for the set_top_value function. Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
This commit is contained in:
parent
20c4c426ef
commit
8566b00df3
1 changed files with 9 additions and 11 deletions
|
@ -135,27 +135,25 @@ static int mcux_lpc_ctimer_set_top_value(const struct device *dev,
|
||||||
{
|
{
|
||||||
const struct mcux_lpc_ctimer_config *config = dev->config;
|
const struct mcux_lpc_ctimer_config *config = dev->config;
|
||||||
struct mcux_lpc_ctimer_data *data = dev->data;
|
struct mcux_lpc_ctimer_data *data = dev->data;
|
||||||
bool counter_reset = true;
|
|
||||||
bool counter_interrupt = true;
|
|
||||||
|
|
||||||
data->top_callback = cfg->callback;
|
data->top_callback = cfg->callback;
|
||||||
data->top_user_data = cfg->user_data;
|
data->top_user_data = cfg->user_data;
|
||||||
|
|
||||||
if (cfg->flags & COUNTER_TOP_CFG_DONT_RESET) {
|
if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) {
|
||||||
counter_reset = false;
|
CTIMER_Reset(config->base);
|
||||||
}
|
} else if (mcux_lpc_ctimer_read(config->base) >= cfg->ticks) {
|
||||||
|
if (cfg->flags & COUNTER_TOP_CFG_RESET_WHEN_LATE) {
|
||||||
/* If top value specified is 0, then turn off the interrupt */
|
CTIMER_Reset(config->base);
|
||||||
if (cfg->ticks == 0) {
|
}
|
||||||
counter_interrupt = false;
|
return -ETIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctimer_match_config_t match_config = { .matchValue = cfg->ticks,
|
ctimer_match_config_t match_config = { .matchValue = cfg->ticks,
|
||||||
.enableCounterReset = counter_reset,
|
.enableCounterReset = true,
|
||||||
.enableCounterStop = false,
|
.enableCounterStop = false,
|
||||||
.outControl = kCTIMER_Output_NoAction,
|
.outControl = kCTIMER_Output_NoAction,
|
||||||
.outPinInitState = false,
|
.outPinInitState = false,
|
||||||
.enableInterrupt = counter_interrupt };
|
.enableInterrupt = true };
|
||||||
|
|
||||||
CTIMER_SetupMatch(config->base, NUM_CHANNELS, &match_config);
|
CTIMER_SetupMatch(config->base, NUM_CHANNELS, &match_config);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue