Commit b86b45c7 authored by Alessandro Rubini's avatar Alessandro Rubini

net: link_status is now a global variable

All "tasks" must have the same prototype, so we'd better get
void in all of them at the time being (so we only change the nerwork
function).

Meanwhile, use value "0" for "link down", so it can work as a simple
enable flag for the IP polling code.

(note: we query the link status in wrc_ptp_update() too, and we should
rather refer to the global variable)
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c7401a84
......@@ -18,10 +18,11 @@
#define PTPD_SOCK_UDP 0 /* wrong name, it should be "WRPC" */
#define PTPD_SOCK_RAW_ETHERNET 1 /* but used in ppsi, which I won't change */
extern int link_status;
#define LINK_DOWN 0
#define LINK_WENT_UP 1
#define LINK_WENT_DOWN 2
#define LINK_UP 3
#define LINK_DOWN 4
// GCC-specific
#ifndef PACKED
......
......@@ -51,7 +51,7 @@ static struct wrpc_socket *rdate_socket;
void __attribute__((weak)) syslog_init(void)
{ }
int __attribute__((weak)) syslog_poll(int l_status)
int __attribute__((weak)) syslog_poll(void)
{ return 0; }
unsigned int ipv4_checksum(unsigned short *buf, int shorts)
......@@ -164,11 +164,11 @@ static int rdate_poll(void)
return 1;
}
int ipv4_poll(int l_status)
int ipv4_poll(void)
{
int ret = 0;
if (l_status == LINK_WENT_UP && ip_status == IP_OK_BOOTP)
if (link_status == LINK_WENT_UP && ip_status == IP_OK_BOOTP)
ip_status = IP_TRAINING;
ret = bootp_poll();
......@@ -176,7 +176,7 @@ int ipv4_poll(int l_status)
ret += rdate_poll();
ret += syslog_poll(l_status);
ret += syslog_poll();
return ret != 0;
}
......
......@@ -34,7 +34,7 @@
#define UDP_END (UDP_CHECKSUM+2)
void ipv4_init(void);
int ipv4_poll(int l_status);
int ipv4_poll(void);
/* Internal to IP stack: */
unsigned int ipv4_checksum(unsigned short *buf, int shorts);
......@@ -66,6 +66,6 @@ struct wr_udp_addr {
void fill_udp(uint8_t * buf, int len, struct wr_udp_addr *uaddr);
void syslog_init(void);
int syslog_poll(int l_status);
int syslog_poll(void);
#endif
......@@ -55,7 +55,7 @@ DEFINE_WRC_COMMAND(mac) = {
};
int syslog_poll(int l_status)
int syslog_poll(void)
{
struct wr_sockaddr addr;
char buf[256];
......@@ -86,9 +86,9 @@ int syslog_poll(int l_status)
goto send;
}
if (l_status == LINK_WENT_DOWN)
if (link_status == LINK_WENT_DOWN)
down_tics = timer_get_tics();
if (l_status == LINK_UP && down_tics) {
if (link_status == LINK_UP && down_tics) {
down_tics = timer_get_tics() - down_tics;
shw_pps_gen_get_time(&secs, NULL);
getIP(ip);
......
......@@ -145,6 +145,8 @@ void init_hw_after_reset(void)
timer_init(1);
}
int link_status;
int main(void)
{
extern uint32_t uptime_sec;
......@@ -166,8 +168,6 @@ int main(void)
lastj = timer_get_tics();
for (;;) {
int l_status = wrc_check_link();
/* count uptime, in seconds, for remote polling */
j = timer_get_tics();
fraction += j -lastj;
......@@ -177,7 +177,9 @@ int main(void)
uptime_sec++;
}
switch (l_status) {
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);
......@@ -188,7 +190,7 @@ int main(void)
case LINK_UP:
update_rx_queues();
if (HAS_IP) {
ipv4_poll(l_status);
ipv4_poll();
arp_poll();
}
break;
......
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