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/] [lwIP_MCF5235_GCC/] [demo.c] - Blame information for rev 615

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 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 <stdio.h>
57
#include <string.h>
58
#include <assert.h>
59
 
60
/* ------------------------ FreeRTOS includes ----------------------------- */
61
#include "FreeRTOS.h"
62
#include "task.h"
63
 
64
/* ------------------------ LWIP includes --------------------------------- */
65
#include "lwip/api.h"
66
#include "lwip/tcpip.h"
67
#include "lwip/memp.h"
68
 
69
/* ------------------------ Project includes ------------------------------ */
70
#include "mcf5xxx.h"
71
#include "mcf523x.h"
72
#include "serial.h"
73
 
74
#include "web.h"
75
#include "integer.h"
76
#include "PollQ.h"
77
#include "semtest.h"
78
#include "BlockQ.h"
79
#include "dynamic.h"
80
#include "flop.h"
81
 
82
/* ------------------------ Defines --------------------------------------- */
83
#define mainCOM_TEST_BAUD_RATE      ( ( unsigned long ) 38400 )
84
 
85
/* Priorities for the demo application tasks. */
86
#define mainLED_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )
87
#define mainCOM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 2 )
88
#define mainQUEUE_POLL_PRIORITY     ( tskIDLE_PRIORITY + 2 )
89
#define mainCHECK_TASK_PRIORITY     ( tskIDLE_PRIORITY + 4 )
90
#define mainSEM_TEST_PRIORITY       ( tskIDLE_PRIORITY + 1 )
91
#define mainBLOCK_Q_PRIORITY        ( tskIDLE_PRIORITY + 2 )
92
#define mainWEB_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )
93
#define STACK_DEFAULT               ( 1024 )
94
 
95
/* Interval in which tasks are checked. */
96
#define mainCHECK_PERIOD            ( ( portTickType ) 2000 / portTICK_RATE_MS  )
97
 
98
/* Constants used by the vMemCheckTask() task. */
99
#define mainCOUNT_INITIAL_VALUE     ( ( unsigned long ) 0 )
100
#define mainNO_TASK                 ( 0 )
101
 
102
/* The size of the memory blocks allocated by the vMemCheckTask() task. */
103
#define mainMEM_CHECK_SIZE_1        ( ( size_t ) 51 )
104
#define mainMEM_CHECK_SIZE_2        ( ( size_t ) 52 )
105
#define mainMEM_CHECK_SIZE_3        ( ( size_t ) 151 )
106
 
107
/* ------------------------ Static variables ------------------------------ */
108
xComPortHandle  xSTDComPort = NULL;
109
 
110
/* ------------------------ Static functions ------------------------------ */
111
static          portTASK_FUNCTION( vErrorChecks, pvParameters );
112
static long prvCheckOtherTasksAreStillRunning( unsigned long
113
                                                   ulMemCheckTaskCount );
114
static          portTASK_FUNCTION( vMemCheckTask, pvParameters );
115
 
116
/* ------------------------ Implementation -------------------------------- */
117
int
118
main( int argc, char *argv[] )
119
{
120
    asm volatile    ( "move.w  #0x2000, %sr\n\t" );
121
 
122
    xSTDComPort = xSerialPortInitMinimal( 38400, 8 );
123
    vlwIPInit(  );
124
 
125
    /* Start the demo/test application tasks. */
126
    vStartIntegerMathTasks( tskIDLE_PRIORITY );
127
    vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
128
    //vStartMathTasks( tskIDLE_PRIORITY );
129
    vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
130
    vStartDynamicPriorityTasks(  );
131
    vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
132
 
133
    /* Start the webserver. */
134
    ( void )sys_thread_new( vBasicWEBServer, NULL, mainWEB_TASK_PRIORITY );
135
 
136
    /* Start the check task - which is defined in this file. */
137
    xTaskCreate( vErrorChecks, ( signed char * )"Check", 512, NULL,
138
                 mainCHECK_TASK_PRIORITY, NULL );
139
        /* Now all the tasks have been started - start the scheduler. */
140
    vTaskStartScheduler(  );
141
 
142
    /* Should never get here! */
143
    return 0;
144
}
145
 
146
static
147
portTASK_FUNCTION( vErrorChecks, pvParameters )
148
{
149
    unsigned long ulMemCheckTaskRunningCount;
150
    xTaskHandle     xCreatedTask;
151
 
152
    /* The parameters are not used in this function. */
153
    ( void )pvParameters;
154
 
155
    for( ;; )
156
    {
157
        ulMemCheckTaskRunningCount = mainCOUNT_INITIAL_VALUE;
158
        xCreatedTask = mainNO_TASK;
159
        if( xTaskCreate( vMemCheckTask, ( signed char * )"MEM",
160
                         configMINIMAL_STACK_SIZE, ( void * )&ulMemCheckTaskRunningCount,
161
                         tskIDLE_PRIORITY, &xCreatedTask ) != pdPASS )
162
        {
163
            xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
164
        }
165
        /* Delay until it is time to execute again. */
166
        vTaskDelay( mainCHECK_PERIOD );
167
 
168
        /* Delete the dynamically created task. */
169
        if( xCreatedTask != mainNO_TASK )
170
        {
171
            vTaskDelete( xCreatedTask );
172
        }
173
 
174
        if( prvCheckOtherTasksAreStillRunning( ulMemCheckTaskRunningCount ) != pdPASS )
175
        {
176
            xSerialPutChar( xSTDComPort, 'E', portMAX_DELAY );
177
        }
178
        else
179
        {
180
            xSerialPutChar( xSTDComPort, '.', portMAX_DELAY );
181
        }
182
    }
183
}
184
 
