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