IQ.Pilot Release Commit @ 2b39aa6
This commit is contained in:
@@ -138,9 +138,11 @@ bus_config_t bus_config[PANDA_CAN_CNT] = {
|
||||
void can_init_all(void) {
|
||||
for (uint8_t i=0U; i < PANDA_CAN_CNT; i++) {
|
||||
bus_config[i].canfd_enabled = false;
|
||||
// Preserve can_data_speed (default 20000U = 2Mbps) through safety model changes.
|
||||
// Auto-detection in can_rx() sets canfd_enabled=true when the first FD frame arrives;
|
||||
// keeping data speed nonzero lets the FDCAN peripheral handle FD frames immediately.
|
||||
// NOTE: do NOT reset can_data_speed here. Matching stock panda, can_init_all() only clears
|
||||
// canfd_enabled (re-discovered on RX via canfd_auto). The old "#ifndef CANFD: can_data_speed = 0U"
|
||||
// fired on every board because CANFD is never defined, zeroing the FD data-phase bitrate on every
|
||||
// set_safety_model() -> CAN-FD frames then failed with form/stuff errors and never re-enabled,
|
||||
// breaking all CAN-FD cars (e.g. Kia EV6) after fingerprinting. can_data_speed is only used by fdcan.
|
||||
can_clear(can_queues[i]);
|
||||
(void)can_init(i);
|
||||
}
|
||||
@@ -169,6 +171,7 @@ void ignition_can_hook(CANPacket_t *msg) {
|
||||
static int tesla_gear = TESLA_DI_GEAR_P;
|
||||
static int toyota_gear = TOYOTA_GEAR_P;
|
||||
static int toyota_hybrid_gear = TOYOTA_HYBRID_GEAR_P;
|
||||
static bool toyota_hybrid_gear_seen = false;
|
||||
|
||||
// GM exception
|
||||
if ((msg->addr == 0x1F1U) && (len == 8)) {
|
||||
@@ -218,8 +221,10 @@ void ignition_can_hook(CANPacket_t *msg) {
|
||||
ignition_can_cnt = 0U;
|
||||
}
|
||||
|
||||
// Toyota/Lexus exception
|
||||
if ((msg->addr == 0x3BCU) && (len == 8)) {
|
||||
// Toyota/Lexus exception. SecOC hybrids (e.g. Sienna 4th gen) report gear on
|
||||
// GEAR_PACKET_HYBRID (0x127); their GEAR_PACKET (0x3BC) does not read Park, so once
|
||||
// the hybrid gear packet is seen, don't let 0x3BC override it (Park -> ignition off).
|
||||
if ((msg->addr == 0x3BCU) && (len == 8) && !toyota_hybrid_gear_seen) {
|
||||
int gear = msg->data[1] & 0x3FU;
|
||||
if ((gear == 0) || (gear == 1) || (gear == 8) || (gear == 16) || (gear == 32)) {
|
||||
toyota_gear = gear;
|
||||
@@ -231,24 +236,14 @@ void ignition_can_hook(CANPacket_t *msg) {
|
||||
if ((msg->addr == 0x127U) && (len == 8)) {
|
||||
int gear = (msg->data[5] >> 4U) & 0xFU;
|
||||
if (gear <= 4) {
|
||||
toyota_hybrid_gear_seen = true;
|
||||
toyota_hybrid_gear = gear;
|
||||
ignition_can = toyota_hybrid_gear != TOYOTA_HYBRID_GEAR_P;
|
||||
ignition_can_cnt = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
// Volkswagen MEB exception
|
||||
if ((msg->addr == 0x3C0U) && (len == 4)) {
|
||||
int counter = msg->data[1] & 0xFU;
|
||||
|
||||
static int prev_counter_vw_meb = -1;
|
||||
if ((counter == ((prev_counter_vw_meb + 1) % 16)) && (prev_counter_vw_meb != -1)) {
|
||||
// Klemmen_Status_01->ZAS_Kl_15
|
||||
ignition_can = ((msg->data[2] >> 1) & 1U) != 0U;
|
||||
ignition_can_cnt = 0U;
|
||||
}
|
||||
prev_counter_vw_meb = counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ void set_intercept_relay(bool intercept, bool ignition_relay) {
|
||||
harness.relay_driven = true;
|
||||
}
|
||||
|
||||
// wait until we're not reading the analog voltages anymore
|
||||
while (harness.sbu_adc_lock) {}
|
||||
// The relay pins are separate from the SBU sense pins, so no need to wait for
|
||||
// orientation sampling: it runs in thread context, sees relay_driven set, and
|
||||
// discards its result. Spinning on sbu_adc_lock here would deadlock when called
|
||||
// from interrupt context while thread-context sampling holds the lock.
|
||||
|
||||
if (harness.status == HARNESS_STATUS_NORMAL) {
|
||||
set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, !ignition_relay);
|
||||
@@ -31,20 +33,25 @@ void set_intercept_relay(bool intercept, bool ignition_relay) {
|
||||
}
|
||||
|
||||
bool harness_check_ignition(void) {
|
||||
bool ret = false;
|
||||
// The SBU pins are in analog mode while orientation sampling is in flight
|
||||
// (thread context), so a digital read would return 0. Return the last good
|
||||
// value instead of spinning: this is called from interrupt context, where
|
||||
// waiting for preempted thread-context sampling to finish would deadlock.
|
||||
bool ret = harness.ignition_line;
|
||||
|
||||
// wait until we're not reading the analog voltages anymore
|
||||
while (harness.sbu_adc_lock) {}
|
||||
|
||||
switch(harness.status){
|
||||
case HARNESS_STATUS_NORMAL:
|
||||
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1);
|
||||
break;
|
||||
case HARNESS_STATUS_FLIPPED:
|
||||
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (!harness.sbu_adc_lock) {
|
||||
switch(harness.status){
|
||||
case HARNESS_STATUS_NORMAL:
|
||||
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1);
|
||||
break;
|
||||
case HARNESS_STATUS_FLIPPED:
|
||||
ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2);
|
||||
break;
|
||||
default:
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
harness.ignition_line = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -81,6 +88,12 @@ static uint8_t harness_detect_orientation(void) {
|
||||
set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT);
|
||||
set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT);
|
||||
harness.sbu_adc_lock = false;
|
||||
|
||||
// This runs in thread context and can be preempted by an interrupt driving
|
||||
// the relay mid-sample, which changes the SBU line voltages; discard
|
||||
if (harness.relay_driven) {
|
||||
ret = harness.status;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
#define HARNESS_STATUS_NORMAL 1U
|
||||
#define HARNESS_STATUS_FLIPPED 2U
|
||||
|
||||
// orientation sampling runs in thread context and shares this state with
|
||||
// interrupt handlers, so the fields are volatile
|
||||
struct harness_t {
|
||||
uint8_t status;
|
||||
uint16_t sbu1_voltage_mV;
|
||||
uint16_t sbu2_voltage_mV;
|
||||
bool relay_driven;
|
||||
bool sbu_adc_lock;
|
||||
volatile uint8_t status;
|
||||
volatile uint16_t sbu1_voltage_mV;
|
||||
volatile uint16_t sbu2_voltage_mV;
|
||||
volatile bool ignition_line;
|
||||
volatile bool relay_driven;
|
||||
volatile bool sbu_adc_lock;
|
||||
};
|
||||
extern struct harness_t harness;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user