auto-sync

This commit is contained in:
rusEfi 2015-01-07 17:04:40 -06:00
parent be30fedb74
commit 2de4b7e839
12 changed files with 67 additions and 60 deletions

View File

@ -65,6 +65,8 @@
#include "vehicle_speed.h" #include "vehicle_speed.h"
#endif #endif
extern OutputPin outputs[IO_PIN_COUNT];
// this 'true' value is needed for simulator // this 'true' value is needed for simulator
static volatile bool fullLog = true; static volatile bool fullLog = true;
int warningEnabled = true; int warningEnabled = true;
@ -350,8 +352,11 @@ static THD_WORKING_AREA(lcdThreadStack, UTILITY_THREAD_STACK_SIZE);
*/ */
static THD_WORKING_AREA(comBlinkingStack, UTILITY_THREAD_STACK_SIZE); static THD_WORKING_AREA(comBlinkingStack, UTILITY_THREAD_STACK_SIZE);
static io_pin_e leds[] = { LED_WARNING, LED_RUNNING, LED_ERROR, LED_COMMUNICATION_1, LED_DEBUG, LED_EXT_1, static OutputPin *leds[] = { &outputs[(int)LED_WARNING], &outputs[(int)LED_RUNNING],
LED_CHECK_ENGINE }; &outputs[(int)LED_ERROR],
&outputs[(int)LED_COMMUNICATION_1],
&outputs[(int)LED_EXT_1],
&outputs[(int)LED_CHECK_ENGINE] };
/** /**
* This method would blink all the LEDs just to test them * This method would blink all the LEDs just to test them
@ -359,12 +364,12 @@ static io_pin_e leds[] = { LED_WARNING, LED_RUNNING, LED_ERROR, LED_COMMUNICATIO
static void initialLedsBlink(void) { static void initialLedsBlink(void) {
int size = sizeof(leds) / sizeof(leds[0]); int size = sizeof(leds) / sizeof(leds[0]);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
setOutputPinValue(leds[i], 1); leds[i]->setValue(1);
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
setOutputPinValue(leds[i], 0); leds[i]->setValue(0);
} }
/** /**
@ -388,16 +393,12 @@ static void comBlinkingThread(void *arg) {
delay = isConsoleReady() ? 100 : 33; delay = isConsoleReady() ? 100 : 33;
} }
setOutputPinValue(LED_COMMUNICATION_1, 0); outputs[(int)LED_COMMUNICATION_1].setValue(0);
setOutputPinValue(LED_EXT_1, 1); outputs[(int)LED_EXT_1].setValue(1);
// setOutputPinValue(LED_EXT_2, 1);
// setOutputPinValue(LED_EXT_3, 1);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
setOutputPinValue(LED_COMMUNICATION_1, 1); outputs[(int)LED_COMMUNICATION_1].setValue(1);
setOutputPinValue(LED_EXT_1, 0); outputs[(int)LED_EXT_1].setValue(0);
// setOutputPinValue(LED_EXT_2, 0);
// setOutputPinValue(LED_EXT_3, 0);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
} }
} }
@ -409,9 +410,9 @@ static void errBlinkingThread(void *arg) {
while (TRUE) { while (TRUE) {
int delay = 33; int delay = 33;
if (isTriggerDecoderError() || isIgnitionTimingError()) if (isTriggerDecoderError() || isIgnitionTimingError())
setOutputPinValue(LED_WARNING, 1); outputs[(int)LED_WARNING].setValue(1);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
setOutputPinValue(LED_WARNING, 0); outputs[(int)LED_WARNING].setValue(0);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
} }
#endif /* EFI_ENGINE_CONTROL */ #endif /* EFI_ENGINE_CONTROL */

View File

