]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/V850ES/port.c
Update version numbers to V7.4.1.
[freertos] / FreeRTOS / Source / portable / IAR / V850ES / port.c
1 /*\r
2     FreeRTOS V7.4.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /* Standard includes. */\r
76 #include <stdlib.h>\r
77 \r
78 /* Scheduler includes. */\r
79 #include "FreeRTOS.h"\r
80 #include "task.h"\r
81 \r
82 /* Critical nesting should be initialised to a non zero value so interrupts don't\r
83 accidentally get enabled before the scheduler is started. */\r
84 #define portINITIAL_CRITICAL_NESTING  (( portSTACK_TYPE ) 10)\r
85 \r
86 /* The PSW value assigned to tasks when they start to run for the first time. */\r
87 #define portPSW           (( portSTACK_TYPE ) 0x00000000)\r
88 \r
89 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
90 any details of its type. */\r
91 typedef void tskTCB;\r
92 extern volatile tskTCB * volatile pxCurrentTCB;\r
93 \r
94 /* Keeps track of the nesting level of critical sections. */\r
95 volatile portSTACK_TYPE usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
96 /*-----------------------------------------------------------*/\r
97 \r
98 /* Sets up the timer to generate the tick interrupt. */\r
99 static void prvSetupTimerInterrupt( void );\r
100 \r
101 /*-----------------------------------------------------------*/\r
102 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
103 {\r
104         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;          /* Task function start address */\r
105         pxTopOfStack--;\r
106         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;          /* Task function start address */\r
107         pxTopOfStack--;\r
108         *pxTopOfStack = portPSW;                            /* Initial PSW value */\r
109         pxTopOfStack--;\r
110         *pxTopOfStack = ( portSTACK_TYPE ) 0x20202020;      /* Initial Value of R20 */\r
111         pxTopOfStack--;\r
112         *pxTopOfStack = ( portSTACK_TYPE ) 0x21212121;      /* Initial Value of R21 */\r
113         pxTopOfStack--;\r
114         *pxTopOfStack = ( portSTACK_TYPE ) 0x22222222;      /* Initial Value of R22 */\r
115         pxTopOfStack--;\r
116         *pxTopOfStack = ( portSTACK_TYPE ) 0x23232323;      /* Initial Value of R23 */\r
117         pxTopOfStack--;\r
118         *pxTopOfStack = ( portSTACK_TYPE ) 0x24242424;      /* Initial Value of R24 */\r
119         pxTopOfStack--;\r
120 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)\r
121         *pxTopOfStack = ( portSTACK_TYPE ) 0x25252525;      /* Initial Value of R25 */\r
122         pxTopOfStack--;\r
123 #endif /* configDATA_MODE */\r
124         *pxTopOfStack = ( portSTACK_TYPE ) 0x26262626;      /* Initial Value of R26 */\r
125         pxTopOfStack--;\r
126         *pxTopOfStack = ( portSTACK_TYPE ) 0x27272727;      /* Initial Value of R27 */\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = ( portSTACK_TYPE ) 0x28282828;      /* Initial Value of R28 */\r
129         pxTopOfStack--;\r
130         *pxTopOfStack = ( portSTACK_TYPE ) 0x29292929;      /* Initial Value of R29 */\r
131         pxTopOfStack--;\r
132         *pxTopOfStack = ( portSTACK_TYPE ) 0x30303030;      /* Initial Value of R30 */\r
133         pxTopOfStack--;         \r
134         *pxTopOfStack = ( portSTACK_TYPE ) 0x19191919;      /* Initial Value of R19 */\r
135         pxTopOfStack--;\r
136         *pxTopOfStack = ( portSTACK_TYPE ) 0x18181818;      /* Initial Value of R18 */\r
137         pxTopOfStack--;\r
138         *pxTopOfStack = ( portSTACK_TYPE ) 0x17171717;      /* Initial Value of R17 */\r
139         pxTopOfStack--;\r
140         *pxTopOfStack = ( portSTACK_TYPE ) 0x16161616;      /* Initial Value of R16 */\r
141         pxTopOfStack--;\r
142         *pxTopOfStack = ( portSTACK_TYPE ) 0x15151515;      /* Initial Value of R15 */\r
143         pxTopOfStack--;\r
144         *pxTopOfStack = ( portSTACK_TYPE ) 0x14141414;      /* Initial Value of R14 */\r
145         pxTopOfStack--;\r
146         *pxTopOfStack = ( portSTACK_TYPE ) 0x13131313;      /* Initial Value of R13 */\r
147         pxTopOfStack--;\r
148         *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;      /* Initial Value of R12 */\r
149         pxTopOfStack--;\r
150         *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111;      /* Initial Value of R11 */\r
151         pxTopOfStack--;\r
152         *pxTopOfStack = ( portSTACK_TYPE ) 0x10101010;      /* Initial Value of R10 */\r
153         pxTopOfStack--;\r
154         *pxTopOfStack = ( portSTACK_TYPE ) 0x99999999;      /* Initial Value of R09 */\r
155         pxTopOfStack--;\r
156         *pxTopOfStack = ( portSTACK_TYPE ) 0x88888888;      /* Initial Value of R08 */\r
157         pxTopOfStack--;\r
158         *pxTopOfStack = ( portSTACK_TYPE ) 0x77777777;      /* Initial Value of R07 */\r
159         pxTopOfStack--;\r
160         *pxTopOfStack = ( portSTACK_TYPE ) 0x66666666;      /* Initial Value of R06 */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = ( portSTACK_TYPE ) 0x55555555;      /* Initial Value of R05 */\r
163         pxTopOfStack--;\r
164 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1\r
165         *pxTopOfStack = ( portSTACK_TYPE ) 0x44444444;      /* Initial Value of R04 */\r
166         pxTopOfStack--;\r
167 #endif /* configDATA_MODE */\r
168         *pxTopOfStack = ( portSTACK_TYPE ) 0x22222222;      /* Initial Value of R02 */\r
169         pxTopOfStack--;\r
170         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;    /* R1 is expected to hold the function parameter*/\r
171         pxTopOfStack--;\r
172         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
173 \r
174         /*\r
175          * Return a pointer to the top of the stack we have generated so this can\r
176          * be stored in the task control block for the task.\r
177          */\r
178         return pxTopOfStack;\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 portBASE_TYPE xPortStartScheduler( void )\r
183 {\r
184         /* Setup the hardware to generate the tick.  Interrupts are disabled when\r
185         this function is called. */\r
186         prvSetupTimerInterrupt();\r
187 \r
188         /* Restore the context of the first task that is going to run. */\r
189         vPortStart();\r
190 \r
191         /* Should not get here as the tasks are now running! */\r
192         return pdTRUE;\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 void vPortEndScheduler( void )\r
197 {\r
198         /* It is unlikely that the V850ES/Fx3 port will get stopped.  If required simply\r
199         disable the tick interrupt here. */\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 /*\r
204  * Hardware initialisation to generate the RTOS tick.  This uses\r
205  */\r
206 static void prvSetupTimerInterrupt( void )\r
207 {\r
208         TM0CE     = 0;  /* TMM0 operation disable */\r
209         TM0EQMK0  = 1;  /* INTTM0EQ0 interrupt disable */\r
210         TM0EQIF0  = 0;  /* clear INTTM0EQ0 interrupt flag */\r
211 \r
212         #ifdef __IAR_V850ES_Fx3__\r
213         {\r
214                 TM0CMP0   = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1);    /* divided by 2 because peripherals only run at CPU_CLOCK/2 */\r
215         }\r
216         #else\r
217         {\r
218                 TM0CMP0   = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);  \r
219         }\r
220         #endif\r
221 \r
222         TM0EQIC0 &= 0xF8;\r
223         TM0CTL0   = 0x00;\r
224         TM0EQIF0 =  0;  /* clear INTTM0EQ0 interrupt flag */\r
225         TM0EQMK0 =  0;  /* INTTM0EQ0 interrupt enable */\r
226         TM0CE =     1;  /* TMM0 operation enable */\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 \r