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