2 FreeRTOS V9.0.0 - Copyright (C) 2016 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 ***************************************************************************
\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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
70 /* Standard includes. */
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\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
81 /* The PSW value assigned to tasks when they start to run for the first time. */
\r
82 #define portPSW (( StackType_t ) 0x00000000)
\r
84 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
85 any details of its type. */
\r
87 extern volatile TCB_t * volatile pxCurrentTCB;
\r
89 /* Keeps track of the nesting level of critical sections. */
\r
90 volatile StackType_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
91 /*-----------------------------------------------------------*/
\r
93 /* Sets up the timer to generate the tick interrupt. */
\r
94 static void prvSetupTimerInterrupt( void );
\r
96 /*-----------------------------------------------------------*/
\r
97 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
99 *pxTopOfStack = ( StackType_t ) pxCode; /* Task function start address */
\r
101 *pxTopOfStack = ( StackType_t ) pxCode; /* Task function start address */
\r
103 *pxTopOfStack = portPSW; /* Initial PSW value */
\r
105 *pxTopOfStack = ( StackType_t ) 0x20202020; /* Initial Value of R20 */
\r
107 *pxTopOfStack = ( StackType_t ) 0x21212121; /* Initial Value of R21 */
\r
109 *pxTopOfStack = ( StackType_t ) 0x22222222; /* Initial Value of R22 */
\r
111 *pxTopOfStack = ( StackType_t ) 0x23232323; /* Initial Value of R23 */
\r
113 *pxTopOfStack = ( StackType_t ) 0x24242424; /* Initial Value of R24 */
\r
115 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)
\r
116 *pxTopOfStack = ( StackType_t ) 0x25252525; /* Initial Value of R25 */
\r
118 #endif /* configDATA_MODE */
\r
119 *pxTopOfStack = ( StackType_t ) 0x26262626; /* Initial Value of R26 */
\r
121 *pxTopOfStack = ( StackType_t ) 0x27272727; /* Initial Value of R27 */
\r
123 *pxTopOfStack = ( StackType_t ) 0x28282828; /* Initial Value of R28 */
\r
125 *pxTopOfStack = ( StackType_t ) 0x29292929; /* Initial Value of R29 */
\r
127 *pxTopOfStack = ( StackType_t ) 0x30303030; /* Initial Value of R30 */
\r
129 *pxTopOfStack = ( StackType_t ) 0x19191919; /* Initial Value of R19 */
\r
131 *pxTopOfStack = ( StackType_t ) 0x18181818; /* Initial Value of R18 */
\r
133 *pxTopOfStack = ( StackType_t ) 0x17171717; /* Initial Value of R17 */
\r
135 *pxTopOfStack = ( StackType_t ) 0x16161616; /* Initial Value of R16 */
\r
137 *pxTopOfStack = ( StackType_t ) 0x15151515; /* Initial Value of R15 */
\r
139 *pxTopOfStack = ( StackType_t ) 0x14141414; /* Initial Value of R14 */
\r
141 *pxTopOfStack = ( StackType_t ) 0x13131313; /* Initial Value of R13 */
\r
143 *pxTopOfStack = ( StackType_t ) 0x12121212; /* Initial Value of R12 */
\r
145 *pxTopOfStack = ( StackType_t ) 0x11111111; /* Initial Value of R11 */
\r
147 *pxTopOfStack = ( StackType_t ) 0x10101010; /* Initial Value of R10 */
\r
149 *pxTopOfStack = ( StackType_t ) 0x99999999; /* Initial Value of R09 */
\r
151 *pxTopOfStack = ( StackType_t ) 0x88888888; /* Initial Value of R08 */
\r
153 *pxTopOfStack = ( StackType_t ) 0x77777777; /* Initial Value of R07 */
\r
155 *pxTopOfStack = ( StackType_t ) 0x66666666; /* Initial Value of R06 */
\r
157 *pxTopOfStack = ( StackType_t ) 0x55555555; /* Initial Value of R05 */
\r
159 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1
\r
160 *pxTopOfStack = ( StackType_t ) 0x44444444; /* Initial Value of R04 */
\r
162 #endif /* configDATA_MODE */
\r
163 *pxTopOfStack = ( StackType_t ) 0x22222222; /* Initial Value of R02 */
\r
165 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 is expected to hold the function parameter*/
\r
167 *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;
\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
173 return pxTopOfStack;
\r
175 /*-----------------------------------------------------------*/
\r
177 BaseType_t xPortStartScheduler( void )
\r
179 /* Setup the hardware to generate the tick. Interrupts are disabled when
\r
180 this function is called. */
\r
181 prvSetupTimerInterrupt();
\r
183 /* Restore the context of the first task that is going to run. */
\r
186 /* Should not get here as the tasks are now running! */
\r
189 /*-----------------------------------------------------------*/
\r
191 void vPortEndScheduler( void )
\r
193 /* It is unlikely that the V850ES/Fx3 port will get stopped. If required simply
\r
194 disable the tick interrupt here. */
\r
196 /*-----------------------------------------------------------*/
\r
199 * Hardware initialisation to generate the RTOS tick. This uses
\r
201 static void prvSetupTimerInterrupt( void )
\r
203 TM0CE = 0; /* TMM0 operation disable */
\r
204 TM0EQMK0 = 1; /* INTTM0EQ0 interrupt disable */
\r
205 TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
\r
207 #ifdef __IAR_V850ES_Fx3__
\r
209 TM0CMP0 = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1); /* divided by 2 because peripherals only run at CPU_CLOCK/2 */
\r
213 TM0CMP0 = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);
\r
219 TM0EQIF0 = 0; /* clear INTTM0EQ0 interrupt flag */
\r
220 TM0EQMK0 = 0; /* INTTM0EQ0 interrupt enable */
\r
221 TM0CE = 1; /* TMM0 operation enable */
\r
223 /*-----------------------------------------------------------*/
\r