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

Subversion Repositories openrisc

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

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
int 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
        return 0;
191
}
192
/*-----------------------------------------------------------*/
193
 
194
static void vCheckTask( void *pvParameters )
195
{
196
static unsigned long ulErrorDetected = pdFALSE;
197
portTickType xLastExecutionTime;
198
unsigned char *ucErrorMessage = ( unsigned char * )"              FAIL";
199
unsigned char *ucSuccessMessage = ( unsigned char * )"              PASS";
200
unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
201
LCDMessage xMessage;
202
 
203
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
204
        works correctly. */
205
        xLastExecutionTime = xTaskGetTickCount();
206
 
207
        for( ;; )
208
        {
209
                /* Wait until it is time for the next cycle. */
210
                vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
211
 
212
                /* Has an error been found in any of the standard demo tasks? */
213
 
214
                if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
215
                {
216
                        ulErrorDetected = pdTRUE;
217
                }
218
 
219
                if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
220
                {
221
                        ulErrorDetected = pdTRUE;
222
                }
223
 
224
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
225
                {
226
                        ulErrorDetected = pdTRUE;
227
                }
228
 
229
                if( xAreComTestTasksStillRunning() != pdTRUE )
230
                {
231
                        ulErrorDetected = pdTRUE;
232
                }
233
 
234
                if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
235
                {
236
                        ulErrorDetected = pdTRUE;
237
                }
238
 
239
                /* Calculate the LCD line on which we would like the message to
240
                be displayed.  The column variable is used for convenience as
241
                it is incremented each cycle anyway. */
242
                xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
243
 
244
                /* The message displayed depends on whether an error was found or
245
                not.  Any discovered error is latched.  Here the column variable
246
                is used as an index into the text string as a simple way of moving
247
                the text from column to column. */
248
                if( ulErrorDetected == pdFALSE )
249
                {
250
                        xMessage.pucString = ucSuccessMessage + uxColumn;
251
                }
252
                else
253
                {
254
                        xMessage.pucString = ucErrorMessage + uxColumn;
255
                }
256
 
257
                /* Send the message to the print task for display. */
258
                xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
259
 
260
                /* Make sure the message is printed in a different column the next
261
                time around. */
262
                uxColumn--;
263
                if( uxColumn == 0 )
264
                {
265
                        uxColumn = mainMAX_WRITE_COLUMN;
266
                }
267
        }
268
}
269
 
270
/*-----------------------------------------------------------*/
271
 
272
static void vPrintTask( void *pvParameters )
273
{
274
LCDMessage xMessage;
275
 
276
        for( ;; )
277
        {
278
                /* Wait until a message arrives. */
279
                while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
280
 
281
                /* The message contains the text to display, and the line on which the
282
                text should be displayed. */
283
                LCD_Clear();
284
                LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
285
        }
286
}
287
/*-----------------------------------------------------------*/
288
 
289
static void prvSetupHardware(void)
290
{
291
ErrorStatus OSC4MStartUpStatus01;
292
 
293
        /* ST provided routine. */
294
 
295
        /* MRCC system reset */
296
        MRCC_DeInit();
297
 
298
        /* Wait for OSC4M start-up */
299
        OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
300
 
301
        if(OSC4MStartUpStatus01 == SUCCESS)
302
        {
303
                /* Set HCLK to 60MHz */
304
                MRCC_HCLKConfig(MRCC_CKSYS_Div1);
305
 
306
                /* Set CKTIM to 60MHz */
307
                MRCC_CKTIMConfig(MRCC_HCLK_Div1);
308
 
309
                /* Set PCLK to 30MHz */
310
                MRCC_PCLKConfig(MRCC_CKTIM_Div2);
311
 
312
                /* Enable Flash Burst mode */
313
                CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
314
 
315
                /* Set CK_SYS to 60 MHz */
316
                MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
317
        }
318
 
319
        /* GPIO pins optimized for 3V3 operation */
320
        MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
321
 
322
        /* GPIO clock source enable */
323
        MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
324
 
325
        /* EXTIT clock source enable */
326
        MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
327
        /* TB clock source enable */
328
        MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
329
 
330
        /* Initialize the demonstration menu */
331
        LCD_Init();
332
 
333
        LCD_DisplayString(Line1, ( unsigned char * ) "www.FreeRTOS.org", BlackText);
334
        LCD_DisplayString(Line2, ( unsigned char * ) "  STR750 Demo  ", BlackText);
335
 
336
        EIC_IRQCmd(ENABLE);
337
}
338
/*-----------------------------------------------------------*/
339
 

powered by: WebSVN 2.1.0

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