Commit 3fcc050a authored by Adam Wujek's avatar Adam Wujek

dev: add support of temp sensors, add support of 1w temp sensor

Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parent 4a9bb60a
......@@ -143,11 +143,6 @@ config WRPC_PPSI
boolean
default y
config W1
depends on EMBEDDED_NODE
boolean
default y
config LATENCY_ETHTYPE
int
default 291
......@@ -427,6 +422,36 @@ config CMD_NETCONSOLE
help
Include command to configure netconsole
config TEMP_SENSORS
depends on WR_NODE
boolean "Add suport for temperature sensors"
default n
help
Adds temp command and periodic task to read temperatures.
Temperatures are can be reported by SNMP, syslog or wrpc-dump.
Please note that temperature sensor type has to be selected as well
(like w1)
config W1
depends on EMBEDDED_NODE
boolean "Add support for W1 bus"
default n
help
Add support for W1 bus
config W1_TEMP
depends on W1 && TEMP_SENSORS
boolean "Add support for W1 temperature sensor"
default n
help
Add support for temperature sensors on W1 bus. Adds w1 command.
config W1_EEPROM
depends on W1
boolean "Add support for W1 eeprom"
default n
help
Add support for eeprom on W1 bus. Adds w1r and w1w commands.
#
# This is a set of configuration options that should not be changed by
# normal users. If the "developer" menu is used, the binary is tainted.
......@@ -688,7 +713,7 @@ config SNMP_VERBOSE
This enables some more diagnostic messages. Normally off.
config TEMP_FAKE
depends on DEVELOPER
depends on DEVELOPER && TEMP_SENSORS
boolean "Offer an array of 3 fake temperatures, for testing"
help
The option adds also a "faketemp" command, used to set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=100
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=4455
CONFIG_LATENCY_SYSLOG=y
CONFIG_IP=y
......@@ -56,6 +55,10 @@ CONFIG_CMD_PPS=y
CONFIG_CMD_SFP_INFO=y
CONFIG_SFP_DOM=y
CONFIG_CMD_LEAPSEC=y
CONFIG_TEMP_SENSORS=y
CONFIG_W1=y
CONFIG_W1_TEMP=y
CONFIG_W1_EEPROM=y
# CONFIG_TRACE_MSGS is not set
CONFIG_TRACE_ALL=0
CONFIG_TRACE_MAIN=0
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_LATENCY_SYSLOG=y
CONFIG_IP=y
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_LATENCY_SYSLOG=y
CONFIG_IP=y
......
......@@ -23,7 +23,6 @@ CONFIG_EMBEDDED_NODE=y
CONFIG_STACKSIZE=10240
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_LATENCY_SYSLOG=y
CONFIG_P2P=y
......
......@@ -26,7 +26,6 @@ CONFIG_VLAN_FOR_CLASS6=20
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
......
......@@ -26,7 +26,6 @@ CONFIG_VLAN_FOR_CLASS6=20
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
......
......@@ -26,7 +26,6 @@ CONFIG_VLAN_FOR_CLASS6=20
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
CONFIG_IPMI_CONSOLE=y
# CONFIG_IP is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -26,7 +26,6 @@ CONFIG_VLAN_FOR_CLASS6=20
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -28,7 +28,6 @@ CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_EMBEDDED_NODE=y
CONFIG_WRPC_PPSI=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=291
# CONFIG_IP is not set
# CONFIG_CMD_CONFIG is not set
......
......@@ -22,7 +22,6 @@ obj-$(CONFIG_EMBEDDED_NODE) += \
dev/netif.o
obj-$(CONFIG_WR_NODE) += \
dev/temperature.o \
dev/pps_gen.o
obj-$(CONFIG_TARGET_WR_SWITCH) += dev/timer-wrs.o dev/gpio.o
......@@ -30,9 +29,10 @@ obj-$(CONFIG_PUTS_SYSLOG) += dev/puts-syslog.o
obj-$(CONFIG_DAC_LOG) += dev/dac_log.o
obj-$(CONFIG_W1) += dev/w1.o dev/w1-hw.o dev/w1-shell.o
obj-$(CONFIG_W1) += dev/w1-temp.o
obj-$(CONFIG_W1) += dev/temp-w1.o
obj-$(CONFIG_W1_EEPROM) += dev/w1-eeprom.o
obj-$(CONFIG_W1_TEMP) += dev/temp-w1.o dev/w1-temp.o
obj-$(CONFIG_TEMP_SENSORS) += dev/temperature.o
obj-$(CONFIG_TEMP_FAKE) += dev/temp-fake.o
obj-$(CONFIG_ETHERBONE) += dev/etherbone.o
......
......@@ -9,26 +9,21 @@
#include <wrc.h>
#include <temperature.h>
#include <shell.h>
#include "dev/temp-fake.h"
static struct wrc_onetemp temp_fake_data[] = {
static struct wrc_temp_sensor temp_fake_data[] = {
{"roof", TEMP_INVALID},
{"core", TEMP_INVALID},
{"case", TEMP_INVALID},
{NULL,}
};
static int temp_fake_refresh(struct wrc_temp *t)
static int temp_fake_refresh(struct wrc_temp_group *t)
{
/* nothing to do */
return 0;
}
#if 0
/* not static at this point, because it's the only one */
DEFINE_TEMPERATURE(w1) = {
.read = temp_fake_refresh,
.t = temp_fake_data,
};
#endif
static int cmd_faketemp(const char *args[])
{
......@@ -54,6 +49,15 @@ static int cmd_faketemp(const char *args[])
return 0;
}
void temp_faketemp_init(void)
{
struct wrc_temp_group tbr;
tbr.used = 1;
tbr.read = temp_fake_refresh;
tbr.t = temp_fake_data;
wrc_temp_register(&tbr);
}
DEFINE_WRC_COMMAND(faketemp) = {
.name = "faketemp",
......
......@@ -11,7 +11,7 @@
#include <dev/w1.h>
#include <temperature.h>
static struct wrc_onetemp temp_w1_data[] = {
static struct wrc_temp_sensor temp_w1_data[] = {
{"pcb", TEMP_INVALID},
{NULL,}
};
......@@ -20,9 +20,8 @@ static unsigned long nextt;
static int niterations;
/* Returns 1 if it did something */
static int temp_w1_refresh(struct wrc_temp *t)
static int temp_w1_refresh(struct wrc_temp_group *t)
{
static int done;
if (!done) {
......@@ -37,6 +36,7 @@ static int temp_w1_refresh(struct wrc_temp *t)
if (time_before(timer_get_tics(), nextt))
return 0;
nextt += intervals[phase];
niterations++;
......@@ -52,11 +52,12 @@ static int temp_w1_refresh(struct wrc_temp *t)
return 1;
}
#if 0
/* not static at this point, because it's the only one */
DEFINE_TEMPERATURE(w1) = {
.read = temp_w1_refresh,
.t = temp_w1_data,
};
void temp_w1_init(void)
{
struct wrc_temp_group tbr;
#endif
\ No newline at end of file
tbr.used = 1;
tbr.read = temp_w1_refresh;
tbr.t = temp_w1_data;
wrc_temp_register(&tbr);
}
......@@ -13,14 +13,15 @@
#include <shell.h>
struct wrc_temp_group temp_sensors[WRC_MAX_TEMPERATURES];
/*
* Library functions
*/
uint32_t wrc_temp_get(char *name)
{
#if 0
struct wrc_temp *ta;
struct wrc_onetemp *wt;
struct wrc_temp_group *ta;
struct wrc_temp_sensor *wt;
for (ta = __temp_begin; ta < __temp_end; ta++)
for (wt = ta->t; wt->name; wt++) {
......@@ -31,37 +32,38 @@ uint32_t wrc_temp_get(char *name)
return TEMP_INVALID;
}
struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *pt)
struct wrc_temp_sensor *wrc_temp_getnext(struct wrc_temp_sensor *pt)
{
#if 0
struct wrc_temp *ta;
struct wrc_onetemp *wt;
struct wrc_temp_sensor *wt;
struct wrc_temp_group *tmp;
int i;
if (!pt) { /* first one */
if (__temp_begin != __temp_end)
return __temp_begin->t;
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
return temp_sensors[i].t;
}
}
if (pt[1].name)
return pt + 1;
/* get next array, if any */
for (ta = __temp_begin; ta < __temp_end; ta++) {
for (wt = ta->t; wt->name; wt++) {
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
tmp = &temp_sensors[i];
for (wt = tmp->t; wt->name; wt++) {
if (wt == pt) {
ta++;
if (ta >= __temp_end)
tmp++;
if (!tmp->t->name)
return NULL;
return ta->t;
return tmp->t;
}
}
}
#endif
return NULL;
}
extern int wrc_temp_format(char *buffer, int len)
{
struct wrc_onetemp *p;
struct wrc_temp_sensor *p;
int l = 0, i = 0;
int32_t t;
......@@ -86,30 +88,43 @@ extern int wrc_temp_format(char *buffer, int len)
return l;
}
/*
* The task
*/
void wrc_temp_init(void)
int wrc_temp_register(struct wrc_temp_group *new_temp_sensor)
{
#if 0
struct wrc_temp *ta;
struct wrc_temp_group *tmp;
int i;
/* Call all actors, so they can init themselves (using ->data) */
for (ta = __temp_begin; ta < __temp_end; ta++)
ta->read(ta);
#endif
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
tmp = &temp_sensors[i];
if (tmp->used) {
/* slot used in the list */
continue;
}
pp_printf("register temp sensor at %d\n", i);
*tmp = *new_temp_sensor;
return 1;
}
return 0;
}
/*
* The task
*/
int wrc_temp_refresh(void)
{
#if 0
struct wrc_temp *ta;
struct wrc_temp_group *tmp;
int i;
int ret = 0;
for (ta = __temp_begin; ta < __temp_end; ta++)
ret += ta->read(ta);
for (i = 0; i < WRC_MAX_TEMPERATURES; i++) {
tmp = &temp_sensors[i];
if (tmp->used) {
ret += tmp->read(tmp);
}
}
return (ret > 0);
#endif
}
/*
......@@ -130,4 +145,3 @@ DEFINE_WRC_COMMAND(temp) = {
.name = "temp",
.exec = cmd_temp,
};
......@@ -3,8 +3,10 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef PERSISTENT_MAC_H
#define PERSISTENT_MAC_H
#ifndef __ONEWIRE_H
#define __ONEWIRE_H
#define ONEWIRE_PORT 0
#define MAX_DEV1WIRE 8
......@@ -16,4 +18,4 @@ int16_t own_readtemp(uint8_t portnum, int16_t * temp, int16_t * t_frac);
int get_persistent_mac(uint8_t portnum, uint8_t * mac);
int set_persistent_mac(uint8_t portnum, uint8_t * mac);
#endif
#endif /* __ONEWIRE_H */
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __FAKETEMP_H
#define __FAKETEMP_H
#ifdef CONFIG_TEMP_FAKE
#define HAS_TEMP_FAKE 1
#else
#define HAS_TEMP_FAKE 0
#endif
void temp_faketemp_init(void);
#endif /* __FAKETEMP_H */
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __W1TEMP_H
#define __W1TEMP_H
#ifdef CONFIG_W1_TEMP
#define HAS_W1_TEMP 1
#else
#define HAS_W1_TEMP 0
#endif
void temp_w1_init(void);
#endif /* __W1TEMP_H */
......@@ -7,7 +7,20 @@
#include <stdint.h>
#ifdef CONFIG_W1
#define HAS_W1 1
#else
#define HAS_W1 0
#endif
#ifdef CONFIG_W1_EEPROM
#define HAS_W1_EEPROM 1
#else
#define HAS_W1_EEPROM 0
#endif
#define W1_MAX_DEVICES 8 /* we have no alloc */
#define ONEWIRE_PORT 0
struct w1_dev {
struct w1_bus *bus;
......
......@@ -11,27 +11,32 @@
#include <stdint.h>
#ifdef CONFIG_TEMP_SENSORS
#define HAS_TEMP_SENSORS 1
#else
#define HAS_TEMP_SENSORS 0
#endif
#define WRC_MAX_TEMPERATURES 4
struct wrc_onetemp {
struct wrc_temp_sensor {
char *name;
int32_t t; /* fixed point, 16.16 (signed!) */
};
#define TEMP_INVALID (0x8000 << 16)
struct wrc_temp {
struct wrc_temp_group {
int used;
int (*read)(struct wrc_temp *);
void *data;
struct wrc_onetemp *t; /* zero-terminated */
int (*read)(struct wrc_temp_group *);
struct wrc_temp_sensor *t; /* zero-terminated */
};
/* lib functions */
extern uint32_t wrc_temp_get(char *name);
struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *);
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);
#endif /* __TEMPERATURE_H__ */
......@@ -14,8 +14,12 @@
#include <errno.h>
#include <wrc.h>
#include "temperature.h"
#include "dev/console.h"
#include "dev/syscon.h"
#include "dev/temp-fake.h"
#include "dev/temp-w1.h"
#include "dev/w1.h"
#include "shell.h"
#include "storage.h"
......@@ -399,6 +403,8 @@ void shell_register_commands(void)
if (HAS_CMD_CONFIG)
REGISTER_WRC_COMMAND(config);
REGISTER_WRC_COMMAND(diag);
if (HAS_TEMP_FAKE)
REGISTER_WRC_COMMAND(faketemp);
REGISTER_WRC_COMMAND(gui);
REGISTER_WRC_COMMAND(help);
REGISTER_WRC_COMMAND(init);
......@@ -421,9 +427,17 @@ void shell_register_commands(void)
REGISTER_WRC_COMMAND(sdb);
REGISTER_WRC_COMMAND(sfp);
REGISTER_WRC_COMMAND(stat);
if (HAS_TEMP_SENSORS)
REGISTER_WRC_COMMAND(temp);
REGISTER_WRC_COMMAND(time);
REGISTER_WRC_COMMAND(ver);
REGISTER_WRC_COMMAND(verbose);
if (HAS_VLANS)
REGISTER_WRC_COMMAND(vlan);
if (HAS_W1_TEMP)
REGISTER_WRC_COMMAND(w1);
if (HAS_W1_EEPROM) {
REGISTER_WRC_COMMAND(w1r);
REGISTER_WRC_COMMAND(w1w);
}
}
......@@ -40,6 +40,9 @@
#include <system_checks.h>
#include <ppsi/ppsi.h>
#include "wrc_global.h"
#include "dev/w1.h"
#include "dev/temp-fake.h"
#include "dev/temp-w1.h"
#include "board.h"
......@@ -120,6 +123,20 @@ static void wrc_initialize(void)
minic_init();
shw_pps_gen_init();
if (HAS_W1) {
/* initialize w1 bus */
wrpc_w1_init();
wrpc_w1_bus.detail = ONEWIRE_PORT;
w1_scan_bus(&wrpc_w1_bus);
/* initialize w1 temp sensor */
if (HAS_TEMP_SENSORS && HAS_W1_TEMP)
temp_w1_init();
}
if (HAS_TEMP_SENSORS && HAS_TEMP_FAKE)
temp_faketemp_init();
wrc_board_init();
storage_load_calibration();
......@@ -231,7 +248,8 @@ static void create_tasks(void)
wrc_task_create( "shell+gui", shell_boot_script, ui_update );
wrc_task_create( "spll-bh", NULL, spll_update );
//wrc_task_create( "temperature", wrc_temp_init, wrc_temp_refresh );
if (HAS_TEMP_SENSORS)
wrc_task_create("temperature", NULL, wrc_temp_refresh);
t = wrc_task_create( "net-bh", NULL, net_bh_poll );
wrc_task_set_enable( t, is_link_up );
......
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