Updated pin definitions and trigger tasks from pickups
This commit is contained in:
@@ -1,40 +1,106 @@
|
||||
#include <Arduino.h>
|
||||
#include "soc/gpio_struct.h"
|
||||
#include "pins.h"
|
||||
|
||||
|
||||
#define CORE_0 0
|
||||
#define CORE_1 1
|
||||
#define TASK_STACK 4096 // in words
|
||||
#define TASK_PRIORITY 2 // priorità leggermente più alta
|
||||
|
||||
// =====================
|
||||
// Event Flags (bitmask)
|
||||
// =====================
|
||||
#define PKDT_FLAG_AP (1 << 0)
|
||||
#define PKDT_FLAG_AN (1 << 1)
|
||||
#define PKDT_FLAG_BP (1 << 2)
|
||||
#define PKDT_FLAG_BN (1 << 3)
|
||||
#define TRIG_FLAG_A12P (1 << 0)
|
||||
#define TRIG_FLAG_A12N (1 << 2)
|
||||
#define TRIG_FLAG_A34P (1 << 1)
|
||||
#define TRIG_FLAG_A34N (1 << 3)
|
||||
#define TRIG_FLAG_B12P (1 << 4)
|
||||
#define TRIG_FLAG_B12N (1 << 6)
|
||||
#define TRIG_FLAG_B34P (1 << 5)
|
||||
#define TRIG_FLAG_B34N (1 << 7)
|
||||
|
||||
// Task handle
|
||||
TaskHandle_t pkdtTaskHandle = NULL;
|
||||
TaskHandle_t trigA_TaskHandle = NULL;
|
||||
TaskHandle_t trigB_TaskHandle = NULL;
|
||||
|
||||
// Task internal Status
|
||||
struct taskStatus {
|
||||
int64_t trig12_start;
|
||||
int64_t trig34_start;
|
||||
|
||||
int64_t trig12_time;
|
||||
int64_t trig34_time;
|
||||
|
||||
bool trig12_complete = false;
|
||||
bool trig34_complete = false;
|
||||
|
||||
bool soft12 = false;
|
||||
bool soft34 = false;
|
||||
|
||||
bool error12 = false;
|
||||
bool error34 = false;
|
||||
};
|
||||
|
||||
taskStatus ignA_status;
|
||||
taskStatus ignB_status;
|
||||
|
||||
// Pin to flag Map
|
||||
static const uint32_t int2flag[] = {
|
||||
[TRIG_A12P] = TRIG_FLAG_A12P,
|
||||
[TRIG_A12N] = TRIG_FLAG_A34P,
|
||||
[TRIG_A34P] = TRIG_FLAG_A12N,
|
||||
[TRIG_A34N] = TRIG_FLAG_A34N,
|
||||
[TRIG_B12P] = TRIG_FLAG_B12P,
|
||||
[TRIG_B12N] = TRIG_FLAG_B34P,
|
||||
[TRIG_B34P] = TRIG_FLAG_B12N,
|
||||
[TRIG_B34N] = TRIG_FLAG_B34N,
|
||||
};
|
||||
|
||||
// =====================
|
||||
// ISR (Pass return bitmask to ISR management function)
|
||||
// one function for each wake up pin conncted to a trigger
|
||||
// =====================
|
||||
void IRAM_ATTR pkdt_isr_ap() {
|
||||
void IRAM_ATTR trig_isr_a() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(pkdtTaskHandle, PKDT_FLAG_AP, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
auto startTime = esp_timer_get_time();
|
||||
|
||||
uint32_t status = GPIO.status;
|
||||
uint32_t flags = 0;
|
||||
|
||||
while (status) {
|
||||
uint32_t pin = __builtin_ctz(status); // trova primo bit attivo
|
||||
status &= ~(1 << pin); // clear bit
|
||||
|
||||
flags |= int2flag[pin];
|
||||
}
|
||||
|
||||
if (flags & (TRIG_FLAG_A12P | TRIG_FLAG_A12N))
|
||||
ignA_status.trig12_start = startTime;
|
||||
else
|
||||
ignA_status.trig12_start = startTime;
|
||||
|
||||
if (trigA_TaskHandle) {
|
||||
xTaskNotifyFromISR(trigA_TaskHandle, flags, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR pkdt_isr_an() {
|
||||
void IRAM_ATTR trig_isr_b() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(pkdtTaskHandle, PKDT_FLAG_AN, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
void IRAM_ATTR pkdt_isr_bp() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(pkdtTaskHandle, PKDT_FLAG_BP, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
uint32_t status = GPIO.status;
|
||||
uint32_t flags = 0;
|
||||
|
||||
void IRAM_ATTR pkdt_isr_bn() {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xTaskNotifyFromISR(pkdtTaskHandle, PKDT_FLAG_BN, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
while (status) {
|
||||
uint32_t pin = __builtin_ctz(status); // trova primo bit attivo
|
||||
status &= ~(1 << pin); // clear bit
|
||||
|
||||
flags |= int2flag[pin];
|
||||
}
|
||||
|
||||
if (trigB_TaskHandle) {
|
||||
xTaskNotifyFromISR(trigB_TaskHandle, flags, eSetBits, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user