OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [MCF5235_GCC/] [demo.c] - Blame information for rev 584

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 584 jeremybenn
/*
2
    FreeRTOS V4.6.1 - Copyright (C) 2003-2006 Richard Barry.
3
    MCF5235 Port - Copyright (C) 2006 Christian Walter.
4
 
5
    This file is part of the FreeRTOS distribution.
6
 
7
    FreeRTOS is free software; you can redistribute it and/or modify
8
    it under the terms of the GNU General Public License** as published by
9
    the Free Software Foundation; either version 2 of the License, or
10
    (at your option) any later version.
11
 
12
    FreeRTOS is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16
 
17
    You should have received a copy of the GNU General Public License
18
    along with FreeRTOS; if not, write to the Free Software
19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 
21
    A special exception to the GPL can be applied should you wish to distribute
22
    a combined work that includes FreeRTOS, without being obliged to provide
23
    the source code for any proprietary components.  See the licensing section
24
    of http://www.FreeRTOS.org for full details of how and when the exception
25
    can be applied.
26
 
27
    ***************************************************************************
28
    ***************************************************************************
29
    *                                                                         *
30
    * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *
31
        *                                                                         *
32
        * This is a concise, step by step, 'hands on' guide that describes both   *
33
        * general multitasking concepts and FreeRTOS specifics. It presents and   *
34
        * explains numerous examples that are written using the FreeRTOS API.     *
35
        * Full source code for all the examples is provided in an accompanying    *
36
        * .zip file.                                                              *
37
    *                                                                         *
38
    ***************************************************************************
39
    ***************************************************************************
40
 
41
        Please ensure to read the configuration and relevant port sections of the
42
        online documentation.
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
/* ------------------------ System includes ------------------------------- */
55
#include <stdlib.h>
56
#include <string.h>
57
 
58
/* ------------------------ FreeRTOS includes ----------------------------- */
59
#include "FreeRTOS.h"
60
#include "task.h"
61
 
62
/* ------------------------ Demo application includes --------------------- */
63
#include "partest.h"
64
#include "flash.h"
65
#include "integer.h"
66
#include "PollQ.h"
67
#include "comtest2.h"
68
#include "semtest.h"
69
#include "flop.h"
70
#include "dynamic.h"
71
#include "BlockQ.h"
72
#include "serial.h"
73
 
74
/* ------------------------ Defines --------------------------------------- */
75
/* Constants for the ComTest tasks. */
76
#define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 38400 )
77
#define mainCOM_TEST_LED        ( -1 )
78
 
79
/* Priorities for the demo application tasks. */
80
#define mainLED_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )
81
#define mainCOM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 2 )
82
#define mainQUEUE_POLL_PRIORITY     ( tskIDLE_PRIORITY + 2 )
83
#define mainCHECK_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )
84
#define mainSEM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 1 )
85
#define mainBLOCK_Q_PRIORITY        ( tskIDLE_PRIORITY + 2 )
86
 
87
/* Interval in which tasks are checked. */
88
#define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )
89
 
90
/* Constants used by the vMemCheckTask() task. */
91
#define mainCOUNT_INITIAL_VALUE     ( ( unsigned long ) 0 )
92
#define mainNO_TASK                 ( 0 )
93
 
94
/* The size of the memory blocks allocated by the vMemCheckTask() task. */
95
#define mainMEM_CHECK_SIZE_1        ( ( size_t ) 51 )
96
#define mainMEM_CHECK_SIZE_2        ( ( size_t ) 52 )
97
#define mainMEM_CHECK_SIZE_3        ( ( size_t ) 151 )
98
 
99
/* ------------------------ Static variables ------------------------------ */
100
xComPortHandle  xSTDComPort = NULL;
101
 
102
/* ------------------------ Static functions ------------------------------ */
103
static          portTASK_FUNCTION( vErrorChecks, pvParameters );
104
static long prvCheckOtherTasksAreStillRunning( unsigned long
105
                                                   ulMemCheckTaskCount );
106
static          portTASK_FUNCTION( vMemCheckTask, pvParameters );
107
 
108
/* ------------------------ Implementation -------------------------------- */
109
int
110
main( int argc, char *argv[] )
111
{
112
    asm volatile    ( "move.w  #0x2000, %sr\n\t" );
113
 
114
    xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
115
 
116
    /* Start the demo/test application tasks. */
117
    vStartIntegerMathTasks( tskIDLE_PRIORITY );
118
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
119
    vStartMathTasks( tskIDLE_PRIORITY );
120
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
121
    vStartDynamicPriorityTasks(  );
122
    vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
123
 
124
    /* Start the check task - which is defined in this file. */
125
    xTaskCreate( vErrorChecks, ( signed char * )"Check", 512, NULL,
126
                 mainCHECK_TASK_PRIORITY, NULL );
127
 
128
    /* Now all the tasks have been started - start the scheduler. */
129
    vTaskStartScheduler(  );
130
 
131
    /* Should never get here! */
132
    return 0;
133
}
134
 
135
 
136
 
