2 FreeRTOS V8.2.0 - Copyright (C) 2015 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 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the RX600 port.
\r
72 *----------------------------------------------------------*/
\r
74 /* Scheduler includes. */
\r
75 #include "FreeRTOS.h"
\r
78 /* Library includes. */
\r
81 /* Hardware specifics. */
\r
82 #include "iodefine.h"
\r
84 /*-----------------------------------------------------------*/
\r
86 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore
\r
87 PSW is set with U and I set, and PM and IPL clear. */
\r
88 #define portINITIAL_PSW ( ( StackType_t ) 0x00030000 )
\r
89 #define portINITIAL_FPSW ( ( StackType_t ) 0x00000100 )
\r
91 /*-----------------------------------------------------------*/
\r
93 /* The following lines are to ensure vSoftwareInterruptEntry can be referenced,
\r
94 and therefore installed in the vector table, when the FreeRTOS code is built
\r
96 extern BaseType_t vSoftwareInterruptEntry;
\r
97 const BaseType_t * p_vSoftwareInterruptEntry = &vSoftwareInterruptEntry;
\r
99 /*-----------------------------------------------------------*/
\r
102 * Function to start the first task executing - written in asm code as direct
\r
103 * access to registers is required.
\r
105 static void prvStartFirstTask( void );
\r
108 * Software interrupt handler. Performs the actual context switch (saving and
\r
109 * restoring of registers). Written in asm code as direct register access is
\r
112 static void prvYieldHandler( void );
\r
115 * The entry point for the software interrupt handler. This is the function
\r
116 * that calls the inline asm function prvYieldHandler(). It is installed in
\r
117 * the vector table, but the code that installs it is in prvYieldHandler rather
\r
118 * than using a #pragma.
\r
120 void vSoftwareInterruptISR( void );
\r
122 /*-----------------------------------------------------------*/
\r
124 /* This is accessed by the inline assembler functions so is file scope for
\r
126 extern void *pxCurrentTCB;
\r
127 extern void vTaskSwitchContext( void );
\r
129 /*-----------------------------------------------------------*/
\r
132 * See header file for description.
\r
134 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
136 /* R0 is not included as it is the stack pointer. */
\r
138 *pxTopOfStack = 0x00;
\r
140 *pxTopOfStack = portINITIAL_PSW;
\r
142 *pxTopOfStack = ( StackType_t ) pxCode;
\r
144 /* When debugging it can be useful if every register is set to a known
\r
145 value. Otherwise code space can be saved by just setting the registers
\r
146 that need to be set. */
\r
147 #ifdef USE_FULL_REGISTER_INITIALISATION
\r
150 *pxTopOfStack = 0xffffffff; /* r15. */
\r
152 *pxTopOfStack = 0xeeeeeeee;
\r
154 *pxTopOfStack = 0xdddddddd;
\r
156 *pxTopOfStack = 0xcccccccc;
\r
158 *pxTopOfStack = 0xbbbbbbbb;
\r
160 *pxTopOfStack = 0xaaaaaaaa;
\r
162 *pxTopOfStack = 0x99999999;
\r
164 *pxTopOfStack = 0x88888888;
\r
166 *pxTopOfStack = 0x77777777;
\r
168 *pxTopOfStack = 0x66666666;
\r
170 *pxTopOfStack = 0x55555555;
\r
172 *pxTopOfStack = 0x44444444;
\r
174 *pxTopOfStack = 0x33333333;
\r
176 *pxTopOfStack = 0x22222222;
\r
181 pxTopOfStack -= 15;
\r
185 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
\r
187 *pxTopOfStack = portINITIAL_FPSW;
\r
189 *pxTopOfStack = 0x12345678; /* Accumulator. */
\r
191 *pxTopOfStack = 0x87654321; /* Accumulator. */
\r
193 return pxTopOfStack;
\r
195 /*-----------------------------------------------------------*/
\r
197 BaseType_t xPortStartScheduler( void )
\r
199 extern void vApplicationSetupTimerInterrupt( void );
\r
201 /* Use pxCurrentTCB just so it does not get optimised away. */
\r
202 if( pxCurrentTCB != NULL )
\r
204 /* Call an application function to set up the timer that will generate the
\r
205 tick interrupt. This way the application can decide which peripheral to
\r
206 use. A demo application is provided to show a suitable example. */
\r
207 vApplicationSetupTimerInterrupt();
\r
209 /* Enable the software interrupt. */
\r
210 _IEN( _ICU_SWINT ) = 1;
\r
212 /* Ensure the software interrupt is clear. */
\r
213 _IR( _ICU_SWINT ) = 0;
\r
215 /* Ensure the software interrupt is set to the kernel priority. */
\r
216 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
\r
218 /* Start the first task. */
\r
219 prvStartFirstTask();
\r
222 /* Just to make sure the function is not optimised away. */
\r
223 ( void ) vSoftwareInterruptISR();
\r
225 /* Should not get here. */
\r
228 /*-----------------------------------------------------------*/
\r
230 #pragma inline_asm prvStartFirstTask
\r
231 static void prvStartFirstTask( void )
\r
233 /* When starting the scheduler there is nothing that needs moving to the
\r
234 interrupt stack because the function is not called from an interrupt.
\r
235 Just ensure the current stack is the user stack. */
\r
238 /* Obtain the location of the stack associated with which ever task
\r
239 pxCurrentTCB is currently pointing to. */
\r
240 MOV.L #_pxCurrentTCB, R15
\r
244 /* Restore the registers from the stack of the task pointed to by
\r
247 MVTACLO R15 /* Accumulator low 32 bits. */
\r
249 MVTACHI R15 /* Accumulator high 32 bits. */
\r
251 MVTC R15,FPSW /* Floating point status word. */
\r
252 POPM R1-R15 /* R1 to R15 - R0 is not included as it is the SP. */
\r
253 RTE /* This pops the remaining registers. */
\r
257 /*-----------------------------------------------------------*/
\r
259 #pragma interrupt ( vTickISR( vect = _VECT( configTICK_VECTOR ), enable ) )
\r
260 void vTickISR( void )
\r
262 /* Increment the tick, and perform any processing the new tick value
\r
264 set_ipl( configMAX_SYSCALL_INTERRUPT_PRIORITY );
\r
266 if( xTaskIncrementTick() != pdFALSE )
\r
271 set_ipl( configKERNEL_INTERRUPT_PRIORITY );
\r
273 /*-----------------------------------------------------------*/
\r
275 void vSoftwareInterruptISR( void )
\r
279 /*-----------------------------------------------------------*/
\r
281 #pragma inline_asm prvYieldHandler
\r
282 static void prvYieldHandler( void )
\r
284 /* Re-enable interrupts. */
\r
287 /* Move the data that was automatically pushed onto the interrupt stack when
\r
288 the interrupt occurred from the interrupt stack to the user stack.
\r
290 R15 is saved before it is clobbered. */
\r
293 /* Read the user stack pointer. */
\r
296 /* Move the address down to the data being moved. */
\r
300 /* Copy the data across. */
\r
301 MOV.L [ R0 ], [ R15 ] ; R15
\r
302 MOV.L 4[ R0 ], 4[ R15 ] ; PC
\r
303 MOV.L 8[ R0 ], 8[ R15 ] ; PSW
\r
305 /* Move the interrupt stack pointer to its new correct position. */
\r
308 /* All the rest of the registers are saved directly to the user stack. */
\r
311 /* Save the rest of the general registers (R15 has been saved already). */
\r
314 /* Save the FPSW and accumulator. */
\r
319 MVFACMI R15 ; Middle order word.
\r
320 SHLL #16, R15 ; Shifted left as it is restored to the low order word.
\r
323 /* Save the stack pointer to the TCB. */
\r
324 MOV.L #_pxCurrentTCB, R15
\r
328 /* Ensure the interrupt mask is set to the syscall priority while the kernel
\r
329 structures are being accessed. */
\r
330 MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY
\r
332 /* Select the next task to run. */
\r
333 BSR.A _vTaskSwitchContext
\r
335 /* Reset the interrupt mask as no more data structure access is required. */
\r
336 MVTIPL #configKERNEL_INTERRUPT_PRIORITY
\r
338 /* Load the stack pointer of the task that is now selected as the Running
\r
339 state task from its TCB. */
\r
340 MOV.L #_pxCurrentTCB,R15
\r
344 /* Restore the context of the new task. The PSW (Program Status Word) and
\r
345 PC will be popped by the RTE instruction. */
\r
357 /*-----------------------------------------------------------*/
\r
359 void vPortEndScheduler( void )
\r
361 /* Not implemented in ports where there is nothing to return to.
\r
362 Artificially force an assert. */
\r
363 configASSERT( pxCurrentTCB == NULL );
\r
365 /* The following line is just to prevent the symbol getting optimised away. */
\r
366 ( void ) vTaskSwitchContext();
\r
368 /*-----------------------------------------------------------*/
\r