mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
Merge pull request #1503 from dalathegreat/bugfix/logging-unreliable
Bugfix: Make setup() unable to return early
This commit is contained in:
commit
c6ad1f8afe
6 changed files with 19 additions and 32 deletions
|
@ -493,7 +493,7 @@ void setup() {
|
||||||
init_serial();
|
init_serial();
|
||||||
|
|
||||||
// We print this after setting up serial, so that is also printed if configured to do so
|
// We print this after setting up serial, so that is also printed if configured to do so
|
||||||
logging.printf("Battery emulator %s build " __DATE__ " " __TIME__ "\n", version_number);
|
DEBUG_PRINTF("Battery emulator %s build " __DATE__ " " __TIME__ "\n", version_number);
|
||||||
|
|
||||||
init_events();
|
init_events();
|
||||||
|
|
||||||
|
@ -504,43 +504,28 @@ void setup() {
|
||||||
&connectivity_loop_task, esp32hal->WIFICORE());
|
&connectivity_loop_task, esp32hal->WIFICORE());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!led_init()) {
|
led_init();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (datalayer.system.info.CAN_SD_logging_active || datalayer.system.info.SD_logging_active) {
|
if (datalayer.system.info.CAN_SD_logging_active || datalayer.system.info.SD_logging_active) {
|
||||||
xTaskCreatePinnedToCore((TaskFunction_t)&logging_loop, "logging_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
xTaskCreatePinnedToCore((TaskFunction_t)&logging_loop, "logging_loop", 4096, NULL, TASK_CONNECTIVITY_PRIO,
|
||||||
&logging_loop_task, esp32hal->WIFICORE());
|
&logging_loop_task, esp32hal->WIFICORE());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!init_contactors()) {
|
init_contactors();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!init_precharge_control()) {
|
init_precharge_control();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_charger();
|
setup_charger();
|
||||||
|
setup_inverter();
|
||||||
if (!setup_inverter()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setup_battery();
|
setup_battery();
|
||||||
setup_can_shunt();
|
setup_can_shunt();
|
||||||
|
|
||||||
// Init CAN only after any CAN receivers have had a chance to register.
|
// Init CAN only after any CAN receivers have had a chance to register.
|
||||||
if (!init_CAN()) {
|
init_CAN();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!init_rs485()) {
|
init_rs485();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!init_equipment_stop_button()) {
|
init_equipment_stop_button();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// BOOT button at runtime is used as an input for various things
|
// BOOT button at runtime is used as an input for various things
|
||||||
pinMode(0, INPUT_PULLUP);
|
pinMode(0, INPUT_PULLUP);
|
||||||
|
@ -569,9 +554,7 @@ void setup() {
|
||||||
// Start tasks
|
// Start tasks
|
||||||
|
|
||||||
if (mqtt_enabled) {
|
if (mqtt_enabled) {
|
||||||
if (!init_mqtt()) {
|
init_mqtt();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, NULL, TASK_MQTT_PRIO, &mqtt_loop_task,
|
xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, NULL, TASK_MQTT_PRIO, &mqtt_loop_task,
|
||||||
esp32hal->WIFICORE());
|
esp32hal->WIFICORE());
|
||||||
|
@ -580,7 +563,7 @@ void setup() {
|
||||||
xTaskCreatePinnedToCore((TaskFunction_t)&core_loop, "core_loop", 4096, NULL, TASK_CORE_PRIO, &main_loop_task,
|
xTaskCreatePinnedToCore((TaskFunction_t)&core_loop, "core_loop", 4096, NULL, TASK_CORE_PRIO, &main_loop_task,
|
||||||
esp32hal->CORE_FUNCTION_CORE());
|
esp32hal->CORE_FUNCTION_CORE());
|
||||||
|
|
||||||
DEBUG_PRINTF("setup() complete\n");
|
DEBUG_PRINTF("Setup complete!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop empty, all functionality runs in tasks
|
// Loop empty, all functionality runs in tasks
|
||||||
|
|
|
@ -74,6 +74,7 @@ bool init_contactors() {
|
||||||
auto precPin = esp32hal->PRECHARGE_PIN();
|
auto precPin = esp32hal->PRECHARGE_PIN();
|
||||||
|
|
||||||
if (!esp32hal->alloc_pins(contactors, posPin, negPin, precPin)) {
|
if (!esp32hal->alloc_pins(contactors, posPin, negPin, precPin)) {
|
||||||
|
DEBUG_PRINTF("GPIO controlled contactor setup failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +98,7 @@ bool init_contactors() {
|
||||||
if (contactor_control_enabled_double_battery) {
|
if (contactor_control_enabled_double_battery) {
|
||||||
auto second_contactors = esp32hal->SECOND_BATTERY_CONTACTORS_PIN();
|
auto second_contactors = esp32hal->SECOND_BATTERY_CONTACTORS_PIN();
|
||||||
if (!esp32hal->alloc_pins(contactors, second_contactors)) {
|
if (!esp32hal->alloc_pins(contactors, second_contactors)) {
|
||||||
|
DEBUG_PRINTF("Secondary battery contactor control setup failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ bool init_contactors() {
|
||||||
if (periodic_bms_reset || remote_bms_reset || esp32hal->always_enable_bms_power()) {
|
if (periodic_bms_reset || remote_bms_reset || esp32hal->always_enable_bms_power()) {
|
||||||
auto pin = esp32hal->BMS_POWER();
|
auto pin = esp32hal->BMS_POWER();
|
||||||
if (!esp32hal->alloc_pins("BMS power", pin)) {
|
if (!esp32hal->alloc_pins("BMS power", pin)) {
|
||||||
|
DEBUG_PRINTF("BMS power setup failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
|
|
|
@ -31,13 +31,11 @@ bool init_precharge_control() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup PWM Channel Frequency and Resolution
|
|
||||||
logging.printf("Precharge control initialised\n");
|
|
||||||
|
|
||||||
auto hia4v1_pin = esp32hal->HIA4V1_PIN();
|
auto hia4v1_pin = esp32hal->HIA4V1_PIN();
|
||||||
auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_PIN();
|
auto inverter_disconnect_contactor_pin = esp32hal->INVERTER_DISCONNECT_CONTACTOR_PIN();
|
||||||
|
|
||||||
if (!esp32hal->alloc_pins("Precharge control", hia4v1_pin, inverter_disconnect_contactor_pin)) {
|
if (!esp32hal->alloc_pins("Precharge control", hia4v1_pin, inverter_disconnect_contactor_pin)) {
|
||||||
|
DEBUG_PRINTF("Precharge control setup failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +44,7 @@ bool init_precharge_control() {
|
||||||
pinMode(inverter_disconnect_contactor_pin, OUTPUT);
|
pinMode(inverter_disconnect_contactor_pin, OUTPUT);
|
||||||
digitalWrite(inverter_disconnect_contactor_pin, LOW);
|
digitalWrite(inverter_disconnect_contactor_pin, LOW);
|
||||||
|
|
||||||
|
DEBUG_PRINTF("Precharge control setup successful\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ bool init_rs485() {
|
||||||
auto pin_5v_en = esp32hal->PIN_5V_EN();
|
auto pin_5v_en = esp32hal->PIN_5V_EN();
|
||||||
|
|
||||||
if (!esp32hal->alloc_pins_ignore_unused("RS485", en_pin, se_pin, pin_5v_en)) {
|
if (!esp32hal->alloc_pins_ignore_unused("RS485", en_pin, se_pin, pin_5v_en)) {
|
||||||
return false;
|
DEBUG_PRINTF("Modbus failed to allocate pins\n");
|
||||||
|
return true; //Early return, we do not set the pins
|
||||||
}
|
}
|
||||||
|
|
||||||
if (en_pin != GPIO_NUM_NC) {
|
if (en_pin != GPIO_NUM_NC) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*
|
*
|
||||||
* @param[in] void
|
* @param[in] void
|
||||||
*
|
*
|
||||||
* @return true if init was successful, false otherwise.
|
* @return Safe to call even if rs485 is not used
|
||||||
*/
|
*/
|
||||||
bool init_rs485();
|
bool init_rs485();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ static LED* led;
|
||||||
|
|
||||||
bool led_init(void) {
|
bool led_init(void) {
|
||||||
if (!esp32hal->alloc_pins("LED", esp32hal->LED_PIN())) {
|
if (!esp32hal->alloc_pins("LED", esp32hal->LED_PIN())) {
|
||||||
|
DEBUG_PRINTF("LED setup failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue