Skip to content

Commit

Permalink
Merge branch 'commaai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rav4kumar authored Mar 25, 2024
2 parents b2a4f50 + 01c54d1 commit 777ccf4
Show file tree
Hide file tree
Showing 40 changed files with 191 additions and 185 deletions.
4 changes: 2 additions & 2 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void black_init_bootloader(void) {
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration black_harness_config = {
harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand All @@ -155,7 +155,7 @@ const harness_configuration black_harness_config = {
.adc_channel_SBU2 = 13
};

const board board_black = {
board board_black = {
.set_bootkick = unused_set_bootkick,
.harness_config = &black_harness_config,
.has_obd = true,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef void (*board_set_bootkick)(BootState state);
typedef bool (*board_read_som_gpio)(void);

struct board {
const harness_configuration *harness_config;
harness_configuration *harness_config;
const bool has_obd;
const bool has_spi;
const bool has_canfd;
Expand Down
2 changes: 1 addition & 1 deletion board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void cuatro_init(void) {
clock_source_init();
}

const board board_cuatro = {
board board_cuatro = {
.harness_config = &red_chiplet_harness_config,
.has_obd = true,
.has_spi = true,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void dos_init(void) {
clock_source_init();
}

const harness_configuration dos_harness_config = {
harness_configuration dos_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand All @@ -180,7 +180,7 @@ const harness_configuration dos_harness_config = {
.adc_channel_SBU2 = 13
};

const board board_dos = {
board board_dos = {
.harness_config = &dos_harness_config,
.has_obd = true,
#ifdef ENABLE_SPI
Expand Down
2 changes: 1 addition & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Most hardware functionality is similar to white panda

const board board_grey = {
board board_grey = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_obd = false,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void red_init(void) {
red_set_can_mode(CAN_MODE_NORMAL);
}

const harness_configuration red_harness_config = {
harness_configuration red_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,
Expand All @@ -167,7 +167,7 @@ const harness_configuration red_harness_config = {
.adc_channel_SBU2 = 17 //ADC1_INP17
};

const board board_red = {
board board_red = {
.set_bootkick = unused_set_bootkick,
.harness_config = &red_harness_config,
.has_obd = true,
Expand Down
2 changes: 1 addition & 1 deletion board/boards/red_chiplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void red_chiplet_init(void) {
red_chiplet_set_can_mode(CAN_MODE_NORMAL);
}

const harness_configuration red_chiplet_harness_config = {
harness_configuration red_chiplet_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOA,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void tres_init(void) {
// Enable USB 3.3V LDO for USB block
register_set_bits(&(PWR->CR3), PWR_CR3_USBREGEN);
register_set_bits(&(PWR->CR3), PWR_CR3_USB33DEN);
while ((PWR->CR3 & PWR_CR3_USB33RDY) == 0);
while ((PWR->CR3 & PWR_CR3_USB33RDY) == 0U);

red_chiplet_init();

Expand Down Expand Up @@ -70,7 +70,7 @@ void tres_init(void) {
clock_source_init();
}

const board board_tres = {
board board_tres = {
.harness_config = &red_chiplet_harness_config,
.has_obd = true,
.has_spi = true,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void uno_init_bootloader(void) {
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration uno_harness_config = {
harness_configuration uno_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand All @@ -191,7 +191,7 @@ const harness_configuration uno_harness_config = {
.adc_channel_SBU2 = 13
};

const board board_uno = {
board board_uno = {
.harness_config = &uno_harness_config,
.has_obd = true,
.has_spi = false,
Expand Down
4 changes: 2 additions & 2 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ void white_grey_init_bootloader(void) {
set_gpio_output(GPIOC, 14, 0);
}

const harness_configuration white_harness_config = {
harness_configuration white_harness_config = {
.has_harness = false
};

const board board_white = {
board board_white = {
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_obd = false,
Expand Down
2 changes: 1 addition & 1 deletion board/bootstub_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ void uart_init(uart_ring *q, int baud) { UNUSED(q); UNUSED(baud); }

// ********************* Globals **********************
uint8_t hw_type = 0;
const board *current_board;
board *current_board;
6 changes: 3 additions & 3 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
can_health[can_number].total_error_cnt += 1U;

// RX message lost due to FIFO overrun
if ((CANx->RF0R & (CAN_RF0R_FOVR0)) != 0) {
if ((CANx->RF0R & (CAN_RF0R_FOVR0)) != 0U) {
can_health[can_number].total_rx_lost_cnt += 1U;
CANx->RF0R &= ~(CAN_RF0R_FOVR0);
}
Expand All @@ -74,7 +74,7 @@ void process_can(uint8_t can_number) {

// check for empty mailbox
CANPacket_t to_send;
if ((CANx->TSR & (CAN_TSR_TERR0 | CAN_TSR_ALST0)) != 0) { // last TX failed due to error arbitration lost
if ((CANx->TSR & (CAN_TSR_TERR0 | CAN_TSR_ALST0)) != 0U) { // last TX failed due to error arbitration lost
can_health[can_number].total_tx_lost_cnt += 1U;
CANx->TSR |= (CAN_TSR_TERR0 | CAN_TSR_ALST0);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ void can_rx(uint8_t can_number) {
CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);

while ((CANx->RF0R & CAN_RF0R_FMP0) != 0) {
while ((CANx->RF0R & CAN_RF0R_FMP0) != 0U) {
can_health[can_number].total_rx_cnt += 1U;

// can is live
Expand Down
4 changes: 2 additions & 2 deletions board/drivers/clock_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void clock_source_init(void) {
set_gpio_alternate(GPIOB, 15, GPIO_AF1_TIM1);

// Set PWM mode
register_set(&(TIM1->CCMR1), (0b110 << TIM_CCMR1_OC2M_Pos), 0xFFFFU);
register_set(&(TIM1->CCMR2), (0b110 << TIM_CCMR2_OC3M_Pos), 0xFFFFU);
register_set(&(TIM1->CCMR1), (0b110UL << TIM_CCMR1_OC2M_Pos), 0xFFFFU);
register_set(&(TIM1->CCMR2), (0b110UL << TIM_CCMR2_OC3M_Pos), 0xFFFFU);

// Enable output
register_set(&(TIM1->BDTR), TIM_BDTR_MOE, 0xFFFFU);
Expand Down
6 changes: 3 additions & 3 deletions board/drivers/fake_siren.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void fake_siren_init(void) {
register_set(&DMA1_Stream1->PAR, (uint32_t) &(DAC1->DHR8R1), 0xFFFFFFFFU);
DMA1_Stream1->NDTR = sizeof(fake_siren_lut);
register_set(&DMA1_Stream1->FCR, 0U, 0x00000083U);
DMA1_Stream1->CR = (0b11 << DMA_SxCR_PL_Pos);
DMA1_Stream1->CR |= DMA_SxCR_MINC | DMA_SxCR_CIRC | (1 << DMA_SxCR_DIR_Pos);
DMA1_Stream1->CR = (0b11UL << DMA_SxCR_PL_Pos);
DMA1_Stream1->CR |= DMA_SxCR_MINC | DMA_SxCR_CIRC | (1U << DMA_SxCR_DIR_Pos);

// Init trigger timer (around 2.5kHz)
register_set(&TIM7->PSC, 0U, 0xFFFFU);
register_set(&TIM7->ARR, 133U, 0xFFFFU);
register_set(&TIM7->CR2, (0b10 << TIM_CR2_MMS_Pos), TIM_CR2_MMS_Msk);
register_set(&TIM7->CR2, (0b10U << TIM_CR2_MMS_Pos), TIM_CR2_MMS_Msk);
register_set(&TIM7->CR1, TIM_CR1_ARPE | TIM_CR1_URS, 0x088EU);
TIM7->SR = 0U;
TIM7->CR1 |= TIM_CR1_CEN;
Expand Down
14 changes: 7 additions & 7 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
FDCANx->IR |= (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EP | FDCAN_IR_BO | FDCAN_IR_RF0L);
can_health[can_number].total_error_cnt += 1U;
// Check for RX FIFO overflow
if ((ir_reg & (FDCAN_IR_RF0L)) != 0) {
if ((ir_reg & (FDCAN_IR_RF0L)) != 0U) {
can_health[can_number].total_rx_lost_cnt += 1U;
}
// Cases:
// 1. while multiplexing between buses 1 and 3 we are getting ACK errors that overwhelm CAN core, by resetting it recovers faster
// 2. H7 gets stuck in bus off recovery state indefinitely
if ((((can_health[can_number].last_error == CAN_ACK_ERROR) || (can_health[can_number].last_data_error == CAN_ACK_ERROR)) && (can_health[can_number].transmit_error_cnt > 127U)) ||
((ir_reg & FDCAN_IR_BO) != 0)) {
((ir_reg & FDCAN_IR_BO) != 0U)) {
can_health[can_number].can_core_reset_cnt += 1U;
can_health[can_number].total_tx_lost_cnt += (FDCAN_TX_FIFO_EL_CNT - (FDCANx->TXFQS & FDCAN_TXFQS_TFFL)); // TX FIFO msgs will be lost after reset
llcan_clear_send(FDCANx);
Expand All @@ -93,15 +93,15 @@ void process_can(uint8_t can_number) {

FDCANx->IR |= FDCAN_IR_TFE; // Clear Tx FIFO Empty flag

if ((FDCANx->TXFQS & FDCAN_TXFQS_TFQF) == 0) {
if ((FDCANx->TXFQS & FDCAN_TXFQS_TFQF) == 0U) {
CANPacket_t to_send;
if (can_pop(can_queues[bus_number], &to_send)) {
if (can_check_checksum(&to_send)) {
can_health[can_number].total_tx_cnt += 1U;

uint32_t TxFIFOSA = FDCAN_START_ADDRESS + (can_number * FDCAN_OFFSET) + (FDCAN_RX_FIFO_0_EL_CNT * FDCAN_RX_FIFO_0_EL_SIZE);
// get the index of the next TX FIFO element (0 to FDCAN_TX_FIFO_EL_CNT - 1)
uint32_t tx_index = (FDCANx->TXFQS >> FDCAN_TXFQS_TFQPI_Pos) & 0x1F;
uint32_t tx_index = (FDCANx->TXFQS >> FDCAN_TXFQS_TFQPI_Pos) & 0x1FU;
// only send if we have received a packet
canfd_fifo *fifo;
fifo = (canfd_fifo *)(TxFIFOSA + (tx_index * FDCAN_TX_FIFO_EL_SIZE));
Expand Down Expand Up @@ -153,14 +153,14 @@ void can_rx(uint8_t can_number) {

// Clear all new messages from Rx FIFO 0
FDCANx->IR |= FDCAN_IR_RF0N;
while((FDCANx->RXF0S & FDCAN_RXF0S_F0FL) != 0) {
while((FDCANx->RXF0S & FDCAN_RXF0S_F0FL) != 0U) {
can_health[can_number].total_rx_cnt += 1U;

// can is live
pending_can_live = 1;

// get the index of the next RX FIFO element (0 to FDCAN_RX_FIFO_0_EL_CNT - 1)
uint32_t rx_fifo_idx = (uint8_t)((FDCANx->RXF0S >> FDCAN_RXF0S_F0GI_Pos) & 0x3F);
uint32_t rx_fifo_idx = (uint8_t)((FDCANx->RXF0S >> FDCAN_RXF0S_F0GI_Pos) & 0x3FU);

// Recommended to offset get index by at least +1 if RX FIFO is in overwrite mode and full (datasheet)
if((FDCANx->RXF0S & FDCAN_RXF0S_F0F) == FDCAN_RXF0S_F0F) {
Expand Down Expand Up @@ -232,7 +232,7 @@ void can_rx(uint8_t can_number) {
}

// Error handling
if ((ir_reg & (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EP | FDCAN_IR_BO | FDCAN_IR_RF0L)) != 0) {
if ((ir_reg & (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EP | FDCAN_IR_BO | FDCAN_IR_RF0L)) != 0U) {
update_can_health_pkt(can_number, ir_reg);
}
}
Expand Down
6 changes: 3 additions & 3 deletions board/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define OUTPUT_TYPE_OPEN_DRAIN 1U

typedef struct {
GPIO_TypeDef *bank;
GPIO_TypeDef * const bank;
uint8_t pin;
} gpio_t;

Expand Down Expand Up @@ -68,13 +68,13 @@ int get_gpio_input(const GPIO_TypeDef *GPIO, unsigned int pin) {
return (GPIO->IDR & (1UL << pin)) == (1UL << pin);
}

void gpio_set_all_output(const gpio_t *pins, uint8_t num_pins, bool enabled) {
void gpio_set_all_output(gpio_t *pins, uint8_t num_pins, bool enabled) {
for (uint8_t i = 0; i < num_pins; i++) {
set_gpio_output(pins[i].bank, pins[i].pin, enabled);
}
}

void gpio_set_bitmask(const gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
void gpio_set_bitmask(gpio_t *pins, uint8_t num_pins, uint32_t bitmask) {
for (uint8_t i = 0; i < num_pins; i++) {
set_gpio_output(pins[i].bank, pins[i].pin, (bitmask >> i) & 1U);
}
Expand Down
20 changes: 10 additions & 10 deletions board/drivers/harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ struct harness_t harness;

struct harness_configuration {
const bool has_harness;
GPIO_TypeDef *GPIO_SBU1;
GPIO_TypeDef *GPIO_SBU2;
GPIO_TypeDef *GPIO_relay_SBU1;
GPIO_TypeDef *GPIO_relay_SBU2;
uint8_t pin_SBU1;
uint8_t pin_SBU2;
uint8_t pin_relay_SBU1;
uint8_t pin_relay_SBU2;
uint8_t adc_channel_SBU1;
uint8_t adc_channel_SBU2;
GPIO_TypeDef * const GPIO_SBU1;
GPIO_TypeDef * const GPIO_SBU2;
GPIO_TypeDef * const GPIO_relay_SBU1;
GPIO_TypeDef * const GPIO_relay_SBU2;
const uint8_t pin_SBU1;
const uint8_t pin_SBU2;
const uint8_t pin_relay_SBU1;
const uint8_t pin_relay_SBU2;
const uint8_t adc_channel_SBU1;
const uint8_t adc_channel_SBU2;
};

// The ignition relay is only used for testing purposes
Expand Down
2 changes: 1 addition & 1 deletion board/drivers/interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void handle_interrupt(IRQn_Type irq_type){

// Every second
void interrupt_timer_handler(void) {
if (INTERRUPT_TIMER->SR != 0) {
if (INTERRUPT_TIMER->SR != 0U) {
for (uint16_t i = 0U; i < NUM_INTERRUPTS; i++) {
// Log IRQ call rate faults
if (check_interrupt_rate && (interrupts[i].call_counter > interrupts[i].max_call_rate)) {
Expand Down
4 changes: 1 addition & 3 deletions board/drivers/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ uint16_t spi_version_packet(uint8_t *out) {
uint16_t data_pos = 7U + 2U;

// write serial
#ifdef UID_BASE
(void)memcpy(&out[data_pos], ((uint8_t *)UID_BASE), 12);
data_len += 12U;
#endif

// HW type
out[data_pos + data_len] = hw_type;
Expand Down Expand Up @@ -232,7 +230,7 @@ void spi_rx_done(void) {
llspi_miso_dma(spi_buf_tx, response_len);

spi_state = next_rx_state;
if (!checksum_valid && (spi_checksum_error_count < __UINT16_MAX__)) {
if (!checksum_valid && (spi_checksum_error_count < UINT16_MAX)) {
spi_checksum_error_count += 1U;
}
}
Expand Down
Loading

0 comments on commit 777ccf4

Please sign in to comment.