Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 5:3f93dd1d4cb3 1 /**
sam_grove 5:3f93dd1d4cb3 2 * @file
sam_grove 5:3f93dd1d4cb3 3 * Stack-internal timers implementation.
sam_grove 5:3f93dd1d4cb3 4 * This file includes timer callbacks for stack-internal timers as well as
sam_grove 5:3f93dd1d4cb3 5 * functions to set up or stop timers and check for expired timers.
sam_grove 5:3f93dd1d4cb3 6 *
sam_grove 5:3f93dd1d4cb3 7 */
sam_grove 5:3f93dd1d4cb3 8
sam_grove 5:3f93dd1d4cb3 9 /*
sam_grove 5:3f93dd1d4cb3 10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sam_grove 5:3f93dd1d4cb3 11 * All rights reserved.
sam_grove 5:3f93dd1d4cb3 12 *
sam_grove 5:3f93dd1d4cb3 13 * Redistribution and use in source and binary forms, with or without modification,
sam_grove 5:3f93dd1d4cb3 14 * are permitted provided that the following conditions are met:
sam_grove 5:3f93dd1d4cb3 15 *
sam_grove 5:3f93dd1d4cb3 16 * 1. Redistributions of source code must retain the above copyright notice,
sam_grove 5:3f93dd1d4cb3 17 * this list of conditions and the following disclaimer.
sam_grove 5:3f93dd1d4cb3 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
sam_grove 5:3f93dd1d4cb3 19 * this list of conditions and the following disclaimer in the documentation
sam_grove 5:3f93dd1d4cb3 20 * and/or other materials provided with the distribution.
sam_grove 5:3f93dd1d4cb3 21 * 3. The name of the author may not be used to endorse or promote products
sam_grove 5:3f93dd1d4cb3 22 * derived from this software without specific prior written permission.
sam_grove 5:3f93dd1d4cb3 23 *
sam_grove 5:3f93dd1d4cb3 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sam_grove 5:3f93dd1d4cb3 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sam_grove 5:3f93dd1d4cb3 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sam_grove 5:3f93dd1d4cb3 27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sam_grove 5:3f93dd1d4cb3 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sam_grove 5:3f93dd1d4cb3 29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sam_grove 5:3f93dd1d4cb3 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sam_grove 5:3f93dd1d4cb3 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sam_grove 5:3f93dd1d4cb3 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sam_grove 5:3f93dd1d4cb3 33 * OF SUCH DAMAGE.
sam_grove 5:3f93dd1d4cb3 34 *
sam_grove 5:3f93dd1d4cb3 35 * This file is part of the lwIP TCP/IP stack.
sam_grove 5:3f93dd1d4cb3 36 *
sam_grove 5:3f93dd1d4cb3 37 * Author: Adam Dunkels <adam@sics.se>
sam_grove 5:3f93dd1d4cb3 38 * Simon Goldschmidt
sam_grove 5:3f93dd1d4cb3 39 *
sam_grove 5:3f93dd1d4cb3 40 */
sam_grove 5:3f93dd1d4cb3 41
sam_grove 5:3f93dd1d4cb3 42 #include "lwip/opt.h"
sam_grove 5:3f93dd1d4cb3 43
sam_grove 5:3f93dd1d4cb3 44 #include "lwip/timers.h"
sam_grove 5:3f93dd1d4cb3 45 #include "lwip/tcp_impl.h"
sam_grove 5:3f93dd1d4cb3 46
sam_grove 5:3f93dd1d4cb3 47 #if LWIP_TIMERS
sam_grove 5:3f93dd1d4cb3 48
sam_grove 5:3f93dd1d4cb3 49 #include "lwip/def.h"
sam_grove 5:3f93dd1d4cb3 50 #include "lwip/memp.h"
sam_grove 5:3f93dd1d4cb3 51 #include "lwip/tcpip.h"
sam_grove 5:3f93dd1d4cb3 52
sam_grove 5:3f93dd1d4cb3 53 #include "lwip/ip_frag.h"
sam_grove 5:3f93dd1d4cb3 54 #include "netif/etharp.h"
sam_grove 5:3f93dd1d4cb3 55 #include "lwip/dhcp.h"
sam_grove 5:3f93dd1d4cb3 56 #include "lwip/autoip.h"
sam_grove 5:3f93dd1d4cb3 57 #include "lwip/igmp.h"
sam_grove 5:3f93dd1d4cb3 58 #include "lwip/dns.h"
sam_grove 5:3f93dd1d4cb3 59
sam_grove 5:3f93dd1d4cb3 60
sam_grove 5:3f93dd1d4cb3 61 /** The one and only timeout list */
sam_grove 5:3f93dd1d4cb3 62 static struct sys_timeo *next_timeout;
sam_grove 5:3f93dd1d4cb3 63 #if NO_SYS
sam_grove 5:3f93dd1d4cb3 64 static u32_t timeouts_last_time;
sam_grove 5:3f93dd1d4cb3 65 #endif /* NO_SYS */
sam_grove 5:3f93dd1d4cb3 66
sam_grove 5:3f93dd1d4cb3 67 #if LWIP_TCP
sam_grove 5:3f93dd1d4cb3 68 /** global variable that shows if the tcp timer is currently scheduled or not */
sam_grove 5:3f93dd1d4cb3 69 static int tcpip_tcp_timer_active;
sam_grove 5:3f93dd1d4cb3 70
sam_grove 5:3f93dd1d4cb3 71 /**
sam_grove 5:3f93dd1d4cb3 72 * Timer callback function that calls tcp_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 73 *
sam_grove 5:3f93dd1d4cb3 74 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 75 */
sam_grove 5:3f93dd1d4cb3 76 static void
sam_grove 5:3f93dd1d4cb3 77 tcpip_tcp_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 78 {
sam_grove 5:3f93dd1d4cb3 79 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 80
sam_grove 5:3f93dd1d4cb3 81 /* call TCP timer handler */
sam_grove 5:3f93dd1d4cb3 82 tcp_tmr();
sam_grove 5:3f93dd1d4cb3 83 /* timer still needed? */
sam_grove 5:3f93dd1d4cb3 84 if (tcp_active_pcbs || tcp_tw_pcbs) {
sam_grove 5:3f93dd1d4cb3 85 /* restart timer */
sam_grove 5:3f93dd1d4cb3 86 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 87 } else {
sam_grove 5:3f93dd1d4cb3 88 /* disable timer */
sam_grove 5:3f93dd1d4cb3 89 tcpip_tcp_timer_active = 0;
sam_grove 5:3f93dd1d4cb3 90 }
sam_grove 5:3f93dd1d4cb3 91 }
sam_grove 5:3f93dd1d4cb3 92
sam_grove 5:3f93dd1d4cb3 93 /**
sam_grove 5:3f93dd1d4cb3 94 * Called from TCP_REG when registering a new PCB:
sam_grove 5:3f93dd1d4cb3 95 * the reason is to have the TCP timer only running when
sam_grove 5:3f93dd1d4cb3 96 * there are active (or time-wait) PCBs.
sam_grove 5:3f93dd1d4cb3 97 */
sam_grove 5:3f93dd1d4cb3 98 void
sam_grove 5:3f93dd1d4cb3 99 tcp_timer_needed(void)
sam_grove 5:3f93dd1d4cb3 100 {
sam_grove 5:3f93dd1d4cb3 101 /* timer is off but needed again? */
sam_grove 5:3f93dd1d4cb3 102 if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
sam_grove 5:3f93dd1d4cb3 103 /* enable and start timer */
sam_grove 5:3f93dd1d4cb3 104 tcpip_tcp_timer_active = 1;
sam_grove 5:3f93dd1d4cb3 105 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 106 }
sam_grove 5:3f93dd1d4cb3 107 }
sam_grove 5:3f93dd1d4cb3 108 #endif /* LWIP_TCP */
sam_grove 5:3f93dd1d4cb3 109
sam_grove 5:3f93dd1d4cb3 110 #if IP_REASSEMBLY
sam_grove 5:3f93dd1d4cb3 111 /**
sam_grove 5:3f93dd1d4cb3 112 * Timer callback function that calls ip_reass_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 113 *
sam_grove 5:3f93dd1d4cb3 114 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 115 */
sam_grove 5:3f93dd1d4cb3 116 static void
sam_grove 5:3f93dd1d4cb3 117 ip_reass_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 118 {
sam_grove 5:3f93dd1d4cb3 119 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 120 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: ip_reass_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 121 ip_reass_tmr();
sam_grove 5:3f93dd1d4cb3 122 sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
sam_grove 5:3f93dd1d4cb3 123 }
sam_grove 5:3f93dd1d4cb3 124 #endif /* IP_REASSEMBLY */
sam_grove 5:3f93dd1d4cb3 125
sam_grove 5:3f93dd1d4cb3 126 #if LWIP_ARP
sam_grove 5:3f93dd1d4cb3 127 /**
sam_grove 5:3f93dd1d4cb3 128 * Timer callback function that calls etharp_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 129 *
sam_grove 5:3f93dd1d4cb3 130 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 131 */
sam_grove 5:3f93dd1d4cb3 132 static void
sam_grove 5:3f93dd1d4cb3 133 arp_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 134 {
sam_grove 5:3f93dd1d4cb3 135 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 136 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: etharp_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 137 etharp_tmr();
sam_grove 5:3f93dd1d4cb3 138 sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 139 }
sam_grove 5:3f93dd1d4cb3 140 #endif /* LWIP_ARP */
sam_grove 5:3f93dd1d4cb3 141
sam_grove 5:3f93dd1d4cb3 142 #if LWIP_DHCP
sam_grove 5:3f93dd1d4cb3 143 /**
sam_grove 5:3f93dd1d4cb3 144 * Timer callback function that calls dhcp_coarse_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 145 *
sam_grove 5:3f93dd1d4cb3 146 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 147 */
sam_grove 5:3f93dd1d4cb3 148 static void
sam_grove 5:3f93dd1d4cb3 149 dhcp_timer_coarse(void *arg)
sam_grove 5:3f93dd1d4cb3 150 {
sam_grove 5:3f93dd1d4cb3 151 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 152 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_coarse_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 153 dhcp_coarse_tmr();
sam_grove 5:3f93dd1d4cb3 154 sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
sam_grove 5:3f93dd1d4cb3 155 }
sam_grove 5:3f93dd1d4cb3 156
sam_grove 5:3f93dd1d4cb3 157 /**
sam_grove 5:3f93dd1d4cb3 158 * Timer callback function that calls dhcp_fine_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 159 *
sam_grove 5:3f93dd1d4cb3 160 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 161 */
sam_grove 5:3f93dd1d4cb3 162 static void
sam_grove 5:3f93dd1d4cb3 163 dhcp_timer_fine(void *arg)
sam_grove 5:3f93dd1d4cb3 164 {
sam_grove 5:3f93dd1d4cb3 165 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 166 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_fine_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 167 dhcp_fine_tmr();
sam_grove 5:3f93dd1d4cb3 168 sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
sam_grove 5:3f93dd1d4cb3 169 }
sam_grove 5:3f93dd1d4cb3 170 #endif /* LWIP_DHCP */
sam_grove 5:3f93dd1d4cb3 171
sam_grove 5:3f93dd1d4cb3 172 #if LWIP_AUTOIP
sam_grove 5:3f93dd1d4cb3 173 /**
sam_grove 5:3f93dd1d4cb3 174 * Timer callback function that calls autoip_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 175 *
sam_grove 5:3f93dd1d4cb3 176 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 177 */
sam_grove 5:3f93dd1d4cb3 178 static void
sam_grove 5:3f93dd1d4cb3 179 autoip_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 180 {
sam_grove 5:3f93dd1d4cb3 181 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 182 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: autoip_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 183 autoip_tmr();
sam_grove 5:3f93dd1d4cb3 184 sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
sam_grove 5:3f93dd1d4cb3 185 }
sam_grove 5:3f93dd1d4cb3 186 #endif /* LWIP_AUTOIP */
sam_grove 5:3f93dd1d4cb3 187
sam_grove 5:3f93dd1d4cb3 188 #if LWIP_IGMP
sam_grove 5:3f93dd1d4cb3 189 /**
sam_grove 5:3f93dd1d4cb3 190 * Timer callback function that calls igmp_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 191 *
sam_grove 5:3f93dd1d4cb3 192 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 193 */
sam_grove 5:3f93dd1d4cb3 194 static void
sam_grove 5:3f93dd1d4cb3 195 igmp_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 196 {
sam_grove 5:3f93dd1d4cb3 197 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 198 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: igmp_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 199 igmp_tmr();
sam_grove 5:3f93dd1d4cb3 200 sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 201 }
sam_grove 5:3f93dd1d4cb3 202 #endif /* LWIP_IGMP */
sam_grove 5:3f93dd1d4cb3 203
sam_grove 5:3f93dd1d4cb3 204 #if LWIP_DNS
sam_grove 5:3f93dd1d4cb3 205 /**
sam_grove 5:3f93dd1d4cb3 206 * Timer callback function that calls dns_tmr() and reschedules itself.
sam_grove 5:3f93dd1d4cb3 207 *
sam_grove 5:3f93dd1d4cb3 208 * @param arg unused argument
sam_grove 5:3f93dd1d4cb3 209 */
sam_grove 5:3f93dd1d4cb3 210 static void
sam_grove 5:3f93dd1d4cb3 211 dns_timer(void *arg)
sam_grove 5:3f93dd1d4cb3 212 {
sam_grove 5:3f93dd1d4cb3 213 LWIP_UNUSED_ARG(arg);
sam_grove 5:3f93dd1d4cb3 214 LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dns_tmr()\n"));
sam_grove 5:3f93dd1d4cb3 215 dns_tmr();
sam_grove 5:3f93dd1d4cb3 216 sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
sam_grove 5:3f93dd1d4cb3 217 }
sam_grove 5:3f93dd1d4cb3 218 #endif /* LWIP_DNS */
sam_grove 5:3f93dd1d4cb3 219
sam_grove 5:3f93dd1d4cb3 220 /** Initialize this module */
sam_grove 5:3f93dd1d4cb3 221 void sys_timeouts_init(void)
sam_grove 5:3f93dd1d4cb3 222 {
sam_grove 5:3f93dd1d4cb3 223 #if IP_REASSEMBLY
sam_grove 5:3f93dd1d4cb3 224 sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
sam_grove 5:3f93dd1d4cb3 225 #endif /* IP_REASSEMBLY */
sam_grove 5:3f93dd1d4cb3 226 #if LWIP_ARP
sam_grove 5:3f93dd1d4cb3 227 sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 228 #endif /* LWIP_ARP */
sam_grove 5:3f93dd1d4cb3 229 #if LWIP_DHCP
sam_grove 5:3f93dd1d4cb3 230 sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
sam_grove 5:3f93dd1d4cb3 231 sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
sam_grove 5:3f93dd1d4cb3 232 #endif /* LWIP_DHCP */
sam_grove 5:3f93dd1d4cb3 233 #if LWIP_AUTOIP
sam_grove 5:3f93dd1d4cb3 234 sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
sam_grove 5:3f93dd1d4cb3 235 #endif /* LWIP_AUTOIP */
sam_grove 5:3f93dd1d4cb3 236 #if LWIP_IGMP
sam_grove 5:3f93dd1d4cb3 237 sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
sam_grove 5:3f93dd1d4cb3 238 #endif /* LWIP_IGMP */
sam_grove 5:3f93dd1d4cb3 239 #if LWIP_DNS
sam_grove 5:3f93dd1d4cb3 240 sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
sam_grove 5:3f93dd1d4cb3 241 #endif /* LWIP_DNS */
sam_grove 5:3f93dd1d4cb3 242
sam_grove 5:3f93dd1d4cb3 243 #if NO_SYS
sam_grove 5:3f93dd1d4cb3 244 /* Initialise timestamp for sys_check_timeouts */
sam_grove 5:3f93dd1d4cb3 245 timeouts_last_time = sys_now();
sam_grove 5:3f93dd1d4cb3 246 #endif
sam_grove 5:3f93dd1d4cb3 247 }
sam_grove 5:3f93dd1d4cb3 248
sam_grove 5:3f93dd1d4cb3 249 /**
sam_grove 5:3f93dd1d4cb3 250 * Create a one-shot timer (aka timeout). Timeouts are processed in the
sam_grove 5:3f93dd1d4cb3 251 * following cases:
sam_grove 5:3f93dd1d4cb3 252 * - while waiting for a message using sys_timeouts_mbox_fetch()
sam_grove 5:3f93dd1d4cb3 253 * - by calling sys_check_timeouts() (NO_SYS==1 only)
sam_grove 5:3f93dd1d4cb3 254 *
sam_grove 5:3f93dd1d4cb3 255 * @param msecs time in milliseconds after that the timer should expire
sam_grove 5:3f93dd1d4cb3 256 * @param handler callback function to call when msecs have elapsed
sam_grove 5:3f93dd1d4cb3 257 * @param arg argument to pass to the callback function
sam_grove 5:3f93dd1d4cb3 258 */
sam_grove 5:3f93dd1d4cb3 259 #if LWIP_DEBUG_TIMERNAMES
sam_grove 5:3f93dd1d4cb3 260 void
sam_grove 5:3f93dd1d4cb3 261 sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)
sam_grove 5:3f93dd1d4cb3 262 #else /* LWIP_DEBUG_TIMERNAMES */
sam_grove 5:3f93dd1d4cb3 263 void
sam_grove 5:3f93dd1d4cb3 264 sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
sam_grove 5:3f93dd1d4cb3 265 #endif /* LWIP_DEBUG_TIMERNAMES */
sam_grove 5:3f93dd1d4cb3 266 {
sam_grove 5:3f93dd1d4cb3 267 struct sys_timeo *timeout, *t;
sam_grove 5:3f93dd1d4cb3 268
sam_grove 5:3f93dd1d4cb3 269 timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT);
sam_grove 5:3f93dd1d4cb3 270 if (timeout == NULL) {
sam_grove 5:3f93dd1d4cb3 271 LWIP_ASSERT("sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL);
sam_grove 5:3f93dd1d4cb3 272 return;
sam_grove 5:3f93dd1d4cb3 273 }
sam_grove 5:3f93dd1d4cb3 274 timeout->next = NULL;
sam_grove 5:3f93dd1d4cb3 275 timeout->h = handler;
sam_grove 5:3f93dd1d4cb3 276 timeout->arg = arg;
sam_grove 5:3f93dd1d4cb3 277 timeout->time = msecs;
sam_grove 5:3f93dd1d4cb3 278 #if LWIP_DEBUG_TIMERNAMES
sam_grove 5:3f93dd1d4cb3 279 timeout->handler_name = handler_name;
sam_grove 5:3f93dd1d4cb3 280 LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n",
sam_grove 5:3f93dd1d4cb3 281 (void *)timeout, msecs, handler_name, (void *)arg));
sam_grove 5:3f93dd1d4cb3 282 #endif /* LWIP_DEBUG_TIMERNAMES */
sam_grove 5:3f93dd1d4cb3 283
sam_grove 5:3f93dd1d4cb3 284 if (next_timeout == NULL) {
sam_grove 5:3f93dd1d4cb3 285 next_timeout = timeout;
sam_grove 5:3f93dd1d4cb3 286 return;
sam_grove 5:3f93dd1d4cb3 287 }
sam_grove 5:3f93dd1d4cb3 288
sam_grove 5:3f93dd1d4cb3 289 if (next_timeout->time > msecs) {
sam_grove 5:3f93dd1d4cb3 290 next_timeout->time -= msecs;
sam_grove 5:3f93dd1d4cb3 291 timeout->next = next_timeout;
sam_grove 5:3f93dd1d4cb3 292 next_timeout = timeout;
sam_grove 5:3f93dd1d4cb3 293 } else {
sam_grove 5:3f93dd1d4cb3 294 for(t = next_timeout; t != NULL; t = t->next) {
sam_grove 5:3f93dd1d4cb3 295 timeout->time -= t->time;
sam_grove 5:3f93dd1d4cb3 296 if (t->next == NULL || t->next->time > timeout->time) {
sam_grove 5:3f93dd1d4cb3 297 if (t->next != NULL) {
sam_grove 5:3f93dd1d4cb3 298 t->next->time -= timeout->time;
sam_grove 5:3f93dd1d4cb3 299 }
sam_grove 5:3f93dd1d4cb3 300 timeout->next = t->next;
sam_grove 5:3f93dd1d4cb3 301 t->next = timeout;
sam_grove 5:3f93dd1d4cb3 302 break;
sam_grove 5:3f93dd1d4cb3 303 }
sam_grove 5:3f93dd1d4cb3 304 }
sam_grove 5:3f93dd1d4cb3 305 }
sam_grove 5:3f93dd1d4cb3 306 }
sam_grove 5:3f93dd1d4cb3 307
sam_grove 5:3f93dd1d4cb3 308 /**
sam_grove 5:3f93dd1d4cb3 309 * Go through timeout list (for this task only) and remove the first matching
sam_grove 5:3f93dd1d4cb3 310 * entry, even though the timeout has not triggered yet.
sam_grove 5:3f93dd1d4cb3 311 *
sam_grove 5:3f93dd1d4cb3 312 * @note This function only works as expected if there is only one timeout
sam_grove 5:3f93dd1d4cb3 313 * calling 'handler' in the list of timeouts.
sam_grove 5:3f93dd1d4cb3 314 *
sam_grove 5:3f93dd1d4cb3 315 * @param handler callback function that would be called by the timeout
sam_grove 5:3f93dd1d4cb3 316 * @param arg callback argument that would be passed to handler
sam_grove 5:3f93dd1d4cb3 317 */
sam_grove 5:3f93dd1d4cb3 318 void
sam_grove 5:3f93dd1d4cb3 319 sys_untimeout(sys_timeout_handler handler, void *arg)
sam_grove 5:3f93dd1d4cb3 320 {
sam_grove 5:3f93dd1d4cb3 321 struct sys_timeo *prev_t, *t;
sam_grove 5:3f93dd1d4cb3 322
sam_grove 5:3f93dd1d4cb3 323 if (next_timeout == NULL) {
sam_grove 5:3f93dd1d4cb3 324 return;
sam_grove 5:3f93dd1d4cb3 325 }
sam_grove 5:3f93dd1d4cb3 326
sam_grove 5:3f93dd1d4cb3 327 for (t = next_timeout, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
sam_grove 5:3f93dd1d4cb3 328 if ((t->h == handler) && (t->arg == arg)) {
sam_grove 5:3f93dd1d4cb3 329 /* We have a match */
sam_grove 5:3f93dd1d4cb3 330 /* Unlink from previous in list */
sam_grove 5:3f93dd1d4cb3 331 if (prev_t == NULL) {
sam_grove 5:3f93dd1d4cb3 332 next_timeout = t->next;
sam_grove 5:3f93dd1d4cb3 333 } else {
sam_grove 5:3f93dd1d4cb3 334 prev_t->next = t->next;
sam_grove 5:3f93dd1d4cb3 335 }
sam_grove 5:3f93dd1d4cb3 336 /* If not the last one, add time of this one back to next */
sam_grove 5:3f93dd1d4cb3 337 if (t->next != NULL) {
sam_grove 5:3f93dd1d4cb3 338 t->next->time += t->time;
sam_grove 5:3f93dd1d4cb3 339 }
sam_grove 5:3f93dd1d4cb3 340 memp_free(MEMP_SYS_TIMEOUT, t);
sam_grove 5:3f93dd1d4cb3 341 return;
sam_grove 5:3f93dd1d4cb3 342 }
sam_grove 5:3f93dd1d4cb3 343 }
sam_grove 5:3f93dd1d4cb3 344 return;
sam_grove 5:3f93dd1d4cb3 345 }
sam_grove 5:3f93dd1d4cb3 346
sam_grove 5:3f93dd1d4cb3 347 #if NO_SYS
sam_grove 5:3f93dd1d4cb3 348
sam_grove 5:3f93dd1d4cb3 349 /** Handle timeouts for NO_SYS==1 (i.e. without using
sam_grove 5:3f93dd1d4cb3 350 * tcpip_thread/sys_timeouts_mbox_fetch(). Uses sys_now() to call timeout
sam_grove 5:3f93dd1d4cb3 351 * handler functions when timeouts expire.
sam_grove 5:3f93dd1d4cb3 352 *
sam_grove 5:3f93dd1d4cb3 353 * Must be called periodically from your main loop.
sam_grove 5:3f93dd1d4cb3 354 */
sam_grove 5:3f93dd1d4cb3 355 void
sam_grove 5:3f93dd1d4cb3 356 sys_check_timeouts(void)
sam_grove 5:3f93dd1d4cb3 357 {
sam_grove 5:3f93dd1d4cb3 358 struct sys_timeo *tmptimeout;
sam_grove 5:3f93dd1d4cb3 359 u32_t diff;
sam_grove 5:3f93dd1d4cb3 360 sys_timeout_handler handler;
sam_grove 5:3f93dd1d4cb3 361 void *arg;
sam_grove 5:3f93dd1d4cb3 362 int had_one;
sam_grove 5:3f93dd1d4cb3 363 u32_t now;
sam_grove 5:3f93dd1d4cb3 364
sam_grove 5:3f93dd1d4cb3 365 now = sys_now();
sam_grove 5:3f93dd1d4cb3 366 if (next_timeout) {
sam_grove 5:3f93dd1d4cb3 367 /* this cares for wraparounds */
sam_grove 5:3f93dd1d4cb3 368 diff = LWIP_U32_DIFF(now, timeouts_last_time);
sam_grove 5:3f93dd1d4cb3 369 do
sam_grove 5:3f93dd1d4cb3 370 {
sam_grove 5:3f93dd1d4cb3 371 had_one = 0;
sam_grove 5:3f93dd1d4cb3 372 tmptimeout = next_timeout;
sam_grove 5:3f93dd1d4cb3 373 if (tmptimeout->time <= diff) {
sam_grove 5:3f93dd1d4cb3 374 /* timeout has expired */
sam_grove 5:3f93dd1d4cb3 375 had_one = 1;
sam_grove 5:3f93dd1d4cb3 376 timeouts_last_time = now;
sam_grove 5:3f93dd1d4cb3 377 diff -= tmptimeout->time;
sam_grove 5:3f93dd1d4cb3 378 next_timeout = tmptimeout->next;
sam_grove 5:3f93dd1d4cb3 379 handler = tmptimeout->h;
sam_grove 5:3f93dd1d4cb3 380 arg = tmptimeout->arg;
sam_grove 5:3f93dd1d4cb3 381 #if LWIP_DEBUG_TIMERNAMES
sam_grove 5:3f93dd1d4cb3 382 if (handler != NULL) {
sam_grove 5:3f93dd1d4cb3 383 LWIP_DEBUGF(TIMERS_DEBUG, ("sct calling h=%s arg=%p\n",
sam_grove 5:3f93dd1d4cb3 384 tmptimeout->handler_name, arg));
sam_grove 5:3f93dd1d4cb3 385 }
sam_grove 5:3f93dd1d4cb3 386 #endif /* LWIP_DEBUG_TIMERNAMES */
sam_grove 5:3f93dd1d4cb3 387 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
sam_grove 5:3f93dd1d4cb3 388 if (handler != NULL) {
sam_grove 5:3f93dd1d4cb3 389 handler(arg);
sam_grove 5:3f93dd1d4cb3 390 }
sam_grove 5:3f93dd1d4cb3 391 }
sam_grove 5:3f93dd1d4cb3 392 /* repeat until all expired timers have been called */
sam_grove 5:3f93dd1d4cb3 393 }while(had_one);
sam_grove 5:3f93dd1d4cb3 394 }
sam_grove 5:3f93dd1d4cb3 395 }
sam_grove 5:3f93dd1d4cb3 396
sam_grove 5:3f93dd1d4cb3 397 /** Set back the timestamp of the last call to sys_check_timeouts()
sam_grove 5:3f93dd1d4cb3 398 * This is necessary if sys_check_timeouts() hasn't been called for a long
sam_grove 5:3f93dd1d4cb3 399 * time (e.g. while saving energy) to prevent all timer functions of that
sam_grove 5:3f93dd1d4cb3 400 * period being called.
sam_grove 5:3f93dd1d4cb3 401 */
sam_grove 5:3f93dd1d4cb3 402 void
sam_grove 5:3f93dd1d4cb3 403 sys_restart_timeouts(void)
sam_grove 5:3f93dd1d4cb3 404 {
sam_grove 5:3f93dd1d4cb3 405 timeouts_last_time = sys_now();
sam_grove 5:3f93dd1d4cb3 406 }
sam_grove 5:3f93dd1d4cb3 407
sam_grove 5:3f93dd1d4cb3 408 #else /* NO_SYS */
sam_grove 5:3f93dd1d4cb3 409
sam_grove 5:3f93dd1d4cb3 410 /**
sam_grove 5:3f93dd1d4cb3 411 * Wait (forever) for a message to arrive in an mbox.
sam_grove 5:3f93dd1d4cb3 412 * While waiting, timeouts are processed.
sam_grove 5:3f93dd1d4cb3 413 *
sam_grove 5:3f93dd1d4cb3 414 * @param mbox the mbox to fetch the message from
sam_grove 5:3f93dd1d4cb3 415 * @param msg the place to store the message
sam_grove 5:3f93dd1d4cb3 416 */
sam_grove 5:3f93dd1d4cb3 417 void
sam_grove 5:3f93dd1d4cb3 418 sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
sam_grove 5:3f93dd1d4cb3 419 {
sam_grove 5:3f93dd1d4cb3 420 u32_t time_needed;
sam_grove 5:3f93dd1d4cb3 421 struct sys_timeo *tmptimeout;
sam_grove 5:3f93dd1d4cb3 422 sys_timeout_handler handler;
sam_grove 5:3f93dd1d4cb3 423 void *arg;
sam_grove 5:3f93dd1d4cb3 424
sam_grove 5:3f93dd1d4cb3 425 again:
sam_grove 5:3f93dd1d4cb3 426 if (!next_timeout) {
sam_grove 5:3f93dd1d4cb3 427 time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
sam_grove 5:3f93dd1d4cb3 428 } else {
sam_grove 5:3f93dd1d4cb3 429 if (next_timeout->time > 0) {
sam_grove 5:3f93dd1d4cb3 430 time_needed = sys_arch_mbox_fetch(mbox, msg, next_timeout->time);
sam_grove 5:3f93dd1d4cb3 431 } else {
sam_grove 5:3f93dd1d4cb3 432 time_needed = SYS_ARCH_TIMEOUT;
sam_grove 5:3f93dd1d4cb3 433 }
sam_grove 5:3f93dd1d4cb3 434
sam_grove 5:3f93dd1d4cb3 435 if (time_needed == SYS_ARCH_TIMEOUT) {
sam_grove 5:3f93dd1d4cb3 436 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
sam_grove 5:3f93dd1d4cb3 437 could be fetched. We should now call the timeout handler and
sam_grove 5:3f93dd1d4cb3 438 deallocate the memory allocated for the timeout. */
sam_grove 5:3f93dd1d4cb3 439 tmptimeout = next_timeout;
sam_grove 5:3f93dd1d4cb3 440 next_timeout = tmptimeout->next;
sam_grove 5:3f93dd1d4cb3 441 handler = tmptimeout->h;
sam_grove 5:3f93dd1d4cb3 442 arg = tmptimeout->arg;
sam_grove 5:3f93dd1d4cb3 443 #if LWIP_DEBUG_TIMERNAMES
sam_grove 5:3f93dd1d4cb3 444 if (handler != NULL) {
sam_grove 5:3f93dd1d4cb3 445 LWIP_DEBUGF(TIMERS_DEBUG, ("stmf calling h=%s arg=%p\n",
sam_grove 5:3f93dd1d4cb3 446 tmptimeout->handler_name, arg));
sam_grove 5:3f93dd1d4cb3 447 }
sam_grove 5:3f93dd1d4cb3 448 #endif /* LWIP_DEBUG_TIMERNAMES */
sam_grove 5:3f93dd1d4cb3 449 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
sam_grove 5:3f93dd1d4cb3 450 if (handler != NULL) {
sam_grove 5:3f93dd1d4cb3 451 /* For LWIP_TCPIP_CORE_LOCKING, lock the core before calling the
sam_grove 5:3f93dd1d4cb3 452 timeout handler function. */
sam_grove 5:3f93dd1d4cb3 453 LOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 454 handler(arg);
sam_grove 5:3f93dd1d4cb3 455 UNLOCK_TCPIP_CORE();
sam_grove 5:3f93dd1d4cb3 456 }
sam_grove 5:3f93dd1d4cb3 457 LWIP_TCPIP_THREAD_ALIVE();
sam_grove 5:3f93dd1d4cb3 458
sam_grove 5:3f93dd1d4cb3 459 /* We try again to fetch a message from the mbox. */
sam_grove 5:3f93dd1d4cb3 460 goto again;
sam_grove 5:3f93dd1d4cb3 461 } else {
sam_grove 5:3f93dd1d4cb3 462 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
sam_grove 5:3f93dd1d4cb3 463 occured. The time variable is set to the number of
sam_grove 5:3f93dd1d4cb3 464 milliseconds we waited for the message. */
sam_grove 5:3f93dd1d4cb3 465 if (time_needed < next_timeout->time) {
sam_grove 5:3f93dd1d4cb3 466 next_timeout->time -= time_needed;
sam_grove 5:3f93dd1d4cb3 467 } else {
sam_grove 5:3f93dd1d4cb3 468 next_timeout->time = 0;
sam_grove 5:3f93dd1d4cb3 469 }
sam_grove 5:3f93dd1d4cb3 470 }
sam_grove 5:3f93dd1d4cb3 471 }
sam_grove 5:3f93dd1d4cb3 472 }
sam_grove 5:3f93dd1d4cb3 473
sam_grove 5:3f93dd1d4cb3 474 #endif /* NO_SYS */
sam_grove 5:3f93dd1d4cb3 475
sam_grove 5:3f93dd1d4cb3 476 #else /* LWIP_TIMERS */
sam_grove 5:3f93dd1d4cb3 477 /* Satisfy the TCP code which calls this function */
sam_grove 5:3f93dd1d4cb3 478 void
sam_grove 5:3f93dd1d4cb3 479 tcp_timer_needed(void)
sam_grove 5:3f93dd1d4cb3 480 {
sam_grove 5:3f93dd1d4cb3 481 }
sam_grove 5:3f93dd1d4cb3 482 #endif /* LWIP_TIMERS */