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

Subversion Repositories openrisc

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

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
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
56
 * documentation provides more details of the standard demo application tasks.
57
 * In addition to the standard demo tasks, the following tasks and tests are
58
 * defined and/or created within this file:
59
 *
60
 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
61
 * using a free running timer to demonstrate the use of the
62
 * configKERNEL_INTERRUPT_PRIORITY configuration constant.  The interrupt
63
 * service routine measures the number of processor clocks that occur between
64
 * each interrupt - and in so doing measures the jitter in the interrupt
65
 * timing.  The maximum measured jitter time is latched in the usMaxJitter
66
 * variable, and displayed on the LCD by the 'Check' as described below.
67
 * The fast interrupt is configured and handled in the timer_test.c source
68
 * file.
69
 *
70
 * "LCD" task - the LCD task is a 'gatekeeper' task.  It is the only task that
71
 * is permitted to access the LCD directly.  Other tasks wishing to write a
72
 * message to the LCD send the message on a queue to the LCD task instead of
73
 * accessing the LCD themselves.  The LCD task just blocks on the queue waiting
74
 * for messages - waking and displaying the messages as they arrive.  The LCD
75
 * task is defined in lcd.c.
76
 *
77
 * "Check" task -  This only executes every three seconds but has the highest
78
 * priority so is guaranteed to get processor time.  Its main function is to
79
 * check that all the standard demo tasks are still operational.  Should any
80
 * unexpected behaviour within a demo task be discovered the 'check' task will
81
 * write "FAIL #n" to the LCD (via the LCD task).  If all the demo tasks are
82
 * executing with their expected behaviour then the check task writes the max
83
 * jitter time to the LCD (again via the LCD task), as described above.
84
 */
85
 
86
/* Standard includes. */
87
#include <stdio.h>
88
 
89
/* Scheduler includes. */
90
#include "FreeRTOS.h"
91
#include "task.h"
92
#include "queue.h"
93
#include "croutine.h"
94
 
95
/* Demo application includes. */
96
#include "BlockQ.h"
97
#include "crflash.h"
98
#include "blocktim.h"
99
#include "integer.h"
100
#include "comtest2.h"
101
#include "partest.h"
102
#include "lcd.h"
103
#include "timertest.h"
104
 
105
/* Demo task priorities. */
106
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
107
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
108
#define mainCOM_TEST_PRIORITY                           ( 2 )
109
 
110
/* The check task may require a bit more stack as it calls sprintf(). */
111
#define mainCHECK_TAKS_STACK_SIZE                       ( configMINIMAL_STACK_SIZE * 2 )
112
 
113
/* The execution period of the check task. */
114
#define mainCHECK_TASK_PERIOD                           ( ( portTickType ) 3000 / portTICK_RATE_MS )
115
 
116
/* The number of flash co-routines to create. */
117
#define mainNUM_FLASH_COROUTINES                        ( 5 )
118
 
119
/* Baud rate used by the comtest tasks. */
120
#define mainCOM_TEST_BAUD_RATE                          ( 19200 )
121
 
122
/* The LED used by the comtest tasks.  mainCOM_TEST_LED + 1 is also used.
123
See the comtest.c file for more information. */
124
#define mainCOM_TEST_LED                                        ( 6 )
125
 
126
/* The frequency at which the "fast interrupt test" interrupt will occur. */
127
#define mainTEST_INTERRUPT_FREQUENCY            ( 20000 )
128
 
129
/* The number of processor clocks we expect to occur between each "fast
130
interrupt test" interrupt. */
131
#define mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ( configCPU_CLOCK_HZ / mainTEST_INTERRUPT_FREQUENCY )
132
 
133
/* The number of nano seconds between each processor clock. */
134
#define mainNS_PER_CLOCK ( ( unsigned short ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
135
 
136
/* Dimension the buffer used to hold the value of the maximum jitter time when
137
it is converted to a string. */
138
#define mainMAX_STRING_LENGTH                           ( 20 )
139
 
140
/*-----------------------------------------------------------*/
141
 
142
/*
143
 * The check task as described at the top of this file.
144
 */
145
static void vCheckTask( void *pvParameters );
146
 
147
/*
148
 * Setup the processor ready for the demo.
149
 */
