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