Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tesla
Browse files Browse the repository at this point in the history
# Conflicts:
#	board/safety/safety_tesla.h
  • Loading branch information
lukasloetkolben committed Oct 1, 2024
2 parents c31f2d4 + cbbae44 commit 6de7337
Show file tree
Hide file tree
Showing 118 changed files with 8,498 additions and 7,382 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ a.out
*~
.#*
dist/
build/
pandacan.egg-info/
obj/
examples/output.csv
Expand All @@ -28,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
8 changes: 7 additions & 1 deletion 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 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
22 changes: 13 additions & 9 deletions board/boards/black.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// /////////////////////////////// //
// Black Panda (STM32F4) + Harness //
// /////////////////////////////// //

void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
Expand All @@ -22,7 +26,7 @@ void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void black_enable_can_transceivers(bool enabled) {
static void black_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -33,7 +37,7 @@ void black_enable_can_transceivers(bool enabled) {
}
}

void black_set_led(uint8_t color, bool enabled) {
static void black_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
Expand All @@ -49,11 +53,11 @@ void black_set_led(uint8_t color, bool enabled) {
}
}

void black_set_usb_load_switch(bool enabled) {
static void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

void black_set_can_mode(uint8_t mode) {
static void black_set_can_mode(uint8_t mode) {
black_enable_can_transceiver(2U, false);
black_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -86,12 +90,12 @@ void black_set_can_mode(uint8_t mode) {
}
}

bool black_check_ignition(void){
static bool black_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}

void black_init(void) {
static void black_init(void) {
common_init_gpio();

// A8,A15: normal CAN3 mode
Expand Down Expand Up @@ -135,13 +139,13 @@ void black_init(void) {
black_set_can_mode(CAN_MODE_NORMAL);
}

void black_init_bootloader(void) {
static void black_init_bootloader(void) {
// GPS OFF
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}

harness_configuration black_harness_config = {
static harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
14 changes: 14 additions & 0 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

// ******************** Prototypes ********************
typedef enum {
BOOT_STANDBY,
Expand Down Expand Up @@ -74,3 +79,12 @@ struct board {
// CAN modes
#define CAN_MODE_NORMAL 0U
#define CAN_MODE_OBD_CAN2 1U

extern struct board board_black;
extern struct board board_dos;
extern struct board board_uno;
extern struct board board_tres;
extern struct board board_grey;
extern struct board board_white;
extern struct board board_cuatro;
extern struct board board_red;
20 changes: 12 additions & 8 deletions board/boards/cuatro.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// ////////////////////////// //
// Cuatro (STM32H7) + Harness //
// ////////////////////////// //

void cuatro_set_led(uint8_t color, bool enabled) {
static void cuatro_set_led(uint8_t color, bool enabled) {
switch (color) {
case LED_RED:
set_gpio_output(GPIOD, 15, !enabled);
Expand All @@ -18,7 +22,7 @@ void cuatro_set_led(uint8_t color, bool enabled) {
}
}

void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver) {
case 1U:
set_gpio_output(GPIOB, 7, !enabled);
Expand All @@ -37,7 +41,7 @@ void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void cuatro_enable_can_transceivers(bool enabled) {
static void cuatro_enable_can_transceivers(bool enabled) {
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for (uint8_t i=1U; i<=4U; i++) {
// Leave main CAN always on for CAN-based ignition detection
Expand All @@ -49,25 +53,25 @@ void cuatro_enable_can_transceivers(bool enabled) {
}
}

uint32_t cuatro_read_voltage_mV(void) {
static uint32_t cuatro_read_voltage_mV(void) {
return adc_get_mV(8) * 11U;
}

uint32_t cuatro_read_current_mA(void) {
static uint32_t cuatro_read_current_mA(void) {
return adc_get_mV(3) * 2U;
}

void cuatro_set_fan_enabled(bool enabled) {
static void cuatro_set_fan_enabled(bool enabled) {
set_gpio_output(GPIOD, 3, !enabled);
}

void cuatro_set_bootkick(BootState state) {
static void cuatro_set_bootkick(BootState state) {
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
// only use if we have to
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
}

void cuatro_init(void) {
static void cuatro_init(void) {
red_chiplet_init();

// init LEDs as open drain
Expand Down
28 changes: 16 additions & 12 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include "board_declarations.h"

// /////////////////////// //
// Dos (STM32F4) + Harness //
// /////////////////////// //

void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
static void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
switch (transceiver){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
Expand All @@ -22,7 +26,7 @@ void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
}
}

void dos_enable_can_transceivers(bool enabled) {
static void dos_enable_can_transceivers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
// Leave main CAN always on for CAN-based ignition detection
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
Expand All @@ -33,7 +37,7 @@ void dos_enable_can_transceivers(bool enabled) {
}
}

void dos_set_led(uint8_t color, bool enabled) {
static void dos_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
Expand All @@ -49,11 +53,11 @@ void dos_set_led(uint8_t color, bool enabled) {
}
}

void dos_set_bootkick(BootState state) {
static void dos_set_bootkick(BootState state) {
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
}

void dos_set_can_mode(uint8_t mode) {
static void dos_set_can_mode(uint8_t mode) {
dos_enable_can_transceiver(2U, false);
dos_enable_can_transceiver(4U, false);
switch (mode) {
Expand Down Expand Up @@ -85,28 +89,28 @@ void dos_set_can_mode(uint8_t mode) {
}
}

bool dos_check_ignition(void){
static bool dos_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}

void dos_set_ir_power(uint8_t percentage){
static void dos_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}

void dos_set_fan_enabled(bool enabled){
static void dos_set_fan_enabled(bool enabled){
set_gpio_output(GPIOA, 1, enabled);
}

void dos_set_siren(bool enabled){
static void dos_set_siren(bool enabled){
set_gpio_output(GPIOC, 12, enabled);
}

bool dos_read_som_gpio (void){
static bool dos_read_som_gpio (void){
return (get_gpio_input(GPIOC, 2) != 0);
}

void dos_init(void) {
static void dos_init(void) {
common_init_gpio();

// A8,A15: normal CAN3 mode
Expand Down Expand Up @@ -166,7 +170,7 @@ void dos_init(void) {
clock_source_init();
}

harness_configuration dos_harness_config = {
static harness_configuration dos_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
Expand Down
4 changes: 4 additions & 0 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#pragma once

#include "board_declarations.h"

// //////////////////// //
// Grey Panda (STM32F4) //
// //////////////////// //
Expand Down
Loading

0 comments on commit 6de7337

Please sign in to comment.