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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [NEC_V850ES_IAR/] [main.c] - Blame information for rev 654

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

Line No. Rev Author Line
1 584 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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
56
 * documentation provides more details of the standard demo application tasks.
57
 * In addition to the standard demo tasks, the following tasks and tests are
58
 * defined and/or created within this file:
59
 *
60
 * "Check" task -  This only executes every three seconds but has a high priority
61
 * to ensure it gets processor time.  Its main function is to check that all the
62
 * standard demo tasks are still operational.  If everything is running as
63
 * expected then the check task will toggle an LED every 3 seconds.  An error
64
 * being discovered in any task will cause the toggle rate to increase to 500ms.
65
 *
66
 * "Reg test" tasks - These fill the registers with known values, then check
67
 * that each register still contains its expected value.  Each task uses
68
 * different values.  The tasks run with very low priority so get preempted very
69
 * frequently.  A register containing an unexpected value is indicative of an
70
 * error in the context switching mechanism.
71
 *
72
 */
73
 
74
/* Standard include files. */
75
#include <stdlib.h>
76
#include <string.h>
77
 
78
/* Scheduler include files. */
79
#include "FreeRTOS.h"
80
#include "task.h"
81
 
82
/* Demo file headers. */
83
#include <intrinsics.h>
84
#include "BlockQ.h"
85
#include "death.h"
86
#include "flash.h"
87
#include "partest.h"
88
#include "semtest.h"
89
#include "PollQ.h"
90
#include "GenQTest.h"
91
#include "QPeek.h"
92
#include "recmutex.h"
93
#include "comtest2.h"
94
 
95
/*
96
 * Priority definitions for most of the tasks in the demo application.  Some
97
 * tasks just use the idle priority.
98
 */
99
#define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )
100
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
101
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
102
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
103
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
104
#define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
105
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
106
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
107
#define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )
108
 
109
/* Passed into the check task just as a test that the parameter passing
110
mechanism is working correctly. */
111
#define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )
112
 
113
/* The period between executions of the check task. */
114
#define mainNO_ERROR_DELAY              ( ( portTickType ) 3000 / portTICK_RATE_MS  )
115
#define mainERROR_DELAY                 ( ( portTickType ) 500 / portTICK_RATE_MS )
116
 
117
/* There are no spare LEDs for the comtest tasks, so this is just set to an
118
invalid number. */
119
#define mainCOMTEST_LED                 ( 4 )
120
 
121
/* The baud rate used by the comtest task. */
122
#define mainBAUD_RATE                   ( 9600 )
123
 
124
/*-----------------------------------------------------------*/
125
 
126
/* The implementation of the 'check' task as described at the top of this file. */
127
static void prvCheckTask( void *pvParameters );
128
 
129
/* Just sets up the LED outputs.  Most generic setup is done in
130
__low_level_init(). */
131
static void prvSetupHardware( void );
132
 
133
/* The RegTest functions as described at the top of this file. */
134
extern void vRegTest1( void *pvParameters );
135
extern void vRegTest2( void *pvParameters );
136
 
137
/* A variable that will get set to fail if a RegTest task finds an error.  The
138
variable is inspected by the 'Check' task. */
139
static volatile portLONG lRegTestStatus = pdPASS;
140
 
141
/*-----------------------------------------------------------*/
142
 
143
/* Create all the demo tasks then start the scheduler. */
144
void main( void )
145
{
146
        /* Just sets up the LED outputs. */
147
        prvSetupHardware();
148
 
149
        /* Standard demo tasks. */
150
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
151
        vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
152
        vStartQueuePeekTasks();
153
 
154
        /* Create the check task as described at the top of this file. */
155
        xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
156
 
157
        /* Create the RegTest tasks as described at the top of this file. */
158
        xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
159
        xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
160
 
161
        #ifdef __IAR_V850ES_Fx3__
162
        {
163
                /* The extra IO required for the com test and led flashing tasks is only
164
                available on the application board, not the target boards. */
165
                vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
166
                vStartLEDFlashTasks( mainFLASH_PRIORITY );
167
 
168
                /* The Fx3 also has enough RAM to run loads more tasks. */
169
                vStartRecursiveMutexTasks();
170
                vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
171
                vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
172
        }
173
        #endif  
174
 
175
        /* The suicide tasks must be created last as they need to know how many
176
        tasks were running prior to their creation in order to ascertain whether
177
        or not the correct/expected number of tasks are running at any given time. */
178
    vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
179
 
180
        /* Start the scheduler. */
181
        vTaskStartScheduler();
182
 
183
        /* If this line is reached then vTaskStartScheduler() returned because there
184
        was insufficient heap memory remaining for the idle task to be created. */
185
        for( ;; );
186
}
187
/*-----------------------------------------------------------*/
188
 
