Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
csouers committed Jan 26, 2024
2 parents f7171ea + eb9b0df commit b574b60
Show file tree
Hide file tree
Showing 80 changed files with 450 additions and 385 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
timeout-minutes: 1
run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh"
- name: MISRA mutation tests
timeout-minutes: 2
timeout-minutes: 3
run: ${{ env.RUN }} "cd tests/misra && ./test_mutation.py"

python_linter:
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: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
rev: v0.1.14
hooks:
- id: ruff
3 changes: 2 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def build_project(project_name, project, extra_flags):
ASCOM="$AS $ASFLAGS -o $TARGET -c $SOURCES",
BUILDERS={
'Objcopy': Builder(generator=objcopy, suffix='.bin', src_suffix='.elf')
}
},
tools=["default", "compilation_db"],
)

startup = env.Object(f"obj/startup_{project_name}", project["STARTUP_FILE"])
Expand Down
12 changes: 12 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,17 @@ AddOption('--coverage',
action='store_true',
help='build with test coverage options')

AddOption('--compile_db',
action='store_true',
help='build clang compilation database')

env = Environment(
COMPILATIONDB_USE_ABSPATH=True,
tools=["default", "compilation_db"],
)

if GetOption('compile_db'):
env.CompilationDatabase("compile_commands.json")

# panda fw & test files
SConscript('SConscript')
3 changes: 3 additions & 0 deletions board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ for project_name, project in build_projects.items():
if ("ENABLE_SPI" in os.environ or "h7" in project_name) and not project_name.startswith('pedal'):
flags.append('-DENABLE_SPI')

if "H723" in os.environ:
flags.append('-DSTM32H723')

build_project(project_name, project, flags)
1 change: 0 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const harness_configuration black_harness_config = {
};

const board board_black = {
.board_type = "Black",
.set_bootkick = unused_set_bootkick,
.harness_config = &black_harness_config,
.has_hw_gmlan = false,
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 @@ -20,7 +20,6 @@ typedef void (*board_set_bootkick)(BootState state);
typedef bool (*board_read_som_gpio)(void);

struct board {
const char *board_type;
const harness_configuration *harness_config;
const bool has_hw_gmlan;
const bool has_obd;
Expand Down Expand Up @@ -58,6 +57,7 @@ struct board {
#define HW_TYPE_RED_PANDA 7U
#define HW_TYPE_RED_PANDA_V2 8U
#define HW_TYPE_TRES 9U
#define HW_TYPE_CUATRO 10U

// LED colors
#define LED_RED 0U
Expand Down
71 changes: 71 additions & 0 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOD, 15, !enabled);
break;
case LED_GREEN:
set_gpio_output(GPIOD, 14, !enabled);
break;
case LED_BLUE:
set_gpio_output(GPIOE, 2, !enabled);
break;
default:
break;
}
}

void cuatro_init(void) {
red_chiplet_init();

// C2: SOM GPIO used as input (fan control at boot)
set_gpio_mode(GPIOC, 2, MODE_INPUT);
set_gpio_pullup(GPIOC, 2, PULL_DOWN);

// SOM bootkick + reset lines
set_gpio_mode(GPIOC, 12, MODE_OUTPUT);
tres_set_bootkick(BOOT_BOOTKICK);

// SOM debugging UART
gpio_uart7_init();
uart_init(&uart_ring_som_debug, 115200);

// SPI init
gpio_spi_init();

// fan setup
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);

// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOC, 9, GPIO_AF2_TIM3);
pwm_init(TIM3, 4);
tres_set_ir_power(0U);

// Clock source
clock_source_init();
}

const board board_cuatro = {
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
.has_spi = true,
.has_canfd = true,
.has_rtc_battery = true,
.fan_max_rpm = 6600U,
.avdd_mV = 1800U,
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 3U,
.init = cuatro_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = red_chiplet_enable_can_transceiver,
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
.set_led = cuatro_set_led,
.set_can_mode = red_chiplet_set_can_mode,
.check_ignition = red_check_ignition,
.read_current = unused_read_current,
.set_fan_enabled = tres_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_siren = unused_set_siren,
.set_bootkick = tres_set_bootkick,
.read_som_gpio = tres_read_som_gpio
};
1 change: 0 additions & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const harness_configuration dos_harness_config = {
};

