auto-sync
This commit is contained in:
parent
b850039a96
commit
e00d3d43d4
|
@ -16,6 +16,7 @@
|
||||||
* Logical pins. See brain_pin_e for physical pins.
|
* Logical pins. See brain_pin_e for physical pins.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
IO_INVALID,
|
||||||
LED_WARNING, // Orange on-board LED
|
LED_WARNING, // Orange on-board LED
|
||||||
LED_RUNNING, // Green on-board LED
|
LED_RUNNING, // Green on-board LED
|
||||||
LED_ERROR, // Red on-board LED
|
LED_ERROR, // Red on-board LED
|
||||||
|
@ -128,6 +129,7 @@ extern "C"
|
||||||
void initPrimaryPins(void);
|
void initPrimaryPins(void);
|
||||||
void initOutputPins(void);
|
void initOutputPins(void);
|
||||||
const char *getPinName(io_pin_e io_pin);
|
const char *getPinName(io_pin_e io_pin);
|
||||||
|
io_pin_e getPinByName(const char *name);
|
||||||
void turnOutputPinOn(io_pin_e pin);
|
void turnOutputPinOn(io_pin_e pin);
|
||||||
void turnOutputPinOff(io_pin_e pin);
|
void turnOutputPinOff(io_pin_e pin);
|
||||||
void setOutputPinValue(io_pin_e pin, int logicValue);
|
void setOutputPinValue(io_pin_e pin, int logicValue);
|
||||||
|
|
|
@ -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);
|
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) {
|
const char *getPinName(io_pin_e io_pin) {
|
||||||
switch (io_pin) {
|
switch (io_pin) {
|
||||||
// todo: refactor this hell - introduce arrays & checks?
|
// todo: refactor this hell - introduce arrays & checks?
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
extern board_configuration_s *boardConfiguration;
|
extern board_configuration_s *boardConfiguration;
|
||||||
|
|
||||||
|
static Logging logger;
|
||||||
|
|
||||||
static pin_output_mode_e *pinDefaultState[IO_PIN_COUNT];
|
static pin_output_mode_e *pinDefaultState[IO_PIN_COUNT];
|
||||||
static OutputPin outputs[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,
|
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
|
* @brief Sets the value according to current electrical settings
|
||||||
*/
|
*/
|
||||||
void setOutputPinValue(io_pin_e pin, int logicValue) {
|
void setOutputPinValue(io_pin_e pin, int logicValue) {
|
||||||
if (outputs[pin].port == GPIO_NULL )
|
if (outputs[pin].port == GPIO_NULL)
|
||||||
return;
|
return;
|
||||||
efiAssertVoid(pinDefaultState[pin]!=NULL, "pin mode not initialized");
|
efiAssertVoid(pinDefaultState[pin]!=NULL, "pin mode not initialized");
|
||||||
pin_output_mode_e mode = *pinDefaultState[pin];
|
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) {
|
static void comBlinkingThread(void *arg) {
|
||||||
(void)arg;
|
(void) arg;
|
||||||
chRegSetThreadName("communication blinking");
|
chRegSetThreadName("communication blinking");
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
int delay;
|
int delay;
|
||||||
|
@ -106,7 +108,7 @@ static void comBlinkingThread(void *arg) {
|
||||||
int isTriggerDecoderError(void);
|
int isTriggerDecoderError(void);
|
||||||
|
|
||||||
static void errBlinkingThread(void *arg) {
|
static void errBlinkingThread(void *arg) {
|
||||||
(void)arg;
|
(void) arg;
|
||||||
chRegSetThreadName("err blinking");
|
chRegSetThreadName("err blinking");
|
||||||
#if EFI_ENGINE_CONTROL
|
#if EFI_ENGINE_CONTROL
|
||||||
while (TRUE) {
|
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,
|
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) {
|
||||||
efiAssertVoid((int)ioPin < IO_PIN_COUNT, "io pin out of range");
|
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;
|
outputs[ioPin].port = port;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertOMode(*outputMode);
|
assertOMode(*outputMode);
|
||||||
iomode_t mode =
|
iomode_t mode = (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ?
|
||||||
(*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ?
|
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, &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) {
|
GPIO_TypeDef * getHwPort(brain_pin_e brainPin) {
|
||||||
if (brainPin == GPIO_NONE)
|
if (brainPin == GPIO_NONE)
|
||||||
return GPIO_NULL ;
|
return GPIO_NULL;
|
||||||
if (brainPin > GPIO_NONE || brainPin < 0) {
|
if (brainPin > GPIO_NONE || brainPin < 0) {
|
||||||
firmwareError("Invalid brain_pin_e: %d", brainPin);
|
firmwareError("Invalid brain_pin_e: %d", brainPin);
|
||||||
return GPIO_NULL ;
|
return GPIO_NULL;
|
||||||
}
|
}
|
||||||
return PORTS[brainPin / 16];
|
return PORTS[brainPin / 16];
|
||||||
}
|
}
|
||||||
|
@ -188,7 +190,19 @@ void initPrimaryPins(void) {
|
||||||
outputPinRegister("LED_ERROR", LED_ERROR, LED_ERROR_PORT, LED_ERROR_PIN);
|
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) {
|
void initOutputPins(void) {
|
||||||
|
initLogging(&logger, "io_pins");
|
||||||
|
|
||||||
outputPinRegister("warning", LED_WARNING, LED_WARNING_PORT, LED_WARNING_PIN);
|
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("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);
|
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);
|
ledRegister(LED_HUGE_20, GPIOE, 1);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
chThdCreateStatic(comBlinkingStack, sizeof(comBlinkingStack), NORMALPRIO, (tfunc_t) comBlinkingThread, NULL );
|
chThdCreateStatic(comBlinkingStack, sizeof(comBlinkingStack), NORMALPRIO, (tfunc_t) comBlinkingThread, NULL);
|
||||||
chThdCreateStatic(errBlinkingStack, sizeof(errBlinkingStack), NORMALPRIO, (tfunc_t) errBlinkingThread, NULL );
|
chThdCreateStatic(errBlinkingStack, sizeof(errBlinkingStack), NORMALPRIO, (tfunc_t) errBlinkingThread, NULL);
|
||||||
|
|
||||||
|
addConsoleActionS("get_pin_value", getPinValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,22 @@ uint32_t efiStrlen(const char *param) {
|
||||||
return strlen(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) {
|
int indexOf(const char *string, char ch) {
|
||||||
// todo: there should be a standard function for this
|
// 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);
|
int len = efiStrlen(string);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (string[i] == ch) {
|
if (string[i] == ch) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ extern "C"
|
||||||
const char * boolToString(bool value);
|
const char * boolToString(bool value);
|
||||||
|
|
||||||
uint32_t efiStrlen(const char *param);
|
uint32_t efiStrlen(const char *param);
|
||||||
|
bool startsWith(const char *line, const char *prefix);
|
||||||
int indexOf(const char *string, char ch);
|
int indexOf(const char *string, char ch);
|
||||||
float atoff(const char *string);
|
float atoff(const char *string);
|
||||||
int atoi(const char *string);
|
int atoi(const char *string);
|
||||||
|
|
|
@ -100,6 +100,7 @@ int main(void) {
|
||||||
testFindIndex();
|
testFindIndex();
|
||||||
testInterpolate2d();
|
testInterpolate2d();
|
||||||
testGpsParser();
|
testGpsParser();
|
||||||
|
testMisc();
|
||||||
prepareFuelMap();
|
prepareFuelMap();
|
||||||
testFuelMap();
|
testFuelMap();
|
||||||
testEngineMath();
|
testEngineMath();
|
||||||
|
@ -130,7 +131,7 @@ int main(void) {
|
||||||
testFLStack();
|
testFLStack();
|
||||||
|
|
||||||
// resizeMap();
|
// resizeMap();
|
||||||
printf("Success 20130914\r\n");
|
printf("Success 20130926\r\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "efilib2.h"
|
#include "efilib2.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "fl_stack.h"
|
#include "fl_stack.h"
|
||||||
|
#include "io_pins.h"
|
||||||
|
|
||||||
void testCrc(void) {
|
void testCrc(void) {
|
||||||
assertEquals(4, efiRound(4.4, 1));
|
assertEquals(4, efiRound(4.4, 1));
|
||||||
|
@ -310,6 +311,9 @@ void testFLStack(void) {
|
||||||
|
|
||||||
FLStack<int, 4> stack;
|
FLStack<int, 4> stack;
|
||||||
assertEquals(0, stack.size());
|
assertEquals(0, stack.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMisc(void) {
|
||||||
|
assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
|
||||||
|
assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ void testMalfunctionCentral(void);
|
||||||
void testConsoleLogic(void);
|
void testConsoleLogic(void);
|
||||||
void testGpsParser(void);
|
void testGpsParser(void);
|
||||||
void testFLStack(void);
|
void testFLStack(void);
|
||||||
|
void testMisc(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue