OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [RX600_RX62N-RSK_GNURX/] [RTOSDemo/] [main-full.c] - Blame information for rev 615

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 585 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/* ****************************************************************************
55
 * This project includes a lot of tasks and tests and is therefore complex.
56
 * If you would prefer a much simpler project to get started with then select
57
 * the 'Blinky' build configuration within the HEW IDE.
58
 * ****************************************************************************
59
 *
60
 * Creates all the demo application tasks, then starts the scheduler.  The web
61
 * documentation provides more details of the standard demo application tasks,
62
 * which provide no particular functionality but do provide a good example of
63
 * how to use the FreeRTOS API.  The tasks defined in flop.c are included in the
64
 * set of standard demo tasks to ensure the floating point unit gets some
65
 * exercise.
66
 *
67
 * In addition to the standard demo tasks, the following tasks and tests are
68
 * defined and/or created within this file:
69
 *
70
 * Webserver ("uIP") task - This serves a number of dynamically generated WEB
71
 * pages to a standard WEB browser.  The IP and MAC addresses are configured by
72
 * constants defined at the bottom of FreeRTOSConfig.h.  Use either a standard
73
 * Ethernet cable to connect through a hug, or a cross over (point to point)
74
 * cable to connect directly.  Ensure the IP address used is compatible with the
75
 * IP address of the machine running the browser - the easiest way to achieve
76
 * this is to ensure the first three octets of the IP addresses are the same.
77
 *
78
 * "Reg test" tasks - These fill the registers with known values, then check
79
 * that each register still contains its expected value.  Each task uses
80
 * different values.  The tasks run with very low priority so get preempted
81
 * very frequently.  A check variable is incremented on each iteration of the
82
 * test loop.  A register containing an unexpected value is indicative of an
83
 * error in the context switching mechanism and will result in a branch to a
84
 * null loop - which in turn will prevent the check variable from incrementing
85
 * any further and allow the check task (described below) to determine that an
86
 * error has occurred.  The nature of the reg test tasks necessitates that they
87
 * are written in assembly code.
88
 *
89
 * "Check" task - This only executes every five seconds but has a high priority
90
 * to ensure it gets processor time.  Its main function is to check that all the
91
 * standard demo tasks are still operational.  While no errors have been
92
 * discovered the check task will toggle LED 5 every 5 seconds - the toggle
93
 * rate increasing to 200ms being a visual indication that at least one task has
94
 * reported unexpected behaviour.
95
 *
96
 * "High frequency timer test" - A high frequency periodic interrupt is
97
 * generated using a timer - the interrupt is assigned a priority above
98
 * configMAX_SYSCALL_INTERRUPT_PRIORITY so should not be effected by anything
99
 * the kernel is doing.  The frequency and priority of the interrupt, in
100
 * combination with other standard tests executed in this demo, should result
101
 * in interrupts nesting at least 3 and probably 4 deep.  This test is only
102
 * included in build configurations that have the optimiser switched on.  In
103
 * optimised builds the count of high frequency ticks is used as the time base
104
 * for the run time stats.
105
 *
106
 * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application
107
 * tasks are executing as expected and no errors have been reported in any
108
 * tasks.  The toggle rate increasing to 200ms indicates that at least one task
109
 * has reported unexpected behaviour.
110
 *
111
 * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let
112
 * the application set up a timer to generate the tick interrupt.  In this
113
 * example a compare match timer is used for this purpose.
114
 *
115
 * *NOTE 3* The CPU must be in Supervisor mode when the scheduler is started.
116
 * The PowerON_Reset_PC() supplied in resetprg.c with this demo has
117
 * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.
118
 *
119
 * *NOTE 4* The IntQueue common demo tasks test interrupt nesting and make use
120
 * of all the 8bit timers (as two cascaded 16bit units).
121
*/
122
 
123
/* Hardware specific includes. */
124
#include "iodefine.h"
125
 
126
/* Kernel includes. */
127
#include "FreeRTOS.h"
128
#include "task.h"
129
 
