Commit d4a1cf96 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Grzegorz Daniluk

wrc: get rid of DEFINE_TASK linker section magic, just do it the crappy non-LINUX-GURU way...

parent 31d75fe2
......@@ -39,7 +39,7 @@ void spll_log_dac(int y)
}
static void daclog_init(void)
void daclog_init(void)
{
daclog_socket = ptpd_netif_create_socket(&__static_daclog_socket, NULL,
PTPD_SOCK_UDP, 1050);
......@@ -48,7 +48,7 @@ static void daclog_init(void)
static int configured;
static int daclog_poll(void)
int daclog_poll(void)
{
struct wr_sockaddr addr;
int len = sizeof(struct daclog_buf);
......@@ -75,12 +75,6 @@ static int daclog_poll(void)
return 1;
}
DEFINE_WRC_TASK(daclog) = {
.name = "daclog",
.init = daclog_init,
.job = daclog_poll,
};
static int cmd_daclog(const char *args[])
{
char b1[32], b2[32];
......
......@@ -52,8 +52,11 @@ 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,
};
#endif
\ No newline at end of file
......@@ -12,13 +12,13 @@
#include <temperature.h>
#include <shell.h>
extern struct wrc_temp __temp_begin[], __temp_end[];
/*
* Library functions
*/
uint32_t wrc_temp_get(char *name)
{
#if 0
struct wrc_temp *ta;
struct wrc_onetemp *wt;
......@@ -27,11 +27,13 @@ uint32_t wrc_temp_get(char *name)
if (!strcmp(wt->name, name))
return wt->t;
}
#endif
return TEMP_INVALID;
}
struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *pt)
{
#if 0
struct wrc_temp *ta;
struct wrc_onetemp *wt;
......@@ -52,6 +54,8 @@ struct wrc_onetemp *wrc_temp_getnext(struct wrc_onetemp *pt)
}
}
}
#endif
return NULL;
}
......@@ -85,31 +89,29 @@ extern int wrc_temp_format(char *buffer, int len)
/*
* The task
*/
static void wrc_temp_init(void)
void wrc_temp_init(void)
{
#if 0
struct wrc_temp *ta;
/* Call all actors, so they can init themselves (using ->data) */
for (ta = __temp_begin; ta < __temp_end; ta++)
ta->read(ta);
#endif
}
static int wrc_temp_refresh(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
}
DEFINE_WRC_TASK(temp) = {
.name = "temperature",
.init = wrc_temp_init,
.job = wrc_temp_refresh,
};
/*
* The shell command
*/
......
......@@ -125,12 +125,3 @@ void ep_init(uint8_t mac_addr[])
void pfilter_init_default(void)
{}
static int task_relax(void)
{
usleep(1000);
return 1; /* we did something */
}
DEFINE_WRC_TASK(relax) = {
.name = "relax",
.job = task_relax,
};
......@@ -9,25 +9,27 @@
#ifndef __TEMPERATURE_H__
#define __TEMPERATURE_H__
#define WRC_MAX_TEMPERATURES 4
struct wrc_onetemp {
char *name;
int32_t t; /* fixed point, 16.16 (signed!) */
};
#define TEMP_INVALID (0x8000 << 16)
struct wrc_temp {
int used;
int (*read)(struct wrc_temp *);
void *data;
struct wrc_onetemp *t; /* zero-terminated */
};
#define DEFINE_TEMPERATURE(_name) \
static struct wrc_temp __wrc_temp_ ## _name \
__attribute__((section(".temp"), __used__))
/* 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);
#endif /* __TEMPERATURE_H__ */
......@@ -6,6 +6,8 @@
#ifndef __WRC_TASK_H__
#define __WRC_TASK_H__
#define WRC_MAX_TASKS 16
/*
* A task is a data structure, but currently suboptimal.
* FIXME: init must return int, and both should get a pointer to data
......@@ -15,7 +17,7 @@
struct wrc_task {
int used;
char name[16];
int *enable; /* A global enable variable */
int (*enabled)(void);
void (*init)(void);
int (*job)(void);
/* And we keep statistics about cpu usage */
......@@ -25,24 +27,12 @@ struct wrc_task {
unsigned long max_run_ticks; /* in ticks */
};
#define WRC_MAX_TASKS 8
extern struct wrc_task tasks[WRC_MAX_TASKS];
/* An helper for periodic tasks, relying on a static varible */
static inline int __task_not_yet(uint32_t *lastt, unsigned period,
uint32_t now)
{
if (!*lastt) {
*lastt = now;
return 0;
}
if (time_before(now, *lastt + period))
return 1; /* not yet */
*lastt += period;
return 0;
}
void wrc_tasks_init(void);
struct wrc_task* wrc_task_create( const char *name, void (*init)(void), int (*job)(void) );
void wrc_task_set_enable( struct wrc_task* task, int (*enabled)(void) );
struct wrc_task *wrc_task_get(int tid);
void wrc_start_all_tasks(void);
void wrc_poll_all_tasks(void);
void wrc_tasks_accounting_init(void);
#endif /* __WRC_TASK_H__ */
......@@ -32,7 +32,7 @@ static struct wrpc_socket *arp_socket;
#define ARP_TPA (ARP_THA+6)
#define ARP_END (ARP_TPA+4)
static void arp_init(void)
void arp_init(void)
{
struct wr_sockaddr saddr;
......@@ -86,7 +86,7 @@ static int process_arp(uint8_t * buf, int len)
return ARP_END;
}
static int arp_poll(void)
int arp_poll(void)
{
uint8_t buf[ARP_END + 100];
struct wr_sockaddr addr;
......@@ -104,9 +104,3 @@ static int arp_poll(void)
return 0;
}
DEFINE_WRC_TASK(arp) = {
.name = "arp",
.enable = &link_status,
.init = arp_init,
.job = arp_poll,
};
......@@ -66,7 +66,7 @@ unsigned int ipv4_checksum(unsigned short *buf, int shorts)
return (~sum & 0xffff);
}
static void ipv4_init(void)
void ipv4_init(void)
{
struct wr_sockaddr saddr;
......@@ -169,7 +169,7 @@ static int rdate_poll(void)
return 1;
}
static int ipv4_poll(void)
int ipv4_poll(void)
{
int ret = 0;
......@@ -191,13 +191,6 @@ void getIP(unsigned char *IP)
memcpy(IP, myIP, 4);
}
DEFINE_WRC_TASK(ipv4) = {
.name = "ipv4",
.enable = &link_status,
.init = ipv4_init,
.job = ipv4_poll,
};
void setIP(unsigned char *IP)
{
volatile unsigned int *eb_ip =
......
......@@ -67,4 +67,15 @@ void syslog_init(void);
int syslog_poll(void);
void syslog_report(const char *buf);
void arp_init(void);
int arp_poll(void);
void ipv4_init(void);
int ipv4_poll(void);
void snmp_init(void);
int snmp_poll(void);
int net_bh_poll(void);
#endif
......@@ -40,7 +40,7 @@ static struct wr_sockaddr latency_addr = {
.ethertype = 0, /* htons(CONFIG_LATENCY_ETHTYPE) -- not constant! */
};
static void latency_init(void)
void latency_init(void)
{
latency_addr.ethertype = htons(CONFIG_LATENCY_ETHTYPE);
latency_socket = ptpd_netif_create_socket(&__static_latency_socket,
......@@ -263,7 +263,7 @@ static int latency_poll_tx(void)
static uint32_t lastt;
static uint32_t latency_period_ms;
static int latency_poll(void)
int latency_poll(void)
{
if (!latency_period_ms)
return latency_poll_rx();
......@@ -274,11 +274,6 @@ static int latency_poll(void)
return latency_poll_tx();
}
DEFINE_WRC_TASK(uptime) = {
.name = "latency-probe",
.init = latency_init,
.job = latency_poll,
};
static int cmd_ltest(const char *args[])
......
obj-y += lib/util.o
obj-y += lib/util.o lib/wrc-tasks.o
obj-$(CONFIG_LM32) += \
lib/atoi.o \
......
......@@ -220,7 +220,7 @@ static void lldp_update(void)
lldp_add_tlv(END_LLDP);
}
static void lldp_init(void)
void lldp_init(void)
{
struct wr_sockaddr saddr;
......@@ -237,7 +237,7 @@ static void lldp_init(void)
lldp_update();
}
static int lldp_poll(void)
int lldp_poll(void)
{
static int ticks;
unsigned char new_ipWR;
......@@ -278,9 +278,3 @@ static int lldp_poll(void)
return 0;
}
}
DEFINE_WRC_TASK(lldp) = {
.name = "lldp",
.init = lldp_init,
.job = lldp_poll,
};
......@@ -11,7 +11,9 @@
#ifndef __LLDP_H
#define __LLDP_H
#include "minic.h"
#define LLDP_MCAST_MAC "\x01\x80\xC2\x00\x00\x0E" /* 802.1AB-2005,
Table 8-1 */
#define LLDP_ETH_TYP 0x88CC /* 802.1AB-2005, Table 8-2 */
......@@ -40,6 +42,7 @@
#define MNG_ADDR_SUBTYPE_IPv4 1 /* ianaAddressFamilyNumbers MIB */
#define MNG_ADDR_SUBTYPE_MAC 6 /* ianaAddressFamilyNumbers MIB */
#define MNG_IF_NUM_SUBTYPE_IFINDEX 2 /* 802.1AB-2005, 9.5.9.5 */
enum TLV_TYPE {
END_LLDP = 0, /* mandatory TLVs */
CHASSIS_ID,
......@@ -53,4 +56,7 @@ enum TLV_TYPE {
USER_DEF
};
void lldp_init(void);
int lldp_poll(void);
#endif /* __LLDP_H */
......@@ -306,7 +306,7 @@ int ptpd_netif_sendto(struct wrpc_socket * sock, struct wr_sockaddr *to, void *d
return rval;
}
static int update_rx_queues(void)
int net_bh_poll(void)
{
struct wrpc_socket *s = NULL, *raws = NULL, *udps = NULL;
struct sockq *q;
......@@ -397,10 +397,3 @@ static int update_rx_queues(void)
q->avail, q->n, q_required);
return 1;
}
/*
DEFINE_WRC_TASK(net_bh) = {
.name = "net-bh",
.enable = &link_status,
.job = update_rx_queues,
};
*/
\ No newline at end of file
......@@ -523,7 +523,7 @@ static struct snmp_oid_limb oid_limb_array[] = {
{ 0, }
};
static void snmp_init(void)
void snmp_init(void)
{
uint32_t aux_diag_id;
uint32_t aux_diag_ver;
......@@ -1813,7 +1813,7 @@ static int snmp_respond(uint8_t *buf)
/* receive snmp through the UDP mechanism */
static int snmp_poll(void)
int snmp_poll(void)
{
struct wr_sockaddr addr;
uint8_t buf[200];
......@@ -1842,10 +1842,3 @@ static int snmp_poll(void)
ptpd_netif_sendto(snmp_socket, &addr, buf, len, 0);
return 1;
}
DEFINE_WRC_TASK(snmp) = {
.name = "snmp",
.enable = &link_status,
.init = snmp_init,
.job = snmp_poll,
};
......@@ -65,7 +65,7 @@ static const char* wrc_ptp_state(void)
if (ip->state == ppi->state)
break;
}
if(!ip)
return ptp_unknown_str;
return ip->name;
......@@ -304,7 +304,7 @@ static void wrc_mon_std_servo(void)
/* internal "last", exported to shell command */
uint32_t wrc_stats_last;
static int wrc_log_stats(void)
int wrc_log_stats(void)
{
struct hal_port_state state;
int tx, rx;
......@@ -392,12 +392,6 @@ static int wrc_log_stats(void)
return 1;
}
/*
DEFINE_WRC_TASK(stats) = {
.name = "stats",
.job = wrc_log_stats,
};
*/
int wrc_wr_diags(void)
{
......@@ -504,11 +498,3 @@ int wrc_wr_diags(void)
return 1;
}
/*
#ifdef CONFIG_WR_DIAG
DEFINE_WRC_TASK(diags) = {
.name = "diags",
.job = wrc_wr_diags,
};
#endif
*/
......@@ -10,8 +10,8 @@
#include <string.h>
#include <shell.h>
extern struct wrc_task wrc_tasks[];
extern int wrc_n_tasks;
#include "wrc-task.h"
extern uint32_t print_task_time_threshold;
static int cmd_ps(const char *args[])
......@@ -23,10 +23,12 @@ static int cmd_ps(const char *args[])
if(!strcasecmp(args[0], "reset")) {
for(i = 0; i < WRC_MAX_TASKS; i++)
{
struct wrc_task* t = &tasks[i];
struct wrc_task* t = wrc_get_task(i);
if(!t)
return 0;
if(!t->used)
continue;
t->nrun = t->seconds = t->nanos = t->max_run_ticks = 0;
t->nrun = t->seconds = t->nanos = t->max_run_ticks = 0;
}
return 0;
} else if (!strcasecmp(args[0], "max")) {
......@@ -40,7 +42,9 @@ static int cmd_ps(const char *args[])
pp_printf(" iterations seconds.micros max_ms name\n");
for(i = 0; i < WRC_MAX_TASKS; i++)
{
struct wrc_task* t = &tasks[i];
struct wrc_task* t = wrc_get_task(i);
if(!t)
return 0;
if(!t->used)
continue;
pp_printf(" %9li %9li.%06li %9ld %s\n", t->nrun,
......
......@@ -30,13 +30,28 @@
#include "lib/ipv4.h"
#include "rxts_calibrator.h"
#include "flash.h"
#include "fram.h"
#include "wrc_ptp.h"
#include "system_checks.h"
#ifndef CONFIG_DEFAULT_PRINT_TASK_TIME_THRESHOLD
#define CONFIG_DEFAULT_PRINT_TASK_TIME_THRESHOLD 0
#ifdef CONFIG_DAC_LOG
#include "dev/dac_log.h"
#endif
#ifdef CONFIG_IP
#include "lib/arp.h"
#endif
#ifdef CONFIG_LATENCY_PROBE
#include "lib/latency.h"
#endif
#ifdef CONFIG_LLDP
#include "lib/lldp.h"
#endif
#ifdef CONFIG_SNMP
#include "lib/snmp.h"
#endif
int wrc_ui_mode = UI_SHELL_MODE;
......@@ -48,10 +63,6 @@ uint32_t cal_phase_transition = 2389;
int wrc_vlan_number = CONFIG_VLAN_NR;
static uint32_t prev_nanos_for_profile;
static uint32_t prev_ticks_for_profile;
uint32_t print_task_time_threshold = CONFIG_DEFAULT_PRINT_TASK_TIME_THRESHOLD;
static void wrc_initialize(void)
{
uint8_t mac_addr[6];
......@@ -65,7 +76,7 @@ static void wrc_initialize(void)
get_hw_name(wrc_hw_name);
wrc_board_init();
if (HAS_GENSDBFS)
storage_read_hdl_cfg();
......@@ -90,15 +101,18 @@ static void wrc_initialize(void)
wrc_ptp_set_mode(WRC_MODE_SLAVE);
wrc_ptp_start();
shw_pps_gen_get_time(NULL, &prev_nanos_for_profile);
/* get tics */
prev_ticks_for_profile = timer_get_tics();
wrc_tasks_accounting_init();
wrc_board_create_tasks();
}
int link_status;
static int is_link_up()
{
return link_status == LINK_UP;
}
static int wrc_check_link(void)
{
static int prev_state = 0;
......@@ -154,6 +168,7 @@ void init_hw_after_reset(void)
timer_init(1);
}
/* count uptime, in seconds, for remote polling */
static uint32_t uptime_lastj;
static void init_uptime(void)
......@@ -177,123 +192,55 @@ static int update_uptime(void)
return 0;
}
static void task_time_normalize(struct wrc_task *t)
{
if (t->nanos > 1000 * 1000 * 1000) {
t->nanos -= 1000 * 1000 * 1000;
t->seconds++;
}
}
extern void wrc_log_stats(void);
/* Account the time to either this task or task 0 */
static void account_task(struct wrc_task *t, int done_sth)
static void create_tasks()
{
uint32_t nanos;
signed int delta;
uint32_t ticks;
signed int delta_ticks;
if (!done_sth)
t = &tasks[0]; /* task 0 is special */
shw_pps_gen_get_time(NULL, &nanos);
/* get monotonic number of ticks */
ticks = timer_get_tics();
delta = nanos - prev_nanos_for_profile;
if (delta < 0)
delta += 1000 * 1000 * 1000;
t->nanos += delta;
task_time_normalize(t);
prev_nanos_for_profile = nanos;
delta_ticks = ticks - prev_ticks_for_profile;
if (delta_ticks < 0)
delta_ticks += TICS_PER_SECOND;
if (t->max_run_ticks < delta_ticks) {/* update max_run_ticks */
if (print_task_time_threshold) {
/* Print only if threshold is set */
pp_printf("New max run time for a task %s, old %ld, "
"new %d\n",
t->name, t->max_run_ticks, delta_ticks);
}
t->max_run_ticks = delta_ticks;
}
if (print_task_time_threshold
&& delta_ticks > print_task_time_threshold)
pp_printf("task %s, run for %d ms\n", t->name, delta_ticks);
struct wrc_task *t;
prev_ticks_for_profile = ticks;
}
wrc_tasks_init();
wrc_task_create( "idle", wrc_initialize, NULL );
//wrc_task_create( "check-link", NULL, wrc_check_link );
wrc_task_create( "uptime", init_uptime, update_uptime );
//wrc_task_create( "ptp", NULL, wrc_ptp_update);
//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 );
/* Run a task with profiling */
static void wrc_run_task(struct wrc_task *t)
{
int done_sth = 0;
if (!t->job) /* idle task, just count iterations */
t->nrun++;
else if (!t->enable || *t->enable) {
/* either enabled or without a check variable */
done_sth = t->job();
t->nrun += done_sth;
}
account_task(t, done_sth);
}
//t = wrc_task_create( "net-bh", NULL, net_bh_poll );
//wrc_task_set_enable( t, is_link_up );
struct wrc_task tasks[WRC_MAX_TASKS];
#ifdef CONFIG_DAC_LOG
wrc_task_create( "dac-logger", daclog_init, daclog_poll );
#endif
static struct wrc_task* task_create( const char *name, void (*init)(), int (*job)() )
{
struct wrc_task *t = NULL;
int i;
for(i = 0; i < WRC_MAX_TASKS; i++)
if(!tasks[i].used)
{
t = &tasks[i];
break;
}
if(!t)
return NULL;
#ifdef CONFIG_IP
t = wrc_task_create( "arp", arp_init, arp_poll );
wrc_task_set_enable( t, is_link_up );
t = wrc_task_create( "ipv4", ipv4_init, ipv4_poll );
wrc_task_set_enable( t, is_link_up );
#endif
t->used = 1;
t->init = init;
t->job = job;
strncpy(t->name, name, 16);
#ifdef CONFIG_LATENCY_PROBE
extern void latency_init(void);
extern void latency_poll(void);
wrc_task_create( "latency-probe", latency_init, latency_poll );
#endif
return t;
}
#ifdef CONFIG_LLDP
wrc_task_create( "lldp", lldp_init, lldp_poll );
#endif
static void wrc_init_all_tasks()
{
int i = 0;
memset(&tasks, 0, sizeof(struct wrc_task) * WRC_MAX_TASKS);
task_create( "idle", wrc_initialize, NULL );
//task_create( "check-link", NULL, wrc_check_link );
task_create( "uptime", init_uptime, update_uptime );
//task_create( "ptp", NULL, wrc_ptp_update);
//task_create( "shell+gui", shell_boot_script, ui_update );
//task_create( "spll-bh", NULL, spll_update );
for( i = 0; i < WRC_MAX_TASKS; i++ )
if( tasks[i].used && tasks[i].init )
{
tasks[i].init();
}
}
#ifdef CONFIG_SNMP
t = wrc_task_create( "snmp", snmp_init, snmp_poll );
wrc_task_set_enable( t, is_link_up );
#endif
static void wrc_run_all_tasks()
{
int i;
//wrc_task_create( "stats", NULL, wrc_log_stats );
for( i = 0; i < WRC_MAX_TASKS; i++ )
if( tasks[i].used )
{
wrc_run_task( &tasks[i] );
}
#ifdef CONFIG_WR_DIAG
//wrc_task_create( "diags", NULL, wrc_wr_diags );
#endif
}
int main(void) __attribute__ ((weak));
......@@ -302,12 +249,13 @@ int main(void)
struct wrc_task *t;
check_reset();
create_tasks();
/* initialization of individual tasks */
wrc_init_all_tasks();
wrc_start_all_tasks();
for (;;) {
wrc_run_all_tasks();
wrc_poll_all_tasks();
/* 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