Skip to content
Snippets Groups Projects
Commit 30d90dee authored by patacongo's avatar patacongo
Browse files

Add the framework to support POSIX timers

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@110 42af7a65-404d-4744-a932-0658087f49c3
parent 96edde22
No related branches found
No related tags found
No related merge requests found
......@@ -65,6 +65,7 @@
* Eliminate compilation warnings that that crept into
recent check-ins
* Add kill()
* Added the framework to support POSIX timers (more to be done)
* Some Documentation updates
* Added support for the Neuros OSD / DM320
This diff is collapsed.
......@@ -62,13 +62,17 @@
#define CLOCK_REALTIME 0
#define CLOCK_ABSTIME
/* This is a flag that may be passed to the timer_settime() function */
#define TIMER_ABSTIME 1
/********************************************************************************
* Global Type Declarations
********************************************************************************/
typedef uint32 time_t;
typedef ubyte clockid_t;
typedef ubyte timer_t;
typedef ubyte time_t;
typedef ubyte clockid_t;
typedef ubyte timer_t;
struct timespec
{
......@@ -135,11 +139,11 @@ EXTERN time_t mktime(struct tm *tp);
EXTERN struct tm *gmtime_r(const time_t *clock, struct tm *result);
#define localtime_r(c,r) gmtime_r(c,r)
EXTERN int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
EXTERN int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid);
EXTERN int timer_delete(timer_t timerid);
EXTERN int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
struct itimerspec *ovalue);
EXTERN int timer_gettime(timer_t timerid, struct itimerspec *value);
EXTERN int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value,
FAR struct itimerspec *ovalue);
EXTERN int timer_gettime(timer_t timerid, FAR struct itimerspec *value);
EXTERN int timer_getoverrun(timer_t timerid);
#undef EXTERN
......
......@@ -99,10 +99,13 @@ SEM_SRCS = sem_initialize.c sem_init.c sem_destroy.c\
sem_open.c sem_close.c sem_unlink.c \
sem_wait.c sem_trywait.c sem_post.c sem_getvalue.c \
sem_waitirq.c sem_findnamed.c
ifneq ($(CONFIG_DISABLE_POSIX_TIMERSA),y)
TIMERS_SRCS = timer_create.c timer_delete.c timer_getoverrun.c timer_gettime.c timer_settime.c
endif
IRQ_SRCS = irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c
CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) $(TIME_SRCS) \
$(SEM_SRCS) $(IRQ_SRCS)
$(SEM_SRCS) $(TIMER_SRCS) $(IRQ_SRCS)
ifneq ($(CONFIG_DISABLE_CLOCK),y)
CSRCS += $(CLOCK_SRCS)
endif
......
/********************************************************************************
* timer_create.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
********************************************************************************/
/********************************************************************************
* Included Files
********************************************************************************/
#include <nuttx/config.h>
#include <time.h>
#include <errno.h>
#ifdef CONFIG_POSIX_TIMERS
/********************************************************************************
* Definitions
********************************************************************************/
/********************************************************************************
* Private Data
********************************************************************************/
/********************************************************************************
* Public Data
********************************************************************************/
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
* Public Functions
********************************************************************************/
/********************************************************************************
* Function: timer_create
*
* Description:
* The timer_create() function creates per-thread timer using the specified
* clock, clock_id, as the timing base. The timer_create() function returns, in
* the location referenced by timerid, a timer ID of type timer_t used to identify
* the timer in timer requests. This timer ID is unique until the timer is
* deleted. The particular clock, clock_id, is defined in <time.h>. The timer
* whose ID is returned will be in a disarmed state upon return from
* timer_create().
*
* The evp argument, if non-NULL, points to a sigevent structure. This structure
* is allocated by the called and defines the asynchronous notification to occur.
* If the evp argument is NULL, the effect is as if the evp argument pointed to
* a sigevent structure with the sigev_notify member having the value SIGEV_SIGNAL,
* the sigev_signo having a default signal number, and the sigev_value member
* having the value of the timer ID.
*
* Each implementation defines a set of clocks that can be used as timing bases
* for per-thread timers. All implementations shall support a clock_id of
* CLOCK_REALTIME.
*
* Parameters:
* clockid - Specifies the clock to use as the timing base.
* evp - Refers to a user allocated sigevent structure that defines the
* asynchronous notification. evp may be NULL (see above).
* timerid - The pre-thread timer created by the call to timer_create().
*
* Return Value:
* If the call succeeds, timer_create() will return 0 (OK) and update the
* location referenced by timerid to a timer_t, which can be passed to the
* other per-thread timer calls. If an error occurs, the function will return
* a value of -1 (ERROR) and set errno to indicate the error.
*
* EAGAIN - The system lacks sufficient signal queuing resources to honor the
* request.
* EAGAIN - The calling process has already created all of the timers it is
* allowed by this implementation.
* EINVAL - The specified clock ID is not defined.
* ENOTSUP - The implementation does not support the creation of a timer attached
* to the CPU-time clock that is specified by clock_id and associated with a
* thread different thread invoking timer_create().
*
* Assumptions:
*
********************************************************************************/
int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid)
{
#warning "Not Implemented"
return ENOTSUP;
}
#endif /* CONFIG_POSIX_TIMERS */
/********************************************************************************
* timer_delete.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
********************************************************************************/
/********************************************************************************
* Included Files
********************************************************************************/
#include <nuttx/config.h>
#include <time.h>
#include <errno.h>
#ifndef CONFIG_DISABLE_POSIX_TIMERS
/********************************************************************************
* Definitions
********************************************************************************/
/********************************************************************************
* Private Data
********************************************************************************/
/********************************************************************************
* Public Data
********************************************************************************/
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
* Public Functions
********************************************************************************/
/********************************************************************************
* Function: timer_delete
*
* Description:
* The timer_delete() function deletes the specified timer, timerid, previously
* created by the timer_create() function. If the timer is armed when
* timer_delete() is called, the timer will be automatically disarmed before
* removal. The disposition of pending signals for the deleted timer is unspecified.
*
* Parameters:
* timerid - The pre-thread timer, previously created by the call to
* timer_create(), to be deleted.
*
* Return Value:
* If the call succeeds, timer_create() will return 0 (OK). Otherwise, the
* function will return a value of -1 (ERROR) and set errno to indicate the error.
*
* EINVAL - The timer specified timerid is not valid.
*
* Assumptions:
*
********************************************************************************/
int timer_delete(timer_t timerid)
{
#warning "Not Implemented"
return ENOTSUP;
}
#endif /* CONFIG_DISABLE_POSIX_TIMERS */
/********************************************************************************
* timer_getoverrun.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
********************************************************************************/
/********************************************************************************
* Included Files
********************************************************************************/
#include <nuttx/config.h>
#include <time.h>
#include <errno.h>
#ifndef CONFIG_DISABLE_POSIX_TIMERS
/********************************************************************************
* Definitions
********************************************************************************/
/********************************************************************************
* Private Data
********************************************************************************/
/********************************************************************************
* Public Data
********************************************************************************/
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
* Public Functions
********************************************************************************/
/********************************************************************************
* Function: timer_getoverrun
*
* Description:
* Only a single signal will be queued to the process for a given timer at any
* point in time. When a timer for which a signal is still pending expires, no
* signal will be queued, and a timer overrun will occur. When a timer
* expiration signal is delivered to or accepted by a process, if the
* implementation supports the Realtime Signals Extension, the
* timer_getoverrun() function will return the timer expiration overrun count for
* the specified timer. The overrun count returned contains the number of extra
* timer expirations that occurred between the time the signal was generated
* (queued) and when it was delivered or accepted, up to but not including an
* implementation-defined maximum of DELAYTIMER_MAX. If the number of such
* extra expirations is greater than or equal to DELAYTIMER_MAX, then the
* overrun count will be set to DELAYTIMER_MAX. The value returned by
* timer_getoverrun() will apply to the most recent expiration signal delivery
* or acceptance for the timer. If no expiration signal has been delivered
* for the timer, or if the Realtime Signals Extension is not supported, the
* return value of timer_getoverrun() is unspecified.
*
* Parameters:
* timerid - The pre-thread timer, previously created by the call to
* timer_create(), whose overrun count will be returned..
*
* Return Value:
* If the timer_getoverrun() function succeeds, it will return the timer
* expiration overrun count as explained above. timer_getoverrun() will fail if:
*
* EINVAL - The timerid argument does not correspond to an ID returned by
* timer_create() but not yet deleted by timer_delete().
*
* Assumptions:
*
********************************************************************************/
int timer_getoverrun(timer_t timerid)
{
#warning "Not Implemented"
return ENOTSUP;
}
#endif /* CONFIG_DISABLE_POSIX_TIMERS */
/********************************************************************************
* timer_gettime.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
********************************************************************************/
/********************************************************************************
* Included Files
********************************************************************************/
#include <nuttx/config.h>
#include <time.h>
#include <errno.h>
#ifndef CONFIG_DISABLE_POSIX_TIMERS
/********************************************************************************
* Definitions
********************************************************************************/
/********************************************************************************
* Private Data
********************************************************************************/
/********************************************************************************
* Public Data
********************************************************************************/
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
* Public Functions
********************************************************************************/
/********************************************************************************
* Function: timer_gettime
*
* Description:
* The timer_gettime() function will store the amount of time until the
* specified timer, timerid, expires and the reload value of the timer into the
* space pointed to by the value argument. The it_value member of this structure
* will contain the amount of time before the timer expires, or zero if the timer
* is disarmed. This value is returned as the interval until timer expiration,
* even if the timer was armed with absolute time. The it_interval member of
* value will contain the reload value last set by timer_settime().
*
* Parameters:
* timerid - The pre-thread timer, previously created by the call to
* timer_create(), whose remaining time count will be returned..
*
* Return Value:
* If the timer_gettime() succeeds, a value of 0 (OK) will be returned.
* If an error occurs, the value -1 (ERROR) will be returned, and errno set to
* indicate the error.
*
* EINVAL - The timerid argument does not correspond to an ID returned by
* timer_create() but not yet deleted by timer_delete().
*
* Assumptions:
*
********************************************************************************/
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
{
#warning "Not Implemented"
return ENOTSUP;
}
#endif /* CONFIG_DISABLE_POSIX_TIMERS */
/********************************************************************************
* timer_settime.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
********************************************************************************/
/********************************************************************************
* Included Files
********************************************************************************/
#include <nuttx/config.h>
#include <time.h>
#include <errno.h>
#ifndef CONFIG_DISABLE_POSIX_TIMERS
/********************************************************************************
* Definitions
********************************************************************************/
/********************************************************************************
* Private Data
********************************************************************************/
/********************************************************************************
* Public Data
********************************************************************************/
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
* Public Functions
********************************************************************************/
/********************************************************************************
* Function: timer_settime
*
* Description:
* The timer_settime() function sets the time until the next expiration of the
* timer specified by timerid from the it_value member of the value argument
* and arm the timer if the it_value member of value is non-zero. If the
* specified timer was already armed when timer_settime() is called, this call
* will reset the time until next expiration to the value specified. If the
* it_value member of value is zero, the timer will be disarmed. The effect
* of disarming or resetting a timer with pending expiration notifications is
* unspecified.
*
* If the flag TIMER_ABSTIME is not set in the argument flags, timer_settime()
* will behave as if the time until next expiration is set to be equal to the
* interval specified by the it_value member of value. That is, the timer will
* expire in it_value nanoseconds from when the call is made. If the flag
* TIMER_ABSTIME is set in the argument flags, timer_settime() will behave as
* if the time until next expiration is set to be equal to the difference between
* the absolute time specified by the it_value member of value and the current
* value of the clock associated with timerid. That is, the timer will expire
* when the clock reaches the value specified by the it_value member of value.
* If the specified time has already passed, the function will succeed and the
* expiration notification will be made.
*
* The reload value of the timer will be set to the value specified by the
* it_interval member of value. When a timer is armed with a non-zero
* it_interval, a periodic (or repetitive) timer is specified.
*
* Time values that are between two consecutive non-negative integer multiples
* of the resolution of the specified timer will be rounded up to the larger
* multiple of the resolution. Quantization error will not cause the timer to
* expire earlier than the rounded time value.
*
* If the argument ovalue is not NULL, the timer_settime() function will store,
* in the location referenced by ovalue, a value representing the previous
* amount of time before the timer would have expired, or zero if the timer was
* disarmed, together with the previous timer reload value. Timers will not
* expire before their scheduled time.
*
* Parameters:
* timerid - The pre-thread timer, previously created by the call to
* timer_create(), to be be set.
* flags - Specifie characteristics of the timer (see above)
* value - Specifies the timer value to set
* ovalue - A location in which to return the time remaining from the previous
* timer setting.
*
* Return Value:
* If the timer_settime() succeeds, a value of 0 (OK) will be returned.
* If an error occurs, the value -1 (ERROR) will be returned, and errno set to
* indicate the error.
*
* EINVAL - The timerid argument does not correspond to an ID returned by
* timer_create() but not yet deleted by timer_delete().
* EINVAL - A value structure specified a nanosecond value less than zero or
* greater than or equal to 1000 million, and the it_value member of that
* structure did not specify zero seconds and nanoseconds.
*
* Assumptions:
*
********************************************************************************/
int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value,
FAR struct itimerspec *ovalue)
{
#warning "Not Implemented"
return ENOTSUP;
}
#endif /* CONFIG_DISABLE_POSIX_TIMERS */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment