Commit 1cc870d5 authored by Tristan Gingold's avatar Tristan Gingold

Revice temperature.

Extract temperature.h from sensors.h
parent 194c69d2
......@@ -87,55 +87,6 @@ struct wrc_sensor* wrc_sensor_find_by_type(uint8_t type)
}
#if 0
extern int wrc_temp_format(char *buffer, int len)
{
struct wrc_onetemp *p;
int l = 0, i = 0;
int32_t t;
for (p = wrc_temp_getnext(NULL); p; p = wrc_temp_getnext(p), i++) {
if (l + 16 > len) {
l += sprintf(buffer + l, " ENOSPC");
return l;
}
t = p->t;
l += sprintf(buffer + l, "%s%s:", i ? " " : "", p->name);
if (t == TEMP_INVALID) {
l += sprintf(buffer + l, "INVALID");
continue;
}
if (t < 0) {
t = -(signed)t;
l += sprintf(buffer + l, "-");
}
l += sprintf(buffer + l,"%d.%04d", t >> 16,
((t & 0xffff) * 10 * 1000 >> 16));
}
return l;
}
/*
* The task
*/
void wrc_temp_init(void)
{
}
int wrc_temp_refresh(void)
{
#if 0
struct wrc_temp *ta;
int ret = 0;
for (ta = __temp_begin; ta < __temp_end; ta++)
ret += ta->read(ta);
return (ret > 0);
#endif
}
#endif
/*
* The shell command
*/
......
......@@ -9,7 +9,7 @@
#include <wrc.h>
#include <dev/w1.h>
#include "sensors.h"
#include "dev/temperature.h"
static struct wrc_temp_sensor temp_w1_data[] = {
{"pcb", TEMP_INVALID},
......@@ -20,7 +20,7 @@ static unsigned long nextt;
static int niterations;
/* Returns 1 if it did something */
static int temp_w1_refresh(struct wrc_temp_group *t)
static int temp_w1_refresh(struct wrc_temp_sensor *t)
{
static int done;
......@@ -30,7 +30,7 @@ static int temp_w1_refresh(struct wrc_temp_group *t)
}
/* Odd iterations: send the command, even iterations: read back */
int phase = niterations & 1;
static int intervals[] = {
static const int intervals[] = {
200, (1000 * CONFIG_TEMP_POLL_INTERVAL) - 200
};
......@@ -56,7 +56,6 @@ void temp_w1_init(void)
{
struct wrc_temp_group tbr;
tbr.used = 1;
tbr.read = temp_w1_refresh;
tbr.t = temp_w1_data;
wrc_temp_register(&tbr);
......
......@@ -9,11 +9,12 @@
#include <wrc.h>
#include <string.h>
#include <temperature.h>
#include <dev/temperature.h>
#include <shell.h>
struct wrc_temp_group temp_sensors[WRC_MAX_TEMPERATURES];
/*
* Library functions
*/
......@@ -24,7 +25,7 @@ uint32_t wrc_temp_get(char *name)
int i;
if (!name)
return TEMP_INVALID;
return TEMP_INVALID;
/* get search all temperature groups */
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
......@@ -100,17 +101,15 @@ extern int wrc_temp_format(char *buffer, int len)
int wrc_temp_register(struct wrc_temp_group *new_temp_sensor)
{
struct wrc_temp_group *tmp;
int i;
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
tmp = &temp_sensors[i];
if (tmp->used) {
struct wrc_temp_group *grp = &temp_sensors[i];
if (grp->t) {
/* slot used in the list */
continue;
}
pp_printf("register temp sensor at %d\n", i);
*tmp = *new_temp_sensor;
*grp = *new_temp_sensor;
return 1;
}
......@@ -123,15 +122,17 @@ int wrc_temp_register(struct wrc_temp_group *new_temp_sensor)
*/
int wrc_temp_refresh(void)
{
struct wrc_temp_group *tmp;
int i;
int ret = 0;
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
tmp = &temp_sensors[i];
if (tmp->used) {
ret += tmp->read(tmp);
}
struct wrc_temp_group *grp = &temp_sensors[i];
struct wrc_temp_sensor *sensor;
if (!grp->t)
continue;
for (sensor = grp->t; sensor->name; sensor++)
ret += grp->read(sensor);
}
return (ret > 0);
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2016 GSI (www.gsi.de)
* Author: Alessandro rubini
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __TEMPERATURE_H__
#define __TEMPERATURE_H__
#include <stdint.h>
#ifdef CONFIG_TEMP_SENSORS
#define HAS_TEMP_SENSORS 1
#define WRC_MAX_TEMPERATURES 4
#else
#define HAS_TEMP_SENSORS 0
#define WRC_MAX_TEMPERATURES 0
#endif
#define TEMP_INVALID (0x8000 << 16)
/* A single temperature sensor */
struct wrc_temp_sensor {
char *name;
int32_t t; /* fixed point, 16.16 (signed!) */
};
/* A list of temperature sensors */
struct wrc_temp_group {
int (*read)(struct wrc_temp_sensor *);
struct wrc_temp_sensor *t; /* zero-terminated */
};
/* lib functions */
extern uint32_t wrc_temp_get(char *name);
struct wrc_temp_sensor *wrc_temp_getnext(struct wrc_temp_sensor *);
extern int wrc_temp_format(char *buffer, int len);
void wrc_temp_init(void);
int wrc_temp_refresh(void);
int wrc_temp_register(struct wrc_temp_group *new_temp_sensor);
#ifdef CONFIG_TEMP_SENSORS
extern struct wrc_temp_group temp_sensors[WRC_MAX_TEMPERATURES];
#endif
#endif /* __TEMPERATURE_H__ */
......@@ -11,14 +11,7 @@
#include <stdint.h>
#ifdef CONFIG_TEMP_SENSORS
#define HAS_TEMP_SENSORS 1
#define WRC_MAX_TEMPERATURES 4
#else
#define HAS_TEMP_SENSORS 0
#define WRC_MAX_TEMPERATURES 0
#endif
/* Flags. */
#define WRC_SENSOR_TEMP_CELSIUS (1<<0)
#define WRC_SENSOR_CURRENT_MA (1<<1)
#define WRC_SENSOR_VOLTAGE_MV (1<<2)
......@@ -34,25 +27,6 @@ struct wrc_sensor
int16_t value;
};
struct wrc_onetemp {
char *name;
int32_t t; /* fixed point, 16.16 (signed!) */
};
struct wrc_temp {
int used;
int (*read)(struct wrc_temp *);
void *data;
struct wrc_onetemp *t; /* zero-terminated */
};
/* lib functions */
extern uint32_t wrc_temp_get(char *name);
struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *);
extern int wrc_temp_format(char *buffer, int len);
void wrc_temp_init(void);
int wrc_temp_refresh(void);
/* generic sensor functions */
void wrc_register_sensors( struct wrc_sensor* s);
struct wrc_sensor* wrc_sensor_find_by_name(char *name);
......
......@@ -15,7 +15,7 @@
#include "ppsi/ppsi.h"
#include "wrpc.h"
#include "dev/wdiags.h"
#include "sensors.h"
#include "dev/temperature.h"
#include "softpll/softpll_ng.h"
#include "dev/netif.h"
#include "dev/pps_gen.h"
......
......@@ -12,12 +12,12 @@
#include <inttypes.h>
#include "wrc-task.h"
#include "sensors.h"
#include "wrpc.h"
#include "softpll/softpll_ng.h"
#include "dev/endpoint.h"
#include "dev/netif.h"
#include "dev/pps_gen.h"
#include "dev/temperature.h"
#include "wrc_global.h"
#include "shell.h"
......
......@@ -13,7 +13,6 @@
#include <errno.h>
int wrc_stat_running;
extern uint32_t wrc_stats_last;
static int cmd_stat(const char *args[])
{
......
......@@ -21,6 +21,7 @@
#include "dev/temp-fake.h"
#include "dev/temp-w1.h"
#include "dev/w1.h"
#include "dev/temperature.h"
#include "shell.h"
#include "storage.h"
......
......@@ -43,6 +43,7 @@
#include "dev/w1.h"
#include "dev/temp-fake.h"
#include "dev/temp-w1.h"
#include "dev/temperature.h"
#include "sensors.h"
#include "board.h"
......
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