]> git.sur5r.net Git - freertos/blob - Source/portable/Paradigm/Tern_EE/small/port.c
Update to V4.3.0 as described in http://www.FreeRTOS.org/History.txt
[freertos] / Source / portable / Paradigm / Tern_EE / small / port.c
1 /*\r
2         FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 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         See http://www.FreeRTOS.org for documentation, latest information, license\r
28         and contact details.  Please ensure to read the configuration and relevant\r
29         port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 \r
37 /*-----------------------------------------------------------\r
38  * Implementation of functions defined in portable.h for the Tern EE 186\r
39  * port.\r
40  *----------------------------------------------------------*/\r
41 \r
42 /* Library includes. */\r
43 #include <embedded.h>\r
44 #include <ae.h>\r
45 \r
46 /* Scheduler includes. */\r
47 #include "FreeRTOS.h"\r
48 #include "task.h"\r
49 #include "portasm.h"\r
50 \r
51 /* The timer increments every four clocks, hence the divide by 4. */\r
52 #define portPRESCALE_VALUE ( 16 )\r
53 #define portTIMER_COMPARE ( configCPU_CLOCK_HZ  / ( configTICK_RATE_HZ * 4UL ) )\r
54 \r
55 /* From the RDC data sheet. */\r
56 #define portENABLE_TIMER_AND_INTERRUPT  ( unsigned portSHORT ) 0xe00b\r
57 #define portENABLE_TIMER                                ( unsigned portSHORT ) 0xC001\r
58 \r
59 /* Interrupt control. */\r
60 #define portEIO_REGISTER 0xff22\r
61 #define portCLEAR_INTERRUPT 0x0008\r
62 \r
63 /* Setup the hardware to generate the required tick frequency. */\r
64 static void prvSetupTimerInterrupt( void );\r
65 \r
66 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
67 is being used. */\r
68 #if( configUSE_PREEMPTION == 1 )\r
69         /* Tick service routine used by the scheduler when preemptive scheduling is\r
70         being used. */\r
71         static void __interrupt __far prvPreemptiveTick( void );\r
72 #else\r
73         /* Tick service routine used by the scheduler when cooperative scheduling is\r
74         being used. */\r
75         static void __interrupt __far prvNonPreemptiveTick( void );\r
76 #endif\r
77 \r
78 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
79 static void __interrupt __far prvYieldProcessor( void );\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 /* See header file for description. */\r
83 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
84 {\r
85 portSTACK_TYPE DS_Reg = 0;\r
86 \r
87         /* We need the true data segment. */\r
88         __asm{  MOV DS_Reg, DS };\r
89 \r
90         /* Place a few bytes of known values on the bottom of the stack.\r
91         This is just useful for debugging. */\r
92 \r
93         *pxTopOfStack = 0x1111;\r
94         pxTopOfStack--;\r
95         *pxTopOfStack = 0x2222;\r
96         pxTopOfStack--;\r
97         *pxTopOfStack = 0x3333;\r
98         pxTopOfStack--;\r
99 \r
100         /* We are going to start the scheduler using a return from interrupt\r
101         instruction to load the program counter, so first there would be the\r
102         function call with parameters preamble. */\r
103         \r
104         *pxTopOfStack = FP_OFF( pvParameters );\r
105         pxTopOfStack--;\r
106         *pxTopOfStack = FP_OFF( pxCode );\r
107         pxTopOfStack--;\r
108 \r
109         /* Next the status register and interrupt return address. */\r
110         *pxTopOfStack = portINITIAL_SW;\r
111         pxTopOfStack--;\r
112         *pxTopOfStack = FP_SEG( pxCode );\r
113         pxTopOfStack--;\r
114         *pxTopOfStack = FP_OFF( pxCode );\r
115         pxTopOfStack--;\r
116 \r
117         /* The remaining registers would be pushed on the stack by our context\r
118         switch function.  These are loaded with values simply to make debugging\r
119         easier. */\r
120         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
121         pxTopOfStack--;\r
122         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
123         pxTopOfStack--;\r
124         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
125         pxTopOfStack--;\r
126         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
129         pxTopOfStack--;\r
130 \r
131         *pxTopOfStack = DS_Reg;                                         /* DS */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
138 \r
139         return pxTopOfStack;\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 portBASE_TYPE xPortStartScheduler( void )\r
144 {\r
145         /* This is called with interrupts already disabled. */\r
146 \r
147         /* Put our manual switch (yield) function on a known\r
148         vector. */\r
149         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
150 \r
151         /* Setup the tick interrupt. */\r
152         prvSetupTimerInterrupt();\r
153 \r
154         /* Kick off the scheduler by setting up the context of the first task. */\r
155         portFIRST_CONTEXT();\r
156 \r
157         /* Should not get here! */\r
158         return pdFALSE;\r
159 }\r
160 /*-----------------------------------------------------------*/\r
161 \r
162 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
163 is being used. */\r
164 #if( configUSE_PREEMPTION == 1 )\r
165         static void __interrupt __far prvPreemptiveTick( void )\r
166         {\r
167                 /* Get the scheduler to update the task states following the tick. */\r
168                 vTaskIncrementTick();\r
169 \r
170                 /* Switch in the context of the next task to be run. */\r
171                 portEND_SWITCHING_ISR();\r
172 \r
173                 /* Reset interrupt. */\r
174                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
175         }\r
176 #else\r
177         static void __interrupt __far prvNonPreemptiveTick( void )\r
178         {\r
179                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
180                 so we don't have to switch in the context of the next task. */\r
181                 vTaskIncrementTick();\r
182                 /* Reset interrupt. */\r
183                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
184         }\r
185 #endif\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void __interrupt __far prvYieldProcessor( void )\r
189 {\r
190         /* Switch in the context of the next task to be run. */\r
191         portEND_SWITCHING_ISR();\r
192 }\r
193 /*-----------------------------------------------------------*/\r
194 \r
195 void vPortEndScheduler( void )\r
196 {\r
197         /* Not implemented. */\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 static void prvSetupTimerInterrupt( void )\r
202 {\r
203 const unsigned portLONG ulCompareValue = portTIMER_COMPARE;\r
204 unsigned portSHORT usTimerCompare;\r
205 \r
206         usTimerCompare = ( unsigned portSHORT ) ( ulCompareValue >> 4 );\r
207     t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );\r
208 \r
209         #if( configUSE_PREEMPTION == 1 )\r
210                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
211                 being used. */\r
212                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );\r
213         #else\r
214                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
215                 being used. */\r
216                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );\r
217         #endif\r
218 }\r
219 \r
220 \r
221 \r
222 \r
223 \r
224 \r
225 \r