2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /* Standard includes. */
\r
99 /* Scheduler includes. */
\r
100 #include "FreeRTOS.h"
\r
103 /* Critical nesting should be initialised to a non zero value so interrupts don't
\r
104 accidentally get enabled before the scheduler is started. */
\r
105 #define portINITIAL_CRITICAL_NESTING (( StackType_t ) 10)
\r
107 /* The PSW value assigned to tasks when they start to run for the first time. */
\r
108 #define portPSW (( StackType_t ) 0x00000000)
\r
110 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
111 any details of its type. */
\r
112 typedef void TCB_t;
\r
113 extern volatile TCB_t * volatile pxCurrentTCB;
\r
115 /* Keeps track of the nesting level of critical sections. */
\r
116 volatile StackType_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
117 /*-----------------------------------------------------------*/
\r
119 /* Sets up the timer to generate the tick interrupt. */
\r
120 static void prvSetupTimerInterrupt( void );
\r
122 /*-----------------------------------------------------------*/
\r
123 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
125 *pxTopOfStack = ( StackType_t ) pxCode; /* Task function start address */
\r
127 *pxTopOfStack = ( StackType_t ) pxCode; /* Task function start address */
\r
129 *pxTopOfStack = portPSW; /* Initial PSW value */
\r
131 *pxTopOfStack = ( StackType_t ) 0x20202020; /* Initial Value of R20 */
\r
133 *pxTopOfStack = ( StackType_t ) 0x21212121; /* Initial Value of R21 */
\r
135 *pxTopOfStack = ( StackType_t ) 0x22222222; /* Initial Value of R22 */
\r
137 *pxTopOfStack = ( StackType_t ) 0x23232323; /* Initial Value of R23 */
\r
139 *pxTopOfStack = ( StackType_t ) 0x24242424; /* Initial Value of R24 */
\r
141 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)
\r
142 *pxTopOfStack = ( StackType_t ) 0x25252525; /* Initial Value of R25 */
\r
144 #endif /* configDATA_MODE */
\r
145 *pxTopOfStack = ( StackType_t ) 0x26262626; /* Initial Value of R26 */
\r
147 *pxTopOfStack = ( StackType_t ) 0x27272727; /* Initial Value of R27 */
\r
149 *pxTopOfStack = ( StackType_t ) 0x28282828; /* Initial Value of R28 */
\r
151 *pxTopOfStack = ( StackType_t ) 0x29292929; /* Initial Value of R29 */
\r
153 *pxTopOfStack = ( StackType_t ) 0x30303030; /* Initial Value of R30 */
\r
155 *pxTopOfStack = ( StackType_t ) 0x19191919; /* Initial Value of R19 */
\r
157 *pxTopOfStack = ( StackType_t ) 0x18181818; /* Initial Value of R18 */
\r
159 *pxTopOfStack = ( StackType_t ) 0x17171717; /* Initial Value of R17 */
\r
161 *pxTopOfStack = ( StackType_t ) 0x16161616; /* Initial Value of R16 */
\r
163 *pxTopOfStack = ( StackType_t ) 0x15151515; /* Initial Value of R15 */
\r
165 *pxTopOfStack = ( StackType_t ) 0x14141414; /* Initial Value of R14 */
\r
167 *pxTopOfStack = ( StackType_t ) 0x13131313; /* Initial Value of R13 */
\r
169 *pxTopOfStack = ( StackType_t ) 0x12121212; /* Initial Value of R12 */
\r
171 *pxTopOfStack = ( StackType_t ) 0x11111111; /* Initial Value of R11 */
\r
173 *pxTopOfStack = ( StackType_t ) 0x10101010; /* Initial Value of R10 */
\r
175 *pxTopOfStack = ( StackType_t ) 0x99999999; /* Initial Value of R09 */
\r
177 *pxTopOfStack = ( StackType_t ) 0x88888888; /* Initial Value of R08 */
\r
179 *pxTopOfStack = ( StackType_t ) 0x77777777; /* Initial Value of R07 */
\r
181 *pxTopOfStack = ( StackType_t ) 0x66666666; /* Initial Value of R06 */
\r
183 *pxTopOfStack = ( StackType_t ) 0x55555555; /* Initial Value of R05 */
\r
185 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1
\r
186 *pxTopOfStack = ( StackType_t ) 0x44444444; /* Initial Value of R04 */
\r
188 #endif /* configDATA_MODE */
\r
189 *pxTopOfStack = ( StackType_t ) 0x22222222; /* Initial Value of R02 */
\r
191 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 is expected to hold the function parameter*/
\r
193 *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;
\r
196 * Return a pointer to the top of the stack we have generated so this can
\r
197 * be stored in the task control block for the task.
\r
199 return pxTopOfStack;
\r
201 /*-----------------------------------------------------------*/
\r
203 BaseType_t xPortStartScheduler( void )
\r
205 /* Setup the hardware to generate the tick. Interrupts are disabled when
\r
206 this function is called. */
\r
207 prvSetupTimerInterrupt();
\r
209 /* Restore the context of the first task that is going to run. */
\r
212 /* Should not get here as the tasks are now running! */
\r
215 /*-----------------------------------------------------------*/
\r
217 void vPortEndScheduler( void )
\r
219 /* It is unlikely that the V850ES/Fx3 port will get stopped. If required simply
\r
220 disable the tick interrupt here. */
\r
222 /*-----------------------------------------------------------*/
\r
225 * Hardware initialisation to generate the RTOS tick. This uses
\r
227 static void prvSetupTimerInterrupt( void )
\r
229 TM0CE = 0; /* TMM0 operation disable */
\r
230 TM0EQMK0 = 1; /* INTTM0EQ0 interrupt disable */
\r
231 TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
\r
233 #ifdef __IAR_V850ES_Fx3__
\r
235 TM0CMP0 = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1); /* divided by 2 because peripherals only run at CPU_CLOCK/2 */
\r
239 TM0CMP0 = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);
\r
245 TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
\r
246 TM0EQMK0 = 0; /* INTTM0EQ0 interrupt enable */
\r
247 TM0CE = 1; /* TMM0 operation enable */
\r
249 /*-----------------------------------------------------------*/
\r