mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-15 14:36:45 +00:00
fix(hal_utils): add division range check in integral algorithm
This commit is contained in:

committed by
Kevin (Lao Kaiyao)

parent
4ecc978bd6
commit
03fb722ca5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -133,6 +133,17 @@ uint32_t hal_utils_calc_clk_div_integer(const hal_utils_clk_info_t *clk_info, ui
|
||||
(freq_error >= clk_info->src_freq_hz / (2 * div_integ * (div_integ + 1))))) {
|
||||
div_integ++;
|
||||
}
|
||||
/* Check the integral division whether in range [min_integ, max_integ) */
|
||||
/* If the result is less than the minimum, set the division to the minimum but return 0 */
|
||||
if (div_integ < clk_info->min_integ) {
|
||||
*int_div = clk_info->min_integ;
|
||||
return 0;
|
||||
}
|
||||
/* if the result is greater or equal to the maximum , set the division to the maximum but return 0 */
|
||||
if (div_integ >= clk_info->max_integ) {
|
||||
*int_div = clk_info->max_integ - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Assign result
|
||||
*int_div = div_integ;
|
||||
|
Reference in New Issue
Block a user