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

Subversion Repositories openrisc

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

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
        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
/*
64
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
65
 * documentation provides more details of the demo application tasks.
66
 *
67
 * Main.c also creates a task called "Check".  This only executes every three
68
 * seconds but has the highest priority so is guaranteed to get processor time.
69
 * Its main function is to check that all the other tasks are still operational.
70
 * Each task (other than the "flash" tasks) maintains a unique count that is
71
 * incremented each time the task successfully completes its function.  Should
72
 * any error occur within such a task the count is permanently halted.  The
73
 * check task inspects the count of each task to ensure it has changed since
74
 * the last time the check task executed.  If all the count variables have
75
 * changed all the tasks are still executing error free, and the check task
76
 * toggles the onboard LED.  Should any task contain an error at any time
77
 * the LED toggle rate will change from 3 seconds to 500ms.
78
 *
79
 */
80
 
81
/* Standard includes. */
82
#include <stdlib.h>
83
 
84
/* Scheduler includes. */
85
#include "FreeRTOS.h"
86
#include "task.h"
87
 
88
/* Demo application includes. */
89
#include "partest.h"
90
#include "flash.h"
91
#include "comtest2.h"
92
#include "serial.h"
93
#include "PollQ.h"
94
#include "BlockQ.h"
95
#include "semtest.h"
96
#include "dynamic.h"
97
 
98
/*-----------------------------------------------------------*/
99
 
100
/* Constants to setup I/O and processor. */
101
#define mainTX_ENABLE           ( ( unsigned portLONG ) 0x00010000 )    /* UART1. */
102
#define mainRX_ENABLE           ( ( unsigned portLONG ) 0x00040000 )    /* UART1. */
103
#define mainBUS_CLK_FULL        ( ( unsigned portCHAR ) 0x01 )
104
#define mainLED_TO_OUTPUT       ( ( unsigned portLONG ) 0xff0000 )
105
 
106
/* Constants for the ComTest demo application tasks. */
107
#define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 115200 )
108
#define mainCOM_TEST_LED                ( 3 )
109
 
110
/* Priorities for the demo application tasks. */
111
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
112
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
113
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
114
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
115
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
116
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
117
 
118
/* Constants used by the "check" task.  As described at the head of this file
119
the check task toggles an LED.  The rate at which the LED flashes is used to
120
indicate whether an error has been detected or not.  If the LED toggles every
121
3 seconds then no errors have been detected.  If the rate increases to 500ms
122
then an error has been detected in at least one of the demo application tasks. */
123
#define mainCHECK_LED                           ( 7 )
124
#define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )
125
#define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )
126
 
127
/*-----------------------------------------------------------*/
128
 
129
/*
130
 * Checks that all the demo application tasks are still executing without error
131
 * - as described at the top of the file.
132
 */
133
static portLONG prvCheckOtherTasksAreStillRunning( void );
134
 
135
/*
136
 * The task that executes at the highest priority and calls
137
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
138
 * of the file.
139
 */
140
static void vErrorChecks( void *pvParameters );
141
 
142
/*
143
 * Configure the processor for use with the Keil demo board.  This is very
144
 * minimal as most of the setup is managed by the settings in the project
145
 * file.
146
 */
147
static void prvSetupHardware( void );
148
 
149
/*-----------------------------------------------------------*/
150
 
151
 
152
 
153
/*
154
 * Application entry point:
155
 * Starts all the other tasks, then starts the scheduler.
156
 */
157
int main( void )
158
{
159
        /* Setup the hardware for use with the Keil demo board. */
160
        prvSetupHardware();
161
 
162
        /* Start the demo/test application tasks. */
163
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
164
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
165
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
166
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
167
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
168
        vStartDynamicPriorityTasks();
169
 
170
        /* Start the check task - which is defined in this file.  This is the task
171
        that periodically checks to see that all the other tasks are executing
172
        without error. */
173
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
174
 
175
        /* Now all the tasks have been started - start the scheduler.
176
 
177
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
178
        The processor MUST be in supervisor mode when vTaskStartScheduler is
179
        called.  The demo applications included in the FreeRTOS.org download switch
180
        to supervisor mode prior to main being called.  If you are not using one of
181
        these demo application projects then ensure Supervisor mode is used here. */
182
        vTaskStartScheduler();
183
 
184
        /* Should never reach here!  If you do then there was not enough heap
185
        available for the idle task to be created. */
186
        for( ;; );
187
}
188
/*-----------------------------------------------------------*/
189
 
190
static void vErrorChecks( void *pvParameters )
191
{
192
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
193
 
194
        /* Parameters are not used. */
195
        ( void ) pvParameters;
196
 
197
        /* Cycle for ever, delaying then checking all the other tasks are still
198
        operating without error.  If an error is detected then the delay period
199
        is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
200
        the on board LED flash rate will increase.
201
 
202
        This task runs at the highest priority. */
203
 
204
        for( ;; )
205
        {
206
                /* The period of the delay depends on whether an error has been
207
                detected or not.  If an error has been detected then the period
208
                is reduced to increase the LED flash rate. */
209
                vTaskDelay( xDelayPeriod );
210
 
211
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
212
                {
213
                        /* An error has been detected in one of the tasks - flash faster. */
214
                        xDelayPeriod = mainERROR_FLASH_PERIOD;
215
                }
216
 
217
                /* Toggle the LED before going back to wait for the next cycle. */
218
                vParTestToggleLED( mainCHECK_LED );
219
        }
220
}
221
/*-----------------------------------------------------------*/
222
 
223
static void prvSetupHardware( void )
224
{
225
        /* Perform the hardware setup required.  This is minimal as most of the
226
        setup is managed by the settings in the project file. */
227
 
228
        /* Configure the UART1 pins.  All other pins remain at their default of 0. */
229
        PINSEL0 |= mainTX_ENABLE;
230
        PINSEL0 |= mainRX_ENABLE;
231
 
232
        /* LED pins need to be output. */
233
        IODIR1 = mainLED_TO_OUTPUT;
234
 
235
        /* Setup the peripheral bus to be the same as the PLL output. */
236
        VPBDIV = mainBUS_CLK_FULL;
237
}
238
/*-----------------------------------------------------------*/
239
 
240
static portLONG prvCheckOtherTasksAreStillRunning( void )
241
{
242
portLONG lReturn = pdPASS;
243
 
244
        /* Check all the demo tasks (other than the flash tasks) to ensure
245
        that they are all still running, and that none of them have detected
246
        an error. */
247
        if( xAreComTestTasksStillRunning() != pdPASS )
248
        {
249
                lReturn = pdFAIL;
250
        }
251
 
252
        if( xArePollingQueuesStillRunning() != pdTRUE )
253
        {
254
                lReturn = pdFAIL;
255
        }
256
 
257
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
258
        {
259
                lReturn = pdFAIL;
260
        }
261
 
262
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
263
        {
264
                lReturn = pdFAIL;
265
        }
266
 
267
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
268
        {
269
                lReturn = pdFAIL;
270
        }
271
 
272
        return lReturn;
273
}
274
/*-----------------------------------------------------------*/
275
 
276
 

powered by: WebSVN 2.1.0

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