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