auto-sync

This commit is contained in:
rusEfi 2014-11-08 10:09:38 -06:00
parent 2622e880c0
commit 64d3677827
11 changed files with 94 additions and 62 deletions

View File

@ -148,10 +148,9 @@ extern "C"
const char *getPinName(io_pin_e io_pin); const char *getPinName(io_pin_e io_pin);
io_pin_e getPinByName(const char *name); io_pin_e getPinByName(const char *name);
void turnOutputPinOn(io_pin_e pin);
void turnOutputPinOff(io_pin_e pin);
void setDefaultPinState(io_pin_e pin, pin_output_mode_e *defaultState);
void setDefaultPinState(io_pin_e pin, pin_output_mode_e *defaultState);
void turnAllPinsOff(void);
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

@ -25,9 +25,6 @@ extern int main_loop_started;
const char *dbg_panic_file; const char *dbg_panic_file;
int dbg_panic_line; int dbg_panic_line;
static void turnAllPinsOff(void) {
}
void chDbgPanic3(const char *msg, const char * file, int line) { void chDbgPanic3(const char *msg, const char * file, int line) {
if (hasFatalError()) if (hasFatalError())
return; return;
@ -41,10 +38,10 @@ void chDbgPanic3(const char *msg, const char * file, int line) {
* low-level function is used here to reduce stack usage * low-level function is used here to reduce stack usage
*/ */
palWritePad(LED_ERROR_PORT, LED_ERROR_PIN, 1); palWritePad(LED_ERROR_PORT, LED_ERROR_PIN, 1);
turnAllPinsOff();
#if EFI_HD44780_LCD #if EFI_HD44780_LCD
lcdShowFatalMessage((char *) msg); lcdShowFatalMessage((char *) msg);
#endif /* EFI_HD44780_LCD */ #endif /* EFI_HD44780_LCD */
turnAllPinsOff();
if (!main_loop_started) { if (!main_loop_started) {
print("fatal %s %s:%d\r\n", msg, file, line); print("fatal %s %s:%d\r\n", msg, file, line);

View File

@ -93,9 +93,9 @@ static void runBench(brain_pin_e brainPin, io_pin_e pin, float delayMs, float on
isRunningBench = true; isRunningBench = true;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
setOutputPinValue(pin, TRUE); setOutputPinValue(pin, true);
chThdSleep((int) (onTimeMs * CH_FREQUENCY / 1000)); chThdSleep((int) (onTimeMs * CH_FREQUENCY / 1000));
setOutputPinValue(pin, FALSE); setOutputPinValue(pin, false);
int offTimeSt = (int) (offTimeMs * CH_FREQUENCY / 1000); int offTimeSt = (int) (offTimeMs * CH_FREQUENCY / 1000);
if (offTimeSt > 0) { if (offTimeSt > 0) {
chThdSleep(offTimeSt); chThdSleep(offTimeSt);

View File

@ -29,6 +29,7 @@
#include "io_pins.h" #include "io_pins.h"
#include "malfunction_central.h" #include "malfunction_central.h"
#include "malfunction_indicator.h" #include "malfunction_indicator.h"
#include "efiGpio.h"
#if EFI_MALFUNCTION_INDICATOR #if EFI_MALFUNCTION_INDICATOR

View File

@ -17,44 +17,15 @@ int getOutputPinValue(io_pin_e pin) {
return getLogicPinValue(&outputs[pin]); return getLogicPinValue(&outputs[pin]);
} }
int getLogicPinValue(OutputPin * outputPin) {
return outputPin->currentLogicValue;
}
/** /**
* @return 0 for OM_DEFAULT and OM_OPENDRAIN * This is used from fatal error handler so it's a macro to be sure that stack is not used
*/ */
inline static int getElectricalValue0(pin_output_mode_e mode) {
return mode == OM_INVERTED || mode == OM_OPENDRAIN_INVERTED;
}
/**
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
*/
inline static int getElectricalValue1(pin_output_mode_e mode) {
return mode == OM_DEFAULT || mode == OM_OPENDRAIN;
}
int getElectricalValue(int logicalValue, pin_output_mode_e mode) { int getElectricalValue(int logicalValue, pin_output_mode_e mode) {
efiAssert(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e", -1); efiAssert(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e", -1);
return logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode); return logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode);
} }
/**
* Set's the value of the pin. On this layer the value is assigned as is, without any conversion.
*/
void setPinValue(OutputPin * outputPin, int electricalValue, int logicValue) {
if (getLogicPinValue(outputPin) == logicValue)
return;
#if EFI_PROD_CODE
palWritePad(outputPin->port, outputPin->pin, electricalValue);
#endif
outputPin->currentLogicValue = logicValue;
}
/** /**
* @brief Sets the value according to current electrical settings * @brief Sets the value according to current electrical settings
*/ */

View File

@ -25,17 +25,56 @@ typedef struct {
int currentLogicValue; int currentLogicValue;
} OutputPin; } OutputPin;
/**
* it's a macro to be sure that stack is not used
* @return 0 for OM_DEFAULT and OM_OPENDRAIN
*/
#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
/**
* it's a macro to be sure that stack is not used
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
*/
#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
#define getLogicPinValue(outputPin) ((outputPin)->currentLogicValue)
/**
* Sets the value of the pin. On this layer the value is assigned as is, without any conversion.
*/
#if EFI_PROD_CODE \
#define setPinValue(outputPin, electricalValue, logicValue) \
{ \
if (getLogicPinValue(outputPin) != (logicValue)) { \
palWritePad((outputPin)->port, (outputPin)->pin, (electricalValue)); \
(outputPin)->currentLogicValue = (logicValue); \
} \
}
#else /* EFI_PROD_CODE */
#define setPinValue(outputPin, electricalValue, logicValue) \
{ \
if (getLogicPinValue(outputPin) != (logicValue)) { \
(outputPin)->currentLogicValue = (logicValue); \
} \
}
#endif /* EFI_PROD_CODE */
#define turnOutputPinOn(pin) setOutputPinValue((pin), true)
#define turnOutputPinOff(pin) setOutputPinValue((pin), false)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
int getLogicPinValue(OutputPin * outputPin);
int getOutputPinValue(io_pin_e pin); int getOutputPinValue(io_pin_e pin);
int getElectricalValue(int logicalValue, pin_output_mode_e mode); int getElectricalValue(int logicalValue, pin_output_mode_e mode);
void setOutputPinValue(io_pin_e pin, int logicValue); void setOutputPinValue(io_pin_e pin, int logicValue);
bool isPinAssigned(io_pin_e pin); bool isPinAssigned(io_pin_e pin);
void setPinValue(OutputPin * outputPin, int electricalValue, int logicValue);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -9,6 +9,7 @@
#include <board.h> #include <board.h>
#include "main.h" #include "main.h"
#include "io_pins.h" #include "io_pins.h"
#include "efiGpio.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "gpio_helper.h" #include "gpio_helper.h"
@ -33,14 +34,6 @@ static GPIO_TypeDef *PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG
static pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT; static pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT;
void turnOutputPinOn(io_pin_e pin) {
setOutputPinValue(pin, TRUE);
}
void turnOutputPinOff(io_pin_e pin) {
setOutputPinValue(pin, FALSE);
}
inline static void assertOMode(pin_output_mode_e mode) { inline static void assertOMode(pin_output_mode_e mode) {
// mode >= 0 is always true since that's an unsigned // mode >= 0 is always true since that's an unsigned
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e");
@ -201,3 +194,24 @@ void initOutputPins(void) {
addConsoleActionS("get_pin_value", getPinValue); addConsoleActionS("get_pin_value", getPinValue);
} }
static io_pin_e TO_BE_TURNED_OFF_ON_ERROR[] = { SPARKOUT_1_OUTPUT, SPARKOUT_2_OUTPUT, SPARKOUT_3_OUTPUT,
SPARKOUT_4_OUTPUT, SPARKOUT_5_OUTPUT, SPARKOUT_6_OUTPUT, SPARKOUT_7_OUTPUT, SPARKOUT_8_OUTPUT,
SPARKOUT_9_OUTPUT, SPARKOUT_10_OUTPUT, SPARKOUT_11_OUTPUT, SPARKOUT_12_OUTPUT,
INJECTOR_1_OUTPUT, INJECTOR_2_OUTPUT, INJECTOR_3_OUTPUT, INJECTOR_4_OUTPUT, INJECTOR_5_OUTPUT,
INJECTOR_6_OUTPUT, INJECTOR_7_OUTPUT, INJECTOR_8_OUTPUT, INJECTOR_9_OUTPUT, INJECTOR_10_OUTPUT,
INJECTOR_11_OUTPUT, INJECTOR_12_OUTPUT, FUEL_PUMP_RELAY };
/**
* This method is part of fatal error handling.
* Please note that worst case scenario the pins might get re-enabled by some other code :(
* The whole method is pretty naive, but that's at least something.
*/
void turnAllPinsOff(void) {
int l = sizeof(TO_BE_TURNED_OFF_ON_ERROR) / sizeof(io_pin_e);
for (int i = 0; i < l; i++) {
turnOutputPinOff(l);
}
}

View File

@ -16,6 +16,8 @@ void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress);
extern stkalign_t __main_stack_base__; extern stkalign_t __main_stack_base__;
#define GET_CFSR() (*((volatile uint32_t *) (0xE000ED28)))
#if defined __GNUC__ #if defined __GNUC__
// GCC version // GCC version
@ -42,8 +44,8 @@ int getRemainingStack(Thread *otp) {
#else /* __GNUC__ */ #else /* __GNUC__ */
extern uint32_t CSTACK$$Base; /* symbol created by the IAR linker */ extern uint32_t CSTACK$$Base; /* symbol created by the IAR linker */
extern uint32_t IRQSTACK$$Base; /* symbol created by the IAR linker */ extern uint32_t IRQSTACK$$Base; /* symbol created by the IAR linker */
int getRemainingStack(Thread *otp) { int getRemainingStack(Thread *otp) {
#if CH_DBG_ENABLE_STACK_CHECK || defined(__DOXYGEN__) #if CH_DBG_ENABLE_STACK_CHECK || defined(__DOXYGEN__)
@ -134,7 +136,7 @@ void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress) {
postmortem_psr = pulFaultStackAddress[7]; postmortem_psr = pulFaultStackAddress[7];
/* Configurable Fault Status Register. Consists of MMSR, BFSR and UFSR */ /* Configurable Fault Status Register. Consists of MMSR, BFSR and UFSR */
postmortem_CFSR = (*((volatile uint32_t *) (0xE000ED28))); postmortem_CFSR = GET_CFSR();
/* Hard Fault Status Register */ /* Hard Fault Status Register */
postmortem_HFSR = (*((volatile uint32_t *) (0xE000ED2C))); postmortem_HFSR = (*((volatile uint32_t *) (0xE000ED2C)));
@ -177,13 +179,20 @@ void HardFaultVector(void) {
" bx r2 \n" " bx r2 \n"
" handler2_address_const: .word prvGetRegistersFromStack \n" " handler2_address_const: .word prvGetRegistersFromStack \n"
); );
#else #else
#endif #endif
chDbgPanic3("HardFaultVector", __FILE__, __LINE__); int cfsr = GET_CFSR();
if (cfsr & 0x100) {
chDbgPanic3("H IBUSERR", __FILE__, __LINE__);
} else if (cfsr & 0x20000) {
chDbgPanic3("H INVSTATE", __FILE__, __LINE__);
} else {
chDbgPanic3("HardFaultVector", __FILE__, __LINE__);
}
while (TRUE) { while (TRUE) {
} }
} }

View File

@ -235,10 +235,12 @@ bool hasFirmwareError(void) {
return hasFirmwareErrorFlag; return hasFirmwareErrorFlag;
} }
// 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); setOutputPinValue(LED_ERROR, 1);
turnAllPinsOff();
hasFirmwareErrorFlag = TRUE; hasFirmwareErrorFlag = TRUE;
firmwareErrorMessageStream.eos = 0; // reset firmwareErrorMessageStream.eos = 0; // reset
va_list ap; va_list ap;

View File

@ -1,5 +1,5 @@
// This file was generated by Version2Header // This file was generated by Version2Header
// Tue Nov 04 16:07:39 EST 2014 // Sat Nov 08 10:29:01 EST 2014
#ifndef VCS_VERSION #ifndef VCS_VERSION
#define VCS_VERSION "5101" #define VCS_VERSION "5226"
#endif #endif

View File

@ -29,7 +29,7 @@ int minI(int i1, int i2) {
} }
float efiRound(float value, float precision) { float efiRound(float value, float precision) {
int a = (int)(value / precision); int a = (int) (value / precision);
return a * precision; return a * precision;
} }
@ -55,11 +55,11 @@ uint32_t efiStrlen(const char *param) {
bool startsWith(const char *line, const char *prefix) { bool startsWith(const char *line, const char *prefix) {
uint32_t len = efiStrlen(prefix); uint32_t len = efiStrlen(prefix);
if(efiStrlen(line) < len) { if (efiStrlen(line) < len) {
return false; return false;
} }
for(int i =0;i<len;i++) { for (uint32_t i = 0; i < len; i++) {
if(line[i]!=prefix[i]) { if (line[i] != prefix[i]) {
return false; return false;
} }
} }