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

Subversion Repositories openrisc

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

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
/*
56
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
57
        The processor MUST be in supervisor mode when vTaskStartScheduler is
58
        called.  The demo applications included in the FreeRTOS.org download switch
59
        to supervisor mode prior to main being called.  If you are not using one of
60
        these demo application projects then ensure Supervisor mode is used.
61
*/
62
 
63
 
64
/*
65
 * Creates all the demo application tasks, then starts the scheduler.  The WEB
66
 * documentation provides more details of the demo application tasks.
67
 *
68
 * Main.c also creates a task called "Check".  This only executes every three
69
 * seconds but has the highest priority so is guaranteed to get processor time.
70
 * Its main function is to check that all the other tasks are still operational.
71
 * Each task (other than the "flash" tasks) maintains a unique count that is
72
 * incremented each time the task successfully completes its function.  Should
73
 * any error occur within such a task the count is permanently halted.  The
74
 * check task inspects the count of each task to ensure it has changed since
75
 * the last time the check task executed.  If all the count variables have
76
 * changed all the tasks are still executing error free, and the check task
77
 * toggles the onboard LED.  Should any task contain an error at any time
78
 * the LED toggle rate will change from 3 seconds to 500ms.
79
 *
80
 */
81
 
82
/* Standard includes. */
83
#include <stdlib.h>
84
 
85
/* Scheduler includes. */
86
#include "FreeRTOS.h"
87
#include "task.h"
88
 
89
/* Demo application includes. */
90
#include "flash.h"
91
#include "integer.h"
92
#include "PollQ.h"
93
#include "BlockQ.h"
94
#include "semtest.h"
95
#include "dynamic.h"
96
#include "partest.h"
97
#include "comtest2.h"
98
 
99
/* Priorities for the demo application tasks. */
100
#define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
101
#define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
102
#define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
103
#define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
104
#define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
105
#define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
106
 
107
/* Constants required by the 'Check' task. */
108
#define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )
109
#define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )
110
#define mainCHECK_TASK_LED                      ( 7 )
111
 
112
/* Constants for the ComTest tasks. */
113
#define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 115200 )
114
#define mainCOM_TEST_LED                        ( 4 )
115
#define mainTX_ENABLE                           ( ( unsigned long ) 0x0001 )
116
#define mainRX_ENABLE                           ( ( unsigned long ) 0x0004 )
117
 
118
/* Constants to setup the PLL. */
119
#define mainPLL_MUL_5                           ( ( unsigned char ) 0x0004 )
120
#define mainPLL_DIV_1                           ( ( unsigned char ) 0x0000 )
121
#define mainPLL_ENABLE                          ( ( unsigned char ) 0x0001 )
122
#define mainPLL_CONNECT                         ( ( unsigned char ) 0x0003 )
123
#define mainPLL_FEED_BYTE1                      ( ( unsigned char ) 0xaa )
124
#define mainPLL_FEED_BYTE2                      ( ( unsigned char ) 0x55 )
125
#define mainPLL_LOCK                            ( ( unsigned long ) 0x0400 )
126
 
127
/* Constants to setup the MAM. */
128
#define mainMAM_TIM_3                           ( ( unsigned char ) 0x03 )
129
#define mainMAM_MODE_FULL                       ( ( unsigned char ) 0x02 )
130
 
131
/* Constants to setup the peripheral bus. */
132
#define mainBUS_CLK_FULL                        ( ( unsigned char ) 0x01 )
133
 
134
/* And finally, constant to setup the port for the LED's. */
135
#define mainLED_TO_OUTPUT                       ( ( unsigned long ) 0xff0000 )
136
 
137
/*
138
 * The task that executes at the highest priority and calls
139
 * prvCheckOtherTasksAreStillRunning().  See the description at the top
140
 * of the file.
141
 */
142
static void vErrorChecks( void *pvParameters );
143
 
144
/*
145
 * Configures the processor for use with this demo.
146
 */
147
static void prvSetupHardware( void );
148
 
149
/*
150
 * Checks that all the demo application tasks are still executing without error
151
 * - as described at the top of the file.
152
 */
153
static long prvCheckOtherTasksAreStillRunning( void );
154
 
155
 
156
/*-----------------------------------------------------------*/
157
 
158
/*
159
 * Starts all the other tasks, then starts the scheduler.
160
 */
