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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LPC1768_GCC_Rowley/] [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
/* Task priorities. */
101
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
102
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
103
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
104
#define mainUIP_TASK_PRIORITY                           ( tskIDLE_PRIORITY + 3 )
105
#define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
106
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )
107
#define mainFLASH_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
108
 
109
/* The WEB server has a larger stack as it utilises stack hungry string
110
handling library calls. */
111
#define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 4 )
112
 
113
/* The message displayed by the WEB server when all tasks are executing
114
without an error being reported. */
115
#define mainPASS_STATUS_MESSAGE                         "All tasks are executing without error."
116
 
117
/*-----------------------------------------------------------*/
118
 
119
/*
120
 * Configure the hardware for the demo.
121
 */
122
static void prvSetupHardware( void );
123
 
124
/*
125
 * The task that handles the uIP stack.  All TCP/IP processing is performed in
126
 * this task.
127
 */
128
extern void vuIP_Task( void *pvParameters );
129
 
130
/*
131
 * The task that handles the USB stack.
132
 */
133
extern void vUSBTask( void *pvParameters );
134
 
135
/*
136
 * Simply returns the current status message for display on served WEB pages.
137
 */
138
char *pcGetTaskStatusMessage( void );
139
 
140
/*-----------------------------------------------------------*/
141
 
142
/* Holds the status message displayed by the WEB server. */
143
static char *pcStatusMessage = mainPASS_STATUS_MESSAGE;
144
 
145
/*-----------------------------------------------------------*/
146
 
147
int main( void )
148
{
149
        /* Configure the hardware for use by this demo. */
150
        prvSetupHardware();
151
 
152
        /* Start the standard demo tasks.  These are just here to exercise the
153
        kernel port and provide examples of how the FreeRTOS API can be used. */
154
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
155
    vCreateBlockTimeTasks();
156
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
157
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
158
    vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
159
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
160
    vStartQueuePeekTasks();
161
    vStartRecursiveMutexTasks();
162
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
163
 
164
    /* Create the USB task. */
165
    xTaskCreate( vUSBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
166
 
167
        /* Create the uIP task.  The WEB server runs in this task. */
168
    xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );
169
 
170
    /* Start the scheduler. */
171
        vTaskStartScheduler();
172
 
173
    /* Will only get here if there was insufficient memory to create the idle
174
    task.  The idle task is created within vTaskStartScheduler(). */
175
        for( ;; );
176
}
177
/*-----------------------------------------------------------*/
178
 
179
void vApplicationTickHook( void )
180
{
181
static unsigned long ulTicksSinceLastDisplay = 0;
182
 
183
        /* Called from every tick interrupt as described in the comments at the top
184
        of this file.
185
 
186
        Have enough ticks passed to make it     time to perform our health status
187
        check again? */
188
        ulTicksSinceLastDisplay++;
189
        if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
190
        {
191
                /* Reset the counter so these checks run again in mainCHECK_DELAY
192
                ticks time. */
193
                ulTicksSinceLastDisplay = 0;
194
 
195
                /* Has an error been found in any task? */
196
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )
197
                {
198
                        pcStatusMessage = "An error has been detected in the Generic Queue test/demo.";
199
                }
200
                else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
201
                {
202
                        pcStatusMessage = "An error has been detected in the Peek Queue test/demo.";
203
                }
204
                else if( xAreBlockingQueuesStillRunning() != pdTRUE )
205
                {
206
                        pcStatusMessage = "An error has been detected in the Block Queue test/demo.";
207
                }
208
                else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
209
                {
210
                        pcStatusMessage = "An error has been detected in the Block Time test/demo.";
211
                }
212
            else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
213
            {
214
                pcStatusMessage = "An error has been detected in the Semaphore test/demo.";
215
            }
216
            else if( xArePollingQueuesStillRunning() != pdTRUE )
217
            {
218
                pcStatusMessage = "An error has been detected in the Poll Queue test/demo.";
219
            }
220
            else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
221
            {
222
                pcStatusMessage = "An error has been detected in the Int Math test/demo.";
223
            }
224
            else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
225
            {
226
                pcStatusMessage = "An error has been detected in the Mutex test/demo.";
227
            }
228
        }
229
}
230
/*-----------------------------------------------------------*/
231
 
232
char *pcGetTaskStatusMessage( void )
233
{
234
        /* Not bothered about a critical section here. */
235
        return pcStatusMessage;
236
}
237
/*-----------------------------------------------------------*/
238
 
239
void prvSetupHardware( void )
240
{
241
        /* Disable peripherals power. */
242
        SC->PCONP = 0;
243
 
244
        /* Enable GPIO power. */
245
        SC->PCONP = PCONP_PCGPIO;
246
 
247
        /* Disable TPIU. */
248
        PINCON->PINSEL10 = 0;
249
 
250
        /*  Setup the peripheral bus to be the same as the PLL output (64 MHz). */
251
        SC->PCLKSEL0 = 0x05555555;
252
 
253
        /* Configure the LEDs. */
254
        vParTestInitialise();
255
}
256
/*-----------------------------------------------------------*/
257
 
258
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
259
{
260
        /* This function will get called if a task overflows its stack. */
261
 
262
        ( void ) pxTask;
263
        ( void ) pcTaskName;
264
 
265
        for( ;; );
266
}
267
/*-----------------------------------------------------------*/
268
 
269
void vConfigureTimerForRunTimeStats( void )
270
{
271
const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;
272
 
273
        /* This function configures a timer that is used as the time base when
274
        collecting run time statistical information - basically the percentage
275
        of CPU time that each task is utilising.  It is called automatically when
276
        the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set
277
        to 1). */
278
 
279
        /* Power up and feed the timer. */
280
        SC->PCONP |= 0x02UL;
281
        SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
282
 
283
        /* Reset Timer 0 */
284
        TIM0->TCR = TCR_COUNT_RESET;
285
 
286
        /* Just count up. */
287
        TIM0->CTCR = CTCR_CTM_TIMER;
288
 
289
        /* Prescale to a frequency that is good enough to get a decent resolution,
290
        but not too fast so as to overflow all the time. */
291
        TIM0->PR =  ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
292
 
293
        /* Start the counter. */
294
        TIM0->TCR = TCR_COUNT_ENABLE;
295
}
296
/*-----------------------------------------------------------*/
297
 

powered by: WebSVN 2.1.0

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