Add latching pgood function to USB power output

This commit is contained in:
Jordan Silverman
2021-01-14 19:07:19 +01:00
committed by Martin Jäger
parent 3653b88d25
commit bcf54f6698
6 changed files with 54 additions and 22 deletions
+9 -3
View File
@@ -23,14 +23,15 @@
extern DeviceStatus dev_stat;
LoadOutput::LoadOutput(DcBus *dc_bus, void (*drv_switch_fn)(bool), void (*drv_init_fn)()) :
LoadOutput::LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)(), bool (*pgood_fn)()) :
PowerPort(dc_bus),
switch_set(drv_switch_fn)
switch_set(switch_fn),
pgood_check(pgood_fn)
{
state = LOAD_STATE_OFF;
// call driver initialization function
drv_init_fn();
init_fn();
switch_set(false);
junction_temperature = 25; // starting point: 25°C
@@ -61,6 +62,11 @@ void LoadOutput::control()
oc_timestamp = uptime();
}
if (pgood_check != NULL && !pgood_check()) {
flags_set(&error_flags, ERR_LOAD_OVERCURRENT);
oc_timestamp = uptime();
}
// negative margin means sourcing current from bus is allowed
if (bus->src_current_margin > -0.1F) {
flags_set(&error_flags, ERR_LOAD_BUS_SRC_CURRENT);
+11 -3
View File
@@ -96,10 +96,11 @@ public:
* Initialize LoadOutput struct and overcurrent / short circuit protection comparator (if existing)
*
* @param dc_bus DC bus the load is connected to
* @param switch_set Pointer to function for enabling/disabling load switch
* @param init Pointer to function for load driver initialization
* @param switch_fn Pointer to function for enabling/disabling load switch
* @param init_fn Pointer to function for load driver initialization
* @param pgood_fn Pointer to pgood check
*/
LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)());
LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)(), bool (*pgood_fn)());
/** Main load control function, should be called by control timer
*
@@ -158,6 +159,11 @@ private:
*/
void (*switch_set)(bool);
/**
* Pointer to the function to check the power output status
*/
bool (*pgood_check)(void);
/**
* Used to prevent switching of because of very short voltage dip
*/
@@ -183,6 +189,8 @@ void usb_out_set(bool);
void load_short_circuit_stop();
bool pgood_check();
#ifdef __cplusplus
}
#endif
+15
View File
@@ -171,6 +171,10 @@ void usb_out_set(bool status)
DT_GPIO_FLAGS(USB_GPIO, gpios) | GPIO_OUTPUT_INACTIVE);
if (status == true) {
gpio_pin_set(dev_usb, DT_GPIO_PIN(USB_GPIO, gpios), 1);
#if DT_PROP(DT_CHILD(DT_PATH(outputs), usb_pwr), latching_pgood)
k_sleep(K_MSEC(50));
gpio_pin_configure(dev_usb, DT_GPIO_PIN(USB_GPIO, gpios), GPIO_INPUT);
#endif
}
else {
gpio_pin_set(dev_usb, DT_GPIO_PIN(USB_GPIO, gpios), 0);
@@ -219,6 +223,15 @@ void usb_out_init()
#endif
}
bool pgood_check()
{
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr))
return gpio_pin_get(dev_usb, DT_GPIO_PIN(USB_GPIO, gpios));
#else
return false;
#endif
}
#else // UNIT_TEST
void load_out_init() {;}
@@ -227,4 +240,6 @@ void usb_out_init() {;}
void load_out_set(bool value) {;}
void usb_out_set(bool value) {;}
bool pgood_check() { return false; }
#endif
+2 -2
View File
@@ -45,11 +45,11 @@ PwmSwitch pwm_switch(&lv_bus);
#endif
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load))
LoadOutput load(&lv_bus, &load_out_set, &load_out_init);
LoadOutput load(&lv_bus, &load_out_set, &load_out_init, NULL);
#endif
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr))
LoadOutput usb_pwr(&lv_bus, &usb_out_set, &usb_out_init);
LoadOutput usb_pwr(&lv_bus, &usb_out_set, &usb_out_init, &pgood_check);
#endif
#if CONFIG_HV_TERMINAL_SOLAR