rusefi-1/firmware/config/boards/microrusefi/board_configuration.cpp

260 lines
8.0 KiB
C++
Raw Normal View History

/**
* @file boards/microrusefi/board_configuration.cpp
*
2019-08-04 18:56:01 -07:00
*
* @brief Configuration defaults for the microRusefi board
*
2020-04-13 11:30:17 -07:00
* MICRO_RUS_EFI
* set engine_type 60
*
2020-05-21 15:36:32 -07:00
* MRE_BOARD_OLD_TEST
2020-04-13 11:30:17 -07:00
* set engine_type 30
*
2020-05-21 15:36:32 -07:00
* MRE_BOARD_NEW_TEST
* set engine_type 31
2020-04-13 11:30:17 -07:00
*
* See https://github.com/rusefi/rusefi/wiki/Hardware_microRusEfi_wiring
2019-08-04 18:56:01 -07:00
*
* @author Matthew Kennedy, (c) 2019
*/
#include "global.h"
#include "engine.h"
#include "engine_math.h"
#include "allsensors.h"
#include "fsio_impl.h"
#include "engine_configuration.h"
EXTERN_ENGINE;
static const ConfigOverrides configOverrides = {
.canTxPin = GPIOB_6,
.canRxPin = GPIOB_12,
};
2020-03-31 13:49:19 -07:00
const ConfigOverrides& getConfigOverrides() {
return configOverrides;
2020-03-31 13:49:19 -07:00
}
2019-08-04 18:56:01 -07:00
static void setInjectorPins() {
Tle8888 big update 1 (#1892) * smart gpio: fix tle8888 direct pin mapping for MRE * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 * TLE8888: cleanup * TLE8888: do not reset driver private data on WD/undervoltage reset * TLE8888: diagnostic updates * TLE8888 driver: BIG driver rework * TLE8888: check SPI answers for abnormal states Reply with other than requested register can be a sign of: -Power-On-Reset, then OpStat0 will be replyed -WatchDog reset, then FWDStat1 will be replyed -Invalid communication frame, then Diag0 will be replyed Keep tracking last accessed register and check with the next reply. * TLE8888: debug clean-up * TLE8888: implement spi array write This reduce CS inactive state time between two consequent accesses from 8.8 uS to 1.4 uS * TLE8888: fix PP outputs in OD mode * TLE8888: cleanup register definitions * TLE8888: run separate driver thread for each chip instance Calculating poll interval for few chips become more complex, avoid this running thread for each device. * TLE8888: fix cypress and kinetic compilation Both platforms define its own MAX and cause redifination error if common.h is included in driver. * MRE: update mapping.yaml and fix direct pin mapping for TLE8888 * TLE8888: diagnnostic: disable switch off in case of overcurrent For all output, use current limiting instead * TLE8888: check for overvoltage on OUT8..OUT13 * TLE8888: add TODO note about how to recover from failure condition Currently TLE8888 automaticly recovers only from overcurrent and (may be) overtemperature conditions. Short to bat cause output disable (bit in OECONFIG is reset) and needs driver/host intervention. * TLE8888: save few bytes of RAM * TLE8888: Lada Kalina is test mule for IDLE stepper on TLE8888 Don't forget to enable PP mode for TLE8888 outputs 21..24: uncomment line 1087 in tle8888.c * TLE8888: reorder code, cleanup * TLE8888: mode all debug/statisctic to per-chip struct * TLE8888: rework poll interval calculation * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 #2
2020-10-23 09:25:30 -07:00
engineConfiguration->injectionPins[0] = TLE8888_PIN_1;
engineConfiguration->injectionPins[1] = TLE8888_PIN_2;
engineConfiguration->injectionPins[2] = TLE8888_PIN_3;
engineConfiguration->injectionPins[3] = TLE8888_PIN_4;
// Disable remainder
for (int i = 4; i < INJECTION_PIN_COUNT;i++) {
engineConfiguration->injectionPins[i] = GPIO_UNASSIGNED;
}
engineConfiguration->injectionPinMode = OM_DEFAULT;
}
2019-08-04 18:56:01 -07:00
static void setIgnitionPins() {
2019-08-17 19:42:22 -07:00
// todo: I wonder if these are not right in light of the network rename and the +12 VP issue?
engineConfiguration->ignitionPins[0] = GPIOD_4;
engineConfiguration->ignitionPins[1] = GPIOD_3;
engineConfiguration->ignitionPins[2] = GPIOD_2;
engineConfiguration->ignitionPins[3] = GPIOD_1;
// disable remainder
for (int i = 4; i < IGNITION_PIN_COUNT; i++) {
engineConfiguration->ignitionPins[i] = GPIO_UNASSIGNED;
}
engineConfiguration->ignitionPinMode = OM_DEFAULT;
}
2019-08-04 18:56:01 -07:00
static void setLedPins() {
2019-09-14 13:03:04 -07:00
#ifdef EFI_COMMUNICATION_PIN
engineConfiguration->communicationLedPin = EFI_COMMUNICATION_PIN;
#else
engineConfiguration->communicationLedPin = GPIOE_2; // d23 = blue
2019-09-14 13:03:04 -07:00
#endif /* EFI_COMMUNICATION_PIN */
engineConfiguration->runningLedPin = GPIOE_4; // d22 = green
2020-05-12 22:16:05 -07:00
engineConfiguration->warningLedPin = GPIOE_1; // d27 = orange or yellow
}
2019-08-04 18:56:01 -07:00
static void setupVbatt() {
2020-02-12 19:15:36 -08:00
/*
below 0.4
// 1k high side/1.5k low side = 1.6667 ratio divider
engineConfiguration->analogInputDividerCoefficient = 2.5f / 1.5f;
2020-02-12 19:15:36 -08:00
*/
// 6.8k high side/10k low side = 1.68 ratio divider
2020-02-12 20:16:46 -08:00
engineConfiguration->analogInputDividerCoefficient = 16.8f / 10.0f;
2020-02-12 19:15:36 -08:00
// set vbatt_divider 8.23
// R139=39k high side/R141=10k low side multiplied by above analogInputDividerCoefficient = 8.232f
engineConfiguration->vbattDividerCoeff = (49.0f / 10.0f) * engineConfiguration->analogInputDividerCoefficient;
2020-05-13 16:27:11 -07:00
// PC1, pin #1 input +12 from Main Relay. Main Relay controlled by TLE8888
2019-08-18 17:18:56 -07:00
engineConfiguration->vbattAdcChannel = EFI_ADC_11;
engineConfiguration->adcVcc = 3.29f;
}
2019-08-04 18:56:01 -07:00
static void setupTle8888() {
2020-05-14 23:31:02 -07:00
// on microRusEFI SPI3 is exposed on PC10/PC11 and there is interest to use SD card there
// PB3/PB4 could be either SPI1 or SP3, let's use not SPI3 to address the contention
// Enable spi1
CONFIG(is_enabled_spi_1) = true;
2020-05-14 23:31:02 -07:00
// Wire up spi1
engineConfiguration->spi1mosiPin = GPIOB_5;
engineConfiguration->spi1misoPin = GPIOB_4;
engineConfiguration->spi1sckPin = GPIOB_3;
// Chip select
engineConfiguration->tle8888_cs = GPIOD_5;
// SPI device
2020-05-14 23:31:02 -07:00
engineConfiguration->tle8888spiDevice = SPI_DEVICE_1;
}
2019-08-04 18:56:01 -07:00
static void setupEtb() {
// TLE9201 driver
// This chip has three control pins:
// DIR - sets direction of the motor
// PWM - pwm control (enable high, coast low)
// DIS - disables motor (enable low)
// PWM pin
engineConfiguration->etbIo[0].controlPin1 = GPIOC_7;
// DIR pin
engineConfiguration->etbIo[0].directionPin1 = GPIOA_8;
// Disable pin
engineConfiguration->etbIo[0].disablePin = GPIOC_8;
// Unused
engineConfiguration->etbIo[0].directionPin2 = GPIO_UNASSIGNED;
2019-08-14 22:59:15 -07:00
2019-08-17 14:33:44 -07:00
// set_analog_input_pin pps PA7
// EFI_ADC_7: "31 - AN volt 3" - PA7
2019-08-14 22:59:15 -07:00
// engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_7;
// we only have pwm/dir, no dira/dirb
2019-11-29 13:51:51 -08:00
engineConfiguration->etb_use_two_wires = false;
}
2019-08-04 18:56:01 -07:00
static void setupDefaultSensorInputs() {
// trigger inputs
// tle8888 VR conditioner
engineConfiguration->triggerInputPins[0] = GPIOC_6;
engineConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED;
engineConfiguration->triggerInputPins[2] = GPIO_UNASSIGNED;
// Direct hall-only cam input
engineConfiguration->camInputs[0] = GPIOA_5;
2019-08-17 19:42:22 -07:00
// open question if it's great to have TPS in default TPS - the down-side is for
// vehicles without TPS or for first start without TPS one would have to turn in off
// to avoid cranking corrections based on wrong TPS data
2020-05-20 20:53:25 -07:00
// tps = "20 - AN volt 5" PC3
engineConfiguration->tps1_1AdcChannel = EFI_ADC_13;
engineConfiguration->tps2_1AdcChannel = EFI_ADC_NONE;
2019-09-02 14:16:36 -07:00
// EFI_ADC_10: "27 - AN volt 1"
engineConfiguration->map.sensor.hwChannel = EFI_ADC_10;
// EFI_ADC_14: "32 - AN volt 6"
engineConfiguration->afr.hwChannel = EFI_ADC_14;
2019-09-02 14:16:36 -07:00
2019-08-14 22:59:15 -07:00
// clt = "18 - AN temp 1"
engineConfiguration->clt.adcChannel = EFI_ADC_0;
engineConfiguration->clt.config.bias_resistor = 2700;
2019-08-14 22:59:15 -07:00
// iat = "23 - AN temp 2"
engineConfiguration->iat.adcChannel = EFI_ADC_1;
engineConfiguration->iat.config.bias_resistor = 2700;
2020-07-27 17:23:57 -07:00
2020-07-27 19:05:40 -07:00
setCommonNTCSensor(&engineConfiguration->auxTempSensor1, 2700);
setCommonNTCSensor(&engineConfiguration->auxTempSensor2, 2700);
2020-07-27 17:23:57 -07:00
#if HW_CHECK_MODE
engineConfiguration->auxTempSensor1.adcChannel = EFI_ADC_2;
engineConfiguration->auxTempSensor2.adcChannel = EFI_ADC_3;
#endif // HW_CHECK_MODE
}
void setPinConfigurationOverrides(void) {
}
void setSerialConfigurationOverrides(void) {
2020-05-02 19:27:20 -07:00
// why would MRE disable serial by default? we definitely have pads exposed
engineConfiguration->useSerialPort = false;
engineConfiguration->binarySerialTxPin = GPIO_UNASSIGNED;
engineConfiguration->binarySerialRxPin = GPIO_UNASSIGNED;
2020-05-02 19:27:20 -07:00
// engineConfiguration->consoleSerialTxPin = GPIO_UNASSIGNED;
// engineConfiguration->consoleSerialRxPin = GPIO_UNASSIGNED;
}
/**
* @brief Board-specific configuration code overrides.
2019-08-04 18:56:01 -07:00
*
* See also setDefaultEngineConfiguration
*
* @todo Add your board-specific code, if any.
*/
void setBoardConfigurationOverrides(void) {
setInjectorPins();
setIgnitionPins();
setLedPins();
setupVbatt();
setupTle8888();
setupEtb();
engineConfiguration->canTxPin = GPIOB_6;
engineConfiguration->canRxPin = GPIOB_12;
2019-09-12 04:29:38 -07:00
// MRE has a special main relay control low side pin
// rusEfi firmware is totally not involved with main relay control on microRusEfi board
// todo: maybe even set EFI_MAIN_RELAY_CONTROL to FALSE for MRE configuration
2019-09-14 13:03:04 -07:00
// TLE8888 half bridges (pushpull, lowside, or high-low) TLE8888_IN11 / TLE8888_OUT21
Tle8888 big update 1 (#1892) * smart gpio: fix tle8888 direct pin mapping for MRE * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 * TLE8888: cleanup * TLE8888: do not reset driver private data on WD/undervoltage reset * TLE8888: diagnostic updates * TLE8888 driver: BIG driver rework * TLE8888: check SPI answers for abnormal states Reply with other than requested register can be a sign of: -Power-On-Reset, then OpStat0 will be replyed -WatchDog reset, then FWDStat1 will be replyed -Invalid communication frame, then Diag0 will be replyed Keep tracking last accessed register and check with the next reply. * TLE8888: debug clean-up * TLE8888: implement spi array write This reduce CS inactive state time between two consequent accesses from 8.8 uS to 1.4 uS * TLE8888: fix PP outputs in OD mode * TLE8888: cleanup register definitions * TLE8888: run separate driver thread for each chip instance Calculating poll interval for few chips become more complex, avoid this running thread for each device. * TLE8888: fix cypress and kinetic compilation Both platforms define its own MAX and cause redifination error if common.h is included in driver. * MRE: update mapping.yaml and fix direct pin mapping for TLE8888 * TLE8888: diagnnostic: disable switch off in case of overcurrent For all output, use current limiting instead * TLE8888: check for overvoltage on OUT8..OUT13 * TLE8888: add TODO note about how to recover from failure condition Currently TLE8888 automaticly recovers only from overcurrent and (may be) overtemperature conditions. Short to bat cause output disable (bit in OECONFIG is reset) and needs driver/host intervention. * TLE8888: save few bytes of RAM * TLE8888: Lada Kalina is test mule for IDLE stepper on TLE8888 Don't forget to enable PP mode for TLE8888 outputs 21..24: uncomment line 1087 in tle8888.c * TLE8888: reorder code, cleanup * TLE8888: mode all debug/statisctic to per-chip struct * TLE8888: rework poll interval calculation * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 #2
2020-10-23 09:25:30 -07:00
// TLE8888_PIN_21: "35 - GP Out 1"
engineConfiguration->fuelPumpPin = TLE8888_PIN_21;
2019-09-02 08:07:34 -07:00
engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
engineConfiguration->spi3mosiPin = GPIOC_12;
engineConfiguration->spi3misoPin = GPIOC_11;
engineConfiguration->spi3sckPin = GPIOC_10;
2020-05-13 20:26:28 -07:00
engineConfiguration->sdCardCsPin = GPIOB_9;
CONFIG(is_enabled_spi_3) = true;
2020-05-13 20:26:28 -07:00
// engineConfiguration->isSdCardEnabled = true;
2019-09-08 08:17:27 -07:00
// TLE8888 high current low side: VVT2 IN9 / OUT5
// GPIOE_10: "3 - Lowside 2"
Tle8888 big update 1 (#1892) * smart gpio: fix tle8888 direct pin mapping for MRE * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 * TLE8888: cleanup * TLE8888: do not reset driver private data on WD/undervoltage reset * TLE8888: diagnostic updates * TLE8888 driver: BIG driver rework * TLE8888: check SPI answers for abnormal states Reply with other than requested register can be a sign of: -Power-On-Reset, then OpStat0 will be replyed -WatchDog reset, then FWDStat1 will be replyed -Invalid communication frame, then Diag0 will be replyed Keep tracking last accessed register and check with the next reply. * TLE8888: debug clean-up * TLE8888: implement spi array write This reduce CS inactive state time between two consequent accesses from 8.8 uS to 1.4 uS * TLE8888: fix PP outputs in OD mode * TLE8888: cleanup register definitions * TLE8888: run separate driver thread for each chip instance Calculating poll interval for few chips become more complex, avoid this running thread for each device. * TLE8888: fix cypress and kinetic compilation Both platforms define its own MAX and cause redifination error if common.h is included in driver. * MRE: update mapping.yaml and fix direct pin mapping for TLE8888 * TLE8888: diagnnostic: disable switch off in case of overcurrent For all output, use current limiting instead * TLE8888: check for overvoltage on OUT8..OUT13 * TLE8888: add TODO note about how to recover from failure condition Currently TLE8888 automaticly recovers only from overcurrent and (may be) overtemperature conditions. Short to bat cause output disable (bit in OECONFIG is reset) and needs driver/host intervention. * TLE8888: save few bytes of RAM * TLE8888: Lada Kalina is test mule for IDLE stepper on TLE8888 Don't forget to enable PP mode for TLE8888 outputs 21..24: uncomment line 1087 in tle8888.c * TLE8888: reorder code, cleanup * TLE8888: mode all debug/statisctic to per-chip struct * TLE8888: rework poll interval calculation * MRE: use TLE8888 pins instead of MCU gpios that drives TLE8888 #2
2020-10-23 09:25:30 -07:00
engineConfiguration->idle.solenoidPin = TLE8888_PIN_5;
2019-09-08 08:17:27 -07:00
2019-09-05 20:14:28 -07:00
// TLE8888_PIN_22: "34 - GP Out 2"
engineConfiguration->fanPin = TLE8888_PIN_22;
2019-09-05 20:14:28 -07:00
// "required" hardware is done - set some reasonable defaults
setupDefaultSensorInputs();
// Some sensible defaults for other options
setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR);
engineConfiguration->trigger.type = TT_TOOTHED_WHEEL_60_2;
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
setAlgorithm(LM_SPEED_DENSITY PASS_CONFIG_PARAMETER_SUFFIX);
engineConfiguration->specs.cylindersCount = 4;
engineConfiguration->specs.firingOrder = FO_1_3_4_2;
engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS; // IM_WASTED_SPARK
engineConfiguration->crankingInjectionMode = IM_SIMULTANEOUS;
engineConfiguration->injectionMode = IM_SIMULTANEOUS;//IM_BATCH;// IM_SEQUENTIAL;
}
void setAdcChannelOverrides(void) {
}
2019-11-06 17:05:44 -08:00
/**
* @brief Board-specific SD card configuration code overrides. Needed by bootloader code.
* @todo Add your board-specific code, if any.
*/
void setSdCardConfigurationOverrides(void) {
}