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