2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the SH2A port.
\r
72 *----------------------------------------------------------*/
\r
74 /* Scheduler includes. */
\r
75 #include "FreeRTOS.h"
\r
78 /* Library includes. */
\r
81 /*-----------------------------------------------------------*/
\r
83 /* The SR assigned to a newly created task. The only important thing in this
\r
84 value is for all interrupts to be enabled. */
\r
85 #define portINITIAL_SR ( 0UL )
\r
87 /* Dimensions the array into which the floating point context is saved.
\r
88 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4
\r
89 bytes big. If this number is changed then the 72 in portasm.src also needs
\r
91 #define portFLOP_REGISTERS_TO_STORE ( 18 )
\r
92 #define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 )
\r
94 #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
\r
95 #error configSUPPORT_DYNAMIC_ALLOCATION must be 1 to use this port.
\r
98 /*-----------------------------------------------------------*/
\r
101 * The TRAPA handler used to force a context switch.
\r
103 void vPortYield( void );
\r
106 * Function to start the first task executing - defined in portasm.src.
\r
108 extern void vPortStartFirstTask( void );
\r
111 * Obtains the current GBR value - defined in portasm.src.
\r
113 extern uint32_t ulPortGetGBR( void );
\r
115 /*-----------------------------------------------------------*/
\r
118 * See header file for description.
\r
120 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
122 /* Mark the end of the stack - used for debugging only and can be removed. */
\r
123 *pxTopOfStack = 0x11111111UL;
\r
125 *pxTopOfStack = 0x22222222UL;
\r
127 *pxTopOfStack = 0x33333333UL;
\r
131 *pxTopOfStack = portINITIAL_SR;
\r
135 *pxTopOfStack = ( uint32_t ) pxCode;
\r
139 *pxTopOfStack = 15;
\r
143 *pxTopOfStack = 14;
\r
147 *pxTopOfStack = 13;
\r
151 *pxTopOfStack = 12;
\r
155 *pxTopOfStack = 11;
\r
159 *pxTopOfStack = 10;
\r
183 *pxTopOfStack = ( uint32_t ) pvParameters;
\r
203 *pxTopOfStack = 16;
\r
207 *pxTopOfStack = 17;
\r
211 *pxTopOfStack = ulPortGetGBR();
\r
213 /* GBR = global base register.
\r
214 VBR = vector base register.
\r
215 TBR = jump table base register.
\r
216 R15 is the stack pointer. */
\r
218 return pxTopOfStack;
\r
220 /*-----------------------------------------------------------*/
\r
222 BaseType_t xPortStartScheduler( void )
\r
224 extern void vApplicationSetupTimerInterrupt( void );
\r
226 /* Call an application function to set up the timer that will generate the
\r
227 tick interrupt. This way the application can decide which peripheral to
\r
228 use. A demo application is provided to show a suitable example. */
\r
229 vApplicationSetupTimerInterrupt();
\r
231 /* Start the first task. This will only restore the standard registers and
\r
232 not the flop registers. This does not really matter though because the only
\r
233 flop register that is initialised to a particular value is fpscr, and it is
\r
234 only initialised to the current value, which will still be the current value
\r
235 when the first task starts executing. */
\r
236 trapa( portSTART_SCHEDULER_TRAP_NO );
\r
238 /* Should not get here. */
\r
241 /*-----------------------------------------------------------*/
\r
243 void vPortEndScheduler( void )
\r
245 /* Not implemented as there is nothing to return to. */
\r
247 /*-----------------------------------------------------------*/
\r
249 void vPortYield( void )
\r
251 int32_t lInterruptMask;
\r
253 /* Ensure the yield trap runs at the same priority as the other interrupts
\r
254 that can cause a context switch. */
\r
255 lInterruptMask = get_imask();
\r
257 /* taskYIELD() can only be called from a task, not an interrupt, so the
\r
258 current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
\r
259 the mask can be set without risk of accidentally lowering the mask value. */
\r
260 set_imask( portKERNEL_INTERRUPT_PRIORITY );
\r
262 trapa( portYIELD_TRAP_NO );
\r
264 /* Restore the interrupt mask to whatever it was previously (when the
\r
265 function was entered). */
\r
266 set_imask( ( int ) lInterruptMask );
\r
268 /*-----------------------------------------------------------*/
\r
270 BaseType_t xPortUsesFloatingPoint( TaskHandle_t xTask )
\r
272 uint32_t *pulFlopBuffer;
\r
273 BaseType_t xReturn;
\r
274 extern void * volatile pxCurrentTCB;
\r
276 /* This function tells the kernel that the task referenced by xTask is
\r
277 going to use the floating point registers and therefore requires the
\r
278 floating point registers saved as part of its context. */
\r
280 /* Passing NULL as xTask is used to indicate that the calling task is the
\r
281 subject task - so pxCurrentTCB is the task handle. */
\r
282 if( xTask == NULL )
\r
284 xTask = ( TaskHandle_t ) pxCurrentTCB;
\r
287 /* Allocate a buffer large enough to hold all the flop registers. */
\r
288 pulFlopBuffer = ( uint32_t * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
\r
290 if( pulFlopBuffer != NULL )
\r
292 /* Start with the registers in a benign state. */
\r
293 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
\r
295 /* The first thing to get saved in the buffer is the FPSCR value -
\r
296 initialise this to the current FPSCR value. */
\r
297 *pulFlopBuffer = get_fpscr();
\r
299 /* Use the task tag to point to the flop buffer. Pass pointer to just
\r
300 above the buffer because the flop save routine uses a pre-decrement. */
\r
301 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
\r
311 /*-----------------------------------------------------------*/
\r