Nut/OS  4.10.3
API Reference
timer.c File Reference

System timer support. More...

#include <cfg/os.h>
#include <dev/irqreg.h>
#include <sys/types.h>
#include <sys/atom.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/nutdebug.h>
#include <sys/osdebug.h>
#include <string.h>
Include dependency graph for timer.c:

Go to the source code of this file.

Defines

#define NUT_TICK_FREQ   1000UL

Functions

void NutTimerInit (void)
 Initialize system timer.
void NutMicroDelay (uint32_t us)
 Loop for a specified number of microseconds.
void NutDelay (uint8_t ms)
 Loop for a specified number of milliseconds.
void NutTimerInsert (NUTTIMERINFO *tn)
 Insert a new timer in the global timer list.
void NutTimerProcessElapsed (void)
 Process elapsed timers.
NUTTIMERINFONutTimerCreate (uint32_t ticks, void(*callback)(HANDLE, void *), void *arg, uint8_t flags)
 Create a new system timer.
HANDLE NutTimerStartTicks (uint32_t ticks, void(*callback)(HANDLE, void *), void *arg, uint8_t flags)
 Start a system timer.
HANDLE NutTimerStart (uint32_t ms, void(*callback)(HANDLE, void *), void *arg, uint8_t flags)
 Start a system timer.
void NutSleep (uint32_t ms)
 Temporarily suspends the current thread.
void NutTimerStop (HANDLE handle)
 Stop a specified timer.
uint32_t NutGetTickCount (void)
 Return the number of system timer ticks.
uint32_t NutGetSeconds (void)
 Return the seconds counter value.
uint32_t NutGetMillis (void)
 Return the milliseconds counter value.
int NutClockSet (int idx, uint32_t freq)
 Return the specified clock frequency.
uint32_t NutGetCpuClock (void)
 Return the CPU clock frequency.

Variables

NUTTIMERINFOnutTimerList
 Double linked list of all system timers.
volatile uint32_t nut_ticks
 System tick counter.
uint32_t nut_delay_loops
 Loops per microsecond.

Detailed Description

System timer support.

