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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MB96340_Softune/] [FreeRTOS_96348hs_SK16FX100PMC/] [Src/] [main.c] - Blame information for rev 867

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 demo application tasks.
57
 *
58
 * In addition to the standard demo tasks, the follow demo specific tasks are
59
 * create:
60
 *
61
 * The "Check" task.  This only executes every three seconds but has the highest
62
 * priority so is guaranteed to get processor time.  Its main function is to
63
 * check that all the other tasks are still operational.  Most tasks maintain
64
 * a unique count that is incremented each time the task successfully completes
65
 * its function.  Should any error occur within such a task the count is
66
 * permanently halted.  The check task inspects the count of each task to ensure
67
 * it has changed since the last time the check task executed.  If all the count
68
 * variables have changed all the tasks are still executing error free, and the
69
 * check task toggles the onboard LED.  Should any task contain an error at any time
70
 * the LED toggle rate will change from 3 seconds to 500ms.
71
 *
72
 * The "Trace Utility" task.  This can be used to obtain trace and debug
73
 * information via UART1.
74
 */
75
 
76
 
77
/* Scheduler includes. */
78
#include "FreeRTOS.h"
79
#include "task.h"
80
#include "semphr.h"
81
 
82
/* Demo application includes. */
83
#include "flash.h"
84
#include "integer.h"
85
#include "comtest2.h"
86
#include "PollQ.h"
87
#include "semtest.h"
88
#include "BlockQ.h"
89
#include "dynamic.h"
90
#include "flop.h"
91
#include "GenQTest.h"
92
#include "QPeek.h"
93
#include "blocktim.h"
94
#include "death.h"
95
#include "taskutility.h"
96
#include "partest.h"
97
#include "crflash.h"
98
#include "watchdog.h"
99
 
100
/* Library includes. */
101
#include <watchdog.h>
102
 
103
/*-----------------------------------------------------------*/
104
 
105
/* Demo task priorities. */
106
#define WTC_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 5 )
107
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
108
#define TASK_UTILITY_PRIORITY           ( tskIDLE_PRIORITY )
109
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )
110
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
111
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
112
#define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 2 )
113
#define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )
114
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
115
#define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )
116
 
117
/* Baud rate used by the COM test tasks. */
118
#define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 19200 )
119
 
120
/* The frequency at which the 'Check' tasks executes.  See the comments at the
121
top of the page.  When the system is operating error free the 'Check' task
122
toggles an LED every three seconds.  If an error is discovered in any task the
123
rate is increased to 500 milliseconds.  [in this case the '*' characters on the
124
LCD represent LED's] */
125
#define mainNO_ERROR_CHECK_DELAY        ( (portTickType) 3000 / portTICK_RATE_MS )
126
#define mainERROR_CHECK_DELAY           ( (portTickType) 500 / portTICK_RATE_MS )
127
 
128
/* LED assignments for the demo tasks. */
129
#define mainNUM_FLASH_CO_ROUTINES       8
130
#define mainCOM_TEST_LED                        0x05
131
#define mainCHECK_TEST_LED                      0x07
132
 
133
/*-----------------------------------------------------------*/
134
 
135
/*
136
 * The function that implements the Check task.  See the comments at the head
137
 * of the page for implementation details.
138
 */
139
static void     vErrorChecks( void *pvParameters );
140
 
141
/*
142
 * Called by the Check task.  Returns pdPASS if all the other tasks are found
143
 * to be operating without error - otherwise returns pdFAIL.
144
 */
145
static short prvCheckOtherTasksAreStillRunning( void );
146
 
147
/*
148
 * Perform any hardware setup necessary for the demo.
149
 */
150
static void prvSetupHardware( void );
151
 
152
/*-----------------------------------------------------------*/
153
 
