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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_LPC2138_Rowley/] [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
 * This file contains a demo created to execute on the Rowley Associates
56
 * LPC2138 CrossFire development board.
57
 *
58
 * main() creates all the demo application tasks, then starts the scheduler.
59
 * The WEB documentation provides more details of the standard demo application
60
 * tasks.
61
 *
62
 * Main.c also creates a task called "Check".  This only executes every few
63
 * seconds but has a high priority so is guaranteed to get processor time.
64
 * Its function is to check that all the other tasks are still operational.
65
 * Each standard demo task maintains a unique count that is incremented each
66
 * time the task successfully completes its function.  Should any error occur
67
 * within such a task the count is permanently halted.  The check task inspects
68
 * the count of each task to ensure it has changed since the last time the
69
 * check task executed.  If all the count variables have changed all the tasks
70
 * are still executing error free, and the check task writes "PASS" to the
71
 * CrossStudio terminal IO window.  Should any task contain an error at any time
72
 * the error is latched and "FAIL" written to the terminal IO window.
73
 *
74
 * Finally, main() sets up an interrupt service routine and task to handle
75
 * pushes of the button that is built into the CrossFire board.  When the button
76
 * is pushed the ISR wakes the button task - which generates a table of task
77
 * status information which is also displayed on the terminal IO window.
78
 *
79
 * A print task is defined to ensure exclusive and consistent access to the
80
 * terminal IO.  This is the only task that is allowed to access the terminal.
81
 * The check and button task therefore do not access the terminal directly but
82
 * instead pass a pointer to the message they wish to display to the print task.
83
 */
84
 
85
/* Standard includes. */
86
#include <__cross_studio_io.h>
87
 
88
/* Scheduler includes. */
89
#include "FreeRTOS.h"
90
#include "task.h"
91
#include "queue.h"
92
#include "semphr.h"
93
 
94
/* Demo app includes. */
95
#include "BlockQ.h"
96
#include "death.h"
97
#include "dynamic.h"
98
#include "integer.h"
99
#include "PollQ.h"
100
#include "blocktim.h"
101
#include "recmutex.h"
102
#include "semtest.h"
103
 
104
/* Hardware configuration definitions. */
105
#define mainBUS_CLK_FULL                                        ( ( unsigned char ) 0x01 )
106
#define mainLED_BIT                                                     0x80000000
107
#define mainP0_14__EINT_1                                       ( 2 << 28 )
108
#define mainEINT_1_EDGE_SENSITIVE                       2
109
#define mainEINT_1_FALLING_EDGE_SENSITIVE       0
110
#define mainEINT_1_CHANNEL                                      15
111
#define mainEINT_1_VIC_CHANNEL_BIT                      ( 1 << mainEINT_1_CHANNEL )
112
#define mainEINT_1_ENABLE_BIT                           ( 1 << 5 )
113
 
114
/* Demo application definitions. */
115
#define mainQUEUE_SIZE                                          ( 3 )
116
#define mainLED_DELAY                                           ( ( portTickType ) 500 / portTICK_RATE_MS )
117
#define mainERROR_LED_DELAY                                     ( ( portTickType ) 50 / portTICK_RATE_MS )
118
#define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
119
#define mainLIST_BUFFER_SIZE                            2048
120
#define mainNO_DELAY                                            ( 0 )
121
#define mainSHORT_DELAY                                         ( 150 / portTICK_RATE_MS )
122
 
123
/* Task priorities. */
124
#define mainLED_TASK_PRIORITY                           ( tskIDLE_PRIORITY + 2 )
125
#define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
126
#define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
127
#define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
128
#define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
129
#define mainPRINT_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 0 )
130
 
131
/*-----------------------------------------------------------*/
132
 
133
/* The semaphore used to wake the button task from within the external interrupt
134
handler. */
135
xSemaphoreHandle xButtonSemaphore;
136
 
137
/* The queue that is used to send message to vPrintTask for display in the
138
terminal output window. */
139
xQueueHandle xPrintQueue;
140
 
141
/* The rate at which the LED will toggle.  The toggle rate increases if an
142
error is detected in any task. */
143
static portTickType xLED_Delay = mainLED_DELAY;
144
/*-----------------------------------------------------------*/
145
 
146
/*
147
 * Simply flashes the on board LED every mainLED_DELAY milliseconds.
148
 */
149
static void vLEDTask( void *pvParameters );
150
 
151
/*
152
 * Checks the status of all the demo tasks then prints a message to the
153
 * CrossStudio terminal IO windows.  The message will be either PASS or FAIL
154
 * depending on the status of the demo applications tasks.  A FAIL status will
155
 * be latched.
156
 *
157
 * Messages are not written directly to the terminal, but passed to vPrintTask
158
 * via a queue.
159
 */
160
static void vCheckTask( void *pvParameters );
161
 
162
/*
163
 * Controls all terminal output.  If a task wants to send a message to the
164
 * terminal IO it posts a pointer to the text to vPrintTask via a queue.  This
165
 * ensures serial access to the terminal IO.
166
 */
167
static void vPrintTask( void *pvParameter );
168
 
169
/*
170
 * Simply waits for an interrupt to be generated from the built in button, then
171
 * generates a table of tasks states that is then written by vPrintTask to the
172
 * terminal output window within CrossStudio.
173
 */
174
static void vButtonHandlerTask( void *pvParameters );
175
 
176
/*-----------------------------------------------------------*/
177
 
178
int main( void )
179
{
180
        /* Setup the peripheral bus to be the same as the PLL output. */
181
        VPBDIV = mainBUS_CLK_FULL;
182
 
183
        /* Create the queue used to pass message to vPrintTask. */
184
        xPrintQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( char * ) );
185
 
186
        /* Create the semaphore used to wake vButtonHandlerTask(). */
187
        vSemaphoreCreateBinary( xButtonSemaphore );
188
        xSemaphoreTake( xButtonSemaphore, 0 );
189
 
190
        /* Start the standard demo tasks. */
191
        vStartIntegerMathTasks( tskIDLE_PRIORITY );
192
        vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
193
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
194
        vStartDynamicPriorityTasks();
195
        vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
196
 
197
        #if configUSE_PREEMPTION == 1
198
        {
199
                /* The timing of console output when not using the preemptive
200
                scheduler causes the block time tests to detect a timing problem. */
201
                vCreateBlockTimeTasks();
202
        }
203
        #endif
204
 
205
    vStartRecursiveMutexTasks();
206
 
207
        /* Start the tasks defined within this file. */
208
        xTaskCreate( vLEDTask, ( signed char * ) "LED", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
209
    xTaskCreate( vCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
210
    xTaskCreate( vPrintTask, ( signed char * ) "Print", configMINIMAL_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );
211
    xTaskCreate( vButtonHandlerTask, ( signed char * ) "Button", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
212
 
213
        /* Start the scheduler. */
214
        vTaskStartScheduler();
215
 
216
        /* The scheduler should now be running, so we will only ever reach here if we
217
        ran out of heap space. */
218
 
219
        return 0;
220
}
221
/*-----------------------------------------------------------*/
222
 
223
static void vLEDTask( void *pvParameters )
224
{
225
        /* Just to remove compiler warnings. */
226
        ( void ) pvParameters;
227
 
228
        /* Configure IO. */
229
        IO0DIR |= mainLED_BIT;
230
        IO0SET = mainLED_BIT;
231
 
232
        for( ;; )
233
        {
234
                /* Not very exiting - just delay... */
235
                vTaskDelay( xLED_Delay );
236
 
237
                /* ...set the IO ... */
238
        IO0CLR = mainLED_BIT;
239
 
240
                /* ...delay again... */
241
                vTaskDelay( xLED_Delay );
242
 
243
                /* ...then clear the IO. */
244
                IO0SET = mainLED_BIT;
245
        }
246
}
247
/*-----------------------------------------------------------*/
248
 
249
static void vCheckTask( void *pvParameters )
250
{
251
portBASE_TYPE xErrorOccurred = pdFALSE;
252
portTickType xLastExecutionTime;
253
const char * const pcPassMessage = "PASS\n";
254
const char * const pcFailMessage = "FAIL\n";
255
 
256
        /* Just to remove compiler warnings. */
257
        ( void ) pvParameters;
258
 
259
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
260
        works correctly. */
261
        xLastExecutionTime = xTaskGetTickCount();
262
 
263
        for( ;; )
264
        {
265
                /* Perform this check every mainCHECK_DELAY milliseconds. */
266
                vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
267
 
268
                /* Has an error been found in any task? */
269
 
270
                if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
271
                {
272
                        xErrorOccurred = pdTRUE;
273
                }
274
 
275
                if( xArePollingQueuesStillRunning() != pdTRUE )
276
                {
277
                        xErrorOccurred = pdTRUE;
278
                }
279
 
280
                if( xAreSemaphoreTasksStillRunning() != pdTRUE )
281
                {
282
                        xErrorOccurred = pdTRUE;
283
                }
284
 
285
                if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
286
                {
287
                        xErrorOccurred = pdTRUE;
288
                }
289
 
290
                if( xAreBlockingQueuesStillRunning() != pdTRUE )
291
                {
292
                        xErrorOccurred = pdTRUE;
293
                }
294
 
295
                #if configUSE_PREEMPTION == 1
296
                {
297
                        /* The timing of console output when not using the preemptive
298
                        scheduler causes the block time tests to detect a timing problem. */
299
                        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
300
                        {
301
                                xErrorOccurred = pdTRUE;
302
                        }
303
                }
304
                #endif
305
 
306
                if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
307
                {
308
                        xErrorOccurred = pdTRUE;
309
                }
310
 
311
                /* Send either a pass or fail message.  If an error is found it is
312
                never cleared again. */
313
                if( xErrorOccurred == pdTRUE )
314
                {
315
                        xLED_Delay = mainERROR_LED_DELAY;
316
                        xQueueSend( xPrintQueue, &pcFailMessage, portMAX_DELAY );
317
                }
318
                else
319
                {
320
                        xQueueSend( xPrintQueue, &pcPassMessage, portMAX_DELAY );
321
                }
322
        }
323
}
324
/*-----------------------------------------------------------*/
325
 
326
static void vPrintTask( void *pvParameters )
327
{
328
char *pcMessage;
329
 
330
        /* Just to stop compiler warnings. */
331
        ( void ) pvParameters;
332
 
333
        for( ;; )
334
        {
335
                /* Wait for a message to arrive. */
336
                while( xQueueReceive( xPrintQueue, &pcMessage, portMAX_DELAY ) != pdPASS );
337
 
338
                /* Write the message to the terminal IO. */
339
                #ifndef NDEBUG
340
                        debug_printf( "%s", pcMessage );
341
                #endif
342
        }
343
}
344
/*-----------------------------------------------------------*/
345
 
346
static void vButtonHandlerTask( void *pvParameters )
347
{
348
static signed char cListBuffer[ mainLIST_BUFFER_SIZE ];
349
const signed char *pcList = &( cListBuffer[ 0 ] );
350
const char * const pcHeader = "\nTask          State  Priority  Stack   #\n************************************************";
351
extern void (vButtonISRWrapper) ( void );
352
 
353
        /* Just to stop compiler warnings. */
354
        ( void ) pvParameters;
355
 
356
        /* Configure the interrupt. */
357
        portENTER_CRITICAL();
358
        {
359
                /* Configure P0.14 to generate interrupts. */
360
                PINSEL0 |= mainP0_14__EINT_1;
361
                EXTMODE = mainEINT_1_EDGE_SENSITIVE;
362
                EXTPOLAR = mainEINT_1_FALLING_EDGE_SENSITIVE;
363
 
364
                /* Setup the VIC for EINT 1. */
365
                VICIntSelect &= ~mainEINT_1_VIC_CHANNEL_BIT;
366
                VICIntEnable |= mainEINT_1_VIC_CHANNEL_BIT;
367
                VICVectAddr1 = ( long ) vButtonISRWrapper;
368
                VICVectCntl1 = mainEINT_1_ENABLE_BIT | mainEINT_1_CHANNEL;
369
        }
370
        portEXIT_CRITICAL();
371
 
372
        for( ;; )
373
        {
374
                /* For debouncing, wait a while then clear the semaphore. */
375
                vTaskDelay( mainSHORT_DELAY );
376
                xSemaphoreTake( xButtonSemaphore, mainNO_DELAY );
377
 
378
                /* Wait for an interrupt. */
379
                xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );
380
 
381
                /* Send the column headers to the print task for display. */
382
                xQueueSend( xPrintQueue, &pcHeader, portMAX_DELAY );
383
 
384
                /* Create the list of task states. */
385
                vTaskList( cListBuffer );
386
 
387
                /* Send the task status information to the print task for display. */
388
                xQueueSend( xPrintQueue, &pcList, portMAX_DELAY );
389
        }
390
}
391
/*-----------------------------------------------------------*/
392
 
393
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
394
{
395
        /* Check pcTaskName for the name of the offending task, or pxCurrentTCB
396
        if pcTaskName has itself been corrupted. */
397
        ( void ) pxTask;
398
        ( void ) pcTaskName;
399
        for( ;; );
400
}
401
 
402
 
403
 
404
 
405
 
406
 

powered by: WebSVN 2.1.0

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