2 FreeRTOS V8.2.0 - Copyright (C) 2015 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 /*-----------------------------------------------------------*/
\r
97 * The TRAPA handler used to force a context switch.
\r
99 void vPortYield( void );
\r
102 * Function to start the first task executing - defined in portasm.src.
\r
104 extern void vPortStartFirstTask( void );
\r
107 * Obtains the current GBR value - defined in portasm.src.
\r
109 extern uint32_t ulPortGetGBR( void );
\r
111 /*-----------------------------------------------------------*/
\r
114 * See header file for description.
\r
116 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
118 /* Mark the end of the stack - used for debugging only and can be removed. */
\r
119 *pxTopOfStack = 0x11111111UL;
\r
121 *pxTopOfStack = 0x22222222UL;
\r
123 *pxTopOfStack = 0x33333333UL;
\r
127 *pxTopOfStack = portINITIAL_SR;
\r
131 *pxTopOfStack = ( uint32_t ) pxCode;
\r
135 *pxTopOfStack = 15;
\r
139 *pxTopOfStack = 14;
\r
143 *pxTopOfStack = 13;
\r
147 *pxTopOfStack = 12;
\r
151 *pxTopOfStack = 11;
\r
155 *pxTopOfStack = 10;
\r
179 *pxTopOfStack = ( uint32_t ) pvParameters;
\r
199 *pxTopOfStack = 16;
\r
203 *pxTopOfStack = 17;
\r
207 *pxTopOfStack = ulPortGetGBR();
\r
209 /* GBR = global base register.
\r
210 VBR = vector base register.
\r
211 TBR = jump table base register.
\r
212 R15 is the stack pointer. */
\r
214 return pxTopOfStack;
\r
216 /*-----------------------------------------------------------*/
\r
218 BaseType_t xPortStartScheduler( void )
\r
220 extern void vApplicationSetupTimerInterrupt( void );
\r
222 /* Call an application function to set up the timer that will generate the
\r
223 tick interrupt. This way the application can decide which peripheral to
\r
224 use. A demo application is provided to show a suitable example. */
\r
225 vApplicationSetupTimerInterrupt();
\r
227 /* Start the first task. This will only restore the standard registers and
\r
228 not the flop registers. This does not really matter though because the only
\r
229 flop register that is initialised to a particular value is fpscr, and it is
\r
230 only initialised to the current value, which will still be the current value
\r
231 when the first task starts executing. */
\r
232 trapa( portSTART_SCHEDULER_TRAP_NO );
\r
234 /* Should not get here. */
\r
237 /*-----------------------------------------------------------*/
\r
239 void vPortEndScheduler( void )
\r
241 /* Not implemented as there is nothing to return to. */
\r
243 /*-----------------------------------------------------------*/
\r
245 void vPortYield( void )
\r
247 int32_t lInterruptMask;
\r
249 /* Ensure the yield trap runs at the same priority as the other interrupts
\r
250 that can cause a context switch. */
\r
251 lInterruptMask = get_imask();
\r
253 /* taskYIELD() can only be called from a task, not an interrupt, so the
\r
254 current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and
\r
255 the mask can be set without risk of accidentally lowering the mask value. */
\r
256 set_imask( portKERNEL_INTERRUPT_PRIORITY );
\r
258 trapa( portYIELD_TRAP_NO );
\r
260 /* Restore the interrupt mask to whatever it was previously (when the
\r
261 function was entered). */
\r
262 set_imask( ( int ) lInterruptMask );
\r
264 /*-----------------------------------------------------------*/
\r
266 BaseType_t xPortUsesFloatingPoint( TaskHandle_t xTask )
\r
268 uint32_t *pulFlopBuffer;
\r
269 BaseType_t xReturn;
\r
270 extern void * volatile pxCurrentTCB;
\r
272 /* This function tells the kernel that the task referenced by xTask is
\r
273 going to use the floating point registers and therefore requires the
\r
274 floating point registers saved as part of its context. */
\r
276 /* Passing NULL as xTask is used to indicate that the calling task is the
\r
277 subject task - so pxCurrentTCB is the task handle. */
\r
278 if( xTask == NULL )
\r
280 xTask = ( TaskHandle_t ) pxCurrentTCB;
\r
283 /* Allocate a buffer large enough to hold all the flop registers. */
\r
284 pulFlopBuffer = ( uint32_t * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
\r
286 if( pulFlopBuffer != NULL )
\r
288 /* Start with the registers in a benign state. */
\r
289 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
\r
291 /* The first thing to get saved in the buffer is the FPSCR value -
\r
292 initialise this to the current FPSCR value. */
\r
293 *pulFlopBuffer = get_fpscr();
\r
295 /* Use the task tag to point to the flop buffer. Pass pointer to just
\r
296 above the buffer because the flop save routine uses a pre-decrement. */
\r
297 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
\r
307 /*-----------------------------------------------------------*/
\r