2 FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
58 /*-----------------------------------------------------------
\r
59 * Port specific definitions.
\r
61 * The settings in this file configure FreeRTOS correctly for the
\r
62 * given hardware and compiler.
\r
64 * These settings should not be altered.
\r
65 *-----------------------------------------------------------
\r
68 /* Type definitions. */
\r
69 #define portCHAR char
\r
70 #define portFLOAT float
\r
71 #define portDOUBLE double
\r
72 #define portLONG long
\r
73 #define portSHORT short
\r
74 #define portSTACK_TYPE unsigned portCHAR
\r
75 #define portBASE_TYPE char
\r
77 #if( configUSE_16_BIT_TICKS == 1 )
\r
78 typedef unsigned portSHORT portTickType;
\r
79 #define portMAX_DELAY ( portTickType ) 0xffff
\r
81 typedef unsigned portLONG portTickType;
\r
82 #define portMAX_DELAY ( portTickType ) 0xffffffff
\r
84 /*-----------------------------------------------------------*/
\r
86 /* Hardware specifics. */
\r
87 #define portBYTE_ALIGNMENT 1
\r
88 #define portSTACK_GROWTH ( -1 )
\r
89 #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
\r
90 #define portYIELD() __asm( "swi" );
\r
91 #define portNOP() __asm( "nop" );
\r
92 /*-----------------------------------------------------------*/
\r
94 /* Critical section handling. */
\r
95 #define portENABLE_INTERRUPTS() __asm( "cli" )
\r
96 #define portDISABLE_INTERRUPTS() __asm( "sei" )
\r
99 * Disable interrupts before incrementing the count of critical section nesting.
\r
100 * The nesting count is maintained so we know when interrupts should be
\r
101 * re-enabled. Once interrupts are disabled the nesting count can be accessed
\r
102 * directly. Each task maintains its own nesting count.
\r
104 #define portENTER_CRITICAL() \
\r
106 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
108 portDISABLE_INTERRUPTS(); \
\r
109 uxCriticalNesting++; \
\r
113 * Interrupts are disabled so we can access the nesting count directly. If the
\r
114 * nesting is found to be 0 (no nesting) then we are leaving the critical
\r
115 * section and interrupts can be re-enabled.
\r
117 #define portEXIT_CRITICAL() \
\r
119 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
121 uxCriticalNesting--; \
\r
122 if( uxCriticalNesting == 0 ) \
\r
124 portENABLE_INTERRUPTS(); \
\r
127 /*-----------------------------------------------------------*/
\r
129 /* Task utilities. */
\r
132 * These macros are very simple as the processor automatically saves and
\r
133 * restores its registers as interrupts are entered and exited. In
\r
134 * addition to the (automatically stacked) registers we also stack the
\r
135 * critical nesting count. Each task maintains its own critical nesting
\r
136 * count as it is legitimate for a task to yield from within a critical
\r
137 * section. If the banked memory model is being used then the PPAGE
\r
138 * register is also stored as part of the tasks context.
\r
141 #ifdef BANKED_MODEL
\r
143 * Load the stack pointer for the task, then pull the critical nesting
\r
144 * count and PPAGE register from the stack. The remains of the
\r
145 * context are restored by the RTI instruction.
\r
147 #define portRESTORE_CONTEXT() \
\r
149 extern volatile void * pxCurrentTCB; \
\r
150 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
152 __asm( "ldx pxCurrentTCB" ); \
\r
153 __asm( "lds 0, x" ); \
\r
155 __asm( "staa uxCriticalNesting" ); \
\r
157 __asm( "staa 0x30" ); /* 0x30 = PPAGE */ \
\r
161 * By the time this macro is called the processor has already stacked the
\r
162 * registers. Simply stack the nesting count and PPAGE value, then save
\r
163 * the task stack pointer.
\r
165 #define portSAVE_CONTEXT() \
\r
167 extern volatile void * pxCurrentTCB; \
\r
168 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
170 __asm( "ldaa 0x30" ); /* 0x30 = PPAGE */ \
\r
172 __asm( "ldaa uxCriticalNesting" ); \
\r
174 __asm( "ldx pxCurrentTCB" ); \
\r
175 __asm( "sts 0, x" ); \
\r
180 * These macros are as per the BANKED versions above, but without saving
\r
181 * and restoring the PPAGE register.
\r
184 #define portRESTORE_CONTEXT() \
\r
186 extern volatile void * pxCurrentTCB; \
\r
187 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
189 __asm( "ldx pxCurrentTCB" ); \
\r
190 __asm( "lds 0, x" ); \
\r
192 __asm( "staa uxCriticalNesting" ); \
\r
195 #define portSAVE_CONTEXT() \
\r
197 extern volatile void * pxCurrentTCB; \
\r
198 extern volatile unsigned portBASE_TYPE uxCriticalNesting; \
\r
200 __asm( "ldaa uxCriticalNesting" ); \
\r
202 __asm( "ldx pxCurrentTCB" ); \
\r
203 __asm( "sts 0, x" ); \
\r
208 * Utility macro to call macros above in correct order in order to perform a
\r
209 * task switch from within a standard ISR. This macro can only be used if
\r
210 * the ISR does not use any local (stack) variables. If the ISR uses stack
\r
211 * variables portYIELD() should be used in it's place.
\r
213 #define portTASK_SWITCH_FROM_ISR() \
\r
214 portSAVE_CONTEXT(); \
\r
215 vTaskSwitchContext(); \
\r
216 portRESTORE_CONTEXT();
\r
219 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
220 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
221 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
223 #endif /* PORTMACRO_H */
\r