Commit 37bdfd74 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/wrsw_hal: bugfix not updating temperatures in wr_mon/HAL

There was a problem with calculating fan timeout in libwr. Problem occurs when
there was a jump back in time. Since gettimeofday was used, delta for timeout
calculation became negative.
One solution was to use monotonic clock like in main function of HAL, or use
the same timeout calculations as main function. Second solution was chosen
since it is much simpler.

--remove calculation of fan/temperature read timeout in function
  shw_update_fans
--remove function shw_pwm_update_timeout and variable fan_update_timeout from
  libwr/fan.c as not needed anymore
--remove function shw_get_tics from libwr/util.c and libwr/util.h (not needed
  anymore)
--remove SHW_FAN_UPDATETO_DEFAULT from libwr/fan.h (not needed anymore)
--increase PORT_FAN_MS_PERIOD to 250ms (trade-off 200ms of port update and 500ms
  of temperatures update)
--remove increasing t1 in HAL;s main, since t1 was overwritten anyway by t2.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent ba32beef
......@@ -47,7 +47,6 @@
#define DESIRED_TEMPERATURE 55.0
static int fan_update_timeout = 0;
static int is_cpu_pwn = 0;
static int enable_d0 = 0;
......@@ -84,12 +83,6 @@ static int pwm_fd;
static volatile struct SPWM_WB *spwm_wbr;
//----------------------------------------
static void shw_pwm_update_timeout(int tout_100ms)
{
fan_update_timeout = tout_100ms * 100000;
pr_info("Fan tick timeout is =%d\n", fan_update_timeout);
}
/* Processes a single sample (x) with Proportional Integrator control algorithm (pi). Returns the value (y) to
drive the actuator. */
static inline float pi_update(pi_controller_t * pi, float x)
......@@ -262,8 +255,6 @@ int shw_init_fans(void)
pi_init(&fan_pi);
shw_pwm_update_timeout(SHW_FAN_UPDATETO_DEFAULT);
return 0;
}
......@@ -273,22 +264,15 @@ int shw_init_fans(void)
*/
void shw_update_fans(struct hal_temp_sensors *sensors)
{
static int64_t last_tics = -1;
int64_t cur_tics = shw_get_tics();
if (fan_update_timeout > 0
&& (last_tics < 0 || (cur_tics - last_tics) > fan_update_timeout)) {
/* drive fan based on PLL temperature */
float t_cur = tmp100_read_temp(TEMP_SENSOR_ADDR_PLL);
float drive = pi_update(&fan_pi, t_cur - DESIRED_TEMPERATURE);
//pr_info("t=%f,pwm=%f\n",t_cur , drive);
shw_pwm_speed(0xFF, drive / 1000); //enable two and one
/* update sensor values */
sensors->fpga = tmp100_read_reg(TEMP_SENSOR_ADDR_FPGA, 0, 2);
sensors->pll = tmp100_read_reg(TEMP_SENSOR_ADDR_PLL, 0, 2);
sensors->psl = tmp100_read_reg(TEMP_SENSOR_ADDR_PSL, 0, 2);
sensors->psr = tmp100_read_reg(TEMP_SENSOR_ADDR_PSR, 0, 2);
last_tics = cur_tics;
}
/* drive fan based on PLL temperature */
float t_cur = tmp100_read_temp(TEMP_SENSOR_ADDR_PLL);
float drive = pi_update(&fan_pi, t_cur - DESIRED_TEMPERATURE);
//pr_info("t=%f,pwm=%f\n",t_cur , drive);
shw_pwm_speed(0xFF, drive / 1000); //enable two and one
/* update sensor values */
sensors->fpga = tmp100_read_reg(TEMP_SENSOR_ADDR_FPGA, 0, 2);
sensors->pll = tmp100_read_reg(TEMP_SENSOR_ADDR_PLL, 0, 2);
sensors->psl = tmp100_read_reg(TEMP_SENSOR_ADDR_PSL, 0, 2);
sensors->psr = tmp100_read_reg(TEMP_SENSOR_ADDR_PSR, 0, 2);
}
......@@ -2,8 +2,6 @@
#define __LIBWR_FAN_H
#include <libwr/hal_shmem.h>
#define SHW_FAN_UPDATETO_DEFAULT 5
int shw_init_fans(void);
void shw_update_fans(struct hal_temp_sensors *sensors);
......
......@@ -8,6 +8,5 @@
void shw_udelay_init(void);
void shw_udelay(uint32_t microseconds);
uint64_t shw_get_tics(void);
#endif /* __LIBWR_HW_UTIL_H */
......@@ -52,12 +52,3 @@ void shw_udelay(uint32_t microseconds)
for (i = 0; i < loops_per_msec * microseconds / 1000; i++)
;
}
uint64_t shw_get_tics()
{
struct timeval tv;
struct timezone tz = { 0, 0 };
gettimeofday(&tv, &tz);
return (uint64_t) tv.tv_usec + (uint64_t) tv.tv_sec * 1000000ULL;
}
......@@ -22,6 +22,7 @@
#include <rt_ipc.h>
#define MAX_CLEANUP_CALLBACKS 16
#define PORT_FAN_MS_PERIOD 250
static int daemon_mode = 0;
static hal_cleanup_callback_t cleanup_cb[MAX_CLEANUP_CALLBACKS];
......@@ -223,7 +224,6 @@ int main(int argc, char *argv[])
* is some jitter from hal_update_wripc() timing.
* includes some jitter.
*/
#define PORT_FAN_MS_PERIOD 200
clock_gettime(CLOCK_MONOTONIC, &t1);
for (;;) {
......@@ -237,13 +237,6 @@ int main(int argc, char *argv[])
if (delay_ms < PORT_FAN_MS_PERIOD)
continue;
/* update the "previous" stamp */
t1.tv_nsec += PORT_FAN_MS_PERIOD * 1000 * 1000;
if (t1.tv_nsec > 1000 * 1000 * 1000) {
t1.tv_nsec -= 1000 * 1000 * 1000;
t1.tv_sec++;
}
hal_port_update_all();
/* update fans and temperatures in shmem */
shw_update_fans(&hal_shmem->temp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment