From 3c3aba3dbcf18d0d4f9f11dc615d2f45ec32603f Mon Sep 17 00:00:00 2001 From: rbiasini Date: Thu, 4 Jul 2019 01:04:58 -0700 Subject: [PATCH] Misra 10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category (#240) * Almost done with 10.4, a couple of non-obvious violations remaining --- board/config.h | 2 +- board/drivers/can.h | 24 ++++++++++------ board/drivers/gmlan_alt.h | 4 +-- board/drivers/llcan.h | 10 +++---- board/drivers/spi.h | 4 +-- board/drivers/uart.h | 28 +++++++++---------- board/drivers/usb.h | 12 ++++---- board/gpio.h | 8 ++++-- board/main.c | 58 +++++++++++++++++++-------------------- board/power_saving.h | 4 +-- board/safety.h | 30 ++++++++++---------- 11 files changed, 97 insertions(+), 87 deletions(-) diff --git a/board/config.h b/board/config.h index 0ce1bd423d4fe2..7fd203fc30e958 100644 --- a/board/config.h +++ b/board/config.h @@ -34,7 +34,7 @@ __typeof__ (b) _b = (b); \ (_a > _b) ? _a : _b; }) -#define MAX_RESP_LEN 0x40 +#define MAX_RESP_LEN 0x40U #endif diff --git a/board/drivers/can.h b/board/drivers/can.h index dbc1eb85d9d3d3..e6ad107b60157a 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -12,7 +12,7 @@ typedef struct { #define CAN_BUS_RET_FLAG 0x80U #define CAN_BUS_NUM_MASK 0x7FU -#define BUS_MAX 4 +#define BUS_MAX 4U extern int can_live, pending_can_live; @@ -63,8 +63,11 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { enter_critical_section(); if (q->w_ptr != q->r_ptr) { *elem = q->elems[q->r_ptr]; - if ((q->r_ptr + 1) == q->fifo_size) q->r_ptr = 0; - else q->r_ptr += 1; + if ((q->r_ptr + 1U) == q->fifo_size) { + q->r_ptr = 0; + } else { + q->r_ptr += 1U; + } ret = 1; } exit_critical_section(); @@ -77,8 +80,11 @@ bool can_push(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) { uint32_t next_w_ptr; enter_critical_section(); - if ((q->w_ptr + 1) == q->fifo_size) next_w_ptr = 0; - else next_w_ptr = q->w_ptr + 1; + if ((q->w_ptr + 1U) == q->fifo_size) { + next_w_ptr = 0; + } else { + next_w_ptr = q->w_ptr + 1U; + } if (next_w_ptr != q->r_ptr) { q->elems[q->w_ptr] = *elem; q->w_ptr = next_w_ptr; @@ -130,7 +136,7 @@ void can_set_speed(uint8_t can_number) { CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number); uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number); - if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, can_silent & (1U << can_number))) { + if (!llcan_set_speed(CAN, can_speed[bus_number], can_loopback, (unsigned int)(can_silent) & (1U << can_number))) { puts("CAN init FAILED!!!!!\n"); puth(can_number); puts(" "); puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n"); @@ -138,7 +144,7 @@ void can_set_speed(uint8_t can_number) { } void can_init(uint8_t can_number) { - if (can_number != 0xff) { + if (can_number != 0xffU) { CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number); set_can_enable(CAN, 1); can_set_speed(can_number); @@ -229,7 +235,7 @@ void can_sce(CAN_TypeDef *CAN) { // ***************************** CAN ***************************** void process_can(uint8_t can_number) { - if (can_number != 0xff) { + if (can_number != 0xffU) { enter_critical_section(); @@ -343,7 +349,7 @@ void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) { // add CAN packet to send queue // bus number isn't passed through to_push->RDTR &= 0xF; - if ((bus_number == 3) && (can_num_lookup[3] == 0xFF)) { + if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) { // TODO: why uint8 bro? only int8? bitbang_gmlan(to_push); } else { diff --git a/board/drivers/gmlan_alt.h b/board/drivers/gmlan_alt.h index b362a95bf7eb7a..dcf27ade71bc69 100644 --- a/board/drivers/gmlan_alt.h +++ b/board/drivers/gmlan_alt.h @@ -44,7 +44,7 @@ int append_crc(char *in, int in_len) { unsigned int crc = 0; for (int i = 0; i < in_len; i++) { crc <<= 1; - if ((in[i] ^ ((crc >> 15) & 1U)) != 0) { + if ((in[i] ^ ((crc >> 15) & 1U)) != 0U) { crc = crc ^ 0x4599U; } crc &= 0x7fffU; @@ -95,7 +95,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) { // extended identifier len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier len = append_int(pkt, len, 3, 2); // SRR+IDE - len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1U << 18) - 1), 18); // Identifier + len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1U << 18) - 1U), 18); // Identifier len = append_int(pkt, len, 0, 3); // RTR+r1+r0 } else { // standard identifier diff --git a/board/drivers/llcan.h b/board/drivers/llcan.h index 293f40dfe41780..c2aa0dd3512009 100644 --- a/board/drivers/llcan.h +++ b/board/drivers/llcan.h @@ -1,12 +1,12 @@ // this is needed for 1 mbps support -#define CAN_QUANTA 8 +#define CAN_QUANTA 8U #define CAN_SEQ1 6 // roundf(quanta * 0.875f) - 1; #define CAN_SEQ2 1 // roundf(quanta * 0.125f); -#define CAN_PCLK 24000 +#define CAN_PCLK 24000U // 333 = 33.3 kbps // 5000 = 500 kbps -#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10 / (x)) +#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10U / (x)) void puts(const char *a); @@ -18,7 +18,7 @@ bool llcan_set_speed(CAN_TypeDef *CAN, uint32_t speed, bool loopback, bool silen // set time quanta from defines CAN->BTR = (CAN_BTR_TS1_0 * (CAN_SEQ1-1)) | (CAN_BTR_TS2_0 * (CAN_SEQ2-1)) | - (can_speed_to_prescaler(speed) - 1); + (can_speed_to_prescaler(speed) - 1U); // silent loopback mode for debugging if (loopback) { @@ -51,7 +51,7 @@ void llcan_init(CAN_TypeDef *CAN) { CAN->sFilterRegister[0].FR2 = 0; CAN->sFilterRegister[14].FR1 = 0; CAN->sFilterRegister[14].FR2 = 0; - CAN->FA1R |= 1 | (1U << 14); + CAN->FA1R |= 1U | (1U << 14); CAN->FMR &= ~(CAN_FMR_FINIT); diff --git a/board/drivers/spi.h b/board/drivers/spi.h index 44d618257ce902..26690984de7bb8 100644 --- a/board/drivers/spi.h +++ b/board/drivers/spi.h @@ -113,12 +113,12 @@ void DMA2_Stream3_IRQHandler(void) { } void EXTI4_IRQHandler(void) { - volatile int pr = EXTI->PR & (1U << 4); + volatile unsigned int pr = EXTI->PR & (1U << 4); #ifdef DEBUG_SPI puts("exti4\n"); #endif // SPI CS falling - if ((pr & (1U << 4)) != 0) { + if ((pr & (1U << 4)) != 0U) { spi_total_count = 0; spi_rx_dma(spi_buf, 0x14); } diff --git a/board/drivers/uart.h b/board/drivers/uart.h index 6eef563e1e1c88..351e1f95114e34 100644 --- a/board/drivers/uart.h +++ b/board/drivers/uart.h @@ -1,6 +1,6 @@ // IRQs: USART1, USART2, USART3, UART5 -#define FIFO_SIZE 0x400 +#define FIFO_SIZE 0x400U typedef struct uart_ring { volatile uint16_t w_ptr_tx; volatile uint16_t r_ptr_tx; @@ -81,7 +81,7 @@ void uart_ring_process(uart_ring *q) { if (q->w_ptr_tx != q->r_ptr_tx) { if ((sr & USART_SR_TXE) != 0) { q->uart->DR = q->elems_tx[q->r_ptr_tx]; - q->r_ptr_tx = (q->r_ptr_tx + 1) % FIFO_SIZE; + q->r_ptr_tx = (q->r_ptr_tx + 1U) % FIFO_SIZE; } // there could be more to send q->uart->CR1 |= USART_CR1_TXEIE; @@ -93,7 +93,7 @@ void uart_ring_process(uart_ring *q) { if ((sr & USART_SR_RXNE) || (sr & USART_SR_ORE)) { uint8_t c = q->uart->DR; // TODO: can drop packets if (q != &esp_ring) { - uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = c; q->w_ptr_rx = next_w_ptr; @@ -124,7 +124,7 @@ bool getc(uart_ring *q, char *elem) { enter_critical_section(); if (q->w_ptr_rx != q->r_ptr_rx) { if (elem != NULL) *elem = q->elems_rx[q->r_ptr_rx]; - q->r_ptr_rx = (q->r_ptr_rx + 1) % FIFO_SIZE; + q->r_ptr_rx = (q->r_ptr_rx + 1U) % FIFO_SIZE; ret = true; } exit_critical_section(); @@ -137,7 +137,7 @@ bool injectc(uart_ring *q, char elem) { uint16_t next_w_ptr; enter_critical_section(); - next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = elem; q->w_ptr_rx = next_w_ptr; @@ -153,7 +153,7 @@ bool putc(uart_ring *q, char elem) { uint16_t next_w_ptr; enter_critical_section(); - next_w_ptr = (q->w_ptr_tx + 1) % FIFO_SIZE; + next_w_ptr = (q->w_ptr_tx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_tx) { q->elems_tx[q->w_ptr_tx] = elem; q->w_ptr_tx = next_w_ptr; @@ -195,10 +195,10 @@ void clear_uart_buff(uart_ring *q) { // ***************************** start UART code ***************************** -#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25) / (4 * (_BAUD_))) -#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100) -#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16) + 50) / 100) -#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F)) +#define __DIV(_PCLK_, _BAUD_) (((_PCLK_) * 25U) / (4U * (_BAUD_))) +#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_)) / 100U) +#define __DIVFRAQ(_PCLK_, _BAUD_) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U) +#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU)) void uart_set_baud(USART_TypeDef *u, unsigned int baud) { if (u == USART1) { @@ -226,7 +226,7 @@ void uart_dma_drain(void) { unsigned int i; for (i = 0; i < (USART1_DMA_LEN - DMA2_Stream5->NDTR); i++) { char c = usart1_dma[i]; - uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE; + uint16_t next_w_ptr = (q->w_ptr_rx + 1U) % FIFO_SIZE; if (next_w_ptr != q->r_ptr_rx) { q->elems_rx[q->w_ptr_rx] = c; q->w_ptr_rx = next_w_ptr; @@ -322,11 +322,11 @@ void putui(uint32_t i) { str[idx] = '\0'; idx--; do { - str[idx] = (i_copy % 10) + 0x30; + str[idx] = (i_copy % 10U) + 0x30U; idx--; i_copy /= 10; - } while (i_copy != 0); - puts(str + idx + 1); + } while (i_copy != 0U); + puts(str + idx + 1U); } void puth(unsigned int i) { diff --git a/board/drivers/usb.h b/board/drivers/usb.h index ae82b276543d83..5102ca46728fe7 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -394,8 +394,8 @@ int current_int0_alt_setting = 0; // packet read and write void *USB_ReadPacket(void *dest, uint16_t len) { - uint32_t i=0; - uint32_t count32b = (len + 3) / 4; + uint32_t i = 0; + uint32_t count32b = (len + 3U) / 4U; for ( i = 0; i < count32b; i++) { // packed? @@ -411,9 +411,9 @@ void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) { hexdump(src, len); #endif - uint8_t numpacket = (len+(MAX_RESP_LEN-1))/MAX_RESP_LEN; + uint8_t numpacket = (len + (MAX_RESP_LEN - 1U)) / MAX_RESP_LEN; uint32_t count32b = 0, i = 0; - count32b = (len + 3) / 4; + count32b = (len + 3U) / 4U; // bullshit USBx_INEP(ep)->DIEPTSIZ = ((numpacket << 19) & USB_OTG_DIEPTSIZ_PKTCNT) | @@ -983,12 +983,12 @@ void usb_irqhandler(void) { puts(" IN PACKET QUEUE\n"); #endif - if ((ep0_txlen != 0) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40)) { + if ((ep0_txlen != 0U) && ((USBx_INEP(0)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= 0x40U)) { uint16_t len = MIN(ep0_txlen, 0x40); USB_WritePacket(ep0_txdata, len, 0); ep0_txdata += len; ep0_txlen -= len; - if (ep0_txlen == 0) { + if (ep0_txlen == 0U) { ep0_txdata = NULL; USBx_DEVICE->DIEPEMPMSK &= ~1; USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK; diff --git a/board/gpio.h b/board/gpio.h index 255789a0414b30..177adabee1c7f9 100644 --- a/board/gpio.h +++ b/board/gpio.h @@ -410,9 +410,13 @@ void early(void) { // if wrong chip, reboot volatile unsigned int id = DBGMCU->IDCODE; #ifdef STM32F4 - if ((id&0xFFF) != 0x463) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + if ((id & 0xFFFU) != 0x463U) { + enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + } #else - if ((id&0xFFF) != 0x411) enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + if ((id & 0xFFFU) != 0x411U) { + enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; + } #endif // setup interrupt table diff --git a/board/main.c b/board/main.c index 4d29d2fa469b18..b8bcb1debc1d98 100644 --- a/board/main.c +++ b/board/main.c @@ -70,8 +70,8 @@ bool is_gpio_started(void) { } void EXTI1_IRQHandler(void) { - volatile int pr = EXTI->PR & (1U << 1); - if ((pr & (1U << 1)) != 0) { + volatile unsigned int pr = EXTI->PR & (1U << 1); + if ((pr & (1U << 1)) != 0U) { #ifdef DEBUG puts("got started interrupt\n"); #endif @@ -117,7 +117,7 @@ int get_health_pkt(void *dat) { // s = 1000/((4095/3.3)*(1/11)) = 8.8623046875 // Avoid needing floating point math - health->voltage_pkt = (voltage * 8862) / 1000; + health->voltage_pkt = (voltage * 8862U) / 1000U; health->current_pkt = adc_get(ADCCHAN_CURRENT); int safety_ignition = safety_ignition_hook(); @@ -154,7 +154,7 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, bool hardwired) { UNUSED(hardwired); uart_ring *ur = get_ring_by_number(usbdata[0]); if ((len != 0) && (ur != NULL)) { - if ((usbdata[0] < 2) || safety_tx_lin_hook(usbdata[0]-2, usbdata+1, len-1)) { + if ((usbdata[0] < 2U) || safety_tx_lin_hook(usbdata[0] - 2U, usbdata + 1, len - 1)) { for (int i = 1; i < len; i++) { while (!putc(ur, usbdata[i])) { // wait @@ -191,7 +191,7 @@ void usb_cb_enumeration_complete() { } int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) { - int resp_len = 0; + unsigned int resp_len = 0; uart_ring *ur = NULL; int i; switch (setup->b.bRequest) { @@ -211,7 +211,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xd0: fetch serial number case 0xd0: // addresses are OTP - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { (void)memcpy(resp, (void *)0x1fff79c0, 0x10); resp_len = 0x10; } else { @@ -249,7 +249,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) case 0xd6: COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN); (void)memcpy(resp, gitversion, sizeof(gitversion)); - resp_len = sizeof(gitversion)-1; + resp_len = sizeof(gitversion) - 1U; break; // **** 0xd8: reset ST case 0xd8: @@ -257,9 +257,9 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xd9: set ESP power case 0xd9: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { set_esp_mode(ESP_ENABLED); - } else if (setup->b.wValue.w == 2) { + } else if (setup->b.wValue.w == 2U) { set_esp_mode(ESP_BOOTMODE); } else { set_esp_mode(ESP_DISABLED); @@ -269,7 +269,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) case 0xda: set_esp_mode(ESP_DISABLED); delay(1000000); - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { set_esp_mode(ESP_BOOTMODE); } else { set_esp_mode(ESP_ENABLED); @@ -279,11 +279,11 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xdb: set GMLAN multiplexing mode case 0xdb: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { // GMLAN ON - if (setup->b.wIndex.w == 1) { + if (setup->b.wIndex.w == 1U) { can_set_gmlan(1); - } else if (setup->b.wIndex.w == 2) { + } else if (setup->b.wIndex.w == 2U) { can_set_gmlan(2); } else { puts("Invalid bus num for GMLAN CAN set\n"); @@ -334,7 +334,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) if ((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w < BUS_MAX) && (setup->b.wValue.w != setup->b.wIndex.w)) { // set forwarding can_set_forwarding(setup->b.wValue.w, setup->b.wIndex.w & CAN_BUS_NUM_MASK); - } else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFF)){ //Clear Forwarding + } else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFFU)){ //Clear Forwarding can_set_forwarding(setup->b.wValue.w, -1); } else { puts("Invalid CAN bus forwarding\n"); @@ -350,7 +350,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) // **** 0xdf: set long controls allowed case 0xdf: if (hardwired) { - long_controls_allowed = setup->b.wValue.w & 1; + long_controls_allowed = setup->b.wValue.w & 1U; } break; // **** 0xe0: uart read @@ -411,15 +411,15 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xe5: set CAN loopback (for testing) case 0xe5: - can_loopback = (setup->b.wValue.w > 0); + can_loopback = (setup->b.wValue.w > 0U); can_init_all(); break; // **** 0xe6: set USB power case 0xe6: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { puts("user setting CDP mode\n"); set_usb_power_mode(USB_POWER_CDP); - } else if (setup->b.wValue.w == 2) { + } else if (setup->b.wValue.w == 2U) { puts("user setting DCP mode\n"); set_usb_power_mode(USB_POWER_DCP); } else { @@ -429,7 +429,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xf0: do k-line wValue pulse on uart2 for Acura case 0xf0: - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->ODR &= ~(1U << 10); GPIOC->MODER &= ~GPIO_MODER_MODER10_1; GPIOC->MODER |= GPIO_MODER_MODER10_0; @@ -441,7 +441,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) for (i = 0; i < 80; i++) { delay(8000); - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->ODR |= (1U << 10); GPIOC->ODR &= ~(1U << 10); } else { @@ -450,7 +450,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) } } - if (setup->b.wValue.w == 1) { + if (setup->b.wValue.w == 1U) { GPIOC->MODER &= ~GPIO_MODER_MODER10_0; GPIOC->MODER |= GPIO_MODER_MODER10_1; } else { @@ -462,7 +462,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) break; // **** 0xf1: Clear CAN ring buffer. case 0xf1: - if (setup->b.wValue.w == 0xFFFF) { + if (setup->b.wValue.w == 0xFFFFU) { puts("Clearing CAN Rx queue\n"); can_clear(&can_rx_q); } else if (setup->b.wValue.w < BUS_MAX) { @@ -530,7 +530,7 @@ void __initialize_hardware_early(void) { void __attribute__ ((noinline)) enable_fpu(void) { // enable the FPU - SCB->CPACR |= ((3UL << (10U * 2)) | (3UL << (11U * 2))); + SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U))); } uint64_t tcnt = 0; @@ -538,8 +538,8 @@ uint64_t marker = 0; // called once per second void TIM3_IRQHandler(void) { - #define CURRENT_THRESHOLD 0xF00 - #define CLICKS 5 // 5 seconds to switch modes + #define CURRENT_THRESHOLD 0xF00U + #define CLICKS 5U // 5 seconds to switch modes if (TIM3->SR != 0) { can_live = pending_can_live; @@ -550,7 +550,7 @@ void TIM3_IRQHandler(void) { switch (usb_power_mode) { case USB_POWER_CLIENT: - if ((tcnt-marker) >= CLICKS) { + if ((tcnt - marker) >= CLICKS) { if (!is_enumerated) { puts("USBP: didn't enumerate, switching to CDP mode\n"); // switch to CDP @@ -606,7 +606,7 @@ void TIM3_IRQHandler(void) { puts("\n");*/ // reset this every 16th pass - if ((tcnt&0xF) == 0) { + if ((tcnt & 0xFU) == 0U) { pending_can_live = 0; } #ifdef DEBUG @@ -621,10 +621,10 @@ void TIM3_IRQHandler(void) { // turn off the blue LED, turned on by CAN // unless we are in power saving mode - set_led(LED_BLUE, (tcnt & 1) && (power_save_status == POWER_SAVE_STATUS_ENABLED)); + set_led(LED_BLUE, (tcnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED)); // on to the next one - tcnt += 1; + tcnt += 1U; } TIM3->SR = 0; } diff --git a/board/power_saving.h b/board/power_saving.h index 986adf3ce29ff5..3a9ae39e433dc2 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -13,14 +13,14 @@ void set_power_save_state(int state) { if (is_grey_panda) { char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78"; uart_ring *ur = get_ring_by_number(1); - for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i])); + for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i])); } } else { puts("disable power savings\n"); if (is_grey_panda) { char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a"; uart_ring *ur = get_ring_by_number(1); - for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i])); + for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i])); } enable = true; } diff --git a/board/safety.h b/board/safety.h index dd99e6db2ee6dd..6b2b5a045e0389 100644 --- a/board/safety.h +++ b/board/safety.h @@ -44,21 +44,21 @@ typedef struct { const safety_hooks *hooks; } safety_hook_config; -#define SAFETY_NOOUTPUT 0 -#define SAFETY_HONDA 1 -#define SAFETY_TOYOTA 2 -#define SAFETY_GM 3 -#define SAFETY_HONDA_BOSCH 4 -#define SAFETY_FORD 5 -#define SAFETY_CADILLAC 6 -#define SAFETY_HYUNDAI 7 -#define SAFETY_TESLA 8 -#define SAFETY_CHRYSLER 9 -#define SAFETY_SUBARU 10 -#define SAFETY_GM_ASCM 0x1334 -#define SAFETY_TOYOTA_IPAS 0x1335 -#define SAFETY_ALLOUTPUT 0x1337 -#define SAFETY_ELM327 0xE327 +#define SAFETY_NOOUTPUT 0U +#define SAFETY_HONDA 1U +#define SAFETY_TOYOTA 2U +#define SAFETY_GM 3U +#define SAFETY_HONDA_BOSCH 4U +#define SAFETY_FORD 5U +#define SAFETY_CADILLAC 6U +#define SAFETY_HYUNDAI 7U +#define SAFETY_TESLA 8U +#define SAFETY_CHRYSLER 9U +#define SAFETY_SUBARU 10U +#define SAFETY_GM_ASCM 0x1334U +#define SAFETY_TOYOTA_IPAS 0x1335U +#define SAFETY_ALLOUTPUT 0x1337U +#define SAFETY_ELM327 0xE327U const safety_hook_config safety_hook_registry[] = { {SAFETY_NOOUTPUT, &nooutput_hooks},