const board board_dos = {
.board_type = "Dos",
.harness_config = &dos_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Most hardware functionality is similar to white panda

const board board_grey = {
.board_type = "Grey",
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const harness_configuration pedal_harness_config = {
};

const board board_pedal = {
.board_type = "Pedal",
.set_bootkick = unused_set_bootkick,
.harness_config = &pedal_harness_config,
.has_hw_gmlan = false,
Expand Down
1 change: 0 additions & 1 deletion board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const harness_configuration red_harness_config = {
};

const board board_red = {
.board_type = "Red",
.set_bootkick = unused_set_bootkick,
.harness_config = &red_harness_config,
.has_hw_gmlan = false,
Expand Down
38 changes: 0 additions & 38 deletions board/boards/red_v2.h

This file was deleted.

1 change: 0 additions & 1 deletion board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void tres_init(void) {
}

const board board_tres = {
.board_type = "Tres",
.harness_config = &red_chiplet_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ const harness_configuration uno_harness_config = {
};

const board board_uno = {
.board_type = "Uno",
.harness_config = &uno_harness_config,
.has_hw_gmlan = false,
.has_obd = true,
Expand Down
1 change: 0 additions & 1 deletion board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ const harness_configuration white_harness_config = {
};

const board board_white = {
.board_type = "White",
.set_bootkick = unused_set_bootkick,
.harness_config = &white_harness_config,
.has_hw_gmlan = true,
Expand Down
2 changes: 1 addition & 1 deletion board/can_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int comms_can_read(uint8_t *data, uint32_t max_len) {
asm_buffer can_write_buffer = {.ptr = 0U, .tail_size = 0U};

// send on CAN
void comms_can_write(uint8_t *data, uint32_t len) {
void comms_can_write(const uint8_t *data, uint32_t len) {
uint32_t pos = 0U;

// Assembling can message with data from buffer
Expand Down
4 changes: 2 additions & 2 deletions board/comms_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ typedef struct {
} __attribute__((packed)) ControlPacket_t;

int comms_control_handler(ControlPacket_t *req, uint8_t *resp);
void comms_endpoint2_write(uint8_t *data, uint32_t len);
void comms_can_write(uint8_t *data, uint32_t len);
void comms_endpoint2_write(const uint8_t *data, uint32_t len);
void comms_can_write(const uint8_t *data, uint32_t len);
int comms_can_read(uint8_t *data, uint32_t max_len);
void comms_can_reset(void);
2 changes: 1 addition & 1 deletion board/crc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

uint8_t crc_checksum(uint8_t *dat, int len, const uint8_t poly) {
uint8_t crc_checksum(const uint8_t *dat, int len, const uint8_t poly) {
uint8_t crc = 0xFFU;
int i;
int j;
Expand Down
6 changes: 3 additions & 3 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool can_pop(can_ring *q, CANPacket_t *elem) {
return ret;
}

bool can_push(can_ring *q, CANPacket_t *elem) {
bool can_push(can_ring *q, const CANPacket_t *elem) {
bool ret = false;
uint32_t next_w_ptr;

Expand Down Expand Up @@ -133,7 +133,7 @@ bool can_push(can_ring *q, CANPacket_t *elem) {
return ret;
}

uint32_t can_slots_empty(can_ring *q) {
uint32_t can_slots_empty(const can_ring *q) {
uint32_t ret = 0;

ENTER_CRITICAL();
Expand Down Expand Up @@ -238,7 +238,7 @@ bool can_tx_check_min_slots_free(uint32_t min) {
(can_slots_empty(&can_txgmlan_q) >= min);
}

uint8_t calculate_checksum(uint8_t *dat, uint32_t len) {
uint8_t calculate_checksum(const uint8_t *dat, uint32_t len) {
uint8_t checksum = 0U;
for (uint32_t i = 0U; i < len; i++) {
checksum ^= dat[i];
Expand Down
8 changes: 4 additions & 4 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ void process_can(uint8_t can_number) {

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)
uint8_t tx_index = (FDCANx->TXFQS >> FDCAN_TXFQS_TFQPI_Pos) & 0x1F;
uint32_t tx_index = (FDCANx->TXFQS >> FDCAN_TXFQS_TFQPI_Pos) & 0x1F;
// only send if we have received a packet
canfd_fifo *fifo;
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 ? (1 << 21) : 0;
uint32_t brs_enabled_header = bus_config[can_number].brs_enabled ? (1 << 20) : 0;
uint32_t canfd_enabled_header = bus_config[can_number].canfd_enabled ? (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;

uint8_t data_len_w = (dlc_to_len[to_send.data_len_code] / 4U);
Expand Down Expand Up @@ -165,7 +165,7 @@ void can_rx(uint8_t can_number) {
pending_can_live = 1;

// get the index of the next RX FIFO element (0 to FDCAN_RX_FIFO_0_EL_CNT - 1)
uint8_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) & 0x3F);

// 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
Loading

0 comments on commit b574b60

Please sign in to comment.