Lines Matching full:top
158 static uint32_t counter_stm32_ticks_add(uint32_t val1, uint32_t val2, uint32_t top) in counter_stm32_ticks_add() argument
162 if (likely(IS_BIT_MASK(top))) { in counter_stm32_ticks_add()
163 return (val1 + val2) & top; in counter_stm32_ticks_add()
166 to_top = top - val1; in counter_stm32_ticks_add()
171 static uint32_t counter_stm32_ticks_sub(uint32_t val, uint32_t old, uint32_t top) in counter_stm32_ticks_sub() argument
173 if (likely(IS_BIT_MASK(top))) { in counter_stm32_ticks_sub()
174 return (val - old) & top; in counter_stm32_ticks_sub()
177 /* if top is not 2^n-1 */ in counter_stm32_ticks_sub()
178 return (val >= old) ? (val - old) : val + top + 1U - old; in counter_stm32_ticks_sub()
202 uint32_t top = counter_stm32_get_top_value(dev); in counter_stm32_set_cc() local
222 max_rel_val = top - data->guard_period; in counter_stm32_set_cc()
234 irq_on_late = val < (top / 2U); in counter_stm32_set_cc()
236 max_rel_val = irq_on_late ? top / 2U : top; in counter_stm32_set_cc()
237 val = counter_stm32_ticks_add(now, val, top); in counter_stm32_set_cc()
245 diff = counter_stm32_ticks_sub(val - 1U, counter_stm32_read(dev), top); in counter_stm32_set_cc()
546 __ASSERT(cb != NULL, "top event enabled - expecting callback"); in counter_stm32_top_irq_handle()