Upgrade to Zephyr v4.3 and migrate boards
Also use new Zephyr CI environment and compile all boards. Board migration script example: python ../zephyr/scripts/utils/board_v1_to_v2.py --board-root . \ -v libresolar -g libresolar -b pwm_2420_lus -s stm32l072xx
This commit is contained in:
+16
-13
@@ -226,12 +226,12 @@ bool battery_conf_check(BatConf *bat_conf)
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->load_reconnect_voltage
|
||||
> (bat_conf->load_disconnect_voltage + 0.4);
|
||||
> (bat_conf->load_disconnect_voltage + 0.4f);
|
||||
},
|
||||
.text = "Load Reconnect Voltage must be higher than Load Disconnect Voltage + 0.4" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->recharge_voltage < (bat_conf->topping_voltage - 0.4);
|
||||
return bat_conf->recharge_voltage < (bat_conf->topping_voltage - 0.4f);
|
||||
},
|
||||
.text = "Recharge Voltage must be lower than Topping Voltage - 0.4" },
|
||||
{ .func =
|
||||
@@ -241,28 +241,29 @@ bool battery_conf_check(BatConf *bat_conf)
|
||||
.text = "Recharge Voltage must be higher than Load Disconnect Voltage + 1.0" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->load_disconnect_voltage > (bat_conf->absolute_min_voltage + 0.4);
|
||||
return bat_conf->load_disconnect_voltage
|
||||
> (bat_conf->absolute_min_voltage + 0.4f);
|
||||
},
|
||||
.text = "Load Disconnecct Voltage must be higher than Absolute Min Voltage + 0.4" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->internal_resistance
|
||||
< bat_conf->load_disconnect_voltage * 0.1 / DISCHARGE_CURRENT_MAX;
|
||||
< bat_conf->load_disconnect_voltage * 0.1f / DISCHARGE_CURRENT_MAX;
|
||||
},
|
||||
.text = "Internal Battery Resistance must not cause more than 10% drop at Max Discharge "
|
||||
"Current" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->wire_resistance
|
||||
< bat_conf->topping_voltage * 0.03 / DISCHARGE_CURRENT_MAX;
|
||||
< bat_conf->topping_voltage * 0.03f / DISCHARGE_CURRENT_MAX;
|
||||
},
|
||||
.text = "Wire Resistances must not cause more than 3% drop at Max Discharge Current" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
return bat_conf->topping_cutoff_current < (bat_conf->nominal_capacity / 10.0);
|
||||
return bat_conf->topping_cutoff_current < (bat_conf->nominal_capacity / 10.0f);
|
||||
},
|
||||
.text = "Topping Cutoff Current must be less than 10% of Nominal Capacity (C/10)" },
|
||||
{ .func = [bat_conf]() { return bat_conf->topping_cutoff_current > 0.01; },
|
||||
{ .func = [bat_conf]() { return bat_conf->topping_cutoff_current > 0.01f; },
|
||||
.text = "Topping Cutoff Current must be higher than 0.01A" },
|
||||
{ .func =
|
||||
[bat_conf]() {
|
||||
@@ -355,10 +356,10 @@ void Charger::detect_num_batteries(BatConf *bat) const
|
||||
&& port->bus->voltage < bat->absolute_max_voltage * 2)
|
||||
{
|
||||
port->bus->series_multiplier = 2;
|
||||
printf("Detected two batteries (total %.2f V max)\n", bat->topping_voltage * 2);
|
||||
printf("Detected two batteries (total %.2f V max)\n", (double)bat->topping_voltage * 2);
|
||||
}
|
||||
else {
|
||||
printf("Detected single battery (%.2f V max)\n", bat->topping_voltage);
|
||||
printf("Detected single battery (%.2f V max)\n", (double)bat->topping_voltage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,9 +367,9 @@ void Charger::update_soc(BatConf *bat_conf)
|
||||
{
|
||||
static int soc_filtered = 0; // SOC / 100 for better filtering
|
||||
|
||||
if (fabs(port->current) < 0.2) {
|
||||
if (fabs(port->current) < 0.2f) {
|
||||
int soc_new = (int)((port->bus->voltage - bat_conf->ocv_empty)
|
||||
/ (bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0);
|
||||
/ (bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0f);
|
||||
|
||||
if (soc_new > 500 && soc_filtered == 0) {
|
||||
// bypass filter during initialization
|
||||
@@ -452,7 +453,8 @@ void Charger::discharge_control(BatConf *bat_conf)
|
||||
// discharging currently not allowed. should we allow it?
|
||||
|
||||
if (port->bus->voltage
|
||||
>= port->bus->src_control_voltage(bat_conf->absolute_min_voltage + 0.1F)) {
|
||||
>= port->bus->src_control_voltage(bat_conf->absolute_min_voltage + 0.1F))
|
||||
{
|
||||
dev_stat.clear_error(ERR_BAT_UNDERVOLTAGE);
|
||||
}
|
||||
|
||||
@@ -463,7 +465,8 @@ void Charger::discharge_control(BatConf *bat_conf)
|
||||
}
|
||||
|
||||
if (!dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_DIS_OVERTEMP
|
||||
| ERR_BAT_DIS_UNDERTEMP)) {
|
||||
| ERR_BAT_DIS_UNDERTEMP))
|
||||
{
|
||||
// discharge current is stored as absolute value in bat_conf, but defined
|
||||
// as negative current for power port
|
||||
port->neg_current_limit = -bat_conf->discharge_current_max;
|
||||
|
||||
+6
-5
@@ -91,7 +91,8 @@ static inline float ntc_temp(uint32_t channel, int32_t vref, float ntc_series_re
|
||||
// resistance of NTC (Ohm)
|
||||
float rts = ntc_series_resistor * v_temp / (vref - v_temp);
|
||||
|
||||
return 1.0 / (1.0 / (273.15 + 25) + 1.0 / NTC_BETA_VALUE * log(rts / 10000.0)) - 273.15; // °C
|
||||
return 1.0f / (1.0f / (273.15f + 25.0f) + 1.0f / (float)NTC_BETA_VALUE * logf(rts / 10000.0f))
|
||||
- 273.15f; // °C
|
||||
}
|
||||
|
||||
void calibrate_current_sensors()
|
||||
@@ -369,13 +370,13 @@ void prepare_adc_readings(AdcValues values)
|
||||
{
|
||||
adc_readings[ADC_POS(vref_mcu)] = (uint16_t)(1.224 / 3.3 * 4096) << 4;
|
||||
adc_readings[ADC_POS(v_high)] =
|
||||
(uint16_t)((values.solar_voltage / ADC_GAIN(v_high)) / 3.3 * 4096) << 4;
|
||||
(uint16_t)((values.solar_voltage / ADC_GAIN(v_high)) / 3.3f * 4096) << 4;
|
||||
adc_readings[ADC_POS(v_low)] =
|
||||
(uint16_t)((values.battery_voltage / ADC_GAIN(v_low)) / 3.3 * 4096) << 4;
|
||||
(uint16_t)((values.battery_voltage / ADC_GAIN(v_low)) / 3.3f * 4096) << 4;
|
||||
adc_readings[ADC_POS(i_dcdc)] =
|
||||
(uint16_t)((values.dcdc_current / ADC_GAIN(i_dcdc)) / 3.3 * 4096) << 4;
|
||||
(uint16_t)((values.dcdc_current / ADC_GAIN(i_dcdc)) / 3.3f * 4096) << 4;
|
||||
adc_readings[ADC_POS(i_load)] =
|
||||
(uint16_t)((values.load_current / ADC_GAIN(i_load)) / 3.3 * 4096) << 4;
|
||||
(uint16_t)((values.load_current / ADC_GAIN(i_load)) / 3.3f * 4096) << 4;
|
||||
}
|
||||
|
||||
void prepare_adc_filtered()
|
||||
|
||||
@@ -1175,7 +1175,9 @@ void data_objects_init()
|
||||
hwinfo_get_device_id(buf, sizeof(buf));
|
||||
|
||||
uint64_t id64 = crc32_ieee(buf, sizeof(buf));
|
||||
#ifdef CONFIG_LIBRE_SOLAR_TYPE_ID
|
||||
id64 += ((uint64_t)CONFIG_LIBRE_SOLAR_TYPE_ID) << 32;
|
||||
#endif
|
||||
|
||||
uint64_to_base32(id64, device_id, sizeof(device_id), alphabet_crockford);
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "helper.h"
|
||||
#include "mcu.h"
|
||||
#include "thingset.h"
|
||||
#include "zephyr/toolchain.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -25,7 +26,7 @@ LOG_MODULE_REGISTER(nvs, CONFIG_DATA_STORAGE_LOG_LEVEL);
|
||||
K_MUTEX_DEFINE(data_buf_lock);
|
||||
|
||||
// Buffer used by store and restore functions (must be word-aligned for hardware CRC calculation)
|
||||
static uint8_t buf[512] __aligned(sizeof(uint32_t));
|
||||
__maybe_unused static uint8_t buf[512] __aligned(sizeof(uint32_t));
|
||||
|
||||
extern ThingSet ts;
|
||||
|
||||
|
||||
+16
-12
@@ -69,7 +69,7 @@ void Dcdc::perturb_observe_buck()
|
||||
power_good_timestamp = uptime();
|
||||
}
|
||||
|
||||
if ((uptime() - power_good_timestamp > 10 || power < -10.0) && mode != DCDC_MODE_AUTO) {
|
||||
if ((uptime() - power_good_timestamp > 10 || power < -10.0f) && mode != DCDC_MODE_AUTO) {
|
||||
// switch off after 10s low power or negative power (if not in nanogrid mode)
|
||||
pwm_direction = 0;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ void Dcdc::perturb_observe_boost()
|
||||
power_good_timestamp = uptime();
|
||||
}
|
||||
|
||||
if ((uptime() - power_good_timestamp > 10 || -power < -10.0) && mode != DCDC_MODE_AUTO) {
|
||||
if ((uptime() - power_good_timestamp > 10 || -power < -10.0f) && mode != DCDC_MODE_AUTO) {
|
||||
// switch off after 10s low power or negative power (if not in nanogrid mode)
|
||||
pwm_direction = 0;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ __weak DcdcOperationMode Dcdc::check_start_conditions()
|
||||
|
||||
if (lvb->sink_current_margin > 0 && lvb->voltage < lvb->sink_control_voltage()
|
||||
&& hvb->src_current_margin < 0 && hvb->voltage > hvb->src_control_voltage()
|
||||
&& hvb->voltage * 0.85 > lvb->voltage)
|
||||
&& hvb->voltage * 0.85f > lvb->voltage)
|
||||
{
|
||||
return DCDC_MODE_BUCK;
|
||||
}
|
||||
@@ -259,7 +259,8 @@ __weak void Dcdc::control()
|
||||
half_bridge_start();
|
||||
power_good_timestamp = uptime();
|
||||
printf("DC/DC %s mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n", mode_name,
|
||||
hvb->voltage, lvb->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
(double)hvb->voltage, (double)lvb->voltage,
|
||||
(double)half_bridge_get_duty_cycle() * 100.0);
|
||||
}
|
||||
else {
|
||||
startup_inhibit(true); // reset inhibit counter
|
||||
@@ -275,7 +276,7 @@ __weak void Dcdc::control()
|
||||
stop_reason = "disabled";
|
||||
}
|
||||
else {
|
||||
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && inductor_current > 0.1)) {
|
||||
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && inductor_current > 0.1f)) {
|
||||
perturb_observe_buck();
|
||||
}
|
||||
else {
|
||||
@@ -289,9 +290,10 @@ __weak void Dcdc::control()
|
||||
LOG_DBG("P %.2fW, inductor %.2fA, HS: %.2fV, %.2fA margin, "
|
||||
"LS: %.2fV (target %.2fV), %.2fA margin, "
|
||||
"PWM: %.1f, dcdc_state: %d, pwm_direction: %d",
|
||||
power, inductor_current, hvb->voltage, hvb->src_current_margin,
|
||||
lvb->voltage, lvb->sink_voltage_intercept, lvb->sink_current_margin,
|
||||
half_bridge_get_duty_cycle() * 100.0, state, pwm_direction);
|
||||
(double)power, (double)inductor_current, (double)hvb->voltage,
|
||||
(double)hvb->src_current_margin, (double)lvb->voltage,
|
||||
(double)lvb->sink_voltage_intercept, (double)lvb->sink_current_margin,
|
||||
(double)half_bridge_get_duty_cycle() * 100.0, state, pwm_direction);
|
||||
}
|
||||
else {
|
||||
stop_reason = "low power";
|
||||
@@ -316,7 +318,7 @@ void Dcdc::test()
|
||||
stop_reason = "disabled";
|
||||
}
|
||||
else {
|
||||
if (half_bridge_get_duty_cycle() > 0.50) {
|
||||
if (half_bridge_get_duty_cycle() > 0.50f) {
|
||||
half_bridge_set_ccr(half_bridge_get_ccr() - 1);
|
||||
}
|
||||
else {
|
||||
@@ -337,8 +339,9 @@ void Dcdc::test()
|
||||
|
||||
half_bridge_set_duty_cycle(lvb->voltage / hvb->voltage);
|
||||
half_bridge_start();
|
||||
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n", hvb->voltage,
|
||||
lvb->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n",
|
||||
(double)hvb->voltage, (double)lvb->voltage,
|
||||
(double)half_bridge_get_duty_cycle() * 100.0);
|
||||
}
|
||||
else {
|
||||
startup_inhibit(true); // reset inhibit counter
|
||||
@@ -394,6 +397,7 @@ void Dcdc::output_hvs_disable()
|
||||
|
||||
#else
|
||||
|
||||
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode) {}
|
||||
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode)
|
||||
{}
|
||||
|
||||
#endif /* BOARD_HAS_DCDC */
|
||||
|
||||
+11
-12
@@ -33,7 +33,11 @@ extern ThingSet ts;
|
||||
extern uint16_t can_node_addr;
|
||||
extern Charger charger;
|
||||
|
||||
#if DT_NODE_EXISTS(DT_NODELABEL(can1))
|
||||
static const struct device *can_dev = DEVICE_DT_GET(DT_NODELABEL(can1));
|
||||
#elif DT_NODE_EXISTS(DT_NODELABEL(fdcan1))
|
||||
static const struct device *can_dev = DEVICE_DT_GET(DT_NODELABEL(fdcan1));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ISOTP
|
||||
|
||||
@@ -46,15 +50,13 @@ const struct isotp_fc_opts fc_opts = {
|
||||
};
|
||||
|
||||
struct isotp_msg_id rx_addr = {
|
||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
||||
.use_ext_addr = 0, // Normal ISO-TP addressing (using only CAN ID)
|
||||
.use_fixed_addr = 1, // enable SAE J1939 compatible addressing
|
||||
// enable SAE J1939 compatible addressing
|
||||
.flags = ISOTP_MSG_FIXED_ADDR | ISOTP_MSG_IDE,
|
||||
};
|
||||
|
||||
struct isotp_msg_id tx_addr = {
|
||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
||||
.use_ext_addr = 0, // Normal ISO-TP addressing (using only CAN ID)
|
||||
.use_fixed_addr = 1, // enable SAE J1939 compatible addressing
|
||||
// enable SAE J1939 compatible addressing
|
||||
.flags = ISOTP_MSG_FIXED_ADDR | ISOTP_MSG_IDE,
|
||||
};
|
||||
|
||||
static struct isotp_recv_ctx recv_ctx;
|
||||
@@ -146,10 +148,8 @@ CAN_MSGQ_DEFINE(sub_msgq, 10);
|
||||
|
||||
const struct can_filter ctrl_filter = {
|
||||
.id = TS_CAN_TYPE_PUBSUB,
|
||||
.rtr = CAN_DATAFRAME,
|
||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
||||
.id_mask = TS_CAN_TYPE_MASK,
|
||||
.rtr_mask = 1,
|
||||
.mask = TS_CAN_TYPE_MASK,
|
||||
.flags = CAN_FILTER_IDE,
|
||||
};
|
||||
|
||||
void can_pub_isr(const struct device *dev, int error, void *user_data)
|
||||
@@ -160,9 +160,8 @@ void can_pub_isr(const struct device *dev, int error, void *user_data)
|
||||
void can_pub_send(uint32_t can_id, uint8_t can_data[8], uint8_t data_len)
|
||||
{
|
||||
struct can_frame frame = { 0 };
|
||||
frame.id_type = CAN_EXTENDED_IDENTIFIER;
|
||||
frame.rtr = CAN_DATAFRAME;
|
||||
frame.id = can_id;
|
||||
frame.flags = CAN_FRAME_IDE;
|
||||
memcpy(frame.data, can_data, 8);
|
||||
|
||||
if (data_len >= 0) {
|
||||
|
||||
@@ -390,7 +390,7 @@ void half_bridge_init(int freq_kHz, int deadtime_ns, float min_duty, float max_d
|
||||
|
||||
void half_bridge_set_duty_cycle(float duty)
|
||||
{
|
||||
if (duty >= 0.0 && duty <= 1.0) {
|
||||
if (duty >= 0.0f && duty <= 1.0f) {
|
||||
half_bridge_set_ccr(half_bridge_get_arr() * duty);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ int main(void)
|
||||
#endif
|
||||
|
||||
#if BOARD_HAS_USB_OUTPUT
|
||||
usb_pwr.set_voltage_limits(bat_conf.load_disconnect_voltage - 0.1, // keep on longer than load
|
||||
usb_pwr.set_voltage_limits(bat_conf.load_disconnect_voltage - 0.1f, // keep on longer than load
|
||||
bat_conf.load_reconnect_voltage, bat_conf.absolute_max_voltage);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user