Tester first iteration

This commit is contained in:
Emanuele Trabattoni
2026-03-31 17:44:00 +02:00
parent 6072a603df
commit 21e50bdca8
10 changed files with 362 additions and 0 deletions

5
RotaxMonitorTester/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.
The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").
For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@@ -0,0 +1,39 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-devtest-release]
board = esp32dev
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
framework = arduino
lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 115200
build_type = release
[env:esp32-devtest-debug]
board = esp32dev
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.37/platform-espressif32.zip
framework = arduino
lib_deps =
hideakitai/DebugLog@^0.8.4
board_build.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 115200
build_type = debug
build_flags =
-O0
-g3
-ggdb
-fno-inline
-fno-ipa-sra
-fno-tree-sra
-fno-builtin

View 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);
}

View 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

View 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();
}

View 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);

View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html