]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Renesas/SH2A_FPU/port.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / Renesas / SH2A_FPU / port.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*-----------------------------------------------------------\r
29  * Implementation of functions defined in portable.h for the SH2A port.\r
30  *----------------------------------------------------------*/\r
31 \r
32 /* Scheduler includes. */\r
33 #include "FreeRTOS.h"\r
34 #include "task.h"\r
35 \r
36 /* Library includes. */\r
37 #include "string.h"\r
38 \r
39 /*-----------------------------------------------------------*/\r
40 \r
41 /* The SR assigned to a newly created task.  The only important thing in this\r
42 value is for all interrupts to be enabled. */\r
43 #define portINITIAL_SR                          ( 0UL )\r
44 \r
45 /* Dimensions the array into which the floating point context is saved.\r
46 Allocate enough space for FPR0 to FPR15, FPUL and FPSCR, each of which is 4\r
47 bytes big.  If this number is changed then the 72 in portasm.src also needs\r
48 changing. */\r
49 #define portFLOP_REGISTERS_TO_STORE     ( 18 )\r
50 #define portFLOP_STORAGE_SIZE           ( portFLOP_REGISTERS_TO_STORE * 4 )\r
51 \r
52 #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )\r
53         #error configSUPPORT_DYNAMIC_ALLOCATION must be 1 to use this port.\r
54 #endif\r
55 \r
56 /*-----------------------------------------------------------*/\r
57 \r
58 /*\r
59  * The TRAPA handler used to force a context switch.\r
60  */\r
61 void vPortYield( void );\r
62 \r
63 /*\r
64  * Function to start the first task executing - defined in portasm.src.\r
65  */\r
66 extern void vPortStartFirstTask( void );\r
67 \r
68 /*\r
69  * Obtains the current GBR value - defined in portasm.src.\r
70  */\r
71 extern uint32_t ulPortGetGBR( void );\r
72 \r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /*\r
76  * See header file for description.\r
77  */\r
78 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
79 {\r
80         /* Mark the end of the stack - used for debugging only and can be removed. */\r
81         *pxTopOfStack = 0x11111111UL;\r
82         pxTopOfStack--;\r
83         *pxTopOfStack = 0x22222222UL;\r
84         pxTopOfStack--;\r
85         *pxTopOfStack = 0x33333333UL;\r
86         pxTopOfStack--;\r
87 \r
88         /* SR. */\r
89         *pxTopOfStack = portINITIAL_SR;\r
90         pxTopOfStack--;\r
91 \r
92         /* PC. */\r
93         *pxTopOfStack = ( uint32_t ) pxCode;\r
94         pxTopOfStack--;\r
95 \r
96         /* PR. */\r
97         *pxTopOfStack = 15;\r
98         pxTopOfStack--;\r
99 \r
100         /* 14. */\r
101         *pxTopOfStack = 14;\r
102         pxTopOfStack--;\r
103 \r
104         /* R13. */\r
105         *pxTopOfStack = 13;\r
106         pxTopOfStack--;\r
107 \r
108         /* R12. */\r
109         *pxTopOfStack = 12;\r
110         pxTopOfStack--;\r
111 \r
112         /* R11. */\r
113         *pxTopOfStack = 11;\r
114         pxTopOfStack--;\r
115 \r
116         /* R10. */\r
117         *pxTopOfStack = 10;\r
118         pxTopOfStack--;\r
119 \r
120         /* R9. */\r
121         *pxTopOfStack = 9;\r
122         pxTopOfStack--;\r
123 \r
124         /* R8. */\r
125         *pxTopOfStack = 8;\r
126         pxTopOfStack--;\r
127 \r
128         /* R7. */\r
129         *pxTopOfStack = 7;\r
130         pxTopOfStack--;\r
131 \r
132         /* R6. */\r
133         *pxTopOfStack = 6;\r
134         pxTopOfStack--;\r
135 \r
136         /* R5. */\r
137         *pxTopOfStack = 5;\r
138         pxTopOfStack--;\r
139 \r
140         /* R4. */\r
141         *pxTopOfStack = ( uint32_t ) pvParameters;\r
142         pxTopOfStack--;\r
143 \r
144         /* R3. */\r
145         *pxTopOfStack = 3;\r
146         pxTopOfStack--;\r
147 \r
148         /* R2. */\r
149         *pxTopOfStack = 2;\r
150         pxTopOfStack--;\r
151 \r
152         /* R1. */\r
153         *pxTopOfStack = 1;\r
154         pxTopOfStack--;\r
155 \r
156         /* R0 */\r
157         *pxTopOfStack = 0;\r
158         pxTopOfStack--;\r
159 \r
160         /* MACL. */\r
161         *pxTopOfStack = 16;\r
162         pxTopOfStack--;\r
163 \r
164         /* MACH. */\r
165         *pxTopOfStack = 17;\r
166         pxTopOfStack--;\r
167 \r
168         /* GBR. */\r
169         *pxTopOfStack = ulPortGetGBR();\r
170 \r
171         /* GBR = global base register.\r
172            VBR = vector base register.\r
173            TBR = jump table base register.\r
174            R15 is the stack pointer. */\r
175 \r
176         return pxTopOfStack;\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 BaseType_t xPortStartScheduler( void )\r
181 {\r
182 extern void vApplicationSetupTimerInterrupt( void );\r
183 \r
184         /* Call an application function to set up the timer that will generate the\r
185         tick interrupt.  This way the application can decide which peripheral to\r
186         use.  A demo application is provided to show a suitable example. */\r
187         vApplicationSetupTimerInterrupt();\r
188 \r
189         /* Start the first task.  This will only restore the standard registers and\r
190         not the flop registers.  This does not really matter though because the only\r
191         flop register that is initialised to a particular value is fpscr, and it is\r
192         only initialised to the current value, which will still be the current value\r
193         when the first task starts executing. */\r
194         trapa( portSTART_SCHEDULER_TRAP_NO );\r
195 \r
196         /* Should not get here. */\r
197         return pdFAIL;\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 void vPortEndScheduler( void )\r
202 {\r
203         /* Not implemented as there is nothing to return to. */\r
204 }\r
205 /*-----------------------------------------------------------*/\r
206 \r
207 void vPortYield( void )\r
208 {\r
209 int32_t lInterruptMask;\r
210 \r
211         /* Ensure the yield trap runs at the same priority as the other interrupts\r
212         that can cause a context switch. */\r
213         lInterruptMask = get_imask();\r
214 \r
215         /* taskYIELD() can only be called from a task, not an interrupt, so the\r
216         current interrupt mask can only be 0 or portKERNEL_INTERRUPT_PRIORITY and\r
217         the mask can be set without risk of accidentally lowering the mask value. */\r
218         set_imask( portKERNEL_INTERRUPT_PRIORITY );\r
219 \r
220         trapa( portYIELD_TRAP_NO );\r
221 \r
222         /* Restore the interrupt mask to whatever it was previously (when the\r
223         function was entered). */\r
224         set_imask( ( int ) lInterruptMask );\r
225 }\r
226 /*-----------------------------------------------------------*/\r
227 \r
228 BaseType_t xPortUsesFloatingPoint( TaskHandle_t xTask )\r
229 {\r
230 uint32_t *pulFlopBuffer;\r
231 BaseType_t xReturn;\r
232 extern void * volatile pxCurrentTCB;\r
233 \r
234         /* This function tells the kernel that the task referenced by xTask is\r
235         going to use the floating point registers and therefore requires the\r
236         floating point registers saved as part of its context. */\r
237 \r
238         /* Passing NULL as xTask is used to indicate that the calling task is the\r
239         subject task - so pxCurrentTCB is the task handle. */\r
240         if( xTask == NULL )\r
241         {\r
242                 xTask = ( TaskHandle_t ) pxCurrentTCB;\r
243         }\r
244 \r
245         /* Allocate a buffer large enough to hold all the flop registers. */\r
246         pulFlopBuffer = ( uint32_t * ) pvPortMalloc( portFLOP_STORAGE_SIZE );\r
247 \r
248         if( pulFlopBuffer != NULL )\r
249         {\r
250                 /* Start with the registers in a benign state. */\r
251                 memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );\r
252 \r
253                 /* The first thing to get saved in the buffer is the FPSCR value -\r
254                 initialise this to the current FPSCR value. */\r
255                 *pulFlopBuffer = get_fpscr();\r
256 \r
257                 /* Use the task tag to point to the flop buffer.  Pass pointer to just\r
258                 above the buffer because the flop save routine uses a pre-decrement. */\r
259                 vTaskSetApplicationTaskTag( xTask, ( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );\r
260                 xReturn = pdPASS;\r
261         }\r
262         else\r
263         {\r
264                 xReturn = pdFAIL;\r
265         }\r
266 \r
267         return xReturn;\r
268 }\r
269 /*-----------------------------------------------------------*/\r
270 \r
271 \r