diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index a73be1a4f2..1ef5cad1a7 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -17,15 +17,6 @@ int getOutputPinValue(io_pin_e pin) { return getLogicPinValue(&outputs[pin]); } -/** - * This is used from fatal error handler so it's a macro to be sure that stack is not used - */ -int getElectricalValue(int logicalValue, pin_output_mode_e mode) { - efiAssert(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e", -1); - - return logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode); -} - /** * @brief Sets the value according to current electrical settings */ @@ -35,10 +26,13 @@ void setOutputPinValue(io_pin_e pin, int logicValue) { return; efiAssertVoid(pinDefaultState[pin]!=NULL, "pin mode not initialized"); pin_output_mode_e mode = *pinDefaultState[pin]; + efiAssert(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e", -1); #else pin_output_mode_e mode = OM_DEFAULT; #endif - setPinValue(&outputs[pin], getElectricalValue(logicValue, mode), logicValue); + OutputPin *output = &outputs[pin]; + int eValue = getElectricalValue(logicValue, mode); + setPinValue(output, eValue, logicValue); } bool isPinAssigned(io_pin_e pin) { diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index dd5574525f..27b1e0d7e8 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -66,13 +66,15 @@ typedef struct { #define turnOutputPinOn(pin) setOutputPinValue((pin), true) #define turnOutputPinOff(pin) setOutputPinValue((pin), false) +#define getElectricalValue(logicalValue, mode) \ + (logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode)) + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ int getOutputPinValue(io_pin_e pin); -int getElectricalValue(int logicalValue, pin_output_mode_e mode); void setOutputPinValue(io_pin_e pin, int logicValue); bool isPinAssigned(io_pin_e pin); diff --git a/firmware/hw_layer/pwm_generator.cpp b/firmware/hw_layer/pwm_generator.cpp index b818ffd358..149669b99b 100644 --- a/firmware/hw_layer/pwm_generator.cpp +++ b/firmware/hw_layer/pwm_generator.cpp @@ -23,10 +23,10 @@ static Logging logger; * This method controls the actual hardware pins */ void applyPinState(PwmConfig *state, int stateIndex) { + efiAssertVoid(stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); efiAssertVoid(state->multiWave.waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount"); for (int waveIndex = 0; waveIndex < state->multiWave.waveCount; waveIndex++) { io_pin_e ioPin = state->outputPins[waveIndex]; - efiAssertVoid(stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); int value = state->multiWave.waves[waveIndex].pinStates[stateIndex]; setOutputPinValue(ioPin, value); } diff --git a/firmware/util/efilib2.cpp b/firmware/util/efilib2.cpp index 0071c76b17..699492430d 100644 --- a/firmware/util/efilib2.cpp +++ b/firmware/util/efilib2.cpp @@ -5,16 +5,8 @@ * @author Andrey Belomutskiy, (c) 2012-2014 */ -#include "main.h" -#if (EFI_PROD_CODE || EFI_SIMULATOR) - #define GET_VALUE() hal_lld_get_counter_value() -#else - #define GET_VALUE() 0 -#endif - #include "efilib2.h" - /** * The main use-case of this class is to keep track of a 64-bit global number of CPU ticks from reset. * @@ -68,7 +60,7 @@ uint64_t Overflow64Counter::get() { /** * We need to take current counter after making a local 64 bit snapshot */ - uint32_t value = GET_VALUE(); + uint32_t value = GET_TIMESTAMP(); if (value < localLow) { // new value less than previous value means there was an overflow in that 32 bit counter diff --git a/firmware/util/efilib2.h b/firmware/util/efilib2.h index 70b7dc233e..375c164845 100644 --- a/firmware/util/efilib2.h +++ b/firmware/util/efilib2.h @@ -28,4 +28,11 @@ class Overflow64Counter State64 state; }; +#include "main.h" +#if (EFI_PROD_CODE || EFI_SIMULATOR) + #define GET_TIMESTAMP() hal_lld_get_counter_value() +#else + #define GET_TIMESTAMP() 0 +#endif + #endif /* EFILIB2_H_ */