Tester first iteration
This commit is contained in:
67
RotaxMonitorTester/src/main.cpp
Normal file
67
RotaxMonitorTester/src/main.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <Arduino.h>
|
||||
#include <DebugLog.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include <map>
|
||||
|
||||
static hw_timer_t *timerA = NULL;
|
||||
static hw_timer_t *timerB = NULL;
|
||||
TaskHandle_t main_t = NULL;
|
||||
|
||||
static const std::map<const uint32_t, const char*> pin2Name = {
|
||||
{PIN_TRIG_A12P, "HIGH_PIN_TRIG_A12P"},
|
||||
{~PIN_TRIG_A12P, "LOW_PIN_TRIG_A12P"},
|
||||
{PIN_TRIG_A12N, "HIGH_PIN_TRIG_A12N"},
|
||||
{~PIN_TRIG_A12N, "LOW_PIN_TRIG_A12N"},
|
||||
{PIN_TRIG_A34P, "HIGH_PIN_TRIG_A34P"},
|
||||
{~PIN_TRIG_A34P, "LOW_PIN_TRIG_A34P"},
|
||||
{PIN_TRIG_A34N, "HIGH_PIN_TRIG_A34N"},
|
||||
{~PIN_TRIG_A34N, "LOW_PIN_TRIG_A34N"},
|
||||
{SPARK_A12, "HIGH_SPARK_A12"},
|
||||
{~SPARK_A12, "LOW_SPARK_A12"},
|
||||
{SPARK_A34, "HIGH_SPARK_A34"},
|
||||
{~SPARK_A34, "LOW_SPARK_A34"}
|
||||
};
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
Serial.begin(115200);
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
|
||||
pinMode(PIN_TRIG_A12P, OUTPUT);
|
||||
pinMode(PIN_TRIG_A12N, OUTPUT);
|
||||
pinMode(PIN_TRIG_A34P, OUTPUT);
|
||||
pinMode(PIN_TRIG_A34N, OUTPUT);
|
||||
pinMode(SPARK_A12, OUTPUT);
|
||||
pinMode(SPARK_A34, OUTPUT);
|
||||
|
||||
pinMode(PIN_TRIG_B12P, OUTPUT);
|
||||
pinMode(PIN_TRIG_B12N, OUTPUT);
|
||||
pinMode(PIN_TRIG_B34P, OUTPUT);
|
||||
pinMode(PIN_TRIG_B34N, OUTPUT);
|
||||
pinMode(SPARK_B12, OUTPUT);
|
||||
pinMode(SPARK_B34, OUTPUT);
|
||||
|
||||
main_t = xTaskGetCurrentTaskHandleForCore(1);
|
||||
|
||||
// Timer: 80MHz / 80 = 1MHz → 1 tick = 1 µs
|
||||
timerA = timerBegin(10000);
|
||||
timerAttachInterruptArg(timerA, &onTimer, (void *)main_t);
|
||||
timerAlarm(timerA, 10000, true, 0);
|
||||
|
||||
// Timer: 80MHz / 80 = 1MHz → 1 tick = 1 µs
|
||||
// timerB = timerBegin(1);
|
||||
// timerAttachInterrupt(timerB, &onTimer);
|
||||
// timerStart(timerB);
|
||||
|
||||
LOG_INFO("Setup Complete");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t value = 0;
|
||||
if (xTaskNotifyWait(0x00, ULONG_MAX, &value, 0))
|
||||
Serial.println(pin2Name.at(value));
|
||||
delay(10);
|
||||
}
|
||||
19
RotaxMonitorTester/src/pins.h
Normal file
19
RotaxMonitorTester/src/pins.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
///// Ignition Box A /////
|
||||
#define PIN_TRIG_A12P 18
|
||||
#define PIN_TRIG_A12N 19
|
||||
#define PIN_TRIG_A34P 21
|
||||
#define PIN_TRIG_A34N 22
|
||||
|
||||
#define SPARK_A12 23
|
||||
#define SPARK_A34 25
|
||||
|
||||
///// Ignition Box /////
|
||||
#define PIN_TRIG_B12P 26
|
||||
#define PIN_TRIG_B12N 27
|
||||
#define PIN_TRIG_B34P 32
|
||||
#define PIN_TRIG_B34N 33
|
||||
|
||||
#define SPARK_B12 4
|
||||
#define SPARK_B34 5
|
||||
119
RotaxMonitorTester/src/timer.cpp
Normal file
119
RotaxMonitorTester/src/timer.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
#include "timer.h"
|
||||
|
||||
#define TIME_CONST 1
|
||||
|
||||
enum State {
|
||||
S_12P,
|
||||
S_12N_DELAY,
|
||||
S_12N,
|
||||
S_WAIT_10MS,
|
||||
S_34P,
|
||||
S_34N_DELAY,
|
||||
S_34N,
|
||||
S_WAIT_1MS,
|
||||
S_WAIT_10MS_END
|
||||
};
|
||||
|
||||
volatile State state = S_12P;
|
||||
volatile uint32_t state_time = 0;
|
||||
|
||||
void onTimer(void* arg) {
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
TaskHandle_t task = (TaskHandle_t)(arg);
|
||||
state_time += 1;
|
||||
|
||||
switch (state) {
|
||||
|
||||
case S_12P:
|
||||
digitalWrite(PIN_TRIG_A12P, HIGH);
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A12, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A12, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12N;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_12N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, HIGH);
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A12N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A12N, LOW);
|
||||
state = S_WAIT_10MS;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34P;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34P:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, HIGH);
|
||||
|
||||
if (state_time == 2*TIME_CONST){
|
||||
xTaskNotifyFromISR(task, SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, HIGH);
|
||||
}
|
||||
|
||||
if (state_time == 7*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~SPARK_A34, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(SPARK_A34, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34P, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34P, LOW);
|
||||
}
|
||||
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_34N;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_34N:
|
||||
xTaskNotifyFromISR(task, PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, HIGH);
|
||||
|
||||
if (state_time >= 5*TIME_CONST) {
|
||||
xTaskNotifyFromISR(task, ~PIN_TRIG_A34N, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
digitalWrite(PIN_TRIG_A34N, LOW);
|
||||
state = S_WAIT_10MS_END;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case S_WAIT_10MS_END:
|
||||
if (state_time >= 10*TIME_CONST) {
|
||||
state = S_12P;
|
||||
state_time = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
9
RotaxMonitorTester/src/timer.h
Normal file
9
RotaxMonitorTester/src/timer.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <DebugLog.h>
|
||||
#include "pins.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
void IRAM_ATTR onTimer(void* arg);
|
||||
Reference in New Issue
Block a user