mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
Merge pull request #1512 from dalathegreat/improvement/configurable-fd-frequency
Improvement: Make CAN-FD frequency configurable
This commit is contained in:
commit
42353efdff
5 changed files with 26 additions and 4 deletions
|
@ -40,12 +40,15 @@ ACAN_ESP32_Settings* settingsespcan;
|
||||||
static uint32_t QUARTZ_FREQUENCY;
|
static uint32_t QUARTZ_FREQUENCY;
|
||||||
SPIClass SPI2515;
|
SPIClass SPI2515;
|
||||||
uint8_t user_selected_can_addon_crystal_frequency_mhz = 0;
|
uint8_t user_selected_can_addon_crystal_frequency_mhz = 0;
|
||||||
|
|
||||||
ACAN2515* can2515;
|
ACAN2515* can2515;
|
||||||
ACAN2515Settings* settings2515;
|
ACAN2515Settings* settings2515;
|
||||||
|
|
||||||
static ACAN2515_Buffer16 gBuffer;
|
static ACAN2515_Buffer16 gBuffer;
|
||||||
|
|
||||||
|
static ACAN2517FDSettings::Oscillator quartz_fd_frequency;
|
||||||
SPIClass SPI2517;
|
SPIClass SPI2517;
|
||||||
|
uint8_t user_selected_canfd_addon_crystal_frequency_mhz = 0;
|
||||||
ACAN2517FD* canfd;
|
ACAN2517FD* canfd;
|
||||||
ACAN2517FDSettings* settings2517;
|
ACAN2517FDSettings* settings2517;
|
||||||
bool use_canfd_as_can = false;
|
bool use_canfd_as_can = false;
|
||||||
|
@ -61,6 +64,14 @@ bool init_CAN() {
|
||||||
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
|
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user_selected_canfd_addon_crystal_frequency_mhz == 20) {
|
||||||
|
quartz_fd_frequency = ACAN2517FDSettings::OSC_20MHz;
|
||||||
|
} else if (user_selected_canfd_addon_crystal_frequency_mhz == 40) {
|
||||||
|
quartz_fd_frequency = ACAN2517FDSettings::OSC_40MHz;
|
||||||
|
} else { // Default to 40MHz incase value invalid/not set
|
||||||
|
quartz_fd_frequency = ACAN2517FDSettings::OSC_40MHz;
|
||||||
|
}
|
||||||
|
|
||||||
auto nativeIt = can_receivers.find(CAN_NATIVE);
|
auto nativeIt = can_receivers.find(CAN_NATIVE);
|
||||||
if (nativeIt != can_receivers.end()) {
|
if (nativeIt != can_receivers.end()) {
|
||||||
auto se_pin = esp32hal->CAN_SE_PIN();
|
auto se_pin = esp32hal->CAN_SE_PIN();
|
||||||
|
@ -181,9 +192,8 @@ bool init_CAN() {
|
||||||
logging.println("CAN FD add-on (ESP32+MCP2517) selected");
|
logging.println("CAN FD add-on (ESP32+MCP2517) selected");
|
||||||
SPI2517.begin(sck_pin, sdo_pin, sdi_pin);
|
SPI2517.begin(sck_pin, sdo_pin, sdi_pin);
|
||||||
auto bitRate = (int)speed * 1000UL;
|
auto bitRate = (int)speed * 1000UL;
|
||||||
settings2517 = new ACAN2517FDSettings(
|
settings2517 = new ACAN2517FDSettings(quartz_fd_frequency, bitRate, DataBitRateFactor::x4);
|
||||||
CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ, bitRate,
|
// Arbitration bit rate: 250/500 kbit/s, data bit rate: 1/2 Mbit/s
|
||||||
DataBitRateFactor::x4); // Arbitration bit rate: 250/500 kbit/s, data bit rate: 1/2 Mbit/s
|
|
||||||
|
|
||||||
// ListenOnly / Normal20B / NormalFDs
|
// ListenOnly / Normal20B / NormalFDs
|
||||||
settings2517->mRequestedMode = use_canfd_as_can ? ACAN2517FDSettings::Normal20B : ACAN2517FDSettings::NormalFD;
|
settings2517->mRequestedMode = use_canfd_as_can ? ACAN2517FDSettings::Normal20B : ACAN2517FDSettings::NormalFD;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
extern bool use_canfd_as_can;
|
extern bool use_canfd_as_can;
|
||||||
extern uint8_t user_selected_can_addon_crystal_frequency_mhz;
|
extern uint8_t user_selected_can_addon_crystal_frequency_mhz;
|
||||||
|
extern uint8_t user_selected_canfd_addon_crystal_frequency_mhz;
|
||||||
|
|
||||||
void dump_can_frame(CAN_frame& frame, frameDirection msgDir);
|
void dump_can_frame(CAN_frame& frame, frameDirection msgDir);
|
||||||
void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface);
|
void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface);
|
||||||
|
|
|
@ -102,6 +102,7 @@ void init_stored_settings() {
|
||||||
user_selected_inverter_battery_type = settings.getUInt("INVBTYPE", 0);
|
user_selected_inverter_battery_type = settings.getUInt("INVBTYPE", 0);
|
||||||
user_selected_inverter_ignore_contactors = settings.getBool("INVICNT", false);
|
user_selected_inverter_ignore_contactors = settings.getBool("INVICNT", false);
|
||||||
user_selected_can_addon_crystal_frequency_mhz = settings.getUInt("CANFREQ", 8);
|
user_selected_can_addon_crystal_frequency_mhz = settings.getUInt("CANFREQ", 8);
|
||||||
|
user_selected_canfd_addon_crystal_frequency_mhz = settings.getUInt("CANFDFREQ", 40);
|
||||||
user_selected_LEAF_interlock_mandatory = settings.getBool("INTERLOCKREQ", false);
|
user_selected_LEAF_interlock_mandatory = settings.getBool("INTERLOCKREQ", false);
|
||||||
user_selected_tesla_digital_HVIL = settings.getBool("DIGITALHVIL", false);
|
user_selected_tesla_digital_HVIL = settings.getBool("DIGITALHVIL", false);
|
||||||
user_selected_tesla_GTW_country = settings.getUInt("GTWCOUNTRY", 0);
|
user_selected_tesla_GTW_country = settings.getUInt("GTWCOUNTRY", 0);
|
||||||
|
|
|
@ -637,6 +637,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
||||||
return String(settings.getUInt("CANFREQ", 8));
|
return String(settings.getUInt("CANFREQ", 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (var == "CANFDFREQ") {
|
||||||
|
return String(settings.getUInt("CANFDFREQ", 40));
|
||||||
|
}
|
||||||
|
|
||||||
if (var == "PRECHGMS") {
|
if (var == "PRECHGMS") {
|
||||||
return String(settings.getUInt("PRECHGMS", 100));
|
return String(settings.getUInt("PRECHGMS", 100));
|
||||||
}
|
}
|
||||||
|
@ -1079,8 +1083,11 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label>Can-addon frequency Mhz: </label>
|
<label>CAN addon crystal (Mhz): </label>
|
||||||
<input name='CANFREQ' type='text' value="%CANFREQ%" pattern="^[0-9]+$" />
|
<input name='CANFREQ' type='text' value="%CANFREQ%" pattern="^[0-9]+$" />
|
||||||
|
|
||||||
|
<label>CAN-FD-addon crystal (Mhz): </label>
|
||||||
|
<input name='CANFDFREQ' type='text' value="%CANFDFREQ%" pattern="^[0-9]+$" />
|
||||||
|
|
||||||
<label>Equipment stop button: </label><select name='EQSTOP'>
|
<label>Equipment stop button: </label><select name='EQSTOP'>
|
||||||
%EQSTOP%
|
%EQSTOP%
|
||||||
|
|
|
@ -554,6 +554,9 @@ void init_webserver() {
|
||||||
} else if (p->name() == "CANFREQ") {
|
} else if (p->name() == "CANFREQ") {
|
||||||
auto type = atoi(p->value().c_str());
|
auto type = atoi(p->value().c_str());
|
||||||
settings.saveUInt("CANFREQ", type);
|
settings.saveUInt("CANFREQ", type);
|
||||||
|
} else if (p->name() == "CANFDFREQ") {
|
||||||
|
auto type = atoi(p->value().c_str());
|
||||||
|
settings.saveUInt("CANFDFREQ", type);
|
||||||
} else if (p->name() == "PRECHGMS") {
|
} else if (p->name() == "PRECHGMS") {
|
||||||
auto type = atoi(p->value().c_str());
|
auto type = atoi(p->value().c_str());
|
||||||
settings.saveUInt("PRECHGMS", type);
|
settings.saveUInt("PRECHGMS", type);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue