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
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 .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Build FW
run: ${{ env.RUN }} "scons -j$(nproc)"
- name: Run MISRA C:2012 analysis
timeout-minutes: 1
timeout-minutes: 2
run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh"
- name: MISRA mutation tests
timeout-minutes: 4
Expand Down
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();
}
25 changes: 12 additions & 13 deletions board/jungle/main.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// ********************* Includes *********************
#include "board/config.h"
#include "../config.h"

#include "board/safety.h"
#include "../safety.h"

#include "board/drivers/pwm.h"
#include "board/drivers/usb.h"
#include "../drivers/pwm.h"
#include "../drivers/usb.h"

#include "board/early_init.h"
#include "board/provision.h"
#include "../early_init.h"
#include "../provision.h"

#include "board/health.h"
#include "../health.h"
#include "jungle_health.h"

#include "board/drivers/can_common.h"
#include "../drivers/can_common.h"

#ifdef STM32H7
#include "board/drivers/fdcan.h"
#include "../drivers/fdcan.h"
#else
#include "board/drivers/bxcan.h"
#include "../drivers/bxcan.h"
#endif

#include "board/obj/gitversion.h"
#include "../obj/gitversion.h"

#include "board/can_comms.h"
#include "../can_comms.h"
#include "main_comms.h"


// ********************* Serial debugging *********************

void debug_ring_callback(uart_ring *ring) {
Expand Down
6 changes: 0 additions & 6 deletions board/stm32f4/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;
}
}
2 changes: 2 additions & 0 deletions tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ unmatchedSuppression
# All interrupt handlers are defined, including ones we don't use
unusedFunction:*/interrupt_handlers*.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
# fixing the violations and all are intended to be removed soon after
Expand Down
15 changes: 10 additions & 5 deletions tests/misra/test_misra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@ cppcheck() {
fi
}

PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA --addon=misra"
PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA -DUID_BASE --addon=misra"

printf "\n${GREEN}** PANDA F4 CODE **${NC}\n"
cppcheck $PANDA_OPTS -DSTM32F4 -DUID_BASE $PANDA_DIR/board/main.c
cppcheck $PANDA_OPTS -DSTM32F4 $PANDA_DIR/board/main.c

printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
cppcheck $PANDA_OPTS -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c
cppcheck $PANDA_OPTS -DSTM32H7 $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/
UNUSED_FUNCTION_OPTS="--enable=unusedFunction --quiet -DPANDA -DFINAL_PROVISIONING"

printf "\n${GREEN}** UNUSED H7 CODE **${NC}\n"
cppcheck $UNUSED_FUNCTION_OPTS -DSTM32H7 $(find $PANDA_DIR/board/ -type f -name '*.[ch]')

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

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

2 changes: 2 additions & 0 deletions tests/misra/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
r"$a #define auto 1\n",
# misra-c2012-20.5
r"$a #define TEST 1\n#undef TEST\n",
# unusedFunction
r"$a void test(void) {}",
]

all_files = glob.glob('board/**', root_dir=ROOT, recursive=True)
Expand Down
Loading