www.freertos.org
Dependents: Nucleo freertos_test FreeRTOS_test freertos_bluetooth ... more
Source/include/StackMacros.h@0:8e57f3e9cc89, 2014-01-24 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jan 24 14:56:04 2014 +0000
- Revision:
- 0:8e57f3e9cc89
Making FreeRTOS available as a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:8e57f3e9cc89 | 1 | /* |
rgrover1 | 0:8e57f3e9cc89 | 2 | FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. |
rgrover1 | 0:8e57f3e9cc89 | 3 | All rights reserved |
rgrover1 | 0:8e57f3e9cc89 | 4 | |
rgrover1 | 0:8e57f3e9cc89 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. |
rgrover1 | 0:8e57f3e9cc89 | 6 | |
rgrover1 | 0:8e57f3e9cc89 | 7 | *************************************************************************** |
rgrover1 | 0:8e57f3e9cc89 | 8 | * * |
rgrover1 | 0:8e57f3e9cc89 | 9 | * FreeRTOS provides completely free yet professionally developed, * |
rgrover1 | 0:8e57f3e9cc89 | 10 | * robust, strictly quality controlled, supported, and cross * |
rgrover1 | 0:8e57f3e9cc89 | 11 | * platform software that has become a de facto standard. * |
rgrover1 | 0:8e57f3e9cc89 | 12 | * * |
rgrover1 | 0:8e57f3e9cc89 | 13 | * Help yourself get started quickly and support the FreeRTOS * |
rgrover1 | 0:8e57f3e9cc89 | 14 | * project by purchasing a FreeRTOS tutorial book, reference * |
rgrover1 | 0:8e57f3e9cc89 | 15 | * manual, or both from: http://www.FreeRTOS.org/Documentation * |
rgrover1 | 0:8e57f3e9cc89 | 16 | * * |
rgrover1 | 0:8e57f3e9cc89 | 17 | * Thank you! * |
rgrover1 | 0:8e57f3e9cc89 | 18 | * * |
rgrover1 | 0:8e57f3e9cc89 | 19 | *************************************************************************** |
rgrover1 | 0:8e57f3e9cc89 | 20 | |
rgrover1 | 0:8e57f3e9cc89 | 21 | This file is part of the FreeRTOS distribution. |
rgrover1 | 0:8e57f3e9cc89 | 22 | |
rgrover1 | 0:8e57f3e9cc89 | 23 | FreeRTOS is free software; you can redistribute it and/or modify it under |
rgrover1 | 0:8e57f3e9cc89 | 24 | the terms of the GNU General Public License (version 2) as published by the |
rgrover1 | 0:8e57f3e9cc89 | 25 | Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. |
rgrover1 | 0:8e57f3e9cc89 | 26 | |
rgrover1 | 0:8e57f3e9cc89 | 27 | >>! NOTE: The modification to the GPL is included to allow you to distribute |
rgrover1 | 0:8e57f3e9cc89 | 28 | >>! a combined work that includes FreeRTOS without being obliged to provide |
rgrover1 | 0:8e57f3e9cc89 | 29 | >>! the source code for proprietary components outside of the FreeRTOS |
rgrover1 | 0:8e57f3e9cc89 | 30 | >>! kernel. |
rgrover1 | 0:8e57f3e9cc89 | 31 | |
rgrover1 | 0:8e57f3e9cc89 | 32 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY |
rgrover1 | 0:8e57f3e9cc89 | 33 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
rgrover1 | 0:8e57f3e9cc89 | 34 | FOR A PARTICULAR PURPOSE. Full license text is available from the following |
rgrover1 | 0:8e57f3e9cc89 | 35 | link: http://www.freertos.org/a00114.html |
rgrover1 | 0:8e57f3e9cc89 | 36 | |
rgrover1 | 0:8e57f3e9cc89 | 37 | 1 tab == 4 spaces! |
rgrover1 | 0:8e57f3e9cc89 | 38 | |
rgrover1 | 0:8e57f3e9cc89 | 39 | *************************************************************************** |
rgrover1 | 0:8e57f3e9cc89 | 40 | * * |
rgrover1 | 0:8e57f3e9cc89 | 41 | * Having a problem? Start by reading the FAQ "My application does * |
rgrover1 | 0:8e57f3e9cc89 | 42 | * not run, what could be wrong?" * |
rgrover1 | 0:8e57f3e9cc89 | 43 | * * |
rgrover1 | 0:8e57f3e9cc89 | 44 | * http://www.FreeRTOS.org/FAQHelp.html * |
rgrover1 | 0:8e57f3e9cc89 | 45 | * * |
rgrover1 | 0:8e57f3e9cc89 | 46 | *************************************************************************** |
rgrover1 | 0:8e57f3e9cc89 | 47 | |
rgrover1 | 0:8e57f3e9cc89 | 48 | http://www.FreeRTOS.org - Documentation, books, training, latest versions, |
rgrover1 | 0:8e57f3e9cc89 | 49 | license and Real Time Engineers Ltd. contact details. |
rgrover1 | 0:8e57f3e9cc89 | 50 | |
rgrover1 | 0:8e57f3e9cc89 | 51 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, |
rgrover1 | 0:8e57f3e9cc89 | 52 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS |
rgrover1 | 0:8e57f3e9cc89 | 53 | compatible FAT file system, and our tiny thread aware UDP/IP stack. |
rgrover1 | 0:8e57f3e9cc89 | 54 | |
rgrover1 | 0:8e57f3e9cc89 | 55 | http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High |
rgrover1 | 0:8e57f3e9cc89 | 56 | Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS |
rgrover1 | 0:8e57f3e9cc89 | 57 | licenses offer ticketed support, indemnification and middleware. |
rgrover1 | 0:8e57f3e9cc89 | 58 | |
rgrover1 | 0:8e57f3e9cc89 | 59 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety |
rgrover1 | 0:8e57f3e9cc89 | 60 | engineered and independently SIL3 certified version for use in safety and |
rgrover1 | 0:8e57f3e9cc89 | 61 | mission critical applications that require provable dependability. |
rgrover1 | 0:8e57f3e9cc89 | 62 | |
rgrover1 | 0:8e57f3e9cc89 | 63 | 1 tab == 4 spaces! |
rgrover1 | 0:8e57f3e9cc89 | 64 | */ |
rgrover1 | 0:8e57f3e9cc89 | 65 | |
rgrover1 | 0:8e57f3e9cc89 | 66 | #ifndef STACK_MACROS_H |
rgrover1 | 0:8e57f3e9cc89 | 67 | #define STACK_MACROS_H |
rgrover1 | 0:8e57f3e9cc89 | 68 | |
rgrover1 | 0:8e57f3e9cc89 | 69 | /* |
rgrover1 | 0:8e57f3e9cc89 | 70 | * Call the stack overflow hook function if the stack of the task being swapped |
rgrover1 | 0:8e57f3e9cc89 | 71 | * out is currently overflowed, or looks like it might have overflowed in the |
rgrover1 | 0:8e57f3e9cc89 | 72 | * past. |
rgrover1 | 0:8e57f3e9cc89 | 73 | * |
rgrover1 | 0:8e57f3e9cc89 | 74 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check |
rgrover1 | 0:8e57f3e9cc89 | 75 | * the current stack state only - comparing the current top of stack value to |
rgrover1 | 0:8e57f3e9cc89 | 76 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 |
rgrover1 | 0:8e57f3e9cc89 | 77 | * will also cause the last few stack bytes to be checked to ensure the value |
rgrover1 | 0:8e57f3e9cc89 | 78 | * to which the bytes were set when the task was created have not been |
rgrover1 | 0:8e57f3e9cc89 | 79 | * overwritten. Note this second test does not guarantee that an overflowed |
rgrover1 | 0:8e57f3e9cc89 | 80 | * stack will always be recognised. |
rgrover1 | 0:8e57f3e9cc89 | 81 | */ |
rgrover1 | 0:8e57f3e9cc89 | 82 | |
rgrover1 | 0:8e57f3e9cc89 | 83 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 84 | |
rgrover1 | 0:8e57f3e9cc89 | 85 | #if( configCHECK_FOR_STACK_OVERFLOW == 0 ) |
rgrover1 | 0:8e57f3e9cc89 | 86 | |
rgrover1 | 0:8e57f3e9cc89 | 87 | /* FreeRTOSConfig.h is not set to check for stack overflows. */ |
rgrover1 | 0:8e57f3e9cc89 | 88 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() |
rgrover1 | 0:8e57f3e9cc89 | 89 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() |
rgrover1 | 0:8e57f3e9cc89 | 90 | |
rgrover1 | 0:8e57f3e9cc89 | 91 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ |
rgrover1 | 0:8e57f3e9cc89 | 92 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 93 | |
rgrover1 | 0:8e57f3e9cc89 | 94 | #if( configCHECK_FOR_STACK_OVERFLOW == 1 ) |
rgrover1 | 0:8e57f3e9cc89 | 95 | |
rgrover1 | 0:8e57f3e9cc89 | 96 | /* FreeRTOSConfig.h is only set to use the first method of |
rgrover1 | 0:8e57f3e9cc89 | 97 | overflow checking. */ |
rgrover1 | 0:8e57f3e9cc89 | 98 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() |
rgrover1 | 0:8e57f3e9cc89 | 99 | |
rgrover1 | 0:8e57f3e9cc89 | 100 | #endif |
rgrover1 | 0:8e57f3e9cc89 | 101 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 102 | |
rgrover1 | 0:8e57f3e9cc89 | 103 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) |
rgrover1 | 0:8e57f3e9cc89 | 104 | |
rgrover1 | 0:8e57f3e9cc89 | 105 | /* Only the current stack state is to be checked. */ |
rgrover1 | 0:8e57f3e9cc89 | 106 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ |
rgrover1 | 0:8e57f3e9cc89 | 107 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 108 | /* Is the currently saved stack pointer within the stack limit? */ \ |
rgrover1 | 0:8e57f3e9cc89 | 109 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ |
rgrover1 | 0:8e57f3e9cc89 | 110 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 111 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
rgrover1 | 0:8e57f3e9cc89 | 112 | } \ |
rgrover1 | 0:8e57f3e9cc89 | 113 | } |
rgrover1 | 0:8e57f3e9cc89 | 114 | |
rgrover1 | 0:8e57f3e9cc89 | 115 | #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */ |
rgrover1 | 0:8e57f3e9cc89 | 116 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 117 | |
rgrover1 | 0:8e57f3e9cc89 | 118 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) |
rgrover1 | 0:8e57f3e9cc89 | 119 | |
rgrover1 | 0:8e57f3e9cc89 | 120 | /* Only the current stack state is to be checked. */ |
rgrover1 | 0:8e57f3e9cc89 | 121 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ |
rgrover1 | 0:8e57f3e9cc89 | 122 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 123 | \ |
rgrover1 | 0:8e57f3e9cc89 | 124 | /* Is the currently saved stack pointer within the stack limit? */ \ |
rgrover1 | 0:8e57f3e9cc89 | 125 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ |
rgrover1 | 0:8e57f3e9cc89 | 126 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 127 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
rgrover1 | 0:8e57f3e9cc89 | 128 | } \ |
rgrover1 | 0:8e57f3e9cc89 | 129 | } |
rgrover1 | 0:8e57f3e9cc89 | 130 | |
rgrover1 | 0:8e57f3e9cc89 | 131 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ |
rgrover1 | 0:8e57f3e9cc89 | 132 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 133 | |
rgrover1 | 0:8e57f3e9cc89 | 134 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) |
rgrover1 | 0:8e57f3e9cc89 | 135 | |
rgrover1 | 0:8e57f3e9cc89 | 136 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ |
rgrover1 | 0:8e57f3e9cc89 | 137 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 138 | static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 139 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 140 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 141 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 142 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ |
rgrover1 | 0:8e57f3e9cc89 | 143 | \ |
rgrover1 | 0:8e57f3e9cc89 | 144 | \ |
rgrover1 | 0:8e57f3e9cc89 | 145 | /* Has the extremity of the task stack ever been written over? */ \ |
rgrover1 | 0:8e57f3e9cc89 | 146 | if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ |
rgrover1 | 0:8e57f3e9cc89 | 147 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 148 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
rgrover1 | 0:8e57f3e9cc89 | 149 | } \ |
rgrover1 | 0:8e57f3e9cc89 | 150 | } |
rgrover1 | 0:8e57f3e9cc89 | 151 | |
rgrover1 | 0:8e57f3e9cc89 | 152 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ |
rgrover1 | 0:8e57f3e9cc89 | 153 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 154 | |
rgrover1 | 0:8e57f3e9cc89 | 155 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) |
rgrover1 | 0:8e57f3e9cc89 | 156 | |
rgrover1 | 0:8e57f3e9cc89 | 157 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ |
rgrover1 | 0:8e57f3e9cc89 | 158 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 159 | char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \ |
rgrover1 | 0:8e57f3e9cc89 | 160 | static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 161 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 162 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 163 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
rgrover1 | 0:8e57f3e9cc89 | 164 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ |
rgrover1 | 0:8e57f3e9cc89 | 165 | \ |
rgrover1 | 0:8e57f3e9cc89 | 166 | \ |
rgrover1 | 0:8e57f3e9cc89 | 167 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ |
rgrover1 | 0:8e57f3e9cc89 | 168 | \ |
rgrover1 | 0:8e57f3e9cc89 | 169 | /* Has the extremity of the task stack ever been written over? */ \ |
rgrover1 | 0:8e57f3e9cc89 | 170 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ |
rgrover1 | 0:8e57f3e9cc89 | 171 | { \ |
rgrover1 | 0:8e57f3e9cc89 | 172 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
rgrover1 | 0:8e57f3e9cc89 | 173 | } \ |
rgrover1 | 0:8e57f3e9cc89 | 174 | } |
rgrover1 | 0:8e57f3e9cc89 | 175 | |
rgrover1 | 0:8e57f3e9cc89 | 176 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ |
rgrover1 | 0:8e57f3e9cc89 | 177 | /*-----------------------------------------------------------*/ |
rgrover1 | 0:8e57f3e9cc89 | 178 | |
rgrover1 | 0:8e57f3e9cc89 | 179 | #endif /* STACK_MACROS_H */ |
rgrover1 | 0:8e57f3e9cc89 | 180 |