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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 577 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 demo application tasks.
57
 *
58
 * In addition to the standard demo tasks there are two tasks defined within
59
 * this file:
60
 *
61
 * 1 - The check task
62
 * The 'check' task is responsible for ensuring that all the standard demo
63
 * tasks are executing as expected.  It only executes every three seconds, but
64
 * has the highest priority within the system so is guaranteed to get execution
65
 * time.  Any errors discovered by the check task are latched until the
66
 * processor is reset.  At the end of each cycle the check task sends either
67
 * a pass or fail message to the 'print' task for display on the LCD.
68
 *
69
 * 2 - The print task
70
 * The print task is the LCD 'gatekeeper'.  That is, it is the only task that
71
 * should access the LCD directly so is always guaranteed exclusive (and
72
 * therefore consistent) access.  The print task simply blocks on a queue
73
 * to wait for messages from other tasks wishing to display text on the LCD.
74
 * When a message arrives it displays its contents on the LCD then blocks to
75
 * wait again.
76
 */
77
 
78
/* ST includes. */
79
#include "lcd.h"
80
 
81
/* Kernel includes. */
82
#include "FreeRTOS.h"
83
#include "task.h"
84
#include "queue.h"
85
 
86
/* Demo application includes. */
87
#include "partest.h"
88
#include "flash.h"
89
#include "integer.h"
90
#include "blocktim.h"
91
#include "BlockQ.h"
92
#include "comtest2.h"
93
#include "dynamic.h"
94
 
95
/* Demo application task priorities. */
96
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
97
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
98
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
99
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
100
#define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
101
 
102
/* How often should we check the other tasks? */
103
#define mainCHECK_TASK_CYCLE_TIME       ( 3000 )
104
 
105
/* The maximum offset into the pass and fail strings sent to the LCD.  An
106
offset is used a simple method of using a different column each time a message
107
is written to the LCD. */
108
#define mainMAX_WRITE_COLUMN            ( 14 )
109
 
110
/* Baud rate used by the comtest tasks. */
111
#define mainCOM_TEST_BAUD_RATE          ( 19200 )
112
 
113
/* The LED used by the comtest tasks. See the comtest.c file for more
114
information. */
115
#define mainCOM_TEST_LED                        ( 3 )
116
 
117
/* The number of messages that can be queued for display on the LCD at any one
118
time. */
119
#define mainLCD_QUEUE_LENGTH            ( 2 )
120
 
121
/* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
122
#define mainNO_DELAY                            ( 0 )
123
 
124
/*-----------------------------------------------------------*/
125
 
126
/* The type that is posted to the LCD queue. */
127
typedef struct LCD_MESSAGE
128
{
129
        unsigned char *pucString; /* Points to the string to be displayed. */
130
        unsigned char ucLine;     /* The line of the LCD that should be used. */
131
} LCDMessage;
132
 
133
/*-----------------------------------------------------------*/
134
 
135
/*
136
 * The task that executes at the highest priority and checks the operation of
137
 * all the other tasks in the system.  See the description at the top of the
138
 * file.
139
 */
140
static void vCheckTask( void *pvParameters );
141
 
142
/*
143
 * ST provided routine to configure the processor.
144
 */
145
static void prvSetupHardware(void);
146
 
147
/*
148
 * The only task that should access the LCD.  Other tasks wanting to write
149
 * to the LCD should send a message of type LCDMessage containing the
150
 * information to display to the print task.  The print task simply blocks
151
 * waiting for the arrival of such messages, displays the message, then blocks
152
 * again.
153
 */
154
static void vPrintTask( void *pvParameters );
155
 
156
/*-----------------------------------------------------------*/
157
 
158
/* The queue used to communicate with the LCD print task. */
159
static xQueueHandle xLCDQueue;
160
 
161
/*-----------------------------------------------------------*/
162
 
