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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [PIC18_MPLAB/] [main2.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
 * Instead of the normal single demo application, the PIC18F demo is split
56
 * into several smaller programs of which this is the second.  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 RTOSDemo2 project is configured for a PIC18F452 device.  Main2.c starts
62
 * 5 tasks (including the idle task).
63
 *
64
 * The first, second and third tasks do nothing but flash an LED.  This gives
65
 * visual feedback that everything is executing as expected.  One task flashes
66
 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
67
 * and the last every 999ms.
68
 *
69
 * The last task runs at the idle priority.  It repeatedly performs a 32bit
70
 * calculation and checks it's result against the expected value.  This checks
71
 * that the temporary storage utilised by the compiler to hold intermediate
72
 * results does not get corrupted when the task gets switched in and out.
73
 * should the calculation ever provide an incorrect result the final LED is
74
 * turned on.
75
 *
76
 * On entry to main() an 'X' is transmitted.  Monitoring the serial port using a
77
 * dumb terminal allows for verification that the device is not continuously
78
 * being reset (no more than one 'X' should be transmitted).
79
 *
80
 * http://www.FreeRTOS.org contains important information on the use of the
81
 * PIC18F port.
82
 */
83
 
84
/*
85
Changes from V2.0.0
86
 
87
        + Delay periods are now specified using variables and constants of
88
          portTickType rather than unsigned long.
89
*/
90
 
91
/* Scheduler include files. */
92
#include "FreeRTOS.h"
93
#include "task.h"
94
 
95
/* Demo app include files. */
96
#include "flash.h"
97
#include "partest.h"
98
#include "serial.h"
99
 
100
/* Priority definitions for the LED tasks.  Other tasks just use the idle
101
priority. */
102
#define mainLED_FLASH_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
103
 
104
/* The LED that is lit when should the calculation fail. */
105
#define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 3 )
106
 
107
/* Constants required for the communications.  Only one character is ever
108
transmitted. */
109
#define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )
110
#define mainNO_BLOCK                                    ( ( portTickType ) 0 )
111
#define mainBAUD_RATE                                   ( ( unsigned long ) 9600 )
112
 
113
/*
114
 * The task that performs the 32 bit calculation at the idle priority.
115
 */
116
static void vCalculationTask( void *pvParameters );
117
 
118
/*-----------------------------------------------------------*/
119
 
120
/* Creates the tasks, then starts the scheduler. */
121
void main( void )
122
{
123
        /* Initialise the required hardware. */
124
        vParTestInitialise();
125
        vPortInitialiseBlocks();
126
 
127
        /* Send a character so we have some visible feedback of a reset. */
128
        xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
129
        xSerialPutChar( NULL, 'X', mainNO_BLOCK );
130
 
131
        /* Start the standard LED flash tasks as defined in demo/common/minimal. */
132
        vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
133
 
134
        /* Start the check task defined in this file. */
135
        xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
136
 
137
        /* Start the scheduler. */
138
        vTaskStartScheduler();
139
}
140
/*-----------------------------------------------------------*/
141
 
142
static void vCalculationTask( void *pvParameters )
143
{
144
volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
145
 
146
        /* Continuously perform a calculation.  If the calculation result is ever
147
        incorrect turn the LED on. */
148
        for( ;; )
149
        {
150
                /* A good optimising compiler would just remove all this! */
151
                ulCalculatedValue = 1234UL;
152
                ulCalculatedValue *= 99UL;
153
 
154
                if( ulCalculatedValue != 122166UL )
155
                {
156
                        vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
157
                }
158
 
159
                ulCalculatedValue *= 9876UL;
160
 
161
                if( ulCalculatedValue != 1206511416UL )
162
                {
163
                        vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
164
                }
165
 
166
                ulCalculatedValue /= 15UL;
167
 
168
                if( ulCalculatedValue != 80434094UL )
169
                {
170
                        vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
171
                }
172
 
173
                ulCalculatedValue += 918273UL;
174
 
175
                if( ulCalculatedValue != 81352367UL )
176
                {
177
                        vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
178
                }
179
        }
180
}
181
/*-----------------------------------------------------------*/
182
 

powered by: WebSVN 2.1.0

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