2 FreeRTOS V7.0.2 - 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
54 /*-----------------------------------------------------------
\r
55 * Implementation of functions defined in portable.h for the ARM CM4F port.
\r
56 *----------------------------------------------------------*/
\r
58 /* Scheduler includes. */
\r
59 #include "FreeRTOS.h"
\r
63 #error This port can only be used when the project options are configured to enable hardware floating point support.
\r
66 /* Constants required to manipulate the NVIC. */
\r
67 #define portNVIC_SYSTICK_CTRL ( ( volatile unsigned long * ) 0xe000e010 )
\r
68 #define portNVIC_SYSTICK_LOAD ( ( volatile unsigned long * ) 0xe000e014 )
\r
69 #define portNVIC_INT_CTRL ( ( volatile unsigned long * ) 0xe000ed04 )
\r
70 #define portNVIC_SYSPRI2 ( ( volatile unsigned long * ) 0xe000ed20 )
\r
71 #define portNVIC_SYSTICK_CLK 0x00000004
\r
72 #define portNVIC_SYSTICK_INT 0x00000002
\r
73 #define portNVIC_SYSTICK_ENABLE 0x00000001
\r
74 #define portNVIC_PENDSVSET 0x10000000
\r
75 #define portNVIC_PENDSV_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 16 )
\r
76 #define portNVIC_SYSTICK_PRI ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 24 )
\r
78 /* Constants required to manipulate the VFP. */
\r
79 #define portFPCCR ( ( volatile unsigned long * ) 0xe000ef34 ) /* Floating point context control register. */
\r
80 #define portASPEN_AND_LSPEN_BITS ( 0x3UL << 30UL )
\r
82 /* Constants required to set up the initial stack. */
\r
83 #define portINITIAL_XPSR ( 0x01000000 )
\r
84 #define portINITIAL_EXEC_RETURN ( 0xfffffffd )
\r
86 /* Each task maintains its own interrupt status in the critical nesting
\r
88 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;
\r
91 * Setup the timer to generate the tick interrupts.
\r
93 static void prvSetupTimerInterrupt( void );
\r
96 * Exception handlers.
\r
98 void xPortSysTickHandler( void );
\r
101 * Start first task is a separate function so it can be tested in isolation.
\r
103 extern void vPortStartFirstTask( void );
\r
106 * Functions defined in portasm.s to enable the VFP.
\r
108 extern void vPortEnableVFP( void );
\r
110 /*-----------------------------------------------------------*/
\r
113 * See header file for description.
\r
115 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
117 /* Simulate the stack frame as it would be created by a context switch
\r
120 /* Offset added to account for the way the MCU uses the stack on entry/exit
\r
121 of interrupts, and to ensure alignment. */
\r
124 *pxTopOfStack = portINITIAL_XPSR; /* xPSR */
\r
126 *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */
\r
128 *pxTopOfStack = 0; /* LR */
\r
130 /* Save code space by skipping register initialisation. */
\r
131 pxTopOfStack -= 5; /* R12, R3, R2 and R1. */
\r
132 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */
\r
134 /* A save method is being used that requiers each task to maintain its
\r
135 own exec return value. */
\r
137 *pxTopOfStack = portINITIAL_EXEC_RETURN;
\r
139 pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */
\r
141 return pxTopOfStack;
\r
143 /*-----------------------------------------------------------*/
\r
146 * See header file for description.
\r
148 portBASE_TYPE xPortStartScheduler( void )
\r
150 /* Make PendSV and SysTick the lowest priority interrupts. */
\r
151 *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
\r
152 *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
\r
154 /* Start the timer that generates the tick ISR. Interrupts are disabled
\r
156 prvSetupTimerInterrupt();
\r
158 /* Initialise the critical nesting count ready for the first task. */
\r
159 uxCriticalNesting = 0;
\r
161 /* Ensure the VFP is enabled - it should be anyway. */
\r
164 /* Lazy save always. */
\r
165 *( portFPCCR ) |= portASPEN_AND_LSPEN_BITS;
\r
167 /* Start the first task. */
\r
168 vPortStartFirstTask();
\r
170 /* Should not get here! */
\r
173 /*-----------------------------------------------------------*/
\r
175 void vPortEndScheduler( void )
\r
177 /* It is unlikely that the CM4F port will require this function as there
\r
178 is nothing to return to. */
\r
180 /*-----------------------------------------------------------*/
\r
182 void vPortYieldFromISR( void )
\r
184 /* Set a PendSV to request a context switch. */
\r
185 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
187 /*-----------------------------------------------------------*/
\r
189 void vPortEnterCritical( void )
\r
191 portDISABLE_INTERRUPTS();
\r
192 uxCriticalNesting++;
\r
194 /*-----------------------------------------------------------*/
\r
196 void vPortExitCritical( void )
\r
198 uxCriticalNesting--;
\r
199 if( uxCriticalNesting == 0 )
\r
201 portENABLE_INTERRUPTS();
\r
204 /*-----------------------------------------------------------*/
\r
206 void xPortSysTickHandler( void )
\r
208 unsigned long ulDummy;
\r
210 /* If using preemption, also force a context switch. */
\r
211 #if configUSE_PREEMPTION == 1
\r
212 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
215 ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
\r
217 vTaskIncrementTick();
\r
219 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
\r
221 /*-----------------------------------------------------------*/
\r
224 * Setup the systick timer to generate the tick interrupts at the required
\r
227 void prvSetupTimerInterrupt( void )
\r
229 /* Configure SysTick to interrupt at the requested rate. */
\r
230 *(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
\r
231 *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
\r
233 /*-----------------------------------------------------------*/
\r