debug testing commit

This commit is contained in:
Emanuele Trabattoni
2026-04-04 03:11:44 +02:00
parent 48df6a509d
commit 941a2b4eaa
11 changed files with 138 additions and 135 deletions

View File

@@ -16,13 +16,14 @@ void rtIgnitionTask(void *pvParameters)
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
const rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
QueueHandle_t rt_queue = params->rt_queue;
TaskHandle_t *rt_handle_ptr = params->rt_handle_ptr;
TaskHandle_t rt_handle_ptr = *params->rt_handle_ptr;
Devices *dev = params->dev;
ADS1256 *adc = dev->adc_a;
PCA9555 *io = dev->io;
static ignitionBoxStatus ign_box_sts;
// Variables for ISR, static to be fixed in memory locations
static ignitionBoxStatus ign_box_sts; // common for all ISR calls
static isrParams isr_params_t12p{
.flag = TRIG_FLAG_12P,
.ign_stat = &ign_box_sts,
@@ -47,7 +48,7 @@ void rtIgnitionTask(void *pvParameters)
.flag = SPARK_FLAG_34,
.ign_stat = &ign_box_sts,
.rt_handle_ptr = rt_handle_ptr};
LOG_INFO("rtTask ISR Params OK");
pinMode(POT_A_CS, OUTPUT);
@@ -80,19 +81,20 @@ void rtIgnitionTask(void *pvParameters)
// WAIT FOR PICKUP SIGNAL
xTaskNotifyWait(
ULONG_MAX, // non pulire all'ingresso
0x00, // non pulire all'ingresso
ULONG_MAX, // pulisci i primi 8 bit
&pickup_flag, // valore ricevuto
portMAX_DELAY);
#ifdef DEBUG
LOG_INFO("Iteration [", it++, "]");
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor home
LOG_INFO("Pickup Flags: ", printBits(pickup_flag).c_str());
LOG_INFO("Iteration [", it++, "]");
if (!names.contains(pickup_flag))
{
LOG_ERROR("Wrong Pickup Flag");
LOG_ERROR("Pickup Flags: ", printBits(pickup_flag).c_str());
continue;
}
else
@@ -106,18 +108,17 @@ void rtIgnitionTask(void *pvParameters)
if (ign_box_sts.coils12.spark_ok || ign_box_sts.coils34.spark_ok) // otherwise timeout if none is set in the ISR
spark_flag = ign_box_sts.coils12.spark_ok ? SPARK_FLAG_12 : SPARK_FLAG_34;
else
spark_flag == SPARK_FLAG_NIL;
xTaskNotifyStateClear(NULL);
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
spark_flag = SPARK_FLAG_NIL;
#ifdef DEBUG
LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
if (!names.contains(spark_flag))
LOG_ERROR("No Spark");
else
// LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
LOG_INFO("Spark12:", ign_box_sts.coils12.spark_ok ? "TRUE" : "FALSE");
LOG_INFO("Spark34:", ign_box_sts.coils34.spark_ok ? "TRUE" : "FALSE");
if (names.contains(spark_flag))
LOG_INFO("Spark Trigger:", names.at(spark_flag));
#endif
xTaskNotifyStateClear(NULL);
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
// A trigger from pickup 12 is followed by a spark event on 34 or vice versa pickup 34 triggers spark on 12
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && spark_flag != SPARK_FLAG_12)
@@ -147,15 +148,16 @@ void rtIgnitionTask(void *pvParameters)
case TRIG_FLAG_12P:
case TRIG_FLAG_34P:
{
LOG_INFO("POSITIVE Edge");
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_NIL)
{
coils->spark_delay = coils->spark_time - coils->trig_time;
coils->spark_delay = coils->trig_time - coils->spark_time;
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
coils->spark_status = sparkStatus::SPARK_POS_OK; // do not wait for spark on negative edge
#ifdef DEBUG
LOG_INFO("Trigger Spark POSITIVE");
LOG_INFO("Spark12 Delay Timer: ", (int)coils->spark_delay);
LOG_INFO("Spark on POSITIVE pulse");
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
#endif
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
@@ -164,33 +166,34 @@ void rtIgnitionTask(void *pvParameters)
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
coils->sstart_status = softStartStatus::NORMAL;
}
new_data = true;
new_data = false;
break; // Do nothing more on positive pulse
}
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
case TRIG_FLAG_12N:
case TRIG_FLAG_34N:
{
const bool expected_negative12 = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
LOG_INFO("NEGATIVE Edge");
const bool expected_negative = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
if (spark_flag != SPARK_FLAG_NIL && expected_negative12)
if (spark_flag != SPARK_FLAG_NIL && expected_negative)
{
coils->spark_delay = coils->spark_time - coils->trig_time;
coils->spark_delay = coils->trig_time - coils->spark_time;
coils->sstart_status = softStartStatus::SOFT_START;
coils->spark_status == sparkStatus::SPARK_NEG_OK;
#ifdef DEBUG
LOG_INFO("Trigger Spark NEGATIVE");
LOG_INFO("Spark12 Delay Timer: ", (int)ign_box_sts.coils12.spark_delay);
LOG_INFO("Spark on NEGATIVE pulse");
LOG_INFO("Spark Delay Timer: ", (int32_t)coils->spark_delay);
#endif
}
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
else if (spark_flag == SPARK_FLAG_NIL && expected_negative12)
else if (spark_flag == SPARK_FLAG_NIL && expected_negative)
{
coils->sstart_status = softStartStatus::NORMAL;
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
}
// Timeout not occouured, unexpected negative edge spark
else if (spark_flag != SPARK_FLAG_NIL && !expected_negative12)
else if (spark_flag != SPARK_FLAG_NIL && !expected_negative)
{
coils->sstart_status = softStartStatus::SOFT_START;
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
@@ -210,8 +213,8 @@ void rtIgnitionTask(void *pvParameters)
if (new_data)
{
vTaskDelay(pdMS_TO_TICKS(1)); // delay 1ms to allow peak detectors to charge for negative cycle
// read adc channels: pickup12, out12 [ pos + neg ]
// vTaskDelay(pdMS_TO_TICKS(1)); // delay 1ms to allow peak detectors to charge for negative cycle
// read adc channels: pickup12, out12 [ pos + neg ]
if (adc) // read only if adc initialized
{
// from peak detector circuits
@@ -225,7 +228,7 @@ void rtIgnitionTask(void *pvParameters)
ign_box_sts.coils34.peak_n_out = adcReadChannel(adc, ADC_CH_PEAK_34N_OUT);
}
else // simulate adc read timig
vTaskDelay(pdMS_TO_TICKS(6));
vTaskDelay(pdMS_TO_TICKS(1));
// reset peak detectors + sample and hold
// outputs on io expander
@@ -237,7 +240,7 @@ void rtIgnitionTask(void *pvParameters)
io->write(iostat & ~rst_bitmask);
}
else
vTaskDelay(pdMS_TO_TICKS(2));
vTaskDelay(pdMS_TO_TICKS(1));
// send essage to main loop with ignition info, by copy so local static variable is ok
if (rt_queue)
@@ -245,7 +248,7 @@ void rtIgnitionTask(void *pvParameters)
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, pdMS_TO_TICKS(1)) != pdPASS)
{
q_fail_count++;
LOG_ERROR("Failed to send to rt_queue");
// LOG_ERROR("Failed to send to rt_queue");
}
}
}