130
/* Standard demo includes. */
131
#include "partest.h"
132
#include "flash.h"
133
#include "IntQueue.h"
134
#include "BlockQ.h"
135
#include "death.h"
136
#include "integer.h"
137
#include "blocktim.h"
138
#include "semtest.h"
139
#include "PollQ.h"
140
#include "GenQTest.h"
141
#include "QPeek.h"
142
#include "recmutex.h"
143
#include "flop.h"
144
 
145
/* Values that are passed into the reg test tasks using the task parameter.  The
146
tasks check that the values are passed in correctly. */
147
#define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )
148
#define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )
149
 
150
/* Priorities at which the tasks are created. */
151
#define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )
152
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )
153
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
154
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
155
#define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )
156
#define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )
157
#define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
158
#define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )
159
#define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )
160
#define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )
161
 
162
/* The WEB server uses string handling functions, which in turn use a bit more
163
stack than most of the other tasks. */
164
#define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )
165
 
166
/* The LED toggled by the check task. */
167
#define mainCHECK_LED                           ( 5 )
168
 
169
/* The rate at which mainCHECK_LED will toggle when all the tasks are running
170
without error.  Controlled by the check task as described at the top of this
171
file. */
172
#define mainNO_ERROR_CYCLE_TIME         ( 5000 / portTICK_RATE_MS )
173
 
174
/* The rate at which mainCHECK_LED will toggle when an error has been reported
175
by at least one task.  Controlled by the check task as described at the top of
176
this file. */
177
#define mainERROR_CYCLE_TIME            ( 200 / portTICK_RATE_MS )
178
 
179
 
180
/*
181
 * vApplicationMallocFailedHook() will only be called if
182
 * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
183
 * function that will execute if a call to pvPortMalloc() fails.
184
 * pvPortMalloc() is called internally by the kernel whenever a task, queue or
185
 * semaphore is created.  It is also called by various parts of the demo
186
 * application.
187
 */
188
void vApplicationMallocFailedHook( void );
189
 
190
/*
191
 * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1
192
 * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration
193
 * of the idle task.  It is essential that code added to this hook function
194
 * never attempts to block in any way (for example, call xQueueReceive() with
195
 * a block time specified).  If the application makes use of the vTaskDelete()
196
 * API function (as this demo application does) then it is also important that
197
 * vApplicationIdleHook() is permitted to return to its calling function because
198
 * it is the responsibility of the idle task to clean up memory allocated by the
199
 * kernel to any task that has since been deleted.
200
 */
201
void vApplicationIdleHook( void );
202
 
203
/*
204
 * vApplicationStackOverflowHook() will only be called if
205
 * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and
206
 * name of the offending task should be passed in the function parameters, but
207
 * it is possible that the stack overflow will have corrupted these - in which
208
 * case pxCurrentTCB can be inspected to find the same information.
209
 */
210
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );
211
 
212
/*
213
 * The reg test tasks as described at the top of this file.
214
 */
215
static void prvRegTest1Task( void *pvParameters );
216
static void prvRegTest2Task( void *pvParameters );
217
 
218
/*
219
 * The actual implementation of the reg test functionality, which, because of
220
 * the direct register access, have to be in assembly.
221
 */
222
static void prvRegTest1Implementation( void ) __attribute__((naked));
223
static void prvRegTest2Implementation( void ) __attribute__((naked));
224
 
225
 
226
/*
227
 * The check task as described at the top of this file.
228
 */
229
static void prvCheckTask( void *pvParameters );
230
 
231
/*
232
 * Contains the implementation of the WEB server.
233
 */
234
extern void vuIP_Task( void *pvParameters );
235
 
236
/*-----------------------------------------------------------*/
237
 
238
/* Variables that are incremented on each iteration of the reg test tasks -
239
provided the tasks have not reported any errors.  The check task inspects these
240
variables to ensure they are still incrementing as expected.  If a variable
241
stops incrementing then it is likely that its associate task has stalled. */
242
unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;
243
 
244
/* The status message that is displayed at the bottom of the "task stats" web
245
page, which is served by the uIP task.  This will report any errors picked up
246
by the reg test task. */
247
static const char *pcStatusMessage = NULL;
248
 
249
/*-----------------------------------------------------------*/
250
 
