]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Paradigm/Tern_EE/small/port.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / Paradigm / Tern_EE / small / port.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - 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 portPRESCALE_VALUE ( 16 )\r
87 #define portTIMER_COMPARE ( configCPU_CLOCK_HZ  / ( configTICK_RATE_HZ * 4UL ) )\r
88 \r
89 /* From the RDC data sheet. */\r
90 #define portENABLE_TIMER_AND_INTERRUPT  ( uint16_t ) 0xe00b\r
91 #define portENABLE_TIMER                                ( uint16_t ) 0xC001\r
92 \r
93 /* Interrupt control. */\r
94 #define portEIO_REGISTER 0xff22\r
95 #define portCLEAR_INTERRUPT 0x0008\r
96 \r
97 /* Setup the hardware to generate the required tick frequency. */\r
98 static void prvSetupTimerInterrupt( void );\r
99 \r
100 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
101 is being used. */\r
102 #if( configUSE_PREEMPTION == 1 )\r
103         /* Tick service routine used by the scheduler when preemptive scheduling is\r
104         being used. */\r
105         static void __interrupt __far prvPreemptiveTick( void );\r
106 #else\r
107         /* Tick service routine used by the scheduler when cooperative scheduling is\r
108         being used. */\r
109         static void __interrupt __far prvNonPreemptiveTick( void );\r
110 #endif\r
111 \r
112 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
113 static void __interrupt __far prvYieldProcessor( void );\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 /* See header file for description. */\r
117 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
118 {\r
119 StackType_t DS_Reg = 0;\r
120 \r
121         /* We need the true data segment. */\r
122         __asm{  MOV DS_Reg, DS };\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_OFF( pvParameters );\r
139         pxTopOfStack--;\r
140         *pxTopOfStack = FP_OFF( pxCode );\r
141         pxTopOfStack--;\r
142 \r
143         /* Next the status register and interrupt return address. */\r
144         *pxTopOfStack = portINITIAL_SW;\r
145         pxTopOfStack--;\r
146         *pxTopOfStack = FP_SEG( pxCode );\r
147         pxTopOfStack--;\r
148         *pxTopOfStack = FP_OFF( pxCode );\r
149         pxTopOfStack--;\r
150 \r
151         /* The remaining registers would be pushed on the stack by our context\r
152         switch function.  These are loaded with values simply to make debugging\r
153         easier. */\r
154         *pxTopOfStack = ( StackType_t ) 0xAAAA; /* AX */\r
155         pxTopOfStack--;\r
156         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */\r
157         pxTopOfStack--;\r
158         *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */\r
159         pxTopOfStack--;\r
160         *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DX */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */\r
163         pxTopOfStack--;\r
164 \r
165         *pxTopOfStack = DS_Reg;                                         /* DS */\r
166         pxTopOfStack--;\r
167         *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */\r
168         pxTopOfStack--;\r
169         *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */\r
170         pxTopOfStack--;\r
171         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */\r
172 \r
173         return pxTopOfStack;\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 BaseType_t xPortStartScheduler( void )\r
178 {\r
179         /* This is called with interrupts already disabled. */\r
180 \r
181         /* Put our manual switch (yield) function on a known\r
182         vector. */\r
183         setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
184 \r
185         /* Setup the tick interrupt. */\r
186         prvSetupTimerInterrupt();\r
187 \r
188         /* Kick off the scheduler by setting up the context of the first task. */\r
189         portFIRST_CONTEXT();\r
190 \r
191         /* Should not get here! */\r
192         return pdFALSE;\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
197 is being used. */\r
198 #if( configUSE_PREEMPTION == 1 )\r
199         static void __interrupt __far prvPreemptiveTick( void )\r
200         {\r
201                 /* Get the scheduler to update the task states following the tick. */\r
202                 if( xTaskIncrementTick() != pdFALSE )\r
203                 {\r
204                         /* Switch in the context of the next task to be run. */\r
205                         portEND_SWITCHING_ISR();\r
206                 }\r
207 \r
208                 /* Reset interrupt. */\r
209                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
210         }\r
211 #else\r
212         static void __interrupt __far prvNonPreemptiveTick( void )\r
213         {\r
214                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
215                 so we don't have to switch in the context of the next task. */\r
216                 xTaskIncrementTick();\r
217                 \r
218                 /* Reset interrupt. */\r
219                 outport( portEIO_REGISTER, portCLEAR_INTERRUPT );\r
220         }\r
221 #endif\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 static void __interrupt __far prvYieldProcessor( void )\r
225 {\r
226         /* Switch in the context of the next task to be run. */\r
227         portEND_SWITCHING_ISR();\r
228 }\r
229 /*-----------------------------------------------------------*/\r
230 \r
231 void vPortEndScheduler( void )\r
232 {\r
233         /* Not implemented. */\r
234 }\r
235 /*-----------------------------------------------------------*/\r
236 \r
237 static void prvSetupTimerInterrupt( void )\r
238 {\r
239 const uint32_t ulCompareValue = portTIMER_COMPARE;\r
240 uint16_t usTimerCompare;\r
241 \r
242         usTimerCompare = ( uint16_t ) ( ulCompareValue >> 4 );\r
243     t2_init( portENABLE_TIMER, portPRESCALE_VALUE, NULL );\r
244 \r
245         #if( configUSE_PREEMPTION == 1 )\r
246                 /* Tick service routine used by the scheduler when preemptive scheduling is\r
247                 being used. */\r
248                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvPreemptiveTick );\r
249         #else\r
250                 /* Tick service routine used by the scheduler when cooperative scheduling is\r
251                 being used. */\r
252                 t1_init( portENABLE_TIMER_AND_INTERRUPT, usTimerCompare, usTimerCompare, prvNonPreemptiveTick );\r
253         #endif\r
254 }\r
255 \r
256 \r
257 \r
258 \r
259 \r
260 \r
261 \r