Skip to content

Commit

Permalink
Bug fix: reset control can be enabled but pin can be set to zero (spe…
Browse files Browse the repository at this point in the history
…eduino#1142)

* Reset control pin: don't over-writie the board default with zero.
The added unit tests interfered with each other & hung -
solution is to reinitialize the global context at the start of
each test.

* Additional pin init tests
  • Loading branch information
adbancroft authored Nov 27, 2023
1 parent 963f631 commit d5d4274
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 7 deletions.
4 changes: 3 additions & 1 deletion speeduino/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,8 +2866,10 @@ void setPinMapping(byte boardID)
because the control pin will go low as soon as the pinMode is set to OUTPUT. */
if ( (configPage4.resetControlConfig != 0) && (configPage4.resetControlPin < BOARD_MAX_IO_PINS) )
{
if (configPage4.resetControlPin!=0U) {
pinResetControl = pinTranslate(configPage4.resetControlPin);
}
resetControl = configPage4.resetControlConfig;
pinResetControl = pinTranslate(configPage4.resetControlPin);
setResetControlPinState();
pinMode(pinResetControl, OUTPUT);
}
Expand Down
3 changes: 3 additions & 0 deletions speeduino/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ void setResetControlPinState(void)
digitalWrite(pinResetControl, HIGH);
BIT_CLEAR(currentStatus.status3, BIT_STATUS3_RESET_PREVENT);
break;
default:
// Do nothing - keep MISRA happy
break;
}
}

Expand Down
24 changes: 23 additions & 1 deletion test/test_init/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#include <Arduino.h>
#include <unity.h>
#include "storage.h"
#include "globals.h"

// Since it's almost impossible for the tests to clean up
// after themselves, we need to reset the global context
// prior to each test running.
//
// Since each test is (usually) testing the results of
// initialiseAll(), the flow is:
// 1. prepareForInitialise()
// 2. Set any config page values.
// 3. initialiseAll()
// 4. ASSERT on the results.
void prepareForInitialiseAll(uint8_t boardId) {
resetConfigPages();
// This is required to prevent initialiseAll() also
// calling resetConfigPages & thus blatting any
// configuration made in step 2.
configPage2.pinMapping = boardId;
initialisationComplete = false;
}


void testInitialisation(void);
void testFuelScheduleInit(void);
Expand All @@ -17,9 +39,9 @@ void setup()

UNITY_BEGIN(); // IMPORTANT LINE!

testInitialisation();
testFuelScheduleInit();
testIgnitionScheduleInit();
testInitialisation();

UNITY_END(); // stop unit testing
}
Expand Down
16 changes: 16 additions & 0 deletions test/test_init/test_fuel_schedule_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "scheduledIO.h"
#include "utilities.h"
#include "../test_utils.h"
#include "storage.h"

extern uint16_t req_fuel_uS;
void prepareForInitialiseAll(uint8_t boardId);

static constexpr uint16_t reqFuel = 86; // ms * 10

Expand Down Expand Up @@ -102,6 +104,7 @@ static void cylinder1_stroke4_semiseq_staged(void)

static void run_1_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 1;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -160,6 +163,7 @@ static void cylinder1_stroke2_semiseq_staged(void)

static void run_1_cylinder_2stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 1;
configPage2.strokes = TWO_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -218,6 +222,7 @@ static void cylinder2_stroke4_semiseq_staged(void)

static void run_2_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 2;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -277,6 +282,7 @@ static void cylinder2_stroke2_semiseq_staged(void)

static void run_2_cylinder_2stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 2;
configPage2.strokes = TWO_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -345,6 +351,7 @@ static void cylinder3_stroke4_semiseq_staged(void)

static void run_3_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 3;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -409,6 +416,7 @@ static void cylinder3_stroke2_semiseq_staged(void)

static void run_3_cylinder_2stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 3;
configPage2.strokes = TWO_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -478,6 +486,7 @@ static void cylinder4_stroke4_semiseq_staged(void)

void run_4_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 4;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -543,6 +552,7 @@ static void cylinder4_stroke2_semiseq_staged(void)

void run_4_cylinder_2stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 4;
configPage2.strokes = TWO_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -617,6 +627,7 @@ static void cylinder5_stroke4_semiseq_staged(void)

void run_5_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 5;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -689,6 +700,7 @@ static void cylinder6_stroke4_semiseq_staged(void)

void run_6_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 6;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -720,6 +732,7 @@ static void cylinder8_stroke4_seq_nostage(void)

void run_8_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 8;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down Expand Up @@ -813,6 +826,7 @@ static void cylinder_8_NoinjTiming_paired(void) {

static void run_no_inj_timing_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
configPage2.injTiming = false;
Expand Down Expand Up @@ -843,6 +857,7 @@ static void cylinder_2_oddfire(void)

static void run_oddfire_tests()
{
prepareForInitialiseAll(3U);
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = ODD_FIRE;
configPage2.injTiming = true;
Expand Down Expand Up @@ -878,6 +893,7 @@ static void run_oddfire_tests()

static void test_partial_sync(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 4;
configPage2.strokes = FOUR_STROKE;
configPage2.engineType = EVEN_FIRE;
Expand Down
11 changes: 11 additions & 0 deletions test/test_init/test_ignition_schedule_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "schedule_calcs.h"
#include "scheduledIO.h"
#include "../test_utils.h"
#include "storage.h"

void prepareForInitialiseAll(uint8_t boardId);

static void assert_ignition_channel(uint16_t angle, uint8_t channel, int channelInjDegrees, voidVoidCallback startFunction, voidVoidCallback endFunction)
{
Expand Down Expand Up @@ -74,6 +77,7 @@ static void cylinder1_stroke4_seq_odd(void)

static void run_1_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 1;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -115,6 +119,7 @@ static void cylinder2_stroke4_seq_odd(void)

static void run_2_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 2;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -155,6 +160,7 @@ static void cylinder3_stroke4_wasted_odd(void)

static void run_3_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 3;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -201,6 +207,7 @@ static void cylinder4_stroke4_seq_odd(void)

static void run_4_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 4;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -229,6 +236,7 @@ static void cylinder5_stroke4_wasted_even(void)

static void run_5_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 5;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -261,6 +269,7 @@ static void cylinder6_stroke4_wasted_even(void)

static void run_6_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 6;
configPage2.strokes = FOUR_STROKE;

Expand Down Expand Up @@ -294,6 +303,7 @@ static void cylinder8_stroke4_wasted_even(void)

static void run_8_cylinder_4stroke_tests(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 8;
configPage2.strokes = FOUR_STROKE;

Expand All @@ -303,6 +313,7 @@ static void run_8_cylinder_4stroke_tests(void)

static void test_partial_sync(void)
{
prepareForInitialiseAll(3U);
configPage2.nCylinders = 4;
configPage2.strokes = FOUR_STROKE;
configPage4.sparkMode = IGN_MODE_SEQUENTIAL;
Expand Down
Loading

0 comments on commit d5d4274

Please sign in to comment.