Strict compiler (#222)

have no Wall warnings from the strict compiler and enforcing it in the regression test.
master
rbiasini 2019-06-24 10:25:30 -07:00 committed by GitHub
parent da59e0cb9a
commit e2d781380a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 102 additions and 63 deletions

View File

@ -51,7 +51,7 @@ jobs:
- run:
name: Build Panda with strict compiler rules
command: |
docker run panda_strict_compiler /bin/bash -c "cd /panda/board; make -f Makefile.strict clean; make -f Makefile.strict bin"
docker run panda_strict_compiler /bin/bash -c "cd /panda/tests/build_strict; ./test_build_strict.sh"
build:
machine:

View File

@ -8,7 +8,7 @@
#define ADCCHAN_VOLTAGE 12
#define ADCCHAN_CURRENT 13
void adc_init() {
void adc_init(void) {
// global setup
ADC->CCR = ADC_CCR_TSVREFE | ADC_CCR_VBATE;
//ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_EOCS | ADC_CR2_DDS;

View File

@ -23,7 +23,7 @@ extern uint32_t can_speed[];
void can_set_forwarding(int from, int to);
void can_init(uint8_t can_number);
void can_init_all();
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);
@ -155,7 +155,7 @@ void can_init(uint8_t can_number) {
process_can(can_number);
}
void can_init_all() {
void can_init_all(void) {
for (int i=0; i < CAN_MAX; i++) {
can_init(i);
}
@ -329,17 +329,17 @@ void can_rx(uint8_t can_number) {
}
}
void CAN1_TX_IRQHandler() { process_can(0); }
void CAN1_RX0_IRQHandler() { can_rx(0); }
void CAN1_SCE_IRQHandler() { can_sce(CAN1); }
void CAN1_TX_IRQHandler(void) { process_can(0); }
void CAN1_RX0_IRQHandler(void) { can_rx(0); }
void CAN1_SCE_IRQHandler(void) { can_sce(CAN1); }
void CAN2_TX_IRQHandler() { process_can(1); }
void CAN2_RX0_IRQHandler() { can_rx(1); }
void CAN2_SCE_IRQHandler() { can_sce(CAN2); }
void CAN2_TX_IRQHandler(void) { process_can(1); }
void CAN2_RX0_IRQHandler(void) { can_rx(1); }
void CAN2_SCE_IRQHandler(void) { can_sce(CAN2); }
void CAN3_TX_IRQHandler() { process_can(2); }
void CAN3_RX0_IRQHandler() { can_rx(2); }
void CAN3_SCE_IRQHandler() { can_sce(CAN3); }
void CAN3_TX_IRQHandler(void) { process_can(2); }
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)) {

View File

@ -1,4 +1,4 @@
void clock_init() {
void clock_init(void) {
// enable external oscillator
RCC->CR |= RCC_CR_HSEON;
while ((RCC->CR & RCC_CR_HSERDY) == 0);
@ -25,7 +25,7 @@ void clock_init() {
// *** running on PLL ***
}
void watchdog_init() {
void watchdog_init(void) {
// setup watchdog
IWDG->KR = 0x5555;
IWDG->PR = 0; // divider /4
@ -34,7 +34,7 @@ void watchdog_init() {
IWDG->KR = 0xCCCC;
}
void watchdog_feed() {
void watchdog_feed(void) {
IWDG->KR = 0xAAAA;
}

View File

@ -9,7 +9,7 @@
#define MAX_BITS_CAN_PACKET (200)
int gmlan_alt_mode = DISABLED;
int gmlan_alt_mode = DISABLED;
// returns out_len
int do_bitstuff(char *out, char *in, int in_len) {
@ -82,7 +82,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
// test packet
int dlc_len = to_bang->RDTR & 0xF;
len = append_int(pkt, len, 0, 1); // Start-of-frame
if (to_bang->RIR & 4) {
// extended identifier
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier
@ -114,7 +114,7 @@ int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) {
return len;
}
void setup_timer4() {
void setup_timer4(void) {
// setup
TIM4->PSC = 48-1; // tick on 1 us
TIM4->CR1 = TIM_CR1_CEN; // enable
@ -131,7 +131,7 @@ void setup_timer4() {
int gmlan_timeout_counter = GMLAN_TICKS_PER_TIMEOUT_TICKLE; //GMLAN transceiver times out every 17ms held high; tickle every 15ms
int can_timeout_counter = GMLAN_TICKS_PER_SECOND; //1 second
int inverted_bit_to_send = GMLAN_HIGH;
int inverted_bit_to_send = GMLAN_HIGH;
int gmlan_switch_below_timeout = -1;
int gmlan_switch_timeout_enable = 0;
@ -140,9 +140,9 @@ void gmlan_switch_init(int timeout_enable) {
gmlan_alt_mode = GPIO_SWITCH;
gmlan_switch_below_timeout = 1;
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);
setup_timer4();
inverted_bit_to_send = GMLAN_LOW; //We got initialized, set the output low
}

View File

@ -39,6 +39,6 @@ void set_gpio_pullup(GPIO_TypeDef *GPIO, int pin, int mode) {
}
int get_gpio_input(GPIO_TypeDef *GPIO, int pin) {
return (GPIO->IDR & (1 << pin)) == (1 << pin);
return (GPIO->IDR & (1U << pin)) == (1U << pin);
}

View File

@ -1,6 +1,6 @@
// IRQs: DMA2_Stream2, DMA2_Stream3, EXTI4
void spi_init();
void spi_init(void);
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out);
// end API
@ -10,7 +10,7 @@ uint8_t spi_buf[SPI_BUF_SIZE];
int spi_buf_count = 0;
int spi_total_count = 0;
void spi_init() {
void spi_init(void) {
//puts("SPI init\n");
SPI1->CR1 = SPI_CR1_SPE;

View File

@ -203,7 +203,7 @@ void uart_set_baud(USART_TypeDef *u, int baud) {
#define USART1_DMA_LEN 0x20
char usart1_dma[USART1_DMA_LEN];
void uart_dma_drain() {
void uart_dma_drain(void) {
uart_ring *q = &esp_ring;
enter_critical_section();
@ -214,8 +214,8 @@ void uart_dma_drain() {
DMA2_Stream5->CR &= ~DMA_SxCR_EN;
while (DMA2_Stream5->CR & DMA_SxCR_EN);
int i;
for (i = 0; i < USART1_DMA_LEN - DMA2_Stream5->NDTR; i++) {
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;
if (next_w_ptr != q->r_ptr_rx) {

View File

@ -23,12 +23,12 @@ typedef union _USB_Setup {
}
USB_Setup_TypeDef;
void usb_init();
void usb_init(void);
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired);
int usb_cb_ep1_in(uint8_t *usbdata, int len, int hardwired);
void usb_cb_ep2_out(uint8_t *usbdata, int len, int hardwired);
void usb_cb_ep3_out(uint8_t *usbdata, int len, int hardwired);
void usb_cb_enumeration_complete();
void usb_cb_enumeration_complete(void);
// **** supporting defines ****
@ -445,7 +445,7 @@ void USB_WritePacket_EP0(uint8_t *src, uint16_t len) {
}
}
void usb_reset() {
void usb_reset(void) {
// unmask endpoint interrupts, so many sets
USBx_DEVICE->DAINT = 0xFFFFFFFF;
USBx_DEVICE->DAINTMSK = 0xFFFFFFFF;
@ -496,7 +496,7 @@ char to_hex_char(int a) {
}
}
void usb_setup() {
void usb_setup(void) {
int resp_len;
// setup packet is ready
switch (setup.b.bRequest) {
@ -663,7 +663,7 @@ void usb_setup() {
}
}
void usb_init() {
void usb_init(void) {
// full speed PHY, do reset and remove power down
/*puth(USBx->GRSTCTL);
puts(" resetting PHY\n");*/

View File

@ -29,7 +29,7 @@ int detect_with_pull(GPIO_TypeDef *GPIO, int pin, int mode) {
}
// must call again from main because BSS is zeroed
void detect() {
void detect(void) {
// detect has_external_debug_serial
has_external_debug_serial = detect_with_pull(GPIOA, 3, PULL_DOWN);
@ -63,7 +63,7 @@ void detect() {
// ********************* bringup *********************
void periph_init() {
void periph_init(void) {
// enable GPIOB, UART2, CAN, USB clock
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
@ -246,7 +246,7 @@ void set_esp_mode(int mode) {
// ********************* big init function *********************
// board specific
void gpio_init() {
void gpio_init(void) {
// pull low to hold ESP in reset??
// enable OTG out tied to ground
GPIOA->ODR = 0;
@ -366,7 +366,7 @@ void gpio_init() {
extern void *g_pfnVectors;
extern uint32_t enter_bootloader_mode;
void jump_to_bootloader() {
void jump_to_bootloader(void) {
// do enter bootloader
enter_bootloader_mode = 0;
void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *)0x1fff0004));
@ -379,7 +379,7 @@ void jump_to_bootloader() {
NVIC_SystemReset();
}
void early() {
void early(void) {
// after it's been in the bootloader, things are initted differently, so we reset
if (enter_bootloader_mode != BOOT_NORMAL &&
enter_bootloader_mode != ENTER_BOOTLOADER_MAGIC &&

View File

@ -1,12 +1,12 @@
// **** shitty libc ****
// **** libc ****
void delay(int a) {
volatile int i;
for (i=0;i<a;i++);
for (i = 0; i < a; i++);
}
void *memset(void *str, int c, unsigned int n) {
int i;
unsigned int i;
for (i = 0; i < n; i++) {
*((uint8_t*)str) = c;
++str;
@ -15,7 +15,7 @@ void *memset(void *str, int c, unsigned int n) {
}
void *memcpy(void *dest, const void *src, unsigned int n) {
int i;
unsigned int i;
// TODO: make not slow
for (i = 0; i < n; i++) {
((uint8_t*)dest)[i] = *(uint8_t*)src;
@ -25,7 +25,7 @@ void *memcpy(void *dest, const void *src, unsigned int n) {
}
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
int i;
unsigned int i;
for (i = 0; i < num; i++) {
if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) return -1;
}
@ -35,19 +35,19 @@ int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
// ********************* IRQ helpers *********************
int interrupts_enabled = 0;
void enable_interrupts() {
void enable_interrupts(void) {
interrupts_enabled = 1;
__enable_irq();
}
int critical_depth = 0;
void enter_critical_section() {
void enter_critical_section(void) {
__disable_irq();
// this is safe because interrupts are disabled
critical_depth += 1;
}
void exit_critical_section() {
void exit_critical_section(void) {
// this is safe because interrupts are disabled
critical_depth -= 1;
if (critical_depth == 0 && interrupts_enabled) {

View File

@ -61,12 +61,12 @@ void debug_ring_callback(uart_ring *ring) {
// ***************************** started logic *****************************
int is_gpio_started() {
int is_gpio_started(void) {
// ignition is on PA1
return (GPIOA->IDR & (1 << 1)) == 0;
}
void EXTI1_IRQHandler() {
void EXTI1_IRQHandler(void) {
volatile int pr = EXTI->PR & (1 << 1);
if (pr & (1 << 1)) {
#ifdef DEBUG
@ -86,7 +86,7 @@ void EXTI1_IRQHandler() {
}
}
void started_interrupt_init() {
void started_interrupt_init(void) {
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
EXTI->IMR |= (1 << 1);
EXTI->RTSR |= (1 << 1);
@ -140,6 +140,7 @@ int get_health_pkt(void *dat) {
}
int usb_cb_ep1_in(uint8_t *usbdata, int len, int hardwired) {
UNUSED(hardwired);
CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata;
int ilen = 0;
while (ilen < MIN(len/0x10, 4) && can_pop(&can_rx_q, &reply[ilen])) ilen++;
@ -148,6 +149,7 @@ int usb_cb_ep1_in(uint8_t *usbdata, int len, int hardwired) {
// send on serial, first byte to select the ring
void usb_cb_ep2_out(uint8_t *usbdata, int len, int hardwired) {
UNUSED(hardwired);
if (len == 0) return;
uart_ring *ur = get_ring_by_number(usbdata[0]);
if (!ur) return;
@ -158,6 +160,7 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len, int hardwired) {
// send on CAN
void usb_cb_ep3_out(uint8_t *usbdata, int len, int hardwired) {
UNUSED(hardwired);
int dpkt = 0;
for (dpkt = 0; dpkt < len; dpkt += 0x10) {
uint32_t *tf = (uint32_t*)(&usbdata[dpkt]);
@ -461,7 +464,7 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
// data[0] = endpoint
// data[2] = length
// data[4:] = data
UNUSED(len);
int resp_len = 0;
switch (data[0]) {
case 0:
@ -487,11 +490,11 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
// ***************************** main code *****************************
void __initialize_hardware_early() {
void __initialize_hardware_early(void) {
early();
}
void __attribute__ ((noinline)) enable_fpu() {
void __attribute__ ((noinline)) enable_fpu(void) {
// enable the FPU
SCB->CPACR |= ((3UL << (10 * 2)) | (3UL << (11 * 2)));
}
@ -500,7 +503,7 @@ uint64_t tcnt = 0;
uint64_t marker = 0;
// called once per second
void TIM3_IRQHandler() {
void TIM3_IRQHandler(void) {
#define CURRENT_THRESHOLD 0xF00
#define CLICKS 5 // 5 seconds to switch modes
@ -588,7 +591,7 @@ void TIM3_IRQHandler() {
TIM3->SR = 0;
}
int main() {
int main(void) {
// shouldn't have interrupts here, but just in case
__disable_irq();

View File

@ -23,7 +23,7 @@ void power_save_enable(void) {
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 (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)-1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
}
power_save_status = POWER_SAVE_STATUS_ENABLED;
@ -49,7 +49,7 @@ void power_save_disable(void) {
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 (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)-1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
}
power_save_status = POWER_SAVE_STATUS_DISABLED;

View File

@ -115,11 +115,12 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void cadillac_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
cadillac_ign = 0;
}
static int cadillac_ign_hook() {
static int cadillac_ign_hook(void) {
return cadillac_ign;
}

View File

@ -112,6 +112,7 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void chrysler_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
chrysler_camera_detected = 0;
}

View File

@ -1,24 +1,33 @@
void default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {}
void default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
UNUSED(to_push);
}
int default_ign_hook() {
int default_ign_hook(void) {
return -1; // use GPIO to determine ignition
}
// *** no output safety mode ***
static void nooutput_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
}
static int nooutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
UNUSED(to_send);
return false;
}
static int nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
UNUSED(lin_num);
UNUSED(data);
UNUSED(len);
return false;
}
static int default_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
UNUSED(bus_num);
UNUSED(to_fwd);
return -1;
}
@ -34,14 +43,19 @@ const safety_hooks nooutput_hooks = {
// *** all output safety mode ***
static void alloutput_init(int16_t param) {
UNUSED(param);
controls_allowed = 1;
}
static int alloutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
UNUSED(to_send);
return true;
}
static int alloutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
UNUSED(lin_num);
UNUSED(data);
UNUSED(len);
return true;
}

View File

@ -225,11 +225,12 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void gm_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
gm_ignition_started = 0;
}
static int gm_ign_hook() {
static int gm_ign_hook(void) {
return gm_ignition_started;
}

View File

@ -149,6 +149,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void honda_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
honda_bosch_hardware = false;
honda_alt_brake_msg = false;

View File

@ -145,6 +145,7 @@ static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
}
static void hyundai_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
hyundai_giraffe_switch_2 = 0;
}

View File

@ -181,12 +181,13 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
static void tesla_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
tesla_ignition_started = 0;
gmlan_switch_init(1); //init the gmlan switch with 1s timeout enabled
}
static int tesla_ign_hook() {
static int tesla_ign_hook(void) {
return tesla_ignition_started;
}

View File

@ -18,7 +18,7 @@ struct lookup_t {
void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
int safety_ignition_hook();
int safety_ignition_hook(void);
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
int to_signed(int d, int bits);
void update_sample(struct sample_t *sample, int sample_new);
@ -35,7 +35,7 @@ typedef void (*safety_hook_init)(int16_t param);
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send);
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
typedef int (*ign_hook)();
typedef int (*ign_hook)(void);
typedef int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd);
typedef struct {

View File

@ -0,0 +1,15 @@
#!/bin/bash -e
cd ../../board/
make -f Makefile.strict clean
make -f Makefile.strict bin 2> compiler_output.txt
if [[ -s "compiler_output.txt" ]]
then
echo "Found alerts from the compiler:"
cat compiler_output.txt
exit 1
fi

View File

@ -42,6 +42,7 @@ TIM_TypeDef *TIM2 = &timer;
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define UNUSED(x) (void)(x)
#define PANDA
#define NULL ((void*)0)