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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_AT91SAM7X256_Eclipse/] [RTOSDemo/] [main.c] - Blame information for rev 577

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
        NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.
56
        The processor MUST be in supervisor mode when vTaskStartScheduler is
57
        called.  The demo applications included in the FreeRTOS.org download switch
58
        to supervisor mode prior to main being called.  If you are not using one of
59
        these demo application projects then ensure Supervisor mode is used.
60
*/
61
 
62
/*
63
 * This demo includes a (basic) USB mouse driver and a WEB server.  It is
64
 * targeted for the AT91SAM7X EK prototyping board which includes a small
65
 * joystick to provide the mouse inputs.  The WEB interface provides some basic
66
 * interactivity through the use of a check box to turn on and off an LED.
67
 *
68
 * main() creates the WEB server, USB, and a set of the standard demo tasks
69
 * before starting the scheduler.  See the online FreeRTOS.org documentation
70
 * for more information on the standard demo tasks.
71
 *
72
 * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will
73
 * toggle at a different fixed frequency.
74
 *
75
 * A tick hook function is used to monitor the standard demo tasks - with LED
76
 * D4 being used to indicate the system status.  D4 toggling every 5 seconds
77
 * indicates that all the standard demo tasks are executing without error.  The
78
 * toggle rate increasing to 500ms is indicative of an error having been found
79
 * in at least one demo task.
80
 *
81
 * See the online documentation page that accompanies this demo for full setup
82
 * and usage information.
83
 */
84
 
85
/* Standard includes. */
86
#include <stdlib.h>
87
 
88
/* Scheduler includes. */
89
#include "FreeRTOS.h"
90
#include "task.h"
91
 
92
/* Demo application includes. */
93
#include "partest.h"
94
#include "USBSample.h"
95
#include "uip_task.h"
96
#include "BlockQ.h"
97
#include "blocktim.h"
98
#include "flash.h"
99
#include "QPeek.h"
100
#include "dynamic.h"
101
 
102
/* Priorities for the demo application tasks. */
103
#define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )
104
#define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )
105
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )
106
#define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
107
#define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) 
108
 
109
/* The task allocated to the uIP task is large to account for its use of the
110
sprintf() library function.  Use of a cut down printf() library would allow
111
the stack usage to be greatly reduced. */
112
#define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )
113
 
114
/* The LED toggle by the tick hook should an error have been found in a task. */
115
#define mainERROR_LED                                           ( 3 )
116
 
117
/*-----------------------------------------------------------*/
118
 
119
/*
120
 * Configure the processor for use with the Atmel demo board.  Setup is minimal
121
 * as the low level init function (called from the startup asm file) takes care
122
 * of most things.
123
 */
124
static void prvSetupHardware( void );
125
 
126
/*-----------------------------------------------------------*/
127
 
128
/*
129
 * Starts all the other tasks, then starts the scheduler.
130
 */
131
int main( void )
132
{
133
        /* Setup any hardware that has not already been configured by the low
134
        level init routines. */
135
        prvSetupHardware();
136
 
137
        /* Start the task that handles the TCP/IP and WEB server functionality. */
138
    xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );
139
 
140
        /* Also start the USB demo which is just for the SAM7. */
141
    vStartUSBTask( mainUSB_PRIORITY );
142
 
143
        /* Start the standard demo tasks. */
144
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
145
    vCreateBlockTimeTasks();
146
    vStartLEDFlashTasks( mainFLASH_PRIORITY );
147
    vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
148
    vStartQueuePeekTasks();
149
    vStartDynamicPriorityTasks();
150
 
151
        /* Start the scheduler.
152
 
153
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
154
        The processor MUST be in supervisor mode when vTaskStartScheduler is
155
        called.  The demo applications included in the FreeRTOS.org download switch
156
        to supervisor mode prior to main being called.  If you are not using one of
157
        these demo application projects then ensure Supervisor mode is used here. */
158
 
159
        vTaskStartScheduler();
160
 
161
        /* We should never get here as control is now taken by the scheduler. */
162
        return 0;
163
}
164
/*-----------------------------------------------------------*/
165
 
166
static void prvSetupHardware( void )
167
{
168
        portDISABLE_INTERRUPTS();
169
 
170
        /* When using the JTAG debugger the hardware is not always initialised to
171
        the correct default state.  This line just ensures that this does not
172
        cause all interrupts to be masked at the start. */
173
        AT91C_BASE_AIC->AIC_EOICR = 0;
174
 
175
        /* Most setup is performed by the low level init function called from the
176
        startup asm file. */
177
 
178
        /* Enable the peripheral clock. */
179
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
180
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
181
        AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
182
 
183
        /* Initialise the LED outputs for use by the demo application tasks. */
184
        vParTestInitialise();
185
}
186
/*-----------------------------------------------------------*/
187
 
188
void vApplicationTickHook( void )
189
{
190
static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;
191
 
192
/* The rate at which LED D4 will toggle if an error has been found in one or
193
more of the standard demo tasks. */
194
const unsigned long ulErrorFlashRate = 500 / portTICK_RATE_MS;
195
 
196
/* The rate at which LED D4 will toggle if no errors have been found in any
197
of the standard demo tasks. */
198
const unsigned long ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;
199
 
200
        ulCallCount++;
201
 
202
        if( ulErrorFound != pdFALSE )
203
        {
204
                /* We have already found an error, so flash the LED with the appropriate
205
                frequency. */
206
                if( ulCallCount > ulErrorFlashRate )
207
                {
208
                        ulCallCount = 0;
209
                        vParTestToggleLED( mainERROR_LED );
210
                }
211
        }
212
        else
213
        {
214
                if( ulCallCount > ulNoErrorCheckRate )
215
                {
216
                        ulCallCount = 0;
217
 
218
                        /* We have not yet found an error.  Check all the demo tasks to ensure
219
                        this is still the case. */
220
 
221
                        if( xAreBlockingQueuesStillRunning() != pdTRUE )
222
                        {
223
                                ulErrorFound |= 0x01;
224
                        }
225
 
226
                        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
227
                        {
228
                                ulErrorFound |= 0x02;
229
                        }
230
 
231
                        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
232
                        {
233
                                ulErrorFound |= 0x04;
234
                        }
235
 
236
                        if( xAreGenericQueueTasksStillRunning() != pdTRUE )
237
                        {
238
                                ulErrorFound |= 0x08;
239
                        }
240
 
241
                        if( xAreQueuePeekTasksStillRunning() != pdTRUE )
242
                        {
243
                                ulErrorFound |= 0x10;
244
                        }
245
 
246
                        vParTestToggleLED( mainERROR_LED );
247
                }
248
        }
249
}
250
 
251
 
252
 
253
 

powered by: WebSVN 2.1.0

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