• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file
3  * Timer implementations
4  * @cond liteos
5  */
6 
7 /*
8  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  *    this list of conditions and the following disclaimer in the documentation
18  *    and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Adam Dunkels <adam@sics.se>
36  *         Simon Goldschmidt
37  *
38  */
39 #ifndef LWIP_HDR_TIMEOUTS_H
40 #define LWIP_HDR_TIMEOUTS_H
41 
42 #include "lwip/opt.h"
43 #include "lwip/err.h"
44 #if !NO_SYS
45 #include "lwip/sys.h"
46 #endif
47 #if LWIP_LOWPOWER
48 #include "lwip/lowpower.h"
49 #endif
50 
51 #if defined (__cplusplus) && __cplusplus
52 extern "C" {
53 #endif
54 
55 #if !LWIP_LOWPOWER
56 
57 #define LWIP_MAX_VALUE 0xFFFFFFFF
58 
59 #ifndef LWIP_DEBUG_TIMERNAMES
60 #ifdef LWIP_DEBUG
61 #define LWIP_DEBUG_TIMERNAMES SYS_DEBUG
62 #else /* LWIP_DEBUG */
63 #define LWIP_DEBUG_TIMERNAMES 0
64 #endif /* LWIP_DEBUG */
65 #endif
66 
67 /* Function prototype for a stack-internal timer function that has to be
68  * called at a defined interval */
69 typedef void (* lwip_cyclic_timer_handler)(void);
70 
71 /* This struct contains information about a stack-internal timer function
72  that has to be called at a defined interval */
73 struct lwip_cyclic_timer {
74   u32_t interval_ms;
75   lwip_cyclic_timer_handler handler;
76 #if LWIP_DEBUG_TIMERNAMES
77   const char *handler_name;
78 #endif /* LWIP_DEBUG_TIMERNAMES */
79 };
80 
81 /* This array contains all stack-internal cyclic timers. To get the number of
82  * timers, use LWIP_ARRAYSIZE() */
83 extern const struct lwip_cyclic_timer lwip_cyclic_timers[];
84 
85 #if LWIP_TIMERS
86 
87 /** Function prototype for a timeout callback function. Register such a function
88  * using sys_timeout().
89  *
90  * @param arg Additional argument to pass to the function - set up by sys_timeout()
91  * @endcond
92  */
93 typedef void (* sys_timeout_handler)(void *arg);
94 
95 struct sys_timeo {
96   struct sys_timeo *next;
97   u32_t time;
98   sys_timeout_handler h;
99   void *arg;
100 #if LWIP_DEBUG_TIMERNAMES
101   const char *handler_name;
102 #endif /* LWIP_DEBUG_TIMERNAMES */
103 };
104 
105 void sys_timeouts_init(void);
106 
107 #if LWIP_DEBUG_TIMERNAMES
108 err_t sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char *handler_name);
109 #define sys_timeout_ext(msecs, handler, arg) sys_timeout_debug(msecs, handler, arg, #handler)
110 #else /* LWIP_DEBUG_TIMERNAMES */
111 err_t sys_timeout_ext(u32_t msecs, sys_timeout_handler handler, void *arg);
112 #endif /* LWIP_DEBUG_TIMERNAMES */
113 
114 #define sys_timeout(msecs, handler, arg) (void)sys_timeout_ext(msecs, handler, arg)
115 
116 void sys_untimeout(sys_timeout_handler handler, void *arg);
117 #if LWIP_API_RICH
118 void sys_restart_timeouts(void);
119 #endif /* LWIP_API_RICH */
120 #if LWIP_TESTMODE || NO_SYS
121 void sys_check_timeouts(void);
122 u32_t sys_timeouts_sleeptime(void);
123 #endif
124 #if !NO_SYS
125 void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg);
126 #ifdef DUAL_MBOX
127 void sys_timeouts_dual_mbox_fetch(sys_dual_mbox_t *mbox, void **msg);
128 #endif /* DUAL_MBOX */
129 #endif /* NO_SYS */
130 
131 #if LWIP_TESTMODE
132 struct sys_timeo** lwip_sys_timers_get_next_timout(void);
133 #endif
134 
135 #endif /* LWIP_TIMERS */
136 #endif /* LWIP_LOWPOWER */
137 #if defined (__cplusplus) && __cplusplus
138 }
139 #endif
140 
141 #endif /* LWIP_HDR_TIMEOUTS_H */
142