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

Subversion Repositories openrisc

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 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
 * (which just exist to test the kernel port and provide an example of how to use
58
 * each FreeRTOS API function).
59
 *
60
 * In addition to the standard demo tasks, the following tasks and tests are
61
 * defined and/or created within this file:
62
 *
63
 * "LCD" task - the LCD task is a 'gatekeeper' task.  It is the only task that
64
 * is permitted to access the display directly.  Other tasks wishing to write a
65
 * message to the LCD send the message on a queue to the LCD task instead of
66
 * accessing the LCD themselves.  The LCD task just blocks on the queue waiting
67
 * for messages - waking and displaying the messages as they arrive.  The use
68
 * of a gatekeeper in this manner permits both tasks and interrupts to write to
69
 * the LCD without worrying about mutual exclusion.  This is demonstrated by the
70
 * check hook (see below) which sends messages to the display even though it
71
 * executes from an interrupt context.
72
 *
73
 * "Check" hook -  This only executes fully every five seconds from the tick
74
 * hook.  Its main function is to check that all the standard demo tasks are
75
 * still operational.  Should any unexpected behaviour be discovered within a
76
 * demo task then the tick hook will write an error to the LCD (via the LCD task).
77
 * If all the demo tasks are executing with their expected behaviour then the
78
 * check task writes PASS to the LCD (again via the LCD task), as described above.
79
 *
80
 */
81
 
82
/* Scheduler includes. */
83
#include "FreeRTOS.h"
84
#include "task.h"
85
#include "queue.h"
86
#include "semphr.h"
87
 
88
/* Demo app includes. */
89
#include "BlockQ.h"
90
#include "integer.h"
91
#include "blocktim.h"
92
#include "flash.h"
93
#include "partest.h"
94
#include "semtest.h"
95
#include "PollQ.h"
96
#include "lcd_message.h"
97
#include "GenQTest.h"
98
#include "QPeek.h"
99
#include "recmutex.h"
100
#include "flash.h"
101
#include "comtest2.h"
102
 
103
/* Atmel library includes. */
104
#include <board.h>
105
#include <lcd/color.h>
106
#include <lcd/lcdd.h>
107
#include <lcd/draw.h>
108
 
109
 
110
/*-----------------------------------------------------------*/
111
 
112
/* The time between cycles of the 'check' functionality (defined within the
113
tick hook). */
114
#define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
115
 
116
/* The LCD task uses the sprintf function so requires a little more stack too. */
117
#define mainLCD_TASK_STACK_SIZE                         ( configMINIMAL_STACK_SIZE * 2 )
118
 
119
/* Task priorities. */
120
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
121
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
122
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
123
#define mainLED_TASK_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
124
#define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
125
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
126
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
127
 
128
/* The maximum number of message that can be waiting for display at any one
129
time. */
130
#define mainLCD_QUEUE_SIZE                                      ( 3 )
131
 
132
/* Constants used by the comtest tasks.  There isn't a spare LED so an invalid
133
LED is specified. */
134
#define mainBAUD_RATE                                           ( 115200 )
135
#define mainCOM_TEST_LED                                        ( 10 )
136
 
137
/*-----------------------------------------------------------*/
138
 
139
/*
140
 * Configure the hardware for the demo.
141
 */
142
static void prvSetupHardware( void );
143
 
144
/*
145
 * The LCD gatekeeper task.  Tasks wishing to write to the LCD do not access
146
 * the LCD directly, but instead send the message to the LCD gatekeeper task.
147
 */
148
static void prvLCDTask( void *pvParameters );
149
 
150
/*
151
 * Hook functions that can get called by the kernel.  The 'check' functionality
152
 * is implemented within the tick hook.
153
 */
154
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );
155
 
156
/*
157
 * The tick hook function as described in the comments at the top of this file.
158
 * The tick hook is used to monitor all the standard demo tasks to look for
159
 * errors.  The tick hook is also used to demonstrate how the LCD gatekeeper
160
 * task can be used to allow interrupts to write to the LCD.
161
 */
162
void vApplicationTickHook( void );
163
 
164
 
165
/*-----------------------------------------------------------*/
166
 
167
/* The queue used to send messages to the LCD task. */
168
static xQueueHandle xLCDQueue;
169
 
170
/*-----------------------------------------------------------*/
171
 
172
int main( void )
173
{
174
        /* Prepare the hardware. */
175
        prvSetupHardware();
176
 
177
        /* Create the queue used by the LCD task.  Messages for display on the LCD
178
        are received via this queue. */
179
        xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) );
180
 
181
        /* Start the standard demo tasks.  These do nothing other than test the
182
        port and provide some APU usage examples. */
