auto-sync
This commit is contained in:
parent
bc15cf88c7
commit
83b80e2fe9
|
@ -81,7 +81,7 @@
|
|||
|
||||
#define EFI_DENSO_ADC FALSE
|
||||
|
||||
#define EFI_CAN_SUPPORT FALSE
|
||||
#define EFI_CAN_SUPPORT TRUE
|
||||
|
||||
#define EFI_HD44780_LCD TRUE
|
||||
|
||||
|
|
|
@ -480,6 +480,7 @@ typedef struct {
|
|||
bool_t hasAfrSensor : 1; // bit 2
|
||||
bool_t useConstantDwellDuringCranking : 1; // bit 3
|
||||
bool_t isDigitalChartEnabled : 1; // bit 4
|
||||
bool_t isCanEnabled : 1; // bit 5
|
||||
// that's the next 32 bit field
|
||||
int hasCltSensor;
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
#if EFI_CAN_SUPPORT || defined(__DOXYGEN__)
|
||||
|
||||
EXTERN_ENGINE;
|
||||
EXTERN_ENGINE
|
||||
;
|
||||
|
||||
static int canReadCounter = 0;
|
||||
static Logging logger;
|
||||
|
@ -42,8 +43,7 @@ extern board_configuration_s *board_configuration;
|
|||
*/
|
||||
static const CANConfig canConfig = {
|
||||
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||||
CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
|
||||
CAN_BTR_TS1(8) | CAN_BTR_BRP(6) };
|
||||
CAN_BTR_SJW(0) | CAN_BTR_TS2(1) | CAN_BTR_TS1(8) | CAN_BTR_BRP(6) };
|
||||
|
||||
static CANRxFrame rxBuffer;
|
||||
static CANTxFrame txmsg;
|
||||
|
@ -59,13 +59,12 @@ static float engine_clt = 0;
|
|||
static void printPacket(CANRxFrame *rx) {
|
||||
// scheduleMsg(&logger, "CAN FMI %x", rx->FMI);
|
||||
// scheduleMsg(&logger, "TIME %x", rx->TIME);
|
||||
scheduleMsg(&logger, "SID %x/%x %x %x %x %x %x %x %x %x", rx->SID, rx->DLC,
|
||||
rx->data8[0], rx->data8[1], rx->data8[2], rx->data8[3],
|
||||
rx->data8[4], rx->data8[5], rx->data8[6], rx->data8[7]);
|
||||
scheduleMsg(&logger, "SID %x/%x %x %x %x %x %x %x %x %x", rx->SID, rx->DLC, rx->data8[0], rx->data8[1],
|
||||
rx->data8[2], rx->data8[3], rx->data8[4], rx->data8[5], rx->data8[6], rx->data8[7]);
|
||||
|
||||
if (rx->SID == CAN_BMW_E46_CLUSTER_STATUS) {
|
||||
int odometerKm = 10 * (rx->data8[1] << 8) + rx->data8[0];
|
||||
int odometerMi = (int)(odometerKm * 0.621371);
|
||||
int odometerMi = (int) (odometerKm * 0.621371);
|
||||
scheduleMsg(&logger, "GOT odometerKm %d", odometerKm);
|
||||
scheduleMsg(&logger, "GOT odometerMi %d", odometerMi);
|
||||
int timeValue = (rx->data8[4] << 8) + rx->data8[3];
|
||||
|
@ -90,34 +89,34 @@ 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 );
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
|
||||
commonTxInit(CAN_BMW_E46_RPM);
|
||||
setShortValue(&txmsg, (int)(engine_rpm * 6.4), 2);
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE );
|
||||
setShortValue(&txmsg, (int) (engine_rpm * 6.4), 2);
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
|
||||
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 );
|
||||
setShortValue(&txmsg, (int) ((engine_clt + 48.373) / 0.75), 1);
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
}
|
||||
|
||||
static void canDashboardFiat(void) {
|
||||
//Fiat Dashboard
|
||||
commonTxInit(CAN_FIAT_MOTOR_INFO);
|
||||
setShortValue(&txmsg, (int)(engine_clt - 40), 3); //Coolant Temp
|
||||
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 );
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
}
|
||||
|
||||
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 );
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
|
||||
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 );
|
||||
setShortValue(&txmsg, (int) ((engine_clt + 48.373) / 0.75), 1); //Coolant Temp
|
||||
canTransmit(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &txmsg, TIME_INFINITE);
|
||||
}
|
||||
|
||||
static void canInfoNBCBroadcast(can_nbc_e typeOfNBC) {
|
||||
|
@ -142,7 +141,7 @@ static void enableCanRead(int value) {
|
|||
|
||||
static void canRead(void) {
|
||||
scheduleMsg(&logger, "waiting for CAN");
|
||||
canReceive(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &rxBuffer, TIME_INFINITE );
|
||||
canReceive(&EFI_CAN_DEVICE, CAN_ANY_MAILBOX, &rxBuffer, TIME_INFINITE);
|
||||
|
||||
canReadCounter++;
|
||||
printPacket(&rxBuffer);
|
||||
|
@ -158,13 +157,12 @@ static void writeStateToCan(void) {
|
|||
static msg_t canThread(void *arg) {
|
||||
chRegSetThreadName("CAN");
|
||||
while (true) {
|
||||
if(engineConfiguration->canWriteEnabled)
|
||||
if (engineConfiguration->canWriteEnabled)
|
||||
writeStateToCan();
|
||||
|
||||
if(engineConfiguration->canReadEnabled)
|
||||
if (engineConfiguration->canReadEnabled)
|
||||
canRead(); // todo: since this is a blocking operation, do we need a separate thread for 'write'?
|
||||
|
||||
|
||||
chThdSleepMilliseconds(engineConfiguration->can_sleep_period);
|
||||
}
|
||||
#if defined __GNUC__
|
||||
|
@ -175,12 +173,15 @@ 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, engineConfiguration->canWriteEnabled);
|
||||
scheduleMsg(&logger, "canReadEnabled=%d canWriteEnabled=%d", engineConfiguration->canReadEnabled,
|
||||
engineConfiguration->canWriteEnabled);
|
||||
|
||||
scheduleMsg(&logger, "CAN rx count %d", canReadCounter);
|
||||
}
|
||||
|
||||
void initCan(void) {
|
||||
if (!engineConfiguration->isCanEnabled)
|
||||
return;
|
||||
initLogging(&logger, "CAN driver");
|
||||
|
||||
#if STM32_CAN_USE_CAN2
|
||||
|
@ -192,7 +193,7 @@ void initCan(void) {
|
|||
#endif
|
||||
|
||||
canStart(&EFI_CAN_DEVICE, &canConfig);
|
||||
chThdCreateStatic(canTreadStack, sizeof(canTreadStack), NORMALPRIO, (tfunc_t) canThread, NULL );
|
||||
chThdCreateStatic(canTreadStack, sizeof(canTreadStack), NORMALPRIO, (tfunc_t) canThread, NULL);
|
||||
|
||||
mySetPadMode2("CAN TX", boardConfiguration->canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
||||
mySetPadMode2("CAN RX", boardConfiguration->canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||
|
|
|
@ -256,7 +256,7 @@ void firmwareError(const char *fmt, ...) {
|
|||
}
|
||||
}
|
||||
|
||||
static char UNUSED_RAM_SIZE[3000];
|
||||
static char UNUSED_RAM_SIZE[2000];
|
||||
|
||||
static char UNUSED_CCM_SIZE[9000] CCM_OPTIONAL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue