-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify module settings and add SolenoidSettings
- Loading branch information
Showing
13 changed files
with
265 additions
and
222 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "module_settings.h" | ||
#include "eeprom_impl.h" | ||
|
||
TCC_MODULE_SETTINGS TCC_CURRENT_SETTINGS = TCC_DEFAULT_SETTINGS; | ||
SOL_MODULE_SETTINGS SOL_CURRENT_SETTINGS = SOL_DEFAULT_SETTINGS; | ||
|
||
// These macro will fail should the naming convension of the settings not be correct | ||
// so it enforces the following rule: | ||
|
||
// (xxx) denotes the 3 letter prefix of the module settings name | ||
// NVS Key name : xxx_SETTINGS_NVS_KEY | ||
// Current settings name : xxx_CURRENT_SETTINGS | ||
// Default settings name : xxx_DEFAULT_SETTINGS | ||
// Settings variable type: xxx_MODULE_SETTINGS | ||
// Settings SCN KEY IDs : xxx_MODULE_SETINGS_SCN_ID | ||
#define READ_EEPROM_SETTING(pfx) \ | ||
EEPROM::read_subsystem_settings<pfx##_MODULE_SETTINGS>(pfx##_SETTINGS_NVS_KEY, &pfx##_CURRENT_SETTINGS, &pfx##_DEFAULT_SETTINGS) | ||
|
||
#define RESET_EEPROM_SETINGS(pfx) \ | ||
pfx##_CURRENT_SETTINGS = pfx##_DEFAULT_SETTINGS; \ | ||
return EEPROM::write_subsystem_settings(pfx##_SETTINGS_NVS_KEY, &pfx##_DEFAULT_SETTINGS); \ | ||
|
||
// Checks and writes the buffer as the setting | ||
#define CHECK_AND_WRITE_SETTINGS(pfx, buffer_len, buffer) \ | ||
if (sizeof(pfx##_MODULE_SETTINGS) != buffer_len) { \ | ||
return ESP_ERR_INVALID_SIZE; \ | ||
} else { \ | ||
pfx##_MODULE_SETTINGS settings = *(pfx##_MODULE_SETTINGS*)buffer; \ | ||
pfx##_CURRENT_SETTINGS = settings; \ | ||
return EEPROM::write_subsystem_settings(pfx##_SETTINGS_NVS_KEY, &pfx##_CURRENT_SETTINGS); \ | ||
} \ | ||
|
||
#define READ_SETTINGS_TO_BUFFER(pfx, buffer_len_dest, buffer_dest) \ | ||
const pfx##_MODULE_SETTINGS* ptr = &pfx##_CURRENT_SETTINGS; \ | ||
uint8_t* dest = (uint8_t*)heap_caps_malloc(sizeof(pfx##_MODULE_SETTINGS)+1, MALLOC_CAP_SPIRAM); \ | ||
if (nullptr == ptr || nullptr == dest) { \ | ||
delete[] dest; \ | ||
return ESP_ERR_NO_MEM; \ | ||
} else { \ | ||
dest[0] = pfx##_MODULE_SETINGS_SCN_ID; \ | ||
memcpy(&dest[1], ptr, sizeof(pfx##_MODULE_SETTINGS)); \ | ||
*buffer_len = sizeof(pfx##_MODULE_SETTINGS)+1; \ | ||
*buffer = dest; \ | ||
return ESP_OK; \ | ||
} \ | ||
|
||
esp_err_t ModuleConfiguration::load_all_settings() { | ||
esp_err_t res = ESP_OK; | ||
READ_EEPROM_SETTING(TCC); | ||
READ_EEPROM_SETTING(SOL); | ||
return res; | ||
} | ||
|
||
esp_err_t ModuleConfiguration::reset_settings(uint8_t idx) { | ||
switch (idx) { | ||
case TCC_MODULE_SETINGS_SCN_ID: | ||
RESET_EEPROM_SETINGS(TCC) | ||
case SOL_MODULE_SETINGS_SCN_ID: | ||
RESET_EEPROM_SETINGS(SOL) | ||
default: | ||
return ESP_ERR_INVALID_ARG; | ||
} | ||
} | ||
|
||
esp_err_t ModuleConfiguration::read_settings(uint8_t module_id, uint16_t* buffer_len, uint8_t** buffer) { | ||
if (module_id == TCC_MODULE_SETINGS_SCN_ID) { | ||
READ_SETTINGS_TO_BUFFER(TCC, buffer_len, buffer); | ||
} else if (module_id == SOL_MODULE_SETINGS_SCN_ID) { | ||
READ_SETTINGS_TO_BUFFER(SOL, buffer_len, buffer); | ||
} else { | ||
return ESP_ERR_INVALID_ARG; | ||
} | ||
} | ||
|
||
esp_err_t ModuleConfiguration::write_settings(uint8_t module_id, uint16_t buffer_len, uint8_t* buffer) { | ||
if (module_id == TCC_MODULE_SETINGS_SCN_ID) { | ||
CHECK_AND_WRITE_SETTINGS(TCC, buffer_len, buffer) | ||
} else if (module_id == SOL_MODULE_SETINGS_SCN_ID) { | ||
CHECK_AND_WRITE_SETTINGS(SOL, buffer_len, buffer) | ||
} | ||
return ESP_ERR_INVALID_ARG; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#ifndef __MODULE_SETTINGS_H | ||
#define __MODULE_SETTINGS_H | ||
|
||
#include <stdint.h> | ||
#include <tcu_maths.h> | ||
#include <esp_err.h> | ||
|
||
// TCC Settings | ||
|
||
#define TCC_SETTINGS_NVS_KEY "TCC_A2" | ||
typedef struct { | ||
bool adapt_enable; | ||
bool enable_d1; | ||
bool enable_d2; | ||
bool enable_d3; | ||
bool enable_d4; | ||
bool enable_d5; | ||
uint16_t prefill_pressure; | ||
uint16_t lock_rpm_threshold; | ||
uint16_t min_locking_rpm; | ||
uint16_t adjust_interval_ms; | ||
uint16_t tcc_stall_speed; | ||
uint16_t min_torque_adapt; | ||
uint16_t max_torque_adapt; | ||
uint16_t prefill_min_engine_rpm; | ||
uint16_t base_pressure_offset_start_ramp; | ||
LinearInterpSetting pressure_increase_ramp_settings; | ||
uint8_t adapt_pressure_inc; | ||
uint16_t adapt_lock_detect_time; | ||
uint16_t pulling_slip_rpm_low_threshold; | ||
uint16_t pulling_slip_rpm_high_threhold; | ||
float reaction_torque_multiplier; | ||
uint16_t trq_consider_coasting; | ||
LinearInterpSetting load_dampening; | ||
LinearInterpSetting pressure_multiplier_output_rpm; | ||
uint16_t max_allowed_bite_pressure; | ||
uint16_t max_allowed_pressure_longterm; | ||
} __attribute__ ((packed)) TCC_MODULE_SETTINGS; | ||
|
||
const TCC_MODULE_SETTINGS TCC_DEFAULT_SETTINGS = { | ||
.adapt_enable = true, | ||
.enable_d1 = true, | ||
.enable_d2 = true, | ||
.enable_d3 = true, | ||
.enable_d4 = true, | ||
.enable_d5 = true, | ||
.prefill_pressure = 500, | ||
.lock_rpm_threshold = 50, | ||
.min_locking_rpm = 1100, | ||
.adjust_interval_ms = 500, | ||
.tcc_stall_speed = 2500, | ||
.min_torque_adapt = 50, | ||
.max_torque_adapt = 110, | ||
.prefill_min_engine_rpm = 900, | ||
.base_pressure_offset_start_ramp = 300, | ||
.pressure_increase_ramp_settings = { | ||
.new_min = 1, | ||
.new_max = 5, | ||
.raw_min = 100, | ||
.raw_max = 1000, | ||
}, | ||
.adapt_pressure_inc = 10, | ||
.adapt_lock_detect_time = 2000, | ||
.pulling_slip_rpm_low_threshold = 20, | ||
.pulling_slip_rpm_high_threhold = 100, | ||
.reaction_torque_multiplier = 1.5, | ||
.trq_consider_coasting = 40, | ||
.load_dampening = { | ||
.new_min = 100, | ||
.new_max = 50, | ||
.raw_min = -40, | ||
.raw_max = 40, | ||
}, | ||
.pressure_multiplier_output_rpm = { | ||
.new_min = 1.00, | ||
.new_max = 1.25, | ||
.raw_min = 1500, | ||
.raw_max = 2500, | ||
}, | ||
.max_allowed_bite_pressure = 1800, | ||
.max_allowed_pressure_longterm = 7000, | ||
}; | ||
|
||
#define SOL_SETTINGS_NVS_KEY "SOL_A0" | ||
|
||
typedef struct { | ||
uint16_t min_batt_power_on_test; | ||
uint16_t current_threshold_error; | ||
uint16_t cc_vref_solenoid; | ||
float cc_temp_coefficient_wires; | ||
float cc_reference_resistance; | ||
float cc_reference_temp; | ||
float cc_max_adjust_per_step; | ||
} __attribute__ ((packed)) SOL_MODULE_SETTINGS; | ||
|
||
const SOL_MODULE_SETTINGS SOL_DEFAULT_SETTINGS = { | ||
.min_batt_power_on_test = 11000, | ||
.current_threshold_error = 500, | ||
.cc_vref_solenoid = 12000, | ||
.cc_temp_coefficient_wires = 0.393, | ||
.cc_reference_resistance = 5.3, | ||
.cc_reference_temp = 25, | ||
.cc_max_adjust_per_step = 2 | ||
}; | ||
|
||
extern TCC_MODULE_SETTINGS TCC_CURRENT_SETTINGS; | ||
extern SOL_MODULE_SETTINGS SOL_CURRENT_SETTINGS; | ||
|
||
// Setting IDx | ||
#define TCC_MODULE_SETINGS_SCN_ID 0x01 | ||
#define SOL_MODULE_SETINGS_SCN_ID 0x02 | ||
|
||
namespace ModuleConfiguration { | ||
esp_err_t load_all_settings(); | ||
esp_err_t reset_settings(uint8_t idx); | ||
esp_err_t write_settings(uint8_t module_id, uint16_t buffer_len, uint8_t* buffer); | ||
esp_err_t read_settings(uint8_t module_id, uint16_t* buffer_len, uint8_t** buffer); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.