2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
75 /*-----------------------------------------------------------
\r
76 * Implementation of functions defined in portable.h for the ARM CM0 port.
\r
77 *----------------------------------------------------------*/
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Constants required to manipulate the NVIC. */
\r
84 #define portNVIC_SYSTICK_CTRL ( ( volatile unsigned long *) 0xe000e010 )
\r
85 #define portNVIC_SYSTICK_LOAD ( ( volatile unsigned long *) 0xe000e014 )
\r
86 #define portNVIC_INT_CTRL ( ( volatile unsigned long *) 0xe000ed04 )
\r
87 #define portNVIC_SYSPRI2 ( ( volatile unsigned long *) 0xe000ed20 )
\r
88 #define portNVIC_SYSTICK_CLK 0x00000004
\r
89 #define portNVIC_SYSTICK_INT 0x00000002
\r
90 #define portNVIC_SYSTICK_ENABLE 0x00000001
\r
91 #define portNVIC_PENDSVSET 0x10000000
\r
92 #define portMIN_INTERRUPT_PRIORITY ( 255UL )
\r
93 #define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
\r
94 #define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
\r
96 /* Constants required to set up the initial stack. */
\r
97 #define portINITIAL_XPSR ( 0x01000000 )
\r
99 /* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is
\r
100 defined. The value 255 should also ensure backward compatibility.
\r
101 FreeRTOS.org versions prior to V4.3.0 did not include this definition. */
\r
102 #ifndef configKERNEL_INTERRUPT_PRIORITY
\r
103 #define configKERNEL_INTERRUPT_PRIORITY 0
\r
106 /* Each task maintains its own interrupt status in the critical nesting
\r
108 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;
\r
111 * Setup the timer to generate the tick interrupts.
\r
113 static void prvSetupTimerInterrupt( void );
\r
116 * Exception handlers.
\r
118 void xPortSysTickHandler( void );
\r
121 * Start first task is a separate function so it can be tested in isolation.
\r
123 extern void vPortStartFirstTask( void );
\r
125 /*-----------------------------------------------------------*/
\r
128 * See header file for description.
\r
130 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
132 /* Simulate the stack frame as it would be created by a context switch
\r
134 pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
\r
135 *pxTopOfStack = portINITIAL_XPSR; /* xPSR */
\r
137 *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* PC */
\r
138 pxTopOfStack -= 6; /* LR, R12, R3..R1 */
\r
139 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */
\r
140 pxTopOfStack -= 8; /* R11..R4. */
\r
142 return pxTopOfStack;
\r
144 /*-----------------------------------------------------------*/
\r
147 * See header file for description.
\r
149 portBASE_TYPE xPortStartScheduler( void )
\r
151 /* Make PendSV and SysTick the lowest priority interrupts. */
\r
152 *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
\r
153 *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
\r
155 /* Start the timer that generates the tick ISR. Interrupts are disabled
\r
157 prvSetupTimerInterrupt();
\r
159 /* Initialise the critical nesting count ready for the first task. */
\r
160 uxCriticalNesting = 0;
\r
162 /* Start the first task. */
\r
163 vPortStartFirstTask();
\r
165 /* Should not get here! */
\r
168 /*-----------------------------------------------------------*/
\r
170 void vPortEndScheduler( void )
\r
172 /* It is unlikely that the CM0 port will require this function as there
\r
173 is nothing to return to. */
\r
175 /*-----------------------------------------------------------*/
\r
177 void vPortYieldFromISR( void )
\r
179 /* Set a PendSV to request a context switch. */
\r
180 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
182 /*-----------------------------------------------------------*/
\r
184 void vPortEnterCritical( void )
\r
186 portDISABLE_INTERRUPTS();
\r
187 uxCriticalNesting++;
\r
189 /*-----------------------------------------------------------*/
\r
191 void vPortExitCritical( void )
\r
193 uxCriticalNesting--;
\r
194 if( uxCriticalNesting == 0 )
\r
196 portENABLE_INTERRUPTS();
\r
199 /*-----------------------------------------------------------*/
\r
201 void xPortSysTickHandler( void )
\r
203 unsigned long ulDummy;
\r
205 /* If using preemption, also force a context switch. */
\r
206 #if configUSE_PREEMPTION == 1
\r
207 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
210 ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
\r
212 vTaskIncrementTick();
\r
214 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
\r
216 /*-----------------------------------------------------------*/
\r
219 * Setup the systick timer to generate the tick interrupts at the required
\r
222 static void prvSetupTimerInterrupt( void )
\r
224 /* Configure SysTick to interrupt at the requested rate. */
\r
225 *(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
\r
226 *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
\r
228 /*-----------------------------------------------------------*/
\r