Misra 14.4: The controlling expression of an if statement and the controlling expression of an iteration‑statement shall have essentially Boolean type (#225)

* Fixed 14.4 Misra violations
master
rbiasini 2019-06-26 13:13:16 -07:00 committed by GitHub
parent 8a45958dfe
commit 73ae4f6acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 56 deletions

View File

@ -25,7 +25,7 @@ void can_set_forwarding(int from, int to);
void can_init(uint8_t can_number);
void can_init_all(void);
void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number);
int can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem);
bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem);
// end API
@ -57,8 +57,8 @@ int can_overflow_cnt = 0;
// ********************* interrupt safe queue *********************
int can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
int ret = 0;
bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
bool ret = 0;
enter_critical_section();
if (q->w_ptr != q->r_ptr) {
@ -292,7 +292,7 @@ void process_can(uint8_t can_number) {
void can_rx(uint8_t can_number) {
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
while (CAN->RF0R & CAN_RF0R_FMP0) {
while ((CAN->RF0R & CAN_RF0R_FMP0) != 0) {
can_rx_cnt += 1;
// can is live
@ -342,7 +342,7 @@ void CAN3_RX0_IRQHandler(void) { can_rx(2); }
void CAN3_SCE_IRQHandler(void) { can_sce(CAN3); }
void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
if (safety_tx_hook(to_push)) {
if (safety_tx_hook(to_push) != 0) {
if (bus_number < BUS_MAX) {
// add CAN packet to send queue
// bus number isn't passed through

View File

@ -44,7 +44,7 @@ int append_crc(char *in, int in_len) {
int crc = 0;
for (int i = 0; i < in_len; i++) {
crc <<= 1;
if (in[i] ^ ((crc>>15)&1)) {
if ((in[i] ^ ((crc >> 15) & 1)) != 0) {
crc = crc ^ 0x4599;
}
crc &= 0x7fff;
@ -88,7 +88,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
int dlc_len = to_bang->RDTR & 0xF;
len = append_int(pkt, len, 0, 1); // Start-of-frame
if (to_bang->RIR & 4) {
if ((to_bang->RIR & 4) != 0) {
// extended identifier
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
len = append_int(pkt, len, 3, 2); // SRR+IDE
@ -167,7 +167,7 @@ void reset_gmlan_switch_timeout(void) {
}
void set_bitbanged_gmlan(int val) {
if (val) {
if (val != 0) {
GPIOB->ODR |= (1 << 13);
} else {
GPIOB->ODR &= ~(1 << 13);
@ -194,7 +194,7 @@ void TIM4_IRQHandler(void) {
gmlan_silent_count++;
}
} else if (gmlan_silent_count == REQUIRED_SILENT_TIME) {
int retry = 0;
bool retry = 0;
// in send loop
if (gmlan_sending > 0 && // not first bit
(read == 0 && pkt_stuffed[gmlan_sending-1] == 1) && // bus wrongly dominant

View File

@ -15,7 +15,7 @@ void set_gpio_mode(GPIO_TypeDef *GPIO, int pin, int mode) {
}
void set_gpio_output(GPIO_TypeDef *GPIO, int pin, int val) {
if (val) {
if (val != 0) {
GPIO->ODR |= (1 << pin);
} else {
GPIO->ODR &= ~(1 << pin);

View File

@ -118,7 +118,7 @@ void EXTI4_IRQHandler(void) {
puts("exti4\n");
#endif
// SPI CS falling
if (pr & (1 << 4)) {
if ((pr & (1 << 4)) != 0) {
spi_total_count = 0;
spi_rx_dma(spi_buf, 0x14);
}

View File

@ -14,8 +14,8 @@ typedef struct uart_ring {
void uart_init(USART_TypeDef *u, int baud);
int getc(uart_ring *q, char *elem);
int putc(uart_ring *q, char elem);
bool getc(uart_ring *q, char *elem);
bool putc(uart_ring *q, char elem);
void puts(const char *a);
void puth(unsigned int i);
@ -72,7 +72,7 @@ void uart_ring_process(uart_ring *q) {
int sr = q->uart->SR;
if (q->w_ptr_tx != q->r_ptr_tx) {
if (sr & USART_SR_TXE) {
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;
}
@ -90,12 +90,14 @@ void uart_ring_process(uart_ring *q) {
if (next_w_ptr != q->r_ptr_rx) {
q->elems_rx[q->w_ptr_rx] = c;
q->w_ptr_rx = next_w_ptr;
if (q->callback) q->callback(q);
if (q->callback != NULL) {
q->callback(q);
}
}
}
}
if (sr & USART_SR_ORE) {
if ((sr & USART_SR_ORE) != 0) {
// set dropped packet flag?
}
@ -109,22 +111,22 @@ void USART2_IRQHandler(void) { uart_ring_process(&debug_ring); }
void USART3_IRQHandler(void) { uart_ring_process(&lin2_ring); }
void UART5_IRQHandler(void) { uart_ring_process(&lin1_ring); }
int getc(uart_ring *q, char *elem) {
int ret = 0;
bool getc(uart_ring *q, char *elem) {
bool ret = false;
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;
ret = 1;
ret = true;
}
exit_critical_section();
return ret;
}
int injectc(uart_ring *q, char elem) {
int ret = 0;
bool injectc(uart_ring *q, char elem) {
int ret = false;
uint16_t next_w_ptr;
enter_critical_section();
@ -132,15 +134,15 @@ int injectc(uart_ring *q, char elem) {
if (next_w_ptr != q->r_ptr_rx) {
q->elems_rx[q->w_ptr_rx] = elem;
q->w_ptr_rx = next_w_ptr;
ret = 1;
ret = true;
}
exit_critical_section();
return ret;
}
int putc(uart_ring *q, char elem) {
int ret = 0;
bool putc(uart_ring *q, char elem) {
bool ret = false;
uint16_t next_w_ptr;
enter_critical_section();
@ -148,7 +150,7 @@ int putc(uart_ring *q, char elem) {
if (next_w_ptr != q->r_ptr_tx) {
q->elems_tx[q->w_ptr_tx] = elem;
q->w_ptr_tx = next_w_ptr;
ret = 1;
ret = true;
}
exit_critical_section();
@ -171,7 +173,7 @@ void uart_flush_sync(uart_ring *q) {
}
void uart_send_break(uart_ring *u) {
while (u->uart->CR1 & USART_CR1_SBK);
while ((u->uart->CR1 & USART_CR1_SBK) != 0);
u->uart->CR1 |= USART_CR1_SBK;
}
@ -212,7 +214,7 @@ void uart_dma_drain(void) {
// disable DMA
q->uart->CR3 &= ~USART_CR3_DMAR;
DMA2_Stream5->CR &= ~DMA_SxCR_EN;
while (DMA2_Stream5->CR & DMA_SxCR_EN);
while ((DMA2_Stream5->CR & DMA_SxCR_EN) != 0);
unsigned int i;
for (i = 0; i < (USART1_DMA_LEN - DMA2_Stream5->NDTR); i++) {
@ -313,7 +315,7 @@ void putui(uint32_t i) {
str[idx] = (i % 10) + 0x30;
idx--;
i /= 10;
} while (i);
} while (i != 0);
puts(str + idx + 1);
}

View File

@ -758,27 +758,27 @@ void usb_irqhandler(void) {
puts(" USB interrupt!\n");
#endif
if (gintsts & USB_OTG_GINTSTS_CIDSCHG) {
if ((gintsts & USB_OTG_GINTSTS_CIDSCHG) != 0) {
puts("connector ID status change\n");
}
if (gintsts & USB_OTG_GINTSTS_ESUSP) {
if ((gintsts & USB_OTG_GINTSTS_ESUSP) != 0) {
puts("ESUSP detected\n");
}
if (gintsts & USB_OTG_GINTSTS_USBRST) {
if ((gintsts & USB_OTG_GINTSTS_USBRST) != 0) {
puts("USB reset\n");
usb_reset();
}
if (gintsts & USB_OTG_GINTSTS_ENUMDNE) {
if ((gintsts & USB_OTG_GINTSTS_ENUMDNE) != 0) {
puts("enumeration done");
// Full speed, ENUMSPD
//puth(USBx_DEVICE->DSTS);
puts("\n");
}
if (gintsts & USB_OTG_GINTSTS_OTGINT) {
if ((gintsts & USB_OTG_GINTSTS_OTGINT) != 0) {
puts("OTG int:");
puth(USBx->GOTGINT);
puts("\n");
@ -788,7 +788,7 @@ void usb_irqhandler(void) {
}
// RX FIFO first
if (gintsts & USB_OTG_GINTSTS_RXFLVL) {
if ((gintsts & USB_OTG_GINTSTS_RXFLVL) != 0) {
// 1. Read the Receive status pop register
volatile unsigned int rxst = USBx->GRXSTSP;
@ -850,7 +850,7 @@ void usb_irqhandler(void) {
USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGONAK | USB_OTG_DCTL_CGINAK;
}
if (gintsts & USB_OTG_GINTSTS_SRQINT) {
if ((gintsts & USB_OTG_GINTSTS_SRQINT) != 0) {
// we want to do "A-device host negotiation protocol" since we are the A-device
/*puts("start request\n");
puth(USBx->GOTGCTL);
@ -861,7 +861,7 @@ void usb_irqhandler(void) {
}
// out endpoint hit
if (gintsts & USB_OTG_GINTSTS_OEPINT) {
if ((gintsts & USB_OTG_GINTSTS_OEPINT) != 0) {
#ifdef DEBUG_USB
puts(" 0:");
puth(USBx_OUTEP(0)->DOEPINT);
@ -876,7 +876,7 @@ void usb_irqhandler(void) {
puts(" OUT ENDPOINT\n");
#endif
if (USBx_OUTEP(2)->DOEPINT & USB_OTG_DOEPINT_XFRC) {
if ((USBx_OUTEP(2)->DOEPINT & USB_OTG_DOEPINT_XFRC) != 0) {
#ifdef DEBUG_USB
puts(" OUT2 PACKET XFRC\n");
#endif
@ -884,32 +884,32 @@ void usb_irqhandler(void) {
USBx_OUTEP(2)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
}
if (USBx_OUTEP(3)->DOEPINT & USB_OTG_DOEPINT_XFRC) {
if ((USBx_OUTEP(3)->DOEPINT & USB_OTG_DOEPINT_XFRC) != 0) {
#ifdef DEBUG_USB
puts(" OUT3 PACKET XFRC\n");
#endif
USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40;
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_CNAK;
} else if (USBx_OUTEP(3)->DOEPINT & 0x2000) {
} else if ((USBx_OUTEP(3)->DOEPINT & 0x2000) != 0) {
#ifdef DEBUG_USB
puts(" OUT3 PACKET WTF\n");
#endif
// if NAK was set trigger this, unknown interrupt
USBx_OUTEP(3)->DOEPTSIZ = (1 << 19) | 0x40;
USBx_OUTEP(3)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
} else if (USBx_OUTEP(3)->DOEPINT) {
} else if ((USBx_OUTEP(3)->DOEPINT) != 0) {
puts("OUTEP3 error ");
puth(USBx_OUTEP(3)->DOEPINT);
puts("\n");
}
if (USBx_OUTEP(0)->DOEPINT & USB_OTG_DIEPINT_XFRC) {
if ((USBx_OUTEP(0)->DOEPINT & USB_OTG_DIEPINT_XFRC) != 0) {
// ready for next packet
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) | (1 * 8);
}
// respond to setup packets
if (USBx_OUTEP(0)->DOEPINT & USB_OTG_DOEPINT_STUP) {
if ((USBx_OUTEP(0)->DOEPINT & USB_OTG_DOEPINT_STUP) != 0) {
usb_setup();
}
@ -919,7 +919,7 @@ void usb_irqhandler(void) {
}
// interrupt endpoint hit (Page 1221)
if (gintsts & USB_OTG_GINTSTS_IEPINT) {
if ((gintsts & USB_OTG_GINTSTS_IEPINT) != 0) {
#ifdef DEBUG_USB
puts(" ");
puth(USBx_INEP(0)->DIEPINT);
@ -944,7 +944,7 @@ void usb_irqhandler(void) {
switch (current_int0_alt_setting) {
case 0: ////// Bulk config
// *** IN token received when TxFIFO is empty
if (USBx_INEP(1)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) {
if ((USBx_INEP(1)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) != 0) {
#ifdef DEBUG_USB
puts(" IN PACKET QUEUE\n");
#endif
@ -955,7 +955,7 @@ void usb_irqhandler(void) {
case 1: ////// Interrupt config
// *** IN token received when TxFIFO is empty
if (USBx_INEP(1)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) {
if ((USBx_INEP(1)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) != 0) {
#ifdef DEBUG_USB
puts(" IN PACKET QUEUE\n");
#endif
@ -968,7 +968,7 @@ void usb_irqhandler(void) {
break;
}
if (USBx_INEP(0)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) {
if ((USBx_INEP(0)->DIEPINT & USB_OTG_DIEPMSK_ITTXFEMSK) != 0) {
#ifdef DEBUG_USB
puts(" IN PACKET QUEUE\n");
#endif

View File

@ -13,17 +13,17 @@
#define PULL_EFFECTIVE_DELAY 10
int has_external_debug_serial = 0;
int is_giant_panda = 0;
int is_entering_bootmode = 0;
bool has_external_debug_serial = 0;
bool is_giant_panda = 0;
bool is_entering_bootmode = 0;
int revision = PANDA_REV_AB;
int is_grey_panda = 0;
bool is_grey_panda = 0;
int detect_with_pull(GPIO_TypeDef *GPIO, int pin, int mode) {
bool detect_with_pull(GPIO_TypeDef *GPIO, int pin, int mode) {
set_gpio_mode(GPIO, pin, MODE_INPUT);
set_gpio_pullup(GPIO, pin, mode);
for (volatile int i=0; i<PULL_EFFECTIVE_DELAY; i++);
int ret = get_gpio_input(GPIO, pin);
bool ret = get_gpio_input(GPIO, pin);
set_gpio_pullup(GPIO, pin, PULL_NONE);
return ret;
}
@ -148,7 +148,7 @@ void set_led(int led_num, int on) {
#endif
}
void set_can_mode(int can, int use_gmlan) {
void set_can_mode(int can, bool use_gmlan) {
// connects to CAN2 xcvr or GMLAN xcvr
if (use_gmlan) {
if (can == 1) {

View File

@ -71,7 +71,7 @@ int is_gpio_started(void) {
void EXTI1_IRQHandler(void) {
volatile int pr = EXTI->PR & (1U << 1);
if (pr & (1U << 1)) {
if ((pr & (1U << 1)) != 0) {
#ifdef DEBUG
puts("got started interrupt\n");
#endif
@ -180,7 +180,7 @@ void usb_cb_ep3_out(uint8_t *usbdata, int len, bool hardwired) {
}
}
int is_enumerated = 0;
bool is_enumerated = 0;
void usb_cb_enumeration_complete() {
puts("USB enumeration complete\n");
@ -448,7 +448,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
case 0xf2:
{
uart_ring * rb = get_ring_by_number(setup->b.wValue.w);
if (rb) {
if (rb != NULL) {
puts("Clearing UART queue.\n");
clear_uart_buff(rb);
}