auto-sync

This commit is contained in:
rusEfi 2014-12-15 19:03:49 -06:00
parent 939c8a6d71
commit 09c525afcd
11 changed files with 127 additions and 29 deletions

View File

@ -17,6 +17,7 @@ typedef enum {
CAN_BUS_NBC_BMW = 0,
CAN_BUS_NBC_FIAT = 1,
CAN_BUS_NBC_VAG = 2,
CAN_BUS_MAZDA_RX8 = 3,
Internal_ForceMyEnumIntSize_can_nbc = ENUM_SIZE_HACK,
} can_nbc_e;

View File

@ -298,6 +298,8 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
engineConfiguration->mafAdcChannel = EFI_ADC_0;
engineConfiguration->afrSensor.afrAdcChannel = EFI_ADC_14;
engineConfiguration->cylinderBore = 87.5;
initEgoSensor(&engineConfiguration->afrSensor, ES_BPSX_D1);
engineConfiguration->globalFuelCorrection = 1;

View File

@ -399,6 +399,7 @@ typedef struct {
int canReadEnabled;
int canWriteEnabled;
// offset 968
can_nbc_e can_nbc_type;
int can_sleep_period;
@ -544,7 +545,12 @@ typedef struct {
float knockDetectionWindowStart;
float knockDetectionWindowEnd;
int unused3[85];
/**
* Cylinder diameter, in mm.
*/
float cylinderBore;
int unused3[84];
} engine_configuration_s;

View File

@ -69,7 +69,7 @@ float interpolate(float x1, float y1, float x2, float y2, float x) {
* @returns the highest index within sorted array such that array[i] is greater than or equal to the parameter
* @note If the parameter is smaller than the first element of the array, -1 is returned.
*/
int findIndex(float array[], int size, float value) {
int findIndex(const float array[], int size, float value) {
efiAssert(!cisnan(value), "NaN in findIndex", 0);
if (value < array[0])

View File

@ -10,7 +10,7 @@
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
int findIndex(float array[], int size, float value);
int findIndex(const float array[], int size, float value);
float interpolate(float x1, float y1, float x2, float y2, float x);
float interpolate2d(float value, float bin[], float values[], int size);
float interpolate3d(float x, float xBin[], int xBinSize, float y, float yBin[], int yBinSize, float* map[]);

View File

@ -664,6 +664,10 @@ static void setSpiMode(int index, bool mode) {
static void enableOrDisable(const char *param, bool isEnabled) {
if (strEqualCaseInsensitive(param, "fastadc")) {
boardConfiguration->isFastAdcEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "can_read")) {
engineConfiguration->canReadEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "can_write")) {
engineConfiguration->canWriteEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "injection")) {
engineConfiguration->isInjectionEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "trigger_details")) {

View File

@ -1,5 +1,5 @@
/**
* @file HIP9011.c
* @file HIP9011.cpp
* @brief HIP9011/TPIC8101 driver
*
* pin1 VDD
@ -10,6 +10,9 @@
* pin12 Slave Data In - MOSI
* pin13 SPI clock - SCLK
*
* http://www.ti.com/lit/ds/symlink/tpic8101.pdf
* http://www.intersil.com/content/dam/Intersil/documents/an97/an9770.pdf
* http://e2e.ti.com/cfs-file/__key/telligent-evolution-components-attachments/00-26-01-00-00-42-36-40/TPIC8101-Training.pdf
*
* SPI frequency: 5MHz
*
@ -19,12 +22,25 @@
#include "main.h"
#include "engine.h"
#include "settings.h"
#include "pin_repository.h"
#if EFI_HIP_9011
#define HIP9011_CS_PORT GPIOE
#define HIP9011_CS_PIN 11
// 0b01000000
#define SET_PRESCALER_CMD 0x40
// 0b11100000
#define SET_CHANNEL_CMD 0xE0
// 0b00000000
#define SET_BAND_PASS_CMD 0x0
// 0b01110001
//#define HIP_ADVANCED_MODE 0x71
static Logging logger;
static THD_WORKING_AREA(htThreadStack, UTILITY_THREAD_STACK_SIZE);
@ -53,19 +69,17 @@ static unsigned char rx_buff[8];
static SPIDriver *driver = &SPID2;
// 0b01110001
#define HIP_ADVANCED_MODE 0x71
static msg_t ivThread(int param) {
chRegSetThreadName("HIP");
int counter = 0;
// tx_buff[0] = 0b11100001;
tx_buff[0] = HIP_ADVANCED_MODE;
// 4MHz
tx_buff[0] = SET_PRESCALER_CMD;
tx_buff[4] = 0xF8; // 0b11111000;
// channel #1
tx_buff[4] = SET_CHANNEL_CMD;
while (TRUE) {
chThdSleepMilliseconds(10);
@ -74,8 +88,8 @@ static msg_t ivThread(int param) {
spiSelect(driver);
spiStartExchange(driver, 8, tx_buff, rx_buff);
// spiUnselect(driver);
spiStartExchange(driver, 2, tx_buff, rx_buff);
spiUnselect(driver);
}
#if defined __GNUC__
@ -94,6 +108,15 @@ EXTERN_ENGINE
static const int integratorValues[INT_TIME_COUNT] = { 40, 45, 50, 55, 60, 65, 70, 75, 80, 90, 100, 110, 120, 130, 140,
150, 160, 180, 200, 220, 240, 260, 280, 300, 320, 360, 400, 440, 480, 520, 560, 600 };
#define BAND_LOOKUP_SIZE 64
static const float bandFreqLookup[BAND_LOOKUP_SIZE] = {1.22, 1.26, 1.31, 1.35, 1.4, 1.45, 1.51, 1.57,
1.63, 1.71, 1.78, 1.87, 1.96, 2.07, 2.18, 2.31, 2.46, 2.54, 2.62, 2.71, 2.81, 2.92, 3.03,
3.15, 3.28, 3.43, 3.59, 3.76, 3.95, 4.16 , 4.39, 4.66, 4.95, 5.12, 5.29, 5.48, 5.68, 5.9,
6.12, 6.37, 6.64, 6.94, 7.27, 7.63, 8.02, 8.46, 8.95, 9.5, 10.12, 10.46, 10.83, 11.22, 11.65,
12.1, 12.6, 13.14, 13.72, 14.36, 15.07, 15.84, 16.71, 17.67, 18.76, 19.98};
#define PIF 3.14159f
static float rpmLookup[INT_TIME_COUNT];
@ -118,6 +141,30 @@ static void prepareRpmLookup(engine_configuration_s *engineConfiguration) {
}
}
#define BAND(bore) (900 / (PIF * (bore) / 2))
static int bandIndex;
static void showHipInfo(void) {
printSpiState(&logger, boardConfiguration);
scheduleMsg(&logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore));
scheduleMsg(&logger, "band index=%d", bandIndex);
scheduleMsg(&logger, "spi= CS=%s", hwPortname(boardConfiguration->hip9011CsPin));
}
void setHip9011FrankensoPinout(void) {
/**
* SPI on PB13/14/15
* ChipSelect is hard-wired
*/
boardConfiguration->isHip9011Enabled = true;
//boardConfiguration->hip9011CsPin =
boardConfiguration->hip9011IntHoldPin = GPIOB_11;
}
void initHip9011(void) {
if (!boardConfiguration->isHip9011Enabled)
return;
@ -126,7 +173,12 @@ void initHip9011(void) {
print("Starting HIP9011/TPIC8101 driver\r\n");
spiStart(driver, &spicfg);
chThdCreateStatic(htThreadStack, sizeof(htThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL);
// chThdCreateStatic(htThreadStack, sizeof(htThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL);
bandIndex = findIndex(bandFreqLookup, BAND_LOOKUP_SIZE, BAND(engineConfiguration->cylinderBore));
addConsoleAction("hipinfo", showHipInfo);
}
#endif

View File

@ -10,5 +10,6 @@
#define HIP9011_H_
void initHip9011(void);
void setHip9011FrankensoPinout(void);
#endif /* HIP9011_H_ */

View File

@ -23,6 +23,8 @@ EXTERN_ENGINE
;
static int canReadCounter = 0;
static int can_write_ok = 0;
static int can_write_not_ok = 0;
static Logging logger;
static THD_WORKING_AREA(canTreadStack, UTILITY_THREAD_STACK_SIZE);
@ -85,19 +87,48 @@ static void commonTxInit(int eid) {
txmsg.DLC = 8;
}
static void sendMessage(void) {
msg_t result = canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
if(result==RDY_OK) {
can_write_ok++;
} else {
can_write_not_ok++;
}
}
static void canDashboardBMW(void) {
//BMW Dashboard
commonTxInit(CAN_BMW_E46_SPEED);
setShortValue(&txmsg, 10 * 8, 1);
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
commonTxInit(CAN_BMW_E46_RPM);
setShortValue(&txmsg, (int) (engine_rpm * 6.4), 2);
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
commonTxInit(CAN_BMW_E46_DME2);
setShortValue(&txmsg, (int) ((engine_clt + 48.373) / 0.75), 1);
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
}
static void canMazdaRX8(void) {
commonTxInit(CAN_MAZDA_RX_RPM_SPEED);
setShortValue(&txmsg, engine_rpm * 4, 1);
setShortValue(&txmsg, 0xFFFF, 3);
setShortValue(&txmsg, 123+10000, 5);
setShortValue(&txmsg, 0, 7);
sendMessage();
// my_data[0] = (RPM * 4) / 256; // rpm
// my_data[1] = (RPM * 4) % 256; // rpm
// my_data[2] = 0xFF; // Unknown, 0xFF from 'live'.
// my_data[3] = 0xFF; // Unknown, 0xFF from 'live'.
// my_data[4] = (kmhspeed+10000) / 256; //speed
// my_data[5] = (kmhspeed+10000) % 256; //speed
// my_data[6] = 0x00; // Unknown possible accelerator pedel if Madox is correc
// my_data[7] = 0x00; //Unknown
}
static void canDashboardFiat(void) {
@ -105,18 +136,18 @@ static void canDashboardFiat(void) {
commonTxInit(CAN_FIAT_MOTOR_INFO);
setShortValue(&txmsg, (int) (engine_clt - 40), 3); //Coolant Temp
setShortValue(&txmsg, engine_rpm / 32, 6); //RPM
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
}
static void canDashboardVAG(void) {
//VAG Dashboard
commonTxInit(CAN_VAG_RPM);
setShortValue(&txmsg, engine_rpm * 4, 2); //RPM
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
commonTxInit(CAN_VAG_CLT);
setShortValue(&txmsg, (int) ((engine_clt + 48.373) / 0.75), 1); //Coolant Temp
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
sendMessage();
}
static void canInfoNBCBroadcast(can_nbc_e typeOfNBC) {
@ -130,15 +161,14 @@ static void canInfoNBCBroadcast(can_nbc_e typeOfNBC) {
case CAN_BUS_NBC_VAG:
canDashboardVAG();
break;
case CAN_BUS_MAZDA_RX8:
canMazdaRX8();
break;
default:
break;
}
}
static void enableCanRead(int value) {
engineConfiguration->canReadEnabled = value;
}
static void canRead(void) {
scheduleMsg(&logger, "waiting for CAN");
canReceive(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &rxBuffer, TIME_INFINITE);
@ -149,7 +179,7 @@ static void canRead(void) {
static void writeStateToCan(void) {
engine_rpm = getRpm();
engine_clt = getCoolantTemperature(engine);
engine_clt = 123;//getCoolantTemperature(engine);
canInfoNBCBroadcast(engineConfiguration->can_nbc_type);
}
@ -173,10 +203,13 @@ static msg_t canThread(void *arg) {
static void canInfo(void) {
scheduleMsg(&logger, "CAN TX %s", hwPortname(boardConfiguration->canTxPin));
scheduleMsg(&logger, "CAN RX %s", hwPortname(boardConfiguration->canRxPin));
scheduleMsg(&logger, "canReadEnabled=%d canWriteEnabled=%d", engineConfiguration->canReadEnabled,
scheduleMsg(&logger, "type=%d canReadEnabled=%d canWriteEnabled=%d",
engineConfiguration->can_nbc_type,
engineConfiguration->canReadEnabled,
engineConfiguration->canWriteEnabled);
scheduleMsg(&logger, "CAN rx count %d", canReadCounter);
scheduleMsg(&logger, "CAN rx count %d/tx ok %d/tx not ok %d", canReadCounter,
can_write_ok, can_write_not_ok);
}
void initCan(void) {
@ -198,8 +231,6 @@ void initCan(void) {
mySetPadMode2("CAN TX", boardConfiguration->canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
mySetPadMode2("CAN RX", boardConfiguration->canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
addConsoleActionI("enable_can_read", enableCanRead);
addConsoleAction("caninfo", canInfo);
}

View File

@ -19,6 +19,7 @@
#define CAN_BMW_E46_DME2 0x329
#define CAN_BMW_E46_CLUSTER_STATUS 0x613
#define CAN_FIAT_MOTOR_INFO 0x561
#define CAN_MAZDA_RX_RPM_SPEED 0x201
#define CAN_VAG_RPM 0x280
#define CAN_VAG_CLT 0x289

View File

@ -265,5 +265,5 @@ int getRusEfiVersion(void) {
return 1; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE == 0)
return 1; // this is here to make the compiler happy about the unused array
return 20141214;
return 20141215;
}