2 FreeRTOS V7.4.1 - 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 it can 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 SH2A port.
\r
77 *----------------------------------------------------------*/
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Library includes. */
\r
86 /*-----------------------------------------------------------*/
\r
88 /* The SR assigned to a newly created task. The only important thing in this
\r
89 value is for all interrupts to be enabled. */
\r
90 #define portINITIAL_SR ( 0UL )
\r
92 /* Dimensions the array into which the floating point context is saved.
\r
93 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4
\r
94 bytes big. If this number is changed then the 72 in portasm.src also needs
\r
96 #define portFLOP_REGISTERS_TO_STORE ( 18 )
\r
97 #define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 )
\r
99 /*-----------------------------------------------------------*/
\r
102 * The TRAPA handler used to force a context switch.
\r
104 void vPortYield( void );
\r
107 * Function to start the first task executing - defined in portasm.src.
\r
109 extern void vPortStartFirstTask( void );
\r
112 * Obtains the current GBR value - defined in portasm.src.
\r
114 extern unsigned long ulPortGetGBR( void );
\r
116 /*-----------------------------------------------------------*/
\r
119 * See header file for description.
\r
121 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
123 /* Mark the end of the stack - used for debugging only and can be removed. */
\r
124 *pxTopOfStack = 0x11111111UL;
\r
126 *pxTopOfStack = 0x22222222UL;
\r
128 *pxTopOfStack = 0x33333333UL;
\r
132 *pxTopOfStack = portINITIAL_SR;
\r
136 *pxTopOfStack = ( unsigned long ) pxCode;
\r
140 *pxTopOfStack = 15;
\r
144 *pxTopOfStack = 14;
\r
148 *pxTopOfStack = 13;
\r
152 *pxTopOfStack = 12;
\r
156 *pxTopOfStack = 11;
\r
160 *pxTopOfStack = 10;
\r
184 *pxTopOfStack = ( unsigned long ) pvParameters;
\r
204 *pxTopOfStack = 16;
\r
208 *pxTopOfStack = 17;
\r
212 *pxTopOfStack = ulPortGetGBR();
\r
214 /* GBR = global base register.
\r
215 VBR = vector base register.
\r
216 TBR = jump table base register.
\r
217 R15 is the stack pointer. */
\r
219 return pxTopOfStack;
\r
221 /*-----------------------------------------------------------*/
\r
223 portBASE_TYPE xPortStartScheduler( void )
\r
225 extern void vApplicationSetupTimerInterrupt( void );
\r
227 /* Call an application function to set up the timer that will generate the
\r
228 tick interrupt. This way the application can decide which peripheral to
\r
229 use. A demo application is provided to show a suitable example. */
\r
230 vApplicationSetupTimerInterrupt();
\r
232 /* Start the first task. This will only restore the standard registers and
\r
233 not the flop registers. This does not really matter though because the only
\r
234 flop register that is initialised to a particular value is fpscr, and it is
\r
235 only initialised to the current value, which will still be the current value
\r
236 when the first task starts executing. */
\r
237 trapa( portSTART_SCHEDULER_TRAP_NO );
\r
239 /* Should not get here. */
\r
242 /*-----------------------------------------------------------*/
\r
244 void vPortEndScheduler( void )
\r
246 /* Not implemented as there is nothing to return to. */
\r
248 /*-----------------------------------------------------------*/
\r
250 void vPortYield( void )
\r
252 long lInterruptMask;
\r
254 /* Ensure the yield trap runs at the same priority as the other interrupts
\r
255 that can cause a context switch. */
\r
256 lInterruptMask = get_imask();
\r
258 /* taskYIELD() can only be called from a task, not an interrupt, so the
\r
259 current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
\r
260 the mask can be set without risk of accidentally lowering the mask value. */
\r
261 set_imask( portKERNEL_INTERRUPT_PRIORITY );
\r
263 trapa( portYIELD_TRAP_NO );
\r
265 /* Restore the interrupt mask to whatever it was previously (when the
\r
266 function was entered). */
\r
267 set_imask( ( int ) lInterruptMask );
\r
269 /*-----------------------------------------------------------*/
\r
271 portBASE_TYPE xPortUsesFloatingPoint( xTaskHandle xTask )
\r
273 unsigned long *pulFlopBuffer;
\r
274 portBASE_TYPE xReturn;
\r
275 extern void * volatile pxCurrentTCB;
\r
277 /* This function tells the kernel that the task referenced by xTask is
\r
278 going to use the floating point registers and therefore requires the
\r
279 floating point registers saved as part of its context. */
\r
281 /* Passing NULL as xTask is used to indicate that the calling task is the
\r
282 subject task - so pxCurrentTCB is the task handle. */
\r
283 if( xTask == NULL )
\r
285 xTask = ( xTaskHandle ) pxCurrentTCB;
\r
288 /* Allocate a buffer large enough to hold all the flop registers. */
\r
289 pulFlopBuffer = ( unsigned long * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
\r
291 if( pulFlopBuffer != NULL )
\r
293 /* Start with the registers in a benign state. */
\r
294 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
\r
296 /* The first thing to get saved in the buffer is the FPSCR value -
\r
297 initialise this to the current FPSCR value. */
\r
298 *pulFlopBuffer = get_fpscr();
\r
300 /* Use the task tag to point to the flop buffer. Pass pointer to just
\r
301 above the buffer because the flop save routine uses a pre-decrement. */
\r
302 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
\r
312 /*-----------------------------------------------------------*/
\r