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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 588 jeremybenn
 
2
/*
3
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
4
 
5
    ***************************************************************************
6
    *                                                                         *
7
    * If you are:                                                             *
8
    *                                                                         *
9
    *    + New to FreeRTOS,                                                   *
10
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
11
    *    + Looking for basic training,                                        *
12
    *    + Wanting to improve your FreeRTOS skills and productivity           *
13
    *                                                                         *
14
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
15
    *                                                                         *
16
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
17
    *                  http://www.FreeRTOS.org/Documentation                  *
18
    *                                                                         *
19
    * A pdf reference manual is also available.  Both are usually delivered   *
20
    * to your inbox within 20 minutes to two hours when purchased between 8am *
21
    * and 8pm GMT (although please allow up to 24 hours in case of            *
22
    * exceptional circumstances).  Thank you for your support!                *
23
    *                                                                         *
24
    ***************************************************************************
25
 
26
    This file is part of the FreeRTOS distribution.
27
 
28
    FreeRTOS is free software; you can redistribute it and/or modify it under
29
    the terms of the GNU General Public License (version 2) as published by the
30
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
31
    ***NOTE*** The exception to the GPL is included to allow you to distribute
32
    a combined work that includes FreeRTOS without being obliged to provide the
33
    source code for proprietary components outside of the FreeRTOS kernel.
34
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
35
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
37
    more details. You should have received a copy of the GNU General Public
38
    License and the FreeRTOS license exception along with FreeRTOS; if not it
39
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
40
    by writing to Richard Barry, contact details for whom are available on the
41
    FreeRTOS WEB site.
42
 
43
    1 tab == 4 spaces!
44
 
45
    http://www.FreeRTOS.org - Documentation, latest information, license and
46
    contact details.
47
 
48
    http://www.SafeRTOS.com - A version that is certified for use in safety
49
    critical systems.
50
 
51
    http://www.OpenRTOS.com - Commercial support, development, porting,
52
    licensing and training services.
53
*/
54
 
55
 
56
/*
57
 *
58
 * vMain() is effectively the demo application entry point.  It is called by
59
 * the main() function generated by the Processor Expert application.
60
 *
61
 * vMain() creates all the demo application tasks, then starts the scheduler.
62
 * The WEB      documentation provides more details of the demo application tasks.
63
 *
64
 * Main.c also creates a task called "Check".  This only executes every three
65
 * seconds but has the highest priority so is guaranteed to get processor time.
66
 * Its main function is to check that all the other tasks are still operational.
67
 * Each task (other than the "flash" tasks) maintains a unique count that is
68
 * incremented each time the task successfully completes its function.  Should
69
 * any error occur within such a task the count is permanently halted.  The
70
 * check task inspects the count of each task to ensure it has changed since
71
 * the last time the check task executed.  If all the count variables have
72
 * changed all the tasks are still executing error free, and the check task
73
 * toggles the onboard LED.  Should any task contain an error at any time
74
 * the LED toggle rate will change from 3 seconds to 500ms.
75
 *
76
 * This file also includes the functionality implemented within the
77
 * standard demo application file integer.c.  This is done to demonstrate the
78
 * use of an idle hook.  See the documentation within integer.c for the
79
 * rationale of the integer task functionality.
80
 * */
81
 
82
/* Kernel includes. */
83
#include "FreeRTOS.h"
84
#include "task.h"
85
#include "queue.h"
86
 
87
/* Demo application includes. */
88
#include "flash.h"
89
#include "PollQ.h"
90
#include "dynamic.h"
91
#include "partest.h"
92
#include "comtest2.h"
93
#include "BlockQ.h"
94
#include "integer.h"
95
#include "death.h"
96
 
97
 
98
/*-----------------------------------------------------------
99
        Definitions.
100
-----------------------------------------------------------*/
101
 
102
/* Priorities assigned to demo application tasks. */
103
#define mainFLASH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )
104
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
105
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )
106
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
107
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
108
#define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )
109
 
110
/* LED that is toggled by the check task.  The check task periodically checks
111
that all the other tasks are operating without error.  If no errors are found
112
the LED is toggled with mainCHECK_PERIOD frequency.  If an error is found
113
then the toggle rate increases to mainERROR_CHECK_PERIOD. */
114
#define mainCHECK_TASK_LED                      ( 7 )
115
#define mainCHECK_PERIOD                        ( ( portTickType ) 3000 / portTICK_RATE_MS  )
116
#define mainERROR_CHECK_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS )
117
 
118
/* The constants used in the idle task calculation. */
119
#define intgCONST1                              ( ( long ) 123 )
120
#define intgCONST2                              ( ( long ) 234567 )
121
#define intgCONST3                              ( ( long ) -3 )
122
#define intgCONST4                              ( ( long ) 7 )
123
#define intgEXPECTED_ANSWER             ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
124
 
125
 
126
/* Baud rate used by the serial port tasks (ComTest tasks).
127
IMPORTANT:  The function COM0_SetBaudRateValue() which is generated by the
128
Processor Expert is used to set the baud rate.  As configured in the FreeRTOS
129
download this value must be one of the following:
130
 
131
 
132
1 to configure for 19200 baud.
133
2 to configure for 9600 baud.
134
3 to configure for 4800 baud. */
135
#define mainCOM_TEST_BAUD_RATE                  ( ( unsigned long ) 2 )
136
 
