Working trigger + Spark recognition!!!
This commit is contained in:
@@ -38,12 +38,12 @@
|
||||
#endif
|
||||
|
||||
static const std::map<const uint32_t, const char*> names = {
|
||||
{TRIG_FLAG_A12P, "TRIG_A12P"},
|
||||
{TRIG_FLAG_A12N, "TRIG_A12N"},
|
||||
{TRIG_FLAG_A34P, "TRIG_A34P"},
|
||||
{TRIG_FLAG_A34N, "TRIG_A34N"},
|
||||
{SPARK_FLAG_A12, "SPARK_A12"},
|
||||
{SPARK_FLAG_A34, "SPARK_A34"},
|
||||
{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"},
|
||||
};
|
||||
|
||||
// Task handle
|
||||
@@ -91,13 +91,16 @@ struct ignitionBoxStatus
|
||||
coilsStatus coils34;
|
||||
// voltage from generator
|
||||
float volts_gen = 0.0;
|
||||
|
||||
bool spark12 = false;
|
||||
bool spark34 = false;
|
||||
};
|
||||
|
||||
ignitionBoxStatus ignA_status;
|
||||
ignitionBoxStatus ignB_status;
|
||||
|
||||
// Pin to flag Map
|
||||
static uint32_t pin2trig[49];
|
||||
static uint32_t pin2trig[49] = {0};
|
||||
void initTriggerPinMapping()
|
||||
{
|
||||
pin2trig[TRIG_A12P] = TRIG_FLAG_A12P;
|
||||
@@ -112,7 +115,7 @@ void initTriggerPinMapping()
|
||||
#endif
|
||||
};
|
||||
|
||||
static uint32_t pin2spark[49];
|
||||
static uint32_t pin2spark[49] = {0};
|
||||
void initSparkPinMapping()
|
||||
{
|
||||
pin2spark[SPARK_A12] = SPARK_FLAG_A12;
|
||||
@@ -127,55 +130,55 @@ void initSparkPinMapping()
|
||||
// ISR (Pass return bitmask to ISR management function)
|
||||
// one function for each wake up pin conncted to a trigger
|
||||
// =====================
|
||||
void IRAM_ATTR trig_isr_a()
|
||||
void IRAM_ATTR trig_isr_a(void* arg)
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
volatile const int64_t time_us = esp_timer_get_time();
|
||||
if (!trigA_TaskHandle)
|
||||
return; // exit if task is not running
|
||||
|
||||
#ifndef TEST
|
||||
uint32_t status = GPIO.status;
|
||||
#else
|
||||
uint32_t status = GPIO.status1.val;
|
||||
#endif
|
||||
uint32_t pickup_flags = 0;
|
||||
uint32_t flag = (uint32_t)arg;
|
||||
ignA_status.spark12 = false;
|
||||
ignA_status.spark34 = false;
|
||||
|
||||
while (status)
|
||||
{
|
||||
uint32_t pin = __builtin_ctz(status); // trova primo bit attivo
|
||||
status &= ~(1 << pin); // clear bit
|
||||
pickup_flags |= pin2trig[pin];
|
||||
if (flag & TRIG_FLAG_A12P) {
|
||||
ignA_status.coils12.trig_time = time_us;
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
}
|
||||
if (flag & TRIG_FLAG_A34P) {
|
||||
ignA_status.coils34.trig_time = time_us;
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
if (flag & SPARK_FLAG_A12) {
|
||||
ignA_status.spark12 = true;
|
||||
ignA_status.coils12.spark_time = time_us;
|
||||
xTaskNotifyGive(trigA_TaskHandle);
|
||||
}
|
||||
if (flag & SPARK_FLAG_A34) {
|
||||
ignA_status.spark12 = false;
|
||||
ignA_status.coils34.spark_time = time_us;
|
||||
xTaskNotifyGive(trigA_TaskHandle);
|
||||
}
|
||||
|
||||
if (pickup_flags & TRIG_FLAG_A12P)
|
||||
ignA_status.coils12.trig_time = time_us;
|
||||
if (pickup_flags & TRIG_FLAG_A34P)
|
||||
ignA_status.coils34.trig_time = time_us;
|
||||
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, GPIO.status1.val, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
//xTaskNotifyFromISR(trigA_TaskHandle, flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR spark_a()
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
volatile const int64_t time_us = esp_timer_get_time();
|
||||
if (!trigA_TaskHandle)
|
||||
return;
|
||||
#ifndef TEST
|
||||
uint32_t spark_flag = GPIO.status1.val & SPARK_A12 ? SPARK_FLAG_A12 : SPARK_FLAG_A34;
|
||||
#else
|
||||
uint32_t spark_flag = GPIO.status & SPARK_A12 ? SPARK_FLAG_A12 : SPARK_FLAG_A34;
|
||||
#endif
|
||||
// void IRAM_ATTR spark_a(void* arg)
|
||||
// {
|
||||
// BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
// volatile const int64_t time_us = esp_timer_get_time();
|
||||
// if (!trigA_TaskHandle)
|
||||
// return;
|
||||
|
||||
if (spark_flag & SPARK_FLAG_A12)
|
||||
ignA_status.coils12.spark_time = time_us;
|
||||
if (spark_flag & SPARK_FLAG_A34)
|
||||
ignA_status.coils12.spark_time = time_us;
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, GPIO.status, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
// uint32_t flag = (uint32_t) arg;
|
||||
|
||||
// xTaskNotifyFromISR(trigA_TaskHandle, flag, eSetBits, &xHigherPriorityTaskWoken);
|
||||
// portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
// }
|
||||
|
||||
#ifndef TEST
|
||||
void IRAM_ATTR trig_isr_b()
|
||||
|
||||
Reference in New Issue
Block a user