Merge remote-tracking branch 'origin/master' into master

This commit is contained in:
rusefillc 2020-12-10 19:38:44 -05:00
commit d26381d6c1
2 changed files with 23 additions and 40 deletions

View File

@ -148,14 +148,6 @@ EnginePins::EnginePins() :
*/ */
#if EFI_PROD_CODE #if EFI_PROD_CODE
#define setPinValue(outputPin, electricalValue, logicValue) \
{ \
if ((outputPin)->currentLogicValue != (logicValue)) { \
palWritePad((outputPin)->port, (outputPin)->pin, (electricalValue)); \
(outputPin)->currentLogicValue = (logicValue); \
} \
}
#define unregisterOutputIfPinChanged(output, pin) { \ #define unregisterOutputIfPinChanged(output, pin) { \
if (isConfigurationChanged(pin)) { \ if (isConfigurationChanged(pin)) { \
(output).unregisterOutput(activeConfiguration.pin); \ (output).unregisterOutput(activeConfiguration.pin); \
@ -168,15 +160,6 @@ EnginePins::EnginePins() :
} \ } \
} }
#else /* EFI_PROD_CODE */
#define setPinValue(outputPin, electricalValue, logicValue) \
{ \
if ((outputPin)->currentLogicValue != (logicValue)) { \
(outputPin)->currentLogicValue = (logicValue); \
} \
setMockState((outputPin)->brainPin, logicValue); \
}
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
bool EnginePins::stopPins() { bool EnginePins::stopPins() {
@ -400,16 +383,13 @@ bool OutputPin::getAndSet(int logicValue) {
return oldValue; return oldValue;
} }
void OutputPin::setOnchipValue(int electricalValue, int logicValue) { // This function is only used on real hardware
#if EFI_PROD_CODE #if EFI_PROD_CODE
if (port != GPIO_NULL) { void OutputPin::setOnchipValue(int electricalValue) {
setPinValue(this, electricalValue, logicValue); palWritePad(port, pin, electricalValue);
} else {
// even without physical pin sometimes it's nice to track logic pin value
currentLogicValue = logicValue;
}
#endif // EFI_PROD_CODE
} }
#endif // EFI_PROD_CODE
void OutputPin::setValue(int logicValue) { void OutputPin::setValue(int logicValue) {
#if ENABLE_PERF_TRACE #if ENABLE_PERF_TRACE
@ -425,24 +405,26 @@ void OutputPin::setValue(int logicValue) {
#if (BOARD_EXT_GPIOCHIPS > 0) #if (BOARD_EXT_GPIOCHIPS > 0)
if (!this->ext) { if (!this->ext) {
setOnchipValue(electricalValue, logicValue); setOnchipValue(electricalValue);
} else { } else {
/* external pin */ /* external pin */
gpiochips_writePad(this->brainPin, logicValue); gpiochips_writePad(this->brainPin, logicValue);
/* TODO: check return value */ /* TODO: check return value */
currentLogicValue = logicValue;
} }
#else #else
setOnchipValue(electricalValue, logicValue); setOnchipValue(electricalValue);
#endif #endif
#else /* EFI_PROD_CODE */ #else /* EFI_PROD_CODE */
setPinValue(this, eValue, logicValue); setMockState(brainPin, logicValue);
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
// Lastly store the current logical value of the pin
currentLogicValue = logicValue;
} }
bool OutputPin::getLogicValue() const { bool OutputPin::getLogicValue() const {
// Compare against 1 since it could also be INITIAL_PIN_STATE (which means 0, but we haven't initialized the pin yet) // Compare against 1 since it could also be INITIAL_PIN_STATE (which means logical 0, but we haven't initialized the pin yet)
return currentLogicValue == 1; return currentLogicValue == 1;
} }
@ -535,8 +517,6 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_
} }
#endif #endif
this->currentLogicValue = 0;
#endif // briefly leave the include guard because we need to set default state in tests #endif // briefly leave the include guard because we need to set default state in tests
// The order of the next two calls may look strange, which is a good observation. // The order of the next two calls may look strange, which is a good observation.
@ -550,18 +530,21 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_
if (brain_pin_is_onchip(brainPin)) { if (brain_pin_is_onchip(brainPin)) {
int actualValue = palReadPad(port, pin); int actualValue = palReadPad(port, pin);
// we had enough drama with pin configuration in board.h and else that we shall self-check // we had enough drama with pin configuration in board.h and else that we shall self-check
// todo: handle OM_OPENDRAIN and OM_OPENDRAIN_INVERTED as well // todo: handle OM_OPENDRAIN and OM_OPENDRAIN_INVERTED as well
if (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) { if (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) {
if (*outputMode == OM_INVERTED) { const int logicalValue =
actualValue = !actualValue; (*outputMode == OM_INVERTED)
} ? !actualValue
if (actualValue) { : actualValue;
// todo: https://github.com/rusefi/rusefi/issues/2006
// firmwareError(OBD_PCM_Processor_Fault, "%s: startup pin state %s value=%d mode=%s", msg, hwPortname(brainPin), actualValue, getPin_output_mode_e(*outputMode)); // if the pin was set to logical 1, then set an error and disable the pin so that things don't catch fire
if (logicalValue) {
efiSetPadUnused(brainPin);
firmwareError(OBD_PCM_Processor_Fault, "%s: startup pin state %s actual value=%d logical value=%d mode=%s", msg, hwPortname(brainPin), actualValue, logicalValue, getPin_output_mode_e(*outputMode));
} }
} }
} }
#endif /* EFI_GPIO_HARDWARE */ #endif /* EFI_GPIO_HARDWARE */
} }

View File

@ -82,7 +82,7 @@ public:
private: private:
// todo: inline this method? // todo: inline this method?
void setDefaultPinState(const pin_output_mode_e *defaultState); void setDefaultPinState(const pin_output_mode_e *defaultState);
void setOnchipValue(int electricalValue, int logicValue); void setOnchipValue(int electricalValue);
// 4 byte pointer is a bit of a memory waste here // 4 byte pointer is a bit of a memory waste here
const pin_output_mode_e *modePtr; const pin_output_mode_e *modePtr;