task.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef INC_TASK_H
  29. #define INC_TASK_H
  30. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h must appear in source files before include task.h"
  32. #endif
  33. /* *INDENT-OFF* */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* *INDENT-ON* */
  38. /*-----------------------------------------------------------
  39. * MACROS AND DEFINITIONS
  40. *----------------------------------------------------------*/
  41. /*
  42. * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development
  43. * after the numbered release.
  44. *
  45. * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD
  46. * values will reflect the last released version number.
  47. */
  48. #define tskKERNEL_VERSION_NUMBER "V10.4.6"
  49. #define tskKERNEL_VERSION_MAJOR 10
  50. #define tskKERNEL_VERSION_MINOR 4
  51. #define tskKERNEL_VERSION_BUILD 6
  52. /**
  53. * task. h
  54. *
  55. * Macro to mark the start of a critical code region. Preemptive context
  56. * switches cannot occur when in a critical region.
  57. *
  58. * NOTE: This may alter the stack (depending on the portable implementation)
  59. * so must be used with care!
  60. *
  61. * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  62. * \ingroup SchedulerControl
  63. */
  64. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  65. #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  66. /**
  67. * task. h
  68. *
  69. * Macro to mark the end of a critical code region. Preemptive context
  70. * switches cannot occur when in a critical region.
  71. *
  72. * NOTE: This may alter the stack (depending on the portable implementation)
  73. * so must be used with care!
  74. *
  75. * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  76. * \ingroup SchedulerControl
  77. */
  78. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  79. #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  80. /**
  81. * task. h
  82. *
  83. * Macro to disable all maskable interrupts.
  84. *
  85. * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  86. * \ingroup SchedulerControl
  87. */
  88. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  89. /**
  90. * task. h
  91. *
  92. * Macro to enable microcontroller interrupts.
  93. *
  94. * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  95. * \ingroup SchedulerControl
  96. */
  97. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  98. /*-----------------------------------------------------------
  99. * SCHEDULER CONTROL
  100. *----------------------------------------------------------*/
  101. /**
  102. * task. h
  103. * @code{c}
  104. * void vTaskSuspendAll( void );
  105. * @endcode
  106. *
  107. * Suspends the scheduler without disabling interrupts. Context switches will
  108. * not occur while the scheduler is suspended.
  109. *
  110. * After calling vTaskSuspendAll () the calling task will continue to execute
  111. * without risk of being swapped out until a call to xTaskResumeAll () has been
  112. * made.
  113. *
  114. * API functions that have the potential to cause a context switch (for example,
  115. * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  116. * is suspended.
  117. *
  118. * Example usage:
  119. * @code{c}
  120. * void vTask1( void * pvParameters )
  121. * {
  122. * for( ;; )
  123. * {
  124. * // Task code goes here.
  125. *
  126. * // ...
  127. *
  128. * // At some point the task wants to perform a long operation during
  129. * // which it does not want to get swapped out. It cannot use
  130. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  131. * // operation may cause interrupts to be missed - including the
  132. * // ticks.
  133. *
  134. * // Prevent the real time kernel swapping out the task.
  135. * vTaskSuspendAll ();
  136. *
  137. * // Perform the operation here. There is no need to use critical
  138. * // sections as we have all the microcontroller processing time.
  139. * // During this time interrupts will still operate and the kernel
  140. * // tick count will be maintained.
  141. *
  142. * // ...
  143. *
  144. * // The operation is complete. Restart the kernel.
  145. * xTaskResumeAll ();
  146. * }
  147. * }
  148. * @endcode
  149. * \defgroup vTaskSuspendAll vTaskSuspendAll
  150. * \ingroup SchedulerControl
  151. */
  152. void vTaskSuspendAll( void );
  153. /**
  154. * task. h
  155. * @code{c}
  156. * BaseType_t xTaskResumeAll( void );
  157. * @endcode
  158. *
  159. * Resumes scheduler activity after it was suspended by a call to
  160. * vTaskSuspendAll().
  161. *
  162. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  163. * that were previously suspended by a call to vTaskSuspend().
  164. *
  165. * @return If resuming the scheduler caused a context switch then pdTRUE is
  166. * returned, otherwise pdFALSE is returned.
  167. *
  168. * Example usage:
  169. * @code{c}
  170. * void vTask1( void * pvParameters )
  171. * {
  172. * for( ;; )
  173. * {
  174. * // Task code goes here.
  175. *
  176. * // ...
  177. *
  178. * // At some point the task wants to perform a long operation during
  179. * // which it does not want to get swapped out. It cannot use
  180. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  181. * // operation may cause interrupts to be missed - including the
  182. * // ticks.
  183. *
  184. * // Prevent the real time kernel swapping out the task.
  185. * vTaskSuspendAll ();
  186. *
  187. * // Perform the operation here. There is no need to use critical
  188. * // sections as we have all the microcontroller processing time.
  189. * // During this time interrupts will still operate and the real
  190. * // time kernel tick count will be maintained.
  191. *
  192. * // ...
  193. *
  194. * // The operation is complete. Restart the kernel. We want to force
  195. * // a context switch - but there is no point if resuming the scheduler
  196. * // caused a context switch already.
  197. * if( !xTaskResumeAll () )
  198. * {
  199. * taskYIELD ();
  200. * }
  201. * }
  202. * }
  203. * @endcode
  204. * \defgroup xTaskResumeAll xTaskResumeAll
  205. * \ingroup SchedulerControl
  206. */
  207. BaseType_t xTaskResumeAll( void );
  208. /* *INDENT-OFF* */
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. /* *INDENT-ON* */
  213. #endif /* INC_TASK_H */