Skip to content

Commit

Permalink
enable misra-c2012-8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
samrum committed Jan 22, 2024
1 parent c5e7940 commit 3df4b6e
Show file tree
Hide file tree
Showing 52 changed files with 294 additions and 288 deletions.
8 changes: 4 additions & 4 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void black_enable_can_transceivers(bool enabled) {
static void black_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -49,11 +49,11 @@ void black_set_led(uint8_t color, bool enabled) {
}
}

void black_set_usb_load_switch(bool enabled) {
static void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

void black_set_can_mode(uint8_t mode) {
static void black_set_can_mode(uint8_t mode) {
black_enable_can_transceiver(2U, false);
black_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -148,7 +148,7 @@ void black_init_bootloader(void) {
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration black_harness_config = {
static const harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
10 changes: 5 additions & 5 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void dos_enable_can_transceivers(bool enabled) {
static void dos_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -49,11 +49,11 @@ void dos_set_led(uint8_t color, bool enabled) {
}
}

void dos_set_bootkick(BootState state) {
static void dos_set_bootkick(BootState state) {
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
}

void dos_set_can_mode(uint8_t mode) {
static void dos_set_can_mode(uint8_t mode) {
dos_enable_can_transceiver(2U, false);
dos_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -94,7 +94,7 @@ void dos_set_usb_switch(bool phone){
set_gpio_output(GPIOB, 3, phone);
}

void dos_set_ir_power(uint8_t percentage){
static void dos_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}

Expand Down Expand Up @@ -177,7 +177,7 @@ void dos_init(void) {
clock_source_init();
}

const harness_configuration dos_harness_config = {
static const harness_configuration dos_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
6 changes: 3 additions & 3 deletions board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Pedal //
// ///// //

void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1:
set_gpio_output(GPIOB, 3, !enabled);
Expand All @@ -13,7 +13,7 @@ void pedal_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void pedal_enable_can_transceivers(bool enabled) {
static void pedal_enable_can_transceivers(bool enabled) {
pedal_enable_can_transceiver(1U, enabled);
}

Expand Down Expand Up @@ -62,7 +62,7 @@ void pedal_init(void) {
pedal_set_led(LED_GREEN, false);
}

const harness_configuration pedal_harness_config = {
static const harness_configuration pedal_harness_config = {
.has_harness = false
};

Expand Down
6 changes: 3 additions & 3 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void red_enable_can_transceivers(bool enabled) {
static void red_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
Expand Down Expand Up @@ -49,7 +49,7 @@ void red_set_led(uint8_t color, bool enabled) {
}
}

void red_set_can_mode(uint8_t mode) {
static void red_set_can_mode(uint8_t mode) {
red_enable_can_transceiver(2U, false);
red_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -156,7 +156,7 @@ void red_init(void) {
}
}

const harness_configuration red_harness_config = {
static const harness_configuration red_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void red_chiplet_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void red_chiplet_enable_can_transceivers(bool enabled) {
static void red_chiplet_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
Expand All @@ -35,7 +35,7 @@ void red_chiplet_enable_can_transceivers(bool enabled) {
}
}

void red_chiplet_set_can_mode(uint8_t mode) {
static void red_chiplet_set_can_mode(uint8_t mode) {
red_chiplet_enable_can_transceiver(2U, false);
red_chiplet_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down
4 changes: 2 additions & 2 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ void tres_update_fan_ir_power(void) {
red_chiplet_set_fan_or_usb_load_switch(tres_ir_enabled || tres_fan_enabled);
}

void tres_set_ir_power(uint8_t percentage){
static void tres_set_ir_power(uint8_t percentage){
tres_ir_enabled = (percentage > 0U);
tres_update_fan_ir_power();
pwm_set(TIM3, 4, percentage);
}

void tres_set_bootkick(BootState state) {
static void tres_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}
Expand Down
10 changes: 5 additions & 5 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void uno_enable_can_transceivers(bool enabled) {
static void uno_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -49,7 +49,7 @@ void uno_set_led(uint8_t color, bool enabled) {
}
}

void uno_set_bootkick(BootState state) {
static void uno_set_bootkick(BootState state) {
if (state == BOOT_BOOTKICK) {
set_gpio_output(GPIOB, 14, false);
} else {
Expand All @@ -58,7 +58,7 @@ void uno_set_bootkick(BootState state) {
}
}

void uno_set_can_mode(uint8_t mode) {
static void uno_set_can_mode(uint8_t mode) {
uno_enable_can_transceiver(2U, false);
uno_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -99,7 +99,7 @@ void uno_set_usb_switch(bool phone){
set_gpio_output(GPIOB, 3, phone);
}

void uno_set_ir_power(uint8_t percentage){
static void uno_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ void uno_init_bootloader(void) {
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration uno_harness_config = {
static const harness_configuration uno_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
6 changes: 3 additions & 3 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// White Panda //
// /////////// //

void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
Expand All @@ -19,7 +19,7 @@ void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void white_enable_can_transceivers(bool enabled) {
static void white_enable_can_transceivers(bool enabled) {
uint8_t t1 = enabled ? 1U : 2U; // leave transceiver 1 enabled to detect CAN ignition
for(uint8_t i=t1; i<=3U; i++) {
white_enable_can_transceiver(i, enabled);
Expand Down Expand Up @@ -65,7 +65,7 @@ void white_set_usb_power_mode(uint8_t mode){
}
}

void white_set_can_mode(uint8_t mode){
static void white_set_can_mode(uint8_t mode){
switch (mode) {
case CAN_MODE_NORMAL:
// B12,B13: disable GMLAN mode
Expand Down
20 changes: 10 additions & 10 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uint8_t can_irq_number[3][3] = {
{ CAN3_TX_IRQn, CAN3_RX0_IRQn, CAN3_SCE_IRQn },
};

bool can_set_speed(uint8_t can_number) {
static bool can_set_speed(uint8_t can_number) {
bool ret = true;
CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
Expand Down Expand Up @@ -227,17 +227,17 @@ void can_rx(uint8_t can_number) {
}
}

void CAN1_TX_IRQ_Handler(void) { process_can(0); }
void CAN1_RX0_IRQ_Handler(void) { can_rx(0); }
void CAN1_SCE_IRQ_Handler(void) { can_sce(0); }
static void CAN1_TX_IRQ_Handler(void) { process_can(0); }
static void CAN1_RX0_IRQ_Handler(void) { can_rx(0); }
static void CAN1_SCE_IRQ_Handler(void) { can_sce(0); }

void CAN2_TX_IRQ_Handler(void) { process_can(1); }
void CAN2_RX0_IRQ_Handler(void) { can_rx(1); }
void CAN2_SCE_IRQ_Handler(void) { can_sce(1); }
static void CAN2_TX_IRQ_Handler(void) { process_can(1); }
static void CAN2_RX0_IRQ_Handler(void) { can_rx(1); }
static void CAN2_SCE_IRQ_Handler(void) { can_sce(1); }

void CAN3_TX_IRQ_Handler(void) { process_can(2); }
void CAN3_RX0_IRQ_Handler(void) { can_rx(2); }
void CAN3_SCE_IRQ_Handler(void) { can_sce(2); }
static void CAN3_TX_IRQ_Handler(void) { process_can(2); }
static void CAN3_RX0_IRQ_Handler(void) { can_rx(2); }
static void CAN3_SCE_IRQ_Handler(void) { can_sce(2); }

bool can_init(uint8_t can_number) {
bool ret = false;
Expand Down
16 changes: 8 additions & 8 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ void process_can(uint8_t can_number);

#ifdef STM32H7
// ITCM RAM and DTCM RAM are the fastest for Cortex-M7 core access
__attribute__((section(".axisram"))) can_buffer(rx_q, CAN_RX_BUFFER_SIZE)
__attribute__((section(".itcmram"))) can_buffer(tx1_q, CAN_TX_BUFFER_SIZE)
__attribute__((section(".itcmram"))) can_buffer(tx2_q, CAN_TX_BUFFER_SIZE)
__attribute__((section(".axisram"))) static can_buffer(rx_q, CAN_RX_BUFFER_SIZE)
__attribute__((section(".itcmram"))) static can_buffer(tx1_q, CAN_TX_BUFFER_SIZE)
__attribute__((section(".itcmram"))) static can_buffer(tx2_q, CAN_TX_BUFFER_SIZE)
#else
can_buffer(rx_q, CAN_RX_BUFFER_SIZE)
can_buffer(tx1_q, CAN_TX_BUFFER_SIZE)
can_buffer(tx2_q, CAN_TX_BUFFER_SIZE)
static can_buffer(rx_q, CAN_RX_BUFFER_SIZE)
static can_buffer(tx1_q, CAN_TX_BUFFER_SIZE)
static can_buffer(tx2_q, CAN_TX_BUFFER_SIZE)
#endif
can_buffer(tx3_q, CAN_TX_BUFFER_SIZE)
can_buffer(txgmlan_q, GMLAN_TX_BUFFER_SIZE)
static can_buffer(tx3_q, CAN_TX_BUFFER_SIZE)
static can_buffer(txgmlan_q, GMLAN_TX_BUFFER_SIZE)
// FIXME:
// cppcheck-suppress misra-c2012-9.3
can_ring *can_queues[] = {&can_tx1_q, &can_tx2_q, &can_tx3_q, &can_txgmlan_q};
Expand Down
6 changes: 3 additions & 3 deletions board/drivers/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ struct fan_state_t {
} fan_state_t;
struct fan_state_t fan_state;

const float FAN_I = 0.001f;

const uint8_t FAN_TICK_FREQ = 8U;
const uint8_t FAN_STALL_THRESHOLD_MIN = 3U;
const uint8_t FAN_STALL_THRESHOLD_MAX = 8U;
Expand All @@ -22,7 +20,7 @@ void fan_set_power(uint8_t percentage) {
fan_state.target_rpm = ((current_board->fan_max_rpm * CLAMP(percentage, 0U, 100U)) / 100U);
}

void llfan_init(void);
static void llfan_init(void);
void fan_init(void) {
fan_state.stall_threshold = FAN_STALL_THRESHOLD_MIN;
fan_state.cooldown_counter = current_board->fan_enable_cooldown_time * FAN_TICK_FREQ;
Expand All @@ -31,6 +29,8 @@ void fan_init(void) {

// Call this at FAN_TICK_FREQ
void fan_tick(void) {
const float FAN_I = 0.001f;

if (current_board->fan_max_rpm > 0U) {
// Measure fan RPM
uint16_t fan_rpm_fast = fan_state.tach_counter * (60U * FAN_TICK_FREQ / 4U); // 4 interrupts per rotation
Expand Down
14 changes: 7 additions & 7 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ uint8_t can_irq_number[3][2] = {

#define CAN_ACK_ERROR 3U

bool can_set_speed(uint8_t can_number) {
static bool can_set_speed(uint8_t can_number) {
bool ret = true;
FDCAN_GlobalTypeDef *FDCANx = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
Expand Down Expand Up @@ -242,14 +242,14 @@ void can_rx(uint8_t can_number) {
}
}

void FDCAN1_IT0_IRQ_Handler(void) { can_rx(0); }
void FDCAN1_IT1_IRQ_Handler(void) { process_can(0); }
static void FDCAN1_IT0_IRQ_Handler(void) { can_rx(0); }
static void FDCAN1_IT1_IRQ_Handler(void) { process_can(0); }

void FDCAN2_IT0_IRQ_Handler(void) { can_rx(1); }
void FDCAN2_IT1_IRQ_Handler(void) { process_can(1); }
static void FDCAN2_IT0_IRQ_Handler(void) { can_rx(1); }
static void FDCAN2_IT1_IRQ_Handler(void) { process_can(1); }

void FDCAN3_IT0_IRQ_Handler(void) { can_rx(2); }
void FDCAN3_IT1_IRQ_Handler(void) { process_can(2); }
static void FDCAN3_IT0_IRQ_Handler(void) { can_rx(2); }
static void FDCAN3_IT1_IRQ_Handler(void) { process_can(2); }

bool can_init(uint8_t can_number) {
bool ret = false;
Expand Down
Loading

0 comments on commit 3df4b6e

Please sign in to comment.