event.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 THE COPYRIGHT HOLDERS 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 THE
  23. * COPYRIGHT OWNER 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$
  52. * Revision 1.9 2008/08/11 07:00:25 haraldkipp
  53. * BSD types replaced by stdint types (feature request #1282721).
  54. *
  55. * Revision 1.8 2006/10/08 16:48:22 haraldkipp
  56. * Documentation fixed
  57. *
  58. * Revision 1.7 2006/08/01 07:39:12 haraldkipp
  59. * Missing typecast in NutEventPostFromIrq() fixed. Thanks to Matthias Wilde.
  60. *
  61. * Revision 1.6 2006/06/28 14:34:02 haraldkipp
  62. * Event/thread/timer re-design.
  63. * A new macro NutEventPostFromIrq() replaces the routine with the same name.
  64. * In opposite to the previous routine, no result will be returned by this
  65. * macro, which may break your existing code.
  66. * The SIGNALED definition had been replaced by a less platform dependent
  67. * variant.
  68. *
  69. * Revision 1.5 2005/01/24 21:11:46 freckle
  70. * renamed NutEventPostFromIRQ into NutEventPostFromIrq
  71. *
  72. * Revision 1.4 2005/01/21 16:49:44 freckle
  73. * Seperated calls to NutEventPostAsync between Threads and IRQs
  74. *
  75. * Revision 1.3 2004/03/16 16:48:44 haraldkipp
  76. * Added Jan Dubiec's H8/300 port.
  77. *
  78. * Revision 1.2 2003/07/20 18:28:54 haraldkipp
  79. * Explain how to disable timeout.
  80. *
  81. * Revision 1.1.1.1 2003/05/09 14:41:19 haraldkipp
  82. * Initial using 3.2.1
  83. *
  84. * Revision 1.8 2003/02/04 18:00:52 harald
  85. * Version 3 released
  86. *
  87. * Revision 1.7 2003/01/14 16:37:58 harald
  88. * Return number of woken up threads
  89. *
  90. * Revision 1.6 2002/06/26 17:29:28 harald
  91. * First pre-release with 2.4 stack
  92. *
  93. */
  94. #include <sys/thread.h>
  95. /*!
  96. * \file sys/event.h
  97. * \brief Event management definitions.
  98. */
  99. /*!
  100. * \addtogroup xgEvent
  101. */
  102. /*@{*/
  103. /*!
  104. * \brief Signaled state definition.
  105. *
  106. * The root of an event queue is set to this value if an event
  107. * is posted to an empty queue. As this may happen during
  108. * interrupts, the root of an event queue must be considered
  109. * volatile.
  110. *
  111. * Timer handles in the THREADINFO structure are set to this value
  112. * if a timeout occured while waiting for an event.
  113. */
  114. #define SIGNALED ((void *)-1)
  115. /*!
  116. * \brief Infinite waiting time definition.
  117. *
  118. * Applications should use this value to disable timeout monitoring
  119. * while waiting for an event.
  120. */
  121. #define NUT_WAIT_INFINITE 0
  122. /*!
  123. * \brief Post an event to a specified queue from interrupt context.
  124. *
  125. * Wake up the thread with the highest priority waiting on the
  126. * specified queue. This function is explicitly provided for IRQ
  127. * handlers to wakeup waiting user threads.
  128. *
  129. * Internally a counter is used to keep track of the posted events.
  130. * This counter will be examined when the currently running thread is
  131. * ready to release the CPU.
  132. *
  133. * \note When calling this function, interrupt routines will change
  134. * the root of an empty event queue to SIGNALED.
  135. *
  136. * \param qp Identifies the queue an event is posted to.
  137. *
  138. */
  139. #define NutEventPostFromIrq(qp) \
  140. { \
  141. if (*qp == 0) { \
  142. *qp = SIGNALED; \
  143. } \
  144. else if (*qp != SIGNALED) { \
  145. NUTTHREADINFO *tp = (NUTTHREADINFO *)(*qp); \
  146. tp->td_qpec++; \
  147. } \
  148. }
  149. /*@}*/
  150. extern void NutEventTimeout(HANDLE timer, void *arg);
  151. extern int NutEventWait(volatile HANDLE *qhp, uint32_t ms);
  152. extern int NutEventWaitNext(volatile HANDLE *qhp, uint32_t ms);
  153. extern int NutEventPostAsync(volatile HANDLE *qhp);
  154. extern int NutEventPost(volatile HANDLE *qhp);
  155. extern int NutEventBroadcastAsync(volatile HANDLE *qhp);
  156. extern int NutEventBroadcast(volatile HANDLE *qhp);
  157. #endif