Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aalc: Add function of pump running time and clear pump running time #2042

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions meta-facebook/aalc-rpu/src/platform/plat_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
#define BUS_8_MUX_ADDR 0xE8 >> 1
#define BUS_9_MUX_ADDR 0xE8 >> 1

#define MUX_CHANNEL_0 1
#define MUX_CHANNEL_1 2
#define MUX_CHANNEL_2 4
#define MUX_CHANNEL_3 8

typedef struct _ads112c_post_arg {
uint8_t plat_sensor_type;
} ads112c_post_arg;
Expand Down
184 changes: 184 additions & 0 deletions meta-facebook/aalc-rpu/src/platform/plat_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@
#include "plat_pwm.h"
#include "plat_status.h"
#include "plat_isr.h"
#include "plat_fru.h"

LOG_MODULE_REGISTER(plat_hwmon);

static uint32_t pump1_last_switch_time = 0;
static uint32_t pump2_last_switch_time = 0;
static uint32_t pump3_last_switch_time = 0;
static uint32_t pump1_current_boot_unrunning_time = 0;
static uint32_t pump2_current_boot_unrunning_time = 0;
static uint32_t pump3_current_boot_unrunning_time = 0;
static uint32_t last_auto_tune_flag = 0;

bool modbus_pump_setting_unsupport_function(pump_reset_struct *data, uint8_t bit_val)
{
CHECK_NULL_ARG_WITH_RETURN(data, false);
Expand Down Expand Up @@ -144,6 +153,11 @@ bool pump_setting_set_auto_tune_flag(pump_reset_struct *data, uint8_t bit_val)
}

set_status_flag(STATUS_FLAG_AUTO_TUNE, 0, bit_val);
if (bit_val != last_auto_tune_flag) {
set_pump_uptime_secs(true, true, true);

last_auto_tune_flag = bit_val;
}

return true;
}
Expand Down Expand Up @@ -415,4 +429,174 @@ uint8_t pwm_control(uint8_t group, uint8_t duty)
return 0;

return 1;
}

bool get_pump_last_switch_time(uint8_t pump_num, uint32_t *return_uptime)
{
switch (pump_num) {
case PUMP_1_UPTIME:
*return_uptime = pump1_last_switch_time;

break;
case PUMP_2_UPTIME:
*return_uptime = pump2_last_switch_time;

break;
case PUMP_3_UPTIME:
*return_uptime = pump3_last_switch_time;

break;
default:
LOG_ERR("unknow pump_num %d when get pump last switch time", pump_num);
return false;
}

return true;
}

bool get_pump_current_boot_unrunning_time(uint8_t pump_num, uint32_t *return_uptime)
{
switch (pump_num) {
case PUMP_1_UPTIME:
*return_uptime = pump1_current_boot_unrunning_time;

break;
case PUMP_2_UPTIME:
*return_uptime = pump2_current_boot_unrunning_time;

break;
case PUMP_3_UPTIME:
*return_uptime = pump3_current_boot_unrunning_time;

break;
default:
LOG_ERR("unknow pump_num %d when get pump current boot unrunning time", pump_num);
return false;
}

return true;
}

pump_running_time pump_running_time_info[] = {
{ PUMP_1_UPTIME, EEPROM_PUMP1_UPTIME_SIZE, EEPROM_PUMP1_UPTIME_OFFSET },
{ PUMP_2_UPTIME, EEPROM_PUMP2_UPTIME_SIZE, EEPROM_PUMP2_UPTIME_OFFSET },
{ PUMP_3_UPTIME, EEPROM_PUMP3_UPTIME_SIZE, EEPROM_PUMP3_UPTIME_OFFSET },
};

