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

Subversion Repositories openrisc

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

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
 * main() creates all the demo application tasks, then starts the scheduler.
59
 * The WEB      documentation provides more details of the demo application tasks.
60
 *
61
 * main.c also creates a task called "Check".  This only executes every three
62
 * seconds but has the highest priority so is guaranteed to get processor time.
63
 * Its main function is to check that all the other tasks are still operational.
64
 * Each task (other than the "flash" tasks) maintains a unique count that is
65
 * incremented each time the task successfully completes its function.  Should
66
 * any error occur within such a task the count is permanently halted.  The
67
 * check task inspects the count of each task to ensure it has changed since
68
 * the last time the check task executed.  If all the count variables have
69
 * changed all the tasks are still executing error free, and the check task
70
 * toggles the onboard LED.  Should any task contain an error at any time
71
 * the LED toggle rate will change from 3 seconds to 500ms.
72
 *
73
 * This file also includes the functionality implemented within the
74
 * standard demo application file integer.c.  This is done to demonstrate the
75
 * use of an idle hook.  See the documentation within integer.c for the
76
 * rationale of the integer task functionality.
77
 * */
78
 
79
/* Kernel includes. */
80
#include "FreeRTOS.h"
81
#include "task.h"
82
#include "queue.h"
83
 
84
#include "cpu.h"
85
 
86
/* special prototypes for memory-banked functions */
87
void vStartPolledQueueTasks( unsigned portBASE_TYPE uxPriority );
88
portBASE_TYPE xArePollingQueuesStillRunning( void );
89
 
90
/* Demo application includes. */
91
#include "flash.h"
92
#include "PollQ.h"
93
#include "dynamic.h"
94
#include "partest.h"
95
#include "comtest2.h"
96
#include "BlockQ.h"
97
#include "integer.h"
98
#include "death.h"
99
 
100
 
101
/*-----------------------------------------------------------
102
        Definitions.
103
-----------------------------------------------------------*/
104
 
105
/* Priorities assigned to demo application tasks. */
106
#define mainFLASH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )
107
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
108
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )
109
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
110
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
111
#define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )
112
 
113
/* LED that is toggled by the check task.  The check task periodically checks
114
that all the other tasks are operating without error.  If no errors are found
115
the LED is toggled with mainCHECK_PERIOD frequency.  If an error is found
116
then the toggle rate increases to mainERROR_CHECK_PERIOD. */
117
#define mainCHECK_TASK_LED                      ( 7 )
118
#define mainCHECK_PERIOD                        ( ( portTickType ) 3000 / portTICK_RATE_MS  )
119
#define mainERROR_CHECK_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS )
120
 
121
/* The constants used in the idle task calculation. */
122
#define intgCONST1                              ( ( long ) 123 )
123
#define intgCONST2                              ( ( long ) 234567 )
124
#define intgCONST3                              ( ( long ) -3 )
125
#define intgCONST4                              ( ( long ) 7 )
126
#define intgEXPECTED_ANSWER             ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
127
 
128
 
129
/* Baud rate used by the serial port tasks (ComTest tasks).
130
IMPORTANT:  The function COM0_SetBaudRateValue() which is generated by the
131
Processor Expert is used to set the baud rate.  As configured in the FreeRTOS
132
download this value must be one of the following:
133
 
134
 
135
1 to configure for 19200 baud.
136
2 to configure for 9600 baud.
137
3 to configure for 4800 baud. */
138
#define mainCOM_TEST_BAUD_RATE                  ( ( unsigned long ) 2 )
139
 
140
/* LED used by the serial port tasks.  This is toggled on each character Tx,
141
and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
142
#define mainCOM_TEST_LED                                ( 3 )
143
 
144
/*-----------------------------------------------------------
145
        Local functions prototypes.
146
-----------------------------------------------------------*/
147
 
148
/*
149
 * The 'Check' task function.  See the explanation at the top of the file.
150
 */
151
static void ATTR_BANK1 vErrorChecks( void* pvParameters );
152
 
153
/*
154
 * The idle task hook - in which the integer task is implemented.  See the
155
 * explanation at the top of the file.
156
 */
157
void ATTR_BANK0 vApplicationIdleHook( void );
158
 
159
/*
160
 * Checks the unique counts of other tasks to ensure they are still operational.
161
 */
162
static long ATTR_BANK0 prvCheckOtherTasksAreStillRunning( void );
163
 
164
 
165
 
166
/*-----------------------------------------------------------
167
        Local variables.
168
-----------------------------------------------------------*/
169
 
