]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Renesas/SH2A_FPU/port.c
Prepare for V7.3.0 release.
[freertos] / FreeRTOS / Source / portable / Renesas / SH2A_FPU / port.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \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
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\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
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \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
32     >>>NOTE<<< The modification to the GPL is included to allow you to\r
33     distribute a combined work that includes FreeRTOS without being obliged to\r
34     provide the source code for proprietary components outside of the FreeRTOS\r
35     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
36     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
37     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
38     more details. You should have received a copy of the GNU General Public\r
39     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
40     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
41     by writing to Richard Barry, contact details for whom are available on the\r
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \r
62     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
63     the code with commercial support, indemnification, and middleware, under \r
64     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
65     provide a safety engineered and independently SIL3 certified version under \r
66     the SafeRTOS brand: http://www.SafeRTOS.com.\r
67 */\r
68 \r
69 /*-----------------------------------------------------------\r
70  * Implementation of functions defined in portable.h for the SH2A port.\r
71  *----------------------------------------------------------*/\r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 \r
77 /* Library includes. */\r
78 #include "string.h"\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /* The SR assigned to a newly created task.  The only important thing in this\r
83 value is for all interrupts to be enabled. */\r
84 #define portINITIAL_SR                          ( 0UL )\r
85 \r
86 /* Dimensions the array into which the floating point context is saved.  \r
87 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4\r
88 bytes big.  If this number is changed then the 72 in portasm.src also needs\r
89 changing. */\r
90 #define portFLOP_REGISTERS_TO_STORE     ( 18 )\r
91 #define portFLOP_STORAGE_SIZE           ( portFLOP_REGISTERS_TO_STORE * 4 )\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 /*\r
96  * The TRAPA handler used to force a context switch.\r
97  */\r
98 void vPortYield( void );\r
99 \r
100 /*\r
101  * Function to start the first task executing - defined in portasm.src.\r
102  */\r
103 extern void vPortStartFirstTask( void );\r
104 \r
105 /*\r
106  * Obtains the current GBR value - defined in portasm.src.\r
107  */\r
108 extern unsigned long ulPortGetGBR( void );\r
109 \r
110 /*-----------------------------------------------------------*/\r
111 \r
112 /* \r
113  * See header file for description. \r
114  */\r
115 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
116 {\r
117         /* Mark the end of the stack - used for debugging only and can be removed. */\r
118         *pxTopOfStack = 0x11111111UL;\r
119         pxTopOfStack--;\r
120         *pxTopOfStack = 0x22222222UL;\r
121         pxTopOfStack--;\r
122         *pxTopOfStack = 0x33333333UL;\r
123         pxTopOfStack--;\r
124 \r
125         /* SR. */\r
126         *pxTopOfStack = portINITIAL_SR; \r
127         pxTopOfStack--;\r
128         \r
129         /* PC. */\r
130         *pxTopOfStack = ( unsigned long ) pxCode;\r
131         pxTopOfStack--;\r
132         \r
133         /* PR. */\r
134         *pxTopOfStack = 15;\r
135         pxTopOfStack--;\r
136         \r
137         /* 14. */\r
138         *pxTopOfStack = 14;\r
139         pxTopOfStack--;\r
140 \r
141         /* R13. */\r
142         *pxTopOfStack = 13;\r
143         pxTopOfStack--;\r
144 \r
145         /* R12. */\r
146         *pxTopOfStack = 12;\r
147         pxTopOfStack--;\r
148 \r
149         /* R11. */\r
150         *pxTopOfStack = 11;\r
151         pxTopOfStack--;\r
152 \r
153         /* R10. */\r
154         *pxTopOfStack = 10;\r
155         pxTopOfStack--;\r
156 \r
157         /* R9. */\r
158         *pxTopOfStack = 9;\r
159         pxTopOfStack--;\r
160 \r
161         /* R8. */\r
162         *pxTopOfStack = 8;\r
163         pxTopOfStack--;\r
164 \r
165         /* R7. */\r
166         *pxTopOfStack = 7;\r
167         pxTopOfStack--;\r
168 \r
169         /* R6. */\r
170         *pxTopOfStack = 6;\r
171         pxTopOfStack--;\r
172 \r
173         /* R5. */\r
174         *pxTopOfStack = 5;\r
175         pxTopOfStack--;\r
176 \r
177         /* R4. */\r
178         *pxTopOfStack = ( unsigned long ) pvParameters;\r
179         pxTopOfStack--;\r
180 \r
181         /* R3. */\r
182         *pxTopOfStack = 3;\r
183         pxTopOfStack--;\r
184 \r
185         /* R2. */\r
186         *pxTopOfStack = 2;\r
187         pxTopOfStack--;\r
188 \r
189         /* R1. */\r
190         *pxTopOfStack = 1;\r
191         pxTopOfStack--;\r
192         \r
193         /* R0 */\r
194         *pxTopOfStack = 0;\r
195         pxTopOfStack--;\r
196         \r
197         /* MACL. */\r
198         *pxTopOfStack = 16;\r
199         pxTopOfStack--;\r
200         \r
201         /* MACH. */\r
202         *pxTopOfStack = 17;\r
203         pxTopOfStack--;\r
204         \r
205         /* GBR. */\r
206         *pxTopOfStack = ulPortGetGBR();\r
207         \r
208         /* GBR = global base register.\r
209            VBR = vector base register.\r
210            TBR = jump table base register.\r
211            R15 is the stack pointer. */\r
212 \r
213         return pxTopOfStack;\r
214 }\r
215 /*-----------------------------------------------------------*/\r
216 \r
217 portBASE_TYPE xPortStartScheduler( void )\r
218 {\r
219 extern void vApplicationSetupTimerInterrupt( void );\r
220 \r
221         /* Call an application function to set up the timer that will generate the\r
222         tick interrupt.  This way the application can decide which peripheral to \r
223         use.  A demo application is provided to show a suitable example. */\r
224         vApplicationSetupTimerInterrupt();\r
225 \r
226         /* Start the first task.  This will only restore the standard registers and\r
227         not the flop registers.  This does not really matter though because the only\r
228         flop register that is initialised to a particular value is fpscr, and it is\r
229         only initialised to the current value, which will still be the current value\r
230         when the first task starts executing. */\r
231         trapa( portSTART_SCHEDULER_TRAP_NO );\r
232 \r
233         /* Should not get here. */\r
234         return pdFAIL;\r
235 }\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 void vPortEndScheduler( void )\r
239 {\r
240         /* Not implemented as there is nothing to return to. */\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 void vPortYield( void )\r
245 {\r
246 long lInterruptMask;\r
247 \r
248         /* Ensure the yield trap runs at the same priority as the other interrupts\r
249         that can cause a context switch. */\r
250         lInterruptMask = get_imask();\r
251 \r
252         /* taskYIELD() can only be called from a task, not an interrupt, so the\r
253         current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and\r
254         the mask can be set without risk of accidentally lowering the mask value. */    \r
255         set_imask( portKERNEL_INTERRUPT_PRIORITY );\r
256         \r
257         trapa( portYIELD_TRAP_NO );\r
258         \r
259         /* Restore the interrupt mask to whatever it was previously (when the\r
260         function was entered). */\r
261         set_imask( ( int ) lInterruptMask );\r
262 }\r
263 /*-----------------------------------------------------------*/\r
264 \r
265 portBASE_TYPE xPortUsesFloatingPoint( xTaskHandle xTask )\r
266 {\r
267 unsigned long *pulFlopBuffer;\r
268 portBASE_TYPE xReturn;\r
269 extern void * volatile pxCurrentTCB;\r
270 \r
271         /* This function tells the kernel that the task referenced by xTask is\r
272         going to use the floating point registers and therefore requires the\r
273         floating point registers saved as part of its context. */\r
274 \r
275         /* Passing NULL as xTask is used to indicate that the calling task is the\r
276         subject task - so pxCurrentTCB is the task handle. */\r
277         if( xTask == NULL )\r
278         {\r
279                 xTask = ( xTaskHandle ) pxCurrentTCB;\r
280         }\r
281 \r
282         /* Allocate a buffer large enough to hold all the flop registers. */\r
283         pulFlopBuffer = ( unsigned long * ) pvPortMalloc( portFLOP_STORAGE_SIZE );\r
284         \r
285         if( pulFlopBuffer != NULL )\r
286         {\r
287                 /* Start with the registers in a benign state. */\r
288                 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );\r
289                 \r
290                 /* The first thing to get saved in the buffer is the FPSCR value -\r
291                 initialise this to the current FPSCR value. */\r
292                 *pulFlopBuffer = get_fpscr();\r
293                 \r
294                 /* Use the task tag to point to the flop buffer.  Pass pointer to just \r
295                 above the buffer because the flop save routine uses a pre-decrement. */\r
296                 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );                \r
297                 xReturn = pdPASS;\r
298         }\r
299         else\r
300         {\r
301                 xReturn = pdFAIL;\r
302         }\r
303         \r
304         return xReturn;\r
305 }\r
306 /*-----------------------------------------------------------*/\r
307 \r
308 \r