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

enable unusedFunction #1878

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
improvements
  • Loading branch information
0x41head committed Feb 23, 2024
commit de1b0f74a08244a86304c6af78c8970ce15a4df4
14 changes: 0 additions & 14 deletions board/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,6 @@ void print(const char *a) {
}
}

void putui(uint32_t i) {
uint32_t i_copy = i;
char str[11];
uint8_t idx = 10;
str[idx] = '\0';
idx--;
do {
str[idx] = (i_copy % 10U) + 0x30U;
idx--;
i_copy /= 10;
} while (i_copy != 0U);
print(&str[idx + 1U]);
}

void puthx(uint32_t i, uint8_t len) {
const char c[] = "0123456789abcdef";
for (int pos = ((int)len * 4) - 4; pos > -4; pos -= 4) {
Expand Down
24 changes: 0 additions & 24 deletions board/drivers/watchdog.h
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
typedef enum {
WATCHDOG_50_MS = (400U - 1U),
WATCHDOG_500_MS = 4000U,
} WatchdogTimeout;

void watchdog_feed(void) {
IND_WDG->KR = 0xAAAAU;
}

void watchdog_init(WatchdogTimeout timeout) {
// enable watchdog
IND_WDG->KR = 0xCCCCU;
IND_WDG->KR = 0x5555U;

// 32KHz / 4 prescaler = 8000Hz
register_set(&(IND_WDG->PR), 0x0U, IWDG_PR_PR_Msk);
register_set(&(IND_WDG->RLR), timeout, IWDG_RLR_RL_Msk);

// wait for watchdog to be updated
while (IND_WDG->SR != 0U);

// start the countdown
watchdog_feed();
}
1 change: 1 addition & 0 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ bool is_car_safety_mode(uint16_t mode) {

// ***************************** main code *****************************

void test (void){}
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
void __initialize_hardware_early(void) {
early_initialization();
Expand Down
6 changes: 0 additions & 6 deletions board/stm32fx/lluart.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ void uart_rx_ring(uart_ring *q){
EXIT_CRITICAL();
}

void uart_send_break(uart_ring *u) {
while ((u->uart->CR1 & USART_CR1_SBK) != 0);
u->uart->CR1 |= USART_CR1_SBK;
}

// This read after reading SR clears all error interrupts. We don't want compiler warnings, nor optimizations
#define UART_READ_DR(uart) volatile uint8_t t = (uart)->DR; UNUSED(t);
Expand Down Expand Up @@ -78,8 +74,6 @@ void uart_interrupt_handler(uart_ring *q) {
EXIT_CRITICAL();
}

void USART2_IRQ_Handler(void) { uart_interrupt_handler(&uart_ring_debug); }

// ***************************** Hardware setup *****************************

#define DIV_(_PCLK_, _BAUD_) (((_PCLK_) * 25U) / (4U * (_BAUD_)))
Expand Down
42 changes: 0 additions & 42 deletions board/stm32h7/lldac.h
Original file line number Diff line number Diff line change
@@ -1,42 +0,0 @@
void dac_init(DAC_TypeDef *dac, uint8_t channel, bool dma) {
register_set(&dac->CR, 0U, 0xFFFFU);
register_set(&dac->MCR, 0U, 0xFFFFU);

switch(channel) {
case 1:
if (dma) {
register_set_bits(&dac->CR, DAC_CR_DMAEN1);
// register_set(&DAC->CR, (6U << DAC_CR_TSEL1_Pos), DAC_CR_TSEL1);
register_set_bits(&dac->CR, DAC_CR_TEN1);
} else {
register_clear_bits(&dac->CR, DAC_CR_DMAEN1);
}
register_set_bits(&dac->CR, DAC_CR_EN1);
break;
case 2:
if (dma) {
register_set_bits(&dac->CR, DAC_CR_DMAEN2);
} else {
register_clear_bits(&dac->CR, DAC_CR_DMAEN2);
}
register_set_bits(&dac->CR, DAC_CR_EN2);
break;
default:
break;
}
}

// Set channel 1 value, in mV
void dac_set(DAC_TypeDef *dac, uint8_t channel, uint32_t value) {
uint32_t raw_val = MAX(MIN(value * (1UL << 8U) / 3300U, (1UL << 8U)), 0U);
switch(channel) {
case 1:
register_set(&dac->DHR8R1, raw_val, 0xFFU);
break;
case 2:
register_set(&dac->DHR8R2, raw_val, 0xFFU);
break;
default:
break;
}
}
3 changes: 1 addition & 2 deletions tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ unmatchedSuppression
# All interrupt handlers are defined, including ones we don't use
unusedFunction:*/interrupt_handlers*.h

# REGISTER_INTERRUPT defined in interrupt_handlers.h
unknownMacro:*/gmlan_alt.h
unknownMacro

# all of the below suppressions are from new checks introduced after updating
# cppcheck from 2.5 -> 2.13. they are listed here to separate the update from
Expand Down
7 changes: 5 additions & 2 deletions tests/misra/test_misra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
cppcheck $PANDA_OPTS -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c

# unused needs to run globally
printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n"
cppcheck --enable=unusedFunction --quiet $PANDA_DIR/board/main.c
printf "\n${GREEN}** UNUSED H7 CODE **${NC}\n"
cppcheck --enable=unusedFunction --quiet -DSTM32H7 $(find $PANDA_DIR/board/ -type f -name '*[ch]')

printf "\n${GREEN}** UNUSED F4 CODE **${NC}\n"
cppcheck --enable=unusedFunction --quiets -DSTM32F4 $(find $PANDA_DIR/board/ -type f -name '*[ch]')

printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"

Loading