163
/* Create all the demo application tasks, then start the scheduler. */
164
void main( void )
165
{
166
        /* Perform any hardware setup necessary. */
167
        prvSetupHardware();
168
        vParTestInitialise();
169
 
170
        /* Create the queue used to communicate with the LCD print task. */
171
        xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
172
 
173
        /* Create the standard demo application tasks.  See the WEB documentation
174
        for more information on these tasks. */
175
        vCreateBlockTimeTasks();
176
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
177
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
178
        vStartDynamicPriorityTasks();
179
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
180
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
181
 
182
        /* Create the tasks defined within this file. */
183
        xTaskCreate( vPrintTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
184
        xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
185
 
186
        vTaskStartScheduler();
187
 
188
        /* Execution will only reach here if there was insufficient heap to
189
        start the scheduler. */
190
}
191
/*-----------------------------------------------------------*/
192
 
193
static void vCheckTask( void *pvParameters )
194
{
195
static unsigned long ulErrorDetected = pdFALSE;
196
portTickType xLastExecutionTime;
197
unsigned char *cErrorMessage = "              FAIL";
198
unsigned char *cSuccessMessage = "              PASS";
199
unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
200
LCDMessage xMessage;
201
 
202
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
203
        works correctly. */
204
        xLastExecutionTime = xTaskGetTickCount();
205
 
206
        for( ;; )
207
        {
208
                /* Wait until it is time for the next cycle. */
209
                vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
210
 
211
                /* Has an error been found in any of the standard demo tasks? */
212
 
213
                if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
214
                {
215
                        ulErrorDetected = pdTRUE;
216
                }
217
 
218
                if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
219
                {
220
                        ulErrorDetected = pdTRUE;
221
                }
222
 
223
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
224
                {
225
                        ulErrorDetected = pdTRUE;
226
                }
227
 
228
                if( xAreComTestTasksStillRunning() != pdTRUE )
229
                {
230
                        ulErrorDetected = pdTRUE;
231
                }
232
 
233
                if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
234
                {
235
                        ulErrorDetected = pdTRUE;
236
                }
237
 
238
                /* Calculate the LCD line on which we would like the message to
239
                be displayed.  The column variable is used for convenience as
240
                it is incremented each cycle anyway. */
241
                xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
242
 
243
                /* The message displayed depends on whether an error was found or
244
                not.  Any discovered error is latched.  Here the column variable
245
                is used as an index into the text string as a simple way of moving
246
                the text from column to column. */
247
                if( ulErrorDetected == pdFALSE )
248
                {
249
                        xMessage.pucString = cSuccessMessage + uxColumn;
250
                }
251
                else
252
                {
253
                        xMessage.pucString = cErrorMessage + uxColumn;
254
                }
255
 
256
                /* Send the message to the print task for display. */
257
                xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
258
 
259
                /* Make sure the message is printed in a different column the next
260
                time around. */
261
                uxColumn--;
262
                if( uxColumn == 0 )
263
                {
264
                        uxColumn = mainMAX_WRITE_COLUMN;
265
                }
266
        }
267
}
268
/*-----------------------------------------------------------*/
269
 
270
static void vPrintTask( void *pvParameters )
271
{
272
LCDMessage xMessage;
273
 
274
        for( ;; )
275
        {
276
                /* Wait until a message arrives. */
277
                while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
278
 
279
                /* The message contains the text to display, and the line on which the
280
                text should be displayed. */
281
                LCD_Clear();
282
                LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
283
        }
284
}
285
/*-----------------------------------------------------------*/
286
 
287
static void prvSetupHardware(void)
288
{
289
ErrorStatus OSC4MStartUpStatus01;
290
 
291
        /* ST provided routine. */
292
 
293
        /* MRCC system reset */
294
        MRCC_DeInit();
295
 
296
        /* Wait for OSC4M start-up */
297
        OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
298
 
299
        if(OSC4MStartUpStatus01 == SUCCESS)
300
        {
301
                /* Set HCLK to 60MHz */
302
                MRCC_HCLKConfig(MRCC_CKSYS_Div1);
303
 
304
                /* Set CKTIM to 60MHz */
305
                MRCC_CKTIMConfig(MRCC_HCLK_Div1);
306
 
307
                /* Set PCLK to 30MHz */
308
                MRCC_PCLKConfig(MRCC_CKTIM_Div2);
309
 
310
                /* Enable Flash Burst mode */
311
                CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
312
 
313
                /* Set CK_SYS to 60 MHz */
314
                MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
315
        }
316
 
317
        /* GPIO pins optimized for 3V3 operation */
318
        MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
319
 
320
        /* GPIO clock source enable */
321
        MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
322
 
323
        /* EXTIT clock source enable */
324
        MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
325
        /* TB clock source enable */
326
        MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
327
 
328
        /* Initialize the demonstration menu */
329
        LCD_Init();
330
 
331
        LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
332
        LCD_DisplayString(Line2, "  STR750 Demo  ", BlackText);
333
 
334
        EIC_IRQCmd(ENABLE);
335
}
336
/*-----------------------------------------------------------*/

powered by: WebSVN 2.1.0

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