This kernel module contains the hardware independent system timer routines.

 *
 * $Log$
 * Revision 1.39  2009/03/05 22:16:57  freckle
 * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__
 *
 * Revision 1.38  2009/01/19 18:55:12  haraldkipp
 * Added stack checking code.
 *
 * Revision 1.37  2009/01/17 15:37:52  haraldkipp
 * Added some NUTASSERT macros to check function parameters.
 *
 * Revision 1.36  2008/08/22 09:25:35  haraldkipp
 * Clock value caching and new functions NutArchClockGet, NutClockGet and
 * NutClockSet added.
 *
 * Revision 1.35  2008/08/11 07:00:34  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.34  2008/07/29 07:28:17  haraldkipp
 * Late timer destroy, hopefully solves bug #2029411.
 *
 * Revision 1.33  2008/07/08 08:25:05  haraldkipp
 * NutDelay is no more architecture specific.
 * Number of loops per millisecond is configurable or will be automatically
 * determined.
 * A new function NutMicroDelay provides shorter delays.
 *
 * Revision 1.32  2007/05/29 16:31:25  freckle
 * corrected comment
 *
 * Revision 1.31  2006/07/26 11:16:12  haraldkipp
 * NutSleep() didn't take the difference between timer creation time and
 * last timer elapsed processing into account. This may resulted in shorter
 * sleep time. Thanks to Andras Albert for this fix.
 *
 * Revision 1.30  2006/06/28 14:42:28  haraldkipp
 * Event and timer handling re-design, again.
 * Time-out timers are now released early.
 * The timer list is now double linked to reduce removal time.
 * Internally timeout condition is now flagged by setting the timer handle
 * to SIGNALED.
 * The documentation had been updated.
 * NUTDEBUG code requires some updates. Temporarly removed.
 * LGPL copyright removed after all the initial sources had been finally
 * replaced by BSDL'ed code.
 * Variable nut_ticks_resume is used in NutTimerProcessElapsed() only. Moved
 * there.
 *
 * Revision 1.29  2006/01/26 15:34:49  going_nuts
 * adapted to new interrupt handling scheme for unix emulation
 * now uses Unix timer and runs without interrupts unless you emulate other hardware
 *
 * Revision 1.28  2005/08/03 14:43:54  freckle
 * made nut_tick public
 *
 * Revision 1.27  2005/07/26 16:01:19  haraldkipp
 * Cygwin added.
 * Platform dependent code is now located in arch/(target)/ostimer.c.
 *
 * Revision 1.26  2005/07/21 15:31:04  freckle
 * rewrote timer handling. timer interrupt handler only updates nut_ticks now
 *
 * Revision 1.25  2005/07/20 09:26:34  haraldkipp
 * Use native heap calls to avoid dependencies
 *
 * Revision 1.24  2005/07/15 14:44:46  freckle
 * corrected NutGetMillis, update comments
 *
 * Revision 1.23  2005/07/12 16:37:02  freckle
 * made NutTimerInsert public
 *
 * Revision 1.22  2005/07/12 16:26:04  freckle
 * extracted timer creation from NutTimerStartTicks into NutTimerCreate
 *
 * Revision 1.21  2005/07/12 15:23:40  olereinhardt
 * Added NULL pointer checks in NutTimerProcessElapsed(void)
 *
 * Revision 1.20  2005/07/12 15:10:43  freckle
 * removed critical section in NutSleep
 *
 * Revision 1.19  2005/07/07 12:43:49  freckle
 * removed stopped timers in NutTimerProcessElapsed
 *
 * Revision 1.18  2005/06/14 19:04:44  freckle
 * Fixed NutTimerStopAsync(): it now removes callback ptr => timer stop
 *
 * Revision 1.17  2005/06/12 16:53:01  haraldkipp
 * Major redesing to reduce interrupt latency.
 * Much better seperation of hardware dependent and independent parts.
 *
 * Revision 1.16  2005/05/27 17:30:27  drsung
 * Platform dependant files were moved to /arch directory.
 *
 * Revision 1.15  2005/02/21 12:37:57  phblum
 * Removed tabs and added semicolons after NUTTRACER macros
 *
 * Revision 1.14  2005/02/16 19:53:27  haraldkipp
 * Ready-to-run queue handling removed from interrupt context.
 *
 * Revision 1.13  2005/02/10 07:06:51  hwmaier
 * Changes to incorporate support for AT90CAN128 CPU
 *
 * Revision 1.12  2005/01/24 22:34:40  freckle
 * Added new tracer by Phlipp Blum <blum@tik.ee.ethz.ch>
 *
 * Revision 1.11  2005/01/19 17:59:43  freckle
 * Improved interrupt performance by reducing some critical section
 *
 * Revision 1.10  2005/01/13 18:51:23  haraldkipp
 * Moved ms62_5 counter to nutinit.c to make sure this is located in internal
 * RAM (AVR platforms). This fixes the wrong baudrate bug for applications
 * occupying all internal RAM.
 *
 * Optimized some timer handling.
 *
 * Revision 1.9  2005/01/02 10:07:10  haraldkipp
 * Replaced platform dependant formats in debug outputs.
 *
 * Revision 1.8  2004/09/08 10:53:25  haraldkipp
 * os/timer.c
 *
 * Revision 1.7  2004/04/07 12:13:58  haraldkipp
 * Matthias Ringwald's *nix emulation added
 *
 * Revision 1.6  2004/03/19 09:05:12  jdubiec
 * Fixed format strings declarations for AVR.
 *
 * Revision 1.5  2004/03/16 16:48:45  haraldkipp
 * Added Jan Dubiec's H8/300 port.
 *
 * Revision 1.4  2004/02/01 18:49:48  haraldkipp
 * Added CPU family support
 *
 * Revision 1.3  2003/11/03 16:34:21  haraldkipp
 * New API returns system uptime in miliseconds
 *
 * Revision 1.2  2003/10/13 10:17:11  haraldkipp
 * Seconds counter added
 *
 * Revision 1.1.1.1  2003/05/09 14:41:55  haraldkipp
 * Initial using 3.2.1
 *
 * Revision 1.24  2003/05/06 18:56:58  harald
 * Allow compilation without clock crystal
 *
 * Revision 1.23  2003/04/21 17:09:19  harald
 * *** empty log message ***
 *
 * Revision 1.22  2003/03/31 14:39:54  harald
 * *** empty log message ***
 *
 * Revision 1.21  2003/02/04 18:15:57  harald
 * Version 3 released
 *
 * Revision 1.20  2003/01/14 16:58:41  harald
 * Tick counter added.
 *
 * Revision 1.19  2002/10/29 15:37:55  harald
 * Some compilers refuse fixed crystal source
 *
 * Revision 1.18  2002/09/15 17:08:07  harald
 * *** empty log message ***
 *
 * Revision 1.17  2002/08/08 17:32:44  harald
 * Imagecraft support by Klaus Ummenhofer
 *
 * Revision 1.16  2002/06/26 17:29:45  harald
 * First pre-release with 2.4 stack
 *
 * 

Definition in file timer.c.


Define Documentation

#define NUT_TICK_FREQ   1000UL