diff --git a/Dockerfile b/Dockerfile index 68362f8cfd..750cb07ff8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,13 +37,13 @@ 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="e1ce3619a5db661ef2b406ccf258a253baf6eebc" +ENV OPENDBC_REF="b89fe79950121ca93d8a1f0d3fd17df31703be2a" 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/ && \ pip3 install --break-system-packages --no-cache-dir Cython numpy && \ - scons -j8 --minimal opendbc/ && \ - ln -s $PWD/opendbc $PYTHONPATH/opendbc + ln -s $PWD/opendbc $PYTHONPATH/opendbc && \ + scons -j8 --minimal opendbc/ # for Jenkins COPY README.md panda.tar.* /tmp/ diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 90d0627517..5d4bdad43f 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -71,10 +71,6 @@ static void cuatro_set_bootkick(BootState state) { //set_gpio_output(GPIOC, 12, state != BOOT_RESET); } -static void cuatro_set_siren(bool enabled){ - beeper_enable(enabled); -} - static void cuatro_set_amp_enabled(bool enabled){ set_gpio_output(GPIOA, 5, enabled); } @@ -133,10 +129,6 @@ static void cuatro_init(void) { // Clock source clock_source_init(); - // 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 @@ -170,7 +162,7 @@ board board_cuatro = { .read_current_mA = cuatro_read_current_mA, .set_fan_enabled = cuatro_set_fan_enabled, .set_ir_power = unused_set_ir_power, - .set_siren = cuatro_set_siren, + .set_siren = unused_set_siren, .set_bootkick = cuatro_set_bootkick, .read_som_gpio = tres_read_som_gpio, .set_amp_enabled = cuatro_set_amp_enabled diff --git a/board/drivers/beeper.h b/board/drivers/beeper.h deleted file mode 100644 index 0ae02ff5e6..0000000000 --- a/board/drivers/beeper.h +++ /dev/null @@ -1,26 +0,0 @@ - -#define BEEPER_COUNTER_OVERFLOW 25000U // 4kHz - -void beeper_enable(bool enabled) { - if (enabled) { - register_set_bits(&(TIM4->CCER), TIM_CCER_CC3E); - } else { - register_clear_bits(&(TIM4->CCER), TIM_CCER_CC3E); - } -} - -void beeper_init(void) { - // Enable timer and auto-reload - register_set(&(TIM4->CR1), TIM_CR1_CEN | TIM_CR1_ARPE, 0x3FU); - - // Set channel as PWM mode 1 and disable output - register_set_bits(&(TIM4->CCMR2), (TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3PE)); - beeper_enable(false); - - // Set max counter value and compare to get 50% duty - register_set(&(TIM4->CCR3), BEEPER_COUNTER_OVERFLOW / 2U, 0xFFFFU); - register_set(&(TIM4->ARR), BEEPER_COUNTER_OVERFLOW, 0xFFFFU); - - // Update registers and clear counter - TIM4->EGR |= TIM_EGR_UG; -} diff --git a/board/main.c b/board/main.c index aaea95d089..de2a917213 100644 --- a/board/main.c +++ b/board/main.c @@ -216,7 +216,7 @@ static void tick_handler(void) { } if (controls_allowed || heartbeat_engaged) { - controls_allowed_countdown = 30U; + controls_allowed_countdown = 5U; } else if (controls_allowed_countdown > 0U) { controls_allowed_countdown -= 1U; } else { diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 3e9d23216c..cf73afee62 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -250,8 +250,17 @@ static int hyundai_fwd_hook(int bus_num, int addr) { if (bus_num == 0) { bus_fwd = 2; } - if ((bus_num == 2) && (addr != 0x340) && (addr != 0x485)) { - bus_fwd = 0; + + if (bus_num == 2) { + // Stock LKAS11 messages + bool is_lkas_11 = (addr == 0x340); + // LFA and HDA cluster icons + bool is_lfahda_mfc = (addr == 0x485); + + bool block_msg = is_lkas_11 || is_lfahda_mfc; + if (!block_msg) { + bus_fwd = 0; + } } return bus_fwd; diff --git a/board/stm32h7/board.h b/board/stm32h7/board.h index ea4812245e..6ab75f55d8 100644 --- a/board/stm32h7/board.h +++ b/board/stm32h7/board.h @@ -10,7 +10,6 @@ #include "drivers/fan.h" #include "stm32h7/llfan.h" #include "stm32h7/lldac.h" -#include "drivers/beeper.h" #include "drivers/fake_siren.h" #include "stm32h7/sound.h" #include "drivers/clock_source.h" diff --git a/board/stm32h7/peripherals.h b/board/stm32h7/peripherals.h index c6874b8ac3..db89a38ad3 100644 --- a/board/stm32h7/peripherals.h +++ b/board/stm32h7/peripherals.h @@ -130,7 +130,6 @@ void peripherals_init(void) { RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // clock source timer RCC->APB1LENR |= RCC_APB1LENR_TIM2EN; // main counter RCC->APB1LENR |= RCC_APB1LENR_TIM3EN; // fan pwm - RCC->APB1LENR |= RCC_APB1LENR_TIM4EN; // beeper source RCC->APB1LENR |= RCC_APB1LENR_TIM6EN; // interrupt timer RCC->APB1LENR |= RCC_APB1LENR_TIM7EN; // DMA trigger timer RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; // tick timer diff --git a/board/stm32h7/sound.h b/board/stm32h7/sound.h index 6251936c62..1400a6eae8 100644 --- a/board/stm32h7/sound.h +++ b/board/stm32h7/sound.h @@ -2,6 +2,7 @@ #define SOUND_TX_BUF_SIZE (SOUND_RX_BUF_SIZE/2U) __attribute__((section(".sram4"))) static uint16_t sound_rx_buf[2][SOUND_RX_BUF_SIZE]; +__attribute__((section(".sram4"))) static uint16_t sound_tx_buf[2][SOUND_TX_BUF_SIZE]; static uint8_t sound_idle_count; @@ -10,24 +11,24 @@ void sound_tick(void) { sound_idle_count--; if (sound_idle_count == 0U) { current_board->set_amp_enabled(false); + register_clear_bits(&DMA1_Stream1->CR, DMA_SxCR_EN); } } } // Playback processing static void BDMA_Channel0_IRQ_Handler(void) { - __attribute__((section(".sram4"))) static uint16_t tx_buf[SOUND_TX_BUF_SIZE]; - BDMA->IFCR |= BDMA_IFCR_CGIF0; // clear flag - uint8_t buf_idx = (((BDMA_Channel0->CCR & BDMA_CCR_CT) >> BDMA_CCR_CT_Pos) == 1U) ? 0U : 1U; + uint8_t rx_buf_idx = (((BDMA_Channel0->CCR & BDMA_CCR_CT) >> BDMA_CCR_CT_Pos) == 1U) ? 0U : 1U; + uint8_t tx_buf_idx = (((DMA1_Stream1->CR & DMA_SxCR_CT) >> DMA_SxCR_CT_Pos) == 1U) ? 0U : 1U; // process samples (shift to 12b and bias to be unsigned) bool sound_playing = false; 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 - tx_buf[i/2U] = ((sound_rx_buf[buf_idx][i] + (1UL << 14)) >> 3); - if (sound_rx_buf[buf_idx][i] > 0U) { + sound_tx_buf[tx_buf_idx][i/2U] = ((sound_rx_buf[rx_buf_idx][i] + (1UL << 14)) >> 3); + if (sound_rx_buf[rx_buf_idx][i] > 0U) { sound_playing = true; } } @@ -36,16 +37,17 @@ static void BDMA_Channel0_IRQ_Handler(void) { if (sound_playing) { if (sound_idle_count == 0U) { current_board->set_amp_enabled(true); + + // empty the other buf and start playing that + for (uint16_t i=0U; i < SOUND_TX_BUF_SIZE; i++) { + sound_tx_buf[1U - tx_buf_idx][i] = (1UL << 11); + } + register_set(&DMA1_Stream1->CR, (1UL - tx_buf_idx) << DMA_SxCR_CT_Pos, DMA_SxCR_CT_Msk); + register_set_bits(&DMA1_Stream1->CR, DMA_SxCR_EN); } sound_idle_count = 4U; } sound_tick(); - - DMA1->LIFCR |= 0xF40; - DMA1_Stream1->CR &= ~DMA_SxCR_EN; - register_set(&DMA1_Stream1->M0AR, (uint32_t) tx_buf, 0xFFFFFFFFU); - DMA1_Stream1->NDTR = SOUND_TX_BUF_SIZE; - DMA1_Stream1->CR |= DMA_SxCR_EN; } void sound_init(void) { @@ -61,8 +63,11 @@ void sound_init(void) { // Setup DMA register_set(&DMA1_Stream1->PAR, (uint32_t) &(DAC1->DHR12R1), 0xFFFFFFFFU); + register_set(&DMA1_Stream1->M0AR, (uint32_t) sound_tx_buf[0], 0xFFFFFFFFU); + register_set(&DMA1_Stream1->M1AR, (uint32_t) sound_tx_buf[1], 0xFFFFFFFFU); register_set(&DMA1_Stream1->FCR, 0U, 0x00000083U); - DMA1_Stream1->CR = (0b11UL << DMA_SxCR_PL_Pos) | (0b01UL << DMA_SxCR_MSIZE_Pos) | (0b01UL << DMA_SxCR_PSIZE_Pos) | DMA_SxCR_MINC | (1U << DMA_SxCR_DIR_Pos); + DMA1_Stream1->NDTR = SOUND_TX_BUF_SIZE; + DMA1_Stream1->CR = DMA_SxCR_DBM | (0b11UL << DMA_SxCR_PL_Pos) | (0b01UL << DMA_SxCR_MSIZE_Pos) | (0b01UL << DMA_SxCR_PSIZE_Pos) | DMA_SxCR_MINC | (1U << DMA_SxCR_DIR_Pos); // Init trigger timer (little slower than 48kHz, pulled in sync by SAI4_FS_B) register_set(&TIM5->PSC, 2600U, 0xFFFFU); diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index c35ed02a13..64a6bf27a8 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -50,7 +50,7 @@ cppcheck() { --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ --suppress=*:*include/* --error-exitcode=2 --check-level=exhaustive --safety \ --platform=arm32-wchar_t4 $COMMON_DEFINES --checkers-report=$CHECKLIST.tmp \ - --std=c11 "$@" |& tee $OUTPUT + --std=c11 "$@" 2>&1 | tee $OUTPUT cat $CHECKLIST.tmp >> $CHECKLIST rm $CHECKLIST.tmp