185
static long
186
prvCheckOtherTasksAreStillRunning( unsigned long ulMemCheckTaskCount )
187
{
188
    long        lReturn = ( long ) pdPASS;
189
 
190
    /* Check all the demo tasks (other than the flash tasks) to ensure
191
     * that they are all still running, and that none of them have detected
192
     * an error.
193
     */
194
    if( xAreIntegerMathsTaskStillRunning(  ) != pdTRUE )
195
    {
196
        lReturn = ( long ) pdFAIL;
197
    }
198
 
199
    if( xArePollingQueuesStillRunning(  ) != pdTRUE )
200
    {
201
        lReturn = ( long ) pdFAIL;
202
    }
203
 
204
    if( xAreSemaphoreTasksStillRunning(  ) != pdTRUE )
205
    {
206
        lReturn = ( long ) pdFAIL;
207
    }
208
 
209
    if( xAreDynamicPriorityTasksStillRunning(  ) != pdTRUE )
210
    {
211
        lReturn = ( long ) pdFAIL;
212
    }
213
 
214
    if( xAreBlockingQueuesStillRunning(  ) != pdTRUE )
215
    {
216
        lReturn = ( long ) pdFAIL;
217
    }
218
 
219
    if( ulMemCheckTaskCount == mainCOUNT_INITIAL_VALUE )
220
    {
221
        /* The vMemCheckTask did not increment the counter - it must
222
         * have failed.
223
         */
224
        lReturn = ( long ) pdFAIL;
225
    }
226
    return lReturn;
227
}
228
 
229
static void
230
vMemCheckTask( void *pvParameters )
231
{
232
    unsigned long *pulMemCheckTaskRunningCounter;
233
    void           *pvMem1, *pvMem2, *pvMem3;
234
    static long lErrorOccurred = pdFALSE;
235
 
236
    /* This task is dynamically created then deleted during each cycle of the
237
       vErrorChecks task to check the operation of the memory allocator.  Each time
238
       the task is created memory is allocated for the stack and TCB.  Each time
239
       the task is deleted this memory is returned to the heap.  This task itself
240
       exercises the allocator by allocating and freeing blocks.
241
 
242
       The task executes at the idle priority so does not require a delay.
243
 
244
       pulMemCheckTaskRunningCounter is incremented each cycle to indicate to the
245
       vErrorChecks() task that this task is still executing without error. */
246
 
247
    pulMemCheckTaskRunningCounter = ( unsigned long * )pvParameters;
248
 
249
    for( ;; )
250
    {
251
        if( lErrorOccurred == pdFALSE )
252
        {
253
            /* We have never seen an error so increment the counter. */
254
            ( *pulMemCheckTaskRunningCounter )++;
255
        }
256
 
257
        /* Allocate some memory - just to give the allocator some extra
258
           exercise.  This has to be in a critical section to ensure the
259
           task does not get deleted while it has memory allocated. */
260
        vTaskSuspendAll(  );
261
        {
262
            pvMem1 = pvPortMalloc( mainMEM_CHECK_SIZE_1 );
263
            if( pvMem1 == NULL )
264
            {
265
                lErrorOccurred = pdTRUE;
266
            }
267
            else
268
            {
269
                memset( pvMem1, 0xaa, mainMEM_CHECK_SIZE_1 );
270
                vPortFree( pvMem1 );
271
            }
272
        }
273
        xTaskResumeAll(  );
274
 
275
        /* Again - with a different size block. */
276
        vTaskSuspendAll(  );
277
        {
278
            pvMem2 = pvPortMalloc( mainMEM_CHECK_SIZE_2 );
279
            if( pvMem2 == NULL )
280
            {
281
                lErrorOccurred = pdTRUE;
282
            }
283
            else
284
            {
285
                memset( pvMem2, 0xaa, mainMEM_CHECK_SIZE_2 );
286
                vPortFree( pvMem2 );
287
            }
288
        }
289
        xTaskResumeAll(  );
290
 
291
        /* Again - with a different size block. */
292
        vTaskSuspendAll(  );
293
        {
294
            pvMem3 = pvPortMalloc( mainMEM_CHECK_SIZE_3 );
295
            if( pvMem3 == NULL )
296
            {
297
                lErrorOccurred = pdTRUE;
298
            }
299
            else
300
            {
301
                memset( pvMem3, 0xaa, mainMEM_CHECK_SIZE_3 );
302
                vPortFree( pvMem3 );
303
            }
304
        }
305
        xTaskResumeAll(  );
306
    }
307
}

powered by: WebSVN 2.1.0

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