154
void main( void )
155
{
156
        InitIrqLevels();                /* Initialize interrupts */
157
        __set_il( 7 );                  /* Allow all levels      */
158
 
159
        prvSetupHardware();
160
 
161
        #if WATCHDOG == WTC_IN_TASK
162
                vStartWatchdogTask( WTC_TASK_PRIORITY );
163
        #endif
164
 
165
        /* Start the standard demo application tasks. */
166
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
167
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
168
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
169
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
170
        vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
171
        vStartDynamicPriorityTasks();
172
        vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
173
        vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
174
        vCreateBlockTimeTasks();
175
 
176
        /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
177
        #if INCLUDE_TraceListTasks == 1
178
                vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
179
        #else
180
                vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
181
        #endif
182
 
183
        /* Start the 'Check' task which is defined in this file. */
184
        xTaskCreate( vErrorChecks, (signed char *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
185
 
186
        /* The suicide tasks must be started last as they record the number of other
187
        tasks that exist within the system.  The value is then used to ensure at run
188
        time the number of tasks that exists is within expected bounds. */
189
        vCreateSuicidalTasks( mainDEATH_PRIORITY );
190
 
191
        /* Now start the scheduler.  Following this call the created tasks should
192
        be executing. */
193
        vTaskStartScheduler( );
194
 
195
        /* vTaskStartScheduler() will only return if an error occurs while the
196
        idle task is being created. */
197
        for( ;; );
198
}
199
/*-----------------------------------------------------------*/
200
 
201
static void prvSetupHardware( void )
202
{
203
        /* Initialise the port used by the LEDs. */
204
        vParTestInitialise();
205
 
206
        /* See watchdog.h for definitions relating to the watchdog use. */
207
        #if WATCHDOG != WTC_NONE
208
                InitWatchdog();
209
        #endif
210
}
211
/*-----------------------------------------------------------*/
212
 
213
static void vErrorChecks( void *pvParameters )
214
{
215
portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
216
 
217
        /* Just to remove compiler warnings. */
218
        ( void ) pvParameters;
219
 
220
        /* Cycle for ever, delaying then checking all the other tasks are still
221
        operating without error. */
222
        for( ;; )
223
        {
224
                /* Wait until it is time to check again.  The time we wait here depends
225
                on whether an error has been detected or not.  When an error is
226
                detected the time is shortened resulting in a faster LED flash rate. */
227
                vTaskDelay( xDelayPeriod );
228
 
229
                /* See if the other tasks are all ok. */
230
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
231
                {
232
                        /* An error occurred in one of the tasks so shorten the delay
233
                        period - which has the effect of increasing the frequency of the
234
                        LED toggle. */
235
                        xDelayPeriod = mainERROR_CHECK_DELAY;
236
                }
237
 
238
                /* Flash! */
239
                vParTestToggleLED( mainCHECK_TEST_LED );
240
        }
241
}
242
/*-----------------------------------------------------------*/
243
 
244
static short prvCheckOtherTasksAreStillRunning( void )
245
{
246
        static short    sNoErrorFound = pdTRUE;
247
 
248
        /* The demo tasks maintain a count that increments every cycle of the task
249
        provided that the task has never encountered an error.  This function
250
        checks the counts maintained by the tasks to ensure they are still being
251
        incremented.  A count remaining at the same value between calls therefore
252
        indicates that an error has been detected.  Only tasks that do not flash
253
        an LED are checked. */
254
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
255
        {
256
                sNoErrorFound = pdFALSE;
257
        }
258
 
259
        if( xArePollingQueuesStillRunning() != pdTRUE )
260
        {
261
                sNoErrorFound = pdFALSE;
262
        }
263
 
264
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
265
        {
266
                sNoErrorFound = pdFALSE;
267
        }
268
 
269
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
270
        {
271
                sNoErrorFound = pdFALSE;
272
        }
273
 
274
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
275
        {
276
                sNoErrorFound = pdFALSE;
277
        }
278
 
279
        if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
280
        {
281
                sNoErrorFound = pdFALSE;
282
        }
283
 
284
        if( xAreGenericQueueTasksStillRunning() != pdTRUE )
285
        {
286
                sNoErrorFound = pdFALSE;
287
        }
288
 
289
        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
290
        {
291
                sNoErrorFound = pdFALSE;
292
        }
293
 
294
        if( xIsCreateTaskStillRunning() != pdTRUE )
295
        {
296
                sNoErrorFound = pdFALSE;
297
        }
298
 
299
        #if INCLUDE_TraceListTasks == 0
300
        {
301
                if( xAreComTestTasksStillRunning() != pdTRUE )
302
                {
303
                        sNoErrorFound = pdFALSE;
304
                }
305
        }
306
        #endif
307
 
308
        return sNoErrorFound;
309
}
310
/*-----------------------------------------------------------*/
311
 
312
/* Idle hook function. */
313
#if configUSE_IDLE_HOOK == 1
314
        void vApplicationIdleHook( void )
315
        {
316
                /* Are we using the idle task to kick the watchdog?  See watchdog.h
317
                for watchdog kicking options. Note this is for demonstration only
318
                and is not a suggested method of servicing the watchdog in a real
319
                application. */
320
                #if WATCHDOG == WTC_IN_IDLE
321
                        Kick_Watchdog();
322
                #endif
323
 
324
                vCoRoutineSchedule();
325
        }
326
#else
327
        #if WATCHDOG == WTC_IN_IDLE
328
                #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
329
        #endif
330
#endif
331
 
332
/*-----------------------------------------------------------*/
333
 
334
/* Tick hook function. */
335
#if configUSE_TICK_HOOK == 1
336
        void vApplicationTickHook( void )
337
        {
338
                /* Are we using the tick to kick the watchdog?  See watchdog.h
339
                for watchdog kicking options.  Note this is for demonstration
340
                only and is not a suggested method of servicing the watchdog in
341
                a real application. */
342
                #if WATCHDOG == WTC_IN_TICK
343
                        Kick_Watchdog();
344
                #endif
345
        }
346
#else
347
        #if WATCHDOG == WTC_IN_TICK
348
                #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
349
        #endif
350
#endif
351
/*-----------------------------------------------------------*/

powered by: WebSVN 2.1.0

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