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