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