event.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef _SYS_EVENT_H_
  2. #define _SYS_EVENT_H_
  3. /*
  4. * Copyright (C) 2001-2006 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  36. *
  37. * This file is distributed in the hope that it will be useful, but WITHOUT
  38. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  39. * FITNESS FOR A PARTICULAR PURPOSE.
  40. *
  41. * You can redistribute this file and/or modify it under the terms of the GNU
  42. * General Public License (GPL) as published by the Free Software Foundation;
  43. * either version 2 of the License, or (at your discretion) any later version.
  44. * See the accompanying file "copying-gpl.txt" for more details.
  45. *
  46. * As a special exception to the GPL, permission is granted for additional
  47. * uses of the text contained in this file. See the accompanying file
  48. * "copying-liquorice.txt" for details.
  49. */
  50. /*
  51. * $Log: event.h,v $
  52. * Revision 1.8 2006/10/08 16:48:22 haraldkipp
  53. * Documentation fixed
  54. *
  55. * Revision 1.7 2006/08/01 07:39:12 haraldkipp
  56. * Missing typecast in NutEventPostFromIrq() fixed. Thanks to Matthias Wilde.
  57. *
  58. * Revision 1.6 2006/06/28 14:34:02 haraldkipp
  59. * Event/thread/timer re-design.
  60. * A new macro NutEventPostFromIrq() replaces the routine with the same name.
  61. * In opposite to the previous routine, no result will be returned by this
  62. * macro, which may break your existing code.
  63. * The SIGNALED definition had been replaced by a less platform dependent
  64. * variant.
  65. *
  66. * Revision 1.5 2005/01/24 21:11:46 freckle
  67. * renamed NutEventPostFromIRQ into NutEventPostFromIrq
  68. *
  69. * Revision 1.4 2005/01/21 16:49:44 freckle
  70. * Seperated calls to NutEventPostAsync between Threads and IRQs
  71. *
  72. * Revision 1.3 2004/03/16 16:48:44 haraldkipp
  73. * Added Jan Dubiec's H8/300 port.
  74. *
  75. * Revision 1.2 2003/07/20 18:28:54 haraldkipp
  76. * Explain how to disable timeout.
  77. *
  78. * Revision 1.1.1.1 2003/05/09 14:41:19 haraldkipp
  79. * Initial using 3.2.1
  80. *
  81. * Revision 1.8 2003/02/04 18:00:52 harald
  82. * Version 3 released
  83. *
  84. * Revision 1.7 2003/01/14 16:37:58 harald
  85. * Return number of woken up threads
  86. *
  87. * Revision 1.6 2002/06/26 17:29:28 harald
  88. * First pre-release with 2.4 stack
  89. *
  90. */
  91. #include <sys/thread.h>
  92. /*!
  93. * \file sys/event.h
  94. * \brief Event management definitions.
  95. */
  96. /*!
  97. * \addtogroup xgEvent
  98. */
  99. /*@{*/
  100. /*!
  101. * \brief Signaled state definition.
  102. *
  103. * The root of an event queue is set to this value if an event
  104. * is posted to an empty queue. As this may happen during
  105. * interrupts, the root of an event queue must be considered
  106. * volatile.
  107. *
  108. * Timer handles in the THREADINFO structure are set to this value
  109. * if a timeout occured while waiting for an event.
  110. */
  111. #define SIGNALED ((void *)-1)
  112. /*!
  113. * \brief Infinite waiting time definition.
  114. *
  115. * Applications should use this value to disable timeout monitoring
  116. * while waiting for an event.
  117. */
  118. #define NUT_WAIT_INFINITE 0
  119. /*!
  120. * \brief Post an event to a specified queue from interrupt context.
  121. *
  122. * Wake up the thread with the highest priority waiting on the
  123. * specified queue. This function is explicitly provided for IRQ
  124. * handlers to wakeup waiting user threads.
  125. *
  126. * Internally a counter is used to keep track of the posted events.
  127. * This counter will be examined when the currently running thread is
  128. * ready to release the CPU.
  129. *
  130. * \note When calling this function, interrupt routines will change
  131. * the root of an empty event queue to SIGNALED.
  132. *
  133. * \param qp Identifies the queue an event is posted to.
  134. *
  135. */
  136. #define NutEventPostFromIrq(qp) \
  137. { \
  138. if (*qp == 0) { \
  139. *qp = SIGNALED; \
  140. } \
  141. else if (*qp != SIGNALED) { \
  142. NUTTHREADINFO *tp = (NUTTHREADINFO *)(*qp); \
  143. tp->td_qpec++; \
  144. } \
  145. }
  146. /*@}*/
  147. __BEGIN_DECLS
  148. /* Function prototypes. */
  149. extern void NutEventTimeout(HANDLE timer, void *arg);
  150. extern int NutEventWait(volatile HANDLE *qhp, u_long ms);
  151. extern int NutEventWaitNext(volatile HANDLE *qhp, u_long ms);
  152. extern int NutEventPostAsync(volatile HANDLE *qhp);
  153. extern int NutEventPost(volatile HANDLE *qhp);
  154. extern int NutEventBroadcastAsync(volatile HANDLE *qhp);
  155. extern int NutEventBroadcast(volatile HANDLE *qhp);
  156. __END_DECLS
  157. /* */
  158. #endif