A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
root@mbed.org 0:5e1631496985 1 /**
root@mbed.org 0:5e1631496985 2 * @file
root@mbed.org 0:5e1631496985 3 * lwIP Operating System abstraction
root@mbed.org 0:5e1631496985 4 *
root@mbed.org 0:5e1631496985 5 */
root@mbed.org 0:5e1631496985 6
root@mbed.org 0:5e1631496985 7 /*
root@mbed.org 0:5e1631496985 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
root@mbed.org 0:5e1631496985 9 * All rights reserved.
root@mbed.org 0:5e1631496985 10 *
root@mbed.org 0:5e1631496985 11 * Redistribution and use in source and binary forms, with or without modification,
root@mbed.org 0:5e1631496985 12 * are permitted provided that the following conditions are met:
root@mbed.org 0:5e1631496985 13 *
root@mbed.org 0:5e1631496985 14 * 1. Redistributions of source code must retain the above copyright notice,
root@mbed.org 0:5e1631496985 15 * this list of conditions and the following disclaimer.
root@mbed.org 0:5e1631496985 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
root@mbed.org 0:5e1631496985 17 * this list of conditions and the following disclaimer in the documentation
root@mbed.org 0:5e1631496985 18 * and/or other materials provided with the distribution.
root@mbed.org 0:5e1631496985 19 * 3. The name of the author may not be used to endorse or promote products
root@mbed.org 0:5e1631496985 20 * derived from this software without specific prior written permission.
root@mbed.org 0:5e1631496985 21 *
root@mbed.org 0:5e1631496985 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
root@mbed.org 0:5e1631496985 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
root@mbed.org 0:5e1631496985 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
root@mbed.org 0:5e1631496985 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
root@mbed.org 0:5e1631496985 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
root@mbed.org 0:5e1631496985 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
root@mbed.org 0:5e1631496985 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
root@mbed.org 0:5e1631496985 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
root@mbed.org 0:5e1631496985 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
root@mbed.org 0:5e1631496985 31 * OF SUCH DAMAGE.
root@mbed.org 0:5e1631496985 32 *
root@mbed.org 0:5e1631496985 33 * This file is part of the lwIP TCP/IP stack.
root@mbed.org 0:5e1631496985 34 *
root@mbed.org 0:5e1631496985 35 * Author: Adam Dunkels <adam@sics.se>
root@mbed.org 0:5e1631496985 36 *
root@mbed.org 0:5e1631496985 37 */
root@mbed.org 0:5e1631496985 38
root@mbed.org 0:5e1631496985 39 #include "lwip/opt.h"
root@mbed.org 0:5e1631496985 40
root@mbed.org 0:5e1631496985 41 #if (NO_SYS == 0) /* don't build if not configured for use in lwipopts.h */
root@mbed.org 0:5e1631496985 42
root@mbed.org 0:5e1631496985 43 #include "lwip/sys.h"
root@mbed.org 0:5e1631496985 44 #include "lwip/def.h"
root@mbed.org 0:5e1631496985 45 #include "lwip/memp.h"
root@mbed.org 0:5e1631496985 46 #include "lwip/tcpip.h"
root@mbed.org 0:5e1631496985 47
root@mbed.org 0:5e1631496985 48 /**
root@mbed.org 0:5e1631496985 49 * Struct used for sys_sem_wait_timeout() to tell wether the time
root@mbed.org 0:5e1631496985 50 * has run out or the semaphore has really become available.
root@mbed.org 0:5e1631496985 51 */
root@mbed.org 0:5e1631496985 52 struct sswt_cb
root@mbed.org 0:5e1631496985 53 {
root@mbed.org 0:5e1631496985 54 s16_t timeflag;
root@mbed.org 0:5e1631496985 55 sys_sem_t *psem;
root@mbed.org 0:5e1631496985 56 };
root@mbed.org 0:5e1631496985 57
root@mbed.org 0:5e1631496985 58 /**
root@mbed.org 0:5e1631496985 59 * Wait (forever) for a message to arrive in an mbox.
root@mbed.org 0:5e1631496985 60 * While waiting, timeouts (for this thread) are processed.
root@mbed.org 0:5e1631496985 61 *
root@mbed.org 0:5e1631496985 62 * @param mbox the mbox to fetch the message from
root@mbed.org 0:5e1631496985 63 * @param msg the place to store the message
root@mbed.org 0:5e1631496985 64 */
root@mbed.org 0:5e1631496985 65 void
root@mbed.org 0:5e1631496985 66 sys_mbox_fetch(sys_mbox_t mbox, void **msg)
root@mbed.org 0:5e1631496985 67 {
root@mbed.org 0:5e1631496985 68 u32_t time_needed;
root@mbed.org 0:5e1631496985 69 struct sys_timeouts *timeouts;
root@mbed.org 0:5e1631496985 70 struct sys_timeo *tmptimeout;
root@mbed.org 0:5e1631496985 71 sys_timeout_handler h;
root@mbed.org 0:5e1631496985 72 void *arg;
root@mbed.org 0:5e1631496985 73
root@mbed.org 0:5e1631496985 74 again:
root@mbed.org 0:5e1631496985 75 timeouts = sys_arch_timeouts();
root@mbed.org 0:5e1631496985 76
root@mbed.org 0:5e1631496985 77 if (!timeouts || !timeouts->next) {
root@mbed.org 0:5e1631496985 78 UNLOCK_TCPIP_CORE();
root@mbed.org 0:5e1631496985 79 time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
root@mbed.org 0:5e1631496985 80 LOCK_TCPIP_CORE();
root@mbed.org 0:5e1631496985 81 } else {
root@mbed.org 0:5e1631496985 82 if (timeouts->next->time > 0) {
root@mbed.org 0:5e1631496985 83 UNLOCK_TCPIP_CORE();
root@mbed.org 0:5e1631496985 84 time_needed = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
root@mbed.org 0:5e1631496985 85 LOCK_TCPIP_CORE();
root@mbed.org 0:5e1631496985 86 } else {
root@mbed.org 0:5e1631496985 87 time_needed = SYS_ARCH_TIMEOUT;
root@mbed.org 0:5e1631496985 88 }
root@mbed.org 0:5e1631496985 89
root@mbed.org 0:5e1631496985 90 if (time_needed == SYS_ARCH_TIMEOUT) {
root@mbed.org 0:5e1631496985 91 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
root@mbed.org 0:5e1631496985 92 could be fetched. We should now call the timeout handler and
root@mbed.org 0:5e1631496985 93 deallocate the memory allocated for the timeout. */
root@mbed.org 0:5e1631496985 94 tmptimeout = timeouts->next;
root@mbed.org 0:5e1631496985 95 timeouts->next = tmptimeout->next;
root@mbed.org 0:5e1631496985 96 h = tmptimeout->h;
root@mbed.org 0:5e1631496985 97 arg = tmptimeout->arg;
root@mbed.org 0:5e1631496985 98 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
root@mbed.org 0:5e1631496985 99 if (h != NULL) {
root@mbed.org 0:5e1631496985 100 LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void*)&h, arg));
root@mbed.org 0:5e1631496985 101 h(arg);
root@mbed.org 0:5e1631496985 102 }
root@mbed.org 0:5e1631496985 103
root@mbed.org 0:5e1631496985 104 /* We try again to fetch a message from the mbox. */
root@mbed.org 0:5e1631496985 105 goto again;
root@mbed.org 0:5e1631496985 106 } else {
root@mbed.org 0:5e1631496985 107 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
root@mbed.org 0:5e1631496985 108 occured. The time variable is set to the number of
root@mbed.org 0:5e1631496985 109 milliseconds we waited for the message. */
root@mbed.org 0:5e1631496985 110 if (time_needed < timeouts->next->time) {
root@mbed.org 0:5e1631496985 111 timeouts->next->time -= time_needed;
root@mbed.org 0:5e1631496985 112 } else {
root@mbed.org 0:5e1631496985 113 timeouts->next->time = 0;
root@mbed.org 0:5e1631496985 114 }
root@mbed.org 0:5e1631496985 115 }
root@mbed.org 0:5e1631496985 116 }
root@mbed.org 0:5e1631496985 117 }
root@mbed.org 0:5e1631496985 118
root@mbed.org 0:5e1631496985 119 /**
root@mbed.org 0:5e1631496985 120 * Wait (forever) for a semaphore to become available.
root@mbed.org 0:5e1631496985 121 * While waiting, timeouts (for this thread) are processed.
root@mbed.org 0:5e1631496985 122 *
root@mbed.org 0:5e1631496985 123 * @param sem semaphore to wait for
root@mbed.org 0:5e1631496985 124 */
root@mbed.org 0:5e1631496985 125 void
root@mbed.org 0:5e1631496985 126 sys_sem_wait(sys_sem_t sem)
root@mbed.org 0:5e1631496985 127 {
root@mbed.org 0:5e1631496985 128 u32_t time_needed;
root@mbed.org 0:5e1631496985 129 struct sys_timeouts *timeouts;
root@mbed.org 0:5e1631496985 130 struct sys_timeo *tmptimeout;
root@mbed.org 0:5e1631496985 131 sys_timeout_handler h;
root@mbed.org 0:5e1631496985 132 void *arg;
root@mbed.org 0:5e1631496985 133
root@mbed.org 0:5e1631496985 134 again:
root@mbed.org 0:5e1631496985 135
root@mbed.org 0:5e1631496985 136 timeouts = sys_arch_timeouts();
root@mbed.org 0:5e1631496985 137
root@mbed.org 0:5e1631496985 138 if (!timeouts || !timeouts->next) {
root@mbed.org 0:5e1631496985 139 sys_arch_sem_wait(sem, 0);
root@mbed.org 0:5e1631496985 140 } else {
root@mbed.org 0:5e1631496985 141 if (timeouts->next->time > 0) {
root@mbed.org 0:5e1631496985 142 time_needed = sys_arch_sem_wait(sem, timeouts->next->time);
root@mbed.org 0:5e1631496985 143 } else {
root@mbed.org 0:5e1631496985 144 time_needed = SYS_ARCH_TIMEOUT;
root@mbed.org 0:5e1631496985 145 }
root@mbed.org 0:5e1631496985 146
root@mbed.org 0:5e1631496985 147 if (time_needed == SYS_ARCH_TIMEOUT) {
root@mbed.org 0:5e1631496985 148 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
root@mbed.org 0:5e1631496985 149 could be fetched. We should now call the timeout handler and
root@mbed.org 0:5e1631496985 150 deallocate the memory allocated for the timeout. */
root@mbed.org 0:5e1631496985 151 tmptimeout = timeouts->next;
root@mbed.org 0:5e1631496985 152 timeouts->next = tmptimeout->next;
root@mbed.org 0:5e1631496985 153 h = tmptimeout->h;
root@mbed.org 0:5e1631496985 154 arg = tmptimeout->arg;
root@mbed.org 0:5e1631496985 155 memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
root@mbed.org 0:5e1631496985 156 if (h != NULL) {
root@mbed.org 0:5e1631496985 157 LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void*)&h, (void *)arg));
root@mbed.org 0:5e1631496985 158 h(arg);
root@mbed.org 0:5e1631496985 159 }
root@mbed.org 0:5e1631496985 160
root@mbed.org 0:5e1631496985 161 /* We try again to fetch a message from the mbox. */
root@mbed.org 0:5e1631496985 162 goto again;
root@mbed.org 0:5e1631496985 163 } else {
root@mbed.org 0:5e1631496985 164 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
root@mbed.org 0:5e1631496985 165 occured. The time variable is set to the number of
root@mbed.org 0:5e1631496985 166 milliseconds we waited for the message. */
root@mbed.org 0:5e1631496985 167 if (time_needed < timeouts->next->time) {
root@mbed.org 0:5e1631496985 168 timeouts->next->time -= time_needed;
root@mbed.org 0:5e1631496985 169 } else {
root@mbed.org 0:5e1631496985 170 timeouts->next->time = 0;
root@mbed.org 0:5e1631496985 171 }
root@mbed.org 0:5e1631496985 172 }
root@mbed.org 0:5e1631496985 173 }
root@mbed.org 0:5e1631496985 174 }
root@mbed.org 0:5e1631496985 175
root@mbed.org 0:5e1631496985 176 /**
root@mbed.org 0:5e1631496985 177 * Create a one-shot timer (aka timeout). Timeouts are processed in the
root@mbed.org 0:5e1631496985 178 * following cases:
root@mbed.org 0:5e1631496985 179 * - while waiting for a message using sys_mbox_fetch()
root@mbed.org 0:5e1631496985 180 * - while waiting for a semaphore using sys_sem_wait() or sys_sem_wait_timeout()
root@mbed.org 0:5e1631496985 181 * - while sleeping using the inbuilt sys_msleep()
root@mbed.org 0:5e1631496985 182 *
root@mbed.org 0:5e1631496985 183 * @param msecs time in milliseconds after that the timer should expire
root@mbed.org 0:5e1631496985 184 * @param h callback function to call when msecs have elapsed
root@mbed.org 0:5e1631496985 185 * @param arg argument to pass to the callback function
root@mbed.org 0:5e1631496985 186 */
root@mbed.org 0:5e1631496985 187 void
root@mbed.org 0:5e1631496985 188 sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
root@mbed.org 0:5e1631496985 189 {
root@mbed.org 0:5e1631496985 190 struct sys_timeouts *timeouts;
root@mbed.org 0:5e1631496985 191 struct sys_timeo *timeout, *t;
root@mbed.org 0:5e1631496985 192
root@mbed.org 0:5e1631496985 193 timeout = memp_malloc(MEMP_SYS_TIMEOUT);
root@mbed.org 0:5e1631496985 194 if (timeout == NULL) {
root@mbed.org 0:5e1631496985 195 LWIP_ASSERT("sys_timeout: timeout != NULL", timeout != NULL);
root@mbed.org 0:5e1631496985 196 return;
root@mbed.org 0:5e1631496985 197 }
root@mbed.org 0:5e1631496985 198 timeout->next = NULL;
root@mbed.org 0:5e1631496985 199 timeout->h = h;
root@mbed.org 0:5e1631496985 200 timeout->arg = arg;
root@mbed.org 0:5e1631496985 201 timeout->time = msecs;
root@mbed.org 0:5e1631496985 202
root@mbed.org 0:5e1631496985 203 timeouts = sys_arch_timeouts();
root@mbed.org 0:5e1631496985 204
root@mbed.org 0:5e1631496985 205 LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" h=%p arg=%p\n",
root@mbed.org 0:5e1631496985 206 (void *)timeout, msecs, (void*)&h, (void *)arg));
root@mbed.org 0:5e1631496985 207
root@mbed.org 0:5e1631496985 208 if (timeouts == NULL) {
root@mbed.org 0:5e1631496985 209 LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
root@mbed.org 0:5e1631496985 210 return;
root@mbed.org 0:5e1631496985 211 }
root@mbed.org 0:5e1631496985 212
root@mbed.org 0:5e1631496985 213 if (timeouts->next == NULL) {
root@mbed.org 0:5e1631496985 214 timeouts->next = timeout;
root@mbed.org 0:5e1631496985 215 return;
root@mbed.org 0:5e1631496985 216 }
root@mbed.org 0:5e1631496985 217
root@mbed.org 0:5e1631496985 218 if (timeouts->next->time > msecs) {
root@mbed.org 0:5e1631496985 219 timeouts->next->time -= msecs;
root@mbed.org 0:5e1631496985 220 timeout->next = timeouts->next;
root@mbed.org 0:5e1631496985 221 timeouts->next = timeout;
root@mbed.org 0:5e1631496985 222 } else {
root@mbed.org 0:5e1631496985 223 for(t = timeouts->next; t != NULL; t = t->next) {
root@mbed.org 0:5e1631496985 224 timeout->time -= t->time;
root@mbed.org 0:5e1631496985 225 if (t->next == NULL || t->next->time > timeout->time) {
root@mbed.org 0:5e1631496985 226 if (t->next != NULL) {
root@mbed.org 0:5e1631496985 227 t->next->time -= timeout->time;
root@mbed.org 0:5e1631496985 228 }
root@mbed.org 0:5e1631496985 229 timeout->next = t->next;
root@mbed.org 0:5e1631496985 230 t->next = timeout;
root@mbed.org 0:5e1631496985 231 break;
root@mbed.org 0:5e1631496985 232 }
root@mbed.org 0:5e1631496985 233 }
root@mbed.org 0:5e1631496985 234 }
root@mbed.org 0:5e1631496985 235 }
root@mbed.org 0:5e1631496985 236
root@mbed.org 0:5e1631496985 237 /**
root@mbed.org 0:5e1631496985 238 * Go through timeout list (for this task only) and remove the first matching
root@mbed.org 0:5e1631496985 239 * entry, even though the timeout has not triggered yet.
root@mbed.org 0:5e1631496985 240 *
root@mbed.org 0:5e1631496985 241 * @note This function only works as expected if there is only one timeout
root@mbed.org 0:5e1631496985 242 * calling 'h' in the list of timeouts.
root@mbed.org 0:5e1631496985 243 *
root@mbed.org 0:5e1631496985 244 * @param h callback function that would be called by the timeout
root@mbed.org 0:5e1631496985 245 * @param arg callback argument that would be passed to h
root@mbed.org 0:5e1631496985 246 */
root@mbed.org 0:5e1631496985 247 void
root@mbed.org 0:5e1631496985 248 sys_untimeout(sys_timeout_handler h, void *arg)
root@mbed.org 0:5e1631496985 249 {
root@mbed.org 0:5e1631496985 250 struct sys_timeouts *timeouts;
root@mbed.org 0:5e1631496985 251 struct sys_timeo *prev_t, *t;
root@mbed.org 0:5e1631496985 252
root@mbed.org 0:5e1631496985 253 timeouts = sys_arch_timeouts();
root@mbed.org 0:5e1631496985 254
root@mbed.org 0:5e1631496985 255 if (timeouts == NULL) {
root@mbed.org 0:5e1631496985 256 LWIP_ASSERT("sys_untimeout: timeouts != NULL", timeouts != NULL);
root@mbed.org 0:5e1631496985 257 return;
root@mbed.org 0:5e1631496985 258 }
root@mbed.org 0:5e1631496985 259 if (timeouts->next == NULL) {
root@mbed.org 0:5e1631496985 260 return;
root@mbed.org 0:5e1631496985 261 }
root@mbed.org 0:5e1631496985 262
root@mbed.org 0:5e1631496985 263 for (t = timeouts->next, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
root@mbed.org 0:5e1631496985 264 if ((t->h == h) && (t->arg == arg)) {
root@mbed.org 0:5e1631496985 265 /* We have a match */
root@mbed.org 0:5e1631496985 266 /* Unlink from previous in list */
root@mbed.org 0:5e1631496985 267 if (prev_t == NULL)
root@mbed.org 0:5e1631496985 268 timeouts->next = t->next;
root@mbed.org 0:5e1631496985 269 else
root@mbed.org 0:5e1631496985 270 prev_t->next = t->next;
root@mbed.org 0:5e1631496985 271 /* If not the last one, add time of this one back to next */
root@mbed.org 0:5e1631496985 272 if (t->next != NULL)
root@mbed.org 0:5e1631496985 273 t->next->time += t->time;
root@mbed.org 0:5e1631496985 274 memp_free(MEMP_SYS_TIMEOUT, t);
root@mbed.org 0:5e1631496985 275 return;
root@mbed.org 0:5e1631496985 276 }
root@mbed.org 0:5e1631496985 277 }
root@mbed.org 0:5e1631496985 278 return;
root@mbed.org 0:5e1631496985 279 }
root@mbed.org 0:5e1631496985 280
root@mbed.org 0:5e1631496985 281 /**
root@mbed.org 0:5e1631496985 282 * Timeout handler function for sys_sem_wait_timeout()
root@mbed.org 0:5e1631496985 283 *
root@mbed.org 0:5e1631496985 284 * @param arg struct sswt_cb* used to signal a semaphore and end waiting.
root@mbed.org 0:5e1631496985 285 */
root@mbed.org 0:5e1631496985 286 static void
root@mbed.org 0:5e1631496985 287 sswt_handler(void *arg)
root@mbed.org 0:5e1631496985 288 {
root@mbed.org 0:5e1631496985 289 struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;
root@mbed.org 0:5e1631496985 290
root@mbed.org 0:5e1631496985 291 /* Timeout. Set flag to TRUE and signal semaphore */
root@mbed.org 0:5e1631496985 292 sswt_cb->timeflag = 1;
root@mbed.org 0:5e1631496985 293 sys_sem_signal(*(sswt_cb->psem));
root@mbed.org 0:5e1631496985 294 }
root@mbed.org 0:5e1631496985 295
root@mbed.org 0:5e1631496985 296 /**
root@mbed.org 0:5e1631496985 297 * Wait for a semaphore with timeout (specified in ms)
root@mbed.org 0:5e1631496985 298 *
root@mbed.org 0:5e1631496985 299 * @param sem semaphore to wait
root@mbed.org 0:5e1631496985 300 * @param timeout timeout in ms (0: wait forever)
root@mbed.org 0:5e1631496985 301 * @return 0 on timeout, 1 otherwise
root@mbed.org 0:5e1631496985 302 */
root@mbed.org 0:5e1631496985 303 int
root@mbed.org 0:5e1631496985 304 sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
root@mbed.org 0:5e1631496985 305 {
root@mbed.org 0:5e1631496985 306 struct sswt_cb sswt_cb;
root@mbed.org 0:5e1631496985 307
root@mbed.org 0:5e1631496985 308 sswt_cb.psem = &sem;
root@mbed.org 0:5e1631496985 309 sswt_cb.timeflag = 0;
root@mbed.org 0:5e1631496985 310
root@mbed.org 0:5e1631496985 311 /* If timeout is zero, then just wait forever */
root@mbed.org 0:5e1631496985 312 if (timeout > 0) {
root@mbed.org 0:5e1631496985 313 /* Create a timer and pass it the address of our flag */
root@mbed.org 0:5e1631496985 314 sys_timeout(timeout, sswt_handler, &sswt_cb);
root@mbed.org 0:5e1631496985 315 }
root@mbed.org 0:5e1631496985 316 sys_sem_wait(sem);
root@mbed.org 0:5e1631496985 317 /* Was it a timeout? */
root@mbed.org 0:5e1631496985 318 if (sswt_cb.timeflag) {
root@mbed.org 0:5e1631496985 319 /* timeout */
root@mbed.org 0:5e1631496985 320 return 0;
root@mbed.org 0:5e1631496985 321 } else {
root@mbed.org 0:5e1631496985 322 /* Not a timeout. Remove timeout entry */
root@mbed.org 0:5e1631496985 323 sys_untimeout(sswt_handler, &sswt_cb);
root@mbed.org 0:5e1631496985 324 return 1;
root@mbed.org 0:5e1631496985 325 }
root@mbed.org 0:5e1631496985 326 }
root@mbed.org 0:5e1631496985 327
root@mbed.org 0:5e1631496985 328 /**
root@mbed.org 0:5e1631496985 329 * Sleep for some ms. Timeouts are processed while sleeping.
root@mbed.org 0:5e1631496985 330 *
root@mbed.org 0:5e1631496985 331 * @param ms number of milliseconds to sleep
root@mbed.org 0:5e1631496985 332 */
root@mbed.org 0:5e1631496985 333 void
root@mbed.org 0:5e1631496985 334 sys_msleep(u32_t ms)
root@mbed.org 0:5e1631496985 335 {
root@mbed.org 0:5e1631496985 336 sys_sem_t delaysem = sys_sem_new(0);
root@mbed.org 0:5e1631496985 337
root@mbed.org 0:5e1631496985 338 sys_sem_wait_timeout(delaysem, ms);
root@mbed.org 0:5e1631496985 339
root@mbed.org 0:5e1631496985 340 sys_sem_free(delaysem);
root@mbed.org 0:5e1631496985 341 }
root@mbed.org 0:5e1631496985 342
root@mbed.org 0:5e1631496985 343
root@mbed.org 0:5e1631496985 344 #endif /* NO_SYS */