Updated pin definitions and trigger tasks from pickups

This commit is contained in:
Emanuele Trabattoni
2026-03-25 14:16:23 +01:00
parent b42474fff5
commit 8c5b7d4a1c
4 changed files with 294 additions and 98 deletions

View File

@@ -10,38 +10,21 @@
#include <isr.h>
#include <pins.h>
#include <channels.h>
#include <tasks.h>
// Device Libraries
#include <ADS1256.h>
#include <AD5292.h>
void pkdtTask(void *pvParameters) {
uint32_t notifiedValue;
while (true) {
// attende eventi
xTaskNotifyWait(
0x00, // non pulire all'ingresso
0xFFFFFFFF, // pulisci tutti i bit all'uscita
&notifiedValue, // valore ricevuto
portMAX_DELAY
);
// 🔥 QUI GIRA SU CORE 0
switch (notifiedValue)
case PKDT_FLAG_AP: {
handlePKDT(PKDT_AP);
break;
}
default:
LOG_ERROR("Invalid Interrupt: ", notifiedValue);
}
}
void setup() {
Serial.begin(9600);
delay(250);
Serial.begin(115200);
// Setup Logger
LOG_ATTACH_SERIAL(Serial);
LOG_SET_LEVEL(DebugLogLevel::LVL_INFO);
// Print Processor Info
LOG_INFO("ESP32 Chip:", ESP.getChipModel());
LOG_INFO("ESP32 PSram:", ESP.getPsramSize());
LOG_INFO("ESP32 Flash:", ESP.getFlashChipSize());
@@ -49,40 +32,72 @@ void setup() {
LOG_INFO("ESP32 Sketch:", ESP.getFreeSketchSpace());
// Initialize Interrupt pins on peak detectors
pinMode(PKDT_AP, INPUT_PULLDOWN);
pinMode(PKDT_AN, INPUT_PULLDOWN);
pinMode(PKDT_BP, INPUT_PULLDOWN);
pinMode(PKDT_BN, INPUT_PULLDOWN);
// interrupt
attachInterrupt(PKDT_AP, pkdt_isr_ap, RISING);
attachInterrupt(PKDT_AN, pkdt_isr_an, RISING);
attachInterrupt(PKDT_BP, pkdt_isr_bp, RISING);
attachInterrupt(PKDT_BN, pkdt_isr_bn, RISING);
pinMode(TRIG_A12P, INPUT_PULLDOWN);
pinMode(TRIG_A12N, INPUT_PULLDOWN);
pinMode(TRIG_A34P, INPUT_PULLDOWN);
pinMode(TRIG_A34N, INPUT_PULLDOWN);
pinMode(TRIG_B12P, INPUT_PULLDOWN);
pinMode(TRIG_B12N, INPUT_PULLDOWN);
pinMode(TRIG_B34P, INPUT_PULLDOWN);
pinMode(TRIG_B34N, INPUT_PULLDOWN);
// Ignition A Interrupts
attachInterrupt(TRIG_A12P, trig_isr_a, RISING);
attachInterrupt(TRIG_A34P, trig_isr_a, RISING);
attachInterrupt(TRIG_A12N, trig_isr_a, RISING);
attachInterrupt(TRIG_A34N, trig_isr_a, RISING);
// Ignition B Interrupts
attachInterrupt(TRIG_B12P, trig_isr_b, RISING);
attachInterrupt(TRIG_B34P, trig_isr_b, RISING);
attachInterrupt(TRIG_B12N, trig_isr_b, RISING);
attachInterrupt(TRIG_B34N, trig_isr_b, RISING);
// Init SPI interface
SPI.begin();
// Init ADC
auto adc = ADS1256(ADC_DRDY, ADC_RST, ADC_SYNC, ADC_CS, 0.0, SPI);
ADS1256.
}
void loop() {
// task su core 0
auto isrTask = xTaskCreatePinnedToCore(
pkdtTask,
"pkdtTask",
4096,
// global variables
bool running = true;
// Ignition A on Core 0
auto ignA_task_success = xTaskCreatePinnedToCore(
ignitionA_task,
"ignitionA_task",
TASK_STACK,
NULL,
2, // priorità leggermente più alta
&pkdtTaskHandle,
0
TASK_PRIORITY,
&trigA_TaskHandle,
CORE_0
);
if (isrTask != pdPASS){
// Ignition A on Core 1
auto ignB_task_success = xTaskCreatePinnedToCore(
ignitionB_task,
"ignitionB_task",
TASK_STACK,
NULL,
TASK_PRIORITY, // priorità leggermente più alta
&trigA_TaskHandle,
CORE_1
);
if ((ignA_task_success && ignB_task_success) != pdPASS){
LOG_ERROR("Unble to initialize ISR task");
}
LOG_INFO("Real Time Tasks A&B initialized");
////////////////////// MAIN LOOP //////////////////////
while (running) {
}
if (trigA_TaskHandle)
vTaskDelete(trigA_TaskHandle);
if (trigB_TaskHandle)
vTaskDelete(trigB_TaskHandle);
////////////////////// MAIN LOOP //////////////////////
}