]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c
80e96b0d059c973ace0d108356cfbb7b8e9bac71
[freertos] / FreeRTOS / Source / portable / Paradigm / Tern_EE / large_untested / port.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32     >>>NOTE<<< The modification to the GPL is included to allow you to\r
33     distribute a combined work that includes FreeRTOS without being obliged to\r
34     provide the source code for proprietary components outside of the FreeRTOS\r
35     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
36     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
37     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
38     more details. You should have received a copy of the GNU General Public\r
39     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
40     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
41     by writing to Richard Barry, contact details for whom are available on the\r
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \r
62     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
63     the code with commercial support, indemnification, and middleware, under \r
64     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
65     provide a safety engineered and independently SIL3 certified version under \r
66     the SafeRTOS brand: http://www.SafeRTOS.com.\r
67 */\r
68 \r
69 \r
70 /*-----------------------------------------------------------\r
71  * Implementation of functions defined in portable.h for the Tern EE 186\r
72  * port.\r
73  *----------------------------------------------------------*/\r
74 \r
75 /* Library includes. */\r
76 #include <embedded.h>\r
77 #include <ae.h>\r
78 \r
79 /* Scheduler includes. */\r
80 #include "FreeRTOS.h"\r
81 #include "task.h"\r
82 #include "portasm.h"\r
83 \r
84 /* The timer increments every four clocks, hence the divide by 4. */\r
85 #define portTIMER_COMPARE ( unsigned short ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( unsigned long ) 4 )\r
86 \r
87 /* From the RDC data sheet. */\r
88 #define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe001\r
89 \r
90 /* Interrupt control. */\r
91 #define portEIO_REGISTER 0xff22\r
92 #define portCLEAR_INTERRUPT 0x0008\r
93 \r
94 /* Setup the hardware to generate the required tick frequency. */\r
95 static void prvSetupTimerInterrupt( void );\r
96 \r
97 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
98 is being used. */\r
99 #if( configUSE_PREEMPTION == 1 )\r
100         /* Tick service routine used by the scheduler when preemptive scheduling is\r
101         being used. */\r
102         static void __interrupt __far prvPreemptiveTick( void );\r
103 #else\r
104         /* Tick service routine used by the scheduler when cooperative scheduling is\r
105         being used. */\r
106         static void __interrupt __far prvNonPreemptiveTick( void );\r
107 #endif\r
108 \r
109 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
110 static void __interrupt __far prvYieldProcessor( void );\r
111 \r
112 /* The timer initialisation functions leave interrupts enabled,\r
113 which is not what we want.  This ISR is installed temporarily in case\r
114 the timer fires before we get a change to disable interrupts again. */\r
115 static void __interrupt __far prvDummyISR( void );\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 /* See header file for description. */\r
119 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
120 {\r
121 portSTACK_TYPE DS_Reg = 0;\r
122 \r
123         /* Place a few bytes of known values on the bottom of the stack.\r
124         This is just useful for debugging. */\r
125 \r
126         *pxTopOfStack = 0x1111;\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = 0x2222;\r
129         pxTopOfStack--;\r
130         *pxTopOfStack = 0x3333;\r
131         pxTopOfStack--;\r
132 \r
133         /* We are going to start the scheduler using a return from interrupt\r
134         instruction to load the program counter, so first there would be the\r
135         function call with parameters preamble. */\r
136         \r
137         *pxTopOfStack = FP_SEG( pvParameters );\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = FP_OFF( pvParameters );\r
140         pxTopOfStack--;\r
141         *pxTopOfStack = FP_SEG( pxCode );\r
142         pxTopOfStack--;\r
143         *pxTopOfStack = FP_OFF( pxCode );\r
144         pxTopOfStack--;\r
145 \r
146         /* Next the status register and interrupt return address. */\r
147         *pxTopOfStack = portINITIAL_SW;\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = FP_SEG( pxCode );\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = FP_OFF( pxCode );\r
152         pxTopOfStack--;\r
153 \r
154         /* The remaining registers would be pushed on the stack by our context\r
155         switch function.  These are loaded with values simply to make debugging\r
156         easier. */\r
157         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
158         pxTopOfStack--;\r
159         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
160         pxTopOfStack--;\r
161         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
162         pxTopOfStack--;\r
163         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
164         pxTopOfStack--;\r
165         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
166         pxTopOfStack--;\r
167 \r
168         /* We need the true data segment. */\r
169         __asm{  MOV DS_Reg, DS };\r
170 \r
171         *pxTopOfStack = DS_Reg;                                         /* DS */\r
172         pxTopOfStack--;\r
173         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
174         pxTopOfStack--;\r
175         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
176         pxTopOfStack--;\r
177         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
178 \r
179         return pxTopOfStack;\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 portBASE_TYPE xPortStartScheduler( void )\r
184 {\r
185         /* This is called with interrupts already disabled. */\r
186 \r
187         /* Put our manual switch (yield) function on a known\r
188         vector. */\r
189         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
190 \r
191         /* Setup the tick interrupt. */\r
192         prvSetupTimerInterrupt();\r
193 \r
194         /* Kick off the scheduler by setting up the context of the first task. */\r
195         portFIRST_CONTEXT();\r
196 \r
197         /* Should not get here! */\r
198         return pdFALSE;\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 static void __interrupt __far prvDummyISR( void )\r
203 {\r
204         /* The timer initialisation functions leave interrupts enabled,\r
205         which is not what we want.  This ISR is installed temporarily in case\r
206         the timer fires before we get a change to disable interrupts again. */\r
207         outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r
211 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
212 is being used. */\r
213 #if( configUSE_PREEMPTION == 1 )\r
214         static void __interrupt __far prvPreemptiveTick( void )\r
215         {\r
216                 /* Get the scheduler to update the task states following the tick. */\r
217                 vTaskIncrementTick();\r
218 \r
219                 /* Switch in the context of the next task to be run. */\r
220                 portSWITCH_CONTEXT();\r
221 \r
222                 /* Reset interrupt. */\r
223                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
224         }\r
225 #else\r
226         static void __interrupt __far prvNonPreemptiveTick( void )\r
227         {\r
228                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
229                 so we don't have to switch in the context of the next task. */\r
230                 vTaskIncrementTick();\r
231                 /* Reset interrupt. */\r
232                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
233         }\r
234 #endif\r
235 /*-----------------------------------------------------------*/\r
236 \r
237 static void __interrupt __far prvYieldProcessor( void )\r
238 {\r
239         /* Switch in the context of the next task to be run. */\r
240         portSWITCH_CONTEXT();\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 void vPortEndScheduler( void )\r
245 {\r
246         /* Not implemented. */\r
247 }\r
248 /*-----------------------------------------------------------*/\r
249 \r
250 static void prvSetupTimerInterrupt( void )\r
251 {\r
252 const unsigned short usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT;\r
253 const unsigned short usT2_IRQ = 0x13;\r
254 \r
255         /* Configure the timer, the dummy handler is used here as the init\r
256         function leaves interrupts enabled. */\r
257         t2_init( usTimerAMode, usTimerACompare, prvDummyISR );\r
258 \r
259         /* Disable interrupts again before installing the real handlers. */\r
260         portDISABLE_INTERRUPTS();\r
261 \r
262         #if( configUSE_PREEMPTION == 1 )\r
263                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
264                 being used. */\r
265                 setvect( usT2_IRQ, prvPreemptiveTick );\r
266         #else\r
267                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
268                 being used. */\r
269                 setvect( usT2_IRQ, prvNonPreemptiveTick );\r
270         #endif\r
271 }\r
272 \r
273 \r
274 \r
275 \r
276 \r
277 \r
278 \r