Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/commaai/panda into alfa-r…
Browse files Browse the repository at this point in the history
…omeo
  • Loading branch information
jyoung8607 committed Oct 7, 2024
2 parents 583a490 + abdc418 commit ac2a556
Show file tree
Hide file tree
Showing 111 changed files with 8,591 additions and 7,376 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ jobs:
timeout-minutes: 5
run: ${{ env.RUN }} "cd tests/misra && pytest -n8 test_mutation.py"

mutation:
name: Mutation tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # need master to get diff
- name: Build Docker image
run: eval "$BUILD"
- name: Mutation tests
timeout-minutes: 5
run: ${{ env.RUN }} "GIT_REF=${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.event.before || 'origin/master' }} cd tests/safety && ./mutation.sh"

static_analysis:
name: static analysis
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ nosetests.xml
*.gcno
tests/safety/coverage-out
tests/safety/coverage.info

*.profraw
*.profdata
mull.yml
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
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
apt clean && \
cd /usr/lib/gcc/arm-none-eabi/* && \
rm -rf arm/ && \
rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp
rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp && \
apt-get update && apt-get install -y clang-17 && \
ln -s $(which clang-17) /usr/bin/clang

RUN apt-get update && apt-get install -y curl && \
curl -1sLf 'https://dl.cloudsmith.io/public/mull-project/mull-stable/setup.deb.sh' | bash && \
apt-get update && apt-get install -y mull-17

ENV CPPCHECK_DIR=/tmp/cppcheck
COPY tests/misra/install.sh /tmp/
Expand All @@ -31,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
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pipeline {
phone_steps("panda-tres", [
["build", "scons -j4"],
["flash", "cd tests/ && ./reflash_internal_panda.py"],
["flash jungle", "cd board/jungle && ./flash.py"],
["flash jungle", "cd board/jungle && ./flash.py --all"],
["test", "cd tests/hitl && HW_TYPES=9 pytest -n0 --durations=0 2*.py [5-9]*.py"],
])
}
Expand All @@ -118,7 +118,7 @@ pipeline {
phone_steps("panda-dos", [
["build", "scons -j4"],
["flash", "cd tests/ && ./reflash_internal_panda.py"],
["flash jungle", "cd board/jungle && ./flash.py"],
["flash jungle", "cd board/jungle && ./flash.py --all"],
["test", "cd tests/hitl && HW_TYPES=6 pytest -n0 --durations=0 [2-9]*.py -k 'not test_send_recv'"],
])
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ In addition, we run the [ruff linter](https://github.com/astral-sh/ruff) and [my
Setup dependencies:
```bash
# Ubuntu
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git clang-17

# macOS
brew install --cask gcc-arm-embedded
Expand Down
4 changes: 3 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ Export('base_project_f4', 'base_project_h7', 'build_project')

# Common autogenerated includes
with open("board/obj/gitversion.h", "w") as f:
f.write(f'const uint8_t gitversion[] = "{get_version(BUILDER, BUILD_TYPE)}";\n')
version = get_version(BUILDER, BUILD_TYPE)
f.write(f'extern const uint8_t gitversion[{len(version)}];\n')
f.write(f'const uint8_t gitversion[{len(version)}] = "{version}";\n')

with open("board/obj/version", "w") as f:
f.write(f'{get_version(BUILDER, BUILD_TYPE)}')
Expand Down
4 changes: 4 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ AddOption('--compile_db',
action='store_true',
help='build clang compilation database')

AddOption('--mutation',
action='store_true',
help='generate mutation-ready code')

env = Environment(
COMPILATIONDB_USE_ABSPATH=True,
tools=["default", "compilation_db"],
Expand Down
7 changes: 7 additions & 0 deletions board/can.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "can_declarations.h"

static const uint8_t PANDA_CAN_CNT = 3U;
static const uint8_t PANDA_BUS_CNT = 3U;

static const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};
12 changes: 6 additions & 6 deletions board/can_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {
uint8_t data[72];
} asm_buffer;

asm_buffer can_read_buffer = {.ptr = 0U, .tail_size = 0U};
static asm_buffer can_read_buffer = {.ptr = 0U, .tail_size = 0U};

int comms_can_read(uint8_t *data, uint32_t max_len) {
uint32_t pos = 0U;
Expand All @@ -38,10 +38,10 @@ int comms_can_read(uint8_t *data, uint32_t max_len) {
while ((pos < max_len) && can_pop(&can_rx_q, &can_packet)) {
uint32_t pckt_len = CANPACKET_HEAD_SIZE + dlc_to_len[can_packet.data_len_code];
if ((pos + pckt_len) <= max_len) {
(void)memcpy(&data[pos], &can_packet, pckt_len);
(void)memcpy(&data[pos], (uint8_t*)&can_packet, pckt_len);
pos += pckt_len;
} else {
(void)memcpy(&data[pos], &can_packet, max_len - pos);
(void)memcpy(&data[pos], (uint8_t*)&can_packet, max_len - pos);
can_read_buffer.ptr += pckt_len - (max_len - pos);
// cppcheck-suppress objectIndex
(void)memcpy(can_read_buffer.data, &((uint8_t*)&can_packet)[(max_len - pos)], can_read_buffer.ptr);
Expand All @@ -53,7 +53,7 @@ int comms_can_read(uint8_t *data, uint32_t max_len) {
return pos;
}

asm_buffer can_write_buffer = {.ptr = 0U, .tail_size = 0U};
static asm_buffer can_write_buffer = {.ptr = 0U, .tail_size = 0U};

// send on CAN
void comms_can_write(const uint8_t *data, uint32_t len) {
Expand All @@ -69,7 +69,7 @@ void comms_can_write(const uint8_t *data, uint32_t len) {
pos += can_write_buffer.tail_size;

// send out
(void)memcpy(&to_push, can_write_buffer.data, can_write_buffer.ptr);
(void)memcpy((uint8_t*)&to_push, can_write_buffer.data, can_write_buffer.ptr);
can_send(&to_push, to_push.bus, false);

// reset overflow buffer
Expand All @@ -90,7 +90,7 @@ void comms_can_write(const uint8_t *data, uint32_t len) {
uint32_t pckt_len = CANPACKET_HEAD_SIZE + dlc_to_len[(data[pos] >> 4U)];
if ((pos + pckt_len) <= len) {
CANPacket_t to_push = {0};
(void)memcpy(&to_push, &data[pos], pckt_len);
(void)memcpy((uint8_t*)&to_push, &data[pos], pckt_len);
can_send(&to_push, to_push.bus, false);
pos += pckt_len;
} else {
Expand Down
5 changes: 0 additions & 5 deletions board/can_definitions.h → board/can_declarations.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

const uint8_t PANDA_CAN_CNT = 3U;
const uint8_t PANDA_BUS_CNT = 3U;

// bump this when changing the CAN packet
#define CAN_PACKET_VERSION 4

Expand All @@ -27,8 +24,6 @@ typedef struct {
unsigned char data[CANPACKET_DATA_SIZE_MAX];
} __attribute__((packed, aligned(4))) CANPacket_t;

const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};

#define GET_BUS(msg) ((msg)->bus)
#define GET_LEN(msg) (dlc_to_len[(msg)->data_len_code])
#define GET_ADDR(msg) ((msg)->addr)
17 changes: 5 additions & 12 deletions board/critical.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "critical_declarations.h"

// ********************* Critical section helpers *********************
volatile bool interrupts_enabled = false;
uint8_t global_critical_depth = 0U;

static volatile bool interrupts_enabled = false;

void enable_interrupts(void) {
interrupts_enabled = true;
Expand All @@ -10,14 +14,3 @@ void disable_interrupts(void) {
interrupts_enabled = false;
__disable_irq();
}

uint8_t global_critical_depth = 0U;
#define ENTER_CRITICAL() \
__disable_irq(); \
global_critical_depth += 1U;

#define EXIT_CRITICAL() \
global_critical_depth -= 1U; \
if ((global_critical_depth == 0U) && interrupts_enabled) { \
__enable_irq(); \
}
17 changes: 17 additions & 0 deletions board/critical_declarations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

// ********************* Critical section helpers *********************
void enable_interrupts(void);
void disable_interrupts(void);

extern uint8_t global_critical_depth;

#define ENTER_CRITICAL() \
__disable_irq(); \
global_critical_depth += 1U;

#define EXIT_CRITICAL() \
global_critical_depth -= 1U; \
if ((global_critical_depth == 0U) && interrupts_enabled) { \
__enable_irq(); \
}
13 changes: 7 additions & 6 deletions board/drivers/bootkick.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
bool bootkick_ign_prev = false;
BootState boot_state = BOOT_BOOTKICK;
uint8_t bootkick_harness_status_prev = HARNESS_STATUS_NC;
#include "bootkick_declarations.h"

uint8_t boot_reset_countdown = 0;
uint8_t waiting_to_boot_countdown = 0;
bool bootkick_reset_triggered = false;
uint16_t bootkick_last_serial_ptr = 0;

void bootkick_tick(bool ignition, bool recent_heartbeat) {
static uint16_t bootkick_last_serial_ptr = 0;
static uint8_t waiting_to_boot_countdown = 0;
static uint8_t boot_reset_countdown = 0;
static uint8_t bootkick_harness_status_prev = HARNESS_STATUS_NC;
static bool bootkick_ign_prev = false;
static BootState boot_state = BOOT_BOOTKICK;
BootState boot_state_prev = boot_state;
const bool harness_inserted = (harness.status != bootkick_harness_status_prev) && (harness.status != HARNESS_STATUS_NC);

Expand Down
5 changes: 5 additions & 0 deletions board/drivers/bootkick_declarations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

extern bool bootkick_reset_triggered;

void bootkick_tick(bool ignition, bool recent_heartbeat);
26 changes: 14 additions & 12 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "bxcan_declarations.h"

// IRQs: CAN1_TX, CAN1_RX0, CAN1_SCE
// CAN2_TX, CAN2_RX0, CAN2_SCE
// CAN3_TX, CAN3_RX0, CAN3_SCE

CAN_TypeDef *cans[] = {CAN1, CAN2, CAN3};
uint8_t can_irq_number[3][3] = {
CAN_TypeDef *cans[CAN_ARRAY_SIZE] = {CAN1, CAN2, CAN3};
uint8_t can_irq_number[CAN_IRQS_ARRAY_SIZE][CAN_IRQS_ARRAY_SIZE] = {
{ CAN1_TX_IRQn, CAN1_RX0_IRQn, CAN1_SCE_IRQn },
{ CAN2_TX_IRQn, CAN2_RX0_IRQn, CAN2_SCE_IRQn },
{ CAN3_TX_IRQn, CAN3_RX0_IRQn, CAN3_SCE_IRQn },
Expand Down Expand Up @@ -63,7 +65,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {

// ***************************** CAN *****************************
// CANx_SCE IRQ Handler
void can_sce(uint8_t can_number) {
static void can_sce(uint8_t can_number) {
update_can_health_pkt(can_number, 1U);
}

Expand Down Expand Up @@ -181,17 +183,17 @@ void can_rx(uint8_t can_number) {
}
}

void CAN1_TX_IRQ_Handler(void) { process_can(0); }
void CAN1_RX0_IRQ_Handler(void) { can_rx(0); }
void CAN1_SCE_IRQ_Handler(void) { can_sce(0); }
static void CAN1_TX_IRQ_Handler(void) { process_can(0); }
static void CAN1_RX0_IRQ_Handler(void) { can_rx(0); }
static void CAN1_SCE_IRQ_Handler(void) { can_sce(0); }

void CAN2_TX_IRQ_Handler(void) { process_can(1); }
void CAN2_RX0_IRQ_Handler(void) { can_rx(1); }
void CAN2_SCE_IRQ_Handler(void) { can_sce(1); }
static void CAN2_TX_IRQ_Handler(void) { process_can(1); }
static void CAN2_RX0_IRQ_Handler(void) { can_rx(1); }
static void CAN2_SCE_IRQ_Handler(void) { can_sce(1); }

void CAN3_TX_IRQ_Handler(void) { process_can(2); }
void CAN3_RX0_IRQ_Handler(void) { can_rx(2); }
void CAN3_SCE_IRQ_Handler(void) { can_sce(2); }
static void CAN3_TX_IRQ_Handler(void) { process_can(2); }
static void CAN3_RX0_IRQ_Handler(void) { can_rx(2); }
static void CAN3_SCE_IRQ_Handler(void) { can_sce(2); }

bool can_init(uint8_t can_number) {
bool ret = false;
Expand Down
22 changes: 22 additions & 0 deletions board/drivers/bxcan_declarations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

// IRQs: CAN1_TX, CAN1_RX0, CAN1_SCE
// CAN2_TX, CAN2_RX0, CAN2_SCE
// CAN3_TX, CAN3_RX0, CAN3_SCE

#define CAN_ARRAY_SIZE 3
#define CAN_IRQS_ARRAY_SIZE 3
extern CAN_TypeDef *cans[CAN_ARRAY_SIZE];
extern uint8_t can_irq_number[CAN_IRQS_ARRAY_SIZE][CAN_IRQS_ARRAY_SIZE];

bool can_set_speed(uint8_t can_number);
void can_clear_send(CAN_TypeDef *CANx, uint8_t can_number);
void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg);

// ***************************** CAN *****************************
// CANx_TX IRQ Handler
void process_can(uint8_t can_number);
// CANx_RX0 IRQ Handler
// blink blue when we are receiving CAN messages
void can_rx(uint8_t can_number);
bool can_init(uint8_t can_number);
Loading

0 comments on commit ac2a556

Please sign in to comment.