170
/* A few tasks are defined within this file.  This flag is used to indicate
171
their status.  If an error is detected in one of the locally defined tasks then
172
this flag is set to pdTRUE. */
173
portBASE_TYPE xLocalError = pdFALSE;
174
 
175
 
176
/*-----------------------------------------------------------*/
177
 
178
/* This is called from startup. */
179
int ATTR_BANK0 main ( void )
180
{
181
        /* Start some of the standard demo tasks. */
182
        vStartLEDFlashTasks( mainFLASH_PRIORITY );
183
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
184
        vStartDynamicPriorityTasks();
185
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
186
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
187
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
188
 
189
        /* Start the locally defined tasks.  There is also a task implemented as
190
        the idle hook. */
191
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
192
 
193
        /* Must be the last demo created. */
194
        vCreateSuicidalTasks( mainDEATH_PRIORITY );
195
 
196
        /* All the tasks have been created - start the scheduler. */
197
        vTaskStartScheduler();
198
 
199
        /* Should not reach here! */
200
        for( ;; );
201
        return 0;
202
}
203
/*-----------------------------------------------------------*/
204
 
205
static void vErrorChecks( void *pvParameters )
206
{
207
portTickType xDelayPeriod = mainCHECK_PERIOD;
208
portTickType xLastWakeTime;
209
 
210
        /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
211
        functions correctly. */
212
        xLastWakeTime = xTaskGetTickCount();
213
 
214
        for( ;; )
215
        {
216
                /* Delay until it is time to execute again.  The delay period is
217
                shorter following an error. */
218
                vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
219
 
220
                /* Check all the demo application tasks are executing without
221
                error. If an error is found the delay period is shortened - this
222
                has the effect of increasing the flash rate of the 'check' task
223
                LED. */
224
                if( prvCheckOtherTasksAreStillRunning() == pdFAIL )
225
                {
226
                        /* An error has been detected in one of the tasks - flash faster. */
227
                        xDelayPeriod = mainERROR_CHECK_PERIOD;
228
                }
229
 
230
                /* Toggle the LED each cycle round. */
231
                vParTestToggleLED( mainCHECK_TASK_LED );
232
        }
233
}
234
/*-----------------------------------------------------------*/
235
 
236
static long prvCheckOtherTasksAreStillRunning( void )
237
{
238
portBASE_TYPE xAllTasksPassed = pdPASS;
239
 
240
        if( xArePollingQueuesStillRunning() != pdTRUE )
241
        {
242
                xAllTasksPassed = pdFAIL;
243
        }
244
 
245
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
246
        {
247
                xAllTasksPassed = pdFAIL;
248
        }
249
 
250
        if( xAreComTestTasksStillRunning() != pdTRUE )
251
        {
252
                xAllTasksPassed = pdFALSE;
253
        }
254
 
255
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
256
        {
257
                xAllTasksPassed = pdFALSE;
258
        }
259
 
260
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
261
        {
262
                xAllTasksPassed = pdFALSE;
263
        }
264
 
265
    if( xIsCreateTaskStillRunning() != pdTRUE )
266
    {
267
        xAllTasksPassed = pdFALSE;
268
    }
269
 
270
        /* Also check the status flag for the tasks defined within this function. */
271
        if( xLocalError != pdFALSE )
272
        {
273
                xAllTasksPassed = pdFAIL;
274
        }
275
 
276
        return xAllTasksPassed;
277
}
278
/*-----------------------------------------------------------*/
279
 
280
void vApplicationIdleHook( void )
281
{
282
/* This variable is effectively set to a constant so it is made volatile to
283
ensure the compiler does not just get rid of it. */
284
volatile long lValue;
285
 
286
        /* Keep performing a calculation and checking the result against a constant. */
287
 
288
        /* Perform the calculation.  This will store partial value in
289
        registers, resulting in a good test of the context switch mechanism. */
290
        lValue = intgCONST1;
291
        lValue += intgCONST2;
292
        lValue *= intgCONST3;
293
        lValue /= intgCONST4;
294
 
295
        /* Did we perform the calculation correctly with no corruption? */
296
        if( lValue != intgEXPECTED_ANSWER )
297
        {
298
                /* Error! */
299
                portENTER_CRITICAL();
300
                        xLocalError = pdTRUE;
301
                portEXIT_CRITICAL();
302
        }
303
 
304
        /* Yield in case cooperative scheduling is being used. */
305
        #if configUSE_PREEMPTION == 0
306
        {
307
                taskYIELD();
308
        }
309
        #endif          
310
}
311
/*-----------------------------------------------------------*/
312
 

powered by: WebSVN 2.1.0

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