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