Skip to content

Commit

Permalink
enable misra-c2012-11.8 (#1916)
Browse files Browse the repository at this point in the history
* fix up harness_config definition

* enable misra-c2012-11.8
  • Loading branch information
adeebshihadeh authored Mar 24, 2024
1 parent 418fca3 commit 01c54d1
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 40 deletions.
4 changes: 2 additions & 2 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion board/bootstub_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions board/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define OUTPUT_TYPE_OPEN_DRAIN 1U

typedef struct {
GPIO_TypeDef *bank;
GPIO_TypeDef * const bank;
uint8_t pin;
} gpio_t;

Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 10 additions & 10 deletions board/drivers/harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion board/jungle/boards/board_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions board/jungle/boards/board_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion board/main_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01c54d1

Please sign in to comment.