First Test env
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#define TEST
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <map>
|
||||
#include "soc/gpio_struct.h"
|
||||
#include "pins.h"
|
||||
#ifndef TEST
|
||||
#include "pins.h"
|
||||
#else
|
||||
#include "pins_test.h"
|
||||
#endif
|
||||
|
||||
#define CORE_0 0
|
||||
#define CORE_1 1
|
||||
@@ -16,15 +23,28 @@
|
||||
#define TRIG_FLAG_A12N (1 << 2)
|
||||
#define TRIG_FLAG_A34P (1 << 1)
|
||||
#define TRIG_FLAG_A34N (1 << 3)
|
||||
#ifndef TEST
|
||||
#define TRIG_FLAG_B12P (1 << 4)
|
||||
#define TRIG_FLAG_B12N (1 << 6)
|
||||
#define TRIG_FLAG_B34P (1 << 5)
|
||||
#define TRIG_FLAG_B34N (1 << 7)
|
||||
#endif
|
||||
|
||||
#define SPARK_FLAG_A12 (1 << 8)
|
||||
#define SPARK_FLAG_A34 (1 << 9)
|
||||
#ifndef TEST
|
||||
#define SPARK_FLAG_B12 (1 << 10)
|
||||
#define SPARK_FLAG_B34 (1 << 11)
|
||||
#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"},
|
||||
};
|
||||
|
||||
// Task handle
|
||||
TaskHandle_t trigA_TaskHandle = NULL;
|
||||
@@ -52,7 +72,7 @@ enum softStartStatus
|
||||
NORMAL
|
||||
};
|
||||
|
||||
typedef struct coilsStatus
|
||||
struct coilsStatus
|
||||
{
|
||||
int64_t trig_time;
|
||||
int64_t spark_time;
|
||||
@@ -64,7 +84,7 @@ typedef struct coilsStatus
|
||||
};
|
||||
|
||||
// Task internal Status
|
||||
typedef struct ignitionBoxStatus
|
||||
struct ignitionBoxStatus
|
||||
{
|
||||
// coils pairs for each ignition
|
||||
coilsStatus coils12;
|
||||
@@ -84,10 +104,12 @@ void initTriggerPinMapping()
|
||||
pin2trig[TRIG_A12N] = TRIG_FLAG_A12N;
|
||||
pin2trig[TRIG_A34P] = TRIG_FLAG_A34P;
|
||||
pin2trig[TRIG_A34N] = TRIG_FLAG_A34N;
|
||||
#ifndef TEST
|
||||
pin2trig[TRIG_B12P] = TRIG_FLAG_B12P;
|
||||
pin2trig[TRIG_B12N] = TRIG_FLAG_B12N;
|
||||
pin2trig[TRIG_B34P] = TRIG_FLAG_B34P;
|
||||
pin2trig[TRIG_B34N] = TRIG_FLAG_B34N;
|
||||
#endif
|
||||
};
|
||||
|
||||
static uint32_t pin2spark[49];
|
||||
@@ -95,8 +117,10 @@ void initSparkPinMapping()
|
||||
{
|
||||
pin2spark[SPARK_A12] = SPARK_FLAG_A12;
|
||||
pin2spark[SPARK_A34] = SPARK_FLAG_A34;
|
||||
#ifndef TEST
|
||||
pin2spark[SPARK_B12] = SPARK_FLAG_B12;
|
||||
pin2spark[SPARK_B34] = SPARK_FLAG_B34;
|
||||
#endif
|
||||
};
|
||||
|
||||
// =====================
|
||||
@@ -110,7 +134,11 @@ void IRAM_ATTR trig_isr_a()
|
||||
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;
|
||||
|
||||
while (status)
|
||||
@@ -125,7 +153,7 @@ void IRAM_ATTR trig_isr_a()
|
||||
if (pickup_flags & TRIG_FLAG_A34P)
|
||||
ignA_status.coils34.trig_time = time_us;
|
||||
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, pickup_flags, eSetBits, &xHigherPriorityTaskWoken);
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, GPIO.status1.val, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
@@ -135,15 +163,21 @@ void IRAM_ATTR spark_a()
|
||||
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
|
||||
|
||||
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, spark_flag, eSetBits, &xHigherPriorityTaskWoken);
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, GPIO.status, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
#ifndef TEST
|
||||
void IRAM_ATTR trig_isr_b()
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
@@ -151,7 +185,11 @@ void IRAM_ATTR trig_isr_b()
|
||||
if (!trigB_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;
|
||||
|
||||
while (status)
|
||||
@@ -184,3 +222,4 @@ void IRAM_ATTR spark_b()
|
||||
xTaskNotifyFromISR(trigB_TaskHandle, spark_flag, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user