Commit 39edf0a3 authored by Alessandro Rubini's avatar Alessandro Rubini

wrc_main: define the idea of wrc_task

This commit turns individual calls to polling functions into an array
of tasks.  On this basis we can add profiling and periodic execution
(instead of continuous polling).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f695c5d0
......@@ -37,6 +37,6 @@ void env_init(void);
int shell_exec(const char *buf);
int shell_interactive(void);
int shell_boot_script(void);
void shell_boot_script(void);
#endif
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __WRC_TASK_H__
#define __WRC_TASK_H__
/*
* A task is a data structure, but currently suboptimal.
* FIXME: init must return int, and both should get a pointer to data
* FIXME: provide a jiffy-based period.
*/
struct wrc_task {
char *name;
int *enable; /* A global enable variable */
void (*init)(void);
int (*job)(void);
/* And we keep statistics about cpu usage */
unsigned long nrun;
};
#endif /* __WRC_TASK_H__ */
......@@ -17,6 +17,7 @@
#include <pp-printf.h>
#include <util.h>
#include <trace.h>
#include <wrc-task.h>
#define vprintf pp_vprintf
#define sprintf pp_sprintf
......
......@@ -248,12 +248,12 @@ const char *fromdec(const char *dec, int *v)
return dec;
}
int shell_boot_script(void)
void shell_boot_script(void)
{
uint8_t next = 0;
if (!has_eeprom)
return -1;
return;
while (1) {
cmd_len = storage_init_readcmd((uint8_t *)cmd_buf,
......@@ -270,5 +270,5 @@ int shell_boot_script(void)
next = 1;
}
return 0;
return;
}
......@@ -89,11 +89,6 @@ static void wrc_initialize(void)
//try reading t24 phase transition from EEPROM
calib_t24p(WRC_MODE_MASTER, &cal_phase_transition);
spll_very_init();
if (HAS_IP) {
ipv4_init();
arp_init();
}
}
static int wrc_check_link(void)
......@@ -147,10 +142,57 @@ void init_hw_after_reset(void)
int link_status;
struct wrc_task wrc_tasks[] = {
{
.name = "idle",
}, {
.name = "net-bh",
.enable = &link_status,
.job = update_rx_queues,
}, {
.name = "ptp",
.job = wrc_ptp_update,
}, {
.name = "shell+gui",
.init = shell_boot_script,
.job = ui_update,
}, {
.name = "stats",
.job = wrc_log_stats,
}, {
.name = "spll-bh",
.job = spll_update,
#ifdef CONFIG_IP
}, {
.name = "ipv4",
.enable = &link_status,
.init = ipv4_init,
.job = ipv4_poll,
}, {
.name = "arp",
.enable = &link_status,
.init = arp_init,
.job = arp_poll,
#endif
}
};
int wrc_n_tasks = ARRAY_SIZE(wrc_tasks);
static void wrc_run_task(struct wrc_task *t)
{
if (t->enable && !*t->enable)
return;
if (t->job)
t->nrun += t->job();
else t->nrun++;
}
int main(void)
{
extern uint32_t uptime_sec;
uint32_t j, lastj, fraction = 0;
int i;
check_reset();
wrc_ui_mode = UI_SHELL_MODE;
......@@ -163,10 +205,13 @@ int main(void)
wrc_ptp_set_mode(WRC_MODE_SLAVE);
wrc_ptp_start();
//try to read and execute init script from EEPROM
shell_boot_script();
lastj = timer_get_tics();
/* initialization of individual tasks */
for (i = 0; i < wrc_n_tasks; i++)
if (wrc_tasks[i].init)
wrc_tasks[i].init();
lastj = timer_get_tics();
for (;;) {
/* count uptime, in seconds, for remote polling */
j = timer_get_tics();
......@@ -177,29 +222,18 @@ int main(void)
uptime_sec++;
}
/* update link_status and do special-case processing */
link_status = wrc_check_link();
switch (link_status) {
case LINK_WENT_DOWN:
if (wrc_ptp_get_mode() == WRC_MODE_SLAVE) {
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
shw_pps_gen_enable_output(0);
}
/* fall through */
case LINK_WENT_UP:
case LINK_UP:
update_rx_queues();
if (HAS_IP) {
ipv4_poll();
arp_poll();
}
break;
if (link_status == LINK_WENT_DOWN) {
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
shw_pps_gen_enable_output(0);
}
ui_update();
wrc_log_stats();
wrc_ptp_update();
spll_update();
/* run your tasks */
for (i = 0; i < wrc_n_tasks; i++)
wrc_run_task(wrc_tasks + i);
/* better safe than sorry */
check_stack();
}
}
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