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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LPC1768_GCC_RedSuite/] [src/] [main.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 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
#error The batch file Demo\CORTEX_LPC1768_GCC_RedSuite\CreateProjectDirectoryStructure.bat must be executed before the first build.  After executing the batch file hit F5 to refrech the Eclipse project, then delete this line.
56
 
57
 
58
 
59
/*
60
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
61
 * documentation provides more details of the standard demo application tasks
62
 * (which just exist to test the kernel port and provide an example of how to use
63
 * each FreeRTOS API function).
64
 *
65
 * In addition to the standard demo tasks, the following tasks and tests are
66
 * defined and/or created within this file:
67
 *
68
 * "Check" hook -  This only executes fully every five seconds from the tick
69
 * hook.  Its main function is to check that all the standard demo tasks are
70
 * still operational.  The status can be viewed using on the Task Stats page
71
 * served by the WEB server.
72
 *
73
 * "uIP" task -  This is the task that handles the uIP stack.  All TCP/IP
74
 * processing is performed in this task.
75
 *
76
 * "USB" task - Enumerates the USB device as a CDC class, then echoes back all
77
 * received characters with a configurable offset (for example, if the offset
78
 * is 1 and 'A' is received then 'B' will be sent back).  A dumb terminal such
79
 * as Hyperterminal can be used to talk to the USB task.
80
 */
81
 
82
/* Standard includes. */
83
#include "stdio.h"
84
 
85
/* Scheduler includes. */
86
#include "FreeRTOS.h"
87
#include "task.h"
88
 
89
/* Demo app includes. */
90
#include "BlockQ.h"
91
#include "integer.h"
92
#include "blocktim.h"
93
#include "flash.h"
94
#include "partest.h"
95
#include "semtest.h"
96
#include "PollQ.h"
97
#include "GenQTest.h"
98
#include "QPeek.h"
99
#include "recmutex.h"
100
 
101
/* Red Suite includes. */
102
#include "lcd_driver.h"
103
#include "lcd.h"
104
 
105
/*-----------------------------------------------------------*/
106
 
107
/* The time between cycles of the 'check' functionality (defined within the
108
tick hook. */
109
#define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
110
 
111
/* Task priorities. */
112
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
113
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
114
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
115
#define mainUIP_TASK_PRIORITY                           ( tskIDLE_PRIORITY + 3 )
116
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
117
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
118
#define mainFLASH_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
119
 
120
/* The WEB server has a larger stack as it utilises stack hungry string
121
handling library calls. */
122
#define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 4 )
123
 
124
/* The message displayed by the WEB server when all tasks are executing
125
without an error being reported. */
126
#define mainPASS_STATUS_MESSAGE                         "All tasks are executing without error."
127
 
128
/* Bit definitions. */
129
#define PCONP_PCGPIO    0x00008000
130
#define PLLFEED_FEED1   0x000000AA
131
#define PLLFEED_FEED2   0x00000055
132
/*-----------------------------------------------------------*/
133
 
134
/*
135
 * Configure the hardware for the demo.
136
 */
137
static void prvSetupHardware( void );
138
 
139
/*
140
 * The task that handles the uIP stack.  All TCP/IP processing is performed in
141
 * this task.
142
 */
143
extern void vuIP_Task( void *pvParameters );
144
 
145
/*
146
 * The task that handles the USB stack.
147
 */
148
extern void vUSBTask( void *pvParameters );
149
 
150
/*
151
 * Simply returns the current status message for display on served WEB pages.
152
 */
153
char *pcGetTaskStatusMessage( void );
154
 
155
/*-----------------------------------------------------------*/
156
 
157
/* Holds the status message displayed by the WEB server. */
158
static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;
159
 
160
/*-----------------------------------------------------------*/
161
 
162
int main( void )
163
{
164
char cIPAddress[ 16 ]; /* Enough space for "xxx.xxx.xxx.xxx\0". */
165
 
166
        /* Configure the hardware for use by this demo. */
167
        prvSetupHardware();
168
 
169
        /* Start the standard demo tasks.  These are just here to exercise the
170
        kernel port and provide examples of how the FreeRTOS API can be used. */
171
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
172
    vCreateBlockTimeTasks();
173
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
174
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
175
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
176
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
177
    vStartQueuePeekTasks();
178
    vStartRecursiveMutexTasks();
179
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
180
 
181
    /* Create the USB task. */
182
    xTaskCreate( vUSBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
183
 
184
        /* Display the IP address, then create the uIP task.  The WEB server runs
185
        in this task. */
186
        LCDdriver_initialisation();
187
        LCD_PrintString( 5, 10, "FreeRTOS.org", 14, COLOR_GREEN);
188
        sprintf( cIPAddress, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
189
        LCD_PrintString( 5, 30, cIPAddress, 14, COLOR_RED);
190
    xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );
191
 
192
    /* Start the scheduler. */
193
        vTaskStartScheduler();
194
 
195
    /* Will only get here if there was insufficient memory to create the idle
196
    task.  The idle task is created within vTaskStartScheduler(). */
197
        for( ;; );
198
}
199
/*-----------------------------------------------------------*/
200
 
201
void vApplicationTickHook( void )
202
{
203
static unsigned long ulTicksSinceLastDisplay = 0;
204
 
205
        /* Called from every tick interrupt as described in the comments at the top
206
        of this file.
207
 
208
        Have enough ticks passed to make it     time to perform our health status
209
        check again? */
210
        ulTicksSinceLastDisplay++;
211
        if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
212
        {
213
                /* Reset the counter so these checks run again in mainCHECK_DELAY
214
                ticks time. */
215
                ulTicksSinceLastDisplay = 0;
216
 
217
                /* Has an error been found in any task? */
218
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
219
                {
220
                        pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";
221
                }
222
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
223
                {
224
                        pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";
225
                }
226
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )
227
                {
228
                        pcStatusMessage = "An error has been detected in the Block Queue test/demo.";
229
                }
230
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
231
                {
232
                        pcStatusMessage = "An error has been detected in the Block Time test/demo.";
233
                }
234
            else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
235
            {
236
                pcStatusMessage = "An error has been detected in the Semaphore test/demo.";
237
            }
238
            else if( xArePollingQueuesStillRunning() != pdTRUE )
239
            {
240
                pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";
241
            }
242
            else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
243
            {
244
                pcStatusMessage = "An error has been detected in the Int Math test/demo.";
245
            }
246
            else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
247
            {
248
                pcStatusMessage = "An error has been detected in the Mutex test/demo.";
249
            }
250
        }
251
}
252
/*-----------------------------------------------------------*/
253
 
254
char *pcGetTaskStatusMessage( void )
255
{
256
        /* Not bothered about a critical section here. */
257
        return pcStatusMessage;
258
}
259
/*-----------------------------------------------------------*/
260
 
261
void prvSetupHardware( void )
262
{
263
        /* Disable peripherals power. */
264
        LPC_SC->PCONP = 0;
265
 
266
        /* Enable GPIO power. */
267
        LPC_SC->PCONP = PCONP_PCGPIO;
268
 
269
        /* Disable TPIU. */
270
        LPC_PINCON->PINSEL10 = 0;
271
 
272
        if ( LPC_SC->PLL0STAT & ( 1 << 25 ) )
273
        {
274
                /* Enable PLL, disconnected. */
275
                LPC_SC->PLL0CON = 1;
276
                LPC_SC->PLL0FEED = PLLFEED_FEED1;
277
                LPC_SC->PLL0FEED = PLLFEED_FEED2;
278
        }
279
 
280
        /* Disable PLL, disconnected. */
281
        LPC_SC->PLL0CON = 0;
282
        LPC_SC->PLL0FEED = PLLFEED_FEED1;
283
        LPC_SC->PLL0FEED = PLLFEED_FEED2;
284
 
285
        /* Enable main OSC. */
286
        LPC_SC->SCS |= 0x20;
287
        while( !( LPC_SC->SCS & 0x40 ) );
288
 
289
        /* select main OSC, 12MHz, as the PLL clock source. */
290
        LPC_SC->CLKSRCSEL = 0x1;
291
 
292
        LPC_SC->PLL0CFG = 0x20031;
293
        LPC_SC->PLL0FEED = PLLFEED_FEED1;
294
        LPC_SC->PLL0FEED = PLLFEED_FEED2;
295
 
296
        /* Enable PLL, disconnected. */
297
        LPC_SC->PLL0CON = 1;
298
        LPC_SC->PLL0FEED = PLLFEED_FEED1;
299
        LPC_SC->PLL0FEED = PLLFEED_FEED2;
300
 
301
        /* Set clock divider. */
302
        LPC_SC->CCLKCFG = 0x03;
303
 
304
        /* Configure flash accelerator. */
305
        LPC_SC->FLASHCFG = 0x403a;
306
 
307
        /* Check lock bit status. */
308
        while( ( ( LPC_SC->PLL0STAT & ( 1 << 26 ) ) == 0 ) );
309
 
310
        /* Enable and connect. */
311
        LPC_SC->PLL0CON = 3;
312
        LPC_SC->PLL0FEED = PLLFEED_FEED1;
313
        LPC_SC->PLL0FEED = PLLFEED_FEED2;
314
        while( ( ( LPC_SC->PLL0STAT & ( 1 << 25 ) ) == 0 ) );
315
 
316
 
317
 
318
 
319
        /* Configure the clock for the USB. */
320
 
321
        if( LPC_SC->PLL1STAT & ( 1 << 9 ) )
322
        {
323
                /* Enable PLL, disconnected. */
324
                LPC_SC->PLL1CON = 1;
325
                LPC_SC->PLL1FEED = PLLFEED_FEED1;
326
                LPC_SC->PLL1FEED = PLLFEED_FEED2;
327
        }
328
 
329
        /* Disable PLL, disconnected. */
330
        LPC_SC->PLL1CON = 0;
331
        LPC_SC->PLL1FEED = PLLFEED_FEED1;
332
        LPC_SC->PLL1FEED = PLLFEED_FEED2;
333
 
334
        LPC_SC->PLL1CFG = 0x23;
335
        LPC_SC->PLL1FEED = PLLFEED_FEED1;
336
        LPC_SC->PLL1FEED = PLLFEED_FEED2;
337
 
338
        /* Enable PLL, disconnected. */
339
        LPC_SC->PLL1CON = 1;
340
        LPC_SC->PLL1FEED = PLLFEED_FEED1;
341
        LPC_SC->PLL1FEED = PLLFEED_FEED2;
342
        while( ( ( LPC_SC->PLL1STAT & ( 1 << 10 ) ) == 0 ) );
343
 
344
        /* Enable and connect. */
345
        LPC_SC->PLL1CON = 3;
346
        LPC_SC->PLL1FEED = PLLFEED_FEED1;
347
        LPC_SC->PLL1FEED = PLLFEED_FEED2;
348
        while( ( ( LPC_SC->PLL1STAT & ( 1 << 9 ) ) == 0 ) );
349
 
350
        /*  Setup the peripheral bus to be the same as the PLL output (64 MHz). */
351
        LPC_SC->PCLKSEL0 = 0x05555555;
352
 
353
        /* Configure the LEDs. */
354
        vParTestInitialise();
355
}
356
/*-----------------------------------------------------------*/
357
 
358
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
359
{
360
        /* This function will get called if a task overflows its stack. */
361
 
362
        ( void ) pxTask;
363
        ( void ) pcTaskName;
364
 
365
        for( ;; );
366
}
367
/*-----------------------------------------------------------*/
368
 
369
void vConfigureTimerForRunTimeStats( void )
370
{
371
const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;
372
 
373
        /* This function configures a timer that is used as the time base when
374
        collecting run time statistical information - basically the percentage
375
        of CPU time that each task is utilising.  It is called automatically when
376
        the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set
377
        to 1). */
378
 
379
        /* Power up and feed the timer. */
380
        LPC_SC->PCONP |= 0x02UL;
381
        LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
382
 
383
        /* Reset Timer 0 */
384
        LPC_TIM0->TCR = TCR_COUNT_RESET;
385
 
386
        /* Just count up. */
387
        LPC_TIM0->CTCR = CTCR_CTM_TIMER;
388
 
389
        /* Prescale to a frequency that is good enough to get a decent resolution,
390
        but not too fast so as to overflow all the time. */
391
        LPC_TIM0->PR =  ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
392
 
393
        /* Start the counter. */
394
        LPC_TIM0->TCR = TCR_COUNT_ENABLE;
395
}
396
/*-----------------------------------------------------------*/
397
 

powered by: WebSVN 2.1.0

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