]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Cygnal/main.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / Cygnal / main.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  * Creates the demo application tasks, then starts the scheduler.  The WEB\r
72  * documentation provides more details of the demo application tasks.\r
73  * \r
74  * Main. c also creates four other tasks:\r
75  * \r
76  * 1) vErrorChecks()\r
77  * This only executes every few seconds but has the highest priority so is \r
78  * guaranteed to get processor time.  Its main function is to check that all \r
79  * the standard demo application tasks are still operational and have not\r
80  * experienced any errors.  vErrorChecks() will toggle the on board LED\r
81  * every mainNO_ERROR_FLASH_PERIOD milliseconds if none of the demo application\r
82  * tasks have reported an error.  Should any task report an error at any time\r
83  * the rate at which the on board LED is toggled is increased to \r
84  * mainERROR_FLASH_PERIOD - providing visual feedback that something has gone\r
85  * wrong.\r
86  *\r
87  * 2) vRegisterCheck()\r
88  * This is a very simple task that checks that all the registers are always\r
89  * in their expected state.  The task only makes use of the A register, so\r
90  * all the other registers should always contain their initial values.\r
91  * An incorrect value indicates an error in the context switch mechanism.\r
92  * The task operates at the idle priority so will be preempted regularly.\r
93  * Any error will cause the toggle rate of the on board LED to increase to\r
94  * mainERROR_FLASH_PERIOD milliseconds.\r
95  *\r
96  * 3 and 4) vFLOPCheck1() and vFLOPCheck2()\r
97  * These are very basic versions of the standard FLOP tasks.  They are good\r
98  * at detecting errors in the context switch mechanism, and also check that\r
99  * the floating point libraries are correctly built to be re-enterant.  The\r
100  * stack restrictions of the 8051 prevent the use of the standard FLOP demo\r
101  * tasks.\r
102  */\r
103 \r
104 /* Standard includes. */\r
105 #include <stdlib.h>\r
106 \r
107 /* Scheduler includes. */\r
108 #include "FreeRTOS.h"\r
109 #include "task.h"\r
110 \r
111 /* Demo application includes. */\r
112 #include "partest.h"\r
113 #include "flash.h"\r
114 #include "integer.h"\r
115 #include "PollQ.h"\r
116 #include "comtest2.h"\r
117 #include "semtest.h"\r
118 \r
119 /* Demo task priorities. */\r
120 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
121 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
122 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
123 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
124 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
125 #define mainINTEGER_PRIORITY            tskIDLE_PRIORITY\r
126 \r
127 /* Constants required to disable the watchdog. */\r
128 #define mainDISABLE_BYTE_1                      ( ( unsigned char ) 0xde )\r
129 #define mainDISABLE_BYTE_2                      ( ( unsigned char ) 0xad )\r
130 \r
131 /* Constants to setup and use the on board LED. */\r
132 #define ucLED_BIT                                       ( ( unsigned char ) 0x40 )\r
133 #define mainPORT_1_BIT_6                        ( ( unsigned char ) 0x40 )\r
134 #define mainENABLE_CROSS_BAR            ( ( unsigned char ) 0x40 )\r
135 \r
136 /* Constants to set the clock frequency. */\r
137 #define mainSELECT_INTERNAL_OSC         ( ( unsigned char ) 0x80 )\r
138 #define mainDIVIDE_CLOCK_BY_1           ( ( unsigned char ) 0x03 )\r
139 #define mainPLL_USES_INTERNAL_OSC       ( ( unsigned char ) 0x04 )\r
140 #define mainFLASH_READ_TIMING           ( ( unsigned char ) 0x30 )\r
141 #define mainPLL_POWER_ON                        ( ( unsigned char ) 0x01 )\r
142 #define mainPLL_NO_PREDIVIDE            ( ( unsigned char ) 0x01 )\r
143 #define mainPLL_FILTER                          ( ( unsigned char ) 0x01 )\r
144 #define mainPLL_MULTIPLICATION          ( ( unsigned char ) 0x04 )\r
145 #define mainENABLE_PLL                          ( ( unsigned char ) 0x02 )\r
146 #define mainPLL_LOCKED                          ( ( unsigned char ) 0x10 )\r
147 #define mainSELECT_PLL_AS_SOURCE        ( ( unsigned char ) 0x02 )\r
148 \r
149 /* Toggle rate for the on board LED - which is dependent on whether or not\r
150 an error has been detected. */\r
151 #define mainNO_ERROR_FLASH_PERIOD       ( ( TickType_t ) 5000 )\r
152 #define mainERROR_FLASH_PERIOD          ( ( TickType_t ) 250 )\r
153 \r
154 /* Baud rate used by the serial port tasks. */\r
155 #define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 115200 )\r
156 \r
157 /* Pass an invalid LED number to the COM test task as we don't want it to flash\r
158 an LED.  There are only 8 LEDs (excluding the on board LED) wired in and these\r
159 are all used by the flash tasks. */\r
160 #define mainCOM_TEST_LED                        ( 200 )\r
161 \r
162 /* We want the Cygnal to act as much as possible as a standard 8052. */\r
163 #define mainAUTO_SFR_OFF                        ( ( unsigned char ) 0 )\r
164 \r
165 /* Constants required to setup the IO pins for serial comms. */\r
166 #define mainENABLE_COMS                         ( ( unsigned char ) 0x04 )\r
167 #define mainCOMS_LINES_TO_PUSH_PULL ( ( unsigned char ) 0x03 )\r
168 \r
169 /* Pointer passed as a parameter to vRegisterCheck() just so it has some know\r
170 values to check for in the DPH, DPL and B registers. */\r
171 #define mainDUMMY_POINTER               ( ( xdata void * ) 0xabcd )\r
172 \r
173 /* Macro that lets vErrorChecks() know that one of the tasks defined in\r
174 main. c has detected an error.  A critical region is used around xLatchError\r
175 as it is accessed from vErrorChecks(), which has a higher priority. */ \r
176 #define mainLATCH_ERROR()                       \\r
177 {                                                                       \\r
178         portENTER_CRITICAL();                   \\r
179                 xLatchedError = pdTRUE;         \\r
180         portEXIT_CRITICAL();                    \\r
181 }\r
182 \r
183 /*\r
184  * Setup the Cygnal microcontroller for its fastest operation. \r
185  */\r
186 static void prvSetupSystemClock( void );\r
187 \r
188 /*\r
189  * Setup the peripherals, including the on board LED. \r
190  */\r
191 static void prvSetupHardware( void );\r
192 \r
193 /*\r
194  * Toggle the state of the on board LED. \r
195  */\r
196 static void prvToggleOnBoardLED( void );\r
197 \r
198 /*\r
199  * See comments at the top of the file for details. \r
200  */\r
201 static void vErrorChecks( void *pvParameters );\r
202 \r
203 /*\r
204  * See comments at the top of the file for details. \r
205  */\r
206 static void vRegisterCheck( void *pvParameters );\r
207 \r
208 /*\r
209  * See comments at the top of the file for details. \r
210  */\r
211 static void vFLOPCheck1( void *pvParameters );\r
212 \r
213 /*\r
214  * See comments at the top of the file for details. \r
215  */\r
216 static void vFLOPCheck2( void *pvParameters );\r
217 \r
218 /* File scope variable used to communicate the occurrence of an error between\r
219 tasks. */\r
220 static portBASE_TYPE xLatchedError = pdFALSE;\r
221 \r
222 /*-----------------------------------------------------------*/\r
223 \r
224 /*\r
225  * Starts all the other tasks, then starts the scheduler. \r
226  */\r
227 void main( void )\r
228 {\r
229         /* Initialise the hardware including the system clock and on board\r
230         LED. */\r
231         prvSetupHardware();\r
232 \r
233         /* Initialise the port that controls the external LED's utilized by the\r
234         flash tasks. */\r
235         vParTestInitialise();\r
236 \r
237         /* Start the used standard demo tasks. */\r
238         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
239         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
240         vStartIntegerMathTasks( mainINTEGER_PRIORITY );\r
241         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
242         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
243 \r
244         /* Start the tasks defined in this file.  The first three never block so\r
245         must not be used with the co-operative scheduler. */\r
246         #if configUSE_PREEMPTION == 1\r
247         {\r
248                 xTaskCreate( vRegisterCheck, "RegChck", configMINIMAL_STACK_SIZE, mainDUMMY_POINTER, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );\r
249                 xTaskCreate( vFLOPCheck1, "FLOP", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );\r
250                 xTaskCreate( vFLOPCheck2, "FLOP", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );\r
251         }\r
252         #endif \r
253 \r
254         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, ( TaskHandle_t * ) NULL );\r
255 \r
256         /* Finally kick off the scheduler.  This function should never return. */\r
257         vTaskStartScheduler();\r
258 \r
259         /* Should never reach here as the tasks will now be executing under control\r
260         of the scheduler. */\r
261 }\r
262 /*-----------------------------------------------------------*/\r
263 \r
264 /*\r
265  * Setup the hardware prior to using the scheduler.  Most of the Cygnal\r
266  * specific initialisation is performed here leaving standard 8052 setup\r
267  * only in the driver code.\r
268  */\r
269 static void prvSetupHardware( void )\r
270 {\r
271 unsigned char ucOriginalSFRPage;\r
272 \r
273         /* Remember the SFR page before it is changed so it can get set back\r
274         before the function exits. */\r
275         ucOriginalSFRPage = SFRPAGE;\r
276 \r
277         /* Setup the SFR page to access the config SFR's. */\r
278         SFRPAGE = CONFIG_PAGE;\r
279 \r
280         /* Don't allow the microcontroller to automatically switch SFR page, as the\r
281         SFR page is not stored as part of the task context. */\r
282         SFRPGCN = mainAUTO_SFR_OFF;\r
283 \r
284         /* Disable the watchdog. */\r
285         WDTCN = mainDISABLE_BYTE_1;\r
286         WDTCN = mainDISABLE_BYTE_2;\r
287 \r
288         /* Set the on board LED to push pull. */\r
289         P1MDOUT |= mainPORT_1_BIT_6;\r
290 \r
291         /* Setup the cross bar to enable serial comms here as it is not part of the \r
292         standard 8051 setup and therefore is not in the driver code. */\r
293         XBR0 |= mainENABLE_COMS;\r
294         P0MDOUT |= mainCOMS_LINES_TO_PUSH_PULL;\r
295 \r
296         /* Enable the cross bar so our hardware setup takes effect. */\r
297         XBR2 = mainENABLE_CROSS_BAR;\r
298 \r
299         /* Setup a fast system clock. */\r
300         prvSetupSystemClock();\r
301 \r
302         /* Return the SFR page. */\r
303         SFRPAGE = ucOriginalSFRPage;\r
304 }\r
305 /*-----------------------------------------------------------*/\r
306 \r
307 static void prvSetupSystemClock( void )\r
308 {\r
309 volatile unsigned short usWait;\r
310 const unsigned short usWaitTime = ( unsigned short ) 0x2ff;\r
311 unsigned char ucOriginalSFRPage;\r
312 \r
313         /* Remember the SFR page so we can set it back at the end. */\r
314         ucOriginalSFRPage = SFRPAGE;\r
315         SFRPAGE = CONFIG_PAGE;\r
316 \r
317         /* Use the internal oscillator set to its fasted frequency. */\r
318         OSCICN = mainSELECT_INTERNAL_OSC | mainDIVIDE_CLOCK_BY_1;\r
319 \r
320         /* Ensure the clock is stable. */\r
321         for( usWait = 0; usWait < usWaitTime; usWait++ );\r
322 \r
323         /* Setup the clock source for the PLL. */\r
324         PLL0CN &= ~mainPLL_USES_INTERNAL_OSC;\r
325 \r
326         /* Change the read timing for the flash ready for the fast clock. */\r
327         SFRPAGE = LEGACY_PAGE;\r
328         FLSCL |= mainFLASH_READ_TIMING;\r
329 \r
330         /* Turn on the PLL power. */\r
331         SFRPAGE = CONFIG_PAGE;\r
332         PLL0CN |= mainPLL_POWER_ON;\r
333 \r
334         /* Don't predivide the clock. */\r
335         PLL0DIV = mainPLL_NO_PREDIVIDE;\r
336 \r
337         /* Set filter for fastest clock. */\r
338         PLL0FLT = mainPLL_FILTER;\r
339         PLL0MUL = mainPLL_MULTIPLICATION;\r
340 \r
341         /* Ensure the clock is stable. */\r
342         for( usWait = 0; usWait < usWaitTime; usWait++ );\r
343 \r
344         /* Enable the PLL and wait for it to lock. */\r
345         PLL0CN |= mainENABLE_PLL;\r
346         for( usWait = 0; usWait < usWaitTime; usWait++ )\r
347         {\r
348                 if( PLL0CN & mainPLL_LOCKED )\r
349                 {\r
350                         break;\r
351                 }\r
352         }\r
353 \r
354         /* Select the PLL as the clock source. */\r
355         CLKSEL |= mainSELECT_PLL_AS_SOURCE;\r
356 \r
357         /* Return the SFR back to its original value. */\r
358         SFRPAGE = ucOriginalSFRPage;\r
359 }\r
360 /*-----------------------------------------------------------*/\r
361 \r
362 static void prvToggleOnBoardLED( void )\r
363 {\r
364         /* If the on board LED is on, turn it off and vice versa. */\r
365         if( P1 & ucLED_BIT )\r
366         {\r
367                 P1 &= ~ucLED_BIT;\r
368         }\r
369         else\r
370         {\r
371                 P1 |= ucLED_BIT;\r
372         }\r
373 }\r
374 /*-----------------------------------------------------------*/\r
375 \r
376 /*\r
377  * See the documentation at the top of this file. \r
378  */\r
379 static void vErrorChecks( void *pvParameters )\r
380 {\r
381 portBASE_TYPE xErrorHasOccurred = pdFALSE;\r
382         \r
383         /* Just to prevent compiler warnings. */\r
384         ( void ) pvParameters;\r
385         \r
386         /* Cycle for ever, delaying then checking all the other tasks are still\r
387         operating without error.   The delay period depends on whether an error\r
388         has ever been detected. */\r
389         for( ;; )\r
390         {\r
391                 if( xLatchedError == pdFALSE )\r
392                 {               \r
393                         /* No errors have been detected so delay for a longer period.  The\r
394                         on board LED will get toggled every mainNO_ERROR_FLASH_PERIOD ms. */\r
395                         vTaskDelay( mainNO_ERROR_FLASH_PERIOD );\r
396                 }\r
397                 else\r
398                 {\r
399                         /* We have at some time recognised an error in one of the demo\r
400                         application tasks, delay for a shorter period.  The on board LED\r
401                         will get toggled every mainERROR_FLASH_PERIOD ms. */\r
402                         vTaskDelay( mainERROR_FLASH_PERIOD );\r
403                 }\r
404 \r
405                 \r
406                 \r
407                 /* Check the demo application tasks for errors. */\r
408 \r
409                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
410                 {\r
411                         xErrorHasOccurred = pdTRUE;\r
412                 }\r
413 \r
414                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
415                 {\r
416                         xErrorHasOccurred = pdTRUE;\r
417                 }\r
418 \r
419                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
420                 {\r
421                         xErrorHasOccurred = pdTRUE;\r
422                 }\r
423 \r
424                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
425                 {\r
426                         xErrorHasOccurred = pdTRUE;\r
427                 }\r
428 \r
429                 /* If an error has occurred, latch it to cause the LED flash rate to \r
430                 increase. */\r
431                 if( xErrorHasOccurred == pdTRUE )\r
432                 {\r
433                         xLatchedError = pdTRUE;\r
434                 }\r
435 \r
436                 /* Toggle the LED to indicate the completion of a check cycle.  The\r
437                 frequency of check cycles is dependent on whether or not we have \r
438                 latched an error. */\r
439                 prvToggleOnBoardLED();\r
440         }\r
441 }\r
442 /*-----------------------------------------------------------*/\r
443 \r
444 /*\r
445  * See the documentation at the top of this file.  Also see the standard FLOP\r
446  * demo task documentation for the rationale of these tasks.\r
447  */\r
448 static void vFLOPCheck1( void *pvParameters )\r
449 {\r
450 volatile portFLOAT fVal1, fVal2, fResult;\r
451 \r
452         ( void ) pvParameters;\r
453 \r
454         for( ;; )\r
455         {\r
456                 fVal1 = ( portFLOAT ) -1234.5678;\r
457                 fVal2 = ( portFLOAT ) 2345.6789;\r
458 \r
459                 fResult = fVal1 + fVal2;\r
460                 if( ( fResult > ( portFLOAT )  1111.15 ) || ( fResult < ( portFLOAT ) 1111.05 ) )\r
461                 {\r
462                         mainLATCH_ERROR();\r
463                 }\r
464 \r
465                 fResult = fVal1 / fVal2;\r
466                 if( ( fResult > ( portFLOAT ) -0.51 ) || ( fResult < ( portFLOAT ) -0.53 ) )\r
467                 {\r
468                         mainLATCH_ERROR();\r
469                 }\r
470         }\r
471 }\r
472 /*-----------------------------------------------------------*/\r
473 \r
474 /*\r
475  * See the documentation at the top of this file.\r
476  */\r
477 static void vFLOPCheck2( void *pvParameters )\r
478 {\r
479 volatile portFLOAT fVal1, fVal2, fResult;\r
480 \r
481         ( void ) pvParameters;\r
482 \r
483         for( ;; )\r
484         {\r
485                 fVal1 = ( portFLOAT ) -12340.5678;\r
486                 fVal2 = ( portFLOAT ) 23450.6789;\r
487 \r
488                 fResult = fVal1 + fVal2;\r
489                 if( ( fResult > ( portFLOAT ) 11110.15 ) || ( fResult < ( portFLOAT ) 11110.05 ) )\r
490                 {\r
491                         mainLATCH_ERROR();\r
492                 }\r
493 \r
494                 fResult = fVal1 / -fVal2;\r
495                 if( ( fResult > ( portFLOAT ) 0.53 ) || ( fResult < ( portFLOAT ) 0.51 ) )\r
496                 {\r
497                         mainLATCH_ERROR();\r
498                 }\r
499         }\r
500 }\r
501 /*-----------------------------------------------------------*/\r
502 \r
503 /*\r
504  * See the documentation at the top of this file. \r
505  */\r
506 static void vRegisterCheck( void *pvParameters )\r
507 {\r
508         ( void ) pvParameters;\r
509 \r
510         for( ;; )\r
511         {\r
512                 if( SP != configSTACK_START )\r
513                 {\r
514                         mainLATCH_ERROR();\r
515                 }\r
516 \r
517                 _asm\r
518                         MOV ACC, ar0\r
519                 _endasm;\r
520 \r
521                 if( ACC != 0 )\r
522                 {\r
523                         mainLATCH_ERROR();\r
524                 }\r
525 \r
526                 _asm\r
527                         MOV ACC, ar1\r
528                 _endasm;\r
529 \r
530                 if( ACC != 1 )\r
531                 {\r
532                         mainLATCH_ERROR();\r
533                 }\r
534                 _asm\r
535                         MOV ACC, ar2\r
536                 _endasm;\r
537 \r
538                 if( ACC != 2 )\r
539                 {\r
540                         mainLATCH_ERROR();\r
541                 }\r
542                 _asm\r
543                         MOV ACC, ar3\r
544                 _endasm;\r
545 \r
546                 if( ACC != 3 )\r
547                 {\r
548                         mainLATCH_ERROR();\r
549                 }\r
550                 _asm\r
551                         MOV ACC, ar4\r
552                 _endasm;\r
553 \r
554                 if( ACC != 4 )\r
555                 {\r
556                         mainLATCH_ERROR();\r
557                 }\r
558                 _asm\r
559                         MOV ACC, ar5\r
560                 _endasm;\r
561 \r
562                 if( ACC != 5 )\r
563                 {\r
564                         mainLATCH_ERROR();\r
565                 }\r
566                 _asm\r
567                         MOV ACC, ar6\r
568                 _endasm;\r
569 \r
570                 if( ACC != 6 )\r
571                 {\r
572                         mainLATCH_ERROR();\r
573                 }\r
574                 _asm\r
575                         MOV ACC, ar7\r
576                 _endasm;\r
577 \r
578                 if( ACC != 7 )\r
579                 {\r
580                         mainLATCH_ERROR();\r
581                 }\r
582 \r
583                 if( DPL != 0xcd )\r
584                 {\r
585                         mainLATCH_ERROR();\r
586                 }\r
587 \r
588                 if( DPH != 0xab )\r
589                 {\r
590                         mainLATCH_ERROR();\r
591                 }\r
592 \r
593                 if( B != 0x01 )\r
594                 {\r
595                         mainLATCH_ERROR();\r
596                 }                       \r
597         }\r
598 }\r
599 \r
600 \r