Mod to ISR and Tasks ok working

This commit is contained in:
Emanuele Trabattoni
2026-03-31 09:19:11 +02:00
parent ec138553ad
commit 27ad612844
5 changed files with 46 additions and 30 deletions

View File

@@ -77,6 +77,8 @@ void loop()
.rst_io_34p = RST_EXT_A34P,
.rst_io_34n = RST_EXT_A34N}
};
LOG_INFO("Task Variables OK");
#ifndef TEST
QueueHandle_t rt_taskB_queue = xQueueCreate(10, sizeof(ignitionBoxStatus));
rtTaskParams taskB_params {
@@ -100,13 +102,12 @@ void loop()
};
#endif
// Init 2 SPI interfaces
bool spiA_ok = true;
SPIClass SPI_A(FSPI);
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
bool spiB_ok = true;
#ifndef TEST
// Init 2 SPI interfaces
SPIClass SPI_A(FSPI);
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
SPIClass SPI_B(HSPI);
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
#endif
@@ -117,15 +118,15 @@ void loop()
vTaskDelay(pdMS_TO_TICKS(5000));
esp_restart();
}
LOG_INFO("Init SPI [OK]");
LOG_INFO("Init SPI OK");
#ifndef TEST
// Init ADC_A
dev.adc_a = new ADS1256(ADC_A_DRDY, ADC_A_RST, ADC_A_SYNC, ADC_A_CS, 2.5, &SPI_A);
dev.adc_a->InitializeADC();
dev.adc_a->setPGA(PGA_1);
dev.adc_a->setDRATE(DRATE_1000SPS);
#ifndef TEST
// Init ADC_B
dev.adc_a = new ADS1256(ADC_B_DRDY, ADC_B_RST, ADC_B_SYNC, ADC_B_CS, 2.5, &SPI_B);
dev.adc_a->InitializeADC();
@@ -133,7 +134,7 @@ void loop()
dev.adc_a->setDRATE(DRATE_1000SPS);
#endif
LOG_INFO("Init ADC [OK]");
LOG_INFO("Init ADC OK");
// Ignition A on Core 0
auto ignA_task_success = pdPASS;
@@ -151,7 +152,7 @@ void loop()
#ifndef TEST
ignB_task_success = xTaskCreatePinnedToCore(
rtIgnitionTask,
"rtIgnitionTask_boxA",
"rtIgnitionTask_boxB",
TASK_STACK,
(void *)&taskB_params,
TASK_PRIORITY, // priorità leggermente più alta
@@ -173,8 +174,14 @@ void loop()
uint32_t count(0);
while (running)
{
// printTaskList();
delay(10000);
delay(10);
ignitionBoxStatus ignA;
if (xQueueReceive(rt_taskA_queue, &ignA, 0) == pdTRUE){
}
if (!(count++ % 100))
printTaskList();
}
if (trigA_TaskHandle)

View File

@@ -9,6 +9,7 @@ void rtIgnitionTask(void *pvParameters)
LOG_ERROR("Null rt_task_ptr parameters");
vTaskDelete(NULL);
}
LOG_INFO("rtTask Params OK");
// Task Parameters and Devices
rtTaskParams *params = (rtTaskParams *)pvParameters;
@@ -47,6 +48,8 @@ void rtIgnitionTask(void *pvParameters)
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
LOG_INFO("rtTask ISR Params OK");
// Attach Pin Interrupts
attachInterruptArg(rt_int.trig_pin_12p, rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
attachInterruptArg(rt_int.trig_pin_12n, rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
@@ -55,12 +58,15 @@ void rtIgnitionTask(void *pvParameters)
attachInterruptArg(rt_int.spark_pin_12, rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
attachInterruptArg(rt_int.spark_pin_34, rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
LOG_INFO("rtTask ISR Attach OK");
// Compute Reset Pin Bitmask
const uint16_t rst_bitmask = (1 << rt_rst.rst_io_12p) |
(1 << rt_rst.rst_io_12n) |
(1 << rt_rst.rst_io_34p) |
(1 << rt_rst.rst_io_34n);
LOG_WARN("rt Task Init Correct");
uint32_t it = 0;
uint32_t q_fail_count = 0;
while (params->rt_running)
@@ -72,7 +78,7 @@ void rtIgnitionTask(void *pvParameters)
#ifdef DEBUG
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
LOG_INFO("Iteration [", it, "]");
LOG_INFO("Iteration [", it++, "]");
#endif
// WAIT FOR PICKUP SIGNAL

View File

@@ -2,7 +2,7 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
// Serial debug flag
// #define DEBUG
//#define DEBUG
// Arduino Libraries
#include <Arduino.h>
@@ -23,12 +23,12 @@ const uint8_t spark_timeout_max = 2; // in milliseconds
// Debug Variables
#ifdef DEBUG
static const std::map<const uint32_t, const char *> names = {
{TRIG_FLAG_A12P, "TRIG_FLAG_A12P"},
{TRIG_FLAG_A12N, "TRIG_FLAG_A12N"},
{TRIG_FLAG_A34P, "TRIG_FLAG_A34P"},
{TRIG_FLAG_A34N, "TRIG_FLAG_A34N"},
{SPARK_FLAG_A12, "SPARK_FLAG_A12"},
{SPARK_FLAG_A34, "SPARK_FLAG_A34"},
{TRIG_FLAG_12P, "TRIG_FLAG_12P"},
{TRIG_FLAG_12N, "TRIG_FLAG_12N"},
{TRIG_FLAG_34P, "TRIG_FLAG_34P"},
{TRIG_FLAG_34N, "TRIG_FLAG_34N"},
{SPARK_FLAG_12, "SPARK_FLAG_12"},
{SPARK_FLAG_34, "SPARK_FLAG_34"},
};
#endif

View File

@@ -0,0 +1,14 @@
#include "utils.h"
std::string printBits(uint32_t value) {
std::string result;
for (int i = 31; i >= 0; i--) {
// ottieni il singolo bit
result += ((value >> i) & 1) ? '1' : '0';
// aggiungi uno spazio ogni 8 bit, tranne dopo l'ultimo
if (i % 8 == 0 && i != 0) {
result += ' ';
}
}
return result;
}

View File

@@ -3,15 +3,4 @@
#include <Arduino.h>
#include <string>
std::string printBits(uint32_t value) {
std::string result;
for (int i = 31; i >= 0; i--) {
// ottieni il singolo bit
result += ((value >> i) & 1) ? '1' : '0';
// aggiungi uno spazio ogni 8 bit, tranne dopo l'ultimo
if (i % 8 == 0 && i != 0) {
result += ' ';
}
}
return result;
}
std::string printBits(uint32_t value);