mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Make CAN-FD frequence configurable
This commit is contained in:
parent
bf7d10c825
commit
454a4565c0
5 changed files with 26 additions and 4 deletions
|
@ -40,12 +40,15 @@ ACAN_ESP32_Settings* settingsespcan;
|
|||
static uint32_t QUARTZ_FREQUENCY;
|
||||
SPIClass SPI2515;
|
||||
uint8_t user_selected_can_addon_crystal_frequency_mhz = 0;
|
||||
|
||||
ACAN2515* can2515;
|
||||
ACAN2515Settings* settings2515;
|
||||
|
||||
static ACAN2515_Buffer16 gBuffer;
|
||||
|
||||
static ACAN2517FDSettings::Oscillator quartz_fd_frequency;
|
||||
SPIClass SPI2517;
|
||||
uint8_t user_selected_canfd_addon_crystal_frequency_mhz = 0;
|
||||
ACAN2517FD* canfd;
|
||||
ACAN2517FDSettings* settings2517;
|
||||
bool use_canfd_as_can = false;
|
||||
|
@ -61,6 +64,14 @@ bool init_CAN() {
|
|||
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);
|
||||
if (nativeIt != can_receivers.end()) {
|
||||
auto se_pin = esp32hal->CAN_SE_PIN();
|
||||
|
@ -181,9 +192,8 @@ bool init_CAN() {
|
|||
logging.println("CAN FD add-on (ESP32+MCP2517) selected");
|
||||
SPI2517.begin(sck_pin, sdo_pin, sdi_pin);
|
||||
auto bitRate = (int)speed * 1000UL;
|
||||
settings2517 = new ACAN2517FDSettings(
|
||||
CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ, bitRate,
|
||||
DataBitRateFactor::x4); // Arbitration bit rate: 250/500 kbit/s, data bit rate: 1/2 Mbit/s
|
||||
settings2517 = new ACAN2517FDSettings(quartz_fd_frequency, bitRate, DataBitRateFactor::x4);
|
||||
// Arbitration bit rate: 250/500 kbit/s, data bit rate: 1/2 Mbit/s
|
||||
|
||||
// ListenOnly / Normal20B / NormalFDs
|
||||
settings2517->mRequestedMode = use_canfd_as_can ? ACAN2517FDSettings::Normal20B : ACAN2517FDSettings::NormalFD;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
extern bool use_canfd_as_can;
|
||||
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 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_ignore_contactors = settings.getBool("INVICNT", false);
|
||||
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_tesla_digital_HVIL = settings.getBool("DIGITALHVIL", false);
|
||||
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));
|
||||
}
|
||||
|
||||
if (var == "CANFDFREQ") {
|
||||
return String(settings.getUInt("CANFDFREQ", 40));
|
||||
}
|
||||
|
||||
if (var == "PRECHGMS") {
|
||||
return String(settings.getUInt("PRECHGMS", 100));
|
||||
}
|
||||
|
@ -1079,9 +1083,12 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<label>Can-addon frequency Mhz: </label>
|
||||
<label>CAN addon crystal (Mhz): </label>
|
||||
<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'>
|
||||
%EQSTOP%
|
||||
</select>
|
||||
|
|
|
@ -554,6 +554,9 @@ void init_webserver() {
|
|||
} else if (p->name() == "CANFREQ") {
|
||||
auto type = atoi(p->value().c_str());
|
||||
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") {
|
||||
auto type = atoi(p->value().c_str());
|
||||
settings.saveUInt("PRECHGMS", type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue