Skip to content

Commit

Permalink
Merge branch 'commaai:master' into secoc-long
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispypatt authored Dec 3, 2024
2 parents a18c2be + c7cc2de commit 218d6af
Show file tree
Hide file tree
Showing 30 changed files with 238 additions and 58 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ jobs:
scons -j$(nproc) ${{ matrix.flags }} && \
tests/safety/test.sh"
misra:
name: MISRA C:2012
misra_linter:
name: MISRA C:2012 Linter
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand All @@ -99,8 +99,19 @@ jobs:
- name: Build FW
run: ${{ env.RUN }} "scons -j$(nproc)"
- name: Run MISRA C:2012 analysis
timeout-minutes: 1
timeout-minutes: 2
run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh"

misra_mutation:
name: MISRA C:2012 Mutation
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Build FW
run: ${{ env.RUN }} "scons -j$(nproc)"
- name: MISRA mutation tests
timeout-minutes: 5
run: ${{ env.RUN }} "cd tests/misra && pytest -n8 test_mutation.py"
Expand Down
3 changes: 2 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,6 @@ board board_black = {
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
.read_som_gpio = unused_read_som_gpio
.read_som_gpio = unused_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
2 changes: 2 additions & 0 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef void (*board_set_fan_enabled)(bool enabled);
typedef void (*board_set_siren)(bool enabled);
typedef void (*board_set_bootkick)(BootState state);
typedef bool (*board_read_som_gpio)(void);
typedef void (*board_set_amp_enabled)(bool enabled);

struct board {
harness_configuration *harness_config;
Expand All @@ -49,6 +50,7 @@ struct board {
board_set_siren set_siren;
board_set_bootkick set_bootkick;
board_read_som_gpio read_som_gpio;
board_set_amp_enabled set_amp_enabled;
};

// ******************* Definitions ********************
Expand Down
24 changes: 22 additions & 2 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ static void cuatro_set_siren(bool enabled){
beeper_enable(enabled);
}

static void cuatro_set_amp_enabled(bool enabled){
set_gpio_output(GPIOA, 5, enabled);
}

static void cuatro_init(void) {
red_chiplet_init();

Expand All @@ -83,6 +87,10 @@ static void cuatro_init(void) {
set_gpio_output_type(GPIOB, 2, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOD, 15, OUTPUT_TYPE_OPEN_DRAIN);

// more open drain
set_gpio_output_type(GPIOD, 3, OUTPUT_TYPE_OPEN_DRAIN); // FAN_EN
set_gpio_output_type(GPIOC, 12, OUTPUT_TYPE_OPEN_DRAIN); // VBAT_EN

// Power readout
set_gpio_mode(GPIOC, 5, MODE_ANALOG);
set_gpio_mode(GPIOA, 6, MODE_ANALOG);
Expand Down Expand Up @@ -128,6 +136,17 @@ static void cuatro_init(void) {
// Beeper
set_gpio_alternate(GPIOD, 14, GPIO_AF2_TIM4);
beeper_init();

// Sound codec
cuatro_set_amp_enabled(false);
set_gpio_alternate(GPIOA, 2, GPIO_AF8_SAI4); // SAI4_SCK_B
set_gpio_alternate(GPIOC, 0, GPIO_AF8_SAI4); // SAI4_FS_B
set_gpio_alternate(GPIOD, 11, GPIO_AF10_SAI4); // SAI4_SD_A
set_gpio_alternate(GPIOE, 3, GPIO_AF8_SAI4); // SAI4_SD_B
set_gpio_alternate(GPIOE, 4, GPIO_AF2_SAI1); // SAI1_D2
set_gpio_alternate(GPIOE, 5, GPIO_AF2_SAI1); // SAI1_CK2
set_gpio_alternate(GPIOE, 6, GPIO_AF10_SAI4); // SAI4_MCLK_B
sound_init();
}

board board_cuatro = {
Expand All @@ -150,8 +169,9 @@ board board_cuatro = {
.read_voltage_mV = cuatro_read_voltage_mV,
.read_current_mA = cuatro_read_current_mA,
.set_fan_enabled = cuatro_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_ir_power = unused_set_ir_power,
.set_siren = cuatro_set_siren,
.set_bootkick = cuatro_set_bootkick,
.read_som_gpio = tres_read_som_gpio
.read_som_gpio = tres_read_som_gpio,
.set_amp_enabled = cuatro_set_amp_enabled
};
3 changes: 2 additions & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,6 @@ board board_dos = {
.set_ir_power = dos_set_ir_power,
.set_siren = dos_set_siren,
.set_bootkick = dos_set_bootkick,
.read_som_gpio = dos_read_som_gpio
.read_som_gpio = dos_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
3 changes: 2 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ board board_grey = {
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
.read_som_gpio = unused_read_som_gpio
.read_som_gpio = unused_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
3 changes: 2 additions & 1 deletion board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ board board_red = {
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
.read_som_gpio = unused_read_som_gpio
.read_som_gpio = unused_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
3 changes: 2 additions & 1 deletion board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ board board_tres = {
.set_ir_power = tres_set_ir_power,
.set_siren = fake_siren_set,
.set_bootkick = tres_set_bootkick,
.read_som_gpio = tres_read_som_gpio
.read_som_gpio = tres_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
3 changes: 2 additions & 1 deletion board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@ board board_uno = {
.set_ir_power = uno_set_ir_power,
.set_siren = unused_set_siren,
.set_bootkick = uno_set_bootkick,
.read_som_gpio = unused_read_som_gpio
.read_som_gpio = unused_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
4 changes: 4 additions & 0 deletions board/boards/unused_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ void unused_set_bootkick(BootState state) {
bool unused_read_som_gpio(void) {
return false;
}

void unused_set_amp_enabled(bool enabled) {
UNUSED(enabled);
}
3 changes: 2 additions & 1 deletion board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,6 @@ board board_white = {
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
.read_som_gpio = unused_read_som_gpio
.read_som_gpio = unused_read_som_gpio,
.set_amp_enabled = unused_set_amp_enabled
};
2 changes: 1 addition & 1 deletion board/can_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#endif

typedef struct {
unsigned char reserved : 1;
unsigned char fd : 1;
unsigned char bus : 3;
unsigned char data_len_code : 4; // lookup length with dlc_to_len
unsigned char rejected : 1;
Expand Down
3 changes: 3 additions & 0 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void process_can(uint8_t can_number) {
if ((CANx->TSR & CAN_TSR_RQCP0) == CAN_TSR_RQCP0) {
if ((CANx->TSR & CAN_TSR_TXOK0) == CAN_TSR_TXOK0) {
CANPacket_t to_push;
to_push.fd = 0U;
to_push.returned = 1U;
to_push.rejected = 0U;
to_push.extended = (CANx->sTxMailBox[0].TIR >> 2) & 0x1U;
Expand Down Expand Up @@ -144,6 +145,7 @@ void can_rx(uint8_t can_number) {
// add to my fifo
CANPacket_t to_push;

to_push.fd = 0U;
to_push.returned = 0U;
to_push.rejected = 0U;
to_push.extended = (CANx->sFIFOMailBox[0].RIR >> 2) & 0x1U;
Expand All @@ -159,6 +161,7 @@ void can_rx(uint8_t can_number) {
if (bus_fwd_num != -1) {
CANPacket_t to_send;

to_send.fd = 0U;
to_send.returned = 0U;
to_send.rejected = 0U;
to_send.extended = to_push.extended; // TXRQ
Expand Down
10 changes: 5 additions & 5 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ void can_clear(can_ring *q) {
// Helpers
// Panda: Bus 0=CAN1 Bus 1=CAN2 Bus 2=CAN3
bus_config_t bus_config[BUS_CONFIG_ARRAY_SIZE] = {
{ .bus_lookup = 0U, .can_num_lookup = 0U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 1U, .can_num_lookup = 1U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 2U, .can_num_lookup = 2U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 0xFFU, .can_num_lookup = 0xFFU, .forwarding_bus = -1, .can_speed = 333U, .can_data_speed = 333U, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 0U, .can_num_lookup = 0U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 1U, .can_num_lookup = 1U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 2U, .can_num_lookup = 2U, .forwarding_bus = -1, .can_speed = 5000U, .can_data_speed = 20000U, .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
{ .bus_lookup = 0xFFU, .can_num_lookup = 0xFFU, .forwarding_bus = -1, .can_speed = 333U, .can_data_speed = 333U, .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
};

void can_init_all(void) {
Expand Down Expand Up @@ -165,7 +165,7 @@ void ignition_can_hook(CANPacket_t *to_push) {
if (bus == 0) {
int addr = GET_ADDR(to_push);
int len = GET_LEN(to_push);

// GM exception
if ((addr == 0x1F1) && (len == 8)) {
// SystemPowerMode (2=Run, 3=Crank Request)
Expand Down
1 change: 1 addition & 0 deletions board/drivers/can_common_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
int8_t forwarding_bus;
uint32_t can_speed;
uint32_t can_data_speed;
bool canfd_auto;
bool canfd_enabled;
bool brs_enabled;
bool canfd_non_iso;
Expand Down
15 changes: 11 additions & 4 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ void process_can(uint8_t can_number) {
fifo = (canfd_fifo *)(TxFIFOSA + (tx_index * FDCAN_TX_FIFO_EL_SIZE));

fifo->header[0] = (to_send.extended << 30) | ((to_send.extended != 0U) ? (to_send.addr) : (to_send.addr << 18));
uint32_t canfd_enabled_header = bus_config[can_number].canfd_enabled ? (1UL << 21) : 0UL;

// If canfd_auto is set, outgoing packets will be automatically sent as CAN-FD if an incoming CAN-FD packet was seen
bool fd = bus_config[can_number].canfd_auto ? bus_config[can_number].canfd_enabled : (bool)(to_send.fd > 0U);
uint32_t canfd_enabled_header = fd ? (1UL << 21) : 0UL;

uint32_t brs_enabled_header = bus_config[can_number].brs_enabled ? (1UL << 20) : 0UL;
fifo->header[1] = (to_send.data_len_code << 16) | canfd_enabled_header | brs_enabled_header;

Expand All @@ -115,6 +119,7 @@ void process_can(uint8_t can_number) {
// Send back to USB
CANPacket_t to_push;

to_push.fd = fd;
to_push.returned = 1U;
to_push.rejected = 0U;
to_push.extended = to_send.extended;
Expand Down Expand Up @@ -168,16 +173,17 @@ void can_rx(uint8_t can_number) {
// getting address
fifo = (canfd_fifo *)(RxFIFO0SA + (rx_fifo_idx * FDCAN_RX_FIFO_0_EL_SIZE));

bool canfd_frame = ((fifo->header[1] >> 21) & 0x1U);
bool brs_frame = ((fifo->header[1] >> 20) & 0x1U);

to_push.fd = canfd_frame;
to_push.returned = 0U;
to_push.rejected = 0U;
to_push.extended = (fifo->header[0] >> 30) & 0x1U;
to_push.addr = ((to_push.extended != 0U) ? (fifo->header[0] & 0x1FFFFFFFU) : ((fifo->header[0] >> 18) & 0x7FFU));
to_push.bus = bus_number;
to_push.data_len_code = ((fifo->header[1] >> 16) & 0xFU);

bool canfd_frame = ((fifo->header[1] >> 21) & 0x1U);
bool brs_frame = ((fifo->header[1] >> 20) & 0x1U);

uint8_t data_len_w = (dlc_to_len[to_push.data_len_code] / 4U);
data_len_w += ((dlc_to_len[to_push.data_len_code] % 4U) > 0U) ? 1U : 0U;
for (unsigned int i = 0; i < data_len_w; i++) {
Expand All @@ -193,6 +199,7 @@ void can_rx(uint8_t can_number) {
if (bus_fwd_num != -1) {
CANPacket_t to_send;

to_send.fd = to_push.fd;
to_send.returned = 0U;
to_send.rejected = 0U;
to_send.extended = to_push.extended;
Expand Down
1 change: 1 addition & 0 deletions board/faults_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define FAULT_INTERRUPT_RATE_UART_7 (1UL << 24)
#define FAULT_SIREN_MALFUNCTION (1UL << 25)
#define FAULT_HEARTBEAT_LOOP_WATCHDOG (1UL << 26)
#define FAULT_INTERRUPT_RATE_SOUND_DMA (1UL << 27)

// Permanent faults
#define PERMANENT_FAULTS 0U
Expand Down
18 changes: 11 additions & 7 deletions board/jungle/scripts/can_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ def can_printer():

start = sec_since_boot()
lp = sec_since_boot()
msgs = defaultdict(list)
all_msgs = defaultdict(list)

canbus = os.getenv("CAN")
if canbus == "3":
p.set_obd(True)
canbus = "1"

while True:
can_recv = p.can_recv()
for address,dat, src in can_recv:
if canbus is None or str(src) == canbus:
msgs[address].append((dat, src))
for addr, dat, bus in can_recv:
if canbus is None or str(bus) == canbus:
all_msgs[(addr, bus)].append((dat))

if sec_since_boot() - lp > 0.1:
dd = chr(27) + "[2J"
dd += "%5.2f\n" % (sec_since_boot() - start)
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())
for (addr, bus), dat_log in sorted(all_msgs.items()):
dd += "%d: %s(%6d): %s\n" % (bus, "%04X(%4d)" % (addr, addr), len(dat_log), binascii.hexlify(dat_log[-1]).decode())
print(dd)
lp = sec_since_boot()

Expand Down
3 changes: 2 additions & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ static void tick_handler(void) {
usb_tick();
harness_tick();
simple_watchdog_kick();
sound_tick();

// re-init everything that uses harness status
if (harness.status != prev_harness_status) {
Expand Down Expand Up @@ -240,7 +241,7 @@ static void tick_handler(void) {
print(" seconds. Safety is set to SILENT mode.\n");

if (controls_allowed_countdown > 0U) {
siren_countdown = 5U;
siren_countdown = 3U;
controls_allowed_countdown = 0U;
}

Expand Down
4 changes: 4 additions & 0 deletions board/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
case 0xe7:
set_power_save_state(req->param1);
break;
// **** 0xe8: set can-fd auto swithing mode
case 0xe8:
bus_config[req->param1].canfd_auto = req->param2 > 0U;
break;
// **** 0xf1: Clear CAN ring buffer.
case 0xf1:
if (req->param1 == 0xFFFFU) {
Expand Down
8 changes: 1 addition & 7 deletions board/recover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
import os
import time
import subprocess
import argparse

from panda import Panda, PandaDFU

board_path = os.path.dirname(os.path.realpath(__file__))

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--all", action="store_true", help="Recover all Panda devices")
args = parser.parse_args()

subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) {board_path}", shell=True)

serials = Panda.list() if args.all else [None]
for s in serials:
for s in Panda.list():
with Panda(serial=s) as p:
print(f"putting {p.get_usb_serial()} in DFU mode")
p.reset(enter_bootstub=True)
Expand Down
3 changes: 3 additions & 0 deletions board/stm32f4/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "boards/uno.h"
#include "boards/dos.h"

// Unused functions on F4
void sound_tick(void) {}

void detect_board_type(void) {
// SPI lines floating: white (TODO: is this reliable? Not really, we have to enable ESP/GPS to be able to detect this on the UART)
set_gpio_output(GPIOC, 14, 1);
Expand Down
1 change: 1 addition & 0 deletions board/stm32h7/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "stm32h7/lldac.h"
#include "drivers/beeper.h"
#include "drivers/fake_siren.h"
#include "stm32h7/sound.h"
#include "drivers/clock_source.h"
#include "boards/red.h"
#include "boards/red_chiplet.h"
Expand Down
Loading

0 comments on commit 218d6af

Please sign in to comment.