Merge "Code cleanup/refactor."
diff --git a/sysmgr/peripheral/fancontrol.cc b/sysmgr/peripheral/fancontrol.cc
index 3436c12..f22f62a 100644
--- a/sysmgr/peripheral/fancontrol.cc
+++ b/sysmgr/peripheral/fancontrol.cc
@@ -218,7 +218,7 @@
bool FanControl::Init(bool *gpio_mailbox_ready) {
/* Check if the platform instance has been initialized
- * 1) If run sysmgr, the platformInstance_ would be initalized in
+ * 1) If run sysmgr, the platform_ would be initalized in
* platformperipheral module.
* 2) If run test_fan test util, the platformperipheral module won't be used.
*/
@@ -253,95 +253,95 @@
}
void FanControl::InitParams() {
- pfan_ctrl_params_ = new FanControlParams[BRUNO_PARAMS_TYPES];
+ pfan_ctrl_params_ = new FanControlParams[BRUNO_PARAMS_TYPES_MAX];
- uint8_t max;
- switch (platform_ = platformInstance_->PlatformType()) {
+ switch (platform_->PlatformType()) {
case BRUNO_GFMS100:
/* Set thermal fan policy parameters of GFMS100 */
pfan_ctrl_params_[BRUNO_SOC] = kGFMS100FanCtrlSocDefaults;
pfan_ctrl_params_[BRUNO_IS_HDD] = kGFMS100FanCtrlHddDefaults;
- max = BRUNO_IS_HDD;
break;
case BRUNO_GFHD100:
/* Set thermal fan policy parameters of GFHD100 */
pfan_ctrl_params_[BRUNO_SOC] = kGFHD100FanCtrlSocDefaults;
- max = BRUNO_SOC;
break;
case BRUNO_GFHD200:
pfan_ctrl_params_[BRUNO_SOC] = kGFHD200FanCtrlSocDefaults;
- max = BRUNO_SOC;
break;
case BRUNO_GFHD254:
pfan_ctrl_params_[BRUNO_SOC] = kGFHD254FanCtrlSocDefaults;
- max = BRUNO_SOC;
break;
case BRUNO_GFRG200:
/* Set thermal fan policy parameters of GFRG200 */
pfan_ctrl_params_[BRUNO_SOC] = kGFRG200FanCtrlSocDefaults;
- max = BRUNO_SOC;
break;
case BRUNO_GFRG210:
/* Set thermal fan policy parameters of GFRG210 */
pfan_ctrl_params_[BRUNO_SOC] = kGFRG210FanCtrlSocDefaults;
pfan_ctrl_params_[BRUNO_IS_HDD] = kGFRG210FanCtrlHddDefaults;
- max = BRUNO_IS_HDD;
break;
case BRUNO_GFRG250:
/* Set thermal fan policy parameters of GFRG250 */
pfan_ctrl_params_[BRUNO_SOC] = kGFRG250FanCtrlSocDefaults;
pfan_ctrl_params_[BRUNO_IS_HDD] = kGFRG250FanCtrlHddDefaults;
pfan_ctrl_params_[BRUNO_AUX1] = kGFRG250FanCtrlAux1Defaults;
- max = BRUNO_AUX1;
break;
case BRUNO_GFSC100:
/* Set thermal fan policy parameters of GFSC100 */
pfan_ctrl_params_[BRUNO_SOC] = kGFSC100FanCtrlSocDefaults;
pfan_ctrl_params_[BRUNO_IS_HDD] = kGFSC100FanCtrlHddDefaults;
- max = BRUNO_IS_HDD;
break;
case BRUNO_GFLT110:
pfan_ctrl_params_[BRUNO_SOC] = kGFLT110FanCtrlSocDefaults;
- max = BRUNO_SOC;
break;
case BRUNO_UNKNOWN:
LOG(LS_ERROR) << "Invalid platform type, ignore ... " << platform_;
- max = BRUNO_SOC;
break;
}
/* Check if an external fan control parameter table existing */
dbgUpdateFanControlParams();
- FanControlParams *pfan_ctrl;
- uint8_t idx;
/* Adjust the fan control parameters for calculation. */
- for (idx = 0, pfan_ctrl = pfan_ctrl_params_; idx <= max; idx++, pfan_ctrl++) {
+ for (int i = 0; i < BRUNO_PARAMS_TYPES_MAX; i++) {
const char *suffix;
- switch(idx) {
+ switch(i) {
case BRUNO_SOC:
suffix = "_SOC";
break;
+
case BRUNO_IS_HDD:
suffix = "_HDD";
+ if (!platform_->has_hdd()) {
+ LOG(LS_INFO) << "platform does not have hdd.";
+ continue;
+ }
break;
+
case BRUNO_AUX1:
suffix = "_AUX1";
+ if (!platform_->has_aux1()) {
+ LOG(LS_INFO) << "platform does not have aux1.";
+ continue;
+ }
break;
+
default:
suffix = "_UNKNOWN";
- break;
+ LOG(LS_ERROR) << "Unknown type in fan param array";
+ continue;
}
- LOG(LS_INFO) << platformInstance_->PlatformName()
- << suffix << std::endl
- << " Tsetpt: " << pfan_ctrl->temp_setpt << std::endl
- << " Tmax: " << pfan_ctrl->temp_max << std::endl
- << " Tstep: " << pfan_ctrl->temp_step << std::endl
- << " Dmin: " << pfan_ctrl->duty_cycle_min << std::endl
- << " Dmax: " << pfan_ctrl->duty_cycle_max << std::endl
- << " PWMstep: " << pfan_ctrl->pwm_step << std::endl
- << " Toverheat: " << pfan_ctrl->temp_overheat << std::endl;
+ LOG(LS_INFO)
+ << platform_->PlatformName()
+ << suffix << std::endl
+ << " Tsetpt: " << pfan_ctrl_params_[i].temp_setpt << std::endl
+ << " Tmax: " << pfan_ctrl_params_[i].temp_max << std::endl
+ << " Tstep: " << pfan_ctrl_params_[i].temp_step << std::endl
+ << " Dmin: " << pfan_ctrl_params_[i].duty_cycle_min << std::endl
+ << " Dmax: " << pfan_ctrl_params_[i].duty_cycle_max << std::endl
+ << " PWMstep: " << pfan_ctrl_params_[i].pwm_step << std::endl
+ << " Toverheat: " << pfan_ctrl_params_[i].temp_overheat << std::endl;
}
}
@@ -406,7 +406,7 @@
*phdd_temp = 0;
uint16_t hdd_temp;
- if (platformInstance_->PlatformHasHdd() == true) {
+ if (platform_->has_hdd() == true) {
std::string buf = "hdd-temperature /dev/sda";
/* Create vector to hold hdd temperature words */
std::vector<std::string> tokens;
@@ -449,7 +449,7 @@
uint16_t FanControl::__ComputeDutyCycle(
uint16_t temp,
uint16_t fan_speed,
- FanControlParams ¶ms) {
+ const FanControlParams ¶ms) {
uint16_t compute_duty_cycle = duty_cycle_pwm_;
if (temp > params.temp_max) {
@@ -566,19 +566,17 @@
}
FanControlParams *FanControl::get_hdd_fan_ctrl_parms() {
- FanControlParams *ptr = NULL;
- if (platformInstance_->PlatformHasHdd() == true) {
- ptr = &pfan_ctrl_params_[BRUNO_IS_HDD];
+ if (platform_->has_hdd() == true) {
+ return &pfan_ctrl_params_[BRUNO_IS_HDD];
}
- return ptr;
+ return NULL;
}
FanControlParams *FanControl::get_aux1_fan_ctrl_parms() {
- FanControlParams *ptr = NULL;
- if (platformInstance_->PlatformHasAux1() == true) {
- ptr = &pfan_ctrl_params_[BRUNO_AUX1];
+ if (platform_->has_aux1() == true) {
+ return &pfan_ctrl_params_[BRUNO_AUX1];
}
- return ptr;
+ return NULL;
}
@@ -588,7 +586,7 @@
if (params_table_file.is_open()) {
LOG(LS_INFO) << FAN_CONTROL_PARAMS_FILE << " existing...";
dbgGetFanControlParamsFromParamsFile(BRUNO_SOC);
- if (platformInstance_->PlatformHasHdd() == true) {
+ if (platform_->has_hdd() == true) {
dbgGetFanControlParamsFromParamsFile(BRUNO_IS_HDD);
}
}
@@ -607,7 +605,7 @@
/* Get the search platform keyword in the table file: GFMS100_SOC,
* GFMS100_HDD...
*/
- std::string buf = platformInstance_->PlatformName();
+ std::string buf = platform_->PlatformName();
switch (fc_idx) {
case BRUNO_SOC:
buf += "_SOC";
@@ -626,7 +624,7 @@
LOG(LS_INFO) << buf << std::endl;
- std::string result = platformInstance_->GetLine((char *)FAN_CONTROL_PARAMS_FILE, &buf);
+ std::string result = platform_->GetLine((char *)FAN_CONTROL_PARAMS_FILE, &buf);
if (result.empty() == true)
return false;
diff --git a/sysmgr/peripheral/fancontrol.h b/sysmgr/peripheral/fancontrol.h
index 0460973..26f5532 100644
--- a/sysmgr/peripheral/fancontrol.h
+++ b/sysmgr/peripheral/fancontrol.h
@@ -51,7 +51,7 @@
BRUNO_SOC = 0,
BRUNO_IS_HDD,
BRUNO_AUX1,
- BRUNO_PARAMS_TYPES
+ BRUNO_PARAMS_TYPES_MAX
};
static const unsigned int kPwmDefaultStartup;
@@ -76,6 +76,7 @@
static const FanControlParams kGFHD100FanCtrlSocDefaults;
static const FanControlParams kGFHD200FanCtrlSocDefaults;
+
static const FanControlParams kGFHD254FanCtrlSocDefaults;
static const FanControlParams kGFLT110FanCtrlSocDefaults;
@@ -86,16 +87,16 @@
duty_cycle_pwm_(kPwmMinValue),
duty_cycle_startup_(kPwmDefaultStartup),
period_(DUTY_CYCLE_PWM_MAX_VALUE-1),
- platform_(BRUNO_GFHD100),
pfan_ctrl_params_(NULL),
- platformInstance_(platform) {}
+ platform_(platform) {}
virtual ~FanControl();
bool Init(bool *gpio_mailbox_ready);
void Terminate(void);
bool DrivePwm(uint16_t duty_cycle);
- bool AdjustSpeed(uint16_t soc_temp, uint16_t hdd_temp, uint16_t aux1_temp, uint16_t fan_speed);
+ bool AdjustSpeed(uint16_t soc_temp, uint16_t hdd_temp, uint16_t aux1_temp,
+ uint16_t fan_speed);
void GetHddTemperature(uint16_t *phdd_temp);
void GetOverheatTemperature(uint16_t *poverheat_temp);
@@ -104,7 +105,7 @@
void InitParams(void);
std::string ExecCmd(char* cmd, std::string *pattern);
uint16_t __ComputeDutyCycle(uint16_t temp, uint16_t fan_speed,
- FanControlParams ¶ms);
+ const FanControlParams ¶ms);
void ComputeDutyCycle(uint16_t soc_temp, uint16_t hdd_temp, uint16_t aux1_temp,
uint16_t fan_speed, uint16_t *new_duty_cycle_pwm);
@@ -129,9 +130,8 @@
* idx BRUNO_SOC: depending upon GFMS100 (Bruno-IS) or GFHD100 (Thin Bruno);
* idx BRUNO_IS_HDD: use by HDD GFMS100
* */
- enum BrunoPlatformTypes platform_;
FanControlParams *pfan_ctrl_params_;
- Platform *platformInstance_;
+ Platform *platform_;
FanControlParams *get_hdd_fan_ctrl_parms();
FanControlParams *get_aux1_fan_ctrl_parms();
diff --git a/sysmgr/peripheral/peripheralmon.cc b/sysmgr/peripheral/peripheralmon.cc
index 07d5503..fafb6e4 100644
--- a/sysmgr/peripheral/peripheralmon.cc
+++ b/sysmgr/peripheral/peripheralmon.cc
@@ -21,14 +21,14 @@
uint16_t fan_speed = 0;
std::string soc_voltage;
- if (platform_->PlatformHasHdd() &&
+ if (platform_->has_hdd() &&
bruno_base::TimeIsLaterOrEqual(next_time_hdd_temp_check_, now)) {
fan_control_->GetHddTemperature(&hdd_temp_);
LOG(LS_INFO) << "hdd_temperature (new):" << hdd_temp_;
next_time_hdd_temp_check_ = bruno_base::TimeAfter(hdd_temp_interval_);
}
- if (platform_->PlatformHasAux1()) {
+ if (platform_->has_aux1()) {
ReadAux1Temperature(&aux1_temperature);
}
@@ -39,7 +39,7 @@
bool read_soc_temperature = ReadSocTemperature(&soc_temperature);
ReadSocVoltage(&soc_voltage);
- if (platform_->PlatformHasFan()) {
+ if (platform_->has_fan()) {
ReadFanSpeed(&fan_speed);
}
@@ -53,7 +53,7 @@
Overheating(soc_temperature);
}
- if (platform_->PlatformHasFan()) {
+ if (platform_->has_fan()) {
/* If failed to read soc_temperature, don't change PWM */
if (read_soc_temperature) {
fan_control_->AdjustSpeed(
@@ -102,8 +102,7 @@
}
}
-void PeripheralMon::Init(int interval, int hdd_temp_interval) {
- interval_ = interval;
+void PeripheralMon::Init(int hdd_temp_interval) {
hdd_temp_interval_ = hdd_temp_interval;
next_time_hdd_temp_check_ = bruno_base::Time(); // = now
overheating_ = 0;
diff --git a/sysmgr/peripheral/peripheralmon.h b/sysmgr/peripheral/peripheralmon.h
index 26bdcc1..b9a4855 100644
--- a/sysmgr/peripheral/peripheralmon.h
+++ b/sysmgr/peripheral/peripheralmon.h
@@ -19,24 +19,21 @@
class GpIoFanSpeed;
class PeripheralMon : public Mailbox {
public:
- PeripheralMon(Platform *plat, unsigned int interval = 5000,
- unsigned int hdd_temp_interval = 300000)
- : platform_(plat), fan_control_(new FanControl(plat)), interval_(interval),
- hdd_temp_interval_(hdd_temp_interval), hdd_temp_(0),
+ PeripheralMon(Platform *plat)
+ : platform_(plat), fan_control_(new FanControl(plat)),
+ hdd_temp_interval_(300000), hdd_temp_(0),
last_time_(0), next_time_hdd_temp_check_(0),
gpio_mailbox_ready(false) {
}
virtual ~PeripheralMon();
void Probe(void);
-
- void Init(int interval, int hdd_temp_interval);
+ void Init(int hdd_temp_interval);
private:
void Overheating(float soc_temperature);
Platform* platform_;
bruno_base::scoped_ptr<FanControl> fan_control_;
- int interval_;
int hdd_temp_interval_;
uint16_t hdd_temp_;
unsigned int overheating_;
diff --git a/sysmgr/peripheral/platform.h b/sysmgr/peripheral/platform.h
index c4bfb55..80e0a74 100644
--- a/sysmgr/peripheral/platform.h
+++ b/sysmgr/peripheral/platform.h
@@ -48,9 +48,9 @@
void Init(void);
std::string PlatformName(void) const { return name_; }
enum BrunoPlatformTypes PlatformType(void) const { return type_; }
- bool PlatformHasHdd(void) const { return has_hdd_; }
- bool PlatformHasFan(void) const { return has_fan_; }
- bool PlatformHasAux1(void) const { return has_aux1_; }
+ bool has_hdd(void) const { return has_hdd_; }
+ bool has_fan(void) const { return has_fan_; }
+ bool has_aux1(void) const { return has_aux1_; }
std::string GetLine(char *file, std::string *pattern);
private:
diff --git a/sysmgr/sysmgr.cc b/sysmgr/sysmgr.cc
index 8b67912..fcdc1df 100644
--- a/sysmgr/sysmgr.cc
+++ b/sysmgr/sysmgr.cc
@@ -45,7 +45,7 @@
Platform* platform = new Platform();
platform->Init();
PeripheralMon* pmon = new PeripheralMon(platform);
- pmon->Init(FLAG_interval, FLAG_hdd_temp_interval);
+ pmon->Init(FLAG_hdd_temp_interval);
for (;;) {
pmon->Probe();