Separated timer implementation from semaphore/mbox implementation, moved timer implementation to timers.c/.h (TASK#7235)

This commit is contained in:
goldsimon
2009-12-31 16:16:44 +00:00
parent 1740b0d421
commit a566f9d8f2
10 changed files with 556 additions and 519 deletions

View File

@@ -66,9 +66,7 @@ LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_en
LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP")
#endif /* LWIP_IGMP */
#if NO_SYS==0
LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT")
#endif /* NO_SYS==0 */
/*

View File

@@ -44,12 +44,8 @@ extern "C" {
definitions of the sys_ functions. */
typedef u8_t sys_sem_t;
typedef u8_t sys_mbox_t;
struct sys_timeo {u8_t dummy;};
#define sys_init()
#define sys_timeout(m,h,a)
#define sys_untimeout(m,a)
#define sys_sem_new(c) c
#define sys_sem_new(c) ((sys_sem_t)c)
#define sys_sem_signal(s)
#define sys_sem_wait(s)
#define sys_sem_wait_timeout(s,t)
@@ -64,6 +60,8 @@ struct sys_timeo {u8_t dummy;};
#define sys_thread_new(n,t,a,s,p)
#define sys_msleep(t)
#else /* NO_SYS */
/** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */
@@ -77,50 +75,19 @@ struct sys_timeo {u8_t dummy;};
#include "lwip/err.h"
#include "arch/sys_arch.h"
typedef void (* sys_timeout_handler)(void *arg);
struct sys_timeo {
struct sys_timeo *next;
u32_t time;
sys_timeout_handler h;
void *arg;
};
struct sys_timeouts {
struct sys_timeo *next;
};
/* sys_init() must be called before anthing else. */
void sys_init(void);
/*
* sys_timeout():
*
* Schedule a timeout a specified amount of milliseconds in the
* future. When the timeout occurs, the specified timeout handler will
* be called. The handler will be passed the "arg" argument when
* called.
*
*/
void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
void sys_untimeout(sys_timeout_handler h, void *arg);
struct sys_timeouts *sys_arch_timeouts(void);
/* Semaphore functions. */
sys_sem_t sys_sem_new(u8_t count);
void sys_sem_signal(sys_sem_t sem);
/** Wait for a semaphore for the specified timeout: 0=wait forever */
u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);
void sys_sem_free(sys_sem_t sem);
void sys_sem_wait(sys_sem_t sem);
int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout);
#define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
#define sys_sem_wait_timeout(sem, timeout) sys_arch_sem_wait(sem, timeout)
/* Time functions. */
#ifndef sys_msleep
void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
#endif
#ifndef sys_jiffies
u32_t sys_jiffies(void); /* since power up. */
#endif
/* Mailbox functions. */
sys_mbox_t sys_mbox_new(int size);
@@ -133,13 +100,20 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);
/* For now, we map straight to sys_arch implementation. */
#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
void sys_mbox_free(sys_mbox_t mbox);
void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
#define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
/* Thread functions. */
sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio);
#endif /* NO_SYS */
/* sys_init() must be called before anthing else. */
void sys_init(void);
#ifndef sys_jiffies
u32_t sys_jiffies(void); /* since power up. */
#endif
/** Returns the current time in milliseconds. */
u32_t sys_now(void);

View File

@@ -41,6 +41,7 @@
#include "lwip/pbuf.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "lwip/netif.h"
#ifdef __cplusplus

68
src/include/lwip/timers.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
* Simon Goldschmidt
*
*/
#ifndef __LWIP_TIMERS_H__
#define __LWIP_TIMERS_H__
#include "lwip/opt.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void (* sys_timeout_handler)(void *arg);
struct sys_timeo {
struct sys_timeo *next;
u32_t time;
sys_timeout_handler h;
void *arg;
};
void sys_timeouts_init(void);
void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
void sys_untimeout(sys_timeout_handler h, void *arg);
#if NO_SYS
void sys_check_timeouts(void);
#else /* NO_SYS */
void sys_timeouts_mbox_fetch(sys_mbox_t mbox, void **msg);
#endif /* NO_SYS */
#ifdef __cplusplus
}
#endif
#endif /* __LWIP_TIMERS_H__ */