]> begriffs open source - freertos/blob - Source/portable/IAR/V850ES/port.c
Update version number.
[freertos] / Source / portable / IAR / V850ES / port.c
1 /*\r
2         FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it\r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /* Standard includes. */\r
53 #include <stdlib.h>\r
54 \r
55 /* Scheduler includes. */\r
56 #include "FreeRTOS.h"\r
57 #include "task.h"\r
58 \r
59 /* Critical nesting should be initialised to a non zero value so interrupts don't\r
60 accidentally get enabled before the scheduler is started. */\r
61 #define portINITIAL_CRITICAL_NESTING  (( portSTACK_TYPE ) 10)\r
62 \r
63 /* The PSW value assigned to tasks when they start to run for the first time. */\r
64 #define portPSW           (( portSTACK_TYPE ) 0x00000000)\r
65 \r
66 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
67 any details of its type. */\r
68 typedef void tskTCB;\r
69 extern volatile tskTCB * volatile pxCurrentTCB;\r
70 \r
71 /* Keeps track of the nesting level of critical sections. */\r
72 volatile portSTACK_TYPE usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /* Sets up the timer to generate the tick interrupt. */\r
76 static void prvSetupTimerInterrupt( void );\r
77 \r
78 /*-----------------------------------------------------------*/\r
79 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
80 {\r
81         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;          /* Task function start address */\r
82         pxTopOfStack--;\r
83         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;          /* Task function start address */\r
84         pxTopOfStack--;\r
85         *pxTopOfStack = portPSW;                            /* Initial PSW value */\r
86         pxTopOfStack--;\r
87         *pxTopOfStack = ( portSTACK_TYPE ) 0x20202020;      /* Initial Value of R20 */\r
88         pxTopOfStack--;\r
89         *pxTopOfStack = ( portSTACK_TYPE ) 0x21212121;      /* Initial Value of R21 */\r
90         pxTopOfStack--;\r
91         *pxTopOfStack = ( portSTACK_TYPE ) 0x22222222;      /* Initial Value of R22 */\r
92         pxTopOfStack--;\r
93         *pxTopOfStack = ( portSTACK_TYPE ) 0x23232323;      /* Initial Value of R23 */\r
94         pxTopOfStack--;\r
95         *pxTopOfStack = ( portSTACK_TYPE ) 0x24242424;      /* Initial Value of R24 */\r
96         pxTopOfStack--;\r
97 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)\r
98         *pxTopOfStack = ( portSTACK_TYPE ) 0x25252525;      /* Initial Value of R25 */\r
99         pxTopOfStack--;\r
100 #endif /* configDATA_MODE */\r
101         *pxTopOfStack = ( portSTACK_TYPE ) 0x26262626;      /* Initial Value of R26 */\r
102         pxTopOfStack--;\r
103         *pxTopOfStack = ( portSTACK_TYPE ) 0x27272727;      /* Initial Value of R27 */\r
104         pxTopOfStack--;\r
105         *pxTopOfStack = ( portSTACK_TYPE ) 0x28282828;      /* Initial Value of R28 */\r
106         pxTopOfStack--;\r
107         *pxTopOfStack = ( portSTACK_TYPE ) 0x29292929;      /* Initial Value of R29 */\r
108         pxTopOfStack--;\r
109         *pxTopOfStack = ( portSTACK_TYPE ) 0x30303030;      /* Initial Value of R30 */\r
110         pxTopOfStack--;         \r
111         *pxTopOfStack = ( portSTACK_TYPE ) 0x19191919;      /* Initial Value of R19 */\r
112         pxTopOfStack--;\r
113         *pxTopOfStack = ( portSTACK_TYPE ) 0x18181818;      /* Initial Value of R18 */\r
114         pxTopOfStack--;\r
115         *pxTopOfStack = ( portSTACK_TYPE ) 0x17171717;      /* Initial Value of R17 */\r
116         pxTopOfStack--;\r
117         *pxTopOfStack = ( portSTACK_TYPE ) 0x16161616;      /* Initial Value of R16 */\r
118         pxTopOfStack--;\r
119         *pxTopOfStack = ( portSTACK_TYPE ) 0x15151515;      /* Initial Value of R15 */\r
120         pxTopOfStack--;\r
121         *pxTopOfStack = ( portSTACK_TYPE ) 0x14141414;      /* Initial Value of R14 */\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( portSTACK_TYPE ) 0x13131313;      /* Initial Value of R13 */\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;      /* Initial Value of R12 */\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( portSTACK_TYPE ) 0x11111111;      /* Initial Value of R11 */\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = ( portSTACK_TYPE ) 0x10101010;      /* Initial Value of R10 */\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = ( portSTACK_TYPE ) 0x99999999;      /* Initial Value of R09 */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( portSTACK_TYPE ) 0x88888888;      /* Initial Value of R08 */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( portSTACK_TYPE ) 0x77777777;      /* Initial Value of R07 */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( portSTACK_TYPE ) 0x66666666;      /* Initial Value of R06 */\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = ( portSTACK_TYPE ) 0x55555555;      /* Initial Value of R05 */\r
140         pxTopOfStack--;\r
141 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1\r
142         *pxTopOfStack = ( portSTACK_TYPE ) 0x44444444;      /* Initial Value of R04 */\r
143         pxTopOfStack--;\r
144 #endif /* configDATA_MODE */\r
145         *pxTopOfStack = ( portSTACK_TYPE ) 0x22222222;      /* Initial Value of R02 */\r
146         pxTopOfStack--;\r
147         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;    /* R1 is expected to hold the function parameter*/\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
150 \r
151         /*\r
152          * Return a pointer to the top of the stack we have generated so this can\r
153          * be stored in the task control block for the task.\r
154          */\r
155         return pxTopOfStack;\r
156 }\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 portBASE_TYPE xPortStartScheduler( void )\r
160 {\r
161         /* Setup the hardware to generate the tick.  Interrupts are disabled when\r
162         this function is called. */\r
163         prvSetupTimerInterrupt();\r
164 \r
165         /* Restore the context of the first task that is going to run. */\r
166         vPortStart();\r
167 \r
168         /* Should not get here as the tasks are now running! */\r
169         return pdTRUE;\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 void vPortEndScheduler( void )\r
174 {\r
175         /* It is unlikely that the V850ES/Fx3 port will get stopped.  If required simply\r
176         disable the tick interrupt here. */\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 /*\r
181  * Hardware initialisation to generate the RTOS tick.  This uses\r
182  */\r
183 static void prvSetupTimerInterrupt( void )\r
184 {\r
185         TM0CE     = 0;  /* TMM0 operation disable */\r
186         TM0EQMK0  = 1;  /* INTTM0EQ0 interrupt disable */\r
187         TM0EQIF0  = 0;  /* clear INTTM0EQ0 interrupt flag */\r
188 \r
189         #ifdef __IAR_V850ES_Fx3__\r
190         {\r
191                 TM0CMP0   = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1);    /* divided by 2 because peripherals only run at CPU_CLOCK/2 */\r
192         }\r
193         #else\r
194         {\r
195                 TM0CMP0   = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);  \r
196         }\r
197         #endif\r
198 \r
199         TM0EQIC0 &= 0xF8;\r
200         TM0CTL0   = 0x00;\r
201         TM0EQIF0 =  0;  /* clear INTTM0EQ0 interrupt flag */\r
202         TM0EQMK0 =  0;  /* INTTM0EQ0 interrupt enable */\r
203         TM0CE =     1;  /* TMM0 operation enable */\r
204 }\r
205 /*-----------------------------------------------------------*/\r
206 \r
207 \r