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