revert on double task wait, normal and soft start working
This commit is contained in:
@@ -21,7 +21,7 @@ void rtIgnitionTask(void *pvParameters)
|
||||
ADS1256 *adc = dev->adc_a;
|
||||
PCA9555 *io = dev->io;
|
||||
|
||||
static ignitionBoxStatus ign_box_sts;
|
||||
ignitionBoxStatus ign_box_sts;
|
||||
|
||||
// Variables for ISR, static to be fixed in memory locations
|
||||
static isrParams isr_params_t12p{
|
||||
@@ -69,9 +69,9 @@ void rtIgnitionTask(void *pvParameters)
|
||||
|
||||
LOG_WARN("rtTask Init Correct");
|
||||
// Global rt_task_ptr variables
|
||||
uint32_t it = 0;
|
||||
uint32_t q_fail_count = 0;
|
||||
bool first_cycle = true;
|
||||
bool cycle12 = false;
|
||||
bool cycle34 = false;
|
||||
|
||||
while (params->rt_running)
|
||||
{
|
||||
@@ -107,13 +107,26 @@ void rtIgnitionTask(void *pvParameters)
|
||||
}
|
||||
#endif
|
||||
|
||||
// WAIT FOR SPARK TO HAPPEN
|
||||
auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
|
||||
//auto spark_timeout = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
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
|
||||
// WAIT FOR SPARK TO HAPPEN OR TIMEOUT
|
||||
// auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
|
||||
// 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;
|
||||
|
||||
spark_flag = SPARK_FLAG_NIL; // default value in case of timeout, to be set by ISR if spark event occours
|
||||
// WAIT FOR SPARK TO HAPPEN OR TIMEOUT
|
||||
auto sp = xTaskNotifyWait(
|
||||
0x00, // non pulire all'ingresso
|
||||
ULONG_MAX, // pulisci i primi 8 bit
|
||||
&spark_flag, // valore ricevuto
|
||||
pdMS_TO_TICKS(spark_timeout_max)); // wait for spark event or timeout
|
||||
|
||||
// timeout occurred, set spark flag to nil
|
||||
if (sp == pdFALSE)
|
||||
{
|
||||
spark_flag = SPARK_FLAG_NIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
|
||||
@@ -129,8 +142,6 @@ void rtIgnitionTask(void *pvParameters)
|
||||
if ((pickup_flag == TRIG_FLAG_12P || pickup_flag == TRIG_FLAG_12N) && (spark_flag != SPARK_FLAG_12 && spark_flag != SPARK_FLAG_NIL))
|
||||
{
|
||||
ign_box_sts.coils12.spark_status = ign_box_sts.coils34.spark_status = sparkStatus::SPARK_SYNC_FAIL;
|
||||
// Save error on circular buffer and skip to next cycle //
|
||||
LOG_ERROR("Spark Mismatch");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -148,7 +159,6 @@ void rtIgnitionTask(void *pvParameters)
|
||||
break;
|
||||
}
|
||||
|
||||
bool new_data = false;
|
||||
switch (pickup_flag)
|
||||
{
|
||||
case TRIG_FLAG_12P:
|
||||
@@ -171,8 +181,7 @@ void rtIgnitionTask(void *pvParameters)
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
|
||||
coils->sstart_status = softStartStatus::NORMAL;
|
||||
}
|
||||
new_data = false;
|
||||
break; // Do nothing more on positive pulse
|
||||
continue; // Do nothing more on positive pulse
|
||||
}
|
||||
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
|
||||
case TRIG_FLAG_12N:
|
||||
@@ -193,7 +202,7 @@ void rtIgnitionTask(void *pvParameters)
|
||||
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
||||
else if (spark_flag == SPARK_FLAG_NIL && expected_negative)
|
||||
{
|
||||
coils->sstart_status = softStartStatus::NORMAL;
|
||||
coils->sstart_status = softStartStatus::ERROR;
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
|
||||
}
|
||||
// Timeout not occouured, unexpected negative edge spark
|
||||
@@ -203,7 +212,11 @@ void rtIgnitionTask(void *pvParameters)
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
|
||||
}
|
||||
// Wait for finish of negative pulse to save data to buffer
|
||||
new_data = true;
|
||||
coils->n_events++;
|
||||
if (pickup_flag == TRIG_FLAG_12N)
|
||||
cycle12 = true;
|
||||
else
|
||||
cycle34 = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -215,8 +228,10 @@ void rtIgnitionTask(void *pvParameters)
|
||||
break;
|
||||
}
|
||||
|
||||
if (new_data)
|
||||
if (cycle12 && cycle34) // wait for both 12 and 34 cycles to complete before sending data to main loop and resetting peak detectors
|
||||
{
|
||||
cycle12 = false;
|
||||
cycle34 = false;
|
||||
// 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
|
||||
@@ -249,9 +264,9 @@ void rtIgnitionTask(void *pvParameters)
|
||||
// send essage to main loop with ignition info, by copy so local static variable is ok
|
||||
if (rt_queue)
|
||||
ign_box_sts.timestamp = esp_timer_get_time(); // update data timestamp
|
||||
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, pdMS_TO_TICKS(1)) != pdPASS)
|
||||
if (xQueueSendToBack(rt_queue, (void *)&ign_box_sts, 0) != pdPASS)
|
||||
{
|
||||
q_fail_count++;
|
||||
ign_box_sts.n_queue_errors++;
|
||||
LOG_ERROR("Failed to send to rt_queue");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user