189
static void prvCheckTask( void *pvParameters )
190
{
191
portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;
192
unsigned portBASE_TYPE uxLEDToUse = 0;
193
 
194
        /* Ensure parameter is passed in correctly. */
195
        if( pvParameters != mainCHECK_PARAMETER )
196
        {
197
                xDelayPeriod = mainERROR_DELAY;
198
        }
199
 
200
        /* Initialise xLastWakeTime before it is used.  After this point it is not
201
        written to directly. */
202
        xLastWakeTime = xTaskGetTickCount();
203
 
204
        /* Cycle for ever, delaying then checking all the other tasks are still
205
        operating without error. */
206
        for( ;; )
207
        {
208
                /* Wait until it is time to check all the other tasks again. */
209
                vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
210
 
211
                if( lRegTestStatus != pdPASS )
212
                {
213
                        xDelayPeriod = mainERROR_DELAY;
214
                }
215
 
216
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
217
                {
218
                        xDelayPeriod = mainERROR_DELAY;
219
                }
220
 
221
                if( xAreQueuePeekTasksStillRunning() != pdTRUE )
222
                {
223
                        xDelayPeriod = mainERROR_DELAY;
224
                }
225
 
226
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
227
            {
228
                xDelayPeriod = mainERROR_DELAY;
229
            }
230
 
231
                if( xIsCreateTaskStillRunning() != pdTRUE )
232
            {
233
                xDelayPeriod = mainERROR_DELAY;
234
            }
235
 
236
                /* The Fx3 runs more tasks, so more checks are performed. */
237
                #ifdef __IAR_V850ES_Fx3__
238
                {
239
                        if( xAreComTestTasksStillRunning() != pdTRUE )
240
                        {
241
                                xDelayPeriod = mainERROR_DELAY;
242
                        }
243
 
244
                        if( xArePollingQueuesStillRunning() != pdTRUE )
245
                        {
246
                                xDelayPeriod = mainERROR_DELAY;
247
                        }
248
 
249
                        if( xAreBlockingQueuesStillRunning() != pdTRUE )
250
                        {
251
                                xDelayPeriod = mainERROR_DELAY;
252
                        }
253
 
254
                        if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
255
                        {
256
                                xDelayPeriod = mainERROR_DELAY;
257
                        }
258
 
259
                        /* The application board has more LEDs and uses the flash tasks
260
                        so the check task instead uses LED3 as LED3 is still spare. */
261
                        uxLEDToUse = 3;
262
                }
263
                #endif
264
 
265
                /* Toggle the LED.  The toggle rate will depend on whether or not an
266
                error has been found in any tasks. */
267
                vParTestToggleLED( uxLEDToUse );
268
        }
269
}
270
/*-----------------------------------------------------------*/
271
 
272
static void prvSetupHardware( void )
273
{
274
        /* Setup the LED outputs. */
275
        vParTestInitialise();
276
 
277
        /* Any additional hardware configuration can be added here. */
278
}
279
/*-----------------------------------------------------------*/
280
 
281
void vApplicationStackOverflowHook( void )
282
{
283
        /* This will be called if a task overflows its stack.  pxCurrentTCB
284
        can be inspected to see which is the offending task. */
285
        for( ;; );
286
}
287
/*-----------------------------------------------------------*/
288
 
289
void vRegTestFailed( void )
290
{
291
        /* Called by the RegTest tasks if an error is found.  lRegTestStatus is
292
        inspected by the check task. */
293
        lRegTestStatus = pdFAIL;
294
 
295
        /* Do not return from here as the reg test tasks clobber all registers so
296
        function calls may not function correctly. */
297
        for( ;; );
298
}

powered by: WebSVN 2.1.0

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