Skip to content

Commit 718f5db

Browse files
committed
cppcheck mods for safety.c
1 parent 2d16828 commit 718f5db

File tree

9 files changed

+35
-17
lines changed

9 files changed

+35
-17
lines changed

board/drivers/can_common_declarations.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,3 @@ void can_set_checksum(CANPacket_t *packet);
8686
bool can_check_checksum(CANPacket_t *packet);
8787
void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook);
8888
bool is_speed_valid(uint32_t speed, const uint32_t *all_speeds, uint8_t len);
89-
90-
// From opendbc/safety
91-
extern bool safety_tx_hook(CANPacket_t *to_send);

board/drivers/registers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "registers_declarations.h"
2+
#include "safety/board/faults_declarations.h"
23

34
static reg register_map[REGISTER_MAP_SIZE];
45

board/faults.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,3 @@
3636

3737
// Permanent faults
3838
#define PERMANENT_FAULTS 0U
39-
40-
extern uint8_t fault_status;
41-
extern uint32_t faults;
42-
43-
extern void fault_occurred(uint32_t fault);
44-
extern void fault_recovered(uint32_t fault);

board/libc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void assert_fatal(bool condition, const char *msg) {
1515
}
1616
}
1717

18-
// cppcheck-suppress misra-c2012-21.2
18+
// cppcheck-suppress [misra-c2012-21.2,unusedFunction]
1919
void *memset(void *str, int c, unsigned int n) {
2020
uint8_t *s = str;
2121
for (unsigned int i = 0; i < n; i++) {

board/safety.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
// Until opendbc is properly converted to source/header format, we compile our
2+
// own bespoke safety object file so that we can link opendbc implementations
3+
// into panda.
14
#include <stdint.h>
25
#include <stdbool.h>
36

47
extern void print(const char *a);
58
extern void puth(unsigned int i);
69
extern uint32_t microsecond_timer_get(void);
710

11+
// Suppress funky header inclusion ordering. We need the forward declarations
12+
// above. This will all eventually be deleted when opendbc is fixed.
13+
// cppcheck-suppress-begin misra-c2012-20.1 -
814
#include "safety/board/utils.h"
9-
#include "safety/board/faults_declarations.h"
15+
#include "safety/board/faults.h"
1016
#include "safety/board/can.h"
1117
#include "safety/board/drivers/can_common.h"
1218
#include "safety/safety.h"
19+
// cppcheck-suppress-end misra-c2012-20.1

tests/libpanda/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ env = Environment(
2020
".",
2121
"../../board/",
2222
"../../../opendbc/",
23+
"../../../opendbc/safety/",
24+
"../../../opendbc/safety/board/",
2325
],
2426
)
2527
if system == "Darwin":

tests/libpanda/panda.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include "fake_stm.h"
22
#include "config.h"
3-
#include "safety/board/can.h"
4-
#include "safety/board/drivers/can_common.h"
3+
#include "can.h"
54

65
bool can_init(uint8_t can_number) { return true; }
76
void process_can(uint8_t can_number) { }
8-
bool safety_tx_hook(CANPacket_t *to_send) { return 1; }
7+
//int safety_tx_hook(CANPacket_t *to_send) { return 1; }
98

109
typedef struct harness_configuration harness_configuration;
1110
void refresh_can_tx_slots_available(void);
@@ -16,6 +15,9 @@ void can_tx_comms_resume_spi(void) { };
1615
#include "faults.h"
1716
#include "libc.h"
1817
#include "boards/board_declarations.h"
18+
#include "safety/board/drivers/can_common.h"
19+
#include "safety/board/faults.h"
20+
#include "safety/safety.h"
1921
#include "main_definitions.h"
2022
#include "drivers/can_common.h"
2123

tests/misra/suppressions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ unmatchedSuppression
1515
# All interrupt handlers are defined, including ones we don't use
1616
unusedFunction:*/interrupt_handlers*.h
1717

18+
# This header is generated by the SConscript, is working as intended.
19+
misra-c2012-8.9:*/gitversion.h
20+
21+
# dlc_to_len is statically defined in opendbc repo, thus the dlc_to_len definitions is
22+
# duplicated whenever the header is included. This will fixed when opendbc is converted
23+
# to source/header-style
24+
misra-c2012-5.9:*/safety/board/can.h
25+
1826
# all of the below suppressions are from new checks introduced after updating
1927
# cppcheck from 2.5 -> 2.13. they are listed here to separate the update from
2028
# fixing the violations and all are intended to be removed soon after

tests/misra/test_misra.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ cppcheck() {
4444
echo -e "\n\n\n\n\nTEST variant options:" >> $CHECKLIST
4545
echo -e ""${@//$PANDA_DIR/}"\n\n" >> $CHECKLIST # (absolute path removed)
4646

47-
$CPPCHECK_DIR/cppcheck --inline-suppr \
47+
$CPPCHECK_DIR/cppcheck \
48+
--inline-suppr \
4849
-I "$(arm-none-eabi-gcc -print-file-name=include)" \
4950
-I $PANDA_DIR/board/ \
5051
-I $PANDA_DIR/board/stm32f4/inc/ \
5152
-I $PANDA_DIR/board/stm32h7/inc/ \
5253
-I $PANDA_DIR/../opendbc/ \
54+
-I $PANDA_DIR/../opendbc/safety/ \
55+
-I $PANDA_DIR/../opendbc/safety/board/ \
5356
--suppressions-list=$DIR/suppressions.txt \
5457
--suppress=*:*inc/* \
5558
--suppress=*:*include/* \
@@ -68,12 +71,16 @@ cppcheck() {
6871
}
6972

7073
PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA --addon=misra"
74+
# TODO: Make jungle/main.c and bootstub.c MISRA-compliant.
75+
PANDA_SOURCES="$PANDA_DIR/board/ --file-filter=*.c \
76+
-i $PANDA_DIR/board/jungle/main.c \
77+
-i $PANDA_DIR/board/bootstub.c"
7178

7279
printf "\n${GREEN}** PANDA F4 CODE **${NC}\n"
73-
cppcheck $PANDA_OPTS -DSTM32F4 -DSTM32F413xx $PANDA_DIR/board/main.c
80+
cppcheck $PANDA_OPTS -DSTM32F4 -DSTM32F413xx $PANDA_SOURCES
7481

7582
printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
76-
cppcheck $PANDA_OPTS -DSTM32H7 -DSTM32H725xx $PANDA_DIR/board/main.c
83+
cppcheck $PANDA_OPTS -DSTM32H7 -DSTM32H725xx $PANDA_SOURCES
7784

7885
# unused needs to run globally
7986
#printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n"

0 commit comments

Comments
 (0)