From c59dd2b2fcc3ac112c02f2bd3ec087e055c6812c Mon Sep 17 00:00:00 2001 From: Marcos Chaparro Date: Mon, 28 Jan 2019 16:52:02 -0300 Subject: [PATCH] Fix shadowed variables. Add -Wshadow. Signed-off-by: Marcos Chaparro --- ChibiOS_3.0.2/os/hal/lib/streams/chprintf.c | 4 +-- Makefile | 2 +- applications/app_ppm.c | 4 +-- conf_general.c | 2 +- led_external.c | 4 +-- main.c | 4 ++- mcpwm_foc.c | 32 ++++++++++----------- ws2811.c | 2 +- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/ChibiOS_3.0.2/os/hal/lib/streams/chprintf.c b/ChibiOS_3.0.2/os/hal/lib/streams/chprintf.c index 5f4ae4f8..49949e0e 100644 --- a/ChibiOS_3.0.2/os/hal/lib/streams/chprintf.c +++ b/ChibiOS_3.0.2/os/hal/lib/streams/chprintf.c @@ -73,7 +73,7 @@ static char *ch_ltoa(char *p, long num, unsigned radix) { } #if CHPRINTF_USE_FLOAT -static const long pow10[FLOAT_PRECISION] = { +static const long ch_pow10[FLOAT_PRECISION] = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; @@ -82,7 +82,7 @@ static char *ftoa(char *p, double num, unsigned long precision) { if ((precision == 0) || (precision > FLOAT_PRECISION)) precision = FLOAT_PRECISION; - precision = pow10[precision - 1]; + precision = ch_pow10[precision - 1]; l = (long)num; p = long_to_string_with_divisor(p, l, 10, 0); diff --git a/Makefile b/Makefile index f8b95262..2ca0d931 100644 --- a/Makefile +++ b/Makefile @@ -222,7 +222,7 @@ AOPT = TOPT = -mthumb -DTHUMB # Define C warning options here -CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes +CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes -Wshadow # Define C++ warning options here CPPWARN = -Wall -Wextra -Wundef diff --git a/applications/app_ppm.c b/applications/app_ppm.c index beaa4f25..f531b7ea 100644 --- a/applications/app_ppm.c +++ b/applications/app_ppm.c @@ -281,13 +281,13 @@ static THD_FUNCTION(ppm_thread, arg) { } if (send_current && config.multi_esc) { - float current = mc_interface_get_tot_current_directional_filtered(); + float current_filtered = mc_interface_get_tot_current_directional_filtered(); for (int i = 0;i < CAN_STATUS_MSGS_TO_STORE;i++) { can_status_msg *msg = comm_can_get_status_msg_index(i); if (msg->id >= 0 && UTILS_AGE_S(msg->rx_time) < MAX_CAN_AGE) { - comm_can_set_current(msg->id, current); + comm_can_set_current(msg->id, current_filtered); } } } diff --git a/conf_general.c b/conf_general.c index 47f23ba5..fb1cc370 100644 --- a/conf_general.c +++ b/conf_general.c @@ -736,7 +736,7 @@ bool conf_general_measure_flux_linkage(float current, float duty, float erpm_per float vd_avg = 0.0; float iq_avg = 0.0; float id_avg = 0.0; - float samples = 0.0; + samples = 0.0; for (int i = 0;i < 1000;i++) { vq_avg += mcpwm_foc_get_vq(); diff --git a/led_external.c b/led_external.c index d969e480..cc7e9455 100644 --- a/led_external.c +++ b/led_external.c @@ -74,8 +74,8 @@ static THD_FUNCTION(led_thread, arg) { for (int i = 0;i < 50;i++) { scale -= 0.02; uint32_t color = scale_color(COLOR_RED, scale); - for (int i = 0;i < (int)fault;i++) { - set_led_wrapper(i, color); + for (int j = 0;j < (int)fault;j++) { + set_led_wrapper(j, color); } chThdSleepMilliseconds(10); } diff --git a/main.c b/main.c index b061489e..fe890601 100644 --- a/main.c +++ b/main.c @@ -176,10 +176,12 @@ static THD_FUNCTION(timer_thread, arg) { } } +/* When assertions enabled halve PWM frequency. The control loop ISR runs 40% slower */ void assert_failed(uint8_t* file, uint32_t line) { commands_printf("Wrong parameters value: file %s on line %d\r\n", file, line); + mc_interface_release_motor(); while(1) - ; + chThdSleepMilliseconds(1); } int main(void) { diff --git a/mcpwm_foc.c b/mcpwm_foc.c index aac75174..97a6398d 100644 --- a/mcpwm_foc.c +++ b/mcpwm_foc.c @@ -1002,9 +1002,9 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r for (int i = 0; i < it_rat; i++) { float phase_old = m_phase_now_encoder; float phase_ovr_tmp = m_phase_now_override; - for (float i = phase_ovr_tmp; i < phase_ovr_tmp + (2.0 / 3.0) * M_PI; - i += (2.0 * M_PI) / 500.0) { - m_phase_now_override = i; + for (float j = phase_ovr_tmp; j < phase_ovr_tmp + (2.0 / 3.0) * M_PI; + j += (2.0 * M_PI) / 500.0) { + m_phase_now_override = j; chThdSleepMilliseconds(1); } utils_norm_angle_rad((float*)&m_phase_now_override); @@ -1030,9 +1030,9 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r for (int i = 0; i < it_rat; i++) { float phase_old = m_phase_now_encoder; float phase_ovr_tmp = m_phase_now_override; - for (float i = phase_ovr_tmp; i > phase_ovr_tmp - (2.0 / 3.0) * M_PI; - i -= (2.0 * M_PI) / 500.0) { - m_phase_now_override = i; + for (float j = phase_ovr_tmp; j > phase_ovr_tmp - (2.0 / 3.0) * M_PI; + j -= (2.0 * M_PI) / 500.0) { + m_phase_now_override = j; chThdSleepMilliseconds(1); } utils_norm_angle_rad((float*)&m_phase_now_override); @@ -1084,14 +1084,14 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r m_phase_now_override = ((float)i * 2.0 * M_PI * m_conf->foc_encoder_ratio) / ((float)it_ofs); chThdSleepMilliseconds(500); - float diff = utils_angle_difference_rad(m_phase_now_encoder, m_phase_now_override); + float angle_diff = utils_angle_difference_rad(m_phase_now_encoder, m_phase_now_override); float s, c; - sincosf(diff, &s, &c); + sincosf(angle_diff, &s, &c); s_sum += s; c_sum += c; if (print) { - commands_printf("%.2f", (double)(diff * 180.0 / M_PI)); + commands_printf("%.2f", (double)(angle_diff * 180.0 / M_PI)); } } @@ -1099,14 +1099,14 @@ void mcpwm_foc_encoder_detect(float current, bool print, float *offset, float *r m_phase_now_override = ((float)i * 2.0 * M_PI * m_conf->foc_encoder_ratio) / ((float)it_ofs); chThdSleepMilliseconds(500); - float diff = utils_angle_difference_rad(m_phase_now_encoder, m_phase_now_override); + float angle_diff = utils_angle_difference_rad(m_phase_now_encoder, m_phase_now_override); float s, c; - sincosf(diff, &s, &c); + sincosf(angle_diff, &s, &c); s_sum += s; c_sum += c; if (print) { - commands_printf("%.2f", (double)(diff * 180.0 / M_PI)); + commands_printf("%.2f", (double)(angle_diff * 180.0 / M_PI)); } } @@ -1376,8 +1376,8 @@ bool mcpwm_foc_hall_detect(float current, uint8_t *hall_table) { // Forwards for (int i = 0;i < 3;i++) { - for (int i = 0;i < 360;i++) { - m_phase_now_override = (float)i * M_PI / 180.0; + for (int j = 0;j < 360;j++) { + m_phase_now_override = (float)j * M_PI / 180.0; chThdSleepMilliseconds(5); int hall = read_hall(); @@ -1391,8 +1391,8 @@ bool mcpwm_foc_hall_detect(float current, uint8_t *hall_table) { // Reverse for (int i = 0;i < 3;i++) { - for (int i = 360;i >= 0;i--) { - m_phase_now_override = (float)i * M_PI / 180.0; + for (int j = 360;j >= 0;j--) { + m_phase_now_override = (float)j * M_PI / 180.0; chThdSleepMilliseconds(5); int hall = read_hall(); diff --git a/ws2811.c b/ws2811.c index 72475ee9..22b17c20 100644 --- a/ws2811.c +++ b/ws2811.c @@ -74,7 +74,7 @@ void ws2811_init(void) { } // Generate gamma correction table - for (int i = 0;i < 256;i++) { + for (i = 0;i < 256;i++) { gamma_table[i] = (int)roundf(powf((float)i / 255.0, 1.0 / 0.45) * 255.0); }