2 FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Standard includes. */
\r
57 /* Kernel includes. */
\r
58 #include <FreeRTOS.h>
\r
62 /* Standard demo includes. */
\r
63 #include "partest.h"
\r
66 #include "integer.h"
\r
67 //#include "blocktim.h"
\r
68 #include "semtest.h"
\r
70 #include "GenQTest.h"
\r
72 #include "recmutex.h"
\r
75 /* Priorities at which the tasks are created. */
\r
76 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
77 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
78 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
79 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
80 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
81 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
82 #define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
83 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
84 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
85 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
88 #define mainSTDOUT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 4 )
\r
90 /* File scope variables. */
\r
91 static volatile unsigned long ul1 = 0, ul2 = 0;
\r
92 static xQueueHandle xStdoutQueue = NULL;
\r
94 /* Task function prototypes. */
\r
95 static void prvCheckTask( void *pvParameters );
\r
97 /* Create a queue on which console output strings can be posted, then start the
\r
98 task that processes the queue - printf()'ing each string that is received. */
\r
99 static void prvStartStdoutTask( void );
\r
101 /* Post a message for output by the stdout task. Basically queues the message
\r
102 pointed to by pcTextToPrint for output to stdout in a thread safe manner. */
\r
103 void vMainConsolePrint( const char *pcTextToPrint, portTickType xTicksToWait );
\r
105 /*-----------------------------------------------------------*/
\r
109 /* Start the check task as described at the top of this file. */
\r
110 xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
112 /* Create the standard demo tasks. */
\r
113 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
114 // vCreateBlockTimeTasks();
\r
115 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
116 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
117 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
118 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
119 vStartQueuePeekTasks();
\r
120 vStartRecursiveMutexTasks();
\r
121 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
123 /* Start the scheduler itself. */
\r
124 vTaskStartScheduler();
\r
126 /* Should never get here unless there was not enough heap space to create
\r
127 the idle and other system tasks. */
\r
130 /*-----------------------------------------------------------*/
\r
132 static void prvCheckTask( void *pvParameters )
\r
134 portTickType xNextWakeTime;
\r
135 const portTickType xCycleFrequency = 5000 / portTICK_RATE_MS;
\r
136 char *pcStatusMessage = "OK";
\r
137 long lCycleCount = 0;
\r
139 /* Just to remove compiler warning. */
\r
140 ( void ) pvParameters;
\r
142 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
143 xNextWakeTime = xTaskGetTickCount();
\r
147 /* Place this task in the blocked state until it is time to run again. */
\r
148 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
150 /* Check the standard demo tasks are running without error. */
\r
151 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
153 pcStatusMessage = "Error: IntMath";
\r
155 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
157 pcStatusMessage = "Error: GenQueue";
\r
159 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
161 pcStatusMessage = "Error: QueuePeek";
\r
163 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
165 pcStatusMessage = "Error: BlockQueue";
\r
167 // else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
169 // pcStatusMessage = "Error: BlockTime";
\r
171 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
173 pcStatusMessage = "Error: SemTest";
\r
175 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
177 pcStatusMessage = "Error: PollQueue";
\r
179 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
181 pcStatusMessage = "Error: RecMutex";
\r
183 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
185 pcStatusMessage = "Error: Flop";
\r
188 /* This is the only task that uses stdout so its ok to call printf()
\r
190 printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );
\r
193 /*-----------------------------------------------------------*/
\r
195 void vApplicationIdleHook( void )
\r
197 /* Sleep to reduce CPU load, but don't sleep indefinitely if not using
\r
198 preemption as as nothing will cause a task switch. */
\r
199 #if( configUSE_PREEMPTION != 0 )
\r
201 SleepEx( INFINITE, TRUE );
\r
205 const unsigned long ulMSToSleep = 5;
\r
207 SleepEx( ulMSToSleep, TRUE );
\r
211 /*-----------------------------------------------------------*/
\r
213 void vApplicationMallocFailedHook( void )
\r
215 /* Can be implemented if required, but probably not required in this
\r
216 environment and running this demo. */
\r
218 /*-----------------------------------------------------------*/
\r
220 void vApplicationStackOverflowHook( void )
\r
222 /* Can be implemented if required, but not required in this
\r
223 environment and running this demo. */
\r