Use appropriate defined value
authorNathael Pajani <nathael.pajani@ed3l.fr>
Sat, 1 Dec 2018 13:19:17 +0000 (14:19 +0100)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 16:03:05 +0000 (17:03 +0100)
drivers/countertimers.c

index ee49888..a3ac6ff 100644 (file)
@@ -150,7 +150,7 @@ int countertimer_get_counter_val(uint8_t timer_num, uint32_t* val)
 
 int countertimer_get_capture_val(uint8_t timer_num, uint8_t channel, uint32_t* val)
 {
-       if (channel >= MAX_CHANNELS) {
+       if (channel >= NUM_COUNTERTIMERS_CHANS) {
                return -EINVAL;
        }
        *val = countertimers[timer_num].regs->capture_reg[channel];
@@ -161,7 +161,7 @@ int countertimer_get_capture_val(uint8_t timer_num, uint8_t channel, uint32_t* v
 /* Change the match value of a single timer channel */
 int countertimer_set_match(uint8_t timer_num, uint8_t channel, uint32_t val)
 {
-       if (channel > NUM_COUNTERTIMERS_CHANS)
+       if (channel >= NUM_COUNTERTIMERS_CHANS)
                return -EINVAL;
 
        countertimers[timer_num].regs->match_reg[channel] = val;
@@ -219,7 +219,7 @@ int countertimer_pwm_setup(uint8_t timer_num, const struct lpc_timer_pwm_config*
                        break;
        }
 
-       if (conf->period_chan >= MAX_CHANNELS) {
+       if (conf->period_chan >= NUM_COUNTERTIMERS_CHANS) {
                 return -EINVAL;
        }
        /* Setup selected PWM channels */
@@ -287,13 +287,13 @@ int countertimer_tc_setup(uint8_t timer_num, const struct lpc_tc_config* conf)
        }
 
        if (conf->mode & LPC_TIMER_MODE_CAPTURE) {
-               for (i = 0; i < MAX_CHANNELS; i++) {
+               for (i = 0; i < NUM_COUNTERTIMERS_CHANS; i++) {
                        timer->regs->capture_ctrl |= ((conf->cap_control[i] & 0x07) << LPC_TIMER_CAPTURE_SHIFT(i));
                }
        }
 
        if (conf->mode & LPC_TIMER_MODE_MATCH) {
-               for (i = 0; i < MAX_CHANNELS; i++) {
+               for (i = 0; i < NUM_COUNTERTIMERS_CHANS; i++) {
                        timer->regs->match_ctrl |= ((conf->match_control[i] & 0x07) << LPC_TIMER_MATCH_SHIFT(i));
                        timer->regs->match_reg[i] = conf->match[i];
                        timer->regs->external_match |= ((conf->ext_match_config[i] & 0x03) << LPC_TIMER_EXT_MATCH_SHIFT(i));