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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 579 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.
56
 *
57
 * Main.c also creates a task called "Check".  This only executes every three
58
 * seconds but has the highest priority so is guaranteed to get processor time.
59
 * Its main function is to check that all the other tasks are still operational.
60
 * Each task (other than the "flash" tasks) maintains a unique count that is
61
 * incremented each time the task successfully completes its function.  Should
62
 * any error occur within such a task the count is permanently halted.  The
63
 * check task inspects the count of each task to ensure it has changed since
64
 * the last time the check task executed.  If all the count variables have
65
 * changed all the tasks are still executing error free, and the check task
66
 * toggles the on board LED.  Should any task contain an error at any time
67
 * the LED toggle rate will change from 3 seconds to 500ms.
68
 *
69
 * NOTE:  The demo application includes tasks that send and receive characters
70
 * over the UART. The characters sent by one task are received by another -
71
 * with an error condition being flagged should any characters be missed or
72
 * received out of order. A loopback connector is required on the 9way D socket
73
 * for this mechanism to operation (pins 2 and 3 the socket should be connected
74
 * together - a paper clip is normally sufficient).
75
 *
76
 */
77
 
78
/* Standard includes. */
79
#include <stdlib.h>
80
#include <string.h>
81
 
82
/* Scheduler includes. */
83
#include "FreeRTOS.h"
84
#include "task.h"
85
 
86
/* Demo application includes. */
87
#include "partest.h"
88
#include "flash.h"
89
#include "integer.h"
90
#include "PollQ.h"
91
#include "comtest2.h"
92
#include "semtest.h"
93
#include "flop.h"
94
#include "dynamic.h"
95
#include "BlockQ.h"
96
#include "serial.h"
97
#include "demoGpio.h"
98
#include "7seg.h"
99
#include "RegTest.h"
100
 
101
/*-----------------------------------------------------------*/
102
 
103
/* Constants for the ComTest tasks. */
104
#define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 115200 )
105
#define mainCOM_TEST_LED                ( 5 )
106
 
107
/* Priorities for the demo application tasks. */
108
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
109
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
110
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
111
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
112
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
113
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
114
#define main7SEG_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )
115
 
116
/* The rate at which the on board LED will toggle when there is/is not an
117
error. */
118
#define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS      )
119
#define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )
120
#define mainON_BOARD_LED_BIT            ( ( unsigned long ) 7 )
121
 
122
/* The size of the memory blocks allocated by the vMemCheckTask() task. */
123
#define mainMEM_CHECK_SIZE_1            ( ( size_t ) 51 )
124
#define mainMEM_CHECK_SIZE_2            ( ( size_t ) 52 )
125
#define mainMEM_CHECK_SIZE_3            ( ( size_t ) 151 )
126
 
127
/*-----------------------------------------------------------*/
128
 
129
/*
130
 * Checks that all the demo application tasks are still executing without error
131
 * - as described at the top of the file.
132
 */
133
static long prvCheckOtherTasksAreStillRunning( void );
134
 
135
/*
136
 * The task that executes at the highest priority and calls
137
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
138
 * of the file.
139
 */
140
static void vErrorChecks( void *pvParameters );
141
 
142
/*
143
 * Configure the processor for use with the Olimex demo board.  This includes
144
 * setup for the I/O, system clock, and access timings.
145
 */
146
static void prvSetupHardware( void );
147
 
148
 
149
/*-----------------------------------------------------------*/
150
 
151
/*
152
 * Starts all the other tasks, then starts the scheduler.
153
 */
154
int main( void )
155
{
156
        /* Setup the hardware for use with the Xilinx evaluation board. */
157
        prvSetupHardware();
158
 
159
        /* Start the demo/test application tasks. */
160
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
161
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
162
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
163
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
164
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
165
        vStartDynamicPriorityTasks();
166
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
167
        vStart7SegTasks( main7SEG_TASK_PRIORITY );
168
        vStartRegTestTasks();
169
 
170
        /* Start the check task - which is defined in this file. */
171
        xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
172
 
173
        /* Now all the tasks have been started - start the scheduler. */
174
        vTaskStartScheduler();
175
 
176
        /* Should never reach here! */
177
        for( ;; );
178
}
179
/*-----------------------------------------------------------*/
180
 
181
static void vErrorChecks( void *pvParameters )
182
{
183
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
184
 
185
        /* Just to stop compiler warnings. */
186
        ( void ) pvParameters;
187
 
188
        /* Cycle for ever, delaying then checking all the other tasks are still
189
        operating without error.  If an error is detected then the delay period
190
        is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
191
        the on board LED flash rate will increase. */
192
 
193
        for( ;; )
194
        {
195
                /* Delay until it is time to execute again. */
196
                vTaskDelay( xDelayPeriod );
197
 
198
                /* Check all the standard demo application tasks are executing without
199
                error.  */
200
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
201
                {
202
                        /* An error has been detected in one of the tasks - flash faster. */
203
                        xDelayPeriod = mainERROR_FLASH_PERIOD;
204
                }
205
 
206
                /* The toggle rate of the LED depends on how long this task delays for.
207
                An error reduces the delay period and so increases the toggle rate. */
208
                vParTestToggleLED( mainON_BOARD_LED_BIT );
209
        }
210
}
211
/*-----------------------------------------------------------*/
212
 
213
static void prvSetupHardware( void )
214
{
215
        /* Initialise LED outputs. */
216
        vParTestInitialise();
217
}
218
/*-----------------------------------------------------------*/
219
 
220
static long prvCheckOtherTasksAreStillRunning( void )
221
{
222
long lReturn = pdPASS;
223
 
224
        /* Check all the demo tasks (other than the flash tasks) to ensure
225
        that they are all still running, and that none of them have detected
226
        an error. */
227
 
228
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
229
        {
230
                lReturn = pdFAIL;
231
        }
232
 
233
        if( xAreComTestTasksStillRunning() != pdTRUE )
234
        {
235
                lReturn = pdFAIL;
236
        }
237
 
238
        if( xArePollingQueuesStillRunning() != pdTRUE )
239
        {
240
                lReturn = pdFAIL;
241
        }
242
 
243
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
244
        {
245
                lReturn = pdFAIL;
246
        }
247
 
248
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
249
        {
250
                lReturn = pdFAIL;
251
        }
252
 
253
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
254
        {
255
                lReturn = pdFAIL;
256
        }
257
 
258
        if( xAreRegTestTasksStillRunning() != pdTRUE )
259
        {
260
                lReturn = pdFAIL;
261
        }
262
 
263
        return lReturn;
264
}
265
/*-----------------------------------------------------------*/
266
 
267
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
268
{
269
        /* This function will be called if a task overflows its stack.  Inspect
270
        pxCurrentTCB to find the offending task if the overflow was sever enough
271
        to corrupt the pcTaskName parameter. */
272
        vParTestSetLED( 4, 1 );
273
        for( ;; );
274
}
275
/*-----------------------------------------------------------*/
276
 
277
void vApplicationMallocFailedHook( void )
278
{
279
        /* This function will be called if a call to pvPortMalloc() fails to return
280
        the requested memory.  pvPortMalloc() is called internally by the scheduler
281
        whenever a task, queue or semaphore is created. */
282
        vParTestSetLED( 4, 1 );
283
        for( ;; );
284
}
285
/*-----------------------------------------------------------*/
286
 
287
/* Provide an exit function to prevent a whole load of standard library functions
288
being brought into the build. */
289
void exit( int status )
290
{
291
        for( ;; );
292
}
293
 
294
 

powered by: WebSVN 2.1.0

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