150
static void prvSetupHardware( void );
151
 
152
/*-----------------------------------------------------------*/
153
 
154
/* The queue used to send messages to the LCD task. */
155
static xQueueHandle xLCDQueue;
156
 
157
/*-----------------------------------------------------------*/
158
 
159
/*
160
 * Create the demo tasks then start the scheduler.
161
 */
162
int main( void )
163
{
164
        /* Configure any hardware required for this demo. */
165
        prvSetupHardware();
166
 
167
        /* Create the standard demo tasks. */
168
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
169
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
170
        vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
171
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
172
        vCreateBlockTimeTasks();
173
 
174
        /* Create the test tasks defined within this file. */
175
        xTaskCreate( vCheckTask, ( signed char * ) "Check", mainCHECK_TAKS_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
176
 
177
        /* Start the task that will control the LCD.  This returns the handle
178
        to the queue used to write text out to the task. */
179
        xLCDQueue = xStartLCDTask();
180
 
181
        /* Start the high frequency interrupt test. */
182
        vSetupTimerTest( mainTEST_INTERRUPT_FREQUENCY );
183
 
184
        /* Finally start the scheduler. */
185
        vTaskStartScheduler();
186
 
187
        /* Will only reach here if there is insufficient heap available to start
188
        the scheduler. */
189
        return 0;
190
}
191
/*-----------------------------------------------------------*/
192
 
193
static void prvSetupHardware( void )
194
{
195
        vParTestInitialise();
196
}
197
/*-----------------------------------------------------------*/
198
 
199
static void vCheckTask( void *pvParameters )
200
{
201
/* Used to wake the task at the correct frequency. */
202
portTickType xLastExecutionTime;
203
 
204
/* The maximum jitter time measured by the fast interrupt test. */
205
extern unsigned short usMaxJitter ;
206
 
207
/* Buffer into which the maximum jitter time is written as a string. */
208
static char cStringBuffer[ mainMAX_STRING_LENGTH ];
209
 
210
/* The message that is sent on the queue to the LCD task.  The first
211
parameter is the minimum time (in ticks) that the message should be
212
left on the LCD without being overwritten.  The second parameter is a pointer
213
to the message to display itself. */
214
xLCDMessage xMessage = { 0, cStringBuffer };
215
 
216
/* Set to pdTRUE should an error be detected in any of the standard demo tasks. */
217
unsigned short usErrorDetected = pdFALSE;
218
 
219
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
220
        works correctly. */
221
        xLastExecutionTime = xTaskGetTickCount();
222
 
223
        for( ;; )
224
        {
225
                /* Wait until it is time for the next cycle. */
226
                vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_PERIOD );
227
 
228
                /* Has an error been found in any of the standard demo tasks? */
229
 
230
                if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
231
                {
232
                        usErrorDetected = pdTRUE;
233
                        sprintf( cStringBuffer, "FAIL #1" );
234
                }
235
 
236
                if( xAreComTestTasksStillRunning() != pdTRUE )
237
                {
238
                        usErrorDetected = pdTRUE;
239
                        sprintf( cStringBuffer, "FAIL #2" );
240
                }
241
 
242
                if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
243
                {
244
                        usErrorDetected = pdTRUE;
245
                        sprintf( cStringBuffer, "FAIL #3" );
246
                }
247
 
248
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
249
                {
250
                        usErrorDetected = pdTRUE;
251
                        sprintf( cStringBuffer, "FAIL #4" );
252
                }
253
 
254
                if( usErrorDetected == pdFALSE )
255
                {
256
                        /* No errors have been discovered, so display the maximum jitter
257
                        timer discovered by the "fast interrupt test". */
258
                        sprintf( cStringBuffer, "%dns max jitter", ( short ) ( usMaxJitter - mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ) * mainNS_PER_CLOCK );
259
                }
260
 
261
                /* Send the message to the LCD gatekeeper for display. */
262
                xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
263
        }
264
}
265
/*-----------------------------------------------------------*/
266
 
267
void vApplicationIdleHook( void )
268
{
269
        /* Schedule the co-routines from within the idle task hook. */
270
        vCoRoutineSchedule();
271
}
272
/*-----------------------------------------------------------*/
273
 

powered by: WebSVN 2.1.0

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