From ac9c1b3b3ffe4b24f461fb3f29d7e9447539a73c Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Fri, 20 Sep 2024 15:51:27 -0700 Subject: [PATCH] misra8.7 (#2033) * 8_7 * fix test --- board/drivers/spi.h | 20 ++++++++++++-------- board/drivers/spi_declarations.h | 2 +- board/drivers/uart.h | 4 ++++ board/drivers/uart_declarations.h | 2 ++ board/early_init.h | 2 +- board/main_comms.h | 2 +- board/safety.h | 2 ++ board/safety_declarations.h | 2 ++ board/stm32f4/llspi.h | 3 ++- board/stm32h7/llspi.h | 5 +++-- 10 files changed, 30 insertions(+), 14 deletions(-) diff --git a/board/drivers/spi.h b/board/drivers/spi.h index 672aedb83..36f4dd29a 100644 --- a/board/drivers/spi.h +++ b/board/drivers/spi.h @@ -14,17 +14,14 @@ uint8_t spi_buf_rx[SPI_BUF_SIZE]; uint8_t spi_buf_tx[SPI_BUF_SIZE]; #endif +uint16_t spi_checksum_error_count = 0; + +#if defined(ENABLE_SPI) || defined(BOOTSTUB) static uint8_t spi_state = SPI_STATE_HEADER; static uint16_t spi_data_len_mosi; -uint16_t spi_checksum_error_count = 0; static bool spi_can_tx_ready = false; - static const unsigned char version_text[] = "VERSION"; -void can_tx_comms_resume_spi(void) { - spi_can_tx_ready = true; -} - static uint16_t spi_version_packet(uint8_t *out) { // this protocol version request is a stable portion of // the panda's SPI protocol. its contents match that of the @@ -69,7 +66,6 @@ static uint16_t spi_version_packet(uint8_t *out) { return resp_len; } -#if defined(ENABLE_SPI) || defined(BOOTSTUB) void spi_init(void) { // platform init llspi_init(); @@ -78,7 +74,6 @@ void spi_init(void) { spi_state = SPI_STATE_HEADER; llspi_mosi_dma(spi_buf_rx, SPI_HEADER_SIZE); } -#endif static bool validate_checksum(const uint8_t *data, uint16_t len) { // TODO: can speed this up by casting the bulk to uint32_t and xor-ing the bytes afterwards @@ -231,3 +226,12 @@ void spi_tx_done(bool reset) { print("SPI: TX unexpected state: "); puth(spi_state); print("\n"); } } + +void can_tx_comms_resume_spi(void) { + spi_can_tx_ready = true; +} +#else +void can_tx_comms_resume_spi(void) { + return; +} +#endif diff --git a/board/drivers/spi_declarations.h b/board/drivers/spi_declarations.h index 022892cea..8c830e6b0 100644 --- a/board/drivers/spi_declarations.h +++ b/board/drivers/spi_declarations.h @@ -47,6 +47,6 @@ void llspi_miso_dma(uint8_t *addr, int len); void can_tx_comms_resume_spi(void); #if defined(ENABLE_SPI) || defined(BOOTSTUB) void spi_init(void); -#endif void spi_rx_done(void); void spi_tx_done(bool reset); +#endif diff --git a/board/drivers/uart.h b/board/drivers/uart.h index 0c3523bf5..737539c95 100644 --- a/board/drivers/uart.h +++ b/board/drivers/uart.h @@ -149,10 +149,13 @@ void puth2(unsigned int i) { puthx(i, 2U); } +#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG) void puth4(unsigned int i) { puthx(i, 4U); } +#endif +#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG_USB) || defined(DEBUG_COMMS) void hexdump(const void *a, int l) { if (a != NULL) { for (int i=0; i < l; i++) { @@ -163,3 +166,4 @@ void hexdump(const void *a, int l) { } print("\n"); } +#endif diff --git a/board/drivers/uart_declarations.h b/board/drivers/uart_declarations.h index 80fffa210..041fd377c 100644 --- a/board/drivers/uart_declarations.h +++ b/board/drivers/uart_declarations.h @@ -34,5 +34,7 @@ void print(const char *a); void puthx(uint32_t i, uint8_t len); void puth(unsigned int i); void puth2(unsigned int i); +#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG) void puth4(unsigned int i); +#endif void hexdump(const void *a, int l); diff --git a/board/early_init.h b/board/early_init.h index 0e78274c3..1837019d0 100644 --- a/board/early_init.h +++ b/board/early_init.h @@ -9,7 +9,7 @@ extern uint32_t enter_bootloader_mode; typedef void (*bootloader_fcn)(void); typedef bootloader_fcn *bootloader_fcn_ptr; -void jump_to_bootloader(void) { +static void jump_to_bootloader(void) { // do enter bootloader enter_bootloader_mode = 0; diff --git a/board/main_comms.h b/board/main_comms.h index d95ba97cb..7d754d050 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -4,7 +4,7 @@ extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used void set_safety_mode(uint16_t mode, uint16_t param); bool is_car_safety_mode(uint16_t mode); -int get_health_pkt(void *dat) { +static int get_health_pkt(void *dat) { COMPILE_TIME_ASSERT(sizeof(struct health_t) <= USBPACKET_MAX_SIZE); struct health_t * health = (struct health_t*)dat; diff --git a/board/safety.h b/board/safety.h index 1c1616e72..2c39bf90a 100644 --- a/board/safety.h +++ b/board/safety.h @@ -107,6 +107,7 @@ void gen_crc_lookup_table_8(uint8_t poly, uint8_t crc_lut[]) { } } +#ifdef CANFD void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) { for (uint16_t i = 0; i < 256U; i++) { uint16_t crc = i << 8U; @@ -120,6 +121,7 @@ void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) { crc_lut[i] = crc; } } +#endif bool msg_allowed(const CANPacket_t *to_send, const CanMsg msg_list[], int len) { int addr = GET_ADDR(to_send); diff --git a/board/safety_declarations.h b/board/safety_declarations.h index c22ae0016..61044294d 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -192,7 +192,9 @@ bool rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA); float interpolate(struct lookup_t xy, float x); int ROUND(float val); void gen_crc_lookup_table_8(uint8_t poly, uint8_t crc_lut[]); +#ifdef CANFD void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]); +#endif bool msg_allowed(const CANPacket_t *to_send, const CanMsg msg_list[], int len); int get_addr_check_index(const CANPacket_t *to_push, RxCheck addr_list[], const int len); void update_counter(RxCheck addr_list[], int index, uint8_t counter); diff --git a/board/stm32f4/llspi.h b/board/stm32f4/llspi.h index a83e322ce..e986adb4a 100644 --- a/board/stm32f4/llspi.h +++ b/board/stm32f4/llspi.h @@ -1,3 +1,4 @@ +#if defined(ENABLE_SPI) || defined(BOOTSTUB) void llspi_miso_dma(uint8_t *addr, int len) { // disable DMA DMA2_Stream3->CR &= ~DMA_SxCR_EN; @@ -29,7 +30,6 @@ void llspi_mosi_dma(uint8_t *addr, int len) { DMA2_Stream2->CR |= DMA_SxCR_EN; register_set_bits(&(SPI1->CR2), SPI_CR2_RXDMAEN); } - // SPI MOSI DMA FINISHED static void DMA2_Stream2_IRQ_Handler(void) { // Clear interrupt flag @@ -88,3 +88,4 @@ void llspi_init(void) { NVIC_EnableIRQ(DMA2_Stream2_IRQn); NVIC_EnableIRQ(DMA2_Stream3_IRQn); } +#endif diff --git a/board/stm32h7/llspi.h b/board/stm32h7/llspi.h index f89eb9752..a5dca37aa 100644 --- a/board/stm32h7/llspi.h +++ b/board/stm32h7/llspi.h @@ -1,5 +1,4 @@ -static bool spi_tx_dma_done = false; - +#if defined(ENABLE_SPI) || defined(BOOTSTUB) // master -> panda DMA start void llspi_mosi_dma(uint8_t *addr, int len) { // disable DMA + SPI @@ -50,6 +49,7 @@ void llspi_miso_dma(uint8_t *addr, int len) { register_set_bits(&(SPI4->CR1), SPI_CR1_SPE); } +static bool spi_tx_dma_done = false; // master -> panda DMA finished static void DMA2_Stream2_IRQ_Handler(void) { // Clear interrupt flag @@ -106,3 +106,4 @@ void llspi_init(void) { NVIC_EnableIRQ(DMA2_Stream3_IRQn); NVIC_EnableIRQ(SPI4_IRQn); } +#endif