Skip to content

Commit 8566b00

Browse files
mmahadevan108dleach02
authored andcommitted
drivers: counter: Add error checking to MCUX CTImer
Improve the error checking for the set_top_value function. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 20c4c42 commit 8566b00

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

drivers/counter/counter_mcux_ctimer.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,25 @@ static int mcux_lpc_ctimer_set_top_value(const struct device *dev,
135135
{
136136
const struct mcux_lpc_ctimer_config *config = dev->config;
137137
struct mcux_lpc_ctimer_data *data = dev->data;
138-
bool counter_reset = true;
139-
bool counter_interrupt = true;
140138

141139
data->top_callback = cfg->callback;
142140
data->top_user_data = cfg->user_data;
143141

144-
if (cfg->flags & COUNTER_TOP_CFG_DONT_RESET) {
145-
counter_reset = false;
146-
}
147-
148-
/* If top value specified is 0, then turn off the interrupt */
149-
if (cfg->ticks == 0) {
150-
counter_interrupt = false;
142+
if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) {
143+
CTIMER_Reset(config->base);
144+
} else if (mcux_lpc_ctimer_read(config->base) >= cfg->ticks) {
145+
if (cfg->flags & COUNTER_TOP_CFG_RESET_WHEN_LATE) {
146+
CTIMER_Reset(config->base);
147+
}
148+
return -ETIME;
151149
}
152150

153151
ctimer_match_config_t match_config = { .matchValue = cfg->ticks,
154-
.enableCounterReset = counter_reset,
152+
.enableCounterReset = true,
155153
.enableCounterStop = false,
156154
.outControl = kCTIMER_Output_NoAction,
157155
.outPinInitState = false,
158-
.enableInterrupt = counter_interrupt };
156+
.enableInterrupt = true };
159157

160158
CTIMER_SetupMatch(config->base, NUM_CHANNELS, &match_config);
161159

0 commit comments

Comments
 (0)