auto-sync

This commit is contained in:
rusEfi 2014-09-26 00:02:43 -05:00
parent 3e37f1103b
commit 99394e436a
8 changed files with 61 additions and 14 deletions

View File

@ -16,6 +16,7 @@
* Logical pins. See brain_pin_e for physical pins.
*/
typedef enum {
IO_INVALID,
LED_WARNING, // Orange on-board LED
LED_RUNNING, // Green on-board LED
LED_ERROR, // Red on-board LED
@ -128,6 +129,7 @@ extern "C"
void initPrimaryPins(void);
void initOutputPins(void);
const char *getPinName(io_pin_e io_pin);
io_pin_e getPinByName(const char *name);
void turnOutputPinOn(io_pin_e pin);
void turnOutputPinOff(io_pin_e pin);
void setOutputPinValue(io_pin_e pin, int logicValue);

View File

@ -117,6 +117,14 @@ void scheduleOutput(OutputSignal *signal, float delayMs, float durationMs) {
scheduleTask("out down", sDown, (int)MS2US(delayMs + durationMs), (schfunc_t) &turnPinLow, (void*) signal->io_pin);
}
io_pin_e getPinByName(const char *name) {
if(startsWith(name, "spa")) {
int index = atoi(name + 3);
return (io_pin_e)((int)SPARKOUT_1_OUTPUT - 1 + index);
}
return IO_INVALID;
}
const char *getPinName(io_pin_e io_pin) {
switch (io_pin) {
// todo: refactor this hell - introduce arrays & checks?

View File

@ -23,6 +23,8 @@
extern board_configuration_s *boardConfiguration;
static Logging logger;
static pin_output_mode_e *pinDefaultState[IO_PIN_COUNT];
static OutputPin outputs[IO_PIN_COUNT];
static io_pin_e leds[] = { LED_WARNING, LED_RUNNING, LED_ERROR, LED_COMMUNICATION_1, LED_DEBUG, LED_EXT_1,
@ -59,7 +61,7 @@ inline static void assertOMode(pin_output_mode_e mode) {
* @brief Sets the value according to current electrical settings
*/
void setOutputPinValue(io_pin_e pin, int logicValue) {
if (outputs[pin].port == GPIO_NULL )
if (outputs[pin].port == GPIO_NULL)
return;
efiAssertVoid(pinDefaultState[pin]!=NULL, "pin mode not initialized");
pin_output_mode_e mode = *pinDefaultState[pin];
@ -78,7 +80,7 @@ void setDefaultPinState(io_pin_e pin, pin_output_mode_e *outputMode) {
}
static void comBlinkingThread(void *arg) {
(void)arg;
(void) arg;
chRegSetThreadName("communication blinking");
while (TRUE) {
int delay;
@ -106,7 +108,7 @@ static void comBlinkingThread(void *arg) {
int isTriggerDecoderError(void);
static void errBlinkingThread(void *arg) {
(void)arg;
(void) arg;
chRegSetThreadName("err blinking");
#if EFI_ENGINE_CONTROL
while (TRUE) {
@ -123,16 +125,16 @@ static void errBlinkingThread(void *arg) {
static void outputPinRegisterExt(const char *msg, io_pin_e ioPin, GPIO_TypeDef *port, uint32_t pin,
pin_output_mode_e *outputMode) {
efiAssertVoid((int)ioPin < IO_PIN_COUNT, "io pin out of range");
if (port == GPIO_NULL ) {
if (port == GPIO_NULL) {
// that's for GRIO_NONE
outputs[ioPin].port = port;
return;
}
assertOMode(*outputMode);
iomode_t mode =
(*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ?
PAL_MODE_OUTPUT_PUSHPULL : PAL_MODE_OUTPUT_OPENDRAIN;
iomode_t mode = (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ?
PAL_MODE_OUTPUT_PUSHPULL :
PAL_MODE_OUTPUT_OPENDRAIN;
initOutputPinExt(msg, &outputs[ioPin], port, pin, mode);
@ -141,10 +143,10 @@ static void outputPinRegisterExt(const char *msg, io_pin_e ioPin, GPIO_TypeDef *
GPIO_TypeDef * getHwPort(brain_pin_e brainPin) {
if (brainPin == GPIO_NONE)
return GPIO_NULL ;
return GPIO_NULL;
if (brainPin > GPIO_NONE || brainPin < 0) {
firmwareError("Invalid brain_pin_e: %d", brainPin);
return GPIO_NULL ;
return GPIO_NULL;
}
return PORTS[brainPin / 16];
}
@ -188,7 +190,19 @@ void initPrimaryPins(void) {
outputPinRegister("LED_ERROR", LED_ERROR, LED_ERROR_PORT, LED_ERROR_PIN);
}
static void getPinValue(const char *name) {
io_pin_e pin = getPinByName(name);
if (pin == IO_INVALID) {
return;
}
OutputPin * outputPin = &outputs[pin];
int value = getLogicPinValue(outputPin);
scheduleMsg(&logger, "pin_value %s %d", name, value);
}
void initOutputPins(void) {
initLogging(&logger, "io_pins");
outputPinRegister("warning", LED_WARNING, LED_WARNING_PORT, LED_WARNING_PIN);
outputPinRegister("is running status", LED_RUNNING, LED_RUNNING_STATUS_PORT, LED_RUNNING_STATUS_PIN);
outputPinRegister("communication status 1", LED_COMMUNICATION_1, LED_COMMUNICATION_PORT, LED_COMMUNICATION_PIN);
@ -254,6 +268,8 @@ void initOutputPins(void) {
ledRegister(LED_HUGE_20, GPIOE, 1);
*/
chThdCreateStatic(comBlinkingStack, sizeof(comBlinkingStack), NORMALPRIO, (tfunc_t) comBlinkingThread, NULL );
chThdCreateStatic(errBlinkingStack, sizeof(errBlinkingStack), NORMALPRIO, (tfunc_t) errBlinkingThread, NULL );
chThdCreateStatic(comBlinkingStack, sizeof(comBlinkingStack), NORMALPRIO, (tfunc_t) comBlinkingThread, NULL);
chThdCreateStatic(errBlinkingStack, sizeof(errBlinkingStack), NORMALPRIO, (tfunc_t) errBlinkingThread, NULL);
addConsoleActionS("get_pin_value", getPinValue);
}

View File

@ -53,8 +53,22 @@ uint32_t efiStrlen(const char *param) {
return strlen(param);
}
bool startsWith(const char *line, const char *prefix) {
int len = efiStrlen(prefix);
if(efiStrlen(line) < len) {
return false;
}
for(int i =0;i<len;i++) {
if(line[i]!=prefix[i]) {
return false;
}
}
return true;
}
int indexOf(const char *string, char ch) {
// todo: there should be a standard function for this
// todo: on the other hand MISRA wants us not to use standart headers
int len = efiStrlen(string);
for (int i = 0; i < len; i++) {
if (string[i] == ch) {

View File

@ -34,6 +34,7 @@ extern "C"
const char * boolToString(bool value);
uint32_t efiStrlen(const char *param);
bool startsWith(const char *line, const char *prefix);
int indexOf(const char *string, char ch);
float atoff(const char *string);
int atoi(const char *string);

View File

@ -100,6 +100,7 @@ int main(void) {
testFindIndex();
testInterpolate2d();
testGpsParser();
testMisc();
prepareFuelMap();
testFuelMap();
testEngineMath();
@ -130,7 +131,7 @@ int main(void) {
testFLStack();
// resizeMap();
printf("Success 20130914\r\n");
printf("Success 20130926\r\n");
return EXIT_SUCCESS;
}

View File

@ -19,6 +19,7 @@
#include "efilib2.h"
#include "crc.h"
#include "fl_stack.h"
#include "io_pins.h"
void testCrc(void) {
assertEquals(4, efiRound(4.4, 1));
@ -310,6 +311,9 @@ void testFLStack(void) {
FLStack<int, 4> stack;
assertEquals(0, stack.size());
}
void testMisc(void) {
assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
}

View File

@ -21,6 +21,7 @@ void testMalfunctionCentral(void);
void testConsoleLogic(void);
void testGpsParser(void);
void testFLStack(void);
void testMisc(void);
#ifdef __cplusplus
}