EFI_CONSOLE_UART_DEVICE, flash->hw_ports, Fix TLE6240 and misc.fixes (#793)

* rename EFI_CONSOLE_UART_DEVICE -> EFI_CONSOLE_SERIAL_DEVICE

* Impl. EFI_CONSOLE_UART_DEVICE

* Move flash source files to ports/stm32/ & hw_ports.mk

* Fix TLE6240

* Fix EFI_NO_CONFIG_WORKING_COPY

* EFI_PRINT_MESSAGES_TO_TERMINAL
This commit is contained in:
andreika-git 2019-05-05 18:06:27 +03:00 committed by rusefi
parent 11f832306c
commit b80d95578d
19 changed files with 131 additions and 57 deletions

View File

@ -35,8 +35,8 @@
#define ADC_CHANNEL_VREF ADC_CHANNEL_IN14
#undef EFI_CONSOLE_SERIAL_DEVICE
#undef EFI_CONSOLE_UART_DEVICE
//#define EFI_CONSOLE_UART_DEVICE (&SD4)
#undef EFI_UART_GPS
#define EFI_UART_GPS FALSE
@ -94,8 +94,6 @@
#define LED_ERROR_PIN 13
#undef CONSOLE_MODE_SWITCH_PORT
#define CONSOLE_MODE_SWITCH_PORT GPIOE // ???
#undef CONFIG_RESET_SWITCH_PORT
//!!!!!!!!!!!!!!!

View File

@ -15,8 +15,8 @@
/* debug console */
#undef EFI_USE_UART_FOR_CONSOLE
#define EFI_USE_UART_FOR_CONSOLE TRUE
#undef EFI_CONSOLE_UART_DEVICE
#define EFI_CONSOLE_UART_DEVICE (&SD1)
#undef EFI_CONSOLE_SERIAL_DEVICE
#define EFI_CONSOLE_SERIAL_DEVICE (&SD1)
/* TunerStudio binary protocol */
/* do not use UART device for console */
@ -61,7 +61,7 @@
#undef SERIAL_SPEED
#define SERIAL_SPEED 115200
#ifdef EFI_CONSOLE_UART_DEVICE
#ifdef EFI_CONSOLE_SERIAL_DEVICE
#undef EFI_CONSOLE_TX_PORT
#define EFI_CONSOLE_TX_PORT GPIOA
#undef EFI_CONSOLE_TX_PIN

View File

@ -16,7 +16,7 @@
#define EFI_USE_UART_FOR_CONSOLE TRUE
#define EFI_CONSOLE_UART_DEVICE (&SD1)
#define EFI_CONSOLE_SERIAL_DEVICE (&SD1)
#define TS_SERIAL_DEVICE (&SD3)

View File

@ -324,8 +324,8 @@
// todo: start using consoleUartDevice? Not sure
#ifndef EFI_CONSOLE_UART_DEVICE
#define EFI_CONSOLE_UART_DEVICE (&SD3)
#ifndef EFI_CONSOLE_SERIAL_DEVICE
#define EFI_CONSOLE_SERIAL_DEVICE (&SD3)
#endif
/**
@ -343,7 +343,7 @@
// todo: add DMA-mode for Console?
#if (TS_UART_DMA_MODE || TS_UART_MODE)
#undef EFI_CONSOLE_UART_DEVICE
#undef EFI_CONSOLE_SERIAL_DEVICE
#endif
// todo: start using consoleSerialTxPin? Not sure

View File

@ -80,8 +80,8 @@
#define EFI_UART_GPS FALSE
// todo: start using consoleUartDevice? Not sure
#undef EFI_CONSOLE_UART_DEVICE
#define EFI_CONSOLE_UART_DEVICE (&SD3)
#undef EFI_CONSOLE_SERIAL_DEVICE
#define EFI_CONSOLE_SERIAL_DEVICE (&SD3)
// todo: our "DMA-half" ChibiOS patch not implemented for USARTv2/STM32F7
#undef TS_UART_DMA_MODE
@ -94,7 +94,7 @@
// todo: add DMA-mode for Console?
#if (TS_UART_DMA_MODE || TS_UART_MODE)
#undef EFI_CONSOLE_UART_DEVICE
#undef EFI_CONSOLE_SERIAL_DEVICE
#endif
// todo: start using consoleSerialTxPin? Not sure

View File

@ -110,8 +110,6 @@ persistent_config_s configWorkingCopy;
#endif /* EFI_NO_CONFIG_WORKING_COPY */
extern persistent_config_container_s persistentState;
static efitimems_t previousWriteReportMs = 0;
static ts_channel_s tsChannel;
@ -199,7 +197,7 @@ char *getWorkingPageAddr(int pageIndex) {
#if !defined(EFI_NO_CONFIG_WORKING_COPY)
return (char*) &configWorkingCopy.engineConfiguration;
#else
return (char*) &engineConfiguration;
return (char*) engineConfiguration;
#endif /* EFI_NO_CONFIG_WORKING_COPY */
// case 1:
// return (char*) &configWorkingCopy.ve2Table;

View File

@ -36,6 +36,9 @@ EXTERN_ENGINE;
extern SerialUSBDriver SDU1;
#endif /* HAL_USE_SERIAL_USB */
// 10 seconds
#define CONSOLE_WRITE_TIMEOUT 10000
int lastWriteSize;
int lastWriteActual;
@ -74,7 +77,7 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
short c = (short) streamGet(chp);
onDataArrived();
#if defined(EFI_CONSOLE_UART_DEVICE)
#if defined(EFI_CONSOLE_SERIAL_DEVICE)
uint32_t flags;
chSysLock()
@ -131,10 +134,70 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
*/
CommandHandler console_line_callback;
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR )
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR )
static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
#endif
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR )
/* Note: This structure is modified from the default ChibiOS layout! */
static UARTConfig uartConfig = {
.txend1_cb = NULL, .txend2_cb = NULL, .rxend_cb = NULL, .rxchar_cb = NULL, .rxerr_cb = NULL,
.speed = 0, .cr1 = 0, .cr2 = 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN, .cr3 = 0,
.timeout_cb = NULL, .rxhalf_cb = NULL
};
// To use UART driver instead of Serial, we need to imitate "BaseChannel" streaming functionality
static msg_t _putt(void *, uint8_t b, sysinterval_t timeout) {
int n = 1;
uartSendTimeout(EFI_CONSOLE_UART_DEVICE, (size_t *)&n, &b, timeout);
return MSG_OK;
}
static size_t _writet(void *, const uint8_t *bp, size_t n, sysinterval_t timeout) {
uartSendTimeout(EFI_CONSOLE_UART_DEVICE, (size_t *)&n, bp, timeout);
return n;
}
static msg_t _put(void *ip, uint8_t b) {
#ifdef UART_USE_BLOCKING_SEND
// this version can be called from the locked state (no interrupts)
uart_lld_blocking_send(EFI_CONSOLE_UART_DEVICE, 1, (void *)&b);
#else
// uartSendTimeout() needs interrupts to wait for the end of transfer, so we have to unlock them temporary
bool wasLocked = isLocked();
if (wasLocked)
unlockAnyContext();
_putt(ip, b, CONSOLE_WRITE_TIMEOUT);
if (wasLocked)
lockAnyContext();
#endif /* UART_USE_BLOCKING_WRITE */
return MSG_OK;
}
static size_t _write(void *ip, const uint8_t *bp, size_t n) {
return _writet(ip, bp, n, CONSOLE_WRITE_TIMEOUT);
}
static msg_t _gett(void *, sysinterval_t /*timeout*/) {
return 0;
}
static size_t _readt(void *, uint8_t */*bp*/, size_t /*n*/, sysinterval_t /*timeout*/) {
return 0;
}
static msg_t _get(void *) {
return 0;
}
static size_t _read(void *, uint8_t */*bp*/, size_t /*n*/) {
return 0;
}
static msg_t _ctl(void *, unsigned int /*operation*/, void */*arg*/) {
return MSG_OK;
}
// This is a "fake" channel for getConsoleChannel() filled with our handlers
static const struct BaseChannelVMT uartChannelVmt = {
.instance_offset = (size_t)0, .write = _write, .read = _read, .put = _put, .get = _get,
.putt = _putt, .gett = _gett, .writet = _writet, .readt = _readt, .ctl = _ctl
};
static const BaseChannel uartChannel = { .vmt = &uartChannelVmt };
#endif /* EFI_CONSOLE_UART_DEVICE */
#if EFI_PROD_CODE || EFI_EGT
bool isUsbSerial(BaseChannel * channel) {
@ -146,8 +209,12 @@ bool isUsbSerial(BaseChannel * channel) {
}
BaseChannel * getConsoleChannel(void) {
#if defined(EFI_CONSOLE_SERIAL_DEVICE)
return (BaseChannel *) EFI_CONSOLE_SERIAL_DEVICE;
#endif /* EFI_CONSOLE_SERIAL_DEVICE */
#if defined(EFI_CONSOLE_UART_DEVICE)
return (BaseChannel *) EFI_CONSOLE_UART_DEVICE;
return (BaseChannel *) &uartChannel;
#endif /* EFI_CONSOLE_UART_DEVICE */
#if HAL_USE_SERIAL_USB
@ -164,7 +231,7 @@ bool isCommandLineConsoleReady(void) {
#if !defined(EFI_CONSOLE_NO_THREAD)
ts_channel_s binaryConsole;
static ts_channel_s binaryConsole;
static THD_WORKING_AREA(consoleThreadStack, 3 * UTILITY_THREAD_STACK_SIZE);
static THD_FUNCTION(consoleThreadEntryPoint, arg) {
@ -181,9 +248,6 @@ static THD_FUNCTION(consoleThreadEntryPoint, arg) {
#endif /* EFI_CONSOLE_NO_THREAD */
// 10 seconds
#define CONSOLE_WRITE_TIMEOUT 10000
void consolePutChar(int x) {
chnWriteTimeout(getConsoleChannel(), (const uint8_t *)&x, 1, CONSOLE_WRITE_TIMEOUT);
}
@ -203,22 +267,31 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
logger = sharedLogger;
console_line_callback = console_line_callback_p;
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR)
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR)
/*
* Activates the serial
* it is important to set 'NONE' as flow control! in terminal application on the PC
*/
serialConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
sdStart(EFI_CONSOLE_UART_DEVICE, &serialConfig);
sdStart(EFI_CONSOLE_SERIAL_DEVICE, &serialConfig);
// cannot use pin repository here because pin repository prints to console
// cannot use pin repository here because pin repository prints to console
palSetPadMode(EFI_CONSOLE_RX_PORT, EFI_CONSOLE_RX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
palSetPadMode(EFI_CONSOLE_TX_PORT, EFI_CONSOLE_TX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
isSerialConsoleStarted = true;
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1);
#endif /* EFI_PROD_CODE */
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_SERIAL_DEVICE), &consoleEventListener, 1);
#elif (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR)
uartConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
uartStart(EFI_CONSOLE_UART_DEVICE, &uartConfig);
// cannot use pin repository here because pin repository prints to console
palSetPadMode(EFI_CONSOLE_RX_PORT, EFI_CONSOLE_RX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
palSetPadMode(EFI_CONSOLE_TX_PORT, EFI_CONSOLE_TX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
isSerialConsoleStarted = true;
#endif /* EFI_CONSOLE_SERIAL_DEVICE || EFI_CONSOLE_UART_DEVICE */
#if !defined(EFI_CONSOLE_NO_THREAD)
chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, (tfunc_t)consoleThreadEntryPoint, NULL);

View File

@ -31,7 +31,7 @@ static msg_t Thread1(void *arg) {
void runRusEfi(void) {
#if defined(EFI_CONSOLE_UART_DEVICE)
#if defined(EFI_CONSOLE_SERIAL_DEVICE)
/*
* Activates the serial driver 1 using the driver default configuration.
* PA9 and PA10 are routed to USART1.

View File

@ -204,7 +204,8 @@ static int tle6240_chip_init(struct tle6240_priv *chip)
const struct tle6240_config *cfg = chip->cfg;
/* mark pins used */
ret = gpio_pin_markUsed(cfg->spi_config.ssport, cfg->spi_config.sspad, DRIVER_NAME " CS");
//ret = gpio_pin_markUsed(cfg->spi_config.ssport, cfg->spi_config.sspad, DRIVER_NAME " CS");
ret = 0;
if (cfg->reset.port != NULL)
ret |= gpio_pin_markUsed(cfg->reset.port, cfg->reset.pad, DRIVER_NAME " RST");
for (n = 0; n < TLE6240_DIRECT_OUTPUTS; n++)
@ -293,7 +294,7 @@ static int tle6240_chip_init(struct tle6240_priv *chip)
err_gpios:
/* unmark pins */
gpio_pin_markUnused(cfg->spi_config.ssport, cfg->spi_config.sspad);
//gpio_pin_markUnused(cfg->spi_config.ssport, cfg->spi_config.sspad);
if (cfg->reset.port != NULL)
gpio_pin_markUnused(cfg->reset.port, cfg->reset.pad);
for (n = 0; n < TLE6240_DIRECT_OUTPUTS; n++)
@ -478,9 +479,9 @@ int tle6240_add(unsigned int index, const struct tle6240_config *cfg)
return -1;
/* check for valid cs.
* DOTO: remove this check? CS can be driven by SPI */
if (cfg->spi_config.ssport == NULL)
return -1;
* TODO: remove this check? CS can be driven by SPI */
//if (cfg->spi_config.ssport == NULL)
// return -1;
chip = &chips[index];

View File

@ -319,10 +319,6 @@ void applyNewHardwareSettings(void) {
enginePins.unregisterPins();
#if (BOARD_TLE6240_COUNT > 0)
startSmartCsPins();
#endif /* (BOARD_MC33972_COUNT > 0) */
#if EFI_SHAFT_POSITION_INPUT
startTriggerInputPins();
#endif /* EFI_SHAFT_POSITION_INPUT */

View File

@ -7,9 +7,7 @@ HW_LAYER_EGT_CPP = $(PROJECT_DIR)/hw_layer/can_hw.cpp \
HW_LAYER_EMS = $(HW_LAYER_EGT) \
$(PROJECT_DIR)/hw_layer/mcp3208.c \
$(PROJECT_DIR)/hw_layer/mc33816_data.c \
$(PROJECT_DIR)/hw_layer/flash.c \
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
@ -36,18 +34,5 @@ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
$(PROJECT_DIR)/hw_layer/backup_ram.cpp \
ifeq ($(PROJECT_CPU),ARCH_STM32F7)
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash_ex.c
endif
ifeq ($(PROJECT_CPU),ARCH_STM32F4)
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash_ex.c
endif
ifeq ($(PROJECT_CPU),ARCH_STM32F1)
endif
-include $(PROJECT_DIR)/hw_layer/$(CPU_HWLAYER)/hw_ports.mk

View File

@ -1,3 +1,4 @@
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/flash.c
HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f1/mpu_util.cpp \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.cpp

View File

@ -1,3 +1,6 @@
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash_ex.c
HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/mpu_util.cpp \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.cpp

View File

@ -1,3 +1,6 @@
HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash.c \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash_ex.c
HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/mpu_util.cpp \
$(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.cpp

View File

@ -178,7 +178,7 @@ void initSmartGpio() {
ret = -1;
}
if (ret < 0)
#endif /* (BOARD_TLE6240_COUNT > 0) */
#endif /* (BOARD_TLE8888_COUNT > 0) */
/* whenever chip is disabled or error returned - occupy its gpio range */
gpiochip_use_gpio_base(TLE8888_OUTPUTS);
@ -190,18 +190,30 @@ void initSmartGpio() {
#if (BOARD_EXT_GPIOCHIPS > 0)
void stopSmartCsPins() {
#if (BOARD_TLE8888_COUNT > 0)
brain_pin_markUnused(activeConfiguration.tle8888_cs);
#endif /* BOARD_TLE8888_COUNT */
#if (BOARD_TLE6240_COUNT > 0)
brain_pin_markUnused(activeConfiguration.tle6240_cs);
#endif /* BOARD_TLE6240_COUNT */
#if (BOARD_MC33972_COUNT > 0)
brain_pin_markUnused(activeConfiguration.bc.mc33972_cs);
#endif /* BOARD_MC33972_COUNT */
}
void startSmartCsPins() {
#if (BOARD_TLE8888_COUNT > 0)
tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs,
&engineConfiguration->tle8888_csPinMode);
tle6240Cs.initPin("tle8888 CS", engineConfiguration->tle6240_cs,
#endif /* BOARD_TLE8888_COUNT */
#if (BOARD_TLE6240_COUNT > 0)
tle6240Cs.initPin("tle6240 CS", engineConfiguration->tle6240_cs,
&engineConfiguration->tle6240_csPinMode);
#endif /* BOARD_TLE6240_COUNT */
#if (BOARD_MC33972_COUNT > 0)
mc33972Cs.initPin("mc33972 CS", boardConfiguration->mc33972_cs,
&boardConfiguration->mc33972_csPinMode);
#endif /* BOARD_MC33972_COUNT */
}
#endif /* (BOARD_EXT_GPIOCHIPS > 0) */

View File

@ -46,6 +46,10 @@ static char * outputBuffer;
*/
void scheduleLogging(Logging *logging) {
#if EFI_TEXT_LOGGING
#ifdef EFI_PRINT_MESSAGES_TO_TERMINAL
print(logging->buffer);
print("\r\n");
#endif /* EFI_PRINT_MESSAGES_TO_TERMINAL */
// this could be done without locking
int newLength = efiStrlen(logging->buffer);

View File

@ -19,7 +19,7 @@
/**
* This implementation writes to both windows console and console port
*/
#define EFI_CONSOLE_UART_DEVICE (&serialAdapterInstance)
#define EFI_CONSOLE_SERIAL_DEVICE (&serialAdapterInstance)
int getAdcValue(const char *msg, int channel);
#define getSlowAdcCounter() 0

View File

@ -168,5 +168,5 @@ void logMsg(const char *format, ...) {
}
BaseChannel * getConsoleChannel(void) {
return (BaseChannel *)EFI_CONSOLE_UART_DEVICE;
return (BaseChannel *)EFI_CONSOLE_SERIAL_DEVICE;
}