]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Paradigm/Tern_EE/large_untested/port.c
Update version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS / Source / portable / Paradigm / Tern_EE / large_untested / port.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 \r
71 /*-----------------------------------------------------------\r
72  * Implementation of functions defined in portable.h for the Tern EE 186\r
73  * port.\r
74  *----------------------------------------------------------*/\r
75 \r
76 /* Library includes. */\r
77 #include <embedded.h>\r
78 #include <ae.h>\r
79 \r
80 /* Scheduler includes. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 #include "portasm.h"\r
84 \r
85 /* The timer increments every four clocks, hence the divide by 4. */\r
86 #define portTIMER_COMPARE ( uint16_t ) ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) / ( uint32_t ) 4 )\r
87 \r
88 /* From the RDC data sheet. */\r
89 #define portENABLE_TIMER_AND_INTERRUPT ( uint16_t ) 0xe001\r
90 \r
91 /* Interrupt control. */\r
92 #define portEIO_REGISTER 0xff22\r
93 #define portCLEAR_INTERRUPT 0x0008\r
94 \r
95 /* Setup the hardware to generate the required tick frequency. */\r
96 static void prvSetupTimerInterrupt( void );\r
97 \r
98 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
99 is being used. */\r
100 #if( configUSE_PREEMPTION == 1 )\r
101         /* Tick service routine used by the scheduler when preemptive scheduling is\r
102         being used. */\r
103         static void __interrupt __far prvPreemptiveTick( void );\r
104 #else\r
105         /* Tick service routine used by the scheduler when cooperative scheduling is\r
106         being used. */\r
107         static void __interrupt __far prvNonPreemptiveTick( void );\r
108 #endif\r
109 \r
110 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
111 static void __interrupt __far prvYieldProcessor( void );\r
112 \r
113 /* The timer initialisation functions leave interrupts enabled,\r
114 which is not what we want.  This ISR is installed temporarily in case\r
115 the timer fires before we get a change to disable interrupts again. */\r
116 static void __interrupt __far prvDummyISR( void );\r
117 \r
118 /*-----------------------------------------------------------*/\r
119 /* See header file for description. */\r
120 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
121 {\r
122 StackType_t DS_Reg = 0;\r
123 \r
124         /* Place a few bytes of known values on the bottom of the stack.\r
125         This is just useful for debugging. */\r
126 \r
127         *pxTopOfStack = 0x1111;\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = 0x2222;\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = 0x3333;\r
132         pxTopOfStack--;\r
133 \r
134         /* We are going to start the scheduler using a return from interrupt\r
135         instruction to load the program counter, so first there would be the\r
136         function call with parameters preamble. */\r
137         \r
138         *pxTopOfStack = FP_SEG( pvParameters );\r
139         pxTopOfStack--;\r
140         *pxTopOfStack = FP_OFF( pvParameters );\r
141         pxTopOfStack--;\r
142         *pxTopOfStack = FP_SEG( pxCode );\r
143         pxTopOfStack--;\r
144         *pxTopOfStack = FP_OFF( pxCode );\r
145         pxTopOfStack--;\r
146 \r
147         /* Next the status register and interrupt return address. */\r
148         *pxTopOfStack = portINITIAL_SW;\r
149         pxTopOfStack--;\r
150         *pxTopOfStack = FP_SEG( pxCode );\r
151         pxTopOfStack--;\r
152         *pxTopOfStack = FP_OFF( pxCode );\r
153         pxTopOfStack--;\r
154 \r
155         /* The remaining registers would be pushed on the stack by our context\r
156         switch function.  These are loaded with values simply to make debugging\r
157         easier. */\r
158         *pxTopOfStack = ( StackType_t ) 0xAAAA; /* AX */\r
159         pxTopOfStack--;\r
160         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */\r
163         pxTopOfStack--;\r
164         *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DX */\r
165         pxTopOfStack--;\r
166         *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */\r
167         pxTopOfStack--;\r
168 \r
169         /* We need the true data segment. */\r
170         __asm{  MOV DS_Reg, DS };\r
171 \r
172         *pxTopOfStack = DS_Reg;                                         /* DS */\r
173         pxTopOfStack--;\r
174         *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */\r
175         pxTopOfStack--;\r
176         *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */\r
177         pxTopOfStack--;\r
178         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */\r
179 \r
180         return pxTopOfStack;\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 BaseType_t xPortStartScheduler( void )\r
185 {\r
186         /* This is called with interrupts already disabled. */\r
187 \r
188         /* Put our manual switch (yield) function on a known\r
189         vector. */\r
190         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
191 \r
192         /* Setup the tick interrupt. */\r
193         prvSetupTimerInterrupt();\r
194 \r
195         /* Kick off the scheduler by setting up the context of the first task. */\r
196         portFIRST_CONTEXT();\r
197 \r
198         /* Should not get here! */\r
199         return pdFALSE;\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 static void __interrupt __far prvDummyISR( void )\r
204 {\r
205         /* The timer initialisation functions leave interrupts enabled,\r
206         which is not what we want.  This ISR is installed temporarily in case\r
207         the timer fires before we get a change to disable interrupts again. */\r
208         outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
209 }\r
210 /*-----------------------------------------------------------*/\r
211 \r
212 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
213 is being used. */\r
214 #if( configUSE_PREEMPTION == 1 )\r
215         static void __interrupt __far prvPreemptiveTick( void )\r
216         {\r
217                 /* Get the scheduler to update the task states following the tick. */\r
218                 if( xTaskIncrementTick() != pdFALSE )\r
219                 {\r
220                         /* Switch in the context of the next task to be run. */\r
221                         portSWITCH_CONTEXT();\r
222                 }\r
223 \r
224                 /* Reset interrupt. */\r
225                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
226         }\r
227 #else\r
228         static void __interrupt __far prvNonPreemptiveTick( void )\r
229         {\r
230                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
231                 so we don't have to switch in the context of the next task. */\r
232                 xTaskIncrementTick();\r
233                 \r
234                 /* Reset interrupt. */\r
235                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
236         }\r
237 #endif\r
238 /*-----------------------------------------------------------*/\r
239 \r
240 static void __interrupt __far prvYieldProcessor( void )\r
241 {\r
242         /* Switch in the context of the next task to be run. */\r
243         portSWITCH_CONTEXT();\r
244 }\r
245 /*-----------------------------------------------------------*/\r
246 \r
247 void vPortEndScheduler( void )\r
248 {\r
249         /* Not implemented. */\r
250 }\r
251 /*-----------------------------------------------------------*/\r
252 \r
253 static void prvSetupTimerInterrupt( void )\r
254 {\r
255 const uint16_t usTimerACompare = portTIMER_COMPARE, usTimerAMode = portENABLE_TIMER_AND_INTERRUPT;\r
256 const uint16_t usT2_IRQ = 0x13;\r
257 \r
258         /* Configure the timer, the dummy handler is used here as the init\r
259         function leaves interrupts enabled. */\r
260         t2_init( usTimerAMode, usTimerACompare, prvDummyISR );\r
261 \r
262         /* Disable interrupts again before installing the real handlers. */\r
263         portDISABLE_INTERRUPTS();\r
264 \r
265         #if( configUSE_PREEMPTION == 1 )\r
266                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
267                 being used. */\r
268                 setvect( usT2_IRQ, prvPreemptiveTick );\r
269         #else\r
270                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
271                 being used. */\r
272                 setvect( usT2_IRQ, prvNonPreemptiveTick );\r
273         #endif\r
274 }\r
275 \r
276 \r
277 \r
278 \r
279 \r
280 \r
281 \r