diff --git a/firmware/config/engines/audi_aan.h b/firmware/config/engines/audi_aan.h index 5e1edb7c94..28ba423dc9 100644 --- a/firmware/config/engines/audi_aan.h +++ b/firmware/config/engines/audi_aan.h @@ -9,6 +9,7 @@ #ifndef AUDI_AAN_H_ #define AUDI_AAN_H_ +#include "global.h" #if EFI_ENGINE_AUDI_AAN #endif /* EFI_ENGINE_AUDI_AAN */ diff --git a/firmware/config/engines/snow_blower.h b/firmware/config/engines/snow_blower.h index f33e2e468e..16242dfbcb 100644 --- a/firmware/config/engines/snow_blower.h +++ b/firmware/config/engines/snow_blower.h @@ -9,6 +9,8 @@ #ifndef SNOW_BLOWER_H_ #define SNOW_BLOWER_H_ +#include "global.h" + #if EFI_ENGINE_SNOW_BLOWER #endif /* EFI_ENGINE_SNOW_BLOWER */ diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp index 3fad6fcd4a..e2f32ff744 100644 --- a/firmware/controllers/error_handling.cpp +++ b/firmware/controllers/error_handling.cpp @@ -17,18 +17,12 @@ #include static MemoryStream warningStream; static MemoryStream firmwareErrorMessageStream; -extern OutputPin communicationPin; - -#endif - +#endif /* EFI_SIMULATOR || EFI_PROD_CODE */ #define WARNING_BUFFER_SIZE 80 static char warningBuffer[WARNING_BUFFER_SIZE]; static bool isWarningStreamInitialized = false; - - - #if EFI_HD44780_LCD || defined(__DOXYGEN__) #include "lcd_HD44780.h" #endif /* EFI_HD44780_LCD */ @@ -95,15 +89,18 @@ void addWarningCode(obd_code_e code) { engine->engineState.lastErrorCode = code; } +// todo: look into chsnprintf // todo: move to some util file & reuse for 'firmwareError' method void printToStream(MemoryStream *stream, const char *fmt, va_list ap) { stream->eos = 0; // reset chvprintf((BaseSequentialStream *) stream, fmt, ap); stream->buffer[stream->eos] = 0; } -#endif +#else +int unitTestWarningCounter = 0; + +#endif /* EFI_SIMULATOR || EFI_PROD_CODE */ -int warningCounter = 0; /** * OBD_PCM_Processor_Fault is the general error code for now @@ -141,7 +138,7 @@ bool warning(obd_code_e code, const char *fmt, ...) { append(&logger, DELIMETER); scheduleLogging(&logger); #else - warningCounter++; + unitTestWarningCounter++; printf("unit_test_warning: "); va_list ap; va_start(ap, fmt); @@ -199,6 +196,7 @@ void firmwareError(obd_code_e code, const char *fmt, ...) { strncpy((char*) errorMessageBuffer, fmt, sizeof(errorMessageBuffer) - 1); errorMessageBuffer[sizeof(errorMessageBuffer) - 1] = 0; // just to be sure } else { + // todo: look into chsnprintf once on Chibios 3 firmwareErrorMessageStream.eos = 0; // reset va_list ap; va_start(ap, fmt); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 90f5af3bb9..c32033d94e 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -181,7 +181,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, efitick_t nowNt = getTimeNowNt(); engine->m.beforeRpmCb = GET_TIMESTAMP(); #if EFI_PROD_CODE - efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#2z"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "lowstck#2z"); #endif #if EFI_SENSOR_CHART || defined(__DOXYGEN__) diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 486d5cfc97..534a9229cb 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -170,7 +170,7 @@ void hwHandleShaftSignal(trigger_event_e signal) { if (triggerReentraint > maxTriggerReentraint) maxTriggerReentraint = triggerReentraint; triggerReentraint++; - efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#8"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 128, "lowstck#8"); engine->triggerCentral.handleShaftSignal(signal PASS_ENGINE_PARAMETER); triggerReentraint--; triggerDuration = GET_TIMESTAMP() - triggerHanlderEntryTime; diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 95497836c3..2ffe65fe14 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -483,7 +483,7 @@ static TriggerState initState CCM_OPTIONAL; void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_S) { const trigger_config_s *triggerConfig = &engineConfiguration->trigger; #if EFI_PROD_CODE || defined(__DOXYGEN__) - efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "init t"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "init t"); scheduleMsg(logger, "initializeTriggerShape(%s/%d)", getTrigger_type_e(triggerConfig->type), (int) triggerConfig->type); #endif @@ -676,7 +676,7 @@ static void onFindIndex(TriggerState *state) { uint32_t findTriggerZeroEventIndex(TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S) { #if EFI_PROD_CODE || defined(__DOXYGEN__) - efiAssert(getRemainingStack(chThdSelf()) > 128, "findPos", -1); + efiAssert(getRemainingStack(chThdGetSelfX()) > 128, "findPos", -1); #endif isInitializingTrigger = true; errorDetection.clear(); diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 28045d2667..fa8a4aacf2 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -44,7 +44,7 @@ TriggerShape::TriggerShape() : void TriggerShape::calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE_PARAMETER_S) { #if EFI_PROD_CODE || defined(__DOXYGEN__) - efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "calc s"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "calc s"); #endif trigger_config_s const*triggerConfig = &engineConfiguration->trigger; diff --git a/firmware/hw_layer/accelerometer.cpp b/firmware/hw_layer/accelerometer.cpp index 9b9c36a453..828a2b00d4 100644 --- a/firmware/hw_layer/accelerometer.cpp +++ b/firmware/hw_layer/accelerometer.cpp @@ -6,7 +6,7 @@ */ #include "main.h" -#include "lis302dl.h" +//#include "lis302dl.h" void initAccelerometer(DECLARE_ENGINE_PARAMETER_F) { diff --git a/firmware/hw_layer/adc_inputs.cpp b/firmware/hw_layer/adc_inputs.cpp index 117dada0e5..a05d626bec 100644 --- a/firmware/hw_layer/adc_inputs.cpp +++ b/firmware/hw_layer/adc_inputs.cpp @@ -148,7 +148,7 @@ AdcDevice fastAdc(&adcgrpcfg_fast); void doSlowAdc(void) { - efiAssertVoid(getRemainingStack(chThdSelf())> 32, "lwStAdcSlow"); + efiAssertVoid(getRemainingStack(chThdGetSelfX())> 32, "lwStAdcSlow"); #if EFI_INTERNAL_ADC @@ -156,19 +156,19 @@ void doSlowAdc(void) { will be executed in parallel to the current PWM cycle and will terminate before the next PWM cycle.*/ slowAdc.conversionCount++; - chSysLockFromIsr() + chSysLockFromISR() ; if (ADC_SLOW_DEVICE.state != ADC_READY && ADC_SLOW_DEVICE.state != ADC_COMPLETE && ADC_SLOW_DEVICE.state != ADC_ERROR) { // todo: why and when does this happen? firmwareError(OBD_PCM_Processor_Fault, "ADC slow not ready?"); slowAdc.errorsCount++; - chSysUnlockFromIsr() + chSysUnlockFromISR() ; return; } adcStartConversionI(&ADC_SLOW_DEVICE, &adcgrpcfgSlow, slowAdc.samples, ADC_BUF_DEPTH_SLOW); - chSysUnlockFromIsr() + chSysUnlockFromISR() ; #endif } @@ -179,7 +179,7 @@ static void pwmpcb_slow(PWMDriver *pwmp) { } static void pwmpcb_fast(PWMDriver *pwmp) { - efiAssertVoid(getRemainingStack(chThdSelf())> 32, "lwStAdcFast"); + efiAssertVoid(getRemainingStack(chThdGetSelfX())> 32, "lwStAdcFast"); #if EFI_INTERNAL_ADC (void) pwmp; @@ -188,19 +188,19 @@ static void pwmpcb_fast(PWMDriver *pwmp) { * will be executed in parallel to the current PWM cycle and will * terminate before the next PWM cycle. */ - chSysLockFromIsr() + chSysLockFromISR() ; if (ADC_FAST_DEVICE.state != ADC_READY && ADC_FAST_DEVICE.state != ADC_COMPLETE && ADC_FAST_DEVICE.state != ADC_ERROR) { fastAdc.errorsCount++; // todo: when? why? firmwareError(OBD_PCM_Processor_Fault, "ADC fast not ready?"); - chSysUnlockFromIsr() + chSysUnlockFromISR() ; return; } adcStartConversionI(&ADC_FAST_DEVICE, &adcgrpcfg_fast, fastAdc.samples, ADC_BUF_DEPTH_FAST); - chSysUnlockFromIsr() + chSysUnlockFromISR() ; fastAdc.conversionCount++; #endif @@ -483,7 +483,7 @@ static void setAdcDebugReporting(int value) { static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) { (void) buffer; (void) n; - efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9c"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 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) { diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index 822d2b62fc..ecc2a84ced 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -102,9 +102,10 @@ void appendFast(Logging *logging, const char *text) { logging->linePointer += extraLen; } +// todo: look into chsnprintf once on Chibios 3 static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) { intermediateLoggingBuffer.eos = 0; // reset - efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#1b"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 128, "lowstck#1b"); chvprintf((BaseSequentialStream *) &intermediateLoggingBuffer, fmt, arg); intermediateLoggingBuffer.buffer[intermediateLoggingBuffer.eos] = 0; // need to terminate explicitly append(logging, (char *) intermediateLoggingBufferData); @@ -114,7 +115,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 vappendPrintf(Logging *logging, const char *fmt, va_list arg) { - efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#5b"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 128, "lowstck#5b"); if (!intermediateLoggingBufferInited) { firmwareError(CUSTOM_ERR_6532, "intermediateLoggingBufferInited not inited!"); return; @@ -127,7 +128,7 @@ void vappendPrintf(Logging *logging, const char *fmt, va_list arg) { } void appendPrintf(Logging *logging, const char *fmt, ...) { - efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#4"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 128, "lowstck#4"); va_list ap; va_start(ap, fmt); vappendPrintf(logging, fmt, ap); @@ -252,7 +253,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(getRemainingStack(chThdSelf()) > 128, "lowstck#5o"); + efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 128, "lowstck#5o"); // resetLogging(logging); // I guess 'reset' is not needed here? appendMsgPrefix(logger); diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 8e96c74d07..c30bef1785 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -5,8 +5,8 @@ UTILSRC = $(PROJECT_DIR)/util/crc.c \ $(PROJECT_DIR)/util/histogram.c UTILSRC_CPP = $(PROJECT_DIR)/util/cyclic_buffer.cpp \ - $(PROJECT_DIR)/console_util/datalogging.cpp \ - $(PROJECT_DIR)/console_util/loggingcentral.cpp \ + $(PROJECT_DIR)/util/datalogging.cpp \ + $(PROJECT_DIR)/util/loggingcentral.cpp \ $(PROJECT_DIR)/util/listener_array.cpp \ $(PROJECT_DIR)/util/cli_registry.cpp \ $(PROJECT_DIR)/util/efilib.cpp \ diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 8388d37f15..9c437361e4 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -18,11 +18,11 @@ extern int timeNow; extern EnginePins enginePins; extern EventQueue schedulingQueue; -extern int warningCounter; +extern int unitTestWarningCounter; EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persistentConfig) { ec = &persistentConfig.engineConfiguration; - warningCounter = 0; + unitTestWarningCounter = 0; schedulingQueue.clear(); enginePins.reset(); diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 1598aa35d2..215a229465 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -35,7 +35,7 @@ extern int timeNow; extern float unitTestValue; extern float testMafValue; -extern int warningCounter; +extern int unitTestWarningCounter; extern bool printTriggerDebug; extern float actualSynchGap; @@ -1240,7 +1240,7 @@ void testMissedSpark299(void) { engineConfiguration->isIgnitionEnabled = true; engineConfiguration->isInjectionEnabled = false; - assertEqualsM("warningCounter#0", 4, warningCounter); + assertEqualsM("warningCounter#0", 4, unitTestWarningCounter); timeNow += MS2US(20); eth.firePrimaryTriggerRise(); @@ -1311,5 +1311,5 @@ void testMissedSpark299(void) { eth.firePrimaryTriggerFall(); schedulingQueue.executeAll(timeNow); - assertEqualsM("warningCounter#1", 5, warningCounter); + assertEqualsM("warningCounter#1", 5, unitTestWarningCounter); }