]> git.sur5r.net Git - freertos/blob - Demo/CORTUS_APS3_GCC/Demo/RegTest.c
243c7b6ba521996eddc38458d60899e55a111c86
[freertos] / Demo / CORTUS_APS3_GCC / Demo / RegTest.c
1 /*
2     FreeRTOS V6.0.4 - Copyright (C) 2010 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 eBook                                  *
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 #include "FreeRTOS.h"
55 #include "task.h"
56
57 static void vRegTest1( void *pvParameters );// __attribute__((naked));
58 static void vRegTest2( void *pvParameters );// __attribute__((naked));
59
60 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;
61
62 void vStartRegTestTasks( void )
63 {
64         xTaskCreate( vRegTest1, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
65         xTaskCreate( vRegTest2, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
66 }
67 /*-----------------------------------------------------------*/
68
69 static void vRegTest1( void *pvParameters )
70 {
71         __asm volatile
72         (
73                 "       mov             r2, #0x02                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */
74                 "       mov             r3, #0x03                                                       \n"
75                 "       mov             r4, #0x04                                                       \n"
76                 "       mov             r5, #0x05                                                       \n"
77                 "       mov             r6, #0x06                                                       \n"
78                 "       mov             r7, #0x07                                                       \n"
79                 "       mov             r8, #0x08                                                       \n"
80                 "       mov             r9, #0x09                                                       \n"
81                 "       mov             r10, #0x0a                                                      \n"
82                 "       mov             r11, #0x0b                                                      \n"
83                 "       mov             r12, #0x0c                                                      \n"
84                 "       mov             r13, #0x0d                                                      \n"
85                 "       mov             r14, #0x0e                                                      \n"
86                 "       mov             r15, #0x0f                                                      \n"
87                 "                                                                                               \n"
88                 "reg_check_loop_1:                                                              \n"
89                 "       trap    #31                                                                     \n"
90                 "       cmp             r2, #0x02                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */
91                 "       bne.s   reg_check_error_1                                       \n"
92                 "       cmp             r3, #0x03                                                       \n"
93                 "       bne.s   reg_check_error_1                                       \n"
94                 "       cmp             r4, #0x04                                                       \n"
95                 "       bne.s   reg_check_error_1                                       \n"
96                 "       cmp             r5, #0x05                                                       \n"
97                 "       bne.s   reg_check_error_1                                       \n"
98                 "       cmp             r6, #0x06                                                       \n"
99                 "       bne.s   reg_check_error_1                                       \n"
100                 "       cmp             r7, #0x07                                                       \n"
101                 "       bne.s   reg_check_error_1                                       \n"
102                 "       cmp             r8, #0x08                                                       \n"
103                 "       bne.s   reg_check_error_1                                       \n"
104                 "       cmp             r9, #0x09                                                       \n"
105                 "       bne.s   reg_check_error_1                                       \n"
106                 "       cmp             r10, #0x0a                                                      \n"
107                 "       bne.s   reg_check_error_1                                       \n"
108                 "       cmp             r11, #0x0b                                                      \n"
109                 "       bne.s   reg_check_error_1                                       \n"
110                 "       cmp             r12, #0x0c                                                      \n"
111                 "       bne.s   reg_check_error_1                                       \n"
112                 "       cmp             r13, #0x0d                                                      \n"
113                 "       bne.s   reg_check_error_1                                       \n"
114                 "       cmp             r14, #0x0e                                                      \n"
115                 "       bne.s   reg_check_error_1                                       \n"
116                 "       cmp             r15, #0x0f                                                      \n"
117                 "       bne.s   reg_check_error_1                                       \n"
118                 "                                                                                               \n"
119                 "       ld              r2, [r0]+short(ulRegTest1Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */
120                 "       add             r2, #1                                                          \n"
121                 "       st              r2, [r0]+short(ulRegTest1Counter)       \n"
122                 "       mov             r2, #0x02                                                       \n"
123                 "                                                                                               \n"
124                 "       bra.s   reg_check_loop_1                                        \n" /* Do it all again. */
125                 "                                                                                               \n"
126                 "reg_check_error_1:                                                             \n"
127                         "bra.s          .                                                               \n"
128         );
129 }
130 /*-----------------------------------------------------------*/
131
132 static void vRegTest2( void *pvParameters )
133 {
134         __asm volatile
135         (
136                 "       mov             r2, #0x12                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */
137                 "       mov             r3, #0x13                                                       \n"
138                 "       mov             r4, #0x14                                                       \n"
139                 "       mov             r5, #0x15                                                       \n"
140                 "       mov             r6, #0x16                                                       \n"
141                 "       mov             r7, #0x17                                                       \n"
142                 "       mov             r8, #0x18                                                       \n"
143                 "       mov             r9, #0x19                                                       \n"
144                 "       mov             r10, #0x1a                                                      \n"
145                 "       mov             r11, #0x1b                                                      \n"
146                 "       mov             r12, #0x1c                                                      \n"
147                 "       mov             r13, #0x1d                                                      \n"
148                 "       mov             r14, #0x1e                                                      \n"
149                 "       mov             r15, #0x1f                                                      \n"
150                 "                                                                                               \n"
151                 "reg_check_loop_2:                                                              \n"
152                 "       cmp             r2, #0x12                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */
153                 "       bne.s   reg_check_error_2                                       \n"
154                 "       cmp             r3, #0x13                                                       \n"
155                 "       bne.s   reg_check_error_2                                       \n"
156                 "       cmp             r4, #0x14                                                       \n"
157                 "       bne.s   reg_check_error_2                                       \n"
158                 "       cmp             r5, #0x15                                                       \n"
159                 "       bne.s   reg_check_error_2                                       \n"
160                 "       cmp             r6, #0x16                                                       \n"
161                 "       bne.s   reg_check_error_2                                       \n"
162                 "       cmp             r7, #0x17                                                       \n"
163                 "       bne.s   reg_check_error_2                                       \n"
164                 "       cmp             r8, #0x18                                                       \n"
165                 "       bne.s   reg_check_error_2                                       \n"
166                 "       cmp             r9, #0x19                                                       \n"
167                 "       bne.s   reg_check_error_2                                       \n"
168                 "       cmp             r10, #0x1a                                                      \n"
169                 "       bne.s   reg_check_error_2                                       \n"
170                 "       cmp             r11, #0x1b                                                      \n"
171                 "       bne.s   reg_check_error_2                                       \n"
172                 "       cmp             r12, #0x1c                                                      \n"
173                 "       bne.s   reg_check_error_2                                       \n"
174                 "       cmp             r13, #0x1d                                                      \n"
175                 "       bne.s   reg_check_error_2                                       \n"
176                 "       cmp             r14, #0x1e                                                      \n"
177                 "       bne.s   reg_check_error_2                                       \n"
178                 "       cmp             r15, #0x1f                                                      \n"
179                 "       bne.s   reg_check_error_2                                       \n"
180                 "                                                                                               \n"
181                 "       ld              r2, [r0]+short(ulRegTest2Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */
182                 "       add             r2, #1                                                          \n"
183                 "       st              r2, [r0]+short(ulRegTest2Counter)       \n"
184                 "       mov             r2, #0x12                                                       \n"
185                 "                                                                                               \n"
186                 "       bra.s   reg_check_loop_2                                        \n" /* Do it all again. */
187                 "                                                                                               \n"
188                 "reg_check_error_2:                                                             \n"
189                         "bra.s          .                                                               \n"
190         );
191 }
192 /*-----------------------------------------------------------*/
193
194 portBASE_TYPE xAreRegTestTasksStillRunning( void )
195 {
196 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL;
197 long lReturn;
198
199         /* Check that both loop counters are still incrementing, indicating that
200         both reg test tasks are still running error free. */
201         if( ulLastCounter1 == ulRegTest1Counter )
202         {
203                 lReturn = pdFAIL;
204         }
205         else if( ulLastCounter2 == ulRegTest2Counter )
206         {
207                 lReturn = pdFAIL;
208         }
209         else
210         {
211                 lReturn = pdPASS;
212         }
213
214         ulLastCounter1 = ulRegTest1Counter;
215         ulLastCounter2 = ulRegTest2Counter;
216
217         return lReturn;
218 }
219
220
221
222
223
224
225
226
227
228
229
230
231
232