mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-19 01:33:52 +08:00
Merge branch 'upstream/panda/master' into sync-20250422
This commit is contained in:
2
.github/workflows/drivers.yaml
vendored
2
.github/workflows/drivers.yaml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
build_socketcan:
|
||||
name: socketcan build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 1
|
||||
timeout-minutes: 2
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
|
||||
@@ -91,7 +91,7 @@ static void cuatro_init(void) {
|
||||
tres_set_ir_power(0U);
|
||||
|
||||
// Clock source
|
||||
clock_source_init();
|
||||
clock_source_init(true);
|
||||
|
||||
// Sound codec
|
||||
cuatro_set_amp_enabled(false);
|
||||
@@ -105,8 +105,22 @@ static void cuatro_init(void) {
|
||||
sound_init();
|
||||
}
|
||||
|
||||
static harness_configuration cuatro_harness_config = {
|
||||
.has_harness = true,
|
||||
.GPIO_SBU1 = GPIOC,
|
||||
.GPIO_SBU2 = GPIOA,
|
||||
.GPIO_relay_SBU1 = GPIOA,
|
||||
.GPIO_relay_SBU2 = GPIOA,
|
||||
.pin_SBU1 = 4,
|
||||
.pin_SBU2 = 1,
|
||||
.pin_relay_SBU1 = 9,
|
||||
.pin_relay_SBU2 = 3,
|
||||
.adc_channel_SBU1 = 4, // ADC12_INP4
|
||||
.adc_channel_SBU2 = 17 // ADC1_INP17
|
||||
};
|
||||
|
||||
board board_cuatro = {
|
||||
.harness_config = &tres_harness_config,
|
||||
.harness_config = &cuatro_harness_config,
|
||||
.has_spi = true,
|
||||
.has_canfd = true,
|
||||
.fan_max_rpm = 12500U,
|
||||
|
||||
@@ -106,7 +106,7 @@ static void dos_init(void) {
|
||||
dos_set_bootkick(true);
|
||||
|
||||
// Init clock source (camera strobe) using PWM
|
||||
clock_source_init();
|
||||
clock_source_init(false);
|
||||
}
|
||||
|
||||
static harness_configuration dos_harness_config = {
|
||||
|
||||
@@ -129,7 +129,7 @@ static void tres_init(void) {
|
||||
register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT10 | GPIO_OTYPER_OT11); // open drain
|
||||
|
||||
// Clock source
|
||||
clock_source_init();
|
||||
clock_source_init(false);
|
||||
}
|
||||
|
||||
static harness_configuration tres_harness_config = {
|
||||
|
||||
@@ -166,9 +166,6 @@ void ignition_can_hook(CANPacket_t *to_push) {
|
||||
int addr = GET_ADDR(to_push);
|
||||
int len = GET_LEN(to_push);
|
||||
|
||||
// Check counter position on cars with overlap
|
||||
static int prev_counter = -1;
|
||||
|
||||
// GM exception
|
||||
if ((addr == 0x1F1) && (len == 8)) {
|
||||
// SystemPowerMode (2=Run, 3=Crank Request)
|
||||
@@ -181,6 +178,7 @@ void ignition_can_hook(CANPacket_t *to_push) {
|
||||
// 0x152 overlaps with Subaru pre-global which has this bit as the high beam
|
||||
int counter = GET_BYTE(to_push, 1) & 0xFU; // max is only 14
|
||||
|
||||
static int prev_counter = -1;
|
||||
if ((counter == ((prev_counter + 1) % 15)) && (prev_counter != -1)) {
|
||||
// VDM_OutputSignals->VDM_EpasPowerMode
|
||||
ignition_can = ((GET_BYTE(to_push, 7) >> 4U) & 0x3U) == 1U; // VDM_EpasPowerMode_Drive_On=1
|
||||
@@ -194,6 +192,7 @@ void ignition_can_hook(CANPacket_t *to_push) {
|
||||
// 0x221 overlaps with Rivian which has random data on byte 0
|
||||
int counter = GET_BYTE(to_push, 6) >> 4;
|
||||
|
||||
static int prev_counter = -1;
|
||||
if ((counter == ((prev_counter + 1) % 16)) && (prev_counter != -1)) {
|
||||
// VCFRONT_LVPowerState->VCFRONT_vehiclePowerState
|
||||
int power_state = (GET_BYTE(to_push, 0) >> 5U) & 0x3U;
|
||||
|
||||
@@ -4,7 +4,7 @@ void clock_source_set_period(uint8_t period) {
|
||||
register_set(&(TIM1->ARR), ((period*10U) - 1U), 0xFFFFU);
|
||||
}
|
||||
|
||||
void clock_source_init(void) {
|
||||
void clock_source_init(bool enable_channel1) {
|
||||
// Setup timer
|
||||
register_set(&(TIM1->PSC), ((APB2_TIMER_FREQ*100U)-1U), 0xFFFFU); // Tick on 0.1 ms
|
||||
register_set(&(TIM1->ARR), ((CLOCK_SOURCE_PERIOD_MS*10U) - 1U), 0xFFFFU); // Period
|
||||
@@ -21,11 +21,14 @@ void clock_source_init(void) {
|
||||
NVIC_DisableIRQ(TIM1_CC_IRQn);
|
||||
|
||||
// Set GPIO as timer channels
|
||||
if (enable_channel1) {
|
||||
set_gpio_alternate(GPIOA, 8, GPIO_AF1_TIM1);
|
||||
}
|
||||
set_gpio_alternate(GPIOB, 14, GPIO_AF1_TIM1);
|
||||
set_gpio_alternate(GPIOB, 15, GPIO_AF1_TIM1);
|
||||
|
||||
// Set PWM mode
|
||||
register_set(&(TIM1->CCMR1), (0b110UL << TIM_CCMR1_OC2M_Pos), 0xFFFFU);
|
||||
register_set(&(TIM1->CCMR1), (0b110UL << TIM_CCMR1_OC1M_Pos) | (0b110UL << TIM_CCMR1_OC2M_Pos), 0xFFFFU);
|
||||
register_set(&(TIM1->CCMR2), (0b110UL << TIM_CCMR2_OC3M_Pos), 0xFFFFU);
|
||||
|
||||
// Enable output
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
#define CLOCK_SOURCE_PULSE_LEN_MS 2U
|
||||
|
||||
void clock_source_set_period(uint8_t period);
|
||||
void clock_source_init(void);
|
||||
void clock_source_init(bool enable_channel1);
|
||||
|
||||
@@ -100,13 +100,8 @@ void harness_init(void) {
|
||||
set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, 1);
|
||||
set_gpio_output(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, 1);
|
||||
|
||||
// try to detect orientation
|
||||
// detect initial orientation
|
||||
harness.status = harness_detect_orientation();
|
||||
if (harness.status != HARNESS_STATUS_NC) {
|
||||
print("detected car harness with orientation "); puth2(harness.status); print("\n");
|
||||
} else {
|
||||
print("failed to detect car harness!\n");
|
||||
}
|
||||
|
||||
// keep buses connected by default
|
||||
set_intercept_relay(false, false);
|
||||
|
||||
@@ -49,13 +49,10 @@ void check_registers(void){
|
||||
if((uint32_t) register_map[i].address != 0U){
|
||||
ENTER_CRITICAL()
|
||||
if((*(register_map[i].address) & register_map[i].check_mask) != (register_map[i].value & register_map[i].check_mask)){
|
||||
#ifdef DEBUG_FAULTS
|
||||
print("Register at address 0x"); puth((uint32_t) register_map[i].address); print(" is divergent!");
|
||||
print(" Map: 0x"); puth(register_map[i].value);
|
||||
print(" Register: 0x"); puth(*(register_map[i].address));
|
||||
print(" Mask: 0x"); puth(register_map[i].check_mask);
|
||||
print("\n");
|
||||
#endif
|
||||
if(!register_map[i].logged_fault){
|
||||
print("Register 0x"); puth((uint32_t) register_map[i].address); print(" divergent! Map: 0x"); puth(register_map[i].value); print(" Reg: 0x"); puth(*(register_map[i].address)); print("\n");
|
||||
register_map[i].logged_fault = true;
|
||||
}
|
||||
fault_occurred(FAULT_REGISTER_DIVERGENT);
|
||||
}
|
||||
EXIT_CRITICAL()
|
||||
|
||||
@@ -4,6 +4,7 @@ typedef struct reg {
|
||||
volatile uint32_t *address;
|
||||
uint32_t value;
|
||||
uint32_t check_mask;
|
||||
bool logged_fault;
|
||||
} reg;
|
||||
|
||||
// 10 bit hash with 23 as a prime
|
||||
|
||||
@@ -108,7 +108,9 @@ void spi_rx_done(void) {
|
||||
response_len = 1U;
|
||||
} else {
|
||||
// response: NACK and reset state machine
|
||||
print("- incorrect header sync or checksum "); hexdump(spi_buf_rx, SPI_HEADER_SIZE);
|
||||
#ifdef DEBUG_SPI
|
||||
print("- incorrect header sync or checksum "); hexdump(spi_buf_rx, SPI_HEADER_SIZE);
|
||||
#endif
|
||||
spi_buf_tx[0] = SPI_NACK;
|
||||
next_rx_state = SPI_STATE_HEADER_NACK;
|
||||
response_len = 1U;
|
||||
@@ -160,12 +162,14 @@ void spi_rx_done(void) {
|
||||
} else {
|
||||
// Checksum was incorrect
|
||||
response_ack = false;
|
||||
print("- incorrect data checksum ");
|
||||
puth4(spi_data_len_mosi);
|
||||
print("\n");
|
||||
hexdump(spi_buf_rx, SPI_HEADER_SIZE);
|
||||
hexdump(&(spi_buf_rx[SPI_HEADER_SIZE]), MIN(spi_data_len_mosi, 64));
|
||||
print("\n");
|
||||
#ifdef DEBUG_SPI
|
||||
print("- incorrect data checksum ");
|
||||
puth4(spi_data_len_mosi);
|
||||
print("\n");
|
||||
hexdump(spi_buf_rx, SPI_HEADER_SIZE);
|
||||
hexdump(&(spi_buf_rx[SPI_HEADER_SIZE]), MIN(spi_data_len_mosi, 64));
|
||||
print("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!response_ack) {
|
||||
|
||||
@@ -145,10 +145,6 @@ void puth(unsigned int i) {
|
||||
puthx(i, 8U);
|
||||
}
|
||||
|
||||
void puth2(unsigned int i) {
|
||||
puthx(i, 2U);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG)
|
||||
void puth4(unsigned int i) {
|
||||
puthx(i, 4U);
|
||||
@@ -160,7 +156,7 @@ void hexdump(const void *a, int l) {
|
||||
if (a != NULL) {
|
||||
for (int i=0; i < l; i++) {
|
||||
if ((i != 0) && ((i & 0xf) == 0)) print("\n");
|
||||
puth2(((const unsigned char*)a)[i]);
|
||||
puthx(((const unsigned char*)a)[i], 2U);
|
||||
print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ void putch(const char a);
|
||||
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
|
||||
|
||||
@@ -538,21 +538,26 @@ void usb_irqhandler(void) {
|
||||
}
|
||||
|
||||
if ((gintsts & USB_OTG_GINTSTS_USBRST) != 0U) {
|
||||
print("USB reset\n");
|
||||
#ifdef DEBUG_USB
|
||||
print("USB reset\n");
|
||||
#endif
|
||||
usb_reset();
|
||||
}
|
||||
|
||||
if ((gintsts & USB_OTG_GINTSTS_ENUMDNE) != 0U) {
|
||||
print("enumeration done");
|
||||
#ifdef DEBUG_USB
|
||||
print("enumeration done\n");
|
||||
#endif
|
||||
// Full speed, ENUMSPD
|
||||
//puth(USBx_DEVICE->DSTS);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
if ((gintsts & USB_OTG_GINTSTS_OTGINT) != 0U) {
|
||||
print("OTG int:");
|
||||
puth(USBx->GOTGINT);
|
||||
print("\n");
|
||||
#ifdef DEBUG_USB
|
||||
print("OTG int:");
|
||||
puth(USBx->GOTGINT);
|
||||
print("\n");
|
||||
#endif
|
||||
|
||||
// getting ADTOCHG
|
||||
//USBx->GOTGINT = USBx->GOTGINT;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// ******************** Prototypes ********************
|
||||
void print(const char *a);
|
||||
void puth(unsigned int i);
|
||||
void puth2(unsigned int i);
|
||||
void puth4(unsigned int i);
|
||||
void hexdump(const void *a, int l);
|
||||
typedef struct board board;
|
||||
|
||||
Reference in New Issue
Block a user