]> begriffs open source - freertos/blob - portable/IAR/RXv2/port.c
Add SPDX-License-Identifier: MIT to MIT licensed files.
[freertos] / portable / IAR / RXv2 / port.c
1 /*\r
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 /*-----------------------------------------------------------\r
30  * Implementation of functions defined in portable.h for the SH2A port.\r
31  *----------------------------------------------------------*/\r
32 \r
33 /* Scheduler includes. */\r
34 #include "FreeRTOS.h"\r
35 #include "task.h"\r
36 \r
37 /* Library includes. */\r
38 #include "string.h"\r
39 \r
40 /* Hardware specifics. */\r
41 #include <machine.h>\r
42 \r
43 /*-----------------------------------------------------------*/\r
44 \r
45 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore\r
46 PSW is set with U and I set, and PM and IPL clear. */\r
47 #define portINITIAL_PSW  ( ( StackType_t ) 0x00030000 )\r
48 #define portINITIAL_FPSW        ( ( StackType_t ) 0x00000100 )\r
49 \r
50 /*-----------------------------------------------------------*/\r
51 \r
52 /*\r
53  * Function to start the first task executing - written in asm code as direct\r
54  * access to registers is required.\r
55  */\r
56 extern void prvStartFirstTask( void );\r
57 \r
58 /*\r
59  * The tick ISR handler.  The peripheral used is configured by the application\r
60  * via a hook/callback function.\r
61  */\r
62 __interrupt void vTickISR( void );\r
63 \r
64 /*-----------------------------------------------------------*/\r
65 \r
66 extern void *pxCurrentTCB;\r
67 \r
68 /*-----------------------------------------------------------*/\r
69 \r
70 /*\r
71  * See header file for description.\r
72  */\r
73 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
74 {\r
75         /* R0 is not included as it is the stack pointer. */\r
76 \r
77         *pxTopOfStack = 0x00;\r
78         pxTopOfStack--;\r
79         *pxTopOfStack = portINITIAL_PSW;\r
80         pxTopOfStack--;\r
81         *pxTopOfStack = ( StackType_t ) pxCode;\r
82 \r
83         /* When debugging it can be useful if every register is set to a known\r
84         value.  Otherwise code space can be saved by just setting the registers\r
85         that need to be set. */\r
86         #ifdef USE_FULL_REGISTER_INITIALISATION\r
87         {\r
88                 pxTopOfStack--;\r
89                 *pxTopOfStack = 0xffffffff;     /* r15. */\r
90                 pxTopOfStack--;\r
91                 *pxTopOfStack = 0xeeeeeeee;\r
92                 pxTopOfStack--;\r
93                 *pxTopOfStack = 0xdddddddd;\r
94                 pxTopOfStack--;\r
95                 *pxTopOfStack = 0xcccccccc;\r
96                 pxTopOfStack--;\r
97                 *pxTopOfStack = 0xbbbbbbbb;\r
98                 pxTopOfStack--;\r
99                 *pxTopOfStack = 0xaaaaaaaa;\r
100                 pxTopOfStack--;\r
101                 *pxTopOfStack = 0x99999999;\r
102                 pxTopOfStack--;\r
103                 *pxTopOfStack = 0x88888888;\r
104                 pxTopOfStack--;\r
105                 *pxTopOfStack = 0x77777777;\r
106                 pxTopOfStack--;\r
107                 *pxTopOfStack = 0x66666666;\r
108                 pxTopOfStack--;\r
109                 *pxTopOfStack = 0x55555555;\r
110                 pxTopOfStack--;\r
111                 *pxTopOfStack = 0x44444444;\r
112                 pxTopOfStack--;\r
113                 *pxTopOfStack = 0x33333333;\r
114                 pxTopOfStack--;\r
115                 *pxTopOfStack = 0x22222222;\r
116                 pxTopOfStack--;\r
117         }\r
118         #else\r
119         {\r
120                 pxTopOfStack -= 15;\r
121         }\r
122         #endif\r
123 \r
124         *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */\r
125         pxTopOfStack--;\r
126         *pxTopOfStack = portINITIAL_FPSW;\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = 0x11111111; /* Accumulator 0. */\r
129         pxTopOfStack--;\r
130         *pxTopOfStack = 0x22222222; /* Accumulator 0. */\r
131         pxTopOfStack--;\r
132         *pxTopOfStack = 0x33333333; /* Accumulator 0. */\r
133         pxTopOfStack--;\r
134         *pxTopOfStack = 0x44444444; /* Accumulator 1. */\r
135         pxTopOfStack--;\r
136         *pxTopOfStack = 0x55555555; /* Accumulator 1. */\r
137         pxTopOfStack--;\r
138         *pxTopOfStack = 0x66666666; /* Accumulator 1. */\r
139 \r
140         return pxTopOfStack;\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 BaseType_t xPortStartScheduler( void )\r
145 {\r
146 extern void vApplicationSetupTimerInterrupt( void );\r
147 \r
148         /* Use pxCurrentTCB just so it does not get optimised away. */\r
149         if( pxCurrentTCB != NULL )\r
150         {\r
151                 /* Call an application function to set up the timer that will generate the\r
152                 tick interrupt.  This way the application can decide which peripheral to\r
153                 use.  A demo application is provided to show a suitable example. */\r
154                 vApplicationSetupTimerInterrupt();\r
155 \r
156                 /* Enable the software interrupt. */\r
157                 _IEN( _ICU_SWINT ) = 1;\r
158 \r
159                 /* Ensure the software interrupt is clear. */\r
160                 _IR( _ICU_SWINT ) = 0;\r
161 \r
162                 /* Ensure the software interrupt is set to the kernel priority. */\r
163                 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;\r
164 \r
165                 /* Start the first task. */\r
166                 prvStartFirstTask();\r
167         }\r
168 \r
169         /* Should not get here. */\r
170         return pdFAIL;\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 #pragma vector = configTICK_VECTOR\r
175 __interrupt void vTickISR( void )\r
176 {\r
177         /* Re-enable interrupts. */\r
178         __enable_interrupt();\r
179 \r
180         /* Increment the tick, and perform any processing the new tick value\r
181         necessitates. */\r
182         __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );\r
183         {\r
184                 if( xTaskIncrementTick() != pdFALSE )\r
185                 {\r
186                         taskYIELD();\r
187                 }\r
188         }\r
189         __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );\r
190 }\r
191 /*-----------------------------------------------------------*/\r
192 \r
193 void vPortEndScheduler( void )\r
194 {\r
195         /* Not implemented in ports where there is nothing to return to.\r
196         Artificially force an assert. */\r
197         configASSERT( pxCurrentTCB == NULL );\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 \r
202 \r