timer.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef _SYS_TIMER_H
  2. #define _SYS_TIMER_H
  3. /*
  4. * <MFS> Modified for Streamit
  5. * Added timer modifications from Harald Kipp, 2008/07/29 + new NutDelay implementation
  6. *
  7. * Copyright (C) 2001-2006 by egnite Software GmbH. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  26. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. *
  37. * -
  38. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  39. *
  40. * This file is distributed in the hope that it will be useful, but WITHOUT
  41. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  42. * FITNESS FOR A PARTICULAR PURPOSE.
  43. *
  44. * You can redistribute this file and/or modify it under the terms of the GNU
  45. * General Public License (GPL) as published by the Free Software Foundation;
  46. * either version 2 of the License, or (at your discretion) any later version.
  47. * See the accompanying file "copying-gpl.txt" for more details.
  48. *
  49. * As a special exception to the GPL, permission is granted for additional
  50. * uses of the text contained in this file. See the accompanying file
  51. * "copying-liquorice.txt" for details.
  52. */
  53. /*
  54. * $Log: timer.h,v $
  55. * Revision 1.11 2008/07/08 08:25:05 haraldkipp
  56. * NutDelay is no more architecture specific.
  57. * Number of loops per millisecond is configurable or will be automatically
  58. * determined.
  59. * A new function NutMicroDelay provides shorter delays.
  60. *
  61. * Revision 1.10 2006/06/28 14:36:34 haraldkipp
  62. * Event/thread/timer re-design.
  63. *
  64. * Revision 1.9 2005/07/26 16:04:02 haraldkipp
  65. * Hardware dependent timer code moved to nutlibarch.
  66. *
  67. * Revision 1.8 2005/07/12 16:36:53 freckle
  68. * made NutTimerInsert public
  69. *
  70. * Revision 1.7 2005/07/12 16:26:08 freckle
  71. * extracted timer creation from NutTimerStartTicks into NutTimerCreate
  72. *
  73. * Revision 1.6 2005/06/12 16:54:14 haraldkipp
  74. * New function processes elapsed timers.
  75. *
  76. * Revision 1.5 2005/01/19 17:59:42 freckle
  77. * Improved interrupt performance by reducing some critical section
  78. *
  79. * Revision 1.4 2004/03/16 16:48:44 haraldkipp
  80. * Added Jan Dubiec's H8/300 port.
  81. *
  82. * Revision 1.3 2003/11/03 16:35:18 haraldkipp
  83. * New API returns system uptime in miliseconds
  84. *
  85. * Revision 1.2 2003/10/13 10:17:11 haraldkipp
  86. * Seconds counter added
  87. *
  88. * Revision 1.1.1.1 2003/05/09 14:41:22 haraldkipp
  89. * Initial using 3.2.1
  90. *
  91. * Revision 1.12 2003/02/04 18:00:54 harald
  92. * Version 3 released
  93. *
  94. * Revision 1.11 2003/01/14 16:38:18 harald
  95. * New tick counter query
  96. *
  97. * Revision 1.10 2002/06/26 17:29:29 harald
  98. * First pre-release with 2.4 stack
  99. *
  100. */
  101. #include <sys/types.h>
  102. #include <arch/timer.h>
  103. /*!
  104. * \file sys/timer.h
  105. * \brief Timer management definitions.
  106. */
  107. /*!
  108. * \brief Timer type.
  109. */
  110. typedef struct _NUTTIMERINFO NUTTIMERINFO;
  111. /*!
  112. * \struct _NUTTIMERINFO timer.h sys/timer.h
  113. * \brief Timer information structure.
  114. */
  115. struct _NUTTIMERINFO {
  116. /*! \brief Link to next timer.
  117. */
  118. NUTTIMERINFO *tn_next;
  119. /*! \brief Link to previous timer.
  120. */
  121. NUTTIMERINFO *tn_prev;
  122. /*! \brief Number of system ticks.
  123. * Set to zero on one-shot timers.
  124. */
  125. u_long tn_ticks;
  126. /*! \brief Decremented by one on each system tick intervall.
  127. */
  128. u_long tn_ticks_left;
  129. /*! \brief Callback function.
  130. */
  131. void (*tn_callback)(HANDLE, void *);
  132. /*! \brief Argument pointer passed to callback function.
  133. */
  134. volatile void *tn_arg;
  135. };
  136. extern NUTTIMERINFO* nutTimerList;
  137. #define TM_ONESHOT 0x01
  138. __BEGIN_DECLS
  139. /* Prototypes */
  140. /*
  141. * Functions used by the kernel.
  142. */
  143. extern void NutTimerInit(void);
  144. extern NUTTIMERINFO * NutTimerCreate(u_long ticks, void (*callback) (HANDLE, void *), void *arg, u_char flags);
  145. extern void NutTimerInsert(NUTTIMERINFO * tn);
  146. extern void NutTimerProcessElapsed(void);
  147. /*
  148. * API declarations.
  149. */
  150. extern void NutSleep(u_long ms);
  151. extern void NutDelay(u_char ms);
  152. extern void NutMicroDelay(u_long us);
  153. extern u_long NutGetTickCount(void);
  154. extern u_long NutGetSeconds(void);
  155. extern u_long NutGetMillis(void);
  156. extern HANDLE NutTimerStart(u_long ms, void (*callback)(HANDLE, void *), void *arg, u_char flags);
  157. extern HANDLE NutTimerStartTicks(u_long ticks, void (*callback) (HANDLE, void *), void *arg, u_char flags);
  158. extern void NutTimerStop(HANDLE handle);
  159. __END_DECLS
  160. /* End of prototypes */
  161. #endif