dma fix priority and debug

This commit is contained in:
2026-04-02 17:25:10 +03:00
parent af3e012aac
commit e7d7c0e1c1
18 changed files with 89260 additions and 142 deletions

View File

@ -1,5 +1,67 @@
#include "IR_Decoder.h"
#if defined(ARDUINO_ARCH_STM32) && !defined(HAL_EXTI_MODULE_DISABLED)
#include "Arduino.h"
/* NVIC_SetPriority — CMSIS, как в IR_Encoder::begin и Car.ino (без HAL-заголовка yyxx). */
/** NVIC для линии EXTI пина (как в Arduino STM32 SrcWrapper interrupt.cpp). */
static IRQn_Type ir_decoder_exti_irqn_for_pin(uint8_t arduino_pin)
{
#if defined(STM32C0xx) || defined(STM32F0xx) || defined(STM32G0xx) || defined(STM32L0xx)
(void)arduino_pin;
return (IRQn_Type)(-1);
#else
const PinName p = digitalPinToPinName(arduino_pin);
if (p == NC) {
return (IRQn_Type)(-1);
}
const uint16_t pinmask = STM_GPIO_PIN(p);
uint8_t id = 0U;
uint16_t pm = pinmask;
while (pm != 0x0001U) {
pm = (uint16_t)(pm >> 1U);
id++;
}
#if defined(STM32H5xx) || defined(STM32MP1xx) || defined(STM32L5xx) || defined(STM32U5xx) || defined(STM32WBAxx)
static const IRQn_Type exti_irqnb[16] = {
EXTI0_IRQn, EXTI1_IRQn, EXTI2_IRQn, EXTI3_IRQn, EXTI4_IRQn, EXTI5_IRQn, EXTI6_IRQn,
EXTI7_IRQn, EXTI8_IRQn, EXTI9_IRQn, EXTI10_IRQn, EXTI11_IRQn,
EXTI12_IRQn, EXTI13_IRQn, EXTI14_IRQn, EXTI15_IRQn};
#else
static const IRQn_Type exti_irqnb[16] = {
EXTI0_IRQn, EXTI1_IRQn, EXTI2_IRQn, EXTI3_IRQn, EXTI4_IRQn,
EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn,
EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn,
EXTI15_10_IRQn, EXTI15_10_IRQn};
#endif
if (id < 16U) {
return exti_irqnb[id];
}
return (IRQn_Type)(-1);
#endif
}
static void ir_decoder_apply_rx_exti_nvic(uint8_t arduino_pin, uint32_t preempt)
{
const IRQn_Type irqn = ir_decoder_exti_irqn_for_pin(arduino_pin);
if ((int)irqn < 0) {
return;
}
#if !defined(STM32C0xx) && !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
NVIC_SetPriority(irqn, preempt);
#endif
}
void IR_Decoder::setReceiveExtiPreemptPriority(uint32_t preempt)
{
rxExtiPreemptConfigured_ = true;
rxExtiPreemptValue_ = preempt;
if (extiEnabled_) {
ir_decoder_apply_rx_exti_nvic(pin, preempt);
}
}
#endif /* ARDUINO_ARCH_STM32 && !HAL_EXTI_MODULE_DISABLED */
std::list<IR_Decoder *> &IR_Decoder::get_dec_list() // определение функции
{
static std::list<IR_Decoder *> dec_list; // статическая локальная переменная
@ -7,11 +69,11 @@ std::list<IR_Decoder *> &IR_Decoder::get_dec_list() // определение ф
}
// IR_Decoder::IR_Decoder() {};
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair, bool autoHandle)
IR_Decoder::IR_Decoder(const uint8_t pin, uint16_t addr, IR_Encoder *encPair, bool enableOnConstruct)
: IR_DecoderRaw(pin, addr, encPair)
{
get_dec_list().push_back(this);
if(autoHandle){
if (enableOnConstruct) {
enable();
}
};
@ -25,10 +87,17 @@ void IR_Decoder::enable()
}
pinMode(pin, INPUT_PULLUP);
attachInterrupt(pin, (*this)(), CHANGE);
extiEnabled_ = true;
#if defined(ARDUINO_ARCH_STM32) && !defined(HAL_EXTI_MODULE_DISABLED)
if (rxExtiPreemptConfigured_) {
ir_decoder_apply_rx_exti_nvic(pin, rxExtiPreemptValue_);
}
#endif
}
void IR_Decoder::disable()
{
extiEnabled_ = false;
detachInterrupt(pin);
pinMode(pin, INPUT);
auto &dec_list = get_dec_list();
@ -64,9 +133,6 @@ void IR_Decoder::_tick()
if (availableRaw())
{
#ifdef IRDEBUG_INFO
Serial.println("PARSING RAW DATA");
#endif
isWaitingAcceptSend = false;
switch (packInfo.buffer[0] >> 5 & IR_MASK_MSG_TYPE)
{