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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 589 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
 * Main. c also creates a task called "Check".  This only executes every three
59
 * seconds but has the highest priority so is guaranteed to get processor time.
60
 * Its main function is to check that all the other tasks are still operational.
61
 * Each task that does not flash an LED maintains a unique count that is
62
 * incremented each time the task successfully completes its function.  Should
63
 * any error occur within such a task the count is permanently halted.  The
64
 * check task inspects the count of each task to ensure it has changed since
65
 * the last time the check task executed.  If all the count variables have
66
 * changed all the tasks are still executing error free, and the check task
67
 * toggles an LED.  Should any task contain an error at any time the LED toggle
68
 * will stop.
69
 *
70
 * The LED flash and communications test tasks do not maintain a count.
71
 */
72
 
73
/*
74
Changes from V1.2.0
75
 
76
        + Changed the baud rate for the serial test from 19200 to 57600.
77
 
78
Changes from V1.2.3
79
 
80
        + The integer and comtest tasks are now used when the cooperative scheduler
81
          is being used.  Previously they were only used with the preemptive
82
          scheduler.
83
 
84
Changes from V1.2.5
85
 
86
        + Set the baud rate to 38400.  This has a smaller error percentage with an
87
          8MHz clock (according to the manual).
88
 
89
Changes from V2.0.0
90
 
91
        + Delay periods are now specified using variables and constants of
92
          portTickType rather than unsigned long.
93
 
94
Changes from V2.6.1
95
 
96
        + The IAR and WinAVR AVR ports are now maintained separately.
97
 
98
Changes from V4.0.5
99
 
100
        + Modified to demonstrate the use of co-routines.
101
 
102
*/
103
 
104
#include <stdlib.h>
105
#include <string.h>
106
 
107
#ifdef GCC_MEGA_AVR
108
        /* EEPROM routines used only with the WinAVR compiler. */
109
        #include <avr/eeprom.h> 
110
#endif
111
 
112
/* Scheduler include files. */
113
#include "FreeRTOS.h"
114
#include "task.h"
115
#include "croutine.h"
116
 
117
/* Demo file headers. */
118
#include "PollQ.h"
119
#include "integer.h"
120
#include "serial.h"
121
#include "comtest.h"
122
#include "crflash.h"
123
#include "print.h"
124
#include "partest.h"
125
#include "regtest.h"
126
 
127
/* Priority definitions for most of the tasks in the demo application.  Some
128
tasks just use the idle priority. */
129
#define mainLED_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )
130
#define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )
131
#define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 2 )
132
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )
133
 
134
/* Baud rate used by the serial port tasks. */
135
#define mainCOM_TEST_BAUD_RATE                  ( ( unsigned long ) 38400 )
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                                ( 4 )
140
 
141
/* LED that is toggled by the check task.  The check task periodically checks
142
that all the other tasks are operating without error.  If no errors are found
143
the LED is toggled.  If an error is found at any time the LED is never toggles
144
again. */
145
#define mainCHECK_TASK_LED                              ( 7 )
146
 
147
/* The period between executions of the check task. */
148
#define mainCHECK_PERIOD                                ( ( portTickType ) 3000 / portTICK_RATE_MS  )
149
 
150
/* An address in the EEPROM used to count resets.  This is used to check that
151
the demo application is not unexpectedly resetting. */
152
#define mainRESET_COUNT_ADDRESS                 ( ( void * ) 0x50 )
153
 
154
/* The number of coroutines to create. */
155
#define mainNUM_FLASH_COROUTINES                ( 3 )
156
 
157
/*
158
 * The task function for the "Check" task.
159
 */
160
static void vErrorChecks( void *pvParameters );
161
 
162
/*
163
 * Checks the unique counts of other tasks to ensure they are still operational.
164
 * Flashes an LED if everything is okay.
165
 */
166
static void prvCheckOtherTasksAreStillRunning( void );
167
 
168
/*
169
 * Called on boot to increment a count stored in the EEPROM.  This is used to
170
 * ensure the CPU does not reset unexpectedly.
171
 */
172
static void prvIncrementResetCount( void );
173
 
174
/*
175
 * The idle hook is used to scheduler co-routines.
176
 */
177
void vApplicationIdleHook( void );
178
 
179
/*-----------------------------------------------------------*/
180
 
181
short main( void )
182
{
183
        prvIncrementResetCount();
184
 
185
        /* Setup the LED's for output. */
186
        vParTestInitialise();
187
 
188
        /* Create the standard demo tasks. */
189
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
190
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
191
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
192
        vStartRegTestTasks();
193
 
194
        /* Create the tasks defined within this file. */
195
        xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
196
 
197
        /* Create the co-routines that flash the LED's. */
198
        vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
199
 
200
        /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
201
        as 1 in portmacro.h.  To use the cooperative scheduler define
202
        configUSE_PREEMPTION as 0. */
203
        vTaskStartScheduler();
204
 
205
        return 0;
206
}
207
/*-----------------------------------------------------------*/
208
 
209
static void vErrorChecks( void *pvParameters )
210
{
211
static volatile unsigned long ulDummyVariable = 3UL;
212
 
213
        /* The parameters are not used. */
214
        ( void ) pvParameters;
215
 
216
        /* Cycle for ever, delaying then checking all the other tasks are still
217
        operating without error. */
218
        for( ;; )
219
        {
220
                vTaskDelay( mainCHECK_PERIOD );
221
 
222
                /* Perform a bit of 32bit maths to ensure the registers used by the
223
                integer tasks get some exercise. The result here is not important -
224
                see the demo application documentation for more info. */
225
                ulDummyVariable *= 3;
226
 
227
                prvCheckOtherTasksAreStillRunning();
228
        }
229
}
230
/*-----------------------------------------------------------*/
231
 
232
static void prvCheckOtherTasksAreStillRunning( void )
233
{
234
static portBASE_TYPE xErrorHasOccurred = pdFALSE;
235
 
236
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
237
        {
238
                xErrorHasOccurred = pdTRUE;
239
        }
240
 
241
        if( xAreComTestTasksStillRunning() != pdTRUE )
242
        {
243
                xErrorHasOccurred = pdTRUE;
244
        }
245
 
246
        if( xArePollingQueuesStillRunning() != pdTRUE )
247
        {
248
                xErrorHasOccurred = pdTRUE;
249
        }
250
 
251
        if( xAreRegTestTasksStillRunning() != pdTRUE )
252
        {
253
                xErrorHasOccurred = pdTRUE;
254
        }
255
 
256
        if( xErrorHasOccurred == pdFALSE )
257
        {
258
                /* Toggle the LED if everything is okay so we know if an error occurs even if not
259
                using console IO. */
260
                vParTestToggleLED( mainCHECK_TASK_LED );
261
        }
262
}
263
/*-----------------------------------------------------------*/
264
 
265
static void prvIncrementResetCount( void )
266
{
267
unsigned char ucCount;
268
 
269
        eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
270
        ucCount++;
271
        eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
272
}
273
/*-----------------------------------------------------------*/
274
 
275
void vApplicationIdleHook( void )
276
{
277
        vCoRoutineSchedule();
278
}
279
 

powered by: WebSVN 2.1.0

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