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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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