]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/V850ES/port.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Source / portable / IAR / V850ES / port.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 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 /* Standard includes. */\r
71 #include <stdlib.h>\r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 \r
77 /* Critical nesting should be initialised to a non zero value so interrupts don't\r
78 accidentally get enabled before the scheduler is started. */\r
79 #define portINITIAL_CRITICAL_NESTING  (( StackType_t ) 10)\r
80 \r
81 /* The PSW value assigned to tasks when they start to run for the first time. */\r
82 #define portPSW           (( StackType_t ) 0x00000000)\r
83 \r
84 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
85 any details of its type. */\r
86 typedef void TCB_t;\r
87 extern volatile TCB_t * volatile pxCurrentTCB;\r
88 \r
89 /* Keeps track of the nesting level of critical sections. */\r
90 volatile StackType_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /* Sets up the timer to generate the tick interrupt. */\r
94 static void prvSetupTimerInterrupt( void );\r
95 \r
96 /*-----------------------------------------------------------*/\r
97 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
98 {\r
99         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
100         pxTopOfStack--;\r
101         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
102         pxTopOfStack--;\r
103         *pxTopOfStack = portPSW;                            /* Initial PSW value */\r
104         pxTopOfStack--;\r
105         *pxTopOfStack = ( StackType_t ) 0x20202020;      /* Initial Value of R20 */\r
106         pxTopOfStack--;\r
107         *pxTopOfStack = ( StackType_t ) 0x21212121;      /* Initial Value of R21 */\r
108         pxTopOfStack--;\r
109         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R22 */\r
110         pxTopOfStack--;\r
111         *pxTopOfStack = ( StackType_t ) 0x23232323;      /* Initial Value of R23 */\r
112         pxTopOfStack--;\r
113         *pxTopOfStack = ( StackType_t ) 0x24242424;      /* Initial Value of R24 */\r
114         pxTopOfStack--;\r
115 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)\r
116         *pxTopOfStack = ( StackType_t ) 0x25252525;      /* Initial Value of R25 */\r
117         pxTopOfStack--;\r
118 #endif /* configDATA_MODE */\r
119         *pxTopOfStack = ( StackType_t ) 0x26262626;      /* Initial Value of R26 */\r
120         pxTopOfStack--;\r
121         *pxTopOfStack = ( StackType_t ) 0x27272727;      /* Initial Value of R27 */\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( StackType_t ) 0x28282828;      /* Initial Value of R28 */\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = ( StackType_t ) 0x29292929;      /* Initial Value of R29 */\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( StackType_t ) 0x30303030;      /* Initial Value of R30 */\r
128         pxTopOfStack--;         \r
129         *pxTopOfStack = ( StackType_t ) 0x19191919;      /* Initial Value of R19 */\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = ( StackType_t ) 0x18181818;      /* Initial Value of R18 */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( StackType_t ) 0x17171717;      /* Initial Value of R17 */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( StackType_t ) 0x16161616;      /* Initial Value of R16 */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( StackType_t ) 0x15151515;      /* Initial Value of R15 */\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = ( StackType_t ) 0x14141414;      /* Initial Value of R14 */\r
140         pxTopOfStack--;\r
141         *pxTopOfStack = ( StackType_t ) 0x13131313;      /* Initial Value of R13 */\r
142         pxTopOfStack--;\r
143         *pxTopOfStack = ( StackType_t ) 0x12121212;      /* Initial Value of R12 */\r
144         pxTopOfStack--;\r
145         *pxTopOfStack = ( StackType_t ) 0x11111111;      /* Initial Value of R11 */\r
146         pxTopOfStack--;\r
147         *pxTopOfStack = ( StackType_t ) 0x10101010;      /* Initial Value of R10 */\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = ( StackType_t ) 0x99999999;      /* Initial Value of R09 */\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = ( StackType_t ) 0x88888888;      /* Initial Value of R08 */\r
152         pxTopOfStack--;\r
153         *pxTopOfStack = ( StackType_t ) 0x77777777;      /* Initial Value of R07 */\r
154         pxTopOfStack--;\r
155         *pxTopOfStack = ( StackType_t ) 0x66666666;      /* Initial Value of R06 */\r
156         pxTopOfStack--;\r
157         *pxTopOfStack = ( StackType_t ) 0x55555555;      /* Initial Value of R05 */\r
158         pxTopOfStack--;\r
159 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1\r
160         *pxTopOfStack = ( StackType_t ) 0x44444444;      /* Initial Value of R04 */\r
161         pxTopOfStack--;\r
162 #endif /* configDATA_MODE */\r
163         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R02 */\r
164         pxTopOfStack--;\r
165         *pxTopOfStack = ( StackType_t ) pvParameters;    /* R1 is expected to hold the function parameter*/\r
166         pxTopOfStack--;\r
167         *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;        \r
168 \r
169         /*\r
170          * Return a pointer to the top of the stack we have generated so this can\r
171          * be stored in the task control block for the task.\r
172          */\r
173         return pxTopOfStack;\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 BaseType_t xPortStartScheduler( void )\r
178 {\r
179         /* Setup the hardware to generate the tick.  Interrupts are disabled when\r
180         this function is called. */\r
181         prvSetupTimerInterrupt();\r
182 \r
183         /* Restore the context of the first task that is going to run. */\r
184         vPortStart();\r
185 \r
186         /* Should not get here as the tasks are now running! */\r
187         return pdTRUE;\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 void vPortEndScheduler( void )\r
192 {\r
193         /* It is unlikely that the V850ES/Fx3 port will get stopped.  If required simply\r
194         disable the tick interrupt here. */\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 /*\r
199  * Hardware initialisation to generate the RTOS tick.  This uses\r
200  */\r
201 static void prvSetupTimerInterrupt( void )\r
202 {\r
203         TM0CE     = 0;  /* TMM0 operation disable */\r
204         TM0EQMK0  = 1;  /* INTTM0EQ0 interrupt disable */\r
205         TM0EQIF0  = 0;  /* clear INTTM0EQ0 interrupt flag */\r
206 \r
207         #ifdef __IAR_V850ES_Fx3__\r
208         {\r
209                 TM0CMP0   = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1);    /* divided by 2 because peripherals only run at CPU_CLOCK/2 */\r
210         }\r
211         #else\r
212         {\r
213                 TM0CMP0   = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);  \r
214         }\r
215         #endif\r
216 \r
217         TM0EQIC0 &= 0xF8;\r
218         TM0CTL0   = 0x00;\r
219         TM0EQIF0 =  0;  /* clear INTTM0EQ0 interrupt flag */\r
220         TM0EQMK0 =  0;  /* INTTM0EQ0 interrupt enable */\r
221         TM0CE =     1;  /* TMM0 operation enable */\r
222 }\r
223 /*-----------------------------------------------------------*/\r
224 \r
225 \r