]> git.sur5r.net Git - freertos/blob - Source/portable/Paradigm/Tern_EE/large_untested/port.c
cfe5e7c563b3c5172a12e07a53a14b5c1ec645ef
[freertos] / Source / portable / Paradigm / Tern_EE / large_untested / port.c
1 /*\r
2         FreeRTOS.org V4.4.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 portTIMER_COMPARE ( unsigned portSHORT ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( unsigned portLONG ) 4 )\r
53 \r
54 /* From the RDC data sheet. */\r
55 #define portENABLE_TIMER_AND_INTERRUPT ( unsigned portSHORT ) 0xe001\r
56 \r
57 /* Interrupt control. */\r
58 #define portEIO_REGISTER 0xff22\r
59 #define portCLEAR_INTERRUPT 0x0008\r
60 \r
61 /* Setup the hardware to generate the required tick frequency. */\r
62 static void prvSetupTimerInterrupt( void );\r
63 \r
64 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
65 is being used. */\r
66 #if( configUSE_PREEMPTION == 1 )\r
67         /* Tick service routine used by the scheduler when preemptive scheduling is\r
68         being used. */\r
69         static void __interrupt __far prvPreemptiveTick( void );\r
70 #else\r
71         /* Tick service routine used by the scheduler when cooperative scheduling is\r
72         being used. */\r
73         static void __interrupt __far prvNonPreemptiveTick( void );\r
74 #endif\r
75 \r
76 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
77 static void __interrupt __far prvYieldProcessor( void );\r
78 \r
79 /*-----------------------------------------------------------*/\r
80 /* See header file for description. */\r
81 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
82 {\r
83 portSTACK_TYPE DS_Reg = 0;\r
84 \r
85         /* Place a few bytes of known values on the bottom of the stack.\r
86         This is just useful for debugging. */\r
87 \r
88         *pxTopOfStack = 0x1111;\r
89         pxTopOfStack--;\r
90         *pxTopOfStack = 0x2222;\r
91         pxTopOfStack--;\r
92         *pxTopOfStack = 0x3333;\r
93         pxTopOfStack--;\r
94 \r
95         /* We are going to start the scheduler using a return from interrupt\r
96         instruction to load the program counter, so first there would be the\r
97         function call with parameters preamble. */\r
98         \r
99         *pxTopOfStack = FP_SEG( pvParameters );\r
100         pxTopOfStack--;\r
101         *pxTopOfStack = FP_OFF( pvParameters );\r
102         pxTopOfStack--;\r
103         *pxTopOfStack = FP_SEG( pxCode );\r
104         pxTopOfStack--;\r
105         *pxTopOfStack = FP_OFF( pxCode );\r
106         pxTopOfStack--;\r
107 \r
108         /* Next the status register and interrupt return address. */\r
109         *pxTopOfStack = portINITIAL_SW;\r
110         pxTopOfStack--;\r
111         *pxTopOfStack = FP_SEG( pxCode );\r
112         pxTopOfStack--;\r
113         *pxTopOfStack = FP_OFF( pxCode );\r
114         pxTopOfStack--;\r
115 \r
116         /* The remaining registers would be pushed on the stack by our context\r
117         switch function.  These are loaded with values simply to make debugging\r
118         easier. */\r
119         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
120         pxTopOfStack--;\r
121         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
128         pxTopOfStack--;\r
129 \r
130         /* We need the true data segment. */\r
131         __asm{  MOV DS_Reg, DS };\r
132 \r
133         *pxTopOfStack = DS_Reg;                                         /* DS */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
140 \r
141         return pxTopOfStack;\r
142 }\r
143 /*-----------------------------------------------------------*/\r
144 \r
145 portBASE_TYPE xPortStartScheduler( void )\r
146 {\r
147         /* This is called with interrupts already disabled. */\r
148 \r
149         /* Put our manual switch (yield) function on a known\r
150         vector. */\r
151         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
152 \r
153         /* Setup the tick interrupt. */\r
154         prvSetupTimerInterrupt();\r
155 \r
156         /* Kick off the scheduler by setting up the context of the first task. */\r
157         portFIRST_CONTEXT();\r
158 \r
159         /* Should not get here! */\r
160         return pdFALSE;\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
165 is being used. */\r
166 #if( configUSE_PREEMPTION == 1 )\r
167         static void __interrupt __far prvPreemptiveTick( void )\r
168         {\r
169                 /* Get the scheduler to update the task states following the tick. */\r
170                 vTaskIncrementTick();\r
171 \r
172                 /* Switch in the context of the next task to be run. */\r
173                 portSWITCH_CONTEXT();\r
174 \r
175                 /* Reset interrupt. */\r
176                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
177         }\r
178 #else\r
179         static void __interrupt __far prvNonPreemptiveTick( void )\r
180         {\r
181                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
182                 so we don't have to switch in the context of the next task. */\r
183                 vTaskIncrementTick();\r
184                 /* Reset interrupt. */\r
185                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
186         }\r
187 #endif\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 static void __interrupt __far prvYieldProcessor( void )\r
191 {\r
192         /* Switch in the context of the next task to be run. */\r
193         portSWITCH_CONTEXT();\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 void vPortEndScheduler( void )\r
198 {\r
199         /* Not implemented. */\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 static void prvSetupTimerInterrupt( void )\r
204 {\r
205 const unsigned portSHORT usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT;\r
206 \r
207         #if( configUSE_PREEMPTION == 1 )\r
208                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
209                 being used. */\r
210                 t2_init( usTimerAMode, usTimerACompare, prvPreemptiveTick );\r
211         #else\r
212                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
213                 being used. */\r
214                 t2_init( usTimerAMode, usTimerACompare, prvNonPreemptiveTick );\r
215         #endif\r
216 }\r
217 \r
218 \r
219 \r
220 \r
221 \r
222 \r
223 \r