Commit a661eeed authored by Alessandro Rubini's avatar Alessandro Rubini

temperature: make the framework modular

This costs anoter 220 bytes in the binary, becuase we now loop among
all temperature providers in order to return data to the caller.

The providers are clustered using an ELF section.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent e2e7d59a
......@@ -10,4 +10,9 @@ SECTIONS
KEEP(*(.cmd))
__cmd_end = .;
}
.temp : {
__temp_begin = .;
KEEP(*(.temp))
__temp_end = .;
}
}
......@@ -53,7 +53,7 @@ static int temp_w1_refresh(struct wrc_temp *t)
}
/* not static at this point, because it's the only one */
struct wrc_temp temp_w1 = {
DEFINE_TEMPERATURE(w1) = {
.read = temp_w1_refresh,
.t = temp_w1_data,
};
......@@ -12,16 +12,18 @@
#include <temperature.h>
#include <shell.h>
extern struct wrc_temp temp_w1; /* The only one by now */
extern struct wrc_temp __temp_begin[], __temp_end[];
/*
* Library functions
*/
uint32_t wrc_temp_get(char *name)
{
struct wrc_onetemp *wt = temp_w1.t;
struct wrc_temp *ta;
struct wrc_onetemp *wt;
for (; wt->name; wt++) {
for (ta = __temp_begin; ta < __temp_end; ta++)
for (wt = ta->t; wt->name; wt++) {
if (!strcmp(wt->name, name))
return wt->t;
}
......@@ -30,11 +32,26 @@ uint32_t wrc_temp_get(char *name)
struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *pt)
{
if (!pt) /* first one */
return temp_w1.t;
struct wrc_temp *ta;
struct wrc_onetemp *wt;
if (!pt) { /* first one */
if (__temp_begin != __temp_end)
return __temp_begin->t;
}
if (pt[1].name)
return pt + 1;
/* get next array, if any -- none by now */
/* get next array, if any */
for (ta = __temp_begin; ta < __temp_end; ta++) {
for (wt = ta->t; wt->name; wt++) {
if (wt == pt) {
ta++;
if (ta >= __temp_end)
return NULL;
return ta->t;
}
}
}
return NULL;
}
......@@ -70,13 +87,21 @@ extern int wrc_temp_format(char *buffer, int len)
*/
void wrc_temp_init(void)
{
struct wrc_temp *ta;
/* Call all actors, so they can init themselves (using ->data) */
temp_w1.read(&temp_w1);
for (ta = __temp_begin; ta < __temp_end; ta++)
ta->read(ta);
}
int wrc_temp_refresh(void)
{
return temp_w1.read(&temp_w1);
struct wrc_temp *ta;
int ret = 0;
for (ta = __temp_begin; ta < __temp_end; ta++)
ret += ta->read(ta);
return (ret > 0);
}
/*
......
......@@ -21,6 +21,11 @@ struct wrc_temp {
struct wrc_onetemp *t; /* zero-terminated */
};
#define DEFINE_TEMPERATURE(_name) \
static struct wrc_temp __wrc_temp_ ## _name \
__attribute__((section(".temp"), __used__))
/* the task */
extern void wrc_temp_init(void);
extern int wrc_temp_refresh(void);
......
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