2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /*-----------------------------------------------------------
\r
67 * Implementation of functions defined in portable.h for the SH2A port.
\r
68 *----------------------------------------------------------*/
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
74 /* Library includes. */
\r
77 /*-----------------------------------------------------------*/
\r
79 /* The SR assigned to a newly created task. The only important thing in this
\r
80 value is for all interrupts to be enabled. */
\r
81 #define portINITIAL_SR ( 0UL )
\r
83 /* Dimensions the array into which the floating point context is saved.
\r
84 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4
\r
85 bytes big. If this number is changed then the 72 in portasm.src also needs
\r
87 #define portFLOP_REGISTERS_TO_STORE ( 18 )
\r
88 #define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 )
\r
90 /*-----------------------------------------------------------*/
\r
93 * The TRAPA handler used to force a context switch.
\r
95 void vPortYield( void );
\r
98 * Function to start the first task executing - defined in portasm.src.
\r
100 extern void vPortStartFirstTask( void );
\r
103 * Obtains the current GBR value - defined in portasm.src.
\r
105 extern unsigned long ulPortGetGBR( void );
\r
107 /*-----------------------------------------------------------*/
\r
110 * See header file for description.
\r
112 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
114 /* Mark the end of the stack - used for debugging only and can be removed. */
\r
115 *pxTopOfStack = 0x11111111UL;
\r
117 *pxTopOfStack = 0x22222222UL;
\r
119 *pxTopOfStack = 0x33333333UL;
\r
123 *pxTopOfStack = portINITIAL_SR;
\r
127 *pxTopOfStack = ( unsigned long ) pxCode;
\r
131 *pxTopOfStack = 15;
\r
135 *pxTopOfStack = 14;
\r
139 *pxTopOfStack = 13;
\r
143 *pxTopOfStack = 12;
\r
147 *pxTopOfStack = 11;
\r
151 *pxTopOfStack = 10;
\r
175 *pxTopOfStack = ( unsigned long ) pvParameters;
\r
195 *pxTopOfStack = 16;
\r
199 *pxTopOfStack = 17;
\r
203 *pxTopOfStack = ulPortGetGBR();
\r
205 /* GBR = global base register.
\r
206 VBR = vector base register.
\r
207 TBR = jump table base register.
\r
208 R15 is the stack pointer. */
\r
210 return pxTopOfStack;
\r
212 /*-----------------------------------------------------------*/
\r
214 portBASE_TYPE xPortStartScheduler( void )
\r
216 extern void vApplicationSetupTimerInterrupt( void );
\r
218 /* Call an application function to set up the timer that will generate the
\r
219 tick interrupt. This way the application can decide which peripheral to
\r
220 use. A demo application is provided to show a suitable example. */
\r
221 vApplicationSetupTimerInterrupt();
\r
223 /* Start the first task. This will only restore the standard registers and
\r
224 not the flop registers. This does not really matter though because the only
\r
225 flop register that is initialised to a particular value is fpscr, and it is
\r
226 only initialised to the current value, which will still be the current value
\r
227 when the first task starts executing. */
\r
228 trapa( portSTART_SCHEDULER_TRAP_NO );
\r
230 /* Should not get here. */
\r
233 /*-----------------------------------------------------------*/
\r
235 void vPortEndScheduler( void )
\r
237 /* Not implemented as there is nothing to return to. */
\r
239 /*-----------------------------------------------------------*/
\r
241 void vPortYield( void )
\r
243 long lInterruptMask;
\r
245 /* Ensure the yield trap runs at the same priority as the other interrupts
\r
246 that can cause a context switch. */
\r
247 lInterruptMask = get_imask();
\r
249 /* taskYIELD() can only be called from a task, not an interrupt, so the
\r
250 current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
\r
251 the mask can be set without risk of accidentally lowering the mask value. */
\r
252 set_imask( portKERNEL_INTERRUPT_PRIORITY );
\r
254 trapa( portYIELD_TRAP_NO );
\r
256 /* Restore the interrupt mask to whatever it was previously (when the
\r
257 function was entered). */
\r
258 set_imask( ( int ) lInterruptMask );
\r
260 /*-----------------------------------------------------------*/
\r
262 portBASE_TYPE xPortUsesFloatingPoint( xTaskHandle xTask )
\r
264 unsigned long *pulFlopBuffer;
\r
265 portBASE_TYPE xReturn;
\r
266 extern void * volatile pxCurrentTCB;
\r
268 /* This function tells the kernel that the task referenced by xTask is
\r
269 going to use the floating point registers and therefore requires the
\r
270 floating point registers saved as part of its context. */
\r
272 /* Passing NULL as xTask is used to indicate that the calling task is the
\r
273 subject task - so pxCurrentTCB is the task handle. */
\r
274 if( xTask == NULL )
\r
276 xTask = ( xTaskHandle ) pxCurrentTCB;
\r
279 /* Allocate a buffer large enough to hold all the flop registers. */
\r
280 pulFlopBuffer = ( unsigned long * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
\r
282 if( pulFlopBuffer != NULL )
\r
284 /* Start with the registers in a benign state. */
\r
285 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
\r
287 /* The first thing to get saved in the buffer is the FPSCR value -
\r
288 initialise this to the current FPSCR value. */
\r
289 *pulFlopBuffer = get_fpscr();
\r
291 /* Use the task tag to point to the flop buffer. Pass pointer to just
\r
292 above the buffer because the flop save routine uses a pre-decrement. */
\r
293 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
\r
303 /*-----------------------------------------------------------*/
\r