183
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
184
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
185
        vStartRecursiveMutexTasks();
186
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
187
        vCreateBlockTimeTasks();
188
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
189
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
190
        vStartQueuePeekTasks();
191
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
192
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_TEST_LED );
193
 
194
        /* Start the tasks defined within this file/specific to this demo. */
195
        xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
196
 
197
        /* Start the scheduler. */
198
        vTaskStartScheduler();
199
 
200
    /* Will only get here if there was insufficient memory to create the idle
201
    task. */
202
        return 0;
203
}
204
/*-----------------------------------------------------------*/
205
 
206
void prvSetupHardware( void )
207
{
208
        /* Initialise the port used for the LED outputs. */
209
        vParTestInitialise();
210
}
211
/*-----------------------------------------------------------*/
212
 
213
void vApplicationTickHook( void )
214
{
215
static xLCDMessage xMessage = { "PASS" };
216
static unsigned long ulTicksSinceLastDisplay = 0;
217
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
218
 
219
        /* Called from every tick interrupt.  Have enough ticks passed to make it
220
        time to perform our health status check again? */
221
        ulTicksSinceLastDisplay++;
222
        if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
223
        {
224
                ulTicksSinceLastDisplay = 0;
225
 
226
                /* Has an error been found in any task? */
227
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
228
                {
229
                        xMessage.pcMessage = "ERROR IN GEN Q";
230
                }
231
            if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
232
            {
233
                xMessage.pcMessage = "ERROR IN MATH";
234
            }
235
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )
236
                {
237
                        xMessage.pcMessage = "ERROR IN BLOCK Q";
238
                }
239
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
240
                {
241
                        xMessage.pcMessage = "ERROR IN BLOCK TIME";
242
                }
243
                else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
244
                {
245
                        xMessage.pcMessage = "ERROR IN SEMAPHORE";
246
                }
247
                else if( xArePollingQueuesStillRunning() != pdTRUE )
248
                {
249
                        xMessage.pcMessage = "ERROR IN POLL Q";
250
                }
251
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
252
                {
253
                        xMessage.pcMessage = "ERROR IN PEEK Q";
254
                }
255
                else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
256
                {
257
                        xMessage.pcMessage = "ERROR IN REC MUTEX";
258
                }
259
                else if( xAreComTestTasksStillRunning() != pdTRUE )
260
                {
261
                        xMessage.pcMessage = "ERROR IN COMTEST";
262
                }
263
 
264
                /* Send the message to the LCD gatekeeper for display. */
265
                xHigherPriorityTaskWoken = pdFALSE;
266
                xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
267
        }
268
}
269
/*-----------------------------------------------------------*/
270
 
271
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
272
{
273
        ( void ) pxTask;
274
        ( void ) pcTaskName;
275
 
276
        /* If the parameters have been corrupted then inspect pxCurrentTCB to
277
        identify which task has overflowed its stack. */
278
        for( ;; );
279
}
280
/*-----------------------------------------------------------*/
281
 
282
static void prvLCDTask( void *pvParameters )
283
{
284
xLCDMessage xMessage;
285
unsigned long ulY = 0;
286
const unsigned long ulX = 5;
287
const unsigned long ulMaxY = 250, ulYIncrement = 22, ulWidth = 250, ulHeight = 20;;
288
 
289
    /* Initialize LCD. */
290
    LCDD_Initialize();
291
    LCDD_Start();
292
        LCDD_Fill( ( void * ) BOARD_LCD_BASE, COLOR_WHITE );
293
        LCDD_DrawString( ( void * ) BOARD_LCD_BASE, 1, ulY + 3, "  www.FreeRTOS.org", COLOR_BLACK );
294
 
295
        for( ;; )
296
        {
297
                /* Wait for a message from the check function (which is executed in
298
                the tick hook). */
299
                xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY );
300
 
301
                /* Clear the space where the old message was. */
302
        LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_WHITE );
303
 
304
                /* Increment to the next drawing position. */
305
                ulY += ulYIncrement;
306
 
307
                /* Have the Y position moved past the end of the LCD? */
308
                if( ulY >= ulMaxY )
309
                {
310
                        ulY = 0;
311
                }
312
 
313
                /* Draw a new rectangle, in which the message will be written. */
314
        LCDD_DrawRectangle( ( void * ) BOARD_LCD_BASE, 0, ulY, ulWidth, ulHeight, COLOR_GREEN );
315
 
316
                /* Write the message. */
317
        LCDD_DrawString( ( void * ) BOARD_LCD_BASE, ulX, ulY + 3, xMessage.pcMessage, COLOR_BLACK );
318
        }
319
}

powered by: WebSVN 2.1.0

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