2 FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 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
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 /*-----------------------------------------------------------
\r
52 * Implementation of functions defined in portable.h for the Tern EE 186
\r
54 *----------------------------------------------------------*/
\r
56 /* Library includes. */
\r
57 #include <embedded.h>
\r
60 /* Scheduler includes. */
\r
61 #include "FreeRTOS.h"
\r
63 #include "portasm.h"
\r
65 /* The timer increments every four clocks, hence the divide by 4. */
\r
66 #define portPRESCALE_VALUE ( 16 )
\r
67 #define portTIMER_COMPARE ( configCPU_CLOCK_HZ / ( configTICK_RATE_HZ * 4UL ) )
\r
69 /* From the RDC data sheet. */
\r
70 #define portENABLE_TIMER_AND_INTERRUPT ( unsigned portSHORT ) 0xe00b
\r
71 #define portENABLE_TIMER ( unsigned portSHORT ) 0xC001
\r
73 /* Interrupt control. */
\r
74 #define portEIO_REGISTER 0xff22
\r
75 #define portCLEAR_INTERRUPT 0x0008
\r
77 /* Setup the hardware to generate the required tick frequency. */
\r
78 static void prvSetupTimerInterrupt( void );
\r
80 /* The ISR used depends on whether the preemptive or cooperative scheduler
\r
82 #if( configUSE_PREEMPTION == 1 )
\r
83 /* Tick service routine used by the scheduler when preemptive scheduling is
\r
85 static void __interrupt __far prvPreemptiveTick( void );
\r
87 /* Tick service routine used by the scheduler when cooperative scheduling is
\r
89 static void __interrupt __far prvNonPreemptiveTick( void );
\r
92 /* Trap routine used by taskYIELD() to manually cause a context switch. */
\r
93 static void __interrupt __far prvYieldProcessor( void );
\r
95 /*-----------------------------------------------------------*/
\r
96 /* See header file for description. */
\r
97 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
99 portSTACK_TYPE DS_Reg = 0;
\r
101 /* We need the true data segment. */
\r
102 __asm{ MOV DS_Reg, DS };
\r
104 /* Place a few bytes of known values on the bottom of the stack.
\r
105 This is just useful for debugging. */
\r
107 *pxTopOfStack = 0x1111;
\r
109 *pxTopOfStack = 0x2222;
\r
111 *pxTopOfStack = 0x3333;
\r
114 /* We are going to start the scheduler using a return from interrupt
\r
115 instruction to load the program counter, so first there would be the
\r
116 function call with parameters preamble. */
\r
118 *pxTopOfStack = FP_OFF( pvParameters );
\r
120 *pxTopOfStack = FP_OFF( pxCode );
\r
123 /* Next the status register and interrupt return address. */
\r
124 *pxTopOfStack = portINITIAL_SW;
\r
126 *pxTopOfStack = FP_SEG( pxCode );
\r
128 *pxTopOfStack = FP_OFF( pxCode );
\r
131 /* The remaining registers would be pushed on the stack by our context
\r
132 switch function. These are loaded with values simply to make debugging
\r
134 *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA; /* AX */
\r
136 *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BX */
\r
138 *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC; /* CX */
\r
140 *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DX */
\r
142 *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE; /* ES */
\r
145 *pxTopOfStack = DS_Reg; /* DS */
\r
147 *pxTopOfStack = ( portSTACK_TYPE ) 0x0123; /* SI */
\r
149 *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DI */
\r
151 *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BP */
\r
153 return pxTopOfStack;
\r
155 /*-----------------------------------------------------------*/
\r
157 portBASE_TYPE xPortStartScheduler( void )
\r
159 /* This is called with interrupts already disabled. */
\r
161 /* Put our manual switch (yield) function on a known
\r
163 setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );
\r
165 /* Setup the tick interrupt. */
\r
166 prvSetupTimerInterrupt();
\r
168 /* Kick off the scheduler by setting up the context of the first task. */
\r
169 portFIRST_CONTEXT();
\r
171 /* Should not get here! */
\r
174 /*-----------------------------------------------------------*/
\r
176 /* The ISR used depends on whether the preemptive or cooperative scheduler
\r
178 #if( configUSE_PREEMPTION == 1 )
\r
179 static void __interrupt __far prvPreemptiveTick( void )
\r
181 /* Get the scheduler to update the task states following the tick. */
\r
182 vTaskIncrementTick();
\r
184 /* Switch in the context of the next task to be run. */
\r
185 portEND_SWITCHING_ISR();
\r
187 /* Reset interrupt. */
\r
188 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
\r
191 static void __interrupt __far prvNonPreemptiveTick( void )
\r
193 /* Same as preemptive tick, but the cooperative scheduler is being used
\r
194 so we don't have to switch in the context of the next task. */
\r
195 vTaskIncrementTick();
\r
196 /* Reset interrupt. */
\r
197 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
\r
200 /*-----------------------------------------------------------*/
\r
202 static void __interrupt __far prvYieldProcessor( void )
\r
204 /* Switch in the context of the next task to be run. */
\r
205 portEND_SWITCHING_ISR();
\r
207 /*-----------------------------------------------------------*/
\r
209 void vPortEndScheduler( void )
\r
211 /* Not implemented. */
\r
213 /*-----------------------------------------------------------*/
\r
215 static void prvSetupTimerInterrupt( void )
\r
217 const unsigned portLONG ulCompareValue = portTIMER_COMPARE;
\r
218 unsigned portSHORT usTimerCompare;
\r
220 usTimerCompare = ( unsigned portSHORT ) ( ulCompareValue >> 4 );
\r
221 t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );
\r
223 #if( configUSE_PREEMPTION == 1 )
\r
224 /* Tick service routine used by the scheduler when preemptive scheduling is
\r
226 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );
\r
228 /* Tick service routine used by the scheduler when cooperative scheduling is
\r
230 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );
\r