StackMacros.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
  3. FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
  4. http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  5. ***************************************************************************
  6. * *
  7. * FreeRTOS tutorial books are available in pdf and paperback. *
  8. * Complete, revised, and edited pdf reference manuals are also *
  9. * available. *
  10. * *
  11. * Purchasing FreeRTOS documentation will not only help you, by *
  12. * ensuring you get running as quickly as possible and with an *
  13. * in-depth knowledge of how to use FreeRTOS, it will also help *
  14. * the FreeRTOS project to continue with its mission of providing *
  15. * professional grade, cross platform, de facto standard solutions *
  16. * for microcontrollers - completely free of charge! *
  17. * *
  18. * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
  19. * *
  20. * Thank you for using FreeRTOS, and thank you for your support! *
  21. * *
  22. ***************************************************************************
  23. This file is part of the FreeRTOS distribution.
  24. FreeRTOS is free software; you can redistribute it and/or modify it under
  25. the terms of the GNU General Public License (version 2) as published by the
  26. Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  27. >>>NOTE<<< The modification to the GPL is included to allow you to
  28. distribute a combined work that includes FreeRTOS without being obliged to
  29. provide the source code for proprietary components outside of the FreeRTOS
  30. kernel. FreeRTOS is distributed in the hope that it will be useful, but
  31. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  32. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  33. more details. You should have received a copy of the GNU General Public
  34. License and the FreeRTOS license exception along with FreeRTOS; if not it
  35. can be viewed here: http://www.freertos.org/a00114.html and also obtained
  36. by writing to Richard Barry, contact details for whom are available on the
  37. FreeRTOS WEB site.
  38. 1 tab == 4 spaces!
  39. ***************************************************************************
  40. * *
  41. * Having a problem? Start by reading the FAQ "My application does *
  42. * not run, what could be wrong?" *
  43. * *
  44. * http://www.FreeRTOS.org/FAQHelp.html *
  45. * *
  46. ***************************************************************************
  47. http://www.FreeRTOS.org - Documentation, training, latest versions, license
  48. and contact details.
  49. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  50. including FreeRTOS+Trace - an indispensable productivity tool.
  51. Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
  52. the code with commercial support, indemnification, and middleware, under
  53. the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
  54. provide a safety engineered and independently SIL3 certified version under
  55. the SafeRTOS brand: http://www.SafeRTOS.com.
  56. */
  57. #ifndef STACK_MACROS_H
  58. #define STACK_MACROS_H
  59. /*
  60. * Call the stack overflow hook function if the stack of the task being swapped
  61. * out is currently overflowed, or looks like it might have overflowed in the
  62. * past.
  63. *
  64. * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
  65. * the current stack state only - comparing the current top of stack value to
  66. * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
  67. * will also cause the last few stack bytes to be checked to ensure the value
  68. * to which the bytes were set when the task was created have not been
  69. * overwritten. Note this second test does not guarantee that an overflowed
  70. * stack will always be recognised.
  71. */
  72. /*-----------------------------------------------------------*/
  73. #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
  74. /* FreeRTOSConfig.h is not set to check for stack overflows. */
  75. #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
  76. #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
  77. #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
  78. /*-----------------------------------------------------------*/
  79. #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
  80. /* FreeRTOSConfig.h is only set to use the first method of
  81. overflow checking. */
  82. #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
  83. #endif
  84. /*-----------------------------------------------------------*/
  85. #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
  86. /* Only the current stack state is to be checked. */
  87. #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
  88. { \
  89. /* Is the currently saved stack pointer within the stack limit? */ \
  90. if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
  91. { \
  92. vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
  93. } \
  94. }
  95. #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */
  96. /*-----------------------------------------------------------*/
  97. #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
  98. /* Only the current stack state is to be checked. */
  99. #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
  100. { \
  101. \
  102. /* Is the currently saved stack pointer within the stack limit? */ \
  103. if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
  104. { \
  105. vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
  106. } \
  107. }
  108. #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
  109. /*-----------------------------------------------------------*/
  110. #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
  111. #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
  112. { \
  113. static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  114. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  115. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  116. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  117. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
  118. \
  119. \
  120. /* Has the extremity of the task stack ever been written over? */ \
  121. if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
  122. { \
  123. vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
  124. } \
  125. }
  126. #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
  127. /*-----------------------------------------------------------*/
  128. #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
  129. #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
  130. { \
  131. char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \
  132. static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  133. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  134. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  135. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
  136. tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
  137. \
  138. \
  139. pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
  140. \
  141. /* Has the extremity of the task stack ever been written over? */ \
  142. if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
  143. { \
  144. vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
  145. } \
  146. }
  147. #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
  148. /*-----------------------------------------------------------*/
  149. #endif /* STACK_MACROS_H */