]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/BCC/16BitDOS/Flsh186/port.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Source / portable / BCC / 16BitDOS / Flsh186 / 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 Changes from V1.00:\r
98 \r
99         + Call to taskYIELD() from within tick ISR has been replaced by the more\r
100           efficient portSWITCH_CONTEXT().\r
101         + ISR function definitions renamed to include the prv prefix.\r
102 \r
103 Changes from V2.6.1\r
104 \r
105         + Replaced the sUsingPreemption variable with the configUSE_PREEMPTION\r
106           macro to be consistent with the later ports.\r
107 */\r
108 \r
109 /*-----------------------------------------------------------\r
110  * Implementation of functions defined in portable.h for the Flashlite 186\r
111  * port.\r
112  *----------------------------------------------------------*/\r
113 \r
114 #include <dos.h>\r
115 #include <stdlib.h>\r
116 #include <setjmp.h>\r
117 \r
118 #include "FreeRTOS.h"\r
119 #include "task.h"\r
120 #include "portasm.h"\r
121 \r
122 /*lint -e950 Non ANSI reserved words okay in this file only. */\r
123 \r
124 #define portTIMER_EOI_TYPE              ( 8 )\r
125 #define portRESET_PIC()                 portOUTPUT_WORD( ( uint16_t ) 0xff22, portTIMER_EOI_TYPE )\r
126 #define portTIMER_INT_NUMBER    0x12\r
127 \r
128 #define portTIMER_1_CONTROL_REGISTER    ( ( uint16_t ) 0xff5e )\r
129 #define portTIMER_0_CONTROL_REGISTER    ( ( uint16_t ) 0xff56 )\r
130 #define portTIMER_INTERRUPT_ENABLE              ( ( uint16_t ) 0x2000 )\r
131 \r
132 /* Setup the hardware to generate the required tick frequency. */\r
133 static void prvSetTickFrequency( uint32_t ulTickRateHz );\r
134 \r
135 /* Set the hardware back to the state as per before the scheduler started. */\r
136 static void prvExitFunction( void );\r
137 \r
138 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
139 is being used. */\r
140 #if( configUSE_PREEMPTION == 1 )\r
141         /* Tick service routine used by the scheduler when preemptive scheduling is\r
142         being used. */\r
143         static void __interrupt __far prvPreemptiveTick( void );\r
144 #else\r
145         /* Tick service routine used by the scheduler when cooperative scheduling is\r
146         being used. */\r
147         static void __interrupt __far prvNonPreemptiveTick( void );\r
148 #endif\r
149 \r
150 /* Trap routine used by taskYIELD() to manually cause a context switch. */\r
151 static void __interrupt __far prvYieldProcessor( void );\r
152 \r
153 /*lint -e956 File scopes necessary here. */\r
154 \r
155 /* Set true when the vectors are set so the scheduler will service the tick. */\r
156 static BaseType_t xSchedulerRunning = pdFALSE;\r
157 \r
158 /* Points to the original routine installed on the vector we use for manual\r
159 context switches.  This is then used to restore the original routine during\r
160 prvExitFunction(). */\r
161 static void ( __interrupt __far *pxOldSwitchISR )();\r
162 \r
163 /* Used to restore the original DOS context when the scheduler is ended. */\r
164 static jmp_buf xJumpBuf;\r
165 \r
166 /*lint +e956 */\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 BaseType_t xPortStartScheduler( void )\r
170 {\r
171         /* This is called with interrupts already disabled. */\r
172 \r
173         /* Remember what was on the interrupts we are going to use\r
174         so we can put them back later if required. */\r
175         pxOldSwitchISR = _dos_getvect( portSWITCH_INT_NUMBER );\r
176 \r
177         /* Put our manual switch (yield) function on a known\r
178         vector. */\r
179         _dos_setvect( portSWITCH_INT_NUMBER, prvYieldProcessor );\r
180 \r
181         #if( configUSE_PREEMPTION == 1 )\r
182         {\r
183                 /* Put our tick switch function on the timer interrupt. */\r
184                 _dos_setvect( portTIMER_INT_NUMBER, prvPreemptiveTick );\r
185         }\r
186         #else\r
187         {\r
188                 /* We want the timer interrupt to just increment the tick count. */\r
189                 _dos_setvect( portTIMER_INT_NUMBER, prvNonPreemptiveTick );\r
190         }\r
191         #endif\r
192 \r
193         prvSetTickFrequency( configTICK_RATE_HZ );\r
194 \r
195         /* Clean up function if we want to return to DOS. */\r
196         if( setjmp( xJumpBuf ) != 0 )\r
197         {\r
198                 prvExitFunction();\r
199                 xSchedulerRunning = pdFALSE;\r
200         }\r
201         else\r
202         {\r
203                 xSchedulerRunning = pdTRUE;\r
204 \r
205                 /* Kick off the scheduler by setting up the context of the first task. */\r
206                 portFIRST_CONTEXT();\r
207         }\r
208 \r
209         return xSchedulerRunning;\r
210 }\r
211 /*-----------------------------------------------------------*/\r
212 \r
213 /* The ISR used depends on whether the preemptive or cooperative scheduler\r
214 is being used. */\r
215 #if( configUSE_PREEMPTION == 1 )\r
216         static void __interrupt __far prvPreemptiveTick( void )\r
217         {\r
218                 /* Get the scheduler to update the task states following the tick. */\r
219                 if( xTaskIncrementTick() != pdFALSE )\r
220                 {\r
221                         /* Switch in the context of the next task to be run. */\r
222                         portSWITCH_CONTEXT();\r
223                 }\r
224 \r
225                 /* Reset the PIC ready for the next time. */\r
226                 portRESET_PIC();\r
227         }\r
228 #else\r
229         static void __interrupt __far prvNonPreemptiveTick( void )\r
230         {\r
231                 /* Same as preemptive tick, but the cooperative scheduler is being used\r
232                 so we don't have to switch in the context of the next task. */\r
233                 xTaskIncrementTick();\r
234                 portRESET_PIC();\r
235         }\r
236 #endif\r
237 /*-----------------------------------------------------------*/\r
238 \r
239 static void __interrupt __far prvYieldProcessor( void )\r
240 {\r
241         /* Switch in the context of the next task to be run. */\r
242         portSWITCH_CONTEXT();\r
243 }\r
244 /*-----------------------------------------------------------*/\r
245 \r
246 void vPortEndScheduler( void )\r
247 {\r
248         /* Jump back to the processor state prior to starting the\r
249         scheduler.  This means we are not going to be using a\r
250         task stack frame so the task can be deleted. */\r
251         longjmp( xJumpBuf, 1 );\r
252 }\r
253 /*-----------------------------------------------------------*/\r
254 \r
255 static void prvExitFunction( void )\r
256 {\r
257 const uint16_t usTimerDisable = 0x0000;\r
258 uint16_t usTimer0Control;\r
259 \r
260         /* Interrupts should be disabled here anyway - but no\r
261         harm in making sure. */\r
262         portDISABLE_INTERRUPTS();\r
263         if( xSchedulerRunning == pdTRUE )\r
264         {\r
265                 /* Put back the switch interrupt routines that was in place\r
266                 before the scheduler started. */\r
267                 _dos_setvect( portSWITCH_INT_NUMBER, pxOldSwitchISR );\r
268         }\r
269 \r
270         /* Disable the timer used for the tick to ensure the scheduler is\r
271         not called before restoring interrupts.  There was previously nothing\r
272         on this timer so there is no old ISR to restore. */\r
273         portOUTPUT_WORD( portTIMER_1_CONTROL_REGISTER, usTimerDisable );\r
274 \r
275         /* Restart the DOS tick. */\r
276         usTimer0Control = portINPUT_WORD( portTIMER_0_CONTROL_REGISTER );\r
277         usTimer0Control |= portTIMER_INTERRUPT_ENABLE;\r
278         portOUTPUT_WORD( portTIMER_0_CONTROL_REGISTER, usTimer0Control );\r
279 \r
280 \r
281         portENABLE_INTERRUPTS();\r
282 }\r
283 /*-----------------------------------------------------------*/\r
284 \r
285 static void prvSetTickFrequency( uint32_t ulTickRateHz )\r
286 {\r
287 const uint16_t usMaxCountRegister = 0xff5a;\r
288 const uint16_t usTimerPriorityRegister = 0xff32;\r
289 const uint16_t usTimerEnable = 0xC000;\r
290 const uint16_t usRetrigger = 0x0001;\r
291 const uint16_t usTimerHighPriority = 0x0000;\r
292 uint16_t usTimer0Control;\r
293 \r
294 /* ( CPU frequency / 4 ) / clock 2 max count [inpw( 0xff62 ) = 7] */\r
295 \r
296 const uint32_t ulClockFrequency = ( uint32_t ) 0x7f31a0UL;\r
297 \r
298 uint32_t ulTimerCount = ulClockFrequency / ulTickRateHz;\r
299 \r
300         portOUTPUT_WORD( portTIMER_1_CONTROL_REGISTER, usTimerEnable | portTIMER_INTERRUPT_ENABLE | usRetrigger );\r
301         portOUTPUT_WORD( usMaxCountRegister, ( uint16_t ) ulTimerCount );\r
302         portOUTPUT_WORD( usTimerPriorityRegister, usTimerHighPriority );\r
303 \r
304         /* Stop the DOS tick - don't do this if you want to maintain a TOD clock. */\r
305         usTimer0Control = portINPUT_WORD( portTIMER_0_CONTROL_REGISTER );\r
306         usTimer0Control &= ~portTIMER_INTERRUPT_ENABLE;\r
307         portOUTPUT_WORD( portTIMER_0_CONTROL_REGISTER, usTimer0Control );\r
308 }\r
309 \r
310 \r
311 /*lint +e950 */\r
312 \r