Skip to content

Commit 68231ed

Browse files
Statuses struct: use bit fields for status bytes (speeduino#1280)
* Convert statuses::status1: to bit fields * Convert statuses::status2: to bit fields * Convert statuses::status3 to bit fields * Convert statuses::status4 to bit fields * Convert statuses::status5 to bit fields * Convert statuses::airConStatus to bit fields * Convert statuses::engineProtectStatus to bit fields * Remove duplicate #defines (copy/paste error) * Convert statuses::TS_SD_Status to bit fields * Convert statuses::engine to bit fields * statuses::testOutputs: to bit fields * Fix spelling error * Remove type punning from statuses - instead, build the I/O status bytes on demand. This completely separates the internal state from the I/O protocol. * Remove nChannels - never read * MISRA fixes --------- Co-authored-by: Josh Stewart <josh@noisymime.org>
1 parent f11d2c5 commit 68231ed

32 files changed

+931
-862
lines changed

speeduino/SD_logger.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,13 @@ void writeSDLogHeader()
588588
//Sets the status variable for TunerStudio
589589
void setTS_SD_status()
590590
{
591-
if( SD_status == SD_STATUS_ERROR_NO_CARD ) { BIT_CLEAR(currentStatus.TS_SD_Status, SD_STATUS_CARD_PRESENT); } // CARD is not present
592-
else { BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_PRESENT); } // CARD present
593-
594-
BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_TYPE); // CARD is SDHC
595-
596-
BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_READY); // CARD is ready
597-
598-
if( SD_status == SD_STATUS_ACTIVE ) { BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_LOGGING); }// CARD is logging
599-
else { BIT_CLEAR(currentStatus.TS_SD_Status, SD_STATUS_CARD_LOGGING); }// CARD is not logging
600-
601-
if( (SD_status >= SD_STATUS_ERROR_NO_FS) ) { BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_ERROR); }// CARD has an error
602-
else { BIT_CLEAR(currentStatus.TS_SD_Status, SD_STATUS_CARD_ERROR); }// CARD has no error
603-
604-
BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_FS); // CARD has a FAT32 filesystem (Though this will be exFAT)
605-
BIT_CLEAR(currentStatus.TS_SD_Status, SD_STATUS_CARD_UNUSED); //Unused bit is always 0
591+
currentStatus.sdCardPresent = (SD_status != SD_STATUS_ERROR_NO_CARD);
592+
currentStatus.sdCardType = 1U; // CARD is SDHC
593+
currentStatus.sdCardReady = true;
594+
currentStatus.sdCardLogging = (SD_status == SD_STATUS_ACTIVE);
595+
currentStatus.sdCardError = (SD_status >= SD_STATUS_ERROR_NO_FS);
596+
currentStatus.sdCardFS = 1U; // CARD has a FAT32 filesystem (Though this will be exFAT)
597+
currentStatus.sdCardUnused = false; //Unused bit is always 0
606598
}
607599

608600
/**
@@ -637,7 +629,7 @@ void checkForSDStart()
637629
//Check for engine protection based enable
638630
if((configPage13.onboard_log_trigger_prot) && (SD_status == SD_STATUS_READY) )
639631
{
640-
if(currentStatus.engineProtectStatus > 0)
632+
if(isEngineProtectActive(currentStatus))
641633
{
642634
beginSDLogging(); //Setup the log file, preallocation, header row
643635
}
@@ -691,7 +683,7 @@ void checkForSDStop()
691683
}
692684
if(configPage13.onboard_log_trigger_prot)
693685
{
694-
if(currentStatus.engineProtectStatus > 0)
686+
if(isEngineProtectActive(currentStatus))
695687
{
696688
log_prot = true;
697689
}
@@ -742,7 +734,7 @@ void formatExFat()
742734
bool result = false;
743735

744736
//Set the SD status to busy
745-
BIT_CLEAR(currentStatus.TS_SD_Status, SD_STATUS_CARD_READY);
737+
currentStatus.sdCardReady = false;
746738

747739
logFile.close();
748740

@@ -758,7 +750,7 @@ void formatExFat()
758750
}
759751

760752
if(result == false) { SD_status = SD_STATUS_ERROR_FORMAT_FAIL; }
761-
else { BIT_SET(currentStatus.TS_SD_Status, SD_STATUS_CARD_READY); }
753+
else { currentStatus.sdCardReady = true; }
762754
}
763755

764756
/**

speeduino/SD_logger.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
#define SD_STATUS_ERROR_WRITE_FAIL 7 /**< Log file created and opened, but a sector write failed during logging */
2323
#define SD_STATUS_ERROR_FORMAT_FAIL 8 /**< Attempted formatting of SD card failed */
2424

25-
#define SD_STATUS_CARD_PRESENT 0 //0=no card, 1=card present
26-
#define SD_STATUS_CARD_TYPE 1 //0=SD, 1=SDHC
27-
#define SD_STATUS_CARD_READY 2 //0=not ready, 1=ready
28-
#define SD_STATUS_CARD_LOGGING 3 //0=not logging, 1=logging
29-
#define SD_STATUS_CARD_ERROR 4 //0=no error, 1=error
30-
#define SD_STATUS_CARD_VERSION 5 //0=1.x, 1=2.x
31-
#define SD_STATUS_CARD_FS 6 //0=no FAT16, 1=FAT32
32-
#define SD_STATUS_CARD_UNUSED 7 //0=normal, 1=unused
33-
34-
3525
#define SD_SECTOR_SIZE 512 // Standard SD sector size
3626

3727
#if defined CORE_TEENSY

speeduino/TS_CommandButtonHandler.cpp

Lines changed: 58 additions & 59 deletions
Large diffs are not rendered by default.

speeduino/TS_CommandButtonHandler.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ static constexpr uint16_t TS_CMD_STM32_BOOTLOADER = 12801;
6262

6363
static constexpr uint16_t TS_CMD_SD_FORMAT = 13057;
6464

65-
static constexpr uint16_t TS_CMD_VSS_60KMH = 39168; //0x99x00
66-
static constexpr uint16_t TS_CMD_VSS_RATIO1 = 39169;
67-
static constexpr uint16_t TS_CMD_VSS_RATIO2 = 39170;
68-
static constexpr uint16_t TS_CMD_VSS_RATIO3 = 39171;
69-
static constexpr uint16_t TS_CMD_VSS_RATIO4 = 39172;
70-
static constexpr uint16_t TS_CMD_VSS_RATIO5 = 39173;
71-
static constexpr uint16_t TS_CMD_VSS_RATIO6 = 39174;
65+
static constexpr uint16_t TS_CMD_VSS_60KMH = 39168U; //0x99x00
66+
static constexpr uint16_t TS_CMD_VSS_RATIO1 = 39169U;
67+
static constexpr uint16_t TS_CMD_VSS_RATIO2 = 39170U;
68+
static constexpr uint16_t TS_CMD_VSS_RATIO3 = 39171U;
69+
static constexpr uint16_t TS_CMD_VSS_RATIO4 = 39172U;
70+
static constexpr uint16_t TS_CMD_VSS_RATIO5 = 39173U;
71+
static constexpr uint16_t TS_CMD_VSS_RATIO6 = 39174U;
7272

7373
/* the maximum id number is 65,535 */
7474
bool TS_CommandButtonsHandler(uint16_t buttonCommand);

0 commit comments

Comments
 (0)