]> git.sur5r.net Git - freertos/blob - Source/portable/Paradigm/Tern_EE/large_untested/port.c
Update to V6.1.1
[freertos] / Source / portable / Paradigm / Tern_EE / large_untested / port.c
1 /*\r
2     FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \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 exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     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
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 \r
55 /*-----------------------------------------------------------\r
56  * Implementation of functions defined in portable.h for the Tern EE 186\r
57  * port.\r
58  *----------------------------------------------------------*/\r
59 \r
60 /* Library includes. */\r
61 #include <embedded.h>\r
62 #include <ae.h>\r
63 \r
64 /* Scheduler includes. */\r
65 #include "FreeRTOS.h"\r
66 #include "task.h"\r
67 #include "portasm.h"\r
68 \r
69 /* The timer increments every four clocks, hence the divide by 4. */\r
70 #define portTIMER_COMPARE ( unsigned short ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( unsigned long ) 4 )\r
71 \r
72 /* From the RDC data sheet. */\r
73 #define portENABLE_TIMER_AND_INTERRUPT ( unsigned short ) 0xe001\r
74 \r
75 /* Interrupt control. */\r
76 #define portEIO_REGISTER 0xff22\r
77 #define portCLEAR_INTERRUPT 0x0008\r
78 \r
79 /* Setup the hardware to generate the required tick frequency. */\r
80 static void prvSetupTimerInterrupt( void );\r
81 \r
82 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
83 is being used. */\r
84 #if( configUSE_PREEMPTION == 1 )\r
85         /* Tick service routine used by the scheduler when preemptive scheduling is\r
86         being used. */\r
87         static void __interrupt __far prvPreemptiveTick( void );\r
88 #else\r
89         /* Tick service routine used by the scheduler when cooperative scheduling is\r
90         being used. */\r
91         static void __interrupt __far prvNonPreemptiveTick( void );\r
92 #endif\r
93 \r
94 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
95 static void __interrupt __far prvYieldProcessor( void );\r
96 \r
97 /* The timer initialisation functions leave interrupts enabled,\r
98 which is not what we want.  This ISR is installed temporarily in case\r
99 the timer fires before we get a change to disable interrupts again. */\r
100 static void __interrupt __far prvDummyISR( void );\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 /* See header file for description. */\r
104 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
105 {\r
106 portSTACK_TYPE DS_Reg = 0;\r
107 \r
108         /* Place a few bytes of known values on the bottom of the stack.\r
109         This is just useful for debugging. */\r
110 \r
111         *pxTopOfStack = 0x1111;\r
112         pxTopOfStack--;\r
113         *pxTopOfStack = 0x2222;\r
114         pxTopOfStack--;\r
115         *pxTopOfStack = 0x3333;\r
116         pxTopOfStack--;\r
117 \r
118         /* We are going to start the scheduler using a return from interrupt\r
119         instruction to load the program counter, so first there would be the\r
120         function call with parameters preamble. */\r
121         \r
122         *pxTopOfStack = FP_SEG( pvParameters );\r
123         pxTopOfStack--;\r
124         *pxTopOfStack = FP_OFF( pvParameters );\r
125         pxTopOfStack--;\r
126         *pxTopOfStack = FP_SEG( pxCode );\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = FP_OFF( pxCode );\r
129         pxTopOfStack--;\r
130 \r
131         /* Next the status register and interrupt return address. */\r
132         *pxTopOfStack = portINITIAL_SW;\r
133         pxTopOfStack--;\r
134         *pxTopOfStack = FP_SEG( pxCode );\r
135         pxTopOfStack--;\r
136         *pxTopOfStack = FP_OFF( pxCode );\r
137         pxTopOfStack--;\r
138 \r
139         /* The remaining registers would be pushed on the stack by our context\r
140         switch function.  These are loaded with values simply to make debugging\r
141         easier. */\r
142         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
143         pxTopOfStack--;\r
144         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
145         pxTopOfStack--;\r
146         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
147         pxTopOfStack--;\r
148         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
149         pxTopOfStack--;\r
150         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
151         pxTopOfStack--;\r
152 \r
153         /* We need the true data segment. */\r
154         __asm{  MOV DS_Reg, DS };\r
155 \r
156         *pxTopOfStack = DS_Reg;                                         /* DS */\r
157         pxTopOfStack--;\r
158         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
159         pxTopOfStack--;\r
160         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
163 \r
164         return pxTopOfStack;\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 portBASE_TYPE xPortStartScheduler( void )\r
169 {\r
170         /* This is called with interrupts already disabled. */\r
171 \r
172         /* Put our manual switch (yield) function on a known\r
173         vector. */\r
174         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
175 \r
176         /* Setup the tick interrupt. */\r
177         prvSetupTimerInterrupt();\r
178 \r
179         /* Kick off the scheduler by setting up the context of the first task. */\r
180         portFIRST_CONTEXT();\r
181 \r
182         /* Should not get here! */\r
183         return pdFALSE;\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void __interrupt __far prvDummyISR( void )\r
188 {\r
189         /* The timer initialisation functions leave interrupts enabled,\r
190         which is not what we want.  This ISR is installed temporarily in case\r
191         the timer fires before we get a change to disable interrupts again. */\r
192         outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
197 is being used. */\r
198 #if( configUSE_PREEMPTION == 1 )\r
199         static void __interrupt __far prvPreemptiveTick( void )\r
200         {\r
201                 /* Get the scheduler to update the task states following the tick. */\r
202                 vTaskIncrementTick();\r
203 \r
204                 /* Switch in the context of the next task to be run. */\r
205                 portSWITCH_CONTEXT();\r
206 \r
207                 /* Reset interrupt. */\r
208                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
209         }\r
210 #else\r
211         static void __interrupt __far prvNonPreemptiveTick( void )\r
212         {\r
213                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
214                 so we don't have to switch in the context of the next task. */\r
215                 vTaskIncrementTick();\r
216                 /* Reset interrupt. */\r
217                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
218         }\r
219 #endif\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 static void __interrupt __far prvYieldProcessor( void )\r
223 {\r
224         /* Switch in the context of the next task to be run. */\r
225         portSWITCH_CONTEXT();\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 void vPortEndScheduler( void )\r
230 {\r
231         /* Not implemented. */\r
232 }\r
233 /*-----------------------------------------------------------*/\r
234 \r
235 static void prvSetupTimerInterrupt( void )\r
236 {\r
237 const unsigned short usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT;\r
238 const unsigned short usT2_IRQ = 0x13;\r
239 \r
240         /* Configure the timer, the dummy handler is used here as the init\r
241         function leaves interrupts enabled. */\r
242         t2_init( usTimerAMode, usTimerACompare, prvDummyISR );\r
243 \r
244         /* Disable interrupts again before installing the real handlers. */\r
245         portDISABLE_INTERRUPTS();\r
246 \r
247         #if( configUSE_PREEMPTION == 1 )\r
248                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
249                 being used. */\r
250                 setvect( usT2_IRQ, prvPreemptiveTick );\r
251         #else\r
252                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
253                 being used. */\r
254                 setvect( usT2_IRQ, prvNonPreemptiveTick );\r
255         #endif\r
256 }\r
257 \r
258 \r
259 \r
260 \r
261 \r
262 \r
263 \r