]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/V850ES/port.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Source / portable / IAR / V850ES / port.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /* Standard includes. */\r
97 #include <stdlib.h>\r
98 \r
99 /* Scheduler includes. */\r
100 #include "FreeRTOS.h"\r
101 #include "task.h"\r
102 \r
103 /* Critical nesting should be initialised to a non zero value so interrupts don't\r
104 accidentally get enabled before the scheduler is started. */\r
105 #define portINITIAL_CRITICAL_NESTING  (( StackType_t ) 10)\r
106 \r
107 /* The PSW value assigned to tasks when they start to run for the first time. */\r
108 #define portPSW           (( StackType_t ) 0x00000000)\r
109 \r
110 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
111 any details of its type. */\r
112 typedef void TCB_t;\r
113 extern volatile TCB_t * volatile pxCurrentTCB;\r
114 \r
115 /* Keeps track of the nesting level of critical sections. */\r
116 volatile StackType_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 /* Sets up the timer to generate the tick interrupt. */\r
120 static void prvSetupTimerInterrupt( void );\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
124 {\r
125         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = portPSW;                            /* Initial PSW value */\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = ( StackType_t ) 0x20202020;      /* Initial Value of R20 */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( StackType_t ) 0x21212121;      /* Initial Value of R21 */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R22 */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( StackType_t ) 0x23232323;      /* Initial Value of R23 */\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = ( StackType_t ) 0x24242424;      /* Initial Value of R24 */\r
140         pxTopOfStack--;\r
141 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)\r
142         *pxTopOfStack = ( StackType_t ) 0x25252525;      /* Initial Value of R25 */\r
143         pxTopOfStack--;\r
144 #endif /* configDATA_MODE */\r
145         *pxTopOfStack = ( StackType_t ) 0x26262626;      /* Initial Value of R26 */\r
146         pxTopOfStack--;\r
147         *pxTopOfStack = ( StackType_t ) 0x27272727;      /* Initial Value of R27 */\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = ( StackType_t ) 0x28282828;      /* Initial Value of R28 */\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = ( StackType_t ) 0x29292929;      /* Initial Value of R29 */\r
152         pxTopOfStack--;\r
153         *pxTopOfStack = ( StackType_t ) 0x30303030;      /* Initial Value of R30 */\r
154         pxTopOfStack--;         \r
155         *pxTopOfStack = ( StackType_t ) 0x19191919;      /* Initial Value of R19 */\r
156         pxTopOfStack--;\r
157         *pxTopOfStack = ( StackType_t ) 0x18181818;      /* Initial Value of R18 */\r
158         pxTopOfStack--;\r
159         *pxTopOfStack = ( StackType_t ) 0x17171717;      /* Initial Value of R17 */\r
160         pxTopOfStack--;\r
161         *pxTopOfStack = ( StackType_t ) 0x16161616;      /* Initial Value of R16 */\r
162         pxTopOfStack--;\r
163         *pxTopOfStack = ( StackType_t ) 0x15151515;      /* Initial Value of R15 */\r
164         pxTopOfStack--;\r
165         *pxTopOfStack = ( StackType_t ) 0x14141414;      /* Initial Value of R14 */\r
166         pxTopOfStack--;\r
167         *pxTopOfStack = ( StackType_t ) 0x13131313;      /* Initial Value of R13 */\r
168         pxTopOfStack--;\r
169         *pxTopOfStack = ( StackType_t ) 0x12121212;      /* Initial Value of R12 */\r
170         pxTopOfStack--;\r
171         *pxTopOfStack = ( StackType_t ) 0x11111111;      /* Initial Value of R11 */\r
172         pxTopOfStack--;\r
173         *pxTopOfStack = ( StackType_t ) 0x10101010;      /* Initial Value of R10 */\r
174         pxTopOfStack--;\r
175         *pxTopOfStack = ( StackType_t ) 0x99999999;      /* Initial Value of R09 */\r
176         pxTopOfStack--;\r
177         *pxTopOfStack = ( StackType_t ) 0x88888888;      /* Initial Value of R08 */\r
178         pxTopOfStack--;\r
179         *pxTopOfStack = ( StackType_t ) 0x77777777;      /* Initial Value of R07 */\r
180         pxTopOfStack--;\r
181         *pxTopOfStack = ( StackType_t ) 0x66666666;      /* Initial Value of R06 */\r
182         pxTopOfStack--;\r
183         *pxTopOfStack = ( StackType_t ) 0x55555555;      /* Initial Value of R05 */\r
184         pxTopOfStack--;\r
185 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1\r
186         *pxTopOfStack = ( StackType_t ) 0x44444444;      /* Initial Value of R04 */\r
187         pxTopOfStack--;\r
188 #endif /* configDATA_MODE */\r
189         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R02 */\r
190         pxTopOfStack--;\r
191         *pxTopOfStack = ( StackType_t ) pvParameters;    /* R1 is expected to hold the function parameter*/\r
192         pxTopOfStack--;\r
193         *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;        \r
194 \r
195         /*\r
196          * Return a pointer to the top of the stack we have generated so this can\r
197          * be stored in the task control block for the task.\r
198          */\r
199         return pxTopOfStack;\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 BaseType_t xPortStartScheduler( void )\r
204 {\r
205         /* Setup the hardware to generate the tick.  Interrupts are disabled when\r
206         this function is called. */\r
207         prvSetupTimerInterrupt();\r
208 \r
209         /* Restore the context of the first task that is going to run. */\r
210         vPortStart();\r
211 \r
212         /* Should not get here as the tasks are now running! */\r
213         return pdTRUE;\r
214 }\r
215 /*-----------------------------------------------------------*/\r
216 \r
217 void vPortEndScheduler( void )\r
218 {\r
219         /* It is unlikely that the V850ES/Fx3 port will get stopped.  If required simply\r
220         disable the tick interrupt here. */\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 /*\r
225  * Hardware initialisation to generate the RTOS tick.  This uses\r
226  */\r
227 static void prvSetupTimerInterrupt( void )\r
228 {\r
229         TM0CE     = 0;  /* TMM0 operation disable */\r
230         TM0EQMK0  = 1;  /* INTTM0EQ0 interrupt disable */\r
231         TM0EQIF0  = 0;  /* clear INTTM0EQ0 interrupt flag */\r
232 \r
233         #ifdef __IAR_V850ES_Fx3__\r
234         {\r
235                 TM0CMP0   = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1);    /* divided by 2 because peripherals only run at CPU_CLOCK/2 */\r
236         }\r
237         #else\r
238         {\r
239                 TM0CMP0   = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);  \r
240         }\r
241         #endif\r
242 \r
243         TM0EQIC0 &= 0xF8;\r
244         TM0CTL0   = 0x00;\r
245         TM0EQIF0 =  0;  /* clear INTTM0EQ0 interrupt flag */\r
246         TM0EQMK0 =  0;  /* INTTM0EQ0 interrupt enable */\r
247         TM0CE =     1;  /* TMM0 operation enable */\r
248 }\r
249 /*-----------------------------------------------------------*/\r
250 \r
251 \r