refactoring: reducing code duplication

This commit is contained in:
rusefi 2019-02-23 12:33:49 -05:00
parent 4bba678dce
commit 46bdbf82d1
21 changed files with 38 additions and 37 deletions

View File

@ -155,7 +155,7 @@ bool stopTsPort(ts_channel_s *tsChannel) {
}
void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size) {
efiAssertVoid(CUSTOM_ERR_6570, getRemainingStack(chThdGetSelfX()) > 64, "tunerStudioWriteData");
efiAssertVoid(CUSTOM_ERR_6570, getCurrentRemainingStack() > 64, "tunerStudioWriteData");
#if EFI_SIMULATOR || defined(__DOXYGEN__)
logMsg("chSequentialStreamWrite [%d]\r\n", size);
#endif

View File

@ -157,7 +157,7 @@ void runConsoleLoop(ts_channel_s *console) {
}
while (true) {
efiAssertVoid(CUSTOM_ERR_6571, getRemainingStack(chThdGetSelfX()) > 256, "lowstck#9e");
efiAssertVoid(CUSTOM_ERR_6571, getCurrentRemainingStack() > 256, "lowstck#9e");
bool end = getConsoleLine((BaseSequentialStream*) console->channel, console->crcReadBuffer, sizeof(console->crcReadBuffer) - 3);
if (end) {
// firmware simulator is the only case when this happens

View File

@ -1343,7 +1343,7 @@ void validateConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(CUSTOM_APPLY_STACK, getRemainingStack(chThdGetSelfX()) > 256, "apply c");
efiAssertVoid(CUSTOM_APPLY_STACK, getCurrentRemainingStack() > 256, "apply c");
scheduleMsg(logger, "applyNonPersistentConfiguration()");
#endif

View File

@ -139,7 +139,7 @@ void LECalculator::push(le_action_e action, float value) {
*/
bool LECalculator::processElement(LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssert(CUSTOM_ERR_ASSERT, getRemainingStack(chThdGetSelfX()) > 64, "FSIO logic", false);
efiAssert(CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > 64, "FSIO logic", false);
#endif
switch (element->action) {

View File

@ -278,7 +278,7 @@ static void invokePerSecond(void) {
static void periodicSlowCallback(Engine *engine) {
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
efiAssertVoid(CUSTOM_ERR_6661, getRemainingStack(chThdGetSelfX()) > 64, "lowStckOnEv");
efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv");
#if EFI_PROD_CODE
/**
* We need to push current value into the 64 bit counter often enough so that we do not miss an overflow

View File

@ -130,7 +130,7 @@ static persisted_configuration_state_e doReadConfiguration(flashaddr_t address,
* connectivity so no console output here
*/
persisted_configuration_state_e readConfiguration(Logging * logger) {
efiAssert(CUSTOM_ERR_ASSERT, getRemainingStack(chThdGetSelfX()) > 256, "read f", PC_ERROR);
efiAssert(CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > 256, "read f", PC_ERROR);
persisted_configuration_state_e result = doReadConfiguration(FLASH_ADDR, logger);
if (result != PC_OK) {
printMsg(logger, "Reading second configuration copy");

View File

@ -109,7 +109,7 @@ static bool isAveraging = false;
static void startAveraging(void *arg) {
(void) arg;
efiAssertVoid(CUSTOM_ERR_6649, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#9");
efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9");
bool wasLocked = lockAnyContext();
;
// with locking we would have a consistent state
@ -135,7 +135,7 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
/* Calculates the average values from the ADC samples.*/
measurementsPerRevolutionCounter++;
efiAssertVoid(CUSTOM_ERR_6650, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#9a");
efiAssertVoid(CUSTOM_ERR_6650, getCurrentRemainingStack() > 128, "lowstck#9a");
#if (EFI_SENSOR_CHART && EFI_ANALOG_SENSORS) || defined(__DOXYGEN__)
if (ENGINE(sensorChartMode) == SC_MAP) {

View File

@ -43,7 +43,7 @@ uint32_t lastExecutionCount;
static void executorCallback(void *arg) {
(void)arg;
efiAssertVoid(CUSTOM_ERR_6624, getRemainingStack(chThdGetSelfX()) > 256, "lowstck#2y");
efiAssertVoid(CUSTOM_ERR_6624, getCurrentRemainingStack() > 256, "lowstck#2y");
// callbackTime = getTimeNowNt();
// if((callbackTime > nextEventTimeNt) && (callbackTime - nextEventTimeNt > US2NT(5000))) {

View File

@ -404,7 +404,7 @@ void TriggerShape::setSecondTriggerSynchronizationGap(float syncRatio) {
void TriggerShape::initializeTriggerShape(Logging *logger, operation_mode_e operationMode, bool useOnlyRisingEdgeForTrigger, const trigger_config_s *triggerConfig) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(CUSTOM_ERR_6641, getRemainingStack(chThdGetSelfX()) > 256, "init t");
efiAssertVoid(CUSTOM_ERR_6641, getCurrentRemainingStack() > 256, "init t");
scheduleMsg(logger, "initializeTriggerShape(%s/%d)", getTrigger_type_e(triggerConfig->type), (int) triggerConfig->type);
#endif

View File

@ -26,13 +26,6 @@
#include <nvic.h>
#endif
#if (!EFI_PROD_CODE && !EFI_SIMULATOR) || defined(__DOXYGEN__)
#define chThdGetSelfX() 0
#define getRemainingStack(x) (999999)
#endif
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
#include "main_trigger_callback.h"
@ -373,7 +366,7 @@ static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
efiAssertVoid(CUSTOM_ERR_6627, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#3");
efiAssertVoid(CUSTOM_ERR_6627, getCurrentRemainingStack() > 128, "lowstck#3");
efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index");
if (!isInjectionEnabled(PASS_ENGINE_PARAMETER_SIGNATURE) || limitedFuel) {
@ -446,7 +439,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D
*/
return;
}
efiAssertVoid(CUSTOM_ERR_6629, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#2");
efiAssertVoid(CUSTOM_ERR_6629, getCurrentRemainingStack() > 128, "lowstck#2");
if (trgEventIndex >= ENGINE(engineCycleEventCount)) {
/**

View File

@ -228,7 +228,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
efitick_t nowNt = getTimeNowNt();
#if EFI_PROD_CODE
efiAssertVoid(CUSTOM_ERR_6632, getRemainingStack(chThdGetSelfX()) > 256, "lowstckRCL");
efiAssertVoid(CUSTOM_ERR_6632, getCurrentRemainingStack() > 256, "lowstckRCL");
#endif
RpmCalculator *rpmState = &engine->rpmCalculator;

View File

@ -198,7 +198,7 @@ void hwHandleShaftSignal(trigger_event_e signal) {
if (triggerReentraint > maxTriggerReentraint)
maxTriggerReentraint = triggerReentraint;
triggerReentraint++;
efiAssertVoid(CUSTOM_ERR_6636, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#8");
efiAssertVoid(CUSTOM_ERR_6636, getCurrentRemainingStack() > 128, "lowstck#8");
engine->triggerCentral.handleShaftSignal(signal PASS_ENGINE_PARAMETER_SUFFIX);
triggerReentraint--;
triggerDuration = GET_TIMESTAMP() - triggerHandlerEntryTime;

View File

@ -107,7 +107,7 @@ bool isTriggerDecoderError(void) {
void calculateTriggerSynchPoint(TriggerShape *shape, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(CUSTOM_ERR_6642, getRemainingStack(chThdGetSelfX()) > 256, "calc s");
efiAssertVoid(CUSTOM_ERR_6642, getCurrentRemainingStack() > 256, "calc s");
#endif
trigger_config_s const*triggerConfig = &engineConfiguration->trigger;
@ -634,7 +634,7 @@ uint32_t findTriggerZeroEventIndex(TriggerState *state, TriggerShape * shape,
trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX) {
UNUSED(triggerConfig);
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssert(CUSTOM_ERR_ASSERT, getRemainingStack(chThdGetSelfX()) > 128, "findPos", -1);
efiAssert(CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > 128, "findPos", -1);
#endif
errorDetection.clear();
efiAssert(CUSTOM_ERR_ASSERT, state != NULL, "NULL state", -1);

View File

@ -172,7 +172,7 @@ void WaveChart::addEvent3(const char *name, const char * msg) {
efiAssertVoid(CUSTOM_ERR_6651, name!=NULL, "WC: NULL name");
#if EFI_PROD_CODE
efiAssertVoid(CUSTOM_ERR_6652, getRemainingStack(chThdGetSelfX()) > 32, "lowstck#2c");
efiAssertVoid(CUSTOM_ERR_6652, getCurrentRemainingStack() > 32, "lowstck#2c");
#endif
efiAssertVoid(CUSTOM_ERR_6653, isInitialized, "chart not initialized");

View File

@ -103,6 +103,8 @@ typedef unsigned int time_t;
turnAllPinsOff(); \
enginePins.communicationLedPin.setValue(1);
#define getCurrentRemainingStack() getRemainingStack(chThdGetSelfX())
/*
* Stack debugging
* See also getMaxUsedStack()

View File

@ -174,7 +174,7 @@ AdcDevice fastAdc(&adcgrpcfg_fast);
void doSlowAdc(void) {
efiAssertVoid(CUSTOM_ERR_6658, getRemainingStack(chThdGetSelfX())> 32, "lwStAdcSlow");
efiAssertVoid(CUSTOM_ERR_6658, getCurrentRemainingStack()> 32, "lwStAdcSlow");
#if EFI_INTERNAL_ADC
@ -206,7 +206,7 @@ static void pwmpcb_slow(PWMDriver *pwmp) {
}
static void pwmpcb_fast(PWMDriver *pwmp) {
efiAssertVoid(CUSTOM_ERR_6659, getRemainingStack(chThdGetSelfX())> 32, "lwStAdcFast");
efiAssertVoid(CUSTOM_ERR_6659, getCurrentRemainingStack()> 32, "lwStAdcFast");
#if EFI_INTERNAL_ADC
(void) pwmp;
@ -573,7 +573,7 @@ int getSlowAdcCounter() {
static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
(void) buffer;
(void) n;
efiAssertVoid(CUSTOM_ERR_6671, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#9c");
efiAssertVoid(CUSTOM_ERR_6671, getCurrentRemainingStack() > 128, "lowstck#9c");
/* Note, only in the ADC_COMPLETE state because the ADC driver fires
* an intermediate callback when the buffer is half full. */
if (adcp->state == ADC_COMPLETE) {

View File

@ -87,7 +87,7 @@ bool rtcWorks = true;
* Only one consumer can use SPI bus at a given time
*/
void lockSpi(spi_device_e device) {
efiAssertVoid(CUSTOM_ERR_6674, getRemainingStack(chThdGetSelfX()) > 128, "lockSpi");
efiAssertVoid(CUSTOM_ERR_6674, getCurrentRemainingStack() > 128, "lockSpi");
// todo: different locks for different SPI devices!
chMtxLock(&spiMtx);
}
@ -191,7 +191,7 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
/**
* this callback is executed 10 000 times a second, it needs to be as fast as possible
*/
efiAssertVoid(CUSTOM_ERR_6676, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#9b");
efiAssertVoid(CUSTOM_ERR_6676, getCurrentRemainingStack() > 128, "lowstck#9b");
#if EFI_MAP_AVERAGING
mapAveragingAdcCallback(fastAdc.samples[fastMapSampleIndex]);
@ -325,7 +325,7 @@ void showBor(void) {
}
void initHardware(Logging *l) {
efiAssertVoid(CUSTOM_IH_STACK, getRemainingStack(chThdGetSelfX()) > 256, "init h");
efiAssertVoid(CUSTOM_IH_STACK, getCurrentRemainingStack() > 256, "init h");
sharedLogger = l;
engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr;
efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration");

View File

@ -161,7 +161,7 @@ static void scheduleReboot(void) {
}
void runRusEfi(void) {
efiAssertVoid(CUSTOM_RM_STACK_1, getRemainingStack(chThdGetSelfX()) > 512, "init s");
efiAssertVoid(CUSTOM_RM_STACK_1, getCurrentRemainingStack() > 512, "init s");
assertEngineReference();
engine->setConfig(config);
initIntermediateLoggingBuffer();
@ -233,7 +233,7 @@ void runRusEfi(void) {
* control is around main_trigger_callback
*/
while (true) {
efiAssertVoid(CUSTOM_RM_STACK, getRemainingStack(chThdGetSelfX()) > 128, "stack#1");
efiAssertVoid(CUSTOM_RM_STACK, getCurrentRemainingStack() > 128, "stack#1");
#if (EFI_CLI_SUPPORT && !EFI_UART_ECHO_TEST_MODE) || defined(__DOXYGEN__)
// sensor state + all pending messages for our own dev console

View File

@ -100,7 +100,7 @@ static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
return;
}
intermediateLoggingBuffer.eos = 0; // reset
efiAssertVoid(CUSTOM_ERR_6603, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#1b");
efiAssertVoid(CUSTOM_ERR_6603, getCurrentRemainingStack() > 128, "lowstck#1b");
chvprintf((BaseSequentialStream *) &intermediateLoggingBuffer, fmt, arg);
intermediateLoggingBuffer.buffer[intermediateLoggingBuffer.eos] = 0; // need to terminate explicitly
logging->append((char *)intermediateLoggingBuffer.buffer);
@ -110,7 +110,7 @@ static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
* this method acquires system lock to guard the shared intermediateLoggingBuffer memory stream
*/
void Logging::vappendPrintf(const char *fmt, va_list arg) {
efiAssertVoid(CUSTOM_ERR_6604, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#5b");
efiAssertVoid(CUSTOM_ERR_6604, getCurrentRemainingStack() > 128, "lowstck#5b");
int wasLocked = lockAnyContext();
vappendPrintfI(this, fmt, arg);
if (!wasLocked) {
@ -120,7 +120,7 @@ void Logging::vappendPrintf(const char *fmt, va_list arg) {
// todo: replace with logging->appendPrintf
void appendPrintf(Logging *logging, const char *fmt, ...) {
efiAssertVoid(CUSTOM_APPEND_STACK, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#4");
efiAssertVoid(CUSTOM_APPEND_STACK, getCurrentRemainingStack() > 128, "lowstck#4");
va_list ap;
va_start(ap, fmt);
logging->vappendPrintf(fmt, ap);
@ -128,7 +128,7 @@ void appendPrintf(Logging *logging, const char *fmt, ...) {
}
void Logging::appendPrintf(const char *fmt, ...) {
efiAssertVoid(CUSTOM_APPEND_STACK, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#4");
efiAssertVoid(CUSTOM_APPEND_STACK, getCurrentRemainingStack() > 128, "lowstck#4");
va_list ap;
va_start(ap, fmt);
vappendPrintf(fmt, ap);
@ -250,7 +250,7 @@ void resetLogging(Logging *logging) {
* This method should only be invoked on main thread because only the main thread can write to the console
*/
void printMsg(Logging *logger, const char *fmt, ...) {
efiAssertVoid(CUSTOM_ERR_6605, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#5o");
efiAssertVoid(CUSTOM_ERR_6605, getCurrentRemainingStack() > 128, "lowstck#5o");
// resetLogging(logging); // I guess 'reset' is not needed here?
appendMsgPrefix(logger);

View File

@ -64,6 +64,8 @@ extern "C"
void printToConsole(char *p);
#define getCurrentRemainingStack() getRemainingStack(chThdGetSelfX())
int getRemainingStack(thread_t *otp);
// todo: move somewhere else?

View File

@ -17,6 +17,10 @@
#include "boards.h"
//#define chThdGetSelfX() 0
//#define getRemainingStack(x) (999999)
#define getCurrentRemainingStack() (999999)
// this is needed by all DECLARE_ENGINE_PARAMETER_* usages
#include "engine_configuration_generated_structures.h"