]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp/lib/os/7.0.2_tms570/include/os/StackMacros.h
Yet another place to fix
[rpp-test-sw.git] / rpp / lib / os / 7.0.2_tms570 / include / os / StackMacros.h
1 /*
2     FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
3
4
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
24
25     This file is part of the FreeRTOS distribution.
26
27     FreeRTOS is free software; you can redistribute it and/or modify it under
28     the terms of the GNU General Public License (version 2) as published by the
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30     >>>NOTE<<< The modification to the GPL is included to allow you to
31     distribute a combined work that includes FreeRTOS without being obliged to
32     provide the source code for proprietary components outside of the FreeRTOS
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36     more details. You should have received a copy of the GNU General Public
37     License and the FreeRTOS license exception along with FreeRTOS; if not it
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained
39     by writing to Richard Barry, contact details for whom are available on the
40     FreeRTOS WEB site.
41
42     1 tab == 4 spaces!
43
44     http://www.FreeRTOS.org - Documentation, latest information, license and
45     contact details.
46
47     http://www.SafeRTOS.com - A version that is certified for use in safety
48     critical systems.
49
50     http://www.OpenRTOS.com - Commercial support, development, porting,
51     licensing and training services.
52 */
53
54 #ifndef STACK_MACROS_H
55 #define STACK_MACROS_H
56
57 /*
58  * Call the stack overflow hook function if the stack of the task being swapped
59  * out is currently overflowed, or looks like it might have overflowed in the
60  * past.
61  *
62  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
63  * the current stack state only - comparing the current top of stack value to
64  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
65  * will also cause the last few stack bytes to be checked to ensure the value
66  * to which the bytes were set when the task was created have not been
67  * overwritten.  Note this second test does not guarantee that an overflowed
68  * stack will always be recognised.
69  */
70
71 /*-----------------------------------------------------------*/
72
73 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
74
75     /* FreeRTOSConfig.h is not set to check for stack overflows. */
76     #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
77     #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
78
79 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
80 /*-----------------------------------------------------------*/
81
82 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
83
84     /* FreeRTOSConfig.h is only set to use the first method of
85     overflow checking. */
86     #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
87
88 #endif
89 /*-----------------------------------------------------------*/
90
91 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
92
93     /* Only the current stack state is to be checked. */
94     #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                        \
95     {                                                                                                   \
96         /* Is the currently saved stack pointer within the stack limit? */                              \
97         if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                       \
98         {                                                                                               \
99             vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );    \
100         }                                                                                               \
101     }
102
103 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */
104 /*-----------------------------------------------------------*/
105
106 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
107
108     /* Only the current stack state is to be checked. */
109     #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                        \
110     {                                                                                                   \
111                                                                                                         \
112         /* Is the currently saved stack pointer within the stack limit? */                              \
113         if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                  \
114         {                                                                                               \
115             vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );    \
116         }                                                                                               \
117     }
118
119 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
120 /*-----------------------------------------------------------*/
121
122 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
123
124     #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                               \
125     {                                                                                                                                           \
126     static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
127                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
128                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
129                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
130                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };   \
131                                                                                                                                                 \
132                                                                                                                                                 \
133         /* Has the extremity of the task stack ever been written over? */                                                                       \
134         if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                  \
135         {                                                                                                                                       \
136             vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                            \
137         }                                                                                                                                       \
138     }
139
140 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
141 /*-----------------------------------------------------------*/
142
143 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
144
145     #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                               \
146     {                                                                                                                                           \
147     char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack;                                                                                 \
148     static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
149                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
150                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
151                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,     \
152                                                             tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };   \
153                                                                                                                                                 \
154                                                                                                                                                 \
155         pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                         \
156                                                                                                                                                 \
157         /* Has the extremity of the task stack ever been written over? */                                                                       \
158         if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                           \
159         {                                                                                                                                       \
160             vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                            \
161         }                                                                                                                                       \
162     }
163
164 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
165 /*-----------------------------------------------------------*/
166
167 #endif /* STACK_MACROS_H */
168