Skip to content

Commit

Permalink
Merge branch 'commaai:master' into master-new
Browse files Browse the repository at this point in the history
  • Loading branch information
devtekve authored Nov 2, 2024
2 parents 1ac593f + 0b364ec commit e46d040
Show file tree
Hide file tree
Showing 25 changed files with 352 additions and 127 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/drivers.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: drivers
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

jobs:
build_socketcan:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
run: ${{ env.RUN }} "scons -j4 --ubsan"
- name: Build jungle firmware with FINAL_PROVISIONING support
run: ${{ env.RUN }} "FINAL_PROVISIONING=1 scons -j4 board/jungle"
- name: Build panda in release mode
run: ${{ env.RUN }} "CERT=certs/debug RELEASE=1 scons -j4"

unit_tests:
name: unit tests
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ repos:
additional_dependencies: ['numpy', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.6.8
hooks:
- id: ruff
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN pip3 install --break-system-packages --no-cache-dir $PYTHONPATH/panda/[dev]

# TODO: this should be a "pip install" or not even in this repo at all
RUN git config --global --add safe.directory $PYTHONPATH/panda
ENV OPENDBC_REF="5ed7a834a4e0e24c3968dd1e98ceb4b9d5f9791a"
ENV OPENDBC_REF="e1ce3619a5db661ef2b406ccf258a253baf6eebc"
RUN cd /tmp/ && \
git clone --depth 1 https://github.com/commaai/opendbc opendbc_repo && \
cd opendbc_repo && git fetch origin $OPENDBC_REF && git checkout FETCH_HEAD && rm -rf .git/ && \
Expand Down
14 changes: 11 additions & 3 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void cuatro_set_led(uint8_t color, bool enabled) {
set_gpio_output(GPIOD, 15, !enabled);
break;
case LED_GREEN:
set_gpio_output(GPIOD, 14, !enabled);
set_gpio_output(GPIOB, 2, !enabled);
break;
case LED_BLUE:
set_gpio_output(GPIOE, 2, !enabled);
Expand Down Expand Up @@ -71,12 +71,16 @@ static void cuatro_set_bootkick(BootState state) {
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}

static void cuatro_set_siren(bool enabled){
beeper_enable(enabled);
}

static void cuatro_init(void) {
red_chiplet_init();

// init LEDs as open drain
set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOD, 14, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOD, 15, OUTPUT_TYPE_OPEN_DRAIN);

// Power readout
Expand Down Expand Up @@ -120,6 +124,10 @@ static void cuatro_init(void) {

// Clock source
clock_source_init();

// Beeper
set_gpio_alternate(GPIOD, 14, GPIO_AF2_TIM4);
beeper_init();
}

board board_cuatro = {
Expand All @@ -143,7 +151,7 @@ board board_cuatro = {
.read_current_mA = cuatro_read_current_mA,
.set_fan_enabled = cuatro_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_siren = unused_set_siren,
.set_siren = cuatro_set_siren,
.set_bootkick = cuatro_set_bootkick,
.read_som_gpio = tres_read_som_gpio
};
1 change: 0 additions & 1 deletion board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static void tres_init(void) {
set_gpio_alternate(GPIOC, 10, GPIO_AF4_I2C5);
set_gpio_alternate(GPIOC, 11, GPIO_AF4_I2C5);
register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT10 | GPIO_OTYPER_OT11); // open drain
fake_siren_init();

// Clock source
clock_source_init();
Expand Down
26 changes: 26 additions & 0 deletions board/drivers/beeper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#define BEEPER_COUNTER_OVERFLOW 25000U // 4kHz

void beeper_enable(bool enabled) {
if (enabled) {
register_set_bits(&(TIM4->CCER), TIM_CCER_CC3E);
} else {
register_clear_bits(&(TIM4->CCER), TIM_CCER_CC3E);
}
}

void beeper_init(void) {
// Enable timer and auto-reload
register_set(&(TIM4->CR1), TIM_CR1_CEN | TIM_CR1_ARPE, 0x3FU);

// Set channel as PWM mode 1 and disable output
register_set_bits(&(TIM4->CCMR2), (TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3PE));
beeper_enable(false);

// Set max counter value and compare to get 50% duty
register_set(&(TIM4->CCR3), BEEPER_COUNTER_OVERFLOW / 2U, 0xFFFFU);
register_set(&(TIM4->ARR), BEEPER_COUNTER_OVERFLOW, 0xFFFFU);

// Update registers and clear counter
TIM4->EGR |= TIM_EGR_UG;
}
8 changes: 8 additions & 0 deletions board/drivers/fake_siren.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#define CODEC_I2C_ADDR 0x10

void fake_siren_init(void);

void fake_siren_codec_enable(bool enabled) {
if (enabled) {
bool success = true;
Expand All @@ -28,8 +30,14 @@ void fake_siren_codec_enable(bool enabled) {


void fake_siren_set(bool enabled) {
static bool initialized = false;
static bool fake_siren_enabled = false;

if (!initialized) {
fake_siren_init();
initialized = true;
}

if (enabled != fake_siren_enabled) {
fake_siren_codec_enable(enabled);
}
Expand Down
20 changes: 18 additions & 2 deletions board/jungle/scripts/can_health.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/usr/bin/env python3

import time
import re
from panda import PandaJungle

RED = '\033[91m'
GREEN = '\033[92m'

def colorize_errors(value):
if isinstance(value, str):
if re.search(r'(?i)No error', value):
return f'{GREEN}{value}\033[0m'
elif re.search(r'(?i)(?<!No error\s)(err|error)', value):
return f'{RED}{value}\033[0m'
return str(value)

if __name__ == "__main__":
jungle = PandaJungle()

while True:
print(chr(27) + "[2J") # clear screen
print("Connected to " + ("internal panda" if jungle.is_internal() else "External panda") + f" id: {jungle.get_serial()[0]}: {jungle.get_version()}")
for bus in range(3):
print(bus, jungle.can_health(bus))
print(f"\nBus {bus}:")
health = jungle.can_health(bus)
for key, value in health.items():
print(f"{key}: {colorize_errors(value)} ", end=" ")
print()
time.sleep(1)
17 changes: 11 additions & 6 deletions board/jungle/scripts/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ def sec_since_boot():

def can_printer():
p = PandaJungle()
print(f"Connected to: {p._serial}: {p.get_version()}")
time.sleep(1)

p.can_clear(0xFFFF)

start = sec_since_boot()
lp = sec_since_boot()
msgs = defaultdict(list)
canbus = int(os.getenv("CAN", "0"))
canbus = os.getenv("CAN")
while True:
can_recv = p.can_recv()
for address, dat, src in can_recv:
if src == canbus:
msgs[address].append(dat)
for address,dat, src in can_recv:
if canbus is None or str(src) == canbus:
msgs[address].append((dat, src))

if sec_since_boot() - lp > 0.1:
dd = chr(27) + "[2J"
dd += "%5.2f\n" % (sec_since_boot() - start)
for k,v in sorted(zip(list(msgs.keys()), [binascii.hexlify(x[-1]) for x in list(msgs.values())], strict=True)):
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k,k),len(msgs[k]), v)
for k, v in sorted(msgs.items()):
last_msg, last_src = v[-1]
dd += "%d: %s(%6d): %s\n" % (last_src, "%04X(%4d)" % (k, k), len(v), binascii.hexlify(last_msg).decode())
print(dd)
lp = sec_since_boot()

Expand Down
20 changes: 20 additions & 0 deletions board/jungle/scripts/spam_can.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import os
import random
from panda import PandaJungle

def get_test_string():
return b"test" + os.urandom(10)

if __name__ == "__main__":
p = PandaJungle()

p.set_safety_mode(PandaJungle.SAFETY_ALLOUTPUT)

print("Spamming all buses...")
while True:
at = random.randint(1, 2000)
st = get_test_string()[0:8]
bus = random.randint(0, 2)
p.can_send(at, st, bus)
# print("Sent message on bus: ", bus)
5 changes: 3 additions & 2 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,13 @@ int main(void) {
// panda has an FPU, let's use it!
enable_fpu();

microsecond_timer_init();

current_board->set_siren(false);
if (current_board->fan_max_rpm > 0U) {
fan_init();
}

microsecond_timer_init();

// init to SILENT and can silent
set_safety_mode(SAFETY_SILENT, 0U);

Expand Down
50 changes: 25 additions & 25 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,6 @@ static safety_config chrysler_init(uint16_t param) {
.CRUISE_BUTTONS = 0xB1, // Cruise control buttons
};

// CAN messages for the 5th gen RAM HD platform
static const ChryslerAddrs CHRYSLER_RAM_HD_ADDRS = {
.EPS_2 = 0x220, // EPS driver input torque
.ESP_1 = 0x140, // Brake pedal and vehicle speed
.ESP_8 = 0x11C, // Brake pedal and vehicle speed
.ECM_5 = 0x22F, // Throttle position sensor
.DAS_3 = 0x1F4, // ACC engagement states from DASM
.DAS_6 = 0x275, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 0x276, // LKAS controls from DASM
.CRUISE_BUTTONS = 0x23A, // Cruise control buttons
};

static RxCheck chrysler_ram_dt_rx_checks[] = {
{.msg = {{CHRYSLER_RAM_DT_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 100U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_DT_ADDRS.ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
Expand All @@ -240,14 +228,6 @@ static safety_config chrysler_init(uint16_t param) {
{.msg = {{CHRYSLER_ADDRS.DAS_3, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
};

static RxCheck chrysler_ram_hd_rx_checks[] = {
{.msg = {{CHRYSLER_RAM_HD_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 100U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ESP_8, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.DAS_3, 2, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
};

static const CanMsg CHRYSLER_TX_MSGS[] = {
{CHRYSLER_ADDRS.CRUISE_BUTTONS, 0, 3},
{CHRYSLER_ADDRS.LKAS_COMMAND, 0, 6},
Expand All @@ -260,21 +240,41 @@ static safety_config chrysler_init(uint16_t param) {
{CHRYSLER_RAM_DT_ADDRS.DAS_6, 0, 8},
};

#ifdef ALLOW_DEBUG
// CAN messages for the 5th gen RAM HD platform
static const ChryslerAddrs CHRYSLER_RAM_HD_ADDRS = {
.EPS_2 = 0x220, // EPS driver input torque
.ESP_1 = 0x140, // Brake pedal and vehicle speed
.ESP_8 = 0x11C, // Brake pedal and vehicle speed
.ECM_5 = 0x22F, // Throttle position sensor
.DAS_3 = 0x1F4, // ACC engagement states from DASM
.DAS_6 = 0x275, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 0x276, // LKAS controls from DASM
.CRUISE_BUTTONS = 0x23A, // Cruise control buttons
};

static RxCheck chrysler_ram_hd_rx_checks[] = {
{.msg = {{CHRYSLER_RAM_HD_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 100U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ESP_8, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.DAS_3, 2, 8, .check_checksum = true, .max_counter = 15U, .frequency = 50U}, { 0 }, { 0 }}},
};

static const CanMsg CHRYSLER_RAM_HD_TX_MSGS[] = {
{CHRYSLER_RAM_HD_ADDRS.CRUISE_BUTTONS, 2, 3},
{CHRYSLER_RAM_HD_ADDRS.LKAS_COMMAND, 0, 8},
{CHRYSLER_RAM_HD_ADDRS.DAS_6, 0, 8},
};

safety_config ret;

bool enable_ram_dt = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT);

#ifdef ALLOW_DEBUG
const uint32_t CHRYSLER_PARAM_RAM_HD = 2U; // set for Ram HD platform
bool enable_ram_hd = GET_FLAG(param, CHRYSLER_PARAM_RAM_HD);
#endif

safety_config ret;

bool enable_ram_dt = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT);

if (enable_ram_dt) {
chrysler_platform = CHRYSLER_RAM_DT;
chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS;
Expand Down
9 changes: 7 additions & 2 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ static const SteeringLimits FORD_STEERING_LIMITS = {
.max_angle_error = 100, // 0.002 * FORD_STEERING_LIMITS.angle_deg_to_can
.angle_rate_up_lookup = {
{5., 25., 25.},
{0.0002, 0.0001, 0.0001}
{0.00045, 0.0001, 0.0001}
},
.angle_rate_down_lookup = {
{5., 25., 25.},
{0.000225, 0.00015, 0.00015}
{0.00045, 0.00015, 0.00015}
},

// no blending at low speed due to lack of torque wind-up and inaccurate current curvature
Expand Down Expand Up @@ -223,6 +223,9 @@ static bool ford_tx_hook(const CANPacket_t *to_send) {
// Signal: CmbbDeny_B_Actl
bool cmbb_deny = GET_BIT(to_send, 37U);

// Signal: AccBrkPrchg_B_Rq & AccBrkDecel_B_Rq
bool brake_actuation = GET_BIT(to_send, 54U) || GET_BIT(to_send, 55U);

bool violation = false;
violation |= longitudinal_accel_checks(accel, FORD_LONG_LIMITS);
violation |= longitudinal_gas_checks(gas, FORD_LONG_LIMITS);
Expand All @@ -231,6 +234,8 @@ static bool ford_tx_hook(const CANPacket_t *to_send) {
// Safety check for stock AEB
violation |= cmbb_deny; // do not prevent stock AEB actuation

violation |= !get_longitudinal_allowed() && brake_actuation;

if (violation) {
tx = false;
}
Expand Down
Loading

0 comments on commit e46d040

Please sign in to comment.