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 /* Kernel includes. */
\r
74 #include "FreeRTOS.h"
\r
77 /* Machine includes */
\r
78 #include <machine/counter.h>
\r
79 #include <machine/ic.h>
\r
80 /*-----------------------------------------------------------*/
\r
82 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */
\r
83 #define portINITIAL_PSR ( 0x00020000 )
\r
85 /*-----------------------------------------------------------*/
\r
88 * Perform any hardware configuration necessary to generate the tick interrupt.
\r
90 static void prvSetupTimerInterrupt( void );
\r
91 /*-----------------------------------------------------------*/
\r
93 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
95 /* Make space on the stack for the context - this leaves a couple of spaces
\r
99 /* Fill the registers with known values to assist debugging. */
\r
100 pxTopOfStack[ 16 ] = 0;
\r
101 pxTopOfStack[ 15 ] = portINITIAL_PSR;
\r
102 pxTopOfStack[ 14 ] = ( uint32_t ) pxCode;
\r
103 pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */
\r
104 pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */
\r
105 pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;
\r
106 pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;
\r
107 pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;
\r
108 pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;
\r
109 pxTopOfStack[ 7 ] = 0x09090909UL;
\r
110 pxTopOfStack[ 6 ] = 0x08080808UL;
\r
111 pxTopOfStack[ 5 ] = 0x07070707UL;
\r
112 pxTopOfStack[ 4 ] = 0x06060606UL;
\r
113 pxTopOfStack[ 3 ] = 0x05050505UL;
\r
114 pxTopOfStack[ 2 ] = 0x04040404UL;
\r
115 pxTopOfStack[ 1 ] = 0x03030303UL;
\r
116 pxTopOfStack[ 0 ] = ( uint32_t ) pvParameters;
\r
118 return pxTopOfStack;
\r
120 /*-----------------------------------------------------------*/
\r
122 BaseType_t xPortStartScheduler( void )
\r
124 /* Set-up the timer interrupt. */
\r
125 prvSetupTimerInterrupt();
\r
127 /* Integrated Interrupt Controller: Enable all interrupts. */
\r
130 /* Restore callee saved registers. */
\r
131 portRESTORE_CONTEXT();
\r
133 /* Should not get here. */
\r
136 /*-----------------------------------------------------------*/
\r
138 static void prvSetupTimerInterrupt( void )
\r
140 /* Enable timer interrupts */
\r
141 counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;
\r
142 counter1->value = counter1->reload;
\r
143 counter1->mask = 1;
\r
145 /* Set the IRQ Handler priority and enable it. */
\r
146 irq[ IRQ_COUNTER1 ].ien = 1;
\r
148 /*-----------------------------------------------------------*/
\r
150 /* Trap 31 handler. */
\r
151 void interrupt31_handler( void ) __attribute__((naked));
\r
152 void interrupt31_handler( void )
\r
154 portSAVE_CONTEXT();
\r
155 __asm volatile ( "call vTaskSwitchContext" );
\r
156 portRESTORE_CONTEXT();
\r
158 /*-----------------------------------------------------------*/
\r
160 static void prvProcessTick( void ) __attribute__((noinline));
\r
161 static void prvProcessTick( void )
\r
163 if( xTaskIncrementTick() != pdFALSE )
\r
165 vTaskSwitchContext();
\r
168 /* Clear the Tick Interrupt. */
\r
169 counter1->expired = 0;
\r
171 /*-----------------------------------------------------------*/
\r
173 /* Timer 1 interrupt handler, used for tick interrupt. */
\r
174 void interrupt7_handler( void ) __attribute__((naked));
\r
175 void interrupt7_handler( void )
\r
177 portSAVE_CONTEXT();
\r
179 portRESTORE_CONTEXT();
\r
181 /*-----------------------------------------------------------*/
\r
183 void vPortEndScheduler( void )
\r
185 /* Nothing to do. Unlikely to want to end. */
\r
187 /*-----------------------------------------------------------*/
\r