137
/* LED used by the serial port tasks.  This is toggled on each character Tx,
138
and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
139
#define mainCOM_TEST_LED                                ( 3 )
140
 
141
/*-----------------------------------------------------------
142
        Local functions prototypes.
143
-----------------------------------------------------------*/
144
 
145
/*
146
 * The 'Check' task function.  See the explanation at the top of the file.
147
 */
148
static void vErrorChecks( void* pvParameters );
149
 
150
/*
151
 * The idle task hook - in which the integer task is implemented.  See the
152
 * explanation at the top of the file.
153
 */
154
void vApplicationIdleHook( void );
155
 
156
/*
157
 * Checks the unique counts of other tasks to ensure they are still operational.
158
 */
159
static long prvCheckOtherTasksAreStillRunning( void );
160
 
161
 
162
 
163
/*-----------------------------------------------------------
164
        Local variables.
165
-----------------------------------------------------------*/
166
 
167
/* A few tasks are defined within this file.  This flag is used to indicate
168
their status.  If an error is detected in one of the locally defined tasks then
169
this flag is set to pdTRUE. */
170
portBASE_TYPE xLocalError = pdFALSE;
171
 
172
 
173
/*-----------------------------------------------------------*/
174
 
175
/*
176
 * This is called from the main() function generated by the Processor Expert.
177
 */
178
void vMain( void )
179
{
180
        /* Start some of the standard demo tasks. */
181
        vStartLEDFlashTasks( mainFLASH_PRIORITY );
182
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
183
        vStartDynamicPriorityTasks();
184
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
185
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
186
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
187
 
188
        /* Start the locally defined tasks.  There is also a task implemented as
189
        the idle hook. */
190
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
191
 
192
        /* Must be the last demo created. */
193
        vCreateSuicidalTasks( mainDEATH_PRIORITY );
194
 
195
        /* All the tasks have been created - start the scheduler. */
196
        vTaskStartScheduler();
197
 
198
        /* Should not reach here! */
199
        for( ;; );
200
}
201
/*-----------------------------------------------------------*/
202
 
203
static void vErrorChecks( void *pvParameters )
204
{
205
portTickType xDelayPeriod = mainCHECK_PERIOD;
206
portTickType xLastWakeTime;
207
 
208
        /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
209
        functions correctly. */
210
        xLastWakeTime = xTaskGetTickCount();
211
 
212
        for( ;; )
213
        {
214
                /* Delay until it is time to execute again.  The delay period is
215
                shorter following an error. */
216
                vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
217
 
218
                /* Check all the demo application tasks are executing without
219
                error. If an error is found the delay period is shortened - this
220
                has the effect of increasing the flash rate of the 'check' task
221
                LED. */
222
                if( prvCheckOtherTasksAreStillRunning() == pdFAIL )
223
                {
224
                        /* An error has been detected in one of the tasks - flash faster. */
225
                        xDelayPeriod = mainERROR_CHECK_PERIOD;
226
                }
227
 
228
                /* Toggle the LED each cycle round. */
229
                vParTestToggleLED( mainCHECK_TASK_LED );
230
        }
231
}
232
/*-----------------------------------------------------------*/
233
 
234
static long prvCheckOtherTasksAreStillRunning( void )
235
{
236
portBASE_TYPE xAllTasksPassed = pdPASS;
237
 
238
        if( xArePollingQueuesStillRunning() != pdTRUE )
239
        {
240
                xAllTasksPassed = pdFAIL;
241
        }
242
 
243
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
244
        {
245
                xAllTasksPassed = pdFAIL;
246
        }
247
 
248
        if( xAreComTestTasksStillRunning() != pdTRUE )
249
        {
250
                xAllTasksPassed = pdFALSE;
251
        }
252
 
253
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
254
        {
255
                xAllTasksPassed = pdFALSE;
256
        }
257
 
258
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
259
        {
260
                xAllTasksPassed = pdFALSE;
261
        }
262
 
263
    if( xIsCreateTaskStillRunning() != pdTRUE )
264
    {
265
        xAllTasksPassed = pdFALSE;
266
    }
267
 
268
        /* Also check the status flag for the tasks defined within this function. */
269
        if( xLocalError != pdFALSE )
270
        {
271
                xAllTasksPassed = pdFAIL;
272
        }
273
 
274
        return xAllTasksPassed;
275
}
276
/*-----------------------------------------------------------*/
277
 
278
void vApplicationIdleHook( void )
279
{
280
/* This variable is effectively set to a constant so it is made volatile to
281
ensure the compiler does not just get rid of it. */
282
volatile long lValue;
283
 
284
        /* Keep performing a calculation and checking the result against a constant. */
285
 
286
        /* Perform the calculation.  This will store partial value in
287
        registers, resulting in a good test of the context switch mechanism. */
288
        lValue = intgCONST1;
289
        lValue += intgCONST2;
290
        lValue *= intgCONST3;
291
        lValue /= intgCONST4;
292
 
293
        /* Did we perform the calculation correctly with no corruption? */
294
        if( lValue != intgEXPECTED_ANSWER )
295
        {
296
                /* Error! */
297
                portENTER_CRITICAL();
298
                        xLocalError = pdTRUE;
299
                portEXIT_CRITICAL();
300
        }
301
 
302
        /* Yield in case cooperative scheduling is being used. */
303
        #if configUSE_PREEMPTION == 0
304
        {
305
                taskYIELD();
306
        }
307
        #endif          
308
}
309
/*-----------------------------------------------------------*/
310
 
311
 
312
 

powered by: WebSVN 2.1.0

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