]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/RXv2/port.c
Update version number in readiness for V10.2.0 release.
[freertos] / FreeRTOS / Source / portable / IAR / RXv2 / port.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 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 /* Hardware specifics. */\r
40 #include <machine.h>\r
41 \r
42 /*-----------------------------------------------------------*/\r
43 \r
44 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore\r
45 PSW is set with U and I set, and PM and IPL clear. */\r
46 #define portINITIAL_PSW  ( ( StackType_t ) 0x00030000 )\r
47 #define portINITIAL_FPSW        ( ( StackType_t ) 0x00000100 )\r
48 \r
49 /*-----------------------------------------------------------*/\r
50 \r
51 /*\r
52  * Function to start the first task executing - written in asm code as direct\r
53  * access to registers is required.\r
54  */\r
55 extern void prvStartFirstTask( void );\r
56 \r
57 /*\r
58  * The tick ISR handler.  The peripheral used is configured by the application\r
59  * via a hook/callback function.\r
60  */\r
61 __interrupt void vTickISR( void );\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 \r
65 extern void *pxCurrentTCB;\r
66 \r
67 /*-----------------------------------------------------------*/\r
68 \r
69 /*\r
70  * See header file for description.\r
71  */\r
72 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
73 {\r
74         /* R0 is not included as it is the stack pointer. */\r
75 \r
76         *pxTopOfStack = 0x00;\r
77         pxTopOfStack--;\r
78         *pxTopOfStack = portINITIAL_PSW;\r
79         pxTopOfStack--;\r
80         *pxTopOfStack = ( StackType_t ) pxCode;\r
81 \r
82         /* When debugging it can be useful if every register is set to a known\r
83         value.  Otherwise code space can be saved by just setting the registers\r
84         that need to be set. */\r
85         #ifdef USE_FULL_REGISTER_INITIALISATION\r
86         {\r
87                 pxTopOfStack--;\r
88                 *pxTopOfStack = 0xffffffff;     /* r15. */\r
89                 pxTopOfStack--;\r
90                 *pxTopOfStack = 0xeeeeeeee;\r
91                 pxTopOfStack--;\r
92                 *pxTopOfStack = 0xdddddddd;\r
93                 pxTopOfStack--;\r
94                 *pxTopOfStack = 0xcccccccc;\r
95                 pxTopOfStack--;\r
96                 *pxTopOfStack = 0xbbbbbbbb;\r
97                 pxTopOfStack--;\r
98                 *pxTopOfStack = 0xaaaaaaaa;\r
99                 pxTopOfStack--;\r
100                 *pxTopOfStack = 0x99999999;\r
101                 pxTopOfStack--;\r
102                 *pxTopOfStack = 0x88888888;\r
103                 pxTopOfStack--;\r
104                 *pxTopOfStack = 0x77777777;\r
105                 pxTopOfStack--;\r
106                 *pxTopOfStack = 0x66666666;\r
107                 pxTopOfStack--;\r
108                 *pxTopOfStack = 0x55555555;\r
109                 pxTopOfStack--;\r
110                 *pxTopOfStack = 0x44444444;\r
111                 pxTopOfStack--;\r
112                 *pxTopOfStack = 0x33333333;\r
113                 pxTopOfStack--;\r
114                 *pxTopOfStack = 0x22222222;\r
115                 pxTopOfStack--;\r
116         }\r
117         #else\r
118         {\r
119                 pxTopOfStack -= 15;\r
120         }\r
121         #endif\r
122 \r
123         *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = portINITIAL_FPSW;\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = 0x11111111; /* Accumulator 0. */\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = 0x22222222; /* Accumulator 0. */\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = 0x33333333; /* Accumulator 0. */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = 0x44444444; /* Accumulator 1. */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = 0x55555555; /* Accumulator 1. */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = 0x66666666; /* Accumulator 1. */\r
138 \r
139         return pxTopOfStack;\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 BaseType_t xPortStartScheduler( void )\r
144 {\r
145 extern void vApplicationSetupTimerInterrupt( void );\r
146 \r
147         /* Use pxCurrentTCB just so it does not get optimised away. */\r
148         if( pxCurrentTCB != NULL )\r
149         {\r
150                 /* Call an application function to set up the timer that will generate the\r
151                 tick interrupt.  This way the application can decide which peripheral to\r
152                 use.  A demo application is provided to show a suitable example. */\r
153                 vApplicationSetupTimerInterrupt();\r
154 \r
155                 /* Enable the software interrupt. */\r
156                 _IEN( _ICU_SWINT ) = 1;\r
157 \r
158                 /* Ensure the software interrupt is clear. */\r
159                 _IR( _ICU_SWINT ) = 0;\r
160 \r
161                 /* Ensure the software interrupt is set to the kernel priority. */\r
162                 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;\r
163 \r
164                 /* Start the first task. */\r
165                 prvStartFirstTask();\r
166         }\r
167 \r
168         /* Should not get here. */\r
169         return pdFAIL;\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 #pragma vector = configTICK_VECTOR\r
174 __interrupt void vTickISR( void )\r
175 {\r
176         /* Re-enable interrupts. */\r
177         __enable_interrupt();\r
178 \r
179         /* Increment the tick, and perform any processing the new tick value\r
180         necessitates. */\r
181         __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );\r
182         {\r
183                 if( xTaskIncrementTick() != pdFALSE )\r
184                 {\r
185                         taskYIELD();\r
186                 }\r
187         }\r
188         __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );\r
189 }\r
190 /*-----------------------------------------------------------*/\r
191 \r
192 void vPortEndScheduler( void )\r
193 {\r
194         /* Not implemented in ports where there is nothing to return to.\r
195         Artificially force an assert. */\r
196         configASSERT( pxCurrentTCB == NULL );\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 \r
201 \r