Sync: commaai/panda:mastersunnypilot/panda:master

This commit is contained in:
Jason Wen
2026-02-27 16:35:20 -05:00
committed by GitHub
10 changed files with 32 additions and 85 deletions

View File

@@ -66,12 +66,6 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Cache cppcheck
id: cppcheck-cache
uses: actions/cache@v4
with:
path: tests/misra/cppcheck
key: cppcheck-${{ hashFiles('tests/misra/*') }}
- run: ./setup.sh
- name: Build FW
run: ${{ env.RUN }} "scons -j$(nproc)"
@@ -84,16 +78,8 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Cache cppcheck
id: cppcheck-cache
uses: actions/cache@v4
with:
path: tests/misra/cppcheck
key: cppcheck-${{ hashFiles('tests/misra/*') }}
- run: ./setup.sh
- name: Build FW
run: ${{ env.RUN }} "scons -j$(nproc)"
- name: tests/misra/install.sh
run: ${{ env.RUN }} "cd tests/misra && ./install.sh"
- name: MISRA mutation tests
run: ${{ env.RUN }} "cd tests/misra && pytest test_mutation.py"

View File

@@ -1,41 +0,0 @@
name: Update cppcheck
on:
#push:
schedule:
- cron: "0 14 * * 1" # every Monday at 2am UTC (6am PST)
workflow_dispatch:
jobs:
update-cppcheck:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Get latest cppcheck version
id: version
run: |
# Tags are sorted by time (newest first), so get the first version-like tag
LATEST=$(curl -fsSL "https://api.github.com/repos/danmar/cppcheck/tags?per_page=20" | \
jq -r '.[].name' | \
grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)?$' | \
head -n 1)
echo "vers=$LATEST" >> "$GITHUB_OUTPUT"
- name: Update VERS in install.sh
run: |
sed -i "s/^VERS=\".*\"/VERS=\"${{ steps.version.outputs.vers }}\"/" tests/misra/install.sh
grep VERS tests/misra/install.sh
- name: Create Pull Request
uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83
with:
author: Vehicle Researcher <user@comma.ai>
token: ${{ secrets.ACTIONS_CREATE_PR_PAT }}
commit-message: "[bot] Update cppcheck to ${{ steps.version.outputs.vers }}"
title: "[bot] Update cppcheck to ${{ steps.version.outputs.vers }}"
body: "See all cppcheck releases: https://github.com/danmar/cppcheck/releases"
branch: "update-cppcheck"
base: "master"
delete-branch: true
labels: bot

View File

