Doxygen comments added to load and power port files
This commit is contained in:
+22
-1
@@ -55,18 +55,39 @@ void can_process_inbox();
|
||||
void can_send_object_name(int obj_id, uint8_t can_dest_id);
|
||||
|
||||
/** GSM mobile interface via UEXT connector serial interface
|
||||
*
|
||||
* Initialization (called once at program startup)
|
||||
*/
|
||||
void gsm_init();
|
||||
|
||||
/** GSM mobile interface via UEXT connector serial interface
|
||||
*
|
||||
* Process function, called every second
|
||||
*/
|
||||
void gsm_process();
|
||||
|
||||
/** LoRa interface via UEXT connector SPI interface
|
||||
*
|
||||
* Initialization (called once at program startup)
|
||||
*/
|
||||
void lora_init();
|
||||
|
||||
/** LoRa interface via UEXT connector SPI interface
|
||||
*
|
||||
* Process function, called every second
|
||||
*/
|
||||
void lora_process();
|
||||
|
||||
/** GSM mobile interface via UEXT connector serial interface
|
||||
/** WiFi interface with ESP32
|
||||
*
|
||||
* Initialization (called once at program startup)
|
||||
*/
|
||||
void wifi_init();
|
||||
|
||||
/** WiFi interface with ESP32
|
||||
*
|
||||
* Process function, called every second
|
||||
*/
|
||||
void wifi_process();
|
||||
|
||||
/** SD card connected to UEXT connector (e.g. via Olimex adapter)
|
||||
|
||||
+26
-26
@@ -26,50 +26,50 @@ void load_init(load_output_t *load)
|
||||
load->usb_enabled_target = true;
|
||||
hw_load_switch(false);
|
||||
hw_usb_out(false);
|
||||
load->state = LOAD_STATE_DISABLED;
|
||||
load->usb_state = USB_STATE_DISABLED;
|
||||
load->switch_state = LOAD_STATE_DISABLED;
|
||||
load->usb_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
|
||||
|
||||
void usb_state_machine(load_output_t *load)
|
||||
{
|
||||
switch (load->usb_state) {
|
||||
case USB_STATE_DISABLED:
|
||||
case LOAD_STATE_DISABLED:
|
||||
if (load->enabled && load->usb_enabled_target == true) {
|
||||
hw_usb_out(true);
|
||||
load->usb_state = USB_STATE_ON;
|
||||
load->usb_state = LOAD_STATE_ON;
|
||||
}
|
||||
break;
|
||||
case USB_STATE_ON:
|
||||
case LOAD_STATE_ON:
|
||||
// currently still same cut-off SOC limit as the load
|
||||
if (load->state == LOAD_STATE_OFF_LOW_SOC) {
|
||||
if (load->switch_state == LOAD_STATE_OFF_LOW_SOC) {
|
||||
hw_usb_out(false);
|
||||
load->usb_state = USB_STATE_OFF_LOW_SOC;
|
||||
load->usb_state = LOAD_STATE_OFF_LOW_SOC;
|
||||
}
|
||||
else if (load->state == LOAD_STATE_OFF_OVERCURRENT) {
|
||||
else if (load->switch_state == LOAD_STATE_OFF_OVERCURRENT) {
|
||||
hw_usb_out(false);
|
||||
load->usb_state = USB_STATE_OFF_OVERCURRENT;
|
||||
load->usb_state = LOAD_STATE_OFF_OVERCURRENT;
|
||||
}
|
||||
else if (load->usb_enabled_target == false) {
|
||||
hw_usb_out(false);
|
||||
load->usb_state = USB_STATE_DISABLED;
|
||||
load->usb_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
break;
|
||||
case USB_STATE_OFF_LOW_SOC:
|
||||
case LOAD_STATE_OFF_LOW_SOC:
|
||||
// currently still same cut-off SOC limit as the load
|
||||
if (load->state == LOAD_STATE_ON) {
|
||||
if (load->switch_state == LOAD_STATE_ON) {
|
||||
if (load->usb_enabled_target == true) {
|
||||
hw_usb_out(true);
|
||||
load->usb_state = USB_STATE_ON;
|
||||
load->usb_state = LOAD_STATE_ON;
|
||||
}
|
||||
else {
|
||||
load->usb_state = USB_STATE_DISABLED;
|
||||
load->usb_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case USB_STATE_OFF_OVERCURRENT:
|
||||
if (load->state != LOAD_STATE_OFF_OVERCURRENT) {
|
||||
load->usb_state = USB_STATE_DISABLED;
|
||||
case LOAD_STATE_OFF_OVERCURRENT:
|
||||
if (load->switch_state != LOAD_STATE_OFF_OVERCURRENT) {
|
||||
load->usb_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -77,25 +77,25 @@ void usb_state_machine(load_output_t *load)
|
||||
|
||||
void load_state_machine(load_output_t *load, bool source_enabled)
|
||||
{
|
||||
//printf("Load State: %d\n", load->state);
|
||||
switch (load->state) {
|
||||
//printf("Load State: %d\n", load->switch_state);
|
||||
switch (load->switch_state) {
|
||||
case LOAD_STATE_DISABLED:
|
||||
if (source_enabled == true && load->enabled_target == true) {
|
||||
hw_load_switch(true);
|
||||
load->enabled = true;
|
||||
load->state = LOAD_STATE_ON;
|
||||
load->switch_state = LOAD_STATE_ON;
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_ON:
|
||||
if (load->enabled_target == false) {
|
||||
hw_load_switch(false);
|
||||
load->enabled = false;
|
||||
load->state = LOAD_STATE_DISABLED;
|
||||
load->switch_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
else if (source_enabled == false) {
|
||||
hw_load_switch(false);
|
||||
load->enabled = false;
|
||||
load->state = LOAD_STATE_OFF_LOW_SOC;
|
||||
load->switch_state = LOAD_STATE_OFF_LOW_SOC;
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_LOW_SOC:
|
||||
@@ -103,16 +103,16 @@ void load_state_machine(load_output_t *load, bool source_enabled)
|
||||
if (load->enabled_target == true) {
|
||||
hw_load_switch(true);
|
||||
load->enabled = true;
|
||||
load->state = LOAD_STATE_ON;
|
||||
load->switch_state = LOAD_STATE_ON;
|
||||
}
|
||||
else {
|
||||
load->state = LOAD_STATE_DISABLED;
|
||||
load->switch_state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_OVERCURRENT:
|
||||
if (time(NULL) > load->overcurrent_timestamp + 30*60) { // wait 5 min (TODO: make configurable)
|
||||
load->state = LOAD_STATE_DISABLED; // switch to normal mode again
|
||||
load->switch_state = LOAD_STATE_DISABLED; // switch to normal mode again
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ void load_check_overcurrent(load_output_t *load)
|
||||
hw_load_switch(false);
|
||||
hw_usb_out(false);
|
||||
load->enabled = false;
|
||||
load->state = LOAD_STATE_OFF_OVERCURRENT;
|
||||
load->switch_state = LOAD_STATE_OFF_OVERCURRENT;
|
||||
load->overcurrent_timestamp = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-17
@@ -20,34 +20,30 @@
|
||||
/** @file
|
||||
*
|
||||
* @brief
|
||||
* Load output functions and data types
|
||||
* Load/USB output functions and data types
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/** Load/USB output states
|
||||
*
|
||||
* Used for USB or normal load outputs connecting to battery via switch.
|
||||
*/
|
||||
enum load_state_t {
|
||||
LOAD_STATE_DISABLED = 0, ///< Load actively disabled
|
||||
LOAD_STATE_ON, ///< Normal state: Load on
|
||||
LOAD_STATE_OFF_LOW_SOC, ///< Load off to protect battery (overrules remote setting)
|
||||
LOAD_STATE_OFF_OVERCURRENT ///< Load off to protect charge controller (overrules remote setting)
|
||||
LOAD_STATE_DISABLED = 0, ///< Actively disabled
|
||||
LOAD_STATE_ON, ///< Normal state: On
|
||||
LOAD_STATE_OFF_LOW_SOC, ///< Off to protect battery (overrules target setting)
|
||||
LOAD_STATE_OFF_OVERCURRENT ///< Off to protect charge controller (overrules target setting)
|
||||
};
|
||||
|
||||
|
||||
enum usb_state_t {
|
||||
USB_STATE_DISABLED = 0, ///< USB port actively disabled
|
||||
USB_STATE_ON, ///< Normal state: USB on
|
||||
USB_STATE_OFF_LOW_SOC, ///< USB off to protect battery (overrules target setting)
|
||||
USB_STATE_OFF_OVERCURRENT ///< USB off to protect charge controller (overrules target setting)
|
||||
};
|
||||
|
||||
|
||||
/** Load Output type
|
||||
/** Load output type
|
||||
*
|
||||
* Stores status of load output incl. 5V USB output (if existing on PCB)
|
||||
*/
|
||||
typedef struct {
|
||||
load_state_t state;
|
||||
usb_state_t usb_state;
|
||||
uint16_t switch_state; ///< Current state of load output switch
|
||||
uint16_t usb_state; ///< Current state of USB output
|
||||
float current; ///< actual measurement
|
||||
float current_max; ///< maximum allowed current
|
||||
int overcurrent_timestamp; ///< time at which an overcurrent event occured
|
||||
@@ -56,10 +52,16 @@ typedef struct {
|
||||
bool usb_enabled_target; ///< same for USB output
|
||||
} load_output_t;
|
||||
|
||||
/** Initialize load_output_t struct
|
||||
*/
|
||||
void load_init(load_output_t *load);
|
||||
|
||||
/** State machine, called every second.
|
||||
*/
|
||||
void load_state_machine(load_output_t *load, bool source_enabled);
|
||||
|
||||
/** Overcurrent check function, should be called as often as possible
|
||||
*/
|
||||
void load_check_overcurrent(load_output_t *load);
|
||||
|
||||
#endif /* LOAD_H */
|
||||
|
||||
+20
-13
@@ -33,29 +33,36 @@
|
||||
* the control algorithm.
|
||||
*/
|
||||
typedef struct {
|
||||
float voltage; // actual measurements
|
||||
float current;
|
||||
float voltage; ///< measured voltage
|
||||
float current; ///< measured current
|
||||
|
||||
float voltage_output_target; // target voltage if port is configured as output
|
||||
float droop_resistance; // v_target = v_out_max - r_droop * current
|
||||
float voltage_output_min; // minimum voltage to allow current output (necessary
|
||||
// to prevent charging of deep-discharged Li-ion batteries)
|
||||
float voltage_output_target; ///< target voltage if port is configured as output
|
||||
float droop_resistance; ///< v_target = v_out_max - r_droop * current
|
||||
float voltage_output_min; ///< minimum voltage to allow current output (necessary
|
||||
///< to prevent charging of deep-discharged Li-ion batteries)
|
||||
|
||||
// minimum voltage to allow current input (= discharging of batteries)
|
||||
float voltage_input_start; // starting point for discharging of batteries (load reconnect)
|
||||
float voltage_input_stop; // absolute minimum = load disconnect for batteries
|
||||
|
||||
float current_output_max; // charging direction for battery port
|
||||
float current_input_max; // discharging direction for battery port: must be negative value !!!
|
||||
float voltage_input_start; ///< minimum voltage to allow current input (= discharging of batteries),
|
||||
///< starting point for discharging of batteries (load reconnect)
|
||||
float voltage_input_stop; ///< absolute minimum = load disconnect for batteries
|
||||
|
||||
bool output_allowed; // charging direction for battery port
|
||||
bool input_allowed; // discharging direction for battery port
|
||||
float current_output_max; ///< charging direction for battery port
|
||||
float current_input_max; ///< discharging direction for battery port: must be negative value !!!
|
||||
|
||||
bool output_allowed; ///< charging direction for battery port
|
||||
bool input_allowed; ///< discharging direction for battery port
|
||||
} power_port_t;
|
||||
|
||||
/** Initialize power port for battery connection
|
||||
*/
|
||||
void power_port_init_bat(power_port_t *port, battery_conf_t *bat);
|
||||
|
||||
/** Initialize power port for solar panel connection
|
||||
*/
|
||||
void power_port_init_solar(power_port_t *port);
|
||||
|
||||
/** Initialize power port for nanogrid connection
|
||||
*/
|
||||
void power_port_init_nanogrid(power_port_t *port);
|
||||
|
||||
#endif /* POWER_PORT_H */
|
||||
|
||||
Reference in New Issue
Block a user