2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 /*-----------------------------------------------------------
\r
69 * Implementation of functions defined in portable.h for the Tern EE 186
\r
71 *----------------------------------------------------------*/
\r
73 /* Library includes. */
\r
74 #include <embedded.h>
\r
77 /* Scheduler includes. */
\r
78 #include "FreeRTOS.h"
\r
80 #include "portasm.h"
\r
82 /* The timer increments every four clocks, hence the divide by 4. */
\r
83 #define portPRESCALE_VALUE ( 16 )
\r
84 #define portTIMER_COMPARE ( configCPU_CLOCK_HZ / ( configTICK_RATE_HZ * 4UL ) )
\r
86 /* From the RDC data sheet. */
\r
87 #define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe00b
\r
88 #define portENABLE_TIMER ( unsigned short ) 0xC001
\r
90 /* Interrupt control. */
\r
91 #define portEIO_REGISTER 0xff22
\r
92 #define portCLEAR_INTERRUPT 0x0008
\r
94 /* Setup the hardware to generate the required tick frequency. */
\r
95 static void prvSetupTimerInterrupt( void );
\r
97 /* The ISR used depends on whether the preemptive or cooperative scheduler
\r
99 #if( configUSE_PREEMPTION == 1 )
\r
100 /* Tick service routine used by the scheduler when preemptive scheduling is
\r
102 static void __interrupt __far prvPreemptiveTick( void );
\r
104 /* Tick service routine used by the scheduler when cooperative scheduling is
\r
106 static void __interrupt __far prvNonPreemptiveTick( void );
\r
109 /* Trap routine used by taskYIELD() to manually cause a context switch. */
\r
110 static void __interrupt __far prvYieldProcessor( void );
\r
112 /*-----------------------------------------------------------*/
\r
113 /* See header file for description. */
\r
114 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
116 portSTACK_TYPE DS_Reg = 0;
\r
118 /* We need the true data segment. */
\r
119 __asm{ MOV DS_Reg, DS };
\r
121 /* Place a few bytes of known values on the bottom of the stack.
\r
122 This is just useful for debugging. */
\r
124 *pxTopOfStack = 0x1111;
\r
126 *pxTopOfStack = 0x2222;
\r
128 *pxTopOfStack = 0x3333;
\r
131 /* We are going to start the scheduler using a return from interrupt
\r
132 instruction to load the program counter, so first there would be the
\r
133 function call with parameters preamble. */
\r
135 *pxTopOfStack = FP_OFF( pvParameters );
\r
137 *pxTopOfStack = FP_OFF( pxCode );
\r
140 /* Next the status register and interrupt return address. */
\r
141 *pxTopOfStack = portINITIAL_SW;
\r
143 *pxTopOfStack = FP_SEG( pxCode );
\r
145 *pxTopOfStack = FP_OFF( pxCode );
\r
148 /* The remaining registers would be pushed on the stack by our context
\r
149 switch function. These are loaded with values simply to make debugging
\r
151 *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA; /* AX */
\r
153 *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BX */
\r
155 *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC; /* CX */
\r
157 *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DX */
\r
159 *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE; /* ES */
\r
162 *pxTopOfStack = DS_Reg; /* DS */
\r
164 *pxTopOfStack = ( portSTACK_TYPE ) 0x0123; /* SI */
\r
166 *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD; /* DI */
\r
168 *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB; /* BP */
\r
170 return pxTopOfStack;
\r
172 /*-----------------------------------------------------------*/
\r
174 portBASE_TYPE xPortStartScheduler( void )
\r
176 /* This is called with interrupts already disabled. */
\r
178 /* Put our manual switch (yield) function on a known
\r
180 setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );
\r
182 /* Setup the tick interrupt. */
\r
183 prvSetupTimerInterrupt();
\r
185 /* Kick off the scheduler by setting up the context of the first task. */
\r
186 portFIRST_CONTEXT();
\r
188 /* Should not get here! */
\r
191 /*-----------------------------------------------------------*/
\r
193 /* The ISR used depends on whether the preemptive or cooperative scheduler
\r
195 #if( configUSE_PREEMPTION == 1 )
\r
196 static void __interrupt __far prvPreemptiveTick( void )
\r
198 /* Get the scheduler to update the task states following the tick. */
\r
199 vTaskIncrementTick();
\r
201 /* Switch in the context of the next task to be run. */
\r
202 portEND_SWITCHING_ISR();
\r
204 /* Reset interrupt. */
\r
205 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
\r
208 static void __interrupt __far prvNonPreemptiveTick( void )
\r
210 /* Same as preemptive tick, but the cooperative scheduler is being used
\r
211 so we don't have to switch in the context of the next task. */
\r
212 vTaskIncrementTick();
\r
213 /* Reset interrupt. */
\r
214 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );
\r
217 /*-----------------------------------------------------------*/
\r
219 static void __interrupt __far prvYieldProcessor( void )
\r
221 /* Switch in the context of the next task to be run. */
\r
222 portEND_SWITCHING_ISR();
\r
224 /*-----------------------------------------------------------*/
\r
226 void vPortEndScheduler( void )
\r
228 /* Not implemented. */
\r
230 /*-----------------------------------------------------------*/
\r
232 static void prvSetupTimerInterrupt( void )
\r
234 const unsigned long ulCompareValue = portTIMER_COMPARE;
\r
235 unsigned short usTimerCompare;
\r
237 usTimerCompare = ( unsigned short ) ( ulCompareValue >> 4 );
\r
238 t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );
\r
240 #if( configUSE_PREEMPTION == 1 )
\r
241 /* Tick service routine used by the scheduler when preemptive scheduling is
\r
243 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );
\r
245 /* Tick service routine used by the scheduler when cooperative scheduling is
\r
247 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );
\r