refactoring - reducing GPIO complexity

This commit is contained in:
rusefi 2017-04-21 19:23:20 -04:00
parent 2da6e4f4a4
commit 85778e6bf2
8 changed files with 63 additions and 64 deletions

View File

@ -51,53 +51,6 @@ void initSignalExecutor(void) {
initSignalExecutorImpl(); initSignalExecutorImpl();
} }
void turnPinHigh(NamedOutputPin *output) {
efiAssertVoid(output!=NULL, "NULL @ turnPinHigh");
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
// signal->hi_time = hTimeNow();
#endif /* EFI_DEFAILED_LOGGING */
// turn the output level ACTIVE
output->setValue(true);
// sleep for the needed duration
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
// explicit check here is a performance optimization to speed up no-chart mode
if (ENGINE(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
const char *pinName = output->name;
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
addEngineSniffferEvent(pinName, WC_UP);
}
#endif /* EFI_ENGINE_SNIFFER */
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
}
void turnPinLow(NamedOutputPin *output) {
efiAssertVoid(output!=NULL, "NULL turnPinLow");
// turn off the output
output->setValue(false);
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
systime_t after = hTimeNow();
debugInt(&signal->logging, "a_time", after - signal->hi_time);
scheduleLogging(&signal->logging);
#endif /* EFI_DEFAILED_LOGGING */
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
if (ENGINE(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
const char *pinName = output->name;
addEngineSniffferEvent(pinName, WC_DOWN);
}
#endif /* EFI_ENGINE_SNIFFER */
}
#if FUEL_MATH_EXTREME_LOGGING #if FUEL_MATH_EXTREME_LOGGING
extern LoggingWithStorage sharedLogger; extern LoggingWithStorage sharedLogger;
#endif /* FUEL_MATH_EXTREME_LOGGING */ #endif /* FUEL_MATH_EXTREME_LOGGING */

View File

@ -101,7 +101,7 @@ static void startAveraging(void *arg) {
if (!wasLocked) if (!wasLocked)
chSysUnlockFromISR() chSysUnlockFromISR()
; ;
turnPinHigh(&mapAveragingPin); mapAveragingPin.setHigh();
} }
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
@ -167,7 +167,7 @@ static void endAveraging(void *arg) {
if (!wasLocked) if (!wasLocked)
chSysUnlockFromISR() chSysUnlockFromISR()
; ;
turnPinLow(&mapAveragingPin); mapAveragingPin.setLow();
} }
/** /**

View File

@ -16,6 +16,11 @@
EXTERN_ENGINE; EXTERN_ENGINE;
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
#include "engine_sniffer.h"
extern WaveChart waveChart;
#endif /* EFI_ENGINE_SNIFFER */
// todo: clean this mess, this should become 'static'/private // todo: clean this mess, this should become 'static'/private
EnginePins enginePins; EnginePins enginePins;
extern LoggingWithStorage sharedLogger; extern LoggingWithStorage sharedLogger;
@ -91,6 +96,48 @@ NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
this->name = name; this->name = name;
} }
void NamedOutputPin::setHigh() {
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
// signal->hi_time = hTimeNow();
#endif /* EFI_DEFAILED_LOGGING */
// turn the output level ACTIVE
setValue(true);
// sleep for the needed duration
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
// explicit check here is a performance optimization to speed up no-chart mode
if (ENGINE(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
const char *pinName = name;
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
addEngineSniffferEvent(pinName, WC_UP);
}
#endif /* EFI_ENGINE_SNIFFER */
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
}
void NamedOutputPin::setLow() {
// turn off the output
setValue(false);
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
systime_t after = hTimeNow();
debugInt(&signal->logging, "a_time", after - signal->hi_time);
scheduleLogging(&signal->logging);
#endif /* EFI_DEFAILED_LOGGING */
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
if (ENGINE(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
const char *pinName = name;
addEngineSniffferEvent(pinName, WC_DOWN);
}
#endif /* EFI_ENGINE_SNIFFER */
}
InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() { InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() {
reset(); reset();
injectorIndex = -1; injectorIndex = -1;

View File

@ -54,6 +54,8 @@ class NamedOutputPin : public OutputPin {
public: public:
NamedOutputPin(); NamedOutputPin();
NamedOutputPin(const char *name); NamedOutputPin(const char *name);
void setHigh();
void setLow();
/** /**
* @return true if pin was stopped * @return true if pin was stopped
*/ */
@ -141,9 +143,6 @@ public:
#define isPinAssigned(output) (true) #define isPinAssigned(output) (true)
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
void turnPinHigh(NamedOutputPin *output);
void turnPinLow(NamedOutputPin *output);
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__) #if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
ioportmask_t getHwPin(brain_pin_e brainPin); ioportmask_t getHwPin(brain_pin_e brainPin);

View File

@ -18,7 +18,7 @@ EXTERN_ENGINE;
static scheduling_s tachTurnSignalOff; static scheduling_s tachTurnSignalOff;
static void turnTachPinLow(void) { static void turnTachPinLow(void) {
turnPinLow(&enginePins.tachOut); enginePins.tachOut.setLow();
} }
static void tachSignalCallback(trigger_event_e ckpSignalType, static void tachSignalCallback(trigger_event_e ckpSignalType,
@ -26,7 +26,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType,
if (index != engineConfiguration->tachPulseTriggerIndex) { if (index != engineConfiguration->tachPulseTriggerIndex) {
return; return;
} }
turnPinHigh(&enginePins.tachOut); enginePins.tachOut.setHigh();
scheduleTask(false, "tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL); scheduleTask(false, "tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL);
} }

View File

@ -85,7 +85,7 @@ static void startSimultaniousInjection(InjectionEvent *event) {
Engine *engine = event->engine; Engine *engine = event->engine;
#endif #endif
for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) {
turnPinHigh(&enginePins.injectors[i]); enginePins.injectors[i].setHigh();
} }
} }
@ -95,7 +95,7 @@ static void endSimultaniousInjection(InjectionEvent *event) {
EXPAND_Engine; EXPAND_Engine;
#endif #endif
for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) {
turnPinLow(&enginePins.injectors[i]); enginePins.injectors[i].setLow();
} }
engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER); engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER);
} }
@ -129,7 +129,7 @@ static void tempTurnPinHigh(InjectorOutputPin *output) {
// getRevolutionCounter(), getTimeNowUs()); // getRevolutionCounter(), getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */ #endif /* FUEL_MATH_EXTREME_LOGGING */
turnPinHigh(output); output->setHigh();
} }
// todo: make these macro? kind of a penny optimization if compiler is not smart to inline // todo: make these macro? kind of a penny optimization if compiler is not smart to inline
@ -178,7 +178,7 @@ static void tempTurnPinLow(InjectorOutputPin *output) {
#endif /* FUEL_MATH_EXTREME_LOGGING */ #endif /* FUEL_MATH_EXTREME_LOGGING */
return; return;
} }
turnPinLow(output); output->setLow();
} }
void seTurnPinLow(OutputSignalPair *pair) { void seTurnPinLow(OutputSignalPair *pair) {

View File

@ -53,10 +53,10 @@ static void turnSparkPinLow2(IgnitionEvent *event, IgnitionOutputPin *output) {
output->outOfOrder = true; output->outOfOrder = true;
} }
turnPinLow(output); output->setLow();
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) { if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) {
turnPinLow(&enginePins.dizzyOutput); enginePins.dizzyOutput.setLow();
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
} }
@ -102,10 +102,10 @@ static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) {
} }
} }
turnPinHigh(output); output->setHigh();
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) { if (CONFIG(dizzySparkOutputPin) != GPIO_UNASSIGNED) {
turnPinHigh(&enginePins.dizzyOutput); enginePins.dizzyOutput.setHigh();
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
} }

View File

@ -213,7 +213,7 @@ static void startIntegration(void) {
* until we are done integrating * until we are done integrating
*/ */
state = IS_INTEGRATING; state = IS_INTEGRATING;
turnPinHigh(&intHold); intHold.setHigh();
} }
} }
@ -223,7 +223,7 @@ static void endIntegration(void) {
* engine cycle * engine cycle
*/ */
if (state == IS_INTEGRATING) { if (state == IS_INTEGRATING) {
turnPinLow(&intHold); intHold.setLow();
state = WAITING_FOR_ADC_TO_SKIP; state = WAITING_FOR_ADC_TO_SKIP;
} }
} }