@@ -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