uip_timer.c 5.5 KB

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