2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /*-----------------------------------------------------------
\r
66 * Implementation of functions defined in portable.h for the SH2A port.
\r
67 *----------------------------------------------------------*/
\r
69 /* Scheduler includes. */
\r
70 #include "FreeRTOS.h"
\r
73 /* Library includes. */
\r
76 /*-----------------------------------------------------------*/
\r
78 /* The SR assigned to a newly created task. The only important thing in this
\r
79 value is for all interrupts to be enabled. */
\r
80 #define portINITIAL_SR ( 0UL )
\r
82 /* Dimensions the array into which the floating point context is saved.
\r
83 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4
\r
84 bytes big. If this number is changed then the 72 in portasm.src also needs
\r
86 #define portFLOP_REGISTERS_TO_STORE ( 18 )
\r
87 #define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 )
\r
89 /*-----------------------------------------------------------*/
\r
92 * The TRAPA handler used to force a context switch.
\r
94 void vPortYield( void );
\r
97 * Function to start the first task executing - defined in portasm.src.
\r
99 extern void vPortStartFirstTask( void );
\r
102 * Obtains the current GBR value - defined in portasm.src.
\r
104 extern unsigned long ulPortGetGBR( void );
\r
106 /*-----------------------------------------------------------*/
\r
109 * See header file for description.
\r
111 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
113 /* Mark the end of the stack - used for debugging only and can be removed. */
\r
114 *pxTopOfStack = 0x11111111UL;
\r
116 *pxTopOfStack = 0x22222222UL;
\r
118 *pxTopOfStack = 0x33333333UL;
\r
122 *pxTopOfStack = portINITIAL_SR;
\r
126 *pxTopOfStack = ( unsigned long ) pxCode;
\r
130 *pxTopOfStack = 15;
\r
134 *pxTopOfStack = 14;
\r
138 *pxTopOfStack = 13;
\r
142 *pxTopOfStack = 12;
\r
146 *pxTopOfStack = 11;
\r
150 *pxTopOfStack = 10;
\r
174 *pxTopOfStack = ( unsigned long ) pvParameters;
\r
194 *pxTopOfStack = 16;
\r
198 *pxTopOfStack = 17;
\r
202 *pxTopOfStack = ulPortGetGBR();
\r
204 /* GBR = global base register.
\r
205 VBR = vector base register.
\r
206 TBR = jump table base register.
\r
207 R15 is the stack pointer. */
\r
209 return pxTopOfStack;
\r
211 /*-----------------------------------------------------------*/
\r
213 portBASE_TYPE xPortStartScheduler( void )
\r
215 extern void vApplicationSetupTimerInterrupt( void );
\r
217 /* Call an application function to set up the timer that will generate the
\r
218 tick interrupt. This way the application can decide which peripheral to
\r
219 use. A demo application is provided to show a suitable example. */
\r
220 vApplicationSetupTimerInterrupt();
\r
222 /* Start the first task. This will only restore the standard registers and
\r
223 not the flop registers. This does not really matter though because the only
\r
224 flop register that is initialised to a particular value is fpscr, and it is
\r
225 only initialised to the current value, which will still be the current value
\r
226 when the first task starts executing. */
\r
227 trapa( portSTART_SCHEDULER_TRAP_NO );
\r
229 /* Should not get here. */
\r
232 /*-----------------------------------------------------------*/
\r
234 void vPortEndScheduler( void )
\r
236 /* Not implemented as there is nothing to return to. */
\r
238 /*-----------------------------------------------------------*/
\r
240 void vPortYield( void )
\r
242 long lInterruptMask;
\r
244 /* Ensure the yield trap runs at the same priority as the other interrupts
\r
245 that can cause a context switch. */
\r
246 lInterruptMask = get_imask();
\r
248 /* taskYIELD() can only be called from a task, not an interrupt, so the
\r
249 current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
\r
250 the mask can be set without risk of accidentally lowering the mask value. */
\r
251 set_imask( portKERNEL_INTERRUPT_PRIORITY );
\r
253 trapa( portYIELD_TRAP_NO );
\r
255 /* Restore the interrupt mask to whatever it was previously (when the
\r
256 function was entered). */
\r
257 set_imask( ( int ) lInterruptMask );
\r
259 /*-----------------------------------------------------------*/
\r
261 portBASE_TYPE xPortUsesFloatingPoint( xTaskHandle xTask )
\r
263 unsigned long *pulFlopBuffer;
\r
264 portBASE_TYPE xReturn;
\r
265 extern void * volatile pxCurrentTCB;
\r
267 /* This function tells the kernel that the task referenced by xTask is
\r
268 going to use the floating point registers and therefore requires the
\r
269 floating point registers saved as part of its context. */
\r
271 /* Passing NULL as xTask is used to indicate that the calling task is the
\r
272 subject task - so pxCurrentTCB is the task handle. */
\r
273 if( xTask == NULL )
\r
275 xTask = ( xTaskHandle ) pxCurrentTCB;
\r
278 /* Allocate a buffer large enough to hold all the flop registers. */
\r
279 pulFlopBuffer = ( unsigned long * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
\r
281 if( pulFlopBuffer != NULL )
\r
283 /* Start with the registers in a benign state. */
\r
284 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
\r
286 /* The first thing to get saved in the buffer is the FPSCR value -
\r
287 initialise this to the current FPSCR value. */
\r
288 *pulFlopBuffer = get_fpscr();
\r
290 /* Use the task tag to point to the flop buffer. Pass pointer to just
\r
291 above the buffer because the flop save routine uses a pre-decrement. */
\r
292 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
\r
302 /*-----------------------------------------------------------*/
\r