From 01c54d11990fb82b85acc322a6e2e34a4b7ee389 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 24 Mar 2024 12:38:25 -0700 Subject: [PATCH] enable misra-c2012-11.8 (#1916) * fix up harness_config definition * enable misra-c2012-11.8 --- board/boards/black.h | 4 ++-- board/boards/board_declarations.h | 2 +- board/boards/cuatro.h | 2 +- board/boards/dos.h | 4 ++-- board/boards/grey.h | 2 +- board/boards/red.h | 4 ++-- board/boards/red_chiplet.h | 2 +- board/boards/tres.h | 2 +- board/boards/uno.h | 4 ++-- board/boards/white.h | 4 ++-- board/bootstub_declarations.h | 2 +- board/drivers/gpio.h | 6 +++--- board/drivers/harness.h | 20 ++++++++++---------- board/jungle/boards/board_v1.h | 2 +- board/jungle/boards/board_v2.h | 16 ++++++++-------- board/main_declarations.h | 2 +- tests/misra/suppressions.txt | 1 - 17 files changed, 39 insertions(+), 40 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 858ade2e22..c860d1401d 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -141,7 +141,7 @@ void black_init_bootloader(void) { set_gpio_output(GPIOC, 12, 0); } -const harness_configuration black_harness_config = { +harness_configuration black_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, @@ -155,7 +155,7 @@ const harness_configuration black_harness_config = { .adc_channel_SBU2 = 13 }; -const board board_black = { +board board_black = { .set_bootkick = unused_set_bootkick, .harness_config = &black_harness_config, .has_obd = true, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index ac0c14136c..a9ff9297ba 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -21,7 +21,7 @@ typedef void (*board_set_bootkick)(BootState state); typedef bool (*board_read_som_gpio)(void); struct board { - const harness_configuration *harness_config; + harness_configuration *harness_config; const bool has_obd; const bool has_spi; const bool has_canfd; diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index f497f3f691..43a5dfc505 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -103,7 +103,7 @@ void cuatro_init(void) { clock_source_init(); } -const board board_cuatro = { +board board_cuatro = { .harness_config = &red_chiplet_harness_config, .has_obd = true, .has_spi = true, diff --git a/board/boards/dos.h b/board/boards/dos.h index 381ce84139..0164f2b262 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -166,7 +166,7 @@ void dos_init(void) { clock_source_init(); } -const harness_configuration dos_harness_config = { +harness_configuration dos_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, @@ -180,7 +180,7 @@ const harness_configuration dos_harness_config = { .adc_channel_SBU2 = 13 }; -const board board_dos = { +board board_dos = { .harness_config = &dos_harness_config, .has_obd = true, #ifdef ENABLE_SPI diff --git a/board/boards/grey.h b/board/boards/grey.h index 75273c1ad1..516d0fa70f 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -4,7 +4,7 @@ // Most hardware functionality is similar to white panda -const board board_grey = { +board board_grey = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, .has_obd = false, diff --git a/board/boards/red.h b/board/boards/red.h index 90d97c4f10..746c54b622 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -153,7 +153,7 @@ void red_init(void) { red_set_can_mode(CAN_MODE_NORMAL); } -const harness_configuration red_harness_config = { +harness_configuration red_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOA, @@ -167,7 +167,7 @@ const harness_configuration red_harness_config = { .adc_channel_SBU2 = 17 //ADC1_INP17 }; -const board board_red = { +board board_red = { .set_bootkick = unused_set_bootkick, .harness_config = &red_harness_config, .has_obd = true, diff --git a/board/boards/red_chiplet.h b/board/boards/red_chiplet.h index f6c028be1e..d79f8f83a6 100644 --- a/board/boards/red_chiplet.h +++ b/board/boards/red_chiplet.h @@ -132,7 +132,7 @@ void red_chiplet_init(void) { red_chiplet_set_can_mode(CAN_MODE_NORMAL); } -const harness_configuration red_chiplet_harness_config = { +harness_configuration red_chiplet_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOA, diff --git a/board/boards/tres.h b/board/boards/tres.h index 14a02bea70..91b94f68e2 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -70,7 +70,7 @@ void tres_init(void) { clock_source_init(); } -const board board_tres = { +board board_tres = { .harness_config = &red_chiplet_harness_config, .has_obd = true, .has_spi = true, diff --git a/board/boards/uno.h b/board/boards/uno.h index ce69f6cfee..a2e1e98354 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -177,7 +177,7 @@ void uno_init_bootloader(void) { set_gpio_output(GPIOC, 12, 0); } -const harness_configuration uno_harness_config = { +harness_configuration uno_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, @@ -191,7 +191,7 @@ const harness_configuration uno_harness_config = { .adc_channel_SBU2 = 13 }; -const board board_uno = { +board board_uno = { .harness_config = &uno_harness_config, .has_obd = true, .has_spi = false, diff --git a/board/boards/white.h b/board/boards/white.h index 690334568c..8d22afbc9b 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -180,11 +180,11 @@ void white_grey_init_bootloader(void) { set_gpio_output(GPIOC, 14, 0); } -const harness_configuration white_harness_config = { +harness_configuration white_harness_config = { .has_harness = false }; -const board board_white = { +board board_white = { .set_bootkick = unused_set_bootkick, .harness_config = &white_harness_config, .has_obd = false, diff --git a/board/bootstub_declarations.h b/board/bootstub_declarations.h index f61fb310c1..5cdec508e7 100644 --- a/board/bootstub_declarations.h +++ b/board/bootstub_declarations.h @@ -15,4 +15,4 @@ void uart_init(uart_ring *q, int baud) { UNUSED(q); UNUSED(baud); } // ********************* Globals ********************** uint8_t hw_type = 0; -const board *current_board; +board *current_board; diff --git a/board/drivers/gpio.h b/board/drivers/gpio.h index bf96a0326e..0b8fc091b1 100644 --- a/board/drivers/gpio.h +++ b/board/drivers/gpio.h @@ -11,7 +11,7 @@ #define OUTPUT_TYPE_OPEN_DRAIN 1U typedef struct { - GPIO_TypeDef *bank; + GPIO_TypeDef * const bank; uint8_t pin; } gpio_t; @@ -68,13 +68,13 @@ int get_gpio_input(const GPIO_TypeDef *GPIO, unsigned int pin) { return (GPIO->IDR & (1UL << pin)) == (1UL << pin); } -void gpio_set_all_output(const gpio_t *pins, uint8_t num_pins, bool enabled) { +void gpio_set_all_output(gpio_t *pins, uint8_t num_pins, bool enabled) { for (uint8_t i = 0; i < num_pins; i++) { set_gpio_output(pins[i].bank, pins[i].pin, enabled); } } -void gpio_set_bitmask(const gpio_t *pins, uint8_t num_pins, uint32_t bitmask) { +void gpio_set_bitmask(gpio_t *pins, uint8_t num_pins, uint32_t bitmask) { for (uint8_t i = 0; i < num_pins; i++) { set_gpio_output(pins[i].bank, pins[i].pin, (bitmask >> i) & 1U); } diff --git a/board/drivers/harness.h b/board/drivers/harness.h index bfe61050a9..f8f0ccb7d3 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -13,16 +13,16 @@ struct harness_t harness; struct harness_configuration { const bool has_harness; - GPIO_TypeDef *GPIO_SBU1; - GPIO_TypeDef *GPIO_SBU2; - GPIO_TypeDef *GPIO_relay_SBU1; - GPIO_TypeDef *GPIO_relay_SBU2; - uint8_t pin_SBU1; - uint8_t pin_SBU2; - uint8_t pin_relay_SBU1; - uint8_t pin_relay_SBU2; - uint8_t adc_channel_SBU1; - uint8_t adc_channel_SBU2; + GPIO_TypeDef * const GPIO_SBU1; + GPIO_TypeDef * const GPIO_SBU2; + GPIO_TypeDef * const GPIO_relay_SBU1; + GPIO_TypeDef * const GPIO_relay_SBU2; + const uint8_t pin_SBU1; + const uint8_t pin_SBU2; + const uint8_t pin_relay_SBU1; + const uint8_t pin_relay_SBU2; + const uint8_t adc_channel_SBU1; + const uint8_t adc_channel_SBU2; }; // The ignition relay is only used for testing purposes diff --git a/board/jungle/boards/board_v1.h b/board/jungle/boards/board_v1.h index 9581686e2a..efaacf60ce 100644 --- a/board/jungle/boards/board_v1.h +++ b/board/jungle/boards/board_v1.h @@ -157,7 +157,7 @@ void board_v1_init(void) { void board_v1_tick(void) {} -const board board_v1 = { +board board_v1 = { .has_canfd = false, .has_sbu_sense = false, .avdd_mV = 3300U, diff --git a/board/jungle/boards/board_v2.h b/board/jungle/boards/board_v2.h index 095114825b..ae4b2fc8d1 100644 --- a/board/jungle/boards/board_v2.h +++ b/board/jungle/boards/board_v2.h @@ -2,7 +2,7 @@ // Jungle board v2 (STM32H7) // // ///////////////////////// // -const gpio_t power_pins[] = { +gpio_t power_pins[] = { {.bank = GPIOA, .pin = 0}, {.bank = GPIOA, .pin = 1}, {.bank = GPIOF, .pin = 12}, @@ -11,7 +11,7 @@ const gpio_t power_pins[] = { {.bank = GPIOB, .pin = 2}, }; -const gpio_t sbu1_ignition_pins[] = { +gpio_t sbu1_ignition_pins[] = { {.bank = GPIOD, .pin = 0}, {.bank = GPIOD, .pin = 5}, {.bank = GPIOD, .pin = 12}, @@ -20,7 +20,7 @@ const gpio_t sbu1_ignition_pins[] = { {.bank = GPIOE, .pin = 9}, }; -const gpio_t sbu1_relay_pins[] = { +gpio_t sbu1_relay_pins[] = { {.bank = GPIOD, .pin = 1}, {.bank = GPIOD, .pin = 6}, {.bank = GPIOD, .pin = 11}, @@ -29,7 +29,7 @@ const gpio_t sbu1_relay_pins[] = { {.bank = GPIOE, .pin = 10}, }; -const gpio_t sbu2_ignition_pins[] = { +gpio_t sbu2_ignition_pins[] = { {.bank = GPIOD, .pin = 3}, {.bank = GPIOD, .pin = 8}, {.bank = GPIOD, .pin = 9}, @@ -38,7 +38,7 @@ const gpio_t sbu2_ignition_pins[] = { {.bank = GPIOE, .pin = 11}, }; -const gpio_t sbu2_relay_pins[] = { +gpio_t sbu2_relay_pins[] = { {.bank = GPIOD, .pin = 4}, {.bank = GPIOD, .pin = 10}, {.bank = GPIOD, .pin = 13}, @@ -47,7 +47,7 @@ const gpio_t sbu2_relay_pins[] = { {.bank = GPIOE, .pin = 12}, }; -const adc_channel_t sbu1_channels[] = { +adc_channel_t sbu1_channels[] = { {.adc = ADC3, .channel = 12}, {.adc = ADC3, .channel = 2}, {.adc = ADC3, .channel = 4}, @@ -56,7 +56,7 @@ const adc_channel_t sbu1_channels[] = { {.adc = ADC3, .channel = 10}, }; -const adc_channel_t sbu2_channels[] = { +adc_channel_t sbu2_channels[] = { {.adc = ADC1, .channel = 13}, {.adc = ADC3, .channel = 3}, {.adc = ADC3, .channel = 5}, @@ -307,7 +307,7 @@ void board_v2_init(void) { void board_v2_tick(void) {} -const board board_v2 = { +board board_v2 = { .has_canfd = true, .has_sbu_sense = true, .avdd_mV = 3300U, diff --git a/board/main_declarations.h b/board/main_declarations.h index fa860b86c0..a1496c0d0a 100644 --- a/board/main_declarations.h +++ b/board/main_declarations.h @@ -11,7 +11,7 @@ void pwm_set(TIM_TypeDef *TIM, uint8_t channel, uint8_t percentage); // ********************* Globals ********************** uint8_t hw_type = 0; -const board *current_board; +board *current_board; uint32_t uptime_cnt = 0; bool green_led_enabled = false; diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index b16194e6b9..c3e260dfba 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -22,7 +22,6 @@ misra-c2012-1.2 # this is from the extensions (e.g. __typeof__) used in the MI misra-c2012-2.5 # unused macros. a few legit, rest aren't common between F4/H7 builds. should we do this in the unusedFunction pass? misra-c2012-8.7 misra-c2012-8.4 -misra-c2012-11.8 misra-c2012-21.15 # FIXME: violations are in ST's F4 headers