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

Subversion Repositories openrisc

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

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
 * THIS DEMO APPLICATION REQUIRES A LOOPBACK CONNECTOR TO BE FITTED TO THE PIC
56
 * USART PORT - connect pin 2 to pin 3 on J2.
57
 *
58
 * Instead of the normal single demo application, the PIC18F demo is split
59
 * into several smaller programs of which this is the third.  This enables the
60
 * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin
61
 * devices require a more costly development platform and are not so readily
62
 * available.
63
 *
64
 * The RTOSDemo3 project is configured for a PIC18F452 device.  Main3.c starts
65
 * 5 tasks (including the idle task).
66
 *
67
 * The first task repeatedly transmits a string of characters on the PIC USART
68
 * port.  The second task receives the characters, checking that the correct
69
 * sequence is maintained (i.e. what is transmitted is identical to that
70
 * received).  Each transmitted and each received character causes an LED to
71
 * flash.  See demo/common/minimal/comtest. c for more information.
72
 *
73
 * The third task continuously performs a 32 bit calculation.  This is a good
74
 * test of the context switch mechanism as the 8 bit architecture requires
75
 * the use of several file registers to perform the 32 bit operations.  See
76
 * demo/common/minimal/integer. c for more information.
77
 *
78
 * The third task is the check task.  This periodically checks that the other
79
 * tasks are still running and have not experienced any errors.  If no errors
80
 * have been reported by either the comms or integer tasks an LED is flashed
81
 * with a frequency mainNO_ERROR_CHECK_PERIOD.  If an error is discovered the
82
 * frequency is increased to mainERROR_FLASH_RATE.
83
 *
84
 * The check task also provides a visual indication of a system reset by
85
 * flashing the one remaining LED (mainRESET_LED) when it starts.  After
86
 * this initial flash mainRESET_LED should remain off.
87
 *
88
 * http://www.FreeRTOS.org contains important information on the use of the
89
 * PIC18F port.
90
 */
91
 
92
/*
93
Changes from V2.0.0
94
 
95
        + Delay periods are now specified using variables and constants of
96
          portTickType rather than unsigned long.
97
*/
98
 
99
/* Scheduler include files. */
100
#include "FreeRTOS.h"
101
#include "task.h"
102
 
103
/* Demo app include files. */
104
#include "partest.h"
105
#include "serial.h"
106
#include "comtest.h"
107
#include "integer.h"
108
 
109
/* Priority definitions for the LED tasks.  Other tasks just use the idle
110
priority. */
111
#define mainCOMM_TEST_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 2 )
112
#define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 3 )
113
 
114
/* The period between executions of the check task before and after an error
115
has been discovered.  If an error has been discovered the check task runs
116
more frequently - increasing the LED flash rate. */
117
#define mainNO_ERROR_CHECK_PERIOD               ( ( portTickType ) 1000 / portTICK_RATE_MS )
118
#define mainERROR_CHECK_PERIOD                  ( ( portTickType ) 100 / portTICK_RATE_MS )
119
 
120
/* The period for which mainRESET_LED remain on every reset. */
121
#define mainRESET_LED_PERIOD                    ( ( portTickType ) 500 / portTICK_RATE_MS )
122
 
123
/* The LED that is toggled whenever a character is transmitted.
124
mainCOMM_TX_RX_LED + 1 will be toggled every time a character is received. */
125
#define mainCOMM_TX_RX_LED                              ( ( unsigned portBASE_TYPE ) 2 )
126
 
127
/* The LED that is flashed by the check task at a rate that indicates the
128
error status. */
129
#define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 1 )
130
 
131
/* The LED that is flashed once upon every reset. */
132
#define mainRESET_LED                                   ( ( unsigned portBASE_TYPE ) 0 )
133
 
134
/* Constants required for the communications. */
135
#define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )
136
#define mainBAUD_RATE                                   ( ( unsigned long ) 57600 )
137
/*-----------------------------------------------------------*/
138
 
139
/*
140
 * Task function which periodically checks the other tasks for errors.  Flashes
141
 * an LED at a rate that indicates whether an error has ever been detected.
142
 */
143
static void vErrorChecks( void *pvParameters );
144
 
145
/*-----------------------------------------------------------*/
146
 
147
/* Creates the tasks, then starts the scheduler. */
148
void main( void )
149
{
150
        /* Initialise the required hardware. */
151
        vParTestInitialise();
152
 
153
        /* Initialise the block memory allocator. */
154
        vPortInitialiseBlocks();
155
 
156
        /* Start the standard comtest tasks as defined in demo/common/minimal. */
157
        vAltStartComTestTasks( mainCOMM_TEST_PRIORITY, mainBAUD_RATE, mainCOMM_TX_RX_LED );
158
 
159
        /* Start the standard 32bit calculation task as defined in
160
        demo/common/minimal. */
161
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
162
 
163
        /* Start the check task defined in this file. */
164
        xTaskCreate( vErrorChecks, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
165
 
166
        /* Start the scheduler.  This will never return. */
167
        vTaskStartScheduler();
168
}
169
/*-----------------------------------------------------------*/
170
 
171
static void vErrorChecks( void *pvParameters )
172
{
173
portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
174
volatile unsigned long ulDummy = 3UL;
175
 
176
        /* Toggle the LED so we can see when a reset occurs. */
177
        vParTestSetLED( mainRESET_LED, pdTRUE );
178
        vTaskDelay( mainRESET_LED_PERIOD );
179
        vParTestSetLED( mainRESET_LED, pdFALSE );
180
 
181
        /* Cycle for ever, delaying then checking all the other tasks are still
182
        operating without error. */
183
        for( ;; )
184
        {
185
                /* Wait until it is time to check the other tasks. */
186
                vTaskDelay( xDelayTime );
187
 
188
                /* Perform an integer calculation - just to ensure the registers
189
                get used.  The result is not important. */
190
                ulDummy *= 3UL;
191
 
192
                /* Check all the other tasks are running, and running without ever
193
                having an error.  The delay period is lowered if an error is reported,
194
                causing the LED to flash at a higher rate. */
195
                if( xAreIntegerMathsTaskStillRunning() == pdFALSE )
196
                {
197
                        xDelayTime = mainERROR_CHECK_PERIOD;
198
                }
199
 
200
                if( xAreComTestTasksStillRunning() == pdFALSE )
201
                {
202
                        xDelayTime = mainERROR_CHECK_PERIOD;
203
                }
204
 
205
                /* Flash the LED for visual feedback.  The rate of the flash will
206
                indicate the health of the system. */
207
                vParTestToggleLED( mainCHECK_TASK_LED );
208
        }
209
}
210
/*-----------------------------------------------------------*/
211
 

powered by: WebSVN 2.1.0

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