From b7cb464247b09f71fac7b2fee6dec849bb4b4e0d Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Thu, 20 Feb 2014 22:54:33 +0100
Subject: [PATCH 1/2] minimal patch to fix #40245

the timeouts previously handled manually here have been adressed in the
sys_timeouts mechanism since 2009 (a566f9d8).
---
 ports/unix/proj/minimal/lwipopts.h |  5 ---
 ports/unix/proj/minimal/main.c     | 23 +---------
 ports/unix/proj/minimal/timer.c    | 88 --------------------------------------
 ports/unix/proj/minimal/timer.h    |  7 ---
 4 files changed, 2 insertions(+), 121 deletions(-)

diff --git a/ports/unix/proj/minimal/lwipopts.h b/ports/unix/proj/minimal/lwipopts.h
index 06fe17b..859346c 100644
--- a/ports/unix/proj/minimal/lwipopts.h
+++ b/ports/unix/proj/minimal/lwipopts.h
@@ -122,11 +122,6 @@
 #define MEMP_NUM_ARP_QUEUE              2
 
 /**
- * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts.
- */
-#define MEMP_NUM_SYS_TIMEOUT            3
-
-/**
  * MEMP_NUM_NETBUF: the number of struct netbufs.
  * (only needed if you use the sequential API, like api_lib.c)
  */
diff --git a/ports/unix/proj/minimal/main.c b/ports/unix/proj/minimal/main.c
index 87ce26f..9b08ce5 100644
--- a/ports/unix/proj/minimal/main.c
+++ b/ports/unix/proj/minimal/main.c
@@ -192,11 +192,6 @@ main(int argc, char **argv)
   echo_init();
 
   timer_init();
-  timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10);
-  timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10);
-#if IP_REASSEMBLY
-  timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10);
-#endif
   
   printf("Applications started.\n");
     
@@ -225,22 +220,8 @@ main(int argc, char **argv)
         /* ... end critical section */
           sigprocmask(SIG_SETMASK, &oldmask, NULL);
       }
-    
-      if(timer_testclr_evt(TIMER_EVT_TCPTMR))
-      {
-        tcp_tmr();
-      }
-#if IP_REASSEMBLY
-      if(timer_testclr_evt(TIMER_EVT_IPREASSTMR))
-      {
-        ip_reass_tmr();
-      }
-#endif
-      if(timer_testclr_evt(TIMER_EVT_ETHARPTMR))
-      {
-        etharp_tmr();
-      }
-      
+
+      sys_check_timeouts();
   }
   
   return 0;
diff --git a/ports/unix/proj/minimal/timer.c b/ports/unix/proj/minimal/timer.c
index cbd0823..6a2e65f 100644
--- a/ports/unix/proj/minimal/timer.c
+++ b/ports/unix/proj/minimal/timer.c
@@ -43,16 +43,6 @@
 
 static struct itimerval tmr;
 
-struct itmr
-{
-  volatile unsigned int interval;
-  volatile unsigned int cnt;
-  volatile unsigned char event;
-};
-
-static struct itmr timers[TIMER_NUM];
-
-
 void sigalarm_handler(int sig);
 
 /**
@@ -61,18 +51,6 @@ void sigalarm_handler(int sig);
 void
 timer_init(void)
 {
-  unsigned char i;
-  struct itmr *tp;
-
-  tp = &timers[TIMER_NUM-1];
-  for(i = TIMER_NUM; i > 0; i--)
-  {
-    tp->event = 0;
-    tp->interval = 0;
-    tp->cnt = 0;
-    tp--;
-  }
-
   signal(SIGALRM,sigalarm_handler);
 
   /* timer reload is in 10msec steps */
@@ -86,77 +64,11 @@ timer_init(void)
 }
 
 /**
- * Configures timer.
- *
- * @param tmr the timer number from timer.h
- * @param interval when > 0 enables this timer, 0 disables.
- */
-void
-timer_set_interval(unsigned char tmr, unsigned int interval)
-{
-  if (tmr < TIMER_NUM)
-  {
-    timers[tmr].interval = interval;
-  }
-}
-
-
-/**
- * Returns timer event and restarts timer.
- */
-unsigned char
-timer_testclr_evt(unsigned char tmr)
-{
-  if (tmr < TIMER_NUM)
-  {
-    unsigned char evt;
-    struct itmr *tp;
-
-    tp = &timers[tmr];
-    
-    evt = tp->event;
-    if (tp->event != 0)
-    {
-      tp->event = 0;
-      tp->cnt = tp->interval;
-    }
-    return evt;
-  }
-  else
-  {
-    return 0;
-  }
-}
-
-/**
  * interrupting (!) sigalarm handler
  */
 void
 sigalarm_handler(int sig)
 {
-  unsigned char i;
-  struct itmr *tp;
-
   snmp_inc_sysuptime();
-
-  tp = &timers[TIMER_NUM-1];
-  for(i = TIMER_NUM; i > 0; i--)
-  {
-    if (tp->interval != 0)
-    {
-      /* timer is running */
-      if (tp->cnt == 0)
-      {
-        /* timer expired */
-        tp->event |= 1;
-      }
-      else
-      {
-        /* timer ticking */
-        tp->cnt--;
-      }
-    }
-    tp--;
-  }
 }
 
diff --git a/ports/unix/proj/minimal/timer.h b/ports/unix/proj/minimal/timer.h
index f905e7a..5e83147 100644
--- a/ports/unix/proj/minimal/timer.h
+++ b/ports/unix/proj/minimal/timer.h
@@ -1,13 +1,6 @@
 #ifndef _TIMER_H_
 #define _TIMER_H_
 
-#define TIMER_EVT_ETHARPTMR 0
-#define TIMER_EVT_TCPTMR 1
-#define TIMER_EVT_IPREASSTMR 2
-#define TIMER_NUM 3
-
 void timer_init(void);
-void timer_set_interval(unsigned char tmr, unsigned int interval);
-unsigned char timer_testclr_evt(unsigned char tmr);
 
 #endif
-- 
1.9.0

