X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=Demo%2FPC%2Fmain.c;h=0250b1267c9bd4c6b55577a559dcfc349e2c1462;hb=921b32a7bf83d65e25cbeecde3b87b43da084dbb;hp=603c22a9e3a04a45a5a6588ee14a4e31fbe924ee;hpb=6da65e9e6b6ca4cd144f7b982bfb848d64a18ea6;p=freertos
diff --git a/Demo/PC/main.c b/Demo/PC/main.c
index 603c22a9e..0250b1267 100644
--- a/Demo/PC/main.c
+++ b/Demo/PC/main.c
@@ -1,37 +1,54 @@
/*
- FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry.
-
- This file is part of the FreeRTOS.org distribution.
-
- FreeRTOS.org is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- FreeRTOS.org is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with FreeRTOS.org; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- A special exception to the GPL can be applied should you wish to distribute
- a combined work that includes FreeRTOS.org, without being obliged to provide
- the source code for any proprietary components. See the licensing section
- of http://www.FreeRTOS.org for full details of how and when the exception
- can be applied.
-
- ***************************************************************************
- See http://www.FreeRTOS.org for documentation, latest information, license
- and contact details. Please ensure to read the configuration and relevant
- port sections of the online documentation.
-
- Also see http://www.SafeRTOS.com a version that has been certified for use
- in safety critical systems, plus commercial licensing, development and
- support options.
- ***************************************************************************
+ FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
+
+
+ ***************************************************************************
+ * *
+ * FreeRTOS tutorial books are available in pdf and paperback. *
+ * Complete, revised, and edited pdf reference manuals are also *
+ * available. *
+ * *
+ * Purchasing FreeRTOS documentation will not only help you, by *
+ * ensuring you get running as quickly as possible and with an *
+ * in-depth knowledge of how to use FreeRTOS, it will also help *
+ * the FreeRTOS project to continue with its mission of providing *
+ * professional grade, cross platform, de facto standard solutions *
+ * for microcontrollers - completely free of charge! *
+ * *
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
+ * *
+ * Thank you for using FreeRTOS, and thank you for your support! *
+ * *
+ ***************************************************************************
+
+
+ This file is part of the FreeRTOS distribution.
+
+ FreeRTOS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License (version 2) as published by the
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
+ >>>NOTE<<< The modification to the GPL is included to allow you to
+ distribute a combined work that includes FreeRTOS without being obliged to
+ provide the source code for proprietary components outside of the FreeRTOS
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details. You should have received a copy of the GNU General Public
+ License and the FreeRTOS license exception along with FreeRTOS; if not it
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained
+ by writing to Richard Barry, contact details for whom are available on the
+ FreeRTOS WEB site.
+
+ 1 tab == 4 spaces!
+
+ http://www.FreeRTOS.org - Documentation, latest information, license and
+ contact details.
+
+ http://www.SafeRTOS.com - A version that is certified for use in safety
+ critical systems.
+
+ http://www.OpenRTOS.com - Commercial support, development, porting,
+ licensing and training services.
*/
/**
@@ -65,38 +82,6 @@
*
*/
-/*
-Changes from V1.00:
-
- + Prevent the call to kbhit() for debug builds as the debugger seems to
- have problems stepping over the call.
-
-Changes from V1.2.3
-
- + The integer and comtest tasks are now used when the cooperative scheduler
- is being used. Previously they were only used with the preemptive
- scheduler.
-
-Changes from V1.2.6
-
- + Create new tasks as defined by the new demo application file dynamic.c.
-
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- portTickType rather than unsigned portLONG.
-
-Changes from V3.1.1
-
- + The tasks defined in the new file "events.c" are now created and
- monitored for errors.
-
-Changes from V3.2.4
-
- + Now includes the flash co-routine demo rather than the flash task demo.
- This is to demonstrate the co-routine functionality.
-*/
-
#include
#include
#include "FreeRTOS.h"
@@ -120,8 +105,14 @@ Changes from V3.2.4
#include "mevents.h"
#include "crhook.h"
#include "blocktim.h"
+#include "AltBlock.h"
#include "GenQTest.h"
#include "QPeek.h"
+#include "countsem.h"
+#include "AltQTest.h"
+#include "AltPollQ.h"
+#include "AltBlckQ.h"
+#include "RecMutex.h"
/* Priority definitions for the tasks in the demo application. */
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
@@ -133,8 +124,8 @@ Changes from V3.2.4
#define mainSEMAPHORE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
-#define mainPRINT_STACK_SIZE ( ( unsigned portSHORT ) 512 )
-#define mainDEBUG_LOG_BUFFER_SIZE ( ( unsigned portSHORT ) 20480 )
+#define mainPRINT_STACK_SIZE ( ( unsigned short ) 512 )
+#define mainDEBUG_LOG_BUFFER_SIZE ( ( unsigned short ) 20480 )
/* The number of flash co-routines to create. */
#define mainNUM_FLASH_CO_ROUTINES ( 8 )
@@ -153,11 +144,11 @@ static void prvCheckForKeyPresses( void );
/* Buffer used by the trace visualisation utility so only needed if the trace
being used. */
#if configUSE_TRACE_FACILITY == 1
- static portCHAR pcWriteBuffer[ mainDEBUG_LOG_BUFFER_SIZE ];
+ static char pcWriteBuffer[ mainDEBUG_LOG_BUFFER_SIZE ];
#endif
/* Constant definition used to turn on/off the pre-emptive scheduler. */
-static const portSHORT sUsingPreemption = configUSE_PREEMPTION;
+static const short sUsingPreemption = configUSE_PREEMPTION;
/* Start the math tasks appropriate to the build. The Borland port does
not yet support floating point so uses the integer equivalent. */
@@ -166,9 +157,17 @@ static void prvStartMathTasks( void );
/* Check which ever tasks are relevant to this build. */
static portBASE_TYPE prvCheckMathTasksAreStillRunning( void );
+/* Used to demonstrate the "task switched in" callback function. */
+static portBASE_TYPE prvExampleTaskHook( void * pvParameter );
+
+/* Just used to count the number of times the example task callback function is
+called, and the number of times a queue send passes. */
+static unsigned long long uxCheckTaskHookCallCount = 0;
+static unsigned long long uxQueueSendPassedCount = 0;
+
/*-----------------------------------------------------------*/
-portSHORT main( void )
+short main( void )
{
/* Initialise hardware and utilities. */
vParTestInitialise();
@@ -185,7 +184,13 @@ portSHORT main( void )
vStartDynamicPriorityTasks();
vStartMultiEventTasks();
vStartQueuePeekTasks();
-
+ vStartCountingSemaphoreTasks();
+ vStartAltGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
+ vCreateAltBlockTimeTasks();
+ vStartAltBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
+ vStartAltPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
+ vStartRecursiveMutexTasks();
+
/* Create the "Print" task as described at the top of the file. */
xTaskCreate( vErrorChecks, "Print", mainPRINT_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );
@@ -207,18 +212,53 @@ portSHORT main( void )
}
/*-----------------------------------------------------------*/
+static portBASE_TYPE prvExampleTaskHook( void * pvParameter )
+{
+ if( pvParameter != ( void * ) 0xabcd )
+ {
+ /* The parameter did not contain the value we expected, so cause an
+ error to be detected by setting the call count back to zero. */
+ uxCheckTaskHookCallCount = 0;
+ }
+ else
+ {
+ /* Simply increment a number so we know the callback has been executed. */
+ uxCheckTaskHookCallCount++;
+ }
+
+ return 0;
+}
+/*-----------------------------------------------------------*/
+
+void vMainQueueSendPassed( void )
+{
+ /* This is just an example implementation of the "queue send" trace hook. */
+ uxQueueSendPassedCount++;
+}
+/*-----------------------------------------------------------*/
+
static void vErrorChecks( void *pvParameters )
{
portTickType xExpectedWakeTime;
const portTickType xPrintRate = ( portTickType ) 5000 / portTICK_RATE_MS;
-const portLONG lMaxAllowableTimeDifference = ( portLONG ) 0;
+const long lMaxAllowableTimeDifference = ( long ) 0;
portTickType xWakeTime;
-portLONG lTimeDifference;
-const portCHAR *pcReceivedMessage;
-const portCHAR * const pcTaskBlockedTooLongMsg = "Print task blocked too long!\r\n";
+long lTimeDifference;
+const char *pcReceivedMessage;
+const char * const pcTaskBlockedTooLongMsg = "Print task blocked too long!\r\n";
+const char * const pcUnexpectedHookValueMsg = "Task hook has unexpected value!\r\n";
( void ) pvParameters;
+ /* Register our callback function. */
+ vTaskSetApplicationTaskTag( NULL, prvExampleTaskHook );
+
+ /* Just for test purposes. */
+ if( xTaskGetApplicationTaskTag( NULL ) != prvExampleTaskHook )
+ {
+ vPrintDisplayMessage( &pcUnexpectedHookValueMsg );
+ }
+
/* Loop continuously, blocking, then checking all the other tasks are still
running, before blocking once again. This task blocks on the queue of
messages that require displaying so will wake either by its time out expiring,
@@ -245,11 +285,11 @@ const portCHAR * const pcTaskBlockedTooLongMsg = "Print task blocked too long!\r
time we should have unblocked. */
if( xWakeTime > xExpectedWakeTime )
{
- lTimeDifference = ( portLONG ) ( xWakeTime - xExpectedWakeTime );
+ lTimeDifference = ( long ) ( xWakeTime - xExpectedWakeTime );
}
else
{
- lTimeDifference = ( portLONG ) ( xExpectedWakeTime - xWakeTime );
+ lTimeDifference = ( long ) ( xExpectedWakeTime - xWakeTime );
}
if( lTimeDifference > lMaxAllowableTimeDifference )
@@ -283,7 +323,7 @@ const portCHAR * const pcTaskBlockedTooLongMsg = "Print task blocked too long!\r
static void prvCheckForKeyPresses( void )
{
-portSHORT sIn;
+short sIn;
taskENTER_CRITICAL();
#ifdef DEBUG_BUILD
@@ -312,7 +352,7 @@ portSHORT sIn;
break;
case 'e' : {
- unsigned portLONG ulBufferLength;
+ unsigned long ulBufferLength;
ulBufferLength = ulTaskEndTrace();
vWriteBufferToDisk( pcWriteBuffer, ulBufferLength );
}
@@ -328,7 +368,8 @@ portSHORT sIn;
static void prvCheckOtherTasksAreStillRunning( void )
{
-static portSHORT sErrorHasOccurred = pdFALSE;
+static short sErrorHasOccurred = pdFALSE;
+static unsigned long long uxLastHookCallCount = 0, uxLastQueueSendCount = 0;
if( prvCheckMathTasksAreStillRunning() != pdTRUE )
{
@@ -348,12 +389,24 @@ static portSHORT sErrorHasOccurred = pdFALSE;
sErrorHasOccurred = pdTRUE;
}
+ if( xAreAltBlockingQueuesStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Alt blocking queues count unchanged!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
if( xArePollingQueuesStillRunning() != pdTRUE )
{
vDisplayMessage( "Polling queue count unchanged!\r\n" );
sErrorHasOccurred = pdTRUE;
}
+ if( xAreAltPollingQueuesStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Alt polling queue count unchanged!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
if( xIsCreateTaskStillRunning() != pdTRUE )
{
vDisplayMessage( "Incorrect number of tasks running!\r\n" );
@@ -396,18 +449,68 @@ static portSHORT sErrorHasOccurred = pdFALSE;
sErrorHasOccurred = pdTRUE;
}
+ if( xAreAltBlockTimeTestTasksStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Error in fast block time test tasks!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
{
vDisplayMessage( "Error in generic queue test task!\r\n" );
sErrorHasOccurred = pdTRUE;
}
+ if( xAreAltGenericQueueTasksStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Error in fast generic queue test task!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
if( xAreQueuePeekTasksStillRunning() != pdTRUE )
{
vDisplayMessage( "Error in queue peek test task!\r\n" );
sErrorHasOccurred = pdTRUE;
}
+ if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Error in counting semaphore demo task!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
+ if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
+ {
+ vDisplayMessage( "Error in recursive mutex tasks!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+
+ /* The hook function associated with this task is called each time the task
+ is switched in. We therefore expect the number of times the callback
+ function has been executed to have increrment since the last time this
+ function executed. */
+ if( uxCheckTaskHookCallCount <= uxLastHookCallCount )
+ {
+ vDisplayMessage( "Error in task hook call count!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastHookCallCount = uxCheckTaskHookCallCount;
+ }
+
+ /* We would expect some queue sending to occur between calls of this
+ function. */
+ if( uxQueueSendPassedCount <= uxLastQueueSendCount )
+ {
+ vDisplayMessage( "Error in queue send hook call count!\r\n" );
+ sErrorHasOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastQueueSendCount = uxQueueSendPassedCount;
+ }
+
if( sErrorHasOccurred == pdFALSE )
{
vDisplayMessage( "OK " );