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