@ -82,7 +82,6 @@ typedef enum {
TRIGGER_EMULATOR_SECONDARY, TRIGGER_EMULATOR_SECONDARY,
TRIGGER_EMULATOR_3RD, TRIGGER_EMULATOR_3RD,
ELECTRONIC_THROTTLE_CONTROL_1, ELECTRONIC_THROTTLE_CONTROL_1,
ELECTRONIC_THROTTLE_CONTROL_2, ELECTRONIC_THROTTLE_CONTROL_2,
ELECTRONIC_THROTTLE_CONTROL_3, ELECTRONIC_THROTTLE_CONTROL_3,
@ -120,7 +119,7 @@ typedef enum {
// malfunction LED indicator - CheckEngine // malfunction LED indicator - CheckEngine
LED_CHECK_ENGINE, LED_CHECK_ENGINE,
FUEL_PUMP_RELAY, FUEL_PUMP_RELAY,
FAN_RELAY, FAN_RELAY,
O2_HEATER, O2_HEATER,
@ -137,8 +136,6 @@ typedef enum {
MAIN_RELAY, MAIN_RELAY,
/** /**
* This output pin is used to turn alternator on or off * This output pin is used to turn alternator on or off
*/ */
@ -152,17 +149,15 @@ void initPrimaryPins(void);
void initOutputPins(void); void initOutputPins(void);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif /* __cplusplus */ #endif /* __cplusplus */
io_pin_e getPinByName(const char *name); io_pin_e getPinByName(const char *name);
void setDefaultPinState(io_pin_e pin, pin_output_mode_e *defaultState);
#if EFI_GPIO #if EFI_GPIO
void turnAllPinsOff(void); void turnAllPinsOff(void);
#else #else
#define turnAllPinsOff() {} #define turnAllPinsOff() {}
#endif #endif
void outputPinRegisterExt2(const char *msg, io_pin_e ioPin, brain_pin_e brainPin, pin_output_mode_e *outputMode); void outputPinRegisterExt2(const char *msg, io_pin_e ioPin, brain_pin_e brainPin, pin_output_mode_e *outputMode);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -107,13 +107,13 @@ static msg_t csThread(void) {
int is_running = rpm > 0 && !is_cranking; int is_running = rpm > 0 && !is_cranking;
if (is_running) { if (is_running) {
// blinking while running // blinking while running
setOutputPinValue(LED_RUNNING, 0); outputs[(int)LED_RUNNING].setValue(0);
chThdSleepMilliseconds(50); chThdSleepMilliseconds(50);
setOutputPinValue(LED_RUNNING, 1); outputs[(int)LED_RUNNING].setValue(1);
chThdSleepMilliseconds(50); chThdSleepMilliseconds(50);
} else { } else {
// constant on while cranking and off if engine is stopped // constant on while cranking and off if engine is stopped
setOutputPinValue(LED_RUNNING, is_cranking); outputs[(int)LED_RUNNING].setValue(is_cranking);
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
} }
} }

View File

@ -40,11 +40,13 @@
static THD_WORKING_AREA(mfiThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread static THD_WORKING_AREA(mfiThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread
extern OutputPin outputs[IO_PIN_COUNT];
static void blink_digits(int digit, int duration) { static void blink_digits(int digit, int duration) {
for (int iter = 0; iter < digit; iter++) { for (int iter = 0; iter < digit; iter++) {
turnOutputPinOn(LED_CHECK_ENGINE); outputs[(int)LED_CHECK_ENGINE].setValue(0);
chThdSleepMilliseconds(duration); chThdSleepMilliseconds(duration);
turnOutputPinOff(LED_CHECK_ENGINE); outputs[(int)LED_CHECK_ENGINE].setValue(1);
chThdSleepMilliseconds(MFI_BLINK_SEPARATOR); chThdSleepMilliseconds(MFI_BLINK_SEPARATOR);
} }
} }

View File

@ -97,6 +97,16 @@ void OutputPin::setValue(int logicValue) {
doSetOutputPinValue2(this, logicValue); doSetOutputPinValue2(this, logicValue);
} }
void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) {
#if EFI_GPIO
pin_output_mode_e mode = *outputMode;
assertOMode(mode);
this->modePtr = outputMode;
#endif
setValue(false); // initial state
}
extern uint32_t dbgStart; extern uint32_t dbgStart;
extern uint32_t dbgDurr; extern uint32_t dbgDurr;
/** /**

View File

@ -10,6 +10,11 @@
#include "main.h" #include "main.h"
#include "io_pins.h" #include "io_pins.h"
// mode >= 0 is always true since that's an unsigned
#define assertOMode(mode) { \
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \
}
/** /**
* @brief Single output pin reference and state * @brief Single output pin reference and state
*/ */
@ -17,6 +22,7 @@ class OutputPin {
public: public:
OutputPin(); OutputPin();
void setValue(int logicValue); void setValue(int logicValue);
void setDefaultPinState(pin_output_mode_e *defaultState);
#if EFI_PROD_CODE #if EFI_PROD_CODE
GPIO_TypeDef *port; GPIO_TypeDef *port;
int pin; int pin;

View File

@ -7,7 +7,6 @@ HW_LAYER_EGT_CPP = $(PROJECT_DIR)/hw_layer/can_hw.cpp \
HW_LAYER_EMS = $(HW_LAYER_EGT) \ HW_LAYER_EMS = $(HW_LAYER_EGT) \
$(PROJECT_DIR)/hw_layer/pin_repository.c \ $(PROJECT_DIR)/hw_layer/pin_repository.c \
$(PROJECT_DIR)/hw_layer/mcp3208.c \ $(PROJECT_DIR)/hw_layer/mcp3208.c \
$(PROJECT_DIR)/hw_layer/lcd/lcd_HD44780.c \
$(PROJECT_DIR)/hw_layer/microsecond_timer.c \ $(PROJECT_DIR)/hw_layer/microsecond_timer.c \
$(PROJECT_DIR)/hw_layer/flash.c \ $(PROJECT_DIR)/hw_layer/flash.c \
$(PROJECT_DIR)/hw_layer/rtc_helper.c \ $(PROJECT_DIR)/hw_layer/rtc_helper.c \
@ -17,6 +16,7 @@ HW_LAYER_EMS = $(HW_LAYER_EGT) \
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
$(PROJECT_DIR)/hw_layer/hardware.cpp \ $(PROJECT_DIR)/hw_layer/hardware.cpp \
$(PROJECT_DIR)/hw_layer/lcd/lcd_HD44780.cpp \
$(PROJECT_DIR)/hw_layer/adc_inputs.cpp \ $(PROJECT_DIR)/hw_layer/adc_inputs.cpp \
$(PROJECT_DIR)/hw_layer/board_test.cpp \ $(PROJECT_DIR)/hw_layer/board_test.cpp \
$(PROJECT_DIR)/hw_layer/pwm_generator.cpp \ $(PROJECT_DIR)/hw_layer/pwm_generator.cpp \

View File

@ -35,27 +35,12 @@ static GPIO_TypeDef *PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOF};
pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT; pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT;
inline static void assertOMode(pin_output_mode_e mode) { static void outputPinRegisterExt(const char *msg, OutputPin *output, GPIO_TypeDef *port, uint32_t pin,
// mode >= 0 is always true since that's an unsigned
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e");
}
void setDefaultPinState(io_pin_e pin, pin_output_mode_e *outputMode) {
#if EFI_GPIO
pin_output_mode_e mode = *outputMode;
assertOMode(mode);
outputs[(int)pin].modePtr = outputMode;
outputs[(int)pin].setValue(false); // initial state
#endif
}
static void outputPinRegisterExt(const char *msg, io_pin_e ioPin, GPIO_TypeDef *port, uint32_t pin,
pin_output_mode_e *outputMode) { pin_output_mode_e *outputMode) {
#if EFI_GPIO #if EFI_GPIO
efiAssertVoid((int)ioPin < IO_PIN_COUNT, "io pin out of range");
if (port == GPIO_NULL) { if (port == GPIO_NULL) {
// that's for GRIO_NONE // that's for GRIO_NONE
outputs[ioPin].port = port; output->port = port;
return; return;
} }
@ -64,9 +49,9 @@ static void outputPinRegisterExt(const char *msg, io_pin_e ioPin, GPIO_TypeDef *
PAL_MODE_OUTPUT_PUSHPULL : PAL_MODE_OUTPUT_PUSHPULL :
PAL_MODE_OUTPUT_OPENDRAIN; PAL_MODE_OUTPUT_OPENDRAIN;
initOutputPinExt(msg, &outputs[ioPin], port, pin, mode); initOutputPinExt(msg, output, port, pin, mode);
setDefaultPinState(ioPin, outputMode); output->setDefaultPinState(outputMode);
#endif #endif
} }
@ -96,15 +81,15 @@ void outputPinRegisterExt2(const char *msg, io_pin_e ioPin, brain_pin_e brainPin
GPIO_TypeDef *hwPort = getHwPort(brainPin); GPIO_TypeDef *hwPort = getHwPort(brainPin);
int hwPin = getHwPin(brainPin); int hwPin = getHwPin(brainPin);
outputPinRegisterExt(msg, ioPin, hwPort, hwPin, outputMode); outputPinRegisterExt(msg, &outputs[(int)ioPin], hwPort, hwPin, outputMode);
} }
void outputPinRegister(const char *msg, io_pin_e ioPin, GPIO_TypeDef *port, uint32_t pin) { void outputPinRegister(const char *msg, OutputPin *output, GPIO_TypeDef *port, uint32_t pin) {
outputPinRegisterExt(msg, ioPin, port, pin, &DEFAULT_OUTPUT); outputPinRegisterExt(msg, output, port, pin, &DEFAULT_OUTPUT);
} }
void initPrimaryPins(void) { void initPrimaryPins(void) {
outputPinRegister("LED_ERROR", LED_ERROR, LED_ERROR_PORT, LED_ERROR_PIN); outputPinRegister("LED_ERROR", &outputs[(int)LED_ERROR], LED_ERROR_PORT, LED_ERROR_PIN);
} }
static void getPinValue(const char *name) { static void getPinValue(const char *name) {
@ -121,11 +106,11 @@ void initOutputPins(void) {
initLogging(&logger, "io_pins"); initLogging(&logger, "io_pins");
#if EFI_WARNING_LED #if EFI_WARNING_LED
outputPinRegister("warning", LED_WARNING, LED_WARNING_PORT, LED_WARNING_PIN); outputPinRegister("warning", &outputs[(int)LED_WARNING], LED_WARNING_PORT, LED_WARNING_PIN);
outputPinRegister("is running status", LED_RUNNING, LED_RUNNING_STATUS_PORT, LED_RUNNING_STATUS_PIN); outputPinRegister("is running status", &outputs[(int)LED_RUNNING], LED_RUNNING_STATUS_PORT, LED_RUNNING_STATUS_PIN);
#endif /* EFI_WARNING_LED */ #endif /* EFI_WARNING_LED */
outputPinRegister("communication status 1", LED_COMMUNICATION_1, LED_COMMUNICATION_PORT, LED_COMMUNICATION_PIN); outputPinRegister("communication status 1", &outputs[(int)LED_COMMUNICATION_1], LED_COMMUNICATION_PORT, LED_COMMUNICATION_PIN);
/** /**
* want to make sure it's all zeros so that we can compare in initOutputPinExt() method * want to make sure it's all zeros so that we can compare in initOutputPinExt() method
@ -145,7 +130,7 @@ void initOutputPins(void) {
// outputPinRegister("spi CS3", SPI_CS_3, SPI_CS3_PORT, SPI_CS3_PIN); // outputPinRegister("spi CS3", SPI_CS_3, SPI_CS3_PORT, SPI_CS3_PIN);
// outputPinRegister("spi CS4", SPI_CS_4, SPI_CS4_PORT, SPI_CS4_PIN); // outputPinRegister("spi CS4", SPI_CS_4, SPI_CS4_PORT, SPI_CS4_PIN);
#if HAL_USE_SPI || defined(__DOXYGEN__) #if HAL_USE_SPI || defined(__DOXYGEN__)
outputPinRegister("spi CS5", SPI_CS_SD_MODULE, SPI_SD_MODULE_PORT, SPI_SD_MODULE_PIN); outputPinRegister("spi CS5", &outputs[(int)SPI_CS_SD_MODULE], SPI_SD_MODULE_PORT, SPI_SD_MODULE_PIN);
#endif #endif
// todo: should we move this code closer to the fuel pump logic? // todo: should we move this code closer to the fuel pump logic?

View File

@ -15,6 +15,12 @@
#include "hal.h" #include "hal.h"
#include "io_pins.h" #include "io_pins.h"
#ifdef __cplusplus
#include "efiGpio.h"
// does not exactly belong here, but that works better for tests
void outputPinRegister(const char *msg, OutputPin *output, GPIO_TypeDef *port, uint32_t pin);
#endif /* __cplusplus */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -26,8 +32,6 @@ brain_pin_e parseBrainPin(const char *str);
void mySetPadMode(const char *msg, ioportid_t port, ioportmask_t pin, iomode_t mode); void mySetPadMode(const char *msg, ioportid_t port, ioportmask_t pin, iomode_t mode);
void mySetPadMode2(const char *msg, brain_pin_e pin, iomode_t mode); void mySetPadMode2(const char *msg, brain_pin_e pin, iomode_t mode);
char *portname(GPIO_TypeDef* GPIOx); char *portname(GPIO_TypeDef* GPIOx);
// does not exactly belong here, but that works better for tests
void outputPinRegister(const char *msg, io_pin_e ioPin, GPIO_TypeDef *port, uint32_t pin);
iomode_t getInputMode(pin_input_mode_e mode); iomode_t getInputMode(pin_input_mode_e mode);
ioportmask_t getHwPin(brain_pin_e brainPin); ioportmask_t getHwPin(brain_pin_e brainPin);

View File

@ -48,12 +48,14 @@ void startSimplePwm(PwmConfig *state, const char *msg, io_pin_e ioPin, float fre
weComplexInit(msg, state, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback); weComplexInit(msg, state, 2, switchTimes, 1, pinStates, NULL, stateChangeCallback);
} }
extern OutputPin outputs[IO_PIN_COUNT];
void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, io_pin_e ioPin, float frequency, void startSimplePwmExt(PwmConfig *state, const char *msg, brain_pin_e brainPin, io_pin_e ioPin, float frequency,
float dutyCycle, pwm_gen_callback *stateChangeCallback) { float dutyCycle, pwm_gen_callback *stateChangeCallback) {
GPIO_TypeDef * port = getHwPort(brainPin); GPIO_TypeDef * port = getHwPort(brainPin);
int pin = getHwPin(brainPin); int pin = getHwPin(brainPin);
outputPinRegister(msg, ioPin, port, pin); outputPinRegister(msg, &outputs[ioPin], port, pin);
startSimplePwm(state, msg, ioPin, frequency, dutyCycle, stateChangeCallback); startSimplePwm(state, msg, ioPin, frequency, dutyCycle, stateChangeCallback);
} }

View File

@ -230,11 +230,13 @@ void chDbgStackOverflowPanic(Thread *otp) {
chDbgPanic3(panicMessage, __FILE__, __LINE__); chDbgPanic3(panicMessage, __FILE__, __LINE__);
} }
extern OutputPin outputs[IO_PIN_COUNT];
// todo: why is this method here and not in error_handling.c ? // todo: why is this method here and not in error_handling.c ?
void firmwareError(const char *fmt, ...) { void firmwareError(const char *fmt, ...) {
if (hasFirmwareErrorFlag) if (hasFirmwareErrorFlag)
return; return;
setOutputPinValue(LED_ERROR, 1); outputs[(int)LED_ERROR].setValue(1);
turnAllPinsOff(); turnAllPinsOff();
hasFirmwareErrorFlag = TRUE; hasFirmwareErrorFlag = TRUE;
if (indexOf(fmt, '%') == -1) { if (indexOf(fmt, '%') == -1) {