]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Source / portable / Paradigm / Tern_EE / small / port.c
1 /*\r
2     FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\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 modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or 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     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 \r
68 /*-----------------------------------------------------------\r
69  * Implementation of functions defined in portable.h for the Tern EE 186\r
70  * port.\r
71  *----------------------------------------------------------*/\r
72 \r
73 /* Library includes. */\r
74 #include <embedded.h>\r
75 #include <ae.h>\r
76 \r
77 /* Scheduler includes. */\r
78 #include "FreeRTOS.h"\r
79 #include "task.h"\r
80 #include "portasm.h"\r
81 \r
82 /* The timer increments every four clocks, hence the divide by 4. */\r
83 #define portPRESCALE_VALUE ( 16 )\r
84 #define portTIMER_COMPARE ( configCPU_CLOCK_HZ  / ( configTICK_RATE_HZ * 4UL ) )\r
85 \r
86 /* From the RDC data sheet. */\r
87 #define portENABLE_TIMER_AND_INTERRUPT  ( unsigned short ) 0xe00b\r
88 #define portENABLE_TIMER                                ( unsigned short ) 0xC001\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 /*-----------------------------------------------------------*/\r
113 /* See header file for description. */\r
114 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
115 {\r
116 portSTACK_TYPE DS_Reg = 0;\r
117 \r
118         /* We need the true data segment. */\r
119         __asm{  MOV DS_Reg, DS };\r
120 \r
121         /* Place a few bytes of known values on the bottom of the stack.\r
122         This is just useful for debugging. */\r
123 \r
124         *pxTopOfStack = 0x1111;\r
125         pxTopOfStack--;\r
126         *pxTopOfStack = 0x2222;\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = 0x3333;\r
129         pxTopOfStack--;\r
130 \r
131         /* We are going to start the scheduler using a return from interrupt\r
132         instruction to load the program counter, so first there would be the\r
133         function call with parameters preamble. */\r
134         \r
135         *pxTopOfStack = FP_OFF( pvParameters );\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = FP_OFF( pxCode );\r
138         pxTopOfStack--;\r
139 \r
140         /* Next the status register and interrupt return address. */\r
141         *pxTopOfStack = portINITIAL_SW;\r
142         pxTopOfStack--;\r
143         *pxTopOfStack = FP_SEG( pxCode );\r
144         pxTopOfStack--;\r
145         *pxTopOfStack = FP_OFF( pxCode );\r
146         pxTopOfStack--;\r
147 \r
148         /* The remaining registers would be pushed on the stack by our context\r
149         switch function.  These are loaded with values simply to make debugging\r
150         easier. */\r
151         *pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;      /* AX */\r
152         pxTopOfStack--;\r
153         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
154         pxTopOfStack--;\r
155         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
156         pxTopOfStack--;\r
157         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DX */\r
158         pxTopOfStack--;\r
159         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
160         pxTopOfStack--;\r
161 \r
162         *pxTopOfStack = DS_Reg;                                         /* DS */\r
163         pxTopOfStack--;\r
164         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
165         pxTopOfStack--;\r
166         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
167         pxTopOfStack--;\r
168         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
169 \r
170         return pxTopOfStack;\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 portBASE_TYPE xPortStartScheduler( void )\r
175 {\r
176         /* This is called with interrupts already disabled. */\r
177 \r
178         /* Put our manual switch (yield) function on a known\r
179         vector. */\r
180         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
181 \r
182         /* Setup the tick interrupt. */\r
183         prvSetupTimerInterrupt();\r
184 \r
185         /* Kick off the scheduler by setting up the context of the first task. */\r
186         portFIRST_CONTEXT();\r
187 \r
188         /* Should not get here! */\r
189         return pdFALSE;\r
190 }\r
191 /*-----------------------------------------------------------*/\r
192 \r
193 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
194 is being used. */\r
195 #if( configUSE_PREEMPTION == 1 )\r
196         static void __interrupt __far prvPreemptiveTick( void )\r
197         {\r
198                 /* Get the scheduler to update the task states following the tick. */\r
199                 vTaskIncrementTick();\r
200 \r
201                 /* Switch in the context of the next task to be run. */\r
202                 portEND_SWITCHING_ISR();\r
203 \r
204                 /* Reset interrupt. */\r
205                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
206         }\r
207 #else\r
208         static void __interrupt __far prvNonPreemptiveTick( void )\r
209         {\r
210                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
211                 so we don't have to switch in the context of the next task. */\r
212                 vTaskIncrementTick();\r
213                 /* Reset interrupt. */\r
214                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
215         }\r
216 #endif\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 static void __interrupt __far prvYieldProcessor( void )\r
220 {\r
221         /* Switch in the context of the next task to be run. */\r
222         portEND_SWITCHING_ISR();\r
223 }\r
224 /*-----------------------------------------------------------*/\r
225 \r
226 void vPortEndScheduler( void )\r
227 {\r
228         /* Not implemented. */\r
229 }\r
230 /*-----------------------------------------------------------*/\r
231 \r
232 static void prvSetupTimerInterrupt( void )\r
233 {\r
234 const unsigned long ulCompareValue = portTIMER_COMPARE;\r
235 unsigned short usTimerCompare;\r
236 \r
237         usTimerCompare = ( unsigned short ) ( ulCompareValue >> 4 );\r
238     t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );\r
239 \r
240         #if( configUSE_PREEMPTION == 1 )\r
241                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
242                 being used. */\r
243                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );\r
244         #else\r
245                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
246                 being used. */\r
247                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );\r
248         #endif\r
249 }\r
250 \r
251 \r
252 \r
253 \r
254 \r
255 \r
256 \r