xref: /nrf52832-nimble/rt-thread/components/net/uip/uip/uip_timer.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /**
2  * \addtogroup timer
3  * @{
4  */
5 
6 /**
7  * \file
8  * Timer library implementation.
9  * \author
10  * Adam Dunkels <[email protected]>
11  */
12 
13 /*
14  * Copyright (c) 2004, Swedish Institute of Computer Science.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  * 3. Neither the name of the Institute nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  * This file is part of the uIP TCP/IP stack
42  *
43  * Author: Adam Dunkels <[email protected]>
44  *
45  * $Id: timer.c,v 1.2 2006/06/12 08:00:30 adam Exp $
46  */
47 
48 #include "uip_clock.h"
49 #include "uip_timer.h"
50 //#include "rtconfig.h"
51 
52 /*---------------------------------------------------------------------------*/
53 /**
54  * Set a timer.
55  *
56  * This function is used to set a timer for a time sometime in the
57  * future. The function timer_expired() will evaluate to true after
58  * the timer has expired.
59  *
60  * \param t A pointer to the timer
61  * \param interval The interval before the timer expires.
62  *
63  */
64 void
timer_set(struct timer * t,clock_time_t interval)65 timer_set(struct timer *t, clock_time_t interval)
66 {
67   t->interval = interval;
68   t->start = clock_time();
69 }
70 /*---------------------------------------------------------------------------*/
71 /**
72  * Reset the timer with the same interval.
73  *
74  * This function resets the timer with the same interval that was
75  * given to the timer_set() function. The start point of the interval
76  * is the exact time that the timer last expired. Therefore, this
77  * function will cause the timer to be stable over time, unlike the
78  * timer_rester() function.
79  *
80  * \param t A pointer to the timer.
81  *
82  * \sa timer_restart()
83  */
84 void
timer_reset(struct timer * t)85 timer_reset(struct timer *t)
86 {
87   t->start += t->interval;
88 }
89 /*---------------------------------------------------------------------------*/
90 /**
91  * Restart the timer from the current point in time
92  *
93  * This function restarts a timer with the same interval that was
94  * given to the timer_set() function. The timer will start at the
95  * current time.
96  *
97  * \note A periodic timer will drift if this function is used to reset
98  * it. For preioric timers, use the timer_reset() function instead.
99  *
100  * \param t A pointer to the timer.
101  *
102  * \sa timer_reset()
103  */
104 void
timer_restart(struct timer * t)105 timer_restart(struct timer *t)
106 {
107   t->start = clock_time();
108 }
109 /*---------------------------------------------------------------------------*/
110 /**
111  * Check if a timer has expired.
112  *
113  * This function tests if a timer has expired and returns true or
114  * false depending on its status.
115  *
116  * \param t A pointer to the timer
117  *
118  * \return Non-zero if the timer has expired, zero otherwise.
119  *
120  */
121 #include "rtdef.h"
122 #include "uip-conf.h"
123 #include "uip.h"
124 
125 /* eth rx/tx thread */
126 static struct rt_mailbox uip_mbox;
127 static struct rt_thread aa;
128 
129 static char uip_timeout_mb_pool[4 * 4];
130 extern u16_t uip_len, uip_slen;
131 
uip_timeout_entry2(void * parameter)132 void uip_timeout_entry2(void* parameter)
133 {
134 
135 
136 }
uip_timeout_entry(void * parameter)137 void uip_timeout_entry(void* parameter)//����TIMEOUT���������������
138 {
139    // struct timer periodic_timer, arp_timer;
140     static uint8_t cnt;
141     int i;
142 	/* post message to ethernet thread */
143 
144     //if ((rt_sem_take(msg,RT_WAITING_NO)) != -RT_ETIMEOUT)
145     //if (timer_expired(&periodic_timer)) //5s enter once
146     {
147        //timer_reset(&periodic_timer);
148        for (i = 0; i < UIP_CONNS; i++)
149        {
150 	  uip_periodic(i);
151 	/* If the above function invocation resulted in data that
152 	   should be sent out on the network, the global variable
153 	   uip_len is set to a value > 0. */
154 	  if (uip_len > 0)
155           {
156 	      uip_arp_out();
157 	      TransmitPacket();
158 	  }
159        }
160 #if UIP_UDP
161        for (i = 0; i < UIP_UDP_CONNS; i++) //
162        {
163 	   uip_udp_periodic(i);
164 	/* If the above function invocation resulted in data that
165 	   should be sent out on the network, the global variable
166 	   uip_len is set to a value > 0. */
167 	   if (uip_len > 0)
168            {
169 	      uip_arp_out();
170 	      TransmitPacket();
171 	    }
172         }
173 #endif /* UIP_UDP */
174 
175        /* Call the ARP timer function every 10 seconds. */
176        //if (timer_expired(&arp_timer))
177        if (++cnt >= 2) //t
178        {
179 	  //timer_reset(&arp_timer);
180 	  uip_arp_timer();
181           cnt = 0;
182        }
183     }
184 
185 }
186 int
timer_expired(struct timer * t)187 timer_expired(struct timer *t)
188 {//DZ������bug
189     if ((clock_time() - t->start) >= (clock_time_t)t->interval)
190     {
191         //rt_mb_send(mbox,&
192     }
193 
194 }
195 /*---------------------------------------------------------------------------*/
196 
197 /** @} */
198