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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [PIC18_WizC/] [Demo2/] [main.c] - Blame information for rev 587

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 587 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
Changes from V3.0.0
56
 
57
Changes from V3.0.1
58
*/
59
 
60
/*
61
 * Instead of the normal single demo application, the PIC18F demo is split
62
 * into several smaller programs of which this is the second.  This enables the
63
 * demo's to be executed on the RAM limited PIC-devices.
64
 *
65
 * The Demo2 project is configured for a PIC18F4620 device.  Main.c starts 12
66
 * tasks (including the idle task). See the indicated files in the demo/common
67
 * directory for more information.
68
 *
69
 * demo/common/minimal/integer.c:       Creates 1 task
70
 * demo/common/minimal/PollQ.c:         Creates 2 tasks
71
 * demo/common/minimal/semtest.c:       Creates 4 tasks
72
 * demo/common/minimal/flash.c:         Creates 3 tasks
73
 *
74
 * Main.c also creates a check task.  This periodically checks that all the
75
 * other tasks are still running and have not experienced any unexpected
76
 * results.  If all the other tasks are executing correctly an LED is flashed
77
 * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not
78
 * executed, or report an error, the frequency of the LED flash will increase
79
 * to mainERROR_FLASH_RATE.
80
 *
81
 * On entry to main an 'X' is transmitted.  Monitoring the serial port using a
82
 * dumb terminal allows for verification that the device is not continuously
83
 * being reset (no more than one 'X' should be transmitted).
84
 *
85
 * http://www.FreeRTOS.org contains important information on the use of the
86
 * wizC PIC18F port.
87
 */
88
 
89
/* Scheduler include files. */
90
#include <FreeRTOS.h>
91
#include <task.h>
92
 
93
/* Demo app include files. */
94
#include "integer.h"
95
#include "PollQ.h"
96
#include "semtest.h"
97
#include "flash.h"
98
#include "partest.h"
99
#include "serial.h"
100
 
101
/* The period between executions of the check task before and after an error
102
has been discovered.  If an error has been discovered the check task runs
103
more frequently - increasing the LED flash rate. */
104
#define mainNO_ERROR_CHECK_PERIOD       ( ( portTickType ) 10000 / portTICK_RATE_MS )
105
#define mainERROR_CHECK_PERIOD          ( ( portTickType )  1000 / portTICK_RATE_MS )
106
#define mainCHECK_TASK_LED                      ( ( unsigned char ) 3 )
107
 
108
/* Priority definitions for some of the tasks.  Other tasks just use the idle
109
priority. */
110
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 3 )
111
#define mainLED_FLASH_PRIORITY  ( tskIDLE_PRIORITY + ( unsigned char ) 2 )
112
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
113
#define mainSEM_TEST_PRIORITY   ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
114
#define mainINTEGER_PRIORITY    ( tskIDLE_PRIORITY + ( unsigned char ) 0 )
115
 
116
/* Constants required for the communications.  Only one character is ever
117
transmitted. */
118
#define mainCOMMS_QUEUE_LENGTH          ( ( unsigned char ) 5 )
119
#define mainNO_BLOCK                            ( ( portTickType ) 0 )
120
#define mainBAUD_RATE                           ( ( unsigned long ) 57600 )
121
 
122
/*
123
 * The task function for the "Check" task.
124
 */
125
static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
126
 
127
/*
128
 * Checks the unique counts of other tasks to ensure they are still operational.
129
 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
130
 */
131
static char prvCheckOtherTasksAreStillRunning( void );
132
 
133
/*-----------------------------------------------------------*/
134
 
135
/* Creates the tasks, then starts the scheduler. */
136
void main( void )
137
{
138
        /* Initialise the required hardware. */
139
        vParTestInitialise();
140
 
141
        /* Send a character so we have some visible feedback of a reset. */
142
        xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
143
        xSerialPutChar( NULL, 'X', mainNO_BLOCK );
144
 
145
        /* Start a few of the standard demo tasks found in the demo\common directory. */
146
        vStartIntegerMathTasks( mainINTEGER_PRIORITY);
147
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
148
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
149
        vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
150
 
151
        /* Start the check task defined in this file. */
152
        xTaskCreate( vErrorChecks, ( const char * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
153
 
154
        /* Start the scheduler.  Will never return here. */
155
        vTaskStartScheduler();
156
 
157
        while(1)        /* This point should never be reached. */
158
        {
159
        }
160
}
161
/*-----------------------------------------------------------*/
162
 
163
static portTASK_FUNCTION( vErrorChecks, pvParameters )
164
{
165
portTickType xLastCheckTime;
166
portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
167
char cErrorOccurred;
168
 
169
        /* We need to initialise xLastCheckTime prior to the first call to
170
        vTaskDelayUntil(). */
171
        xLastCheckTime = xTaskGetTickCount();
172
 
173
        /* Cycle for ever, delaying then checking all the other tasks are still
174
        operating without error. */
175
        for( ;; )
176
        {
177
                /* Wait until it is time to check the other tasks again. */
178
                vTaskDelayUntil( &xLastCheckTime, xDelayTime );
179
 
180
                /* Check all the other tasks are running, and running without ever
181
                having an error. */
182
                cErrorOccurred = prvCheckOtherTasksAreStillRunning();
183
 
184
                /* If an error was detected increase the frequency of the LED flash. */
185
                if( cErrorOccurred == pdTRUE )
186
                {
187
                        xDelayTime = mainERROR_CHECK_PERIOD;
188
                }
189
 
190
                /* Flash the LED for visual feedback. */
191
                vParTestToggleLED( mainCHECK_TASK_LED );
192
        }
193
}
194
/*-----------------------------------------------------------*/
195
 
196
static char prvCheckOtherTasksAreStillRunning( void )
197
{
198
        char cErrorHasOccurred = ( char ) pdFALSE;
199
 
200
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
201
        {
202
                cErrorHasOccurred = ( char ) pdTRUE;
203
        }
204
 
205
        if( xArePollingQueuesStillRunning() != pdTRUE )
206
        {
207
                cErrorHasOccurred = ( char ) pdTRUE;
208
        }
209
 
210
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
211
        {
212
                cErrorHasOccurred = ( char ) pdTRUE;
213
        }
214
 
215
        return cErrorHasOccurred;
216
}
217
/*-----------------------------------------------------------*/
218
 
219
 

powered by: WebSVN 2.1.0

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