Add Clang-Format file and apply it
The format tries to maintain the previously used Libre Solar firmware coding style as much as possible. Applying the format fixed some issues and re-ordered some parts of the code.
This commit is contained in:
committed by
Martin Jäger
parent
2359a96bbe
commit
5bdbecf19d
+28
-33
@@ -6,28 +6,27 @@
|
||||
|
||||
#include "load.h"
|
||||
|
||||
#include <zephyr.h>
|
||||
#include "board.h"
|
||||
#include <zephyr.h>
|
||||
|
||||
#if BOARD_HAS_LOAD_OUTPUT || UNIT_TEST
|
||||
|
||||
#include "leds.h"
|
||||
#include "device_status.h"
|
||||
#include "helper.h"
|
||||
#include "leds.h"
|
||||
|
||||
#define LOAD_CURRENT_MAX DT_PROP(DT_CHILD(DT_PATH(outputs), load), current_max)
|
||||
#define LOAD_CURRENT_MAX DT_PROP(DT_CHILD(DT_PATH(outputs), load), current_max)
|
||||
|
||||
#define PCB_LS_VOLTAGE_MAX DT_PROP(DT_PATH(pcb), ls_voltage_max)
|
||||
#define PCB_MOSFETS_TJ_MAX DT_PROP(DT_PATH(pcb), mosfets_tj_max)
|
||||
#define PCB_MOSFETS_TAU_JA DT_PROP(DT_PATH(pcb), mosfets_tau_ja)
|
||||
#define PCB_INTERNAL_TREF_MAX DT_PROP(DT_PATH(pcb), internal_tref_max)
|
||||
#define PCB_LS_VOLTAGE_MAX DT_PROP(DT_PATH(pcb), ls_voltage_max)
|
||||
#define PCB_MOSFETS_TJ_MAX DT_PROP(DT_PATH(pcb), mosfets_tj_max)
|
||||
#define PCB_MOSFETS_TAU_JA DT_PROP(DT_PATH(pcb), mosfets_tau_ja)
|
||||
#define PCB_INTERNAL_TREF_MAX DT_PROP(DT_PATH(pcb), internal_tref_max)
|
||||
|
||||
extern DeviceStatus dev_stat;
|
||||
|
||||
LoadOutput::LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)(), bool (*pgood_fn)()) :
|
||||
PowerPort(dc_bus),
|
||||
switch_set(switch_fn),
|
||||
pgood_check(pgood_fn)
|
||||
LoadOutput::LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)(),
|
||||
bool (*pgood_fn)())
|
||||
: PowerPort(dc_bus), switch_set(switch_fn), pgood_check(pgood_fn)
|
||||
{
|
||||
state = LOAD_STATE_OFF;
|
||||
|
||||
@@ -35,14 +34,14 @@ LoadOutput::LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)()
|
||||
init_fn();
|
||||
|
||||
switch_set(false);
|
||||
junction_temperature = 25; // starting point: 25°C
|
||||
junction_temperature = 25; // starting point: 25°C
|
||||
|
||||
oc_recovery_delay = CONFIG_LOAD_OC_RECOVERY_DELAY;
|
||||
lvd_recovery_delay = CONFIG_LOAD_LVD_RECOVERY_DELAY;
|
||||
|
||||
ov_hysteresis = 0.3;
|
||||
|
||||
enable = true; // switch on in next control() call if everything is fine
|
||||
enable = true; // switch on in next control() call if everything is fine
|
||||
}
|
||||
|
||||
// this function is called more often than the state machine
|
||||
@@ -51,14 +50,13 @@ void LoadOutput::control()
|
||||
if (state == LOAD_STATE_ON) {
|
||||
|
||||
// junction temperature calculation model for overcurrent detection
|
||||
junction_temperature = junction_temperature +
|
||||
(dev_stat.internal_temp - junction_temperature + current * current /
|
||||
(LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * (PCB_MOSFETS_TJ_MAX - PCB_INTERNAL_TREF_MAX))
|
||||
/ (PCB_MOSFETS_TAU_JA * CONFIG_CONTROL_FREQUENCY);
|
||||
junction_temperature = junction_temperature
|
||||
+ (dev_stat.internal_temp - junction_temperature
|
||||
+ current * current / (LOAD_CURRENT_MAX * LOAD_CURRENT_MAX)
|
||||
* (PCB_MOSFETS_TJ_MAX - PCB_INTERNAL_TREF_MAX))
|
||||
/ (PCB_MOSFETS_TAU_JA * CONFIG_CONTROL_FREQUENCY);
|
||||
|
||||
if (junction_temperature > PCB_MOSFETS_TJ_MAX ||
|
||||
current > LOAD_CURRENT_MAX * 2)
|
||||
{
|
||||
if (junction_temperature > PCB_MOSFETS_TJ_MAX || current > LOAD_CURRENT_MAX * 2) {
|
||||
flags_set(&error_flags, ERR_LOAD_OVERCURRENT);
|
||||
oc_timestamp = uptime();
|
||||
}
|
||||
@@ -80,9 +78,7 @@ void LoadOutput::control()
|
||||
|
||||
// long-term overvoltage (overvoltage transients are detected as an ADC alert and switch
|
||||
// off the solar input instead of the load output)
|
||||
if (bus->voltage > bus->series_voltage(overvoltage) ||
|
||||
bus->voltage > PCB_LS_VOLTAGE_MAX)
|
||||
{
|
||||
if (bus->voltage > bus->series_voltage(overvoltage) || bus->voltage > PCB_LS_VOLTAGE_MAX) {
|
||||
ov_debounce_counter++;
|
||||
if (ov_debounce_counter > CONFIG_CONTROL_FREQUENCY) {
|
||||
// waited 1s before setting the flag
|
||||
@@ -105,22 +101,22 @@ void LoadOutput::control()
|
||||
else {
|
||||
// load is off: check if errors are resolved and if load can be switched on
|
||||
|
||||
if (flags_check(&error_flags, ERR_LOAD_SHEDDING) &&
|
||||
bus->voltage > bus->src_control_voltage(reconnect_voltage) &&
|
||||
uptime() - lvd_timestamp > lvd_recovery_delay)
|
||||
if (flags_check(&error_flags, ERR_LOAD_SHEDDING)
|
||||
&& bus->voltage > bus->src_control_voltage(reconnect_voltage)
|
||||
&& uptime() - lvd_timestamp > lvd_recovery_delay)
|
||||
{
|
||||
flags_clear(&error_flags, ERR_LOAD_SHEDDING);
|
||||
}
|
||||
|
||||
if (flags_check(&error_flags, ERR_LOAD_OVERCURRENT | ERR_LOAD_VOLTAGE_DIP) &&
|
||||
uptime() - oc_timestamp > oc_recovery_delay)
|
||||
if (flags_check(&error_flags, ERR_LOAD_OVERCURRENT | ERR_LOAD_VOLTAGE_DIP)
|
||||
&& uptime() - oc_timestamp > oc_recovery_delay)
|
||||
{
|
||||
flags_clear(&error_flags, ERR_LOAD_OVERCURRENT | ERR_LOAD_VOLTAGE_DIP);
|
||||
}
|
||||
|
||||
if (flags_check(&error_flags, ERR_LOAD_OVERVOLTAGE) &&
|
||||
bus->voltage < (bus->series_voltage(overvoltage) - ov_hysteresis) &&
|
||||
bus->voltage < (PCB_LS_VOLTAGE_MAX - ov_hysteresis))
|
||||
if (flags_check(&error_flags, ERR_LOAD_OVERVOLTAGE)
|
||||
&& bus->voltage < (bus->series_voltage(overvoltage) - ov_hysteresis)
|
||||
&& bus->voltage < (PCB_LS_VOLTAGE_MAX - ov_hysteresis))
|
||||
{
|
||||
flags_clear(&error_flags, ERR_LOAD_OVERVOLTAGE);
|
||||
}
|
||||
@@ -152,8 +148,7 @@ void LoadOutput::stop(uint32_t flag)
|
||||
|
||||
// flicker the load LED if failure was most probably caused by the user
|
||||
if (flags_check(&error_flags,
|
||||
ERR_LOAD_OVERCURRENT | ERR_LOAD_VOLTAGE_DIP | ERR_LOAD_SHORT_CIRCUIT))
|
||||
{
|
||||
ERR_LOAD_OVERCURRENT | ERR_LOAD_VOLTAGE_DIP | ERR_LOAD_SHORT_CIRCUIT)) {
|
||||
#if LED_EXISTS(load)
|
||||
leds_flicker(LED_POS(load), LED_TIMEOUT_INFINITE);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user