161
void main( void )
162
{
163
        /* Setup the processor. */
164
        prvSetupHardware();
165
 
166
        /* Start all the standard demo application tasks. */
167
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
168
        vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
169
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
170
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
171
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
172
        vStartDynamicPriorityTasks();
173
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
174
 
175
        /* Start the check task - which is defined in this file. */
176
        xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
177
 
178
        /* Start the scheduler.
179
 
180
        NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
181
        The processor MUST be in supervisor mode when vTaskStartScheduler is
182
        called.  The demo applications included in the FreeRTOS.org download switch
183
        to supervisor mode prior to main being called.  If you are not using one of
184
        these demo application projects then ensure Supervisor mode is used here.
185
        */
186
        vTaskStartScheduler();
187
 
188
        /* We should never get here as control is now taken by the scheduler. */
189
        return;
190
}
191
/*-----------------------------------------------------------*/
192
 
193
static void prvSetupHardware( void )
194
{
195
        /* Setup the PLL to multiply the XTAL input by 5. */
196
        PLLCFG = ( mainPLL_MUL_5 | mainPLL_DIV_1 );
197
 
198
        /* Activate the PLL by turning it on then feeding the correct sequence of
199
        bytes. */
200
        PLLCON = mainPLL_ENABLE;
201
        PLLFEED = mainPLL_FEED_BYTE1;
202
        PLLFEED = mainPLL_FEED_BYTE2;
203
 
204
        /* Wait for the PLL to lock... */
205
        while( !( PLLSTAT & mainPLL_LOCK ) );
206
 
207
        /* ...before connecting it using the feed sequence again. */
208
        PLLCON = mainPLL_CONNECT;
209
        PLLFEED = mainPLL_FEED_BYTE1;
210
        PLLFEED = mainPLL_FEED_BYTE2;
211
 
212
        /* Setup and turn on the MAM.  Three cycle access is used due to the fast
213
        PLL used.  It is possible faster overall performance could be obtained by
214
        tuning the MAM and PLL settings. */
215
        MAMTIM = mainMAM_TIM_3;
216
        MAMCR = mainMAM_MODE_FULL;
217
 
218
        /* Setup the peripheral bus to be the same as the PLL output. */
219
        APBDIV = mainBUS_CLK_FULL;
220
 
221
        /* Configure the RS2332 pins.  All other pins remain at their default of 0. */
222
        PINSEL0 |= mainTX_ENABLE;
223
        PINSEL0 |= mainRX_ENABLE;
224
 
225
        /* LED pins need to be output. */
226
        IO1DIR = mainLED_TO_OUTPUT;
227
 
228
        /* Setup the peripheral bus to be the same as the PLL output. */
229
        APBDIV = mainBUS_CLK_FULL;
230
}
231
/*-----------------------------------------------------------*/
232
 
233
static void vErrorChecks( void *pvParameters )
234
{
235
portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
236
 
237
        /* The parameters are not used in this task. */
238
        ( void ) pvParameters;
239
 
240
        /* Cycle for ever, delaying then checking all the other tasks are still
241
        operating without error.  If an error is detected then the delay period
242
        is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
243
        the on board LED flash rate will increase. */
244
 
245
        for( ;; )
246
        {
247
                /* Delay until it is time to execute again. */
248
                vTaskDelay( xDelayPeriod );
249
 
250
                /* Check all the standard demo application tasks are executing without
251
                error. */
252
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )
253
                {
254
                        /* An error has been detected in one of the tasks - flash faster. */
255
                        xDelayPeriod = mainERROR_FLASH_PERIOD;
256
                }
257
 
258
                vParTestToggleLED( mainCHECK_TASK_LED );
259
        }
260
}
261
/*-----------------------------------------------------------*/
262
 
263
static long prvCheckOtherTasksAreStillRunning( void )
264
{
265
long lReturn = ( long ) pdPASS;
266
 
267
        /* Check all the demo tasks (other than the flash tasks) to ensure
268
        that they are all still running, and that none of them have detected
269
        an error. */
270
 
271
        if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
272
        {
273
                lReturn = ( long ) pdFAIL;
274
        }
275
 
276
        if( xArePollingQueuesStillRunning() != pdTRUE )
277
        {
278
                lReturn = ( long ) pdFAIL;
279
        }
280
 
281
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )
282
        {
283
                lReturn = ( long ) pdFAIL;
284
        }
285
 
286
        if( xAreBlockingQueuesStillRunning() != pdTRUE )
287
        {
288
                lReturn = ( long ) pdFAIL;
289
        }
290
 
291
        if( xAreComTestTasksStillRunning() != pdTRUE )
292
        {
293
                lReturn = ( long ) pdFAIL;
294
        }
295
 
296
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
297
        {
298
                lReturn = ( long ) pdFAIL;
299
        }
300
 
301
        return lReturn;
302
}
303
/*-----------------------------------------------------------*/
304
 
305
 

powered by: WebSVN 2.1.0

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