2 FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 /* Kernel includes. */
\r
53 #include "FreeRTOS.h"
\r
57 #define portINITIAL_FORMAT_VECTOR ( ( portSTACK_TYPE ) 0x4000 )
\r
59 /* Supervisor mode set. */
\r
60 #define portINITIAL_STATUS_REGISTER ( ( portSTACK_TYPE ) 0x2000)
\r
62 /* The clock prescale into the timer peripheral. */
\r
63 #define portPRESCALE_VALUE ( ( unsigned portCHAR ) 10 )
\r
65 /* The clock frequency into the RTC. */
\r
66 #define portRTC_CLOCK_HZ ( ( unsigned portLONG ) 1000 )
\r
68 asm void interrupt VectorNumber_VL1swi vPortYieldISR( void );
\r
69 static void prvSetupTimerInterrupt( void );
\r
71 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This
\r
72 will be set to 0 prior to the first task being started. */
\r
73 static unsigned portLONG ulCriticalNesting = 0x9999UL;
\r
75 /*-----------------------------------------------------------*/
\r
77 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
80 unsigned portLONG ulOriginalA5;
\r
82 __asm{ MOVE.L A5, ulOriginalA5 };
\r
85 *pxTopOfStack = (portSTACK_TYPE) 0xDEADBEEF;
\r
88 /* Exception stack frame starts with the return address. */
\r
89 *pxTopOfStack = ( portSTACK_TYPE ) pxCode;
\r
92 *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
\r
95 *pxTopOfStack = ( portSTACK_TYPE ) 0x0; /*FP*/
\r
96 pxTopOfStack -= 14; /* A5 to D0. */
\r
98 /* Parameter in A0. */
\r
99 *( pxTopOfStack + 8 ) = ( portSTACK_TYPE ) pvParameters;
\r
101 /* A5 must be maintained as it is resurved by the compiler. */
\r
102 *( pxTopOfStack + 13 ) = ulOriginalA5;
\r
104 return pxTopOfStack;
\r
106 /*-----------------------------------------------------------*/
\r
108 portBASE_TYPE xPortStartScheduler( void )
\r
110 extern void vPortStartFirstTask( void );
\r
112 ulCriticalNesting = 0UL;
\r
114 /* Configure a timer to generate the tick interrupt. */
\r
115 prvSetupTimerInterrupt();
\r
117 /* Start the first task executing. */
\r
118 vPortStartFirstTask();
\r
122 /*-----------------------------------------------------------*/
\r
124 static void prvSetupTimerInterrupt( void )
\r
126 /* Prescale by 1 - ie no prescale. */
\r
129 /* Compare match value. */
\r
130 RTCMOD = portRTC_CLOCK_HZ / configTICK_RATE_HZ;
\r
132 /* Enable the RTC to generate interrupts - interrupts are already disabled
\r
133 when this code executes. */
\r
136 /*-----------------------------------------------------------*/
\r
138 void vPortEndScheduler( void )
\r
140 /* Not implemented as there is nothing to return to. */
\r
142 /*-----------------------------------------------------------*/
\r
144 void vPortEnterCritical( void )
\r
146 if( ulCriticalNesting == 0UL )
\r
148 /* Guard against context switches being pended simultaneously with a
\r
149 critical section being entered. */
\r
152 portDISABLE_INTERRUPTS();
\r
153 if( INTC_FRC == 0UL )
\r
158 portENABLE_INTERRUPTS();
\r
162 ulCriticalNesting++;
\r
164 /*-----------------------------------------------------------*/
\r
166 void vPortExitCritical( void )
\r
168 ulCriticalNesting--;
\r
169 if( ulCriticalNesting == 0 )
\r
171 portENABLE_INTERRUPTS();
\r
174 /*-----------------------------------------------------------*/
\r
176 void vPortYieldHandler( void )
\r
178 unsigned portLONG ulSavedInterruptMask;
\r
180 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
182 /* Note this will clear all forced interrupts - this is done for speed. */
\r
184 vTaskSwitchContext();
\r
186 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
\r
188 /*-----------------------------------------------------------*/
\r
190 void interrupt VectorNumber_Vrtc vPortTickISR( void )
\r
192 unsigned portLONG ulSavedInterruptMask;
\r
194 /* Clear the interrupt. */
\r
195 RTCSC |= RTCSC_RTIF_MASK;
\r
197 /* Increment the RTOS tick. */
\r
198 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
\r
200 vTaskIncrementTick();
\r
202 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
\r
204 /* If we are using the pre-emptive scheduler then also request a
\r
205 context switch as incrementing the tick could have unblocked a task. */
\r
206 #if configUSE_PREEMPTION == 1
\r