137
static
138
portTASK_FUNCTION( vErrorChecks, pvParameters )
139
{
140
    unsigned long ulMemCheckTaskRunningCount;
141
    xTaskHandle     xCreatedTask;
142
 
143
    /* The parameters are not used in this function. */
144
    ( void )pvParameters;
145
 
146
    xSerialPortInitMinimal( mainCOM_TEST_BAUD_RATE, 8 );
147
 
148
    for( ;; )
149
    {
150
        ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
151
        xCreatedTask = mainNO_TASK;
152
 
153
        if( xTaskCreate
154
            ( vMemCheckTask, ( signed char * )"MEM_CHECK",
155
              configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
156
              tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
157
        {
158
            xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
159
        }
160
 
161
        /* Delay until it is time to execute again. */
162
        vTaskDelay( mainCHECK_PERIOD );
163
 
164
        /* Delete the dynamically created task. */
165
        if( xCreatedTask != mainNO_TASK )
166
        {
167
            vTaskDelete( xCreatedTask );
168
        }
169
 
170
        if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) !=
171
            pdPASS )
172
        {
173
            xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
174
        }
175
        else
176
        {
177
            xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
178
        }
179
    }
180
}
181
 
182
static long
183
prvCheckOtherTasksAreStillRunning( unsigned long ulMemCheckTaskCount )
184
{
185
    long        lReturn = ( long ) pdPASS;
186
 
187
    /* Check all the demo tasks (other than the flash tasks) to ensure
188
     * that they are all still running, and that none of them have detected
189
     * an error.
190
     */
191
 
192
    if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )
193
    {
194
        lReturn = ( long ) pdFAIL;
195
    }
196
 
197
    if( xArePollingQueuesStillRunning(  ) != pdTRUE )
198
    {
199
        lReturn = ( long ) pdFAIL;
200
    }
201
 
202
    if( xAreMathsTaskStillRunning(  ) != pdTRUE )
203
    {
204
        lReturn = ( long ) pdFAIL;
205
    }
206
 
207
    if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )
208
    {
209
        lReturn = ( long ) pdFAIL;
210
    }
211
 
212
    if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )
213
    {
214
        lReturn = ( long ) pdFAIL;
215
    }
216
 
217
    if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )
218
    {
219
        lReturn = ( long ) pdFAIL;
220
    }
221
    if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
222
    {
223
        // The vMemCheckTask did not increment the counter - it must
224
        // have failed.
225
        lReturn = ( long ) pdFAIL;
226
    }
227
    return lReturn;
228
}
229
 
230
static void
231
vMemCheckTask( void *pvParameters )
232
{
233
    unsigned long *pulMemCheckTaskRunningCounter;
234
    void           *pvMem1, *pvMem2, *pvMem3;
235
    static long lErrorOccurred = pdFALSE;
236
 
237
    /* This task is dynamically created then deleted during each cycle of the
238
       vErrorChecks task to check the operation of the memory allocator.  Each time
239
       the task is created memory is allocated for the stack and TCB.  Each time
240
       the task is deleted this memory is returned to the heap.  This task itself
241
       exercises the allocator by allocating and freeing blocks.
242
 
243
       The task executes at the idle priority so does not require a delay.
244
 
245
       pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
246
       vErrorChecks() task that this task is still executing without error. */
247
 
248
    pulMemCheckTaskRunningCounter = ( unsigned long * )pvParameters;
249
 
250
    for( ;; )
251
    {
252
        if( lErrorOccurred == pdFALSE )
253
        {
254
            /* We have never seen an error so increment the counter. */
255
            ( *pulMemCheckTaskRunningCounter )++;
256
        }
257
 
258
        /* Allocate some memory - just to give the allocator some extra
259
           exercise.  This has to be in a critical section to ensure the
260
           task does not get deleted while it has memory allocated. */
261
        vTaskSuspendAll(  );
262
        {
263
            pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
264
            if( pvMem1 == NULL )
265
            {
266
                lErrorOccurred = pdTRUE;
267
            }
268
            else
269
            {
270
                memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
271
                vPortFree( pvMem1 );
272
            }
273
        }
274
        xTaskResumeAll(  );
275
 
276
        /* Again - with a different size block. */
277
        vTaskSuspendAll(  );
278
        {
279
            pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
280
            if( pvMem2 == NULL )
281
            {
282
                lErrorOccurred = pdTRUE;
283
            }
284
            else
285
            {
286
                memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
287
                vPortFree( pvMem2 );
288
            }
289
        }
290
        xTaskResumeAll(  );
291
 
292
        /* Again - with a different size block. */
293
        vTaskSuspendAll(  );
294
        {
295
            pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
296
            if( pvMem3 == NULL )
297
            {
298
                lErrorOccurred = pdTRUE;
299
            }
300
            else
301
            {
302
                memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
303
                vPortFree( pvMem3 );
304
            }
305
        }
306
        xTaskResumeAll(  );
307
    }
308
}
309
 
310
void
311
vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
312
{
313
}
314
 
315
void
316
vParTestToggleLED( unsigned portBASE_TYPE uxLED )
317
{
318
}

powered by: WebSVN 2.1.0

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