251
int main(void)
252
{
253
extern void HardwareSetup( void );
254
 
255
        /* Renesas provided CPU configuration routine.  The clocks are configured in
256
        here. */
257
        HardwareSetup();
258
 
259
        /* Turn all LEDs off. */
260
        vParTestInitialise();
261
 
262
        /* Start the reg test tasks which test the context switching mechanism. */
263
        xTaskCreate( prvRegTest1Task, ( signed char * ) "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
264
        xTaskCreate( prvRegTest2Task, ( signed char * ) "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
265
 
266
        /* The web server task. */
267
        xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );
268
 
269
        /* Start the check task as described at the top of this file. */
270
        xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
271
 
272
        /* Create the standard demo tasks. */
273
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
274
        vCreateBlockTimeTasks();
275
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
276
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
277
        vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
278
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
279
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
280
        vStartQueuePeekTasks();
281
        vStartRecursiveMutexTasks();
282
        vStartInterruptQueueTasks();
283
        vStartMathTasks( mainFLOP_TASK_PRIORITY );
284
 
285
        /* The suicide tasks must be created last as they need to know how many
286
        tasks were running prior to their creation in order to ascertain whether
287
        or not the correct/expected number of tasks are running at any given time. */
288
        vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
289
 
290
        /* Start the tasks running. */
291
        vTaskStartScheduler();
292
 
293
        /* If all is well we will never reach here as the scheduler will now be
294
        running.  If we do reach here then it is likely that there was insufficient
295
        heap available for the idle task to be created. */
296
        for( ;; );
297
 
298
        return 0;
299
}
300
/*-----------------------------------------------------------*/
301
 
302
static void prvCheckTask( void *pvParameters )
303
{
304
static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
305
portTickType xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;
306
extern void vSetupHighFrequencyTimer( void );
307
 
308
        /* If this is being executed then the kernel has been started.  Start the high
309
        frequency timer test as described at the top of this file.  This is only
310
        included in the optimised build configuration - otherwise it takes up too much
311
        CPU time. */
312
        #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST
313
                vSetupHighFrequencyTimer();
314
        #endif
315
 
316
        /* Initialise xNextWakeTime - this only needs to be done once. */
317
        xNextWakeTime = xTaskGetTickCount();
318
 
319
        for( ;; )
320
        {
321
                /* Place this task in the blocked state until it is time to run again. */
322
                vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
323
 
324
                /* Check the standard demo tasks are running without error. */
325
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
326
                {
327
                        pcStatusMessage = "Error: GenQueue";
328
                }
329
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
330
                {
331
                        pcStatusMessage = "Error: QueuePeek\r\n";
332
                }
333
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )
334
                {
335
                        pcStatusMessage = "Error: BlockQueue\r\n";
336
                }
337
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
338
                {
339
                        pcStatusMessage = "Error: BlockTime\r\n";
340
                }
341
            else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
342
            {
343
                        pcStatusMessage = "Error: SemTest\r\n";
344
            }
345
            else if( xArePollingQueuesStillRunning() != pdTRUE )
346
            {
347
                        pcStatusMessage = "Error: PollQueue\r\n";
348
            }
349
            else if( xIsCreateTaskStillRunning() != pdTRUE )
350
            {
351
                        pcStatusMessage = "Error: Death\r\n";
352
            }
353
            else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
354
            {
355
                        pcStatusMessage = "Error: IntMath\r\n";
356
            }
357
            else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
358
            {
359
                        pcStatusMessage = "Error: RecMutex\r\n";
360
            }
361
                else if( xAreIntQueueTasksStillRunning() != pdPASS )
362
                {
363
                        pcStatusMessage = "Error: IntQueue\r\n";
364
                }
365
                else if( xAreMathsTaskStillRunning() != pdPASS )
366
                {
367
                        pcStatusMessage = "Error: Flop\r\n";
368
                }
369
 
370
                /* Check the reg test tasks are still cycling.  They will stop incrementing
371
                their loop counters if they encounter an error. */
372
                if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )
373
                {
374
                        pcStatusMessage = "Error: RegTest1\r\n";
375
                }
376
 
377
                if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )
378
                {
379
                        pcStatusMessage = "Error: RegTest2\r\n";
380
                }
381
 