@@ -2,7 +2,7 @@
// When changing these structs, python/__init__.py needs to be kept up to date!
#define HEALTH_PACKET_VERSION 17
#define HEALTH_PACKET_VERSION 18
struct __attribute__((packed)) health_t {
uint32_t uptime_pkt;
uint32_t voltage_pkt;
@@ -29,6 +29,7 @@ struct __attribute__((packed)) health_t {
uint16_t sbu1_voltage_mV;
uint16_t sbu2_voltage_mV;
uint8_t som_reset_triggered;
uint16_t sound_output_level_pkt;
};
#define CAN_HEALTH_PACKET_VERSION 5

View File

@@ -42,6 +42,8 @@ static int get_health_pkt(void *dat) {
health->som_reset_triggered = bootkick_reset_triggered;
health->sound_output_level_pkt = sound_output_level;
return sizeof(*health);
}

View File

@@ -20,3 +20,6 @@ extern bool heartbeat_disabled;
// siren state
extern bool siren_enabled;
// sound
extern uint16_t sound_output_level;

View File

@@ -12,6 +12,7 @@ __attribute__((section(".sram4"))) static uint16_t mic_tx_buf[2][MIC_TX_BUF_SIZE
static uint8_t sound_idle_count;
static uint8_t mic_idle_count;
static uint8_t mic_buffer_count;
uint16_t sound_output_level;
void sound_tick(void) {
if (sound_idle_count > 0U) {
@@ -19,6 +20,7 @@ void sound_tick(void) {
if (sound_idle_count == 0U) {
current_board->set_amp_enabled(false);
register_clear_bits(&DMA1_Stream1->CR, DMA_SxCR_EN);
sound_output_level = 0U;
}
}
@@ -72,14 +74,31 @@ static void BDMA_Channel0_IRQ_Handler(void) {
// process samples (shift to 12b and bias to be unsigned)
bool sound_playing = false;
uint32_t abs_sum = 0U;
for (uint16_t i=0U; i < SOUND_RX_BUF_SIZE; i += 2U) {
// since we are playing mono and receiving stereo, we take every other sample
sound_tx_buf[playback_buf][i/2U] = ((sound_rx_buf[rx_buf_idx][i] + (1UL << 14)) >> 3);
uint16_t sample = ((sound_rx_buf[rx_buf_idx][i] + (1UL << 14)) >> 3) & 0xFFFU;
sound_tx_buf[playback_buf][i/2U] = sample;
if (sound_rx_buf[rx_buf_idx][i] > 0U) {
sound_playing = true;
}
// this assumes all audio is "zero" centered
if (sample > 0x7FFU) {
abs_sum += (uint32_t)sample - 0x7FFU;
} else {
abs_sum += 0x7FFU - (uint32_t)sample;
}
}
// VU meter: fast attack, slow decay (~460ms half-life at ~96Hz ISR rate)
uint16_t level = (uint16_t)(abs_sum / (SOUND_RX_BUF_SIZE / 2U));
if (level >= sound_output_level) {
sound_output_level = level;
}
sound_output_level -= (sound_output_level >> 6U);
// manage amp state
if (sound_playing) {
if (sound_idle_count == 0U) {
@@ -102,8 +121,6 @@ static void BDMA_Channel0_IRQ_Handler(void) {
DFSDM1_Filter0->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
}
mic_idle_count = SOUND_IDLE_TIMEOUT;
sound_tick();
}
void sound_init_dac(void) {

View File

@@ -31,6 +31,7 @@ dev = [
"setuptools",
"spidev; platform_system == 'Linux'",
"gcc-arm-none-eabi @ git+https://github.com/commaai/dependencies.git@releases#subdirectory=gcc-arm-none-eabi",
"cppcheck @ git+https://github.com/commaai/dependencies.git@releases#subdirectory=cppcheck",
]
[build-system]

View File

@@ -118,9 +118,9 @@ class Panda:
HW_TYPE_BODY = b'\xb1'
CAN_PACKET_VERSION = 4
HEALTH_PACKET_VERSION = 17
HEALTH_PACKET_VERSION = 18
CAN_HEALTH_PACKET_VERSION = 5
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBHBBBHfBBHHHB")
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBHBBBHfBBHHHBH")
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIIIIHHBBBIIII")
H7_DEVICES = [HW_TYPE_RED_PANDA, HW_TYPE_TRES, HW_TYPE_CUATRO, HW_TYPE_BODY]
@@ -524,6 +524,7 @@ class Panda:
"sbu1_voltage_mV": a[22],
"sbu2_voltage_mV": a[23],
"som_reset_triggered": a[24],
"sound_output_level": a[25],
}
@ensure_can_health_packet_version

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
: "${CPPCHECK_DIR:=$DIR/cppcheck/}"
if [ ! -d "$CPPCHECK_DIR" ]; then
git clone https://github.com/danmar/cppcheck.git $CPPCHECK_DIR
fi
cd $CPPCHECK_DIR
VERS="2.16.0"
git fetch --all --tags --force
git checkout $VERS
#make clean
make MATCHCOMPILTER=yes CXXFLAGS="-O2" -j8

View File

@@ -10,12 +10,7 @@ YELLOW="\e[1;33m"
RED="\e[1;31m"
NC='\033[0m'
: "${CPPCHECK_DIR:=$DIR/cppcheck/}"
# install cppcheck if missing
if [ -z "${SKIP_CPPCHECK_INSTALL}" ]; then
$DIR/install.sh
fi
: "${CPPCHECK_DIR:=$(python3 -c "import cppcheck; print(cppcheck.DIR)")}"
# ensure checked in coverage table is up to date
cd $DIR