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