]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/RX600/port.c
Add additional critical section to the default tickless implementations.
[freertos] / FreeRTOS / Source / portable / IAR / RX600 / port.c
1 /*\r
2     FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 /*-----------------------------------------------------------\r
66  * Implementation of functions defined in portable.h for the SH2A port.\r
67  *----------------------------------------------------------*/\r
68 \r
69 /* Scheduler includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 \r
73 /* Library includes. */\r
74 #include "string.h"\r
75 \r
76 /* Hardware specifics. */\r
77 #include <iorx62n.h>\r
78 \r
79 /*-----------------------------------------------------------*/\r
80 \r
81 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore\r
82 PSW is set with U and I set, and PM and IPL clear. */\r
83 #define portINITIAL_PSW  ( ( portSTACK_TYPE ) 0x00030000 )\r
84 #define portINITIAL_FPSW        ( ( portSTACK_TYPE ) 0x00000100 )\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /*\r
89  * Function to start the first task executing - written in asm code as direct\r
90  * access to registers is required.\r
91  */\r
92 extern void prvStartFirstTask( void );\r
93 \r
94 /*\r
95  * The tick ISR handler.  The peripheral used is configured by the application\r
96  * via a hook/callback function.\r
97  */\r
98 __interrupt void vTickISR( void );\r
99 \r
100 /*-----------------------------------------------------------*/\r
101 \r
102 extern void *pxCurrentTCB;\r
103 \r
104 /*-----------------------------------------------------------*/\r
105 \r
106 /*\r
107  * See header file for description.\r
108  */\r
109 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
110 {\r
111         /* R0 is not included as it is the stack pointer. */\r
112 \r
113         *pxTopOfStack = 0x00;\r
114         pxTopOfStack--;\r
115         *pxTopOfStack = portINITIAL_PSW;\r
116         pxTopOfStack--;\r
117         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
118 \r
119         /* When debugging it can be useful if every register is set to a known\r
120         value.  Otherwise code space can be saved by just setting the registers\r
121         that need to be set. */\r
122         #ifdef USE_FULL_REGISTER_INITIALISATION\r
123         {\r
124                 pxTopOfStack--;\r
125                 *pxTopOfStack = 0xffffffff;     /* r15. */\r
126                 pxTopOfStack--;\r
127                 *pxTopOfStack = 0xeeeeeeee;\r
128                 pxTopOfStack--;\r
129                 *pxTopOfStack = 0xdddddddd;\r
130                 pxTopOfStack--;\r
131                 *pxTopOfStack = 0xcccccccc;\r
132                 pxTopOfStack--;\r
133                 *pxTopOfStack = 0xbbbbbbbb;\r
134                 pxTopOfStack--;\r
135                 *pxTopOfStack = 0xaaaaaaaa;\r
136                 pxTopOfStack--;\r
137                 *pxTopOfStack = 0x99999999;\r
138                 pxTopOfStack--;\r
139                 *pxTopOfStack = 0x88888888;\r
140                 pxTopOfStack--;\r
141                 *pxTopOfStack = 0x77777777;\r
142                 pxTopOfStack--;\r
143                 *pxTopOfStack = 0x66666666;\r
144                 pxTopOfStack--;\r
145                 *pxTopOfStack = 0x55555555;\r
146                 pxTopOfStack--;\r
147                 *pxTopOfStack = 0x44444444;\r
148                 pxTopOfStack--;\r
149                 *pxTopOfStack = 0x33333333;\r
150                 pxTopOfStack--;\r
151                 *pxTopOfStack = 0x22222222;\r
152                 pxTopOfStack--;\r
153         }\r
154         #else\r
155         {\r
156                 pxTopOfStack -= 15;\r
157         }\r
158         #endif\r
159 \r
160         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R1 */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = portINITIAL_FPSW;\r
163         pxTopOfStack--;\r
164         *pxTopOfStack = 0x12345678; /* Accumulator. */\r
165         pxTopOfStack--;\r
166         *pxTopOfStack = 0x87654321; /* Accumulator. */\r
167 \r
168         return pxTopOfStack;\r
169 }\r
170 /*-----------------------------------------------------------*/\r
171 \r
172 portBASE_TYPE xPortStartScheduler( void )\r
173 {\r
174 extern void vApplicationSetupTimerInterrupt( void );\r
175 \r
176         /* Use pxCurrentTCB just so it does not get optimised away. */\r
177         if( pxCurrentTCB != NULL )\r
178         {\r
179                 /* Call an application function to set up the timer that will generate the\r
180                 tick interrupt.  This way the application can decide which peripheral to\r
181                 use.  A demo application is provided to show a suitable example. */\r
182                 vApplicationSetupTimerInterrupt();\r
183 \r
184                 /* Enable the software interrupt. */\r
185                 _IEN( _ICU_SWINT ) = 1;\r
186 \r
187                 /* Ensure the software interrupt is clear. */\r
188                 _IR( _ICU_SWINT ) = 0;\r
189 \r
190                 /* Ensure the software interrupt is set to the kernel priority. */\r
191                 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;\r
192 \r
193                 /* Start the first task. */\r
194                 prvStartFirstTask();\r
195         }\r
196 \r
197         /* Should not get here. */\r
198         return pdFAIL;\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 #pragma vector = configTICK_VECTOR\r
203 __interrupt void vTickISR( void )\r
204 {\r
205         /* Re-enable interrupts. */\r
206         __enable_interrupt();\r
207 \r
208         /* Increment the tick, and perform any processing the new tick value\r
209         necessitates. */\r
210         __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );\r
211         {\r
212                 if( xTaskIncrementTick() != pdFALSE )\r
213                 {\r
214                         taskYIELD();\r
215                 }\r
216         }\r
217         __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );\r
218 }\r
219 /*-----------------------------------------------------------*/\r
220 \r
221 void vPortEndScheduler( void )\r
222 {\r
223         /* Not implemented as there is nothing to return to. */\r
224 }\r
225 /*-----------------------------------------------------------*/\r
226 \r
227 \r
228 \r