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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [PIC18_MPLAB/] [main1.c] - Blame information for rev 622

Go to most recent revision | 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
 * Instead of the normal single demo application, the PIC18F demo is split
56
 * into several smaller programs of which this is the first.  This enables the
57
 * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin
58
 * devices require a more costly development platform and are not so readily
59
 * available.
60
 *
61
 * The RTOSDemo1 project is configured for a PIC18F452 device.  Main1.c starts 5
62
 * tasks (including the idle task).
63
 *
64
 * The first task runs at the idle priority.  It repeatedly performs a 32bit
65
 * calculation and checks it's result against the expected value.  This checks
66
 * that the temporary storage utilised by the compiler to hold intermediate
67
 * results does not get corrupted when the task gets switched in and out.  See
68
 * demo/common/minimal/integer.c for more information.
69
 *
70
 * The second and third tasks pass an incrementing value between each other on
71
 * a message queue.  See demo/common/minimal/PollQ.c for more information.
72
 *
73
 * Main1.c also creates a check task.  This periodically checks that all the
74
 * other tasks are still running and have not experienced any unexpected
75
 * results.  If all the other tasks are executing correctly an LED is flashed
76
 * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not
77
 * executed, or report and error, the frequency of the LED flash will increase
78
 * to mainERROR_FLASH_RATE.
79
 *
80
 * On entry to main an 'X' is transmitted.  Monitoring the serial port using a
81
 * dumb terminal allows for verification that the device is not continuously
82
 * being reset (no more than one 'X' should be transmitted).
83
 *
84
 * http://www.FreeRTOS.org contains important information on the use of the
85
 * PIC18F port.
86
 */
87
 
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
 
95
/* Scheduler include files. */
96
#include "FreeRTOS.h"
97
#include "task.h"
98
 
99
/* Demo app include files. */
100
#include "PollQ.h"
101
#include "integer.h"
102
#include "partest.h"
103
#include "serial.h"
104
 
105
/* The period between executions of the check task before and after an error
106
has been discovered.  If an error has been discovered the check task runs
107
more frequently - increasing the LED flash rate. */
108
#define mainNO_ERROR_CHECK_PERIOD               ( ( portTickType ) 1000 / portTICK_RATE_MS )
109
#define mainERROR_CHECK_PERIOD                  ( ( portTickType ) 100 / portTICK_RATE_MS )
110
 
111
/* Priority definitions for some of the tasks.  Other tasks just use the idle
112
priority. */
113
#define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 2 )
114
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )
115
 
116
/* The LED that is flashed by the check task. */
117
#define mainCHECK_TASK_LED                              ( 0 )
118
 
119
/* Constants required for the communications.  Only one character is ever
120
transmitted. */
121
#define mainCOMMS_QUEUE_LENGTH                  ( 5 )
122
#define mainNO_BLOCK                                    ( ( portTickType ) 0 )
123
#define mainBAUD_RATE                                   ( ( unsigned long ) 9600 )
124
 
125
/*
126
 * The task function for the "Check" task.
127
 */
128
static void vErrorChecks( void *pvParameters );
129
 
130
/*
131
 * Checks the unique counts of other tasks to ensure they are still operational.
132
 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
133
 */
134
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
135
 
136
/*-----------------------------------------------------------*/
137
 
138
/* Creates the tasks, then starts the scheduler. */
139
void main( void )
140
{
141
        /* Initialise the required hardware. */
142
        vParTestInitialise();
143
        vPortInitialiseBlocks();
144
 
145
        /* Send a character so we have some visible feedback of a reset. */
146
        xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
147
        xSerialPutChar( NULL, 'X', mainNO_BLOCK );
148
 
149
        /* Start the standard demo tasks found in the demo\common directory. */
150
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
151
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
152
 
153
        /* Start the check task defined in this file. */
154
        xTaskCreate( vErrorChecks, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
155
 
156
        /* Start the scheduler.  Will never return here. */
157
        vTaskStartScheduler();
158
}
159
/*-----------------------------------------------------------*/
160
 
161
static void vErrorChecks( void *pvParameters )
162
{
163
portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
164
portBASE_TYPE xErrorOccurred;
165
 
166
        /* Cycle for ever, delaying then checking all the other tasks are still
167
        operating without error. */
168
        for( ;; )
169
        {
170
                /* Wait until it is time to check the other tasks. */
171
                vTaskDelay( xDelayTime );
172
 
173
                /* Check all the other tasks are running, and running without ever
174
                having an error. */
175
                xErrorOccurred = prvCheckOtherTasksAreStillRunning();
176
 
177
                /* If an error was detected increase the frequency of the LED flash. */
178
                if( xErrorOccurred == pdTRUE )
179
                {
180
                        xDelayTime = mainERROR_CHECK_PERIOD;
181
                }
182
 
183
                /* Flash the LED for visual feedback. */
184
                vParTestToggleLED( mainCHECK_TASK_LED );
185
        }
186
}
187
/*-----------------------------------------------------------*/
188
 
189
static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
190
{
191
portBASE_TYPE xErrorHasOccurred = pdFALSE;
192
 
193
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
194
        {
195
                xErrorHasOccurred = pdTRUE;
196
        }
197
 
198
        if( xArePollingQueuesStillRunning() != pdTRUE )
199
        {
200
                xErrorHasOccurred = pdTRUE;
201
        }
202
 
203
        return xErrorHasOccurred;
204
}
205
/*-----------------------------------------------------------*/
206
 
207
 

powered by: WebSVN 2.1.0

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