bool read_pump_running_time_data_from_eeprom(uint8_t pump_num, uint32_t *return_data)
{
if (pump_num >= PUMP_MAX_NUM) {
LOG_ERR("unknow pump_num when read data from eeprom %d", pump_num);
return false;
}

// read from eeprom
uint8_t tmp_read_data[4] = { 0 }; // 4 bytes
uint16_t offset = 0;

offset = pump_running_time_info[pump_num].eeprom_offset;

if (!plat_eeprom_read(offset, tmp_read_data, pump_running_time_info->size)) {
LOG_ERR("read %d uptime fail!, ", pump_num);
return false;
}

*return_data = (tmp_read_data[0] << 24) | (tmp_read_data[1] << 16) |
(tmp_read_data[2] << 8) | tmp_read_data[3];

return true;
}

bool get_pump_uptime_secs(uint8_t pump_num, uint32_t *return_uptime)
{
CHECK_NULL_ARG_WITH_RETURN(return_uptime, false);

if (pump_num > PUMP_MAX_NUM) {
LOG_ERR("unknow pump_num when read pump uptime secs %d", pump_num);
return false;
}

// get pump running time from eeprom
uint32_t tmp_uptime = 0;
if (!read_pump_running_time_data_from_eeprom(pump_num, &tmp_uptime))
return false;

uint32_t tmp_last_switch_time = 0;
if (!get_pump_last_switch_time(pump_num, &tmp_last_switch_time))
return false;

uint32_t tmp_current_boot_unrunning_time = 0;
if (!get_pump_current_boot_unrunning_time(pump_num, &tmp_current_boot_unrunning_time))
return false;

// if auto tune is on
if (get_status_flag(STATUS_FLAG_AUTO_TUNE))
*return_uptime =
tmp_uptime + (k_uptime_get_32() / 1000) - tmp_current_boot_unrunning_time;
else
*return_uptime =
tmp_uptime + (tmp_last_switch_time - tmp_current_boot_unrunning_time);
return true;
}

bool set_pump_uptime_secs(uint8_t pump_1_set, uint8_t pump_2_set, uint8_t pump_3_set)
{
bool auto_tune_flag = get_status_flag(STATUS_FLAG_AUTO_TUNE);

if (auto_tune_flag == last_auto_tune_flag)
return true;

if (pump_1_set) {
if (auto_tune_flag)
pump1_current_boot_unrunning_time +=
(k_uptime_get_32() / 1000 - pump1_last_switch_time);

pump1_last_switch_time = k_uptime_get_32() / 1000;
}

if (pump_2_set) {
if (auto_tune_flag)
pump2_current_boot_unrunning_time +=
(k_uptime_get_32() / 1000 - pump2_last_switch_time);

pump2_last_switch_time = k_uptime_get_32() / 1000;
}

if (pump_3_set) {
if (auto_tune_flag)
pump3_current_boot_unrunning_time +=
(k_uptime_get_32() / 1000 - pump3_last_switch_time);

pump3_last_switch_time = k_uptime_get_32() / 1000;
}

last_auto_tune_flag = auto_tune_flag;

return true;
}

bool modbus_clear_pump_running_time_function(pump_reset_struct *data, uint8_t bit_val)
{
CHECK_NULL_ARG_WITH_RETURN(data, false);
if (bit_val == 0) // do nothing
return true;

// clear eeprom
uint8_t total_size =
EEPROM_PUMP1_UPTIME_SIZE + EEPROM_PUMP2_UPTIME_SIZE + EEPROM_PUMP3_UPTIME_SIZE;
uint8_t clear_data[12] = { 0 };

if (!plat_eeprom_write(EEPROM_PUMP1_UPTIME_OFFSET, clear_data, total_size)) {
LOG_ERR("clear pump running time fail!");
return false;
}

pump1_last_switch_time = k_uptime_get_32() / 1000;
pump2_last_switch_time = k_uptime_get_32() / 1000;
pump3_last_switch_time = k_uptime_get_32() / 1000;
pump1_current_boot_unrunning_time = k_uptime_get_32() / 1000;
pump2_current_boot_unrunning_time = k_uptime_get_32() / 1000;
pump3_current_boot_unrunning_time = k_uptime_get_32() / 1000;

return true;
}
18 changes: 18 additions & 0 deletions meta-facebook/aalc-rpu/src/platform/plat_hwmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ typedef struct _pump_reset_struct {
uint8_t senser_num;
} pump_reset_struct;