382
                ulLastRegTest1CycleCount = ulRegTest1CycleCount;
383
                ulLastRegTest2CycleCount = ulRegTest2CycleCount;
384
 
385
                /* Toggle the check LED to give an indication of the system status.  If
386
                the LED toggles every 5 seconds then everything is ok.  A faster toggle
387
                indicates an error. */
388
                vParTestToggleLED( mainCHECK_LED );
389
 
390
                /* Ensure the LED toggles at a faster rate if an error has occurred. */
391
                if( pcStatusMessage != NULL )
392
                {
393
                        /* Increase the rate at which this task cycles, which will increase the
394
                        rate at which mainCHECK_LED flashes to give visual feedback that an error
395
                        has occurred. */
396
                        xCycleFrequency = mainERROR_CYCLE_TIME;
397
                }
398
        }
399
}
400
/*-----------------------------------------------------------*/
401
 
402
/* The RX port uses this callback function to configure its tick interrupt.
403
This allows the application to choose the tick interrupt source. */
404
void vApplicationSetupTimerInterrupt( void )
405
{
406
        /* Enable compare match timer 0. */
407
        MSTP( CMT0 ) = 0;
408
 
409
        /* Interrupt on compare match. */
410
        CMT0.CMCR.BIT.CMIE = 1;
411
 
412
        /* Set the compare match value. */
413
        CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
414
 
415
        /* Divide the PCLK by 8. */
416
        CMT0.CMCR.BIT.CKS = 0;
417
 
418
        /* Enable the interrupt... */
419
        _IEN( _CMT0_CMI0 ) = 1;
420
 
421
        /* ...and set its priority to the application defined kernel priority. */
422
        _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
423
 
424
        /* Start the timer. */
425
        CMT.CMSTR0.BIT.STR0 = 1;
426
}
427
/*-----------------------------------------------------------*/
428
 
429
/* This function is explained by the comments above its prototype at the top
430
of this file. */
431
void vApplicationMallocFailedHook( void )
432
{
433
        for( ;; );
434
}
435
/*-----------------------------------------------------------*/
436
 
437
/* This function is explained by the comments above its prototype at the top
438
of this file. */
439
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
440
{
441
        for( ;; );
442
}
443
/*-----------------------------------------------------------*/
444
 
445
/* This function is explained by the comments above its prototype at the top
446
of this file. */
447
void vApplicationIdleHook( void )
448
{
449
}
450
/*-----------------------------------------------------------*/
451
 
452
/* This function is explained in the comments at the top of this file. */
453
static void prvRegTest1Task( void *pvParameters )
454
{
455
        if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )
456
        {
457
                /* The parameter did not contain the expected value. */
458
                for( ;; )
459
                {
460
                        /* Stop the tick interrupt so its obvious something has gone wrong. */
461
                        taskDISABLE_INTERRUPTS();
462
                }
463
        }
464
 
465
        /* This is an asm function that never returns. */
466
        prvRegTest1Implementation();
467
}
468
/*-----------------------------------------------------------*/
469
 
470
/* This function is explained in the comments at the top of this file. */
471
static void prvRegTest2Task( void *pvParameters )
472
{
473
        if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )
474
        {
475
                /* The parameter did not contain the expected value. */
476
                for( ;; )
477
                {
478
                        /* Stop the tick interrupt so its obvious something has gone wrong. */
479
                        taskDISABLE_INTERRUPTS();
480
                }
481
        }
482
 
483
        /* This is an asm function that never returns. */
484
        prvRegTest2Implementation();
485
}
486
/*-----------------------------------------------------------*/
487
 
488
char *pcGetTaskStatusMessage( void )
489
{
490
        /* Not bothered about a critical section here although technically because of
491
        the task priorities the pointer could change it will be atomic if not near
492
        atomic and its not critical. */
493
        if( pcStatusMessage == NULL )
494
        {
495
                return "All tasks running without error";
496
        }
497
        else
498
        {
499
                return ( char * ) pcStatusMessage;
500
        }
501
}
502
/*-----------------------------------------------------------*/
503
 
