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