2 FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Standard includes. */
\r
69 /* Kernel includes. */
\r
70 #include "FreeRTOS.h"
\r
73 /* Machine includes */
\r
74 #include <machine/counter.h>
\r
75 #include <machine/ic.h>
\r
76 /*-----------------------------------------------------------*/
\r
78 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */
\r
79 #define portINITIAL_PSR ( 0x00020000 )
\r
81 /*-----------------------------------------------------------*/
\r
84 * Perform any hardware configuration necessary to generate the tick interrupt.
\r
86 static void prvSetupTimerInterrupt( void );
\r
87 /*-----------------------------------------------------------*/
\r
89 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
91 /* Make space on the stack for the context - this leaves a couple of spaces
\r
95 /* Fill the registers with known values to assist debugging. */
\r
96 pxTopOfStack[ 16 ] = 0;
\r
97 pxTopOfStack[ 15 ] = portINITIAL_PSR;
\r
98 pxTopOfStack[ 14 ] = ( uint32_t ) pxCode;
\r
99 pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */
\r
100 pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */
\r
101 pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;
\r
102 pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;
\r
103 pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;
\r
104 pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;
\r
105 pxTopOfStack[ 7 ] = 0x09090909UL;
\r
106 pxTopOfStack[ 6 ] = 0x08080808UL;
\r
107 pxTopOfStack[ 5 ] = 0x07070707UL;
\r
108 pxTopOfStack[ 4 ] = 0x06060606UL;
\r
109 pxTopOfStack[ 3 ] = 0x05050505UL;
\r
110 pxTopOfStack[ 2 ] = 0x04040404UL;
\r
111 pxTopOfStack[ 1 ] = 0x03030303UL;
\r
112 pxTopOfStack[ 0 ] = ( uint32_t ) pvParameters;
\r
114 return pxTopOfStack;
\r
116 /*-----------------------------------------------------------*/
\r
118 BaseType_t xPortStartScheduler( void )
\r
120 /* Set-up the timer interrupt. */
\r
121 prvSetupTimerInterrupt();
\r
123 /* Integrated Interrupt Controller: Enable all interrupts. */
\r
126 /* Restore callee saved registers. */
\r
127 portRESTORE_CONTEXT();
\r
129 /* Should not get here. */
\r
132 /*-----------------------------------------------------------*/
\r
134 static void prvSetupTimerInterrupt( void )
\r
136 /* Enable timer interrupts */
\r
137 counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;
\r
138 counter1->value = counter1->reload;
\r
139 counter1->mask = 1;
\r
141 /* Set the IRQ Handler priority and enable it. */
\r
142 irq[ IRQ_COUNTER1 ].ien = 1;
\r
144 /*-----------------------------------------------------------*/
\r
146 /* Trap 31 handler. */
\r
147 void interrupt31_handler( void ) __attribute__((naked));
\r
148 void interrupt31_handler( void )
\r
150 portSAVE_CONTEXT();
\r
151 __asm volatile ( "call vTaskSwitchContext" );
\r
152 portRESTORE_CONTEXT();
\r
154 /*-----------------------------------------------------------*/
\r
156 static void prvProcessTick( void ) __attribute__((noinline));
\r
157 static void prvProcessTick( void )
\r
159 if( xTaskIncrementTick() != pdFALSE )
\r
161 vTaskSwitchContext();
\r
164 /* Clear the Tick Interrupt. */
\r
165 counter1->expired = 0;
\r
167 /*-----------------------------------------------------------*/
\r
169 /* Timer 1 interrupt handler, used for tick interrupt. */
\r
170 void interrupt7_handler( void ) __attribute__((naked));
\r
171 void interrupt7_handler( void )
\r
173 portSAVE_CONTEXT();
\r
175 portRESTORE_CONTEXT();
\r
177 /*-----------------------------------------------------------*/
\r
179 void vPortEndScheduler( void )
\r
181 /* Nothing to do. Unlikely to want to end. */
\r
183 /*-----------------------------------------------------------*/
\r