Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling misra-c2012-8.4 #1893

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Export('base_project_f4', 'base_project_h7', 'build_project')

# Common autogenerated includes
with open("board/obj/gitversion.h", "w") as f:
f.write(f'const uint8_t gitversion[] = "{get_version(BUILDER, BUILD_TYPE)}";\n')
f.write(f'const uint8_t gitversion[] = "{get_version(BUILDER, BUILD_TYPE)}"; // cppcheck-suppress misra-c2012-8.4\n')

with open("board/obj/version", "w") as f:
f.write(f'{get_version(BUILDER, BUILD_TYPE)}')
Expand Down
4 changes: 3 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
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 All @@ -162,6 +162,8 @@ const harness_configuration black_harness_config = {
.adc_channel_SBU2 = 13
};

// Unable to use extern becaouse of a composite struct dos_harness_config
// cppcheck-suppress misra-c2012-8.4
const board board_black = {
.set_bootkick = unused_set_bootkick,
.harness_config = &black_harness_config,
Expand Down
3 changes: 3 additions & 0 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void cuatro_init(void) {
clock_source_init();
}

// To be able to use extern and separate declaration
// all of the functions should have separated declaration from implementation
// cppcheck-suppress misra-c2012-8.4
const board board_cuatro = {
.harness_config = &red_chiplet_harness_config,
.has_obd = true,
Expand Down
4 changes: 3 additions & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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 All @@ -187,6 +187,8 @@ const harness_configuration dos_harness_config = {
.adc_channel_SBU2 = 13
};

// Unable to use extern becaouse of a composite struct dos_harness_config
// cppcheck-suppress misra-c2012-8.4
const board board_dos = {
.harness_config = &dos_harness_config,
.has_obd = true,
Expand Down
2 changes: 2 additions & 0 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

// Most hardware functionality is similar to white panda

// If used extern and struct implemented in board.h purpose of this file vanishes
// cppcheck-suppress misra-c2012-8.4
const board board_grey = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
Expand Down
5 changes: 4 additions & 1 deletion board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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 All @@ -174,6 +174,9 @@ const harness_configuration red_harness_config = {
.adc_channel_SBU2 = 17 //ADC1_INP17
};

// To be able to use extern and separate declaration
// all of the functions should have separated declaration from implementation
// cppcheck-suppress misra-c2012-8.4
const board board_red = {
.set_bootkick = unused_set_bootkick,
.harness_config = &red_harness_config,
Expand Down
4 changes: 3 additions & 1 deletion board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ void red_chiplet_init(void) {
can_flip_buses(0, 2);
}
}

// Extern should be used for declaration, but at the current moment there is no appropriate place for
// the implementation
// cppcheck-suppress misra-c2012-8.4
const harness_configuration red_chiplet_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
Expand Down
7 changes: 5 additions & 2 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Tres (STM32H7) + Harness //
// ///////////////////////////

bool tres_ir_enabled;
bool tres_fan_enabled;
static bool tres_ir_enabled;
static bool tres_fan_enabled;
void tres_update_fan_ir_power(void) {
red_chiplet_set_fan_or_usb_load_switch(tres_ir_enabled || tres_fan_enabled);
}
Expand Down Expand Up @@ -70,6 +70,9 @@ void tres_init(void) {
clock_source_init();
}

// To be able to use extern and separate declaration
// all of the functions should have separated declaration from implementation
// cppcheck-suppress misra-c2012-8.4
const board board_tres = {
.harness_config = &red_chiplet_harness_config,
.has_obd = true,
Expand Down
4 changes: 3 additions & 1 deletion board/boards/uno.h
Original file line number Diff line number Diff line change
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 All @@ -198,6 +198,8 @@ const harness_configuration uno_harness_config = {
.adc_channel_SBU2 = 13
};

// Unable to use extern becaouse of a composite struct uno_harness_config
// cppcheck-suppress misra-c2012-8.4
const board board_uno = {
.harness_config = &uno_harness_config,
.has_obd = true,
Expand Down
4 changes: 3 additions & 1 deletion board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ void white_grey_init_bootloader(void) {
set_gpio_output(GPIOC, 14, 0);
}

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

// Unable to use extern because of composite struct white_harness_config
// cppcheck-suppress misra-c2012-8.4
const board board_white = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
Expand Down
4 changes: 2 additions & 2 deletions board/can_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {
uint8_t data[72];
} asm_buffer;

asm_buffer can_read_buffer = {.ptr = 0U, .tail_size = 0U};
static asm_buffer can_read_buffer = {.ptr = 0U, .tail_size = 0U};

int comms_can_read(uint8_t *data, uint32_t max_len) {
uint32_t pos = 0U;
Expand Down Expand Up @@ -53,7 +53,7 @@ int comms_can_read(uint8_t *data, uint32_t max_len) {
return pos;
}

asm_buffer can_write_buffer = {.ptr = 0U, .tail_size = 0U};
static asm_buffer can_write_buffer = {.ptr = 0U, .tail_size = 0U};

// send on CAN
void comms_can_write(const uint8_t *data, uint32_t len) {
Expand Down
6 changes: 6 additions & 0 deletions board/can_definitions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

// Unable to use extern, because of initialization
// cppcheck-suppress misra-c2012-8.4
const uint8_t PANDA_CAN_CNT = 3U;
// Unable to use extern, because of initialization
// cppcheck-suppress misra-c2012-8.4
const uint8_t PANDA_BUS_CNT = 4U;

// bump this when changing the CAN packet
Expand All @@ -27,6 +31,8 @@ typedef struct {
unsigned char data[CANPACKET_DATA_SIZE_MAX];
} __attribute__((packed, aligned(4))) CANPacket_t;

// Unable to use extern, because of initialization
// cppcheck-suppress misra-c2012-8.4
const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};

#define GET_BUS(msg) ((msg)->bus)
Expand Down
4 changes: 3 additions & 1 deletion board/critical.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ********************* Critical section helpers *********************
volatile bool interrupts_enabled = false;
static volatile bool interrupts_enabled = false;

void enable_interrupts(void) {
interrupts_enabled = true;
Expand All @@ -11,6 +11,8 @@ void disable_interrupts(void) {
__disable_irq();
}

// Used across multiple files, unable to use extern
// cppcheck-suppress misra-c2012-8.4
uint8_t global_critical_depth = 0U;
#define ENTER_CRITICAL() \
__disable_irq(); \
Expand Down
18 changes: 11 additions & 7 deletions board/drivers/bootkick.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
bool bootkick_ign_prev = false;
BootState boot_state = BOOT_BOOTKICK;
uint8_t bootkick_harness_status_prev = HARNESS_STATUS_NC;

uint8_t boot_reset_countdown = 0;
uint8_t waiting_to_boot_countdown = 0;
// Unable to use extern keyword at initialization
// cppcheck-suppress misra-c2012-8.4
bool bootkick_reset_triggered = false;
uint16_t bootkick_last_serial_ptr = 0;

void bootkick_tick(bool ignition, bool recent_heartbeat) {
static bool bootkick_ign_prev = false;
static uint8_t bootkick_harness_status_prev = HARNESS_STATUS_NC;
static BootState boot_state = BOOT_BOOTKICK;
static uint8_t boot_reset_countdown = 0;
static uint8_t waiting_to_boot_countdown = 0;
uint16_t bootkick_last_serial_ptr = 0;
BootState boot_state_prev = boot_state;
const bool harness_inserted = (harness.status != bootkick_harness_status_prev) && (harness.status != HARNESS_STATUS_NC);

Expand Down Expand Up @@ -56,6 +57,9 @@ void bootkick_tick(bool ignition, bool recent_heartbeat) {
// update state
bootkick_ign_prev = ignition;
bootkick_harness_status_prev = harness.status;

// misra-c2012-8.4 exposed this assignment
// cppcheck-suppress unreadVariable
bootkick_last_serial_ptr = uart_ring_som_debug.w_ptr_tx;
if (waiting_to_boot_countdown > 0U) {
waiting_to_boot_countdown--;
Expand Down
11 changes: 6 additions & 5 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// CAN2_TX, CAN2_RX0, CAN2_SCE
// CAN3_TX, CAN3_RX0, CAN3_SCE

// cppcheck-suppress misra-c2012-8.4
CAN_TypeDef *cans[] = {CAN1, CAN2, CAN3};
uint8_t can_irq_number[3][3] = {
{ CAN1_TX_IRQn, CAN1_RX0_IRQn, CAN1_SCE_IRQn },
{ CAN2_TX_IRQn, CAN2_RX0_IRQn, CAN2_SCE_IRQn },
{ CAN3_TX_IRQn, CAN3_RX0_IRQn, CAN3_SCE_IRQn },
};

bool can_set_speed(uint8_t can_number) {
bool ret = true;
Expand All @@ -24,6 +20,11 @@ bool can_set_speed(uint8_t can_number) {
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
uint8_t can_irq_number[3][3] = {
{ CAN1_TX_IRQn, CAN1_RX0_IRQn, CAN1_SCE_IRQn },
{ CAN2_TX_IRQn, CAN2_RX0_IRQn, CAN2_SCE_IRQn },
{ CAN3_TX_IRQn, CAN3_RX0_IRQn, CAN3_SCE_IRQn },
};
CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
uint32_t esr_reg = CANx->ESR;

Expand Down
17 changes: 11 additions & 6 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ typedef struct {
bool canfd_non_iso;
} bus_config_t;

// cppcheck-suppress-begin misra-c2012-8.4
uint32_t safety_tx_blocked = 0;
uint32_t safety_rx_invalid = 0;
uint32_t tx_buffer_overflow = 0;
uint32_t rx_buffer_overflow = 0;
uint32_t gmlan_send_errs = 0;

can_health_t can_health[] = {{0}, {0}, {0}};
// Ignition detected from CAN meessages
bool ignition_can = false;
uint32_t ignition_can_cnt = 0U;
// cppcheck-suppress-end misra-c2012-8.4

extern int can_live;
extern int pending_can_live;
Expand All @@ -31,10 +35,6 @@ extern int pending_can_live;
extern int can_silent;
extern bool can_loopback;

// Ignition detected from CAN meessages
bool ignition_can = false;
uint32_t ignition_can_cnt = 0U;

#define ALL_CAN_SILENT 0xFF
#define ALL_CAN_LIVE 0

Expand All @@ -56,6 +56,8 @@ void process_can(uint8_t can_number);
#define CAN_TX_BUFFER_SIZE 416U
#define GMLAN_TX_BUFFER_SIZE 416U

// It is not practical to implement changes to comply with misra, because of initialization of buffers
// cppcheck-suppress-begin misra-c2012-8.4
#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)
Expand All @@ -68,8 +70,11 @@ 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)
// cppcheck-suppress-end misra-c2012-8.4

// FIXME:
// cppcheck-suppress misra-c2012-9.3
// cppcheck-suppress misra-c2012-8.4
can_ring *can_queues[] = {&can_tx1_q, &can_tx2_q, &can_tx3_q, &can_txgmlan_q};

// helpers
Expand Down Expand Up @@ -167,7 +172,7 @@ void can_clear(can_ring *q) {

// Helpers
// Panda: Bus 0=CAN1 Bus 1=CAN2 Bus 2=CAN3
bus_config_t bus_config[] = {
static bus_config_t bus_config[] = {
{ .bus_lookup = 0U, .can_num_lookup = 0U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 1U, .can_num_lookup = 1U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 2U, .can_num_lookup = 2U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
Expand Down
9 changes: 4 additions & 5 deletions board/drivers/fake_siren.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#define CODEC_I2C_ADDR 0x10

// 1Vpp sine wave with 1V offset
const uint8_t fake_siren_lut[360] = { 134U, 135U, 137U, 138U, 139U, 140U, 141U, 143U, 144U, 145U, 146U, 148U, 149U, 150U, 151U, 152U, 154U, 155U, 156U, 157U, 158U, 159U, 160U, 162U, 163U, 164U, 165U, 166U, 167U, 168U, 169U, 170U, 171U, 172U, 174U, 175U, 176U, 177U, 177U, 178U, 179U, 180U, 181U, 182U, 183U, 184U, 185U, 186U, 186U, 187U, 188U, 189U, 190U, 190U, 191U, 192U, 193U, 193U, 194U, 195U, 195U, 196U, 196U, 197U, 197U, 198U, 199U, 199U, 199U, 200U, 200U, 201U, 201U, 202U, 202U, 202U, 203U, 203U, 203U, 203U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 205U, 205U, 205U, 205U, 205U, 205U, 205U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 203U, 203U, 203U, 203U, 202U, 202U, 202U, 201U, 201U, 200U, 200U, 199U, 199U, 199U, 198U, 197U, 197U, 196U, 196U, 195U, 195U, 194U, 193U, 193U, 192U, 191U, 190U, 190U, 189U, 188U, 187U, 186U, 186U, 185U, 184U, 183U, 182U, 181U, 180U, 179U, 178U, 177U, 177U, 176U, 175U, 174U, 172U, 171U, 170U, 169U, 168U, 167U, 166U, 165U, 164U, 163U, 162U, 160U, 159U, 158U, 157U, 156U, 155U, 154U, 152U, 151U, 150U, 149U, 148U, 146U, 145U, 144U, 143U, 141U, 140U, 139U, 138U, 137U, 135U, 134U, 133U, 132U, 130U, 129U, 128U, 127U, 125U, 124U, 123U, 122U, 121U, 119U, 118U, 117U, 116U, 115U, 113U, 112U, 111U, 110U, 109U, 108U, 106U, 105U, 104U, 103U, 102U, 101U, 100U, 99U, 98U, 97U, 96U, 95U, 94U, 93U, 92U, 91U, 90U, 89U, 88U, 87U, 86U, 85U, 84U, 83U, 82U, 82U, 81U, 80U, 79U, 78U, 78U, 77U, 76U, 76U, 75U, 74U, 74U, 73U, 72U, 72U, 71U, 71U, 70U, 70U, 69U, 69U, 68U, 68U, 67U, 67U, 67U, 66U, 66U, 66U, 65U, 65U, 65U, 65U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 63U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 65U, 65U, 65U, 65U, 66U, 66U, 66U, 67U, 67U, 67U, 68U, 68U, 69U, 69U, 70U, 70U, 71U, 71U, 72U, 72U, 73U, 74U, 74U, 75U, 76U, 76U, 77U, 78U, 78U, 79U, 80U, 81U, 82U, 82U, 83U, 84U, 85U, 86U, 87U, 88U, 89U, 90U, 91U, 92U, 93U, 94U, 95U, 96U, 97U, 98U, 99U, 100U, 101U, 102U, 103U, 104U, 105U, 106U, 108U, 109U, 110U, 111U, 112U, 113U, 115U, 116U, 117U, 118U, 119U, 121U, 122U, 123U, 124U, 125U, 127U, 128U, 129U, 130U, 132U, 133U };

bool fake_siren_enabled = false;

void fake_siren_codec_enable(bool enabled) {
if (enabled) {
bool success = true;
Expand All @@ -33,6 +28,7 @@ void fake_siren_codec_enable(bool enabled) {


void fake_siren_set(bool enabled) {
static bool fake_siren_enabled = false;
if (enabled != fake_siren_enabled) {
fake_siren_codec_enable(enabled);
}
Expand All @@ -46,6 +42,9 @@ void fake_siren_set(bool enabled) {
}

void fake_siren_init(void) {
// 1Vpp sine wave with 1V offset
const uint8_t fake_siren_lut[360] = { 134U, 135U, 137U, 138U, 139U, 140U, 141U, 143U, 144U, 145U, 146U, 148U, 149U, 150U, 151U, 152U, 154U, 155U, 156U, 157U, 158U, 159U, 160U, 162U, 163U, 164U, 165U, 166U, 167U, 168U, 169U, 170U, 171U, 172U, 174U, 175U, 176U, 177U, 177U, 178U, 179U, 180U, 181U, 182U, 183U, 184U, 185U, 186U, 186U, 187U, 188U, 189U, 190U, 190U, 191U, 192U, 193U, 193U, 194U, 195U, 195U, 196U, 196U, 197U, 197U, 198U, 199U, 199U, 199U, 200U, 200U, 201U, 201U, 202U, 202U, 202U, 203U, 203U, 203U, 203U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 205U, 205U, 205U, 205U, 205U, 205U, 205U, 204U, 204U, 204U, 204U, 204U, 204U, 204U, 203U, 203U, 203U, 203U, 202U, 202U, 202U, 201U, 201U, 200U, 200U, 199U, 199U, 199U, 198U, 197U, 197U, 196U, 196U, 195U, 195U, 194U, 193U, 193U, 192U, 191U, 190U, 190U, 189U, 188U, 187U, 186U, 186U, 185U, 184U, 183U, 182U, 181U, 180U, 179U, 178U, 177U, 177U, 176U, 175U, 174U, 172U, 171U, 170U, 169U, 168U, 167U, 166U, 165U, 164U, 163U, 162U, 160U, 159U, 158U, 157U, 156U, 155U, 154U, 152U, 151U, 150U, 149U, 148U, 146U, 145U, 144U, 143U, 141U, 140U, 139U, 138U, 137U, 135U, 134U, 133U, 132U, 130U, 129U, 128U, 127U, 125U, 124U, 123U, 122U, 121U, 119U, 118U, 117U, 116U, 115U, 113U, 112U, 111U, 110U, 109U, 108U, 106U, 105U, 104U, 103U, 102U, 101U, 100U, 99U, 98U, 97U, 96U, 95U, 94U, 93U, 92U, 91U, 90U, 89U, 88U, 87U, 86U, 85U, 84U, 83U, 82U, 82U, 81U, 80U, 79U, 78U, 78U, 77U, 76U, 76U, 75U, 74U, 74U, 73U, 72U, 72U, 71U, 71U, 70U, 70U, 69U, 69U, 68U, 68U, 67U, 67U, 67U, 66U, 66U, 66U, 65U, 65U, 65U, 65U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 63U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 64U, 65U, 65U, 65U, 65U, 66U, 66U, 66U, 67U, 67U, 67U, 68U, 68U, 69U, 69U, 70U, 70U, 71U, 71U, 72U, 72U, 73U, 74U, 74U, 75U, 76U, 76U, 77U, 78U, 78U, 79U, 80U, 81U, 82U, 82U, 83U, 84U, 85U, 86U, 87U, 88U, 89U, 90U, 91U, 92U, 93U, 94U, 95U, 96U, 97U, 98U, 99U, 100U, 101U, 102U, 103U, 104U, 105U, 106U, 108U, 109U, 110U, 111U, 112U, 113U, 115U, 116U, 117U, 118U, 119U, 121U, 122U, 123U, 124U, 125U, 127U, 128U, 129U, 130U, 132U, 133U };

// Init DAC
register_set(&DAC1->MCR, 0U, 0xFFFFFFFFU);
register_set(&DAC1->CR, DAC_CR_TEN1 | (6U << DAC_CR_TSEL1_Pos) | DAC_CR_DMAEN1, 0xFFFFFFFFU);
Expand Down
12 changes: 6 additions & 6 deletions board/drivers/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ struct fan_state_t {
uint8_t stall_threshold;
uint8_t total_stall_count;
uint8_t cooldown_counter;
} fan_state_t;
struct fan_state_t fan_state;
};
static 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;
static const uint8_t FAN_TICK_FREQ = 8U;
static const uint8_t FAN_STALL_THRESHOLD_MIN = 3U;


void fan_set_power(uint8_t percentage) {
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;
const uint8_t FAN_STALL_THRESHOLD_MAX = 8U;
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
Loading