From 27ad6128448a099798a562bea30acdb91dbcad39 Mon Sep 17 00:00:00 2001 From: Emanuele Trabattoni Date: Tue, 31 Mar 2026 09:19:11 +0200 Subject: [PATCH] Mod to ISR and Tasks ok working --- RotaxMonitor/src/main.cpp | 27 +++++++++++++++++---------- RotaxMonitor/src/tasks.cpp | 8 +++++++- RotaxMonitor/src/tasks.h | 14 +++++++------- RotaxMonitor/src/utils.cpp | 14 ++++++++++++++ RotaxMonitor/src/utils.h | 13 +------------ 5 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 RotaxMonitor/src/utils.cpp diff --git a/RotaxMonitor/src/main.cpp b/RotaxMonitor/src/main.cpp index 33519e5..4098347 100644 --- a/RotaxMonitor/src/main.cpp +++ b/RotaxMonitor/src/main.cpp @@ -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) diff --git a/RotaxMonitor/src/tasks.cpp b/RotaxMonitor/src/tasks.cpp index 22270a5..fcf7f25 100644 --- a/RotaxMonitor/src/tasks.cpp +++ b/RotaxMonitor/src/tasks.cpp @@ -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 diff --git a/RotaxMonitor/src/tasks.h b/RotaxMonitor/src/tasks.h index 14b53db..b5a4e68 100644 --- a/RotaxMonitor/src/tasks.h +++ b/RotaxMonitor/src/tasks.h @@ -2,7 +2,7 @@ #define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG // Serial debug flag -// #define DEBUG +//#define DEBUG // Arduino Libraries #include @@ -23,12 +23,12 @@ const uint8_t spark_timeout_max = 2; // in milliseconds // Debug Variables #ifdef DEBUG static const std::map 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 diff --git a/RotaxMonitor/src/utils.cpp b/RotaxMonitor/src/utils.cpp new file mode 100644 index 0000000..222f913 --- /dev/null +++ b/RotaxMonitor/src/utils.cpp @@ -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; +} diff --git a/RotaxMonitor/src/utils.h b/RotaxMonitor/src/utils.h index a98a59d..2a1bf71 100644 --- a/RotaxMonitor/src/utils.h +++ b/RotaxMonitor/src/utils.h @@ -3,15 +3,4 @@ #include #include -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);