504
/* This function is explained in the comments at the top of this file. */
505
static void prvRegTest1Implementation( void )
506
{
507
        __asm volatile
508
        (
509
                        /* Put a known value in each register. */
510
                        "MOV    #1, R1                                          \n" \
511
                        "MOV    #2, R2                                          \n" \
512
                        "MOV    #3, R3                                          \n" \
513
                        "MOV    #4, R4                                          \n" \
514
                        "MOV    #5, R5                                          \n" \
515
                        "MOV    #6, R6                                          \n" \
516
                        "MOV    #7, R7                                          \n" \
517
                        "MOV    #8, R8                                          \n" \
518
                        "MOV    #9, R9                                          \n" \
519
                        "MOV    #10, R10                                        \n" \
520
                        "MOV    #11, R11                                        \n" \
521
                        "MOV    #12, R12                                        \n" \
522
                        "MOV    #13, R13                                        \n" \
523
                        "MOV    #14, R14                                        \n" \
524
                        "MOV    #15, R15                                        \n" \
525
 
526
                        /* Loop, checking each itteration that each register still contains the
527
                        expected value. */
528
                "TestLoop1:                                                             \n" \
529
 
530
                        /* Push the registers that are going to get clobbered. */
531
                        "PUSHM  R14-R15                                         \n" \
532
 
533
                        /* Increment the loop counter to show this task is still getting CPU time. */
534
                        "MOV    #_ulRegTest1CycleCount, R14     \n" \
535
                        "MOV    [ R14 ], R15                            \n" \
536
                        "ADD    #1, R15                                         \n" \
537
                        "MOV    R15, [ R14 ]                            \n" \
538
 
539
                        /* Yield to extend the test coverage.  Set the bit in the ITU SWINTR register. */
540
                        "MOV    #1, R14                                         \n" \
541
                        "MOV    #0872E0H, R15                           \n" \
542
                        "MOV.B  R14, [R15]                                      \n" \
543
                        "NOP                                                            \n" \
544
                        "NOP                                                            \n" \
545
 
546
                        /* Restore the clobbered registers. */
547
                        "POPM   R14-R15                                         \n" \
548
 
549
                        /* Now compare each register to ensure it still contains the value that was
550
                        set before this loop was entered. */
551
                        "CMP    #1, R1                                          \n" \
552
                        "BNE    RegTest1Error                           \n" \
553
                        "CMP    #2, R2                                          \n" \
554
                        "BNE    RegTest1Error                           \n" \
555
                        "CMP    #3, R3                                          \n" \
556
                        "BNE    RegTest1Error                           \n" \
557
                        "CMP    #4, R4                                          \n" \
558
                        "BNE    RegTest1Error                           \n" \
559
                        "CMP    #5, R5                                          \n" \
560
                        "BNE    RegTest1Error                           \n" \
561
                        "CMP    #6, R6                                          \n" \
562
                        "BNE    RegTest1Error                           \n" \
563
                        "CMP    #7, R7                                          \n" \
564
                        "BNE    RegTest1Error                           \n" \
565
                        "CMP    #8, R8                                          \n" \
566
                        "BNE    RegTest1Error                           \n" \
567
                        "CMP    #9, R9                                          \n" \
568
                        "BNE    RegTest1Error                           \n" \
569
                        "CMP    #10, R10                                        \n" \
570
                        "BNE    RegTest1Error                           \n" \
571
                        "CMP    #11, R11                                        \n" \
572
                        "BNE    RegTest1Error                           \n" \
573
                        "CMP    #12, R12                                        \n" \
574
                        "BNE    RegTest1Error                           \n" \
575
                        "CMP    #13, R13                                        \n" \
576
                        "BNE    RegTest1Error                           \n" \
577
                        "CMP    #14, R14                                        \n" \
578
                        "BNE    RegTest1Error                           \n" \
579
                        "CMP    #15, R15                                        \n" \
580
                        "BNE    RegTest1Error                           \n" \
581
 
582
                        /* All comparisons passed, start a new itteratio of this loop. */
583
                        "BRA            TestLoop1                               \n" \
584
 
585
                "RegTest1Error:                                                 \n" \
586
                        /* A compare failed, just loop here so the loop counter stops incrementing
587
                        - causing the check task to indicate the error. */
588
                        "BRA RegTest1Error                                        "
589
        );
590
}
591
/*-----------------------------------------------------------*/
592
 
