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 /*-----------------------------------------------------------
\r
97 * Implementation of functions defined in portable.h for the RX600 port.
\r
98 *----------------------------------------------------------*/
\r
100 /* Scheduler includes. */
\r
101 #include "FreeRTOS.h"
\r
104 /* Library includes. */
\r
105 #include "string.h"
\r
107 /* Hardware specifics. */
\r
108 #include "iodefine.h"
\r
110 /*-----------------------------------------------------------*/
\r
112 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore
\r
113 PSW is set with U and I set, and PM and IPL clear. */
\r
114 #define portINITIAL_PSW ( ( StackType_t ) 0x00030000 )
\r
115 #define portINITIAL_FPSW ( ( StackType_t ) 0x00000100 )
\r
117 /*-----------------------------------------------------------*/
\r
119 /* The following lines are to ensure vSoftwareInterruptEntry can be referenced,
\r
120 and therefore installed in the vector table, when the FreeRTOS code is built
\r
122 extern BaseType_t vSoftwareInterruptEntry;
\r
123 const BaseType_t * p_vSoftwareInterruptEntry = &vSoftwareInterruptEntry;
\r
125 /*-----------------------------------------------------------*/
\r
128 * Function to start the first task executing - written in asm code as direct
\r
129 * access to registers is required.
\r
131 static void prvStartFirstTask( void );
\r
134 * Software interrupt handler. Performs the actual context switch (saving and
\r
135 * restoring of registers). Written in asm code as direct register access is
\r
138 static void prvYieldHandler( void );
\r
141 * The entry point for the software interrupt handler. This is the function
\r
142 * that calls the inline asm function prvYieldHandler(). It is installed in
\r
143 * the vector table, but the code that installs it is in prvYieldHandler rather
\r
144 * than using a #pragma.
\r
146 void vSoftwareInterruptISR( void );
\r
148 /*-----------------------------------------------------------*/
\r
150 /* This is accessed by the inline assembler functions so is file scope for
\r
152 extern void *pxCurrentTCB;
\r
153 extern void vTaskSwitchContext( void );
\r
155 /*-----------------------------------------------------------*/
\r
158 * See header file for description.
\r
160 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
162 /* R0 is not included as it is the stack pointer. */
\r
164 *pxTopOfStack = 0x00;
\r
166 *pxTopOfStack = portINITIAL_PSW;
\r
168 *pxTopOfStack = ( StackType_t ) pxCode;
\r
170 /* When debugging it can be useful if every register is set to a known
\r
171 value. Otherwise code space can be saved by just setting the registers
\r
172 that need to be set. */
\r
173 #ifdef USE_FULL_REGISTER_INITIALISATION
\r
176 *pxTopOfStack = 0xffffffff; /* r15. */
\r
178 *pxTopOfStack = 0xeeeeeeee;
\r
180 *pxTopOfStack = 0xdddddddd;
\r
182 *pxTopOfStack = 0xcccccccc;
\r
184 *pxTopOfStack = 0xbbbbbbbb;
\r
186 *pxTopOfStack = 0xaaaaaaaa;
\r
188 *pxTopOfStack = 0x99999999;
\r
190 *pxTopOfStack = 0x88888888;
\r
192 *pxTopOfStack = 0x77777777;
\r
194 *pxTopOfStack = 0x66666666;
\r
196 *pxTopOfStack = 0x55555555;
\r
198 *pxTopOfStack = 0x44444444;
\r
200 *pxTopOfStack = 0x33333333;
\r
202 *pxTopOfStack = 0x22222222;
\r
207 pxTopOfStack -= 15;
\r
211 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
\r
213 *pxTopOfStack = portINITIAL_FPSW;
\r
215 *pxTopOfStack = 0x11111111; /* Accumulator 0. */
\r
217 *pxTopOfStack = 0x22222222; /* Accumulator 0. */
\r
219 *pxTopOfStack = 0x33333333; /* Accumulator 0. */
\r
221 *pxTopOfStack = 0x44444444; /* Accumulator 1. */
\r
223 *pxTopOfStack = 0x55555555; /* Accumulator 1. */
\r
225 *pxTopOfStack = 0x66666666; /* Accumulator 1. */
\r
227 return pxTopOfStack;
\r
229 /*-----------------------------------------------------------*/
\r
231 BaseType_t xPortStartScheduler( void )
\r
233 extern void vApplicationSetupTimerInterrupt( void );
\r
235 /* Use pxCurrentTCB just so it does not get optimised away. */
\r
236 if( pxCurrentTCB != NULL )
\r
238 /* Call an application function to set up the timer that will generate the
\r
239 tick interrupt. This way the application can decide which peripheral to
\r
240 use. A demo application is provided to show a suitable example. */
\r
241 vApplicationSetupTimerInterrupt();
\r
243 /* Enable the software interrupt. */
\r
244 _IEN( _ICU_SWINT ) = 1;
\r
246 /* Ensure the software interrupt is clear. */
\r
247 _IR( _ICU_SWINT ) = 0;
\r
249 /* Ensure the software interrupt is set to the kernel priority. */
\r
250 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
\r
252 /* Start the first task. */
\r
253 prvStartFirstTask();
\r
256 /* Just to make sure the function is not optimised away. */
\r
257 ( void ) vSoftwareInterruptISR();
\r
259 /* Should not get here. */
\r
262 /*-----------------------------------------------------------*/
\r
264 #pragma inline_asm prvStartFirstTask
\r
265 static void prvStartFirstTask( void )
\r
267 /* When starting the scheduler there is nothing that needs moving to the
\r
268 interrupt stack because the function is not called from an interrupt.
\r
269 Just ensure the current stack is the user stack. */
\r
272 /* Obtain the location of the stack associated with which ever task
\r
273 pxCurrentTCB is currently pointing to. */
\r
274 MOV.L #_pxCurrentTCB, R15
\r
278 /* Restore the registers from the stack of the task pointed to by
\r
281 MVTACLO R15, A0 /* Accumulator low 32 bits. */
\r
283 MVTACHI R15, A0 /* Accumulator high 32 bits. */
\r
285 MVTACGU R15, A0 /* Accumulator guard. */
\r
287 MVTACLO R15, A1 /* Accumulator low 32 bits. */
\r
289 MVTACHI R15, A1 /* Accumulator high 32 bits. */
\r
291 MVTACGU R15, A1 /* Accumulator guard. */
\r
293 MVTC R15,FPSW /* Floating point status word. */
\r
294 POPM R1-R15 /* R1 to R15 - R0 is not included as it is the SP. */
\r
295 RTE /* This pops the remaining registers. */
\r
299 /*-----------------------------------------------------------*/
\r
301 #pragma interrupt ( vTickISR( vect = _VECT( configTICK_VECTOR ), enable ) )
\r
302 void vTickISR( void )
\r
304 /* Increment the tick, and perform any processing the new tick value
\r
306 set_ipl( configMAX_SYSCALL_INTERRUPT_PRIORITY );
\r
308 if( xTaskIncrementTick() != pdFALSE )
\r
313 set_ipl( configKERNEL_INTERRUPT_PRIORITY );
\r
315 /*-----------------------------------------------------------*/
\r
317 void vSoftwareInterruptISR( void )
\r
321 /*-----------------------------------------------------------*/
\r
323 #pragma inline_asm prvYieldHandler
\r
324 static void prvYieldHandler( void )
\r
326 /* Re-enable interrupts. */
\r
329 /* Move the data that was automatically pushed onto the interrupt stack when
\r
330 the interrupt occurred from the interrupt stack to the user stack.
\r
332 R15 is saved before it is clobbered. */
\r
335 /* Read the user stack pointer. */
\r
338 /* Move the address down to the data being moved. */
\r
342 /* Copy the data across. */
\r
343 MOV.L [ R0 ], [ R15 ] ; R15
\r
344 MOV.L 4[ R0 ], 4[ R15 ] ; PC
\r
345 MOV.L 8[ R0 ], 8[ R15 ] ; PSW
\r
347 /* Move the interrupt stack pointer to its new correct position. */
\r
350 /* All the rest of the registers are saved directly to the user stack. */
\r
353 /* Save the rest of the general registers (R15 has been saved already). */
\r
356 /* Save the FPSW and accumulators. */
\r
359 MVFACGU #0, A1, R15
\r
361 MVFACHI #0, A1, R15
\r
363 MVFACLO #0, A1, R15 ; Low order word.
\r
365 MVFACGU #0, A0, R15
\r
367 MVFACHI #0, A0, R15
\r
369 MVFACLO #0, A0, R15 ; Low order word.
\r
372 /* Save the stack pointer to the TCB. */
\r
373 MOV.L #_pxCurrentTCB, R15
\r
377 /* Ensure the interrupt mask is set to the syscall priority while the kernel
\r
378 structures are being accessed. */
\r
379 MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY
\r
381 /* Select the next task to run. */
\r
382 BSR.A _vTaskSwitchContext
\r
384 /* Reset the interrupt mask as no more data structure access is required. */
\r
385 MVTIPL #configKERNEL_INTERRUPT_PRIORITY
\r
387 /* Load the stack pointer of the task that is now selected as the Running
\r
388 state task from its TCB. */
\r
389 MOV.L #_pxCurrentTCB,R15
\r
393 /* Restore the context of the new task. The PSW (Program Status Word) and
\r
394 PC will be popped by the RTE instruction. */
\r
396 MVTACLO R15, A0 /* Accumulator low 32 bits. */
\r
398 MVTACHI R15, A0 /* Accumulator high 32 bits. */
\r
400 MVTACGU R15, A0 /* Accumulator guard. */
\r
402 MVTACLO R15, A1 /* Accumulator low 32 bits. */
\r
404 MVTACHI R15, A1 /* Accumulator high 32 bits. */
\r
406 MVTACGU R15, A1 /* Accumulator guard. */
\r
414 /*-----------------------------------------------------------*/
\r
416 void vPortEndScheduler( void )
\r
418 /* Not implemented in ports where there is nothing to return to.
\r
419 Artificially force an assert. */
\r
420 configASSERT( pxCurrentTCB == NULL );
\r
422 /* The following line is just to prevent the symbol getting optimised away. */
\r
423 ( void ) vTaskSwitchContext();
\r
425 /*-----------------------------------------------------------*/
\r