]> git.sur5r.net Git - freertos/blob - Source/portable/Paradigm/Tern_EE/small/port.c
e655559ca038a55b461d7d93f7cdde3726ce3640
[freertos] / Source / portable / Paradigm / Tern_EE / small / port.c
1 /*\r
2         FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \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
10 \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
15 \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
19 \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
24         can be applied.\r
25 \r
26     ***************************************************************************\r
27     ***************************************************************************\r
28     *                                                                         *\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
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 \r
51 /*-----------------------------------------------------------\r
52  * Implementation of functions defined in portable.h for the Tern EE 186\r
53  * port.\r
54  *----------------------------------------------------------*/\r
55 \r
56 /* Library includes. */\r
57 #include <embedded.h>\r
58 #include <ae.h>\r
59 \r
60 /* Scheduler includes. */\r
61 #include "FreeRTOS.h"\r
62 #include "task.h"\r
63 #include "portasm.h"\r
64 \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
68 \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
72 \r
73 /* Interrupt control. */\r
74 #define portEIO_REGISTER 0xff22\r
75 #define portCLEAR_INTERRUPT 0x0008\r
76 \r
77 /* Setup the hardware to generate the required tick frequency. */\r
78 static void prvSetupTimerInterrupt( void );\r
79 \r
80 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
81 is being used. */\r
82 #if( configUSE_PREEMPTION == 1 )\r
83         /* Tick service routine used by the scheduler when preemptive scheduling is\r
84         being used. */\r
85         static void __interrupt __far prvPreemptiveTick( void );\r
86 #else\r
87         /* Tick service routine used by the scheduler when cooperative scheduling is\r
88         being used. */\r
89         static void __interrupt __far prvNonPreemptiveTick( void );\r
90 #endif\r
91 \r
92 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
93 static void __interrupt __far prvYieldProcessor( void );\r
94 \r
95 /*-----------------------------------------------------------*/\r
96 /* See header file for description. */\r
97 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
98 {\r
99 portSTACK_TYPE DS_Reg = 0;\r
100 \r
101         /* We need the true data segment. */\r
102         __asm{  MOV DS_Reg, DS };\r
103 \r
104         /* Place a few bytes of known values on the bottom of the stack.\r
105         This is just useful for debugging. */\r
106 \r
107         *pxTopOfStack = 0x1111;\r
108         pxTopOfStack--;\r
109         *pxTopOfStack = 0x2222;\r
110         pxTopOfStack--;\r
111         *pxTopOfStack = 0x3333;\r
112         pxTopOfStack--;\r
113 \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
117         \r
118         *pxTopOfStack = FP_OFF( pvParameters );\r
119         pxTopOfStack--;\r
120         *pxTopOfStack = FP_OFF( pxCode );\r
121         pxTopOfStack--;\r
122 \r
123         /* Next the status register and interrupt return address. */\r
124         *pxTopOfStack = portINITIAL_SW;\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         /* 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
133         easier. */\r
134         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
135         pxTopOfStack--;\r
136         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
137         pxTopOfStack--;\r
138         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
139         pxTopOfStack--;\r
140         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
141         pxTopOfStack--;\r
142         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
143         pxTopOfStack--;\r
144 \r
145         *pxTopOfStack = DS_Reg;                                         /* DS */\r
146         pxTopOfStack--;\r
147         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
152 \r
153         return pxTopOfStack;\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 portBASE_TYPE xPortStartScheduler( void )\r
158 {\r
159         /* This is called with interrupts already disabled. */\r
160 \r
161         /* Put our manual switch (yield) function on a known\r
162         vector. */\r
163         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
164 \r
165         /* Setup the tick interrupt. */\r
166         prvSetupTimerInterrupt();\r
167 \r
168         /* Kick off the scheduler by setting up the context of the first task. */\r
169         portFIRST_CONTEXT();\r
170 \r
171         /* Should not get here! */\r
172         return pdFALSE;\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
177 is being used. */\r
178 #if( configUSE_PREEMPTION == 1 )\r
179         static void __interrupt __far prvPreemptiveTick( void )\r
180         {\r
181                 /* Get the scheduler to update the task states following the tick. */\r
182                 vTaskIncrementTick();\r
183 \r
184                 /* Switch in the context of the next task to be run. */\r
185                 portEND_SWITCHING_ISR();\r
186 \r
187                 /* Reset interrupt. */\r
188                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
189         }\r
190 #else\r
191         static void __interrupt __far prvNonPreemptiveTick( void )\r
192         {\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
198         }\r
199 #endif\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 static void __interrupt __far prvYieldProcessor( void )\r
203 {\r
204         /* Switch in the context of the next task to be run. */\r
205         portEND_SWITCHING_ISR();\r
206 }\r
207 /*-----------------------------------------------------------*/\r
208 \r
209 void vPortEndScheduler( void )\r
210 {\r
211         /* Not implemented. */\r
212 }\r
213 /*-----------------------------------------------------------*/\r
214 \r
215 static void prvSetupTimerInterrupt( void )\r
216 {\r
217 const unsigned portLONG ulCompareValue = portTIMER_COMPARE;\r
218 unsigned portSHORT usTimerCompare;\r
219 \r
220         usTimerCompare = ( unsigned portSHORT ) ( ulCompareValue >> 4 );\r
221     t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );\r
222 \r
223         #if( configUSE_PREEMPTION == 1 )\r
224                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
225                 being used. */\r
226                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );\r
227         #else\r
228                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
229                 being used. */\r
230                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );\r
231         #endif\r
232 }\r
233 \r
234 \r
235 \r
236 \r
237 \r
238 \r
239 \r