593
/* This function is explained in the comments at the top of this file. */
594
static void prvRegTest2Implementation( void )
595
{
596
        __asm volatile
597
        (
598
                        /* Put a known value in each register. */
599
                        "MOV    #10H, R1                                        \n" \
600
                        "MOV    #20H, R2                                        \n" \
601
                        "MOV    #30H, R3                                        \n" \
602
                        "MOV    #40H, R4                                        \n" \
603
                        "MOV    #50H, R5                                        \n" \
604
                        "MOV    #60H, R6                                        \n" \
605
                        "MOV    #70H, R7                                        \n" \
606
                        "MOV    #80H, R8                                        \n" \
607
                        "MOV    #90H, R9                                        \n" \
608
                        "MOV    #100H, R10                                      \n" \
609
                        "MOV    #110H, R11                                      \n" \
610
                        "MOV    #120H, R12                                      \n" \
611
                        "MOV    #130H, R13                                      \n" \
612
                        "MOV    #140H, R14                                      \n" \
613
                        "MOV    #150H, R15                                      \n" \
614
 
615
                        /* Loop, checking each itteration that each register still contains the
616
                        expected value. */
617
                "TestLoop2:                                                             \n" \
618
 
619
                        /* Push the registers that are going to get clobbered. */
620
                        "PUSHM  R14-R15                                         \n" \
621
 
622
                        /* Increment the loop counter to show this task is still getting CPU time. */
623
                        "MOV    #_ulRegTest2CycleCount, R14     \n" \
624
                        "MOV    [ R14 ], R15                            \n" \
625
                        "ADD    #1, R15                                         \n" \
626
                        "MOV    R15, [ R14 ]                            \n" \
627
 
628
                        /* Restore the clobbered registers. */
629
                        "POPM   R14-R15                                         \n" \
630
 
631
                        /* Now compare each register to ensure it still contains the value that was
632
                        set before this loop was entered. */
633
                        "CMP    #10H, R1                                        \n" \
634
                        "BNE    RegTest2Error                           \n" \
635
                        "CMP    #20H, R2                                        \n" \
636
                        "BNE    RegTest2Error                           \n" \
637
                        "CMP    #30H, R3                                        \n" \
638
                        "BNE    RegTest2Error                           \n" \
639
                        "CMP    #40H, R4                                        \n" \
640
                        "BNE    RegTest2Error                           \n" \
641
                        "CMP    #50H, R5                                        \n" \
642
                        "BNE    RegTest2Error                           \n" \
643
                        "CMP    #60H, R6                                        \n" \
644
                        "BNE    RegTest2Error                           \n" \
645
                        "CMP    #70H, R7                                        \n" \
646
                        "BNE    RegTest2Error                           \n" \
647
                        "CMP    #80H, R8                                        \n" \
648
                        "BNE    RegTest2Error                           \n" \
649
                        "CMP    #90H, R9                                        \n" \
650
                        "BNE    RegTest2Error                           \n" \
651
                        "CMP    #100H, R10                                      \n" \
652
                        "BNE    RegTest2Error                           \n" \
653
                        "CMP    #110H, R11                                      \n" \
654
                        "BNE    RegTest2Error                           \n" \
655
                        "CMP    #120H, R12                                      \n" \
656
                        "BNE    RegTest2Error                           \n" \
657
                        "CMP    #130H, R13                                      \n" \
658
                        "BNE    RegTest2Error                           \n" \
659
                        "CMP    #140H, R14                                      \n" \
660
                        "BNE    RegTest2Error                           \n" \
661
                        "CMP    #150H, R15                                      \n" \
662
                        "BNE    RegTest2Error                           \n" \
663
 
664
                        /* All comparisons passed, start a new itteratio of this loop. */
665
                        "BRA    TestLoop2                                       \n" \
666
 
667
                "RegTest2Error:                                                 \n" \
668
                        /* A compare failed, just loop here so the loop counter stops incrementing
669
                        - causing the check task to indicate the error. */
670
                        "BRA RegTest2Error                                        "
671
        );
672
}
673
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.