enum PUMP_NUM {
PUMP_1_UPTIME,
PUMP_2_UPTIME,
PUMP_3_UPTIME,
PUMP_MAX_NUM,
};

typedef struct _pump_running_time_struct {
uint8_t pump_num;
uint8_t size;
uint16_t eeprom_offset;
} pump_running_time;

bool clear_log_for_modbus_pump_setting(pump_reset_struct *data, uint8_t bit_val);
bool pump_setting_pump1_reset(pump_reset_struct *data, uint8_t bit_val);
bool pump_setting_pump2_reset(pump_reset_struct *data, uint8_t bit_val);
Expand All @@ -52,3 +65,8 @@ void set_pump_redundant_switch_time(uint8_t time);
void set_pump_redundant_switch_time_type(uint8_t type);
void pump_redundant_enable(uint8_t onoff);
uint8_t pwm_control(uint8_t group, uint8_t duty);
bool get_pump_uptime_secs(uint8_t pump_num, uint32_t *return_uptime);
bool set_pump_uptime_secs(uint8_t pump_1_set, uint8_t pump_2_set, uint8_t pump_3_set);
bool get_pump_last_switch_time(uint8_t pump_num, uint32_t *return_uptime);
bool get_pump_current_boot_unrunning_time(uint8_t pump_num, uint32_t *return_uptime);
bool modbus_clear_pump_running_time_function(pump_reset_struct *data, uint8_t bit_val);
21 changes: 19 additions & 2 deletions meta-facebook/aalc-rpu/src/platform/plat_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "plat_status.h"
#include "plat_fru.h"

#define SURPRISE_SHUTDOWN_TOTAL_TIME_LENGTH \
(EEPROM_UPTIME_SIZE + EEPROM_PUMP1_UPTIME_SIZE + EEPROM_PUMP2_UPTIME_SIZE + \
EEPROM_PUMP3_UPTIME_SIZE)

LOG_MODULE_REGISTER(plat_isr);

void deassert_all_rpu_ready_pin(void)
Expand Down Expand Up @@ -128,6 +132,7 @@ void aalc_leak_behavior(uint8_t sensor_num)

void shutdown_save_uptime_action()
{
// get total uptime
uint8_t pre_time[EEPROM_UPTIME_SIZE] = { 0 };
if (!plat_eeprom_read(EEPROM_UPTIME_OFFSET, pre_time, EEPROM_UPTIME_SIZE))
LOG_ERR("read uptime fail!");
Expand All @@ -141,12 +146,24 @@ void shutdown_save_uptime_action()

get_uptime_mins += old_uptime;

uint8_t temp[EEPROM_UPTIME_SIZE] = { 0 };
uint8_t temp[SURPRISE_SHUTDOWN_TOTAL_TIME_LENGTH] = { 0 };
temp[0] = get_uptime_mins >> 24;
temp[1] = get_uptime_mins >> 16;
temp[2] = get_uptime_mins >> 8;
temp[3] = get_uptime_mins;

if (!plat_eeprom_write(EEPROM_UPTIME_OFFSET, temp, EEPROM_UPTIME_SIZE))
// get pump uptime
uint32_t pump_uptime_secs = 0;
for (int i = 0; i < PUMP_MAX_NUM; i++) {
if (get_pump_uptime_secs(i, &pump_uptime_secs)) {
temp[4 + i * 4] = (pump_uptime_secs >> 24);
temp[5 + i * 4] = (pump_uptime_secs >> 16);
temp[6 + i * 4] = (pump_uptime_secs >> 8);
temp[7 + i * 4] = (pump_uptime_secs);
}
}

// write total uptime
if (!plat_eeprom_write(EEPROM_UPTIME_OFFSET, temp, SURPRISE_SHUTDOWN_TOTAL_TIME_LENGTH))
LOG_ERR("write uptime fail!");
}
23 changes: 19 additions & 4 deletions meta-facebook/aalc-rpu/src/platform/plat_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pump_reset_struct modbus_pump_setting_table[] = {
{ SYSTEM_STOP, close_pump, 0 },
{ RPU_REMOTE_POWER_CYCLE, rpu_remote_power_cycle_function, 0 },
{ MANUAL_CONTROL, modbus_pump_setting_unsupport_function, 0 },
{ CLEAR_PUMP_RUNNING_TIME, modbus_pump_setting_unsupport_function, 0 },
{ CLEAR_PUMP_RUNNING_TIME, modbus_clear_pump_running_time_function, 0 },
{ CLEAR_LOG, clear_log_for_modbus_pump_setting, 0 },
{ PUMP_1_RESET, pump_setting_pump1_reset, 0 },
{ PUMP_2_RESET, pump_setting_pump2_reset, 0 },
Expand Down Expand Up @@ -666,6 +666,21 @@ uint8_t modbus_read_time_since_last_on(modbus_command_mapping *cmd)
return MODBUS_EXC_NONE;
}

uint8_t modbus_read_pump_running_time(modbus_command_mapping *cmd)
{
CHECK_NULL_ARG_WITH_RETURN(cmd, MODBUS_EXC_ILLEGAL_DATA_VAL);
uint32_t pump_uptime_sec = 0;
if (get_pump_uptime_secs(cmd->arg0, &pump_uptime_sec)) {
cmd->data[0] = pump_uptime_sec >> 16;
cmd->data[1] = pump_uptime_sec & 0xffff;
} else {
LOG_ERR("read pump running time fail!");
return MODBUS_EXC_SERVER_DEVICE_FAILURE;
}

return MODBUS_EXC_NONE;
}

modbus_command_mapping modbus_command_table[] = {
// addr, write_fn, read_fn, arg0, arg1, arg2, size
{ MODBUS_BPB_RPU_COOLANT_FLOW_RATE_LPM_ADDR, NULL, modbus_get_senser_reading,
Expand Down Expand Up @@ -757,9 +772,9 @@ modbus_command_mapping modbus_command_table[] = {
SENSOR_NUM_PB_3_HSC_P48V_IOUT_CURR_A, 1, -1, 1 },
{ MODBUS_BB_HSC_P48V_PIN_PWR_W_ADDR, NULL, modbus_get_senser_reading,
SENSOR_NUM_BB_HSC_P48V_PIN_PWR_W, 1, -1, 1 },
{ MODBUS_PUMP_1_RUNNING_ADDR, NULL, modbus_to_do_get, 0, 0, 0, 2 },
{ MODBUS_PUMP_2_RUNNING_ADDR, NULL, modbus_to_do_get, 0, 0, 0, 2 },
{ MODBUS_PUMP_3_RUNNING_ADDR, NULL, modbus_to_do_get, 0, 0, 0, 2 },
{ MODBUS_PUMP_1_RUNNING_ADDR, NULL, modbus_read_pump_running_time, PUMP_1_UPTIME, 0, 0, 2 },
{ MODBUS_PUMP_2_RUNNING_ADDR, NULL, modbus_read_pump_running_time, PUMP_2_UPTIME, 0, 0, 2 },
{ MODBUS_PUMP_3_RUNNING_ADDR, NULL, modbus_read_pump_running_time, PUMP_3_UPTIME, 0, 0, 2 },
{ MODBUS_BPB_HSC_P48V_PIN_PWR_W_ADDR, NULL, modbus_get_senser_reading,
SENSOR_NUM_BPB_HSC_P48V_PIN_PWR_W, 1, -1, 1 },
{ MODBUS_PB_1_HSC_P48V_PIN_PWR_W_ADDR, NULL, modbus_get_senser_reading,
Expand Down
Loading