From: rtel Date: Thu, 19 Dec 2013 13:40:37 +0000 (+0000) Subject: Update GCC/Eclipse Win32 simulator port to make better use of Eclipse resource filter... X-Git-Tag: V8.0.0rc1~26 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=01417dac79872d5bcca3d3519df1622bd3cde71d;p=freertos Update GCC/Eclipse Win32 simulator port to make better use of Eclipse resource filters and match the functionality of the MSVC equivalent. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2135 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Demo/WIN32-MingW/.cproject b/FreeRTOS/Demo/WIN32-MingW/.cproject index 4d41c2f22..04ec5c3bc 100644 --- a/FreeRTOS/Demo/WIN32-MingW/.cproject +++ b/FreeRTOS/Demo/WIN32-MingW/.cproject @@ -1,8 +1,8 @@ - - + + @@ -12,301 +12,68 @@ - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + diff --git a/FreeRTOS/Demo/WIN32-MingW/.project b/FreeRTOS/Demo/WIN32-MingW/.project index 3533b8343..4d3dee903 100644 --- a/FreeRTOS/Demo/WIN32-MingW/.project +++ b/FreeRTOS/Demo/WIN32-MingW/.project @@ -9,50 +9,6 @@ org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/RTOSDemo/Debug} - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - @@ -67,4 +23,205 @@ org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + FreeRTOS+Trace Recorder + 2 + FREERTOS_ROOT/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace + + + FreeRTOS_Source + 2 + FREERTOS_ROOT/FreeRTOS/Source + + + Standard_Demo_Tasks + 2 + FREERTOS_ROOT/FreeRTOS/Demo/Common/Minimal + + + Standard_Demo_Tasks/Include + 2 + FREERTOS_ROOT/FreeRTOS/Demo/Common/include + + + + + 1387372952208 + FreeRTOS+Trace Recorder + 10 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-ConfigurationTemplate + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-BlockQ.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-blocktim.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-countsem.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-death.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-dynamic.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-EventGroupsDemo.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-flop.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-GenQTest.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-Integer.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-PollQ.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-QPeek.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-QueueOverwrite.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-QueueSet.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-semtest.c + + + + 0 + Standard_Demo_Tasks + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-timerdemo.c + + + + 0 + FreeRTOS_Source/portable + 9 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-MSVC-MingW + + + + 0 + FreeRTOS_Source/portable + 9 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-MemMang + + + + 0 + FreeRTOS_Source/portable/MemMang + 5 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-heap_4.c + + + + + + FREERTOS_ROOT + $%7BPARENT-3-PROJECT_LOC%7D + + diff --git a/FreeRTOS/Demo/WIN32-MingW/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/FreeRTOS/Demo/WIN32-MingW/.settings/org.eclipse.cdt.managedbuilder.core.prefs index 1e00b8157..a36a15594 100644 --- a/FreeRTOS/Demo/WIN32-MingW/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ b/FreeRTOS/Demo/WIN32-MingW/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -1,12 +1,11 @@ -#Sun Nov 21 18:36:02 GMT 2010 eclipse.preferences.version=1 -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/CPATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/C_INCLUDE_PATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/LIBRARY_PATH/delimiter=; -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.184448914/appendContributed=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/CPATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/CPATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/C_INCLUDE_PATH/delimiter=; +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/C_INCLUDE_PATH/operation=remove +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/append=true +environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/LIBRARY_PATH/delimiter=; +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.396692239/appendContributed=true diff --git a/FreeRTOS/Demo/WIN32-MingW/CreateProjectDirectoryStructure.bat b/FreeRTOS/Demo/WIN32-MingW/CreateProjectDirectoryStructure.bat deleted file mode 100644 index a1986dc04..000000000 --- a/FreeRTOS/Demo/WIN32-MingW/CreateProjectDirectoryStructure.bat +++ /dev/null @@ -1,54 +0,0 @@ -REM This file should be executed from the command line prior to the first -REM build. It will be necessary to refresh the Eclipse project once the -REM .bat file has been executed (normally just press F5 to refresh). - -REM Copies all the required files from their location within the standard -REM FreeRTOS directory structure to under the Eclipse project directory. -REM This permits the Eclipse project to be used in 'managed' mode and without -REM having to setup any linked resources. - -REM Have the files already been copied? -IF EXIST FreeRTOS Goto END - - REM Create the required directory structure. - MD FreeRTOS - MD FreeRTOS\include - MD FreeRTOS\portable - MD FreeRTOS\portable\MSVC-MingW - MD FreeRTOS\portable\MemMang - MD DemoTasks - MD DemoTasks\include - - REM Copy the core kernel files. - copy ..\..\Source\tasks.c FreeRTOS - copy ..\..\Source\queue.c FreeRTOS - copy ..\..\Source\list.c FreeRTOS - - REM Copy the common header files - - copy ..\..\Source\include\*.* FreeRTOS\include - - REM Copy the portable layer files - copy ..\..\Source\portable\MSVC-MingW\*.* FreeRTOS\portable\MSVC-MingW - - REM Copy the basic memory allocation files - copy ..\..\Source\portable\MemMang\heap_3.c FreeRTOS\portable\MemMang - - REM Copy the common demo files that are used by this demo - copy ..\Common\include\BlockQ.h DemoTasks\include - copy ..\Common\include\integer.h DemoTasks\include - copy ..\Common\include\semtest.h DemoTasks\include - copy ..\Common\include\PollQ.h DemoTasks\include - copy ..\Common\include\GenQTest.h DemoTasks\include - copy ..\Common\include\QPeek.h DemoTasks\include - copy ..\Common\include\flop.h DemoTasks\include - copy ..\Common\include\recmutex.h DemoTasks\include - copy ..\Common\Minimal\BlockQ.c DemoTasks - copy ..\Common\Minimal\integer.c DemoTasks - copy ..\Common\Minimal\semtest.c DemoTasks - copy ..\Common\Minimal\PollQ.c DemoTasks - copy ..\Common\Minimal\GenQTest.c DemoTasks - copy ..\Common\Minimal\QPeek.c DemoTasks - copy ..\Common\Minimal\flop.c DemoTasks - -: END \ No newline at end of file diff --git a/FreeRTOS/Demo/WIN32-MingW/DemosModifiedForLowTickRate/recmutex.c b/FreeRTOS/Demo/WIN32-MingW/DemosModifiedForLowTickRate/recmutex.c index ec904707f..67a6cb423 100644 --- a/FreeRTOS/Demo/WIN32-MingW/DemosModifiedForLowTickRate/recmutex.c +++ b/FreeRTOS/Demo/WIN32-MingW/DemosModifiedForLowTickRate/recmutex.c @@ -137,7 +137,7 @@ static volatile unsigned portBASE_TYPE uxControllingCycles = 0, uxBlockingCycles /* Handles of the two higher priority tasks, required so they can be resumed (unsuspended). */ -static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle; +static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle, xPollingTaskHandle; /*-----------------------------------------------------------*/ @@ -160,7 +160,7 @@ void vStartRecursiveMutexTasks( void ) { xTaskCreate( prvRecursiveMutexControllingTask, ( signed portCHAR * ) "Rec1Ctrl", configMINIMAL_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle ); xTaskCreate( prvRecursiveMutexBlockingTask, ( signed portCHAR * ) "Rec2Blck", configMINIMAL_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle ); - xTaskCreate( prvRecursiveMutexPollingTask, ( signed portCHAR * ) "Rec3Poll", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL ); + xTaskCreate( prvRecursiveMutexPollingTask, ( signed portCHAR * ) "Rec3Poll", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, &xPollingTaskHandle ); } } /*-----------------------------------------------------------*/ @@ -223,6 +223,10 @@ unsigned portBASE_TYPE ux; { xErrorOccurred = pdTRUE; } + + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif } /* Having given it back the same number of times as it was taken, we @@ -329,10 +333,17 @@ static void prvRecursiveMutexPollingTask( void *pvParameters ) block indefinitely when it attempts to obtain the mutex, the Controlling task will only block for a fixed period and an error will be latched if the polling task has not returned the - mutex by the time this fixed period has expired. */ + mutex by the time this fixed period has expired. */ vTaskResume( xBlockingTaskHandle ); - vTaskResume( xControllingTaskHandle ); - + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif + + vTaskResume( xControllingTaskHandle ); + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif + /* The other two tasks should now have executed and no longer be suspended. */ if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) ) @@ -345,6 +356,10 @@ static void prvRecursiveMutexPollingTask( void *pvParameters ) { xErrorOccurred = pdTRUE; } + + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif } } diff --git a/FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h b/FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h index ee2738b40..0cb8c9826 100644 --- a/FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h @@ -67,13 +67,7 @@ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H -/* - * The following #error directive is to remind users that a batch file must be - * executed prior to this project being built. The batch file *cannot* be - * executed from within the IDE! Once it has been executed, re-open or refresh - * the Eclipse project and remove the #error line below. - */ -#error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above. +#include /*----------------------------------------------------------- * Application specific definitions. @@ -87,43 +81,71 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 1 -#define configUSE_TICK_HOOK 0 -#define configTICK_RATE_HZ ( 1000 ) /* Note true real time behaviour cannot be achieved in this simulated environment. */ -#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 20 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ -#define configTOTAL_HEAP_SIZE ( ( size_t ) 0 ) /* This parameter has no effect when heap_3.c is included in the project. */ +#define configUSE_TICK_HOOK 1 +#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 50 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 20 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 12 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 -#define configUSE_CO_ROUTINES 0 #define configUSE_MUTEXES 1 -#define configGENERATE_RUN_TIME_STATS 0 #define configCHECK_FOR_STACK_OVERFLOW 0 #define configUSE_RECURSIVE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 0 +#define configQUEUE_REGISTRY_SIZE 20 #define configUSE_MALLOC_FAILED_HOOK 1 -#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_APPLICATION_TASK_TAG 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 1 +#define configUSE_QUEUE_SETS 1 -#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 7 ) -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY 2 +#define configTIMER_QUEUE_LENGTH 20 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +#define configMAX_PRIORITIES ( 7 ) +/* Run time stats gathering definitions. */ +unsigned long ulGetRunTimeCounterValue( void ); +void vConfigureTimerForRunTimeStats( void ); +#define configGENERATE_RUN_TIME_STATS 1 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats() +#define portGET_RUN_TIME_COUNTER_VALUE() ulGetRunTimeCounterValue() /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 +#define configUSE_CO_ROUTINES 1 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_xTaskGetSchedulerState 1 - +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_pcTaskGetTaskName 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xSemaphoreGetMutexHolder 1 +#define INCLUDE_xTimerPendCallbackFromISR 1 + +/* Standard assert semantics. */ +extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName ); +#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __LINE__, __FILE__ ) + +/* configUSE_PORT_OPTIMISED_TASK_SELECTION is only available in the MSVC +version of the Win32 simulator projects. It will be ignored in the GCC +version. */ +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 + +/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */ +#include "trcKernelPort.h" #endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS/Demo/WIN32-MingW/Run-time-stats-utils.c b/FreeRTOS/Demo/WIN32-MingW/Run-time-stats-utils.c new file mode 100644 index 000000000..75865a913 --- /dev/null +++ b/FreeRTOS/Demo/WIN32-MingW/Run-time-stats-utils.c @@ -0,0 +1,140 @@ +/* + FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + 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. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +/* + * Utility functions required to gather run time statistics. See: + * http://www.freertos.org/rtos-run-time-stats.html + * + * Note that this is a simulated port, where simulated time is a lot slower than + * real time, therefore the run time counter values have no real meaningful + * units. + * + * Also note that it is assumed this demo is going to be used for short periods + * of time only, and therefore timer overflows are not handled. +*/ + +/* FreeRTOS includes. */ +#include + +/* FreeRTOS+Trace includes. */ +#include "trcUser.h" + +/* Variables used in the creation of the run time stats time base. Run time +stats record how much time each task spends in the Running state. */ +static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundedthMillisecond = 0LL; + +/*-----------------------------------------------------------*/ + +void vConfigureTimerForRunTimeStats( void ) +{ +LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue; + + /* Initialise the variables used to create the run time stats time base. + Run time stats record how much time each task spends in the Running + state. */ + + if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 ) + { + llTicksPerHundedthMillisecond = 1; + } + else + { + /* How many times does the performance counter increment in 1/100th + millisecond. */ + llTicksPerHundedthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL; + + /* What is the performance counter value now, this will be subtracted + from readings taken at run time. */ + QueryPerformanceCounter( &liInitialRunTimeValue ); + llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart; + } +} +/*-----------------------------------------------------------*/ + +unsigned long ulGetRunTimeCounterValue( void ) +{ +LARGE_INTEGER liCurrentCount; +unsigned long ulReturn; + + /* What is the performance counter value now? */ + QueryPerformanceCounter( &liCurrentCount ); + + /* Subtract the performance counter value reading taken when the + application started to get a count from that reference point, then + scale to (simulated) 1/100ths of a millisecond. */ + if( llTicksPerHundedthMillisecond == 0 ) + { + /* The trace macros are probably calling this function before the + scheduler has been started. */ + ulReturn = 0; + } + else + { + ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundedthMillisecond ); + } + + return ulReturn; +} +/*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcConfig.h b/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcConfig.h new file mode 100644 index 000000000..7a38d67ae --- /dev/null +++ b/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcConfig.h @@ -0,0 +1,510 @@ +/******************************************************************************* + * Tracealyzer v2.4.1 Recorder Library + * Percepio AB, www.percepio.com + * + * trcConfig.h + * + * Configuration parameters for the trace recorder library. Before using the + * trace recorder library, please check that the default settings are + * appropriate for your system, and if necessary adjust these. Most likely, you + * will need to adjust the NTask, NISR, NQueue, NMutex and NSemaphore values to + * reflect the number of such objects in your system. These may be + * over-approximated, although larger values values implies more RAM usage. + * + * Terms of Use + * This software is copyright Percepio AB. The recorder library is free for + * use together with Percepio products. You may distribute the recorder library + * in its original form, including modifications in trcHardwarePort.c/.h + * given that these modification are clearly marked as your own modifications + * and documented in the initial comment section of these source files. + * This software is the intellectual property of Percepio AB and may not be + * sold or in other ways commercially redistributed without explicit written + * permission by Percepio AB. + * + * Disclaimer + * The trace tool and recorder library is being delivered to you AS IS and + * Percepio AB makes no warranty as to its use or performance. Percepio AB does + * not and cannot warrant the performance or results you may obtain by using the + * software or documentation. Percepio AB make no warranties, express or + * implied, as to noninfringement of third party rights, merchantability, or + * fitness for any particular purpose. In no event will Percepio AB, its + * technology partners, or distributors be liable to you for any consequential, + * incidental or special damages, including any lost profits or lost savings, + * even if a representative of Percepio AB has been advised of the possibility + * of such damages, or for any claim by any third party. Some jurisdictions do + * not allow the exclusion or limitation of incidental, consequential or special + * damages, or the exclusion of implied warranties or limitations on how long an + * implied warranty may last, so the above limitations may not apply to you. + * + * Copyright Percepio AB, 2013. + * www.percepio.com + ******************************************************************************/ + +#ifndef TRCCONFIG_H +#define TRCCONFIG_H + +#include + +/******************************************************************************* + * CONFIGURATION RELATED TO CAPACITY AND ALLOCATION + ******************************************************************************/ + +/******************************************************************************* + * EVENT_BUFFER_SIZE + * + * Macro which should be defined as an integer value. + * + * This defines the capacity of the event buffer, i.e., the number of records + * it may store. Each registered event typically use one record (4 byte), but + * vTracePrintF may use multiple records depending on the number of data args. + ******************************************************************************/ + +#define EVENT_BUFFER_SIZE 100000 /* Adjust wrt. to available RAM */ + + +/******************************************************************************* + * USE_LINKER_PRAGMA + * + * Macro which should be defined as an integer value, default is 0. + * + * If this is 1, the header file "recorderdata_linker_pragma.h" is included just + * before the declaration of RecorderData (in trcBase.c), i.e., the trace data + * structure. This allows the user to specify a pragma with linker options. + * + * Example (for IAR Embedded Workbench and NXP LPC17xx): + * #pragma location="AHB_RAM_MEMORY" + * + * This example instructs the IAR linker to place RecorderData in another RAM + * bank, the AHB RAM. This can also be used for other compilers with a similar + * pragmas for linker options. + * + * Note that this only applies if using static allocation, see below. + ******************************************************************************/ + +#define USE_LINKER_PRAGMA 0 + + +/******************************************************************************* + * SYMBOL_TABLE_SIZE + * + * Macro which should be defined as an integer value. + * + * This defines the capacity of the symbol table, in bytes. This symbol table + * stores User Events labels and names of deleted tasks, queues, or other kernel + * objects. Note that the names of active objects not stored here but in the + * Object Table. Thus, if you don't use User Events or delete any kernel + * objects you set this to zero (0) to minimize RAM usage. + ******************************************************************************/ +#define SYMBOL_TABLE_SIZE 5000 + +/******************************************************************************* + * USE_SEPARATE_USER_EVENT_BUFFER + * + * Macro which should be defined as an integer value. + * Default is zero (0). + * + * This enables and disables the use of the separate user event buffer. + * + * Note: When using the separate user event buffer, you may get an artificial + * task instance named "Unknown actor". This is added as a placeholder when the + * user event history is longer than the task scheduling history. + ******************************************************************************/ +#define USE_SEPARATE_USER_EVENT_BUFFER 0 + +/******************************************************************************* + * USER_EVENT_BUFFER_SIZE + * + * Macro which should be defined as an integer value. + * + * This defines the capacity of the user event buffer, in number of slots. + * A single user event can use between 1 and X slots, depending on the data. + * + * Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1. + ******************************************************************************/ +#define USER_EVENT_BUFFER_SIZE 500 + +/******************************************************************************* + * USER_EVENT_CHANNELS + * + * Macro which should be defined as an integer value. + * + * This defines the number of allowed user event channels. + * + * Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1. + ******************************************************************************/ +#define CHANNEL_FORMAT_PAIRS 32 + +/******************************************************************************* + * NTask, NISR, NQueue, NSemaphore, NMutex + * + * A group of Macros which should be defined as an integer value of zero (0) + * or larger. + * + * This defines the capacity of the Object Property Table - the maximum number + * of objects active at any given point within each object class. + * + * NOTE: In case objects are deleted and created during runtime, this setting + * does not limit the total amount of objects, only the number of concurrently + * active objects. + * + * Using too small values will give an error message through the vTraceError + * routine, which makes the error message appear when opening the trace data + * in Tracealyzer. If you are using the recorder status monitor task, + * any error messages are displayed in console prints, assuming that the + * print macro has been defined properly (vConsolePrintMessage). + * + * It can be wise to start with very large values for these constants, + * unless you are very confident on these numbers. Then do a recording and + * check the actual usage in Tracealyzer. This is shown by selecting + * View -> Trace Details -> Resource Usage -> Object Table + * + * NOTE 2: Remember to account for all tasks created by the kernel, such as the + * IDLE task, timer task, and any tasks created by other 3rd party + * software components, such as communication stacks. The recorder also has an + * optional monitor task to account for, if this is used. + * Moreover, one task slot is used to indicate "(startup)", i.e., a fictive + * task that represent the time before the scheduler starts. + * NTask should thus be at least 2-3 slots larger than your application task count. + * + ******************************************************************************/ +#define NTask 100 +#define NISR 20 +#define NQueue 60 +#define NSemaphore 60 +#define NMutex 60 + +/* Maximum object name length for each class (includes zero termination) */ +#define NameLenTask 15 +#define NameLenISR 15 +#define NameLenQueue 15 +#define NameLenSemaphore 15 +#define NameLenMutex 15 + +/****************************************************************************** + * TRACE_DESCRIPTION + * + * Macro which should be defined as a string. + * + * This string is stored in the trace and displayed in Tracealyzer. Can be + * used to store, e.g., system version or build date. This is also used to store + * internal error messages from the recorder, which if occurs overwrites the + * value defined here. This may be maximum 256 chars. + *****************************************************************************/ +#define TRACE_DESCRIPTION "Tracealyzer Recorder Test Program" + +/****************************************************************************** + * TRACE_DESCRIPTION_MAX_LENGTH + * + * The maximum length (including zero termination) for the TRACE_DESCRIPTION + * string. Since this string also is used for internal error messages from the + * recorder do not make it too short, as this may truncate the error messages. + * Default is 80. + * Maximum allowed length is 256 - the trace will fail to load if longer. + *****************************************************************************/ +#define TRACE_DESCRIPTION_MAX_LENGTH 80 + + +/****************************************************************************** + * TRACE_DATA_ALLOCATION + * + * This defines how to allocate the recorder data structure, i.e., using a + * static declaration or using a dynamic allocation in runtime (malloc). + * + * Should be one of these two options: + * - TRACE_DATA_ALLOCATION_STATIC (default) + * - TRACE_DATA_ALLOCATION_DYNAMIC + * + * Using static allocation has the benefits of compile-time errors if the buffer + * is too large (too large constants in trcConfig.h) and no need to call the + * initialization routine (xTraceInitTraceData). + * + * Using dynamic allocation may give more flexibility in some cases. + *****************************************************************************/ + +#define TRACE_DATA_ALLOCATION TRACE_DATA_ALLOCATION_STATIC + + +/****************************************************************************** + * CONFIGURATION REGARDING WHAT CODE/FEATURES TO INCLUDE + *****************************************************************************/ + +/****************************************************************************** + * USE_TRACE_ASSERT + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 0. + * + * If this is one (1), the TRACE_ASSERT macro will verify that a condition is + * true. If the condition is false, vTraceError() will be called. + *****************************************************************************/ +#define USE_TRACE_ASSERT 1 + +/****************************************************************************** + * INCLUDE_FLOAT_SUPPORT + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * If this is zero (0), all references to floating point values are removed, + * in case floating point values are not supported by the platform used. + * Floating point values are only used in vTracePrintF and its subroutines, to + * store float (%f) or double (%lf) argments. + * + * Note: vTracePrintF can still be used with integer and string arguments in + * either case. + *****************************************************************************/ +#define INCLUDE_FLOAT_SUPPORT 0 + +/****************************************************************************** + * INCLUDE_USER_EVENTS + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * If this is zero (0) the code for creating User Events is excluded to + * reduce code size. User Events are application-generated events, like + * "printf" but for the trace log instead of console output. User Events are + * much faster than a printf and can therefore be used in timing critical code. + * See vTraceUserEvent() and vTracePrintF() in trcUser.h + * + * Note that Tracealyzer Standard Edition or Professional Edition is required + * for User Events, they are not displayed in Tracealyzer Free Edition. + *****************************************************************************/ +#define INCLUDE_USER_EVENTS 1 + +/***************************************************************************** + * INCLUDE_READY_EVENTS + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * If this is zero (0), the code for recording Ready events is + * excluded. Note, this will make it impossible to calculate the correct + * response times. + *****************************************************************************/ +#define INCLUDE_READY_EVENTS 1 + +/***************************************************************************** + * INCLUDE_NEW_TIME_EVENTS + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 0. + * + * If this is zero (1), events will be generated whenever the os clock is + * increased. + *****************************************************************************/ +#define INCLUDE_NEW_TIME_EVENTS 0 + +/***************************************************************************** + * INCLUDE_ISR_TRACING + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * If this is zero (0), the code for recording Interrupt Service Routines is + * excluded to reduce code size. + * + * Note, if the kernel has no central interrupt dispatcher, recording ISRs + * require that you insert calls to vTraceStoreISRBegin and vTraceStoreISREnd + * in your interrupt handlers. + *****************************************************************************/ +#define INCLUDE_ISR_TRACING 1 + +/****************************************************************************** + * INCLUDE_OBJECT_DELETE + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * This must be enabled (1) if tasks, queues or other + * traced kernel objects are deleted at runtime. If no deletes are made, this + * can be set to 0 in order to exclude the delete-handling code. + *****************************************************************************/ +#define INCLUDE_OBJECT_DELETE 0 + +/****************************************************************************** + * CONFIGURATION RELATED TO BEHAVIOR + *****************************************************************************/ + +/****************************************************************************** + * TRACE_RECORDER_STORE_MODE + * + * Macro which should be defined as one of: + * - TRACE_STORE_MODE_RING_BUFFER + * - TRACE_STORE_MODE_STOP_WHEN_FULL + * Default is TRACE_STORE_MODE_RING_BUFFER. + * + * With TRACE_RECORDER_STORE_MODE set to TRACE_STORE_MODE_RING_BUFFER, the events are + * stored in a ring buffer, i.e., where the oldest events are overwritten when + * the buffer becomes full. This allows you to get the last events leading up + * to an interesting state, e.g., an error, without having a large trace buffer + * for string the whole run since startup. In this mode, the recorder can run + * "forever" as the buffer never gets full, i.e., in the sense that it always + * has room for more events. + * + * To fetch the trace in mode TRACE_STORE_MODE_RING_BUFFER, you need to first halt the + * system using your debugger and then do a RAM dump, or to explicitly stop the + * recorder using vTraceStop() and then store/upload the trace data using a + * task that you need to provide yourself. The trace data is found in the struct + * RecorderData, initialized in trcBase.c. + * + * Note that, if you upload the trace using a RAM dump, i.e., when the system is + * halted on a breakpoint or by a debugger command, there is no need to stop the + * recorder first. + * + * When TRACE_RECORDER_STORE_MODE is TRACE_STORE_MODE_STOP_WHEN_FULL, the recording is + * stopped when the buffer becomes full. When the recorder stops itself this way + * vTracePortEnd() is called which allows for custom actions, such as triggering + * a task that stores the trace buffer, i.e., in case taking a RAM dump + * using an on-chip debugger is not possible. In the Windows port, vTracePortEnd + * saves the trace to file directly, but this is not recommended in a real-time + * system since the scheduler is blocked during the processing of vTracePortEnd. + *****************************************************************************/ + +#define TRACE_RECORDER_STORE_MODE TRACE_STORE_MODE_RING_BUFFER + +/****************************************************************************** + * STOP_AFTER_N_EVENTS + * + * Macro which should be defined as an integer value, or not defined. + * Default is -1 + * + * STOP_AFTER_N_EVENTS is intended for tests of the ring buffer mode (when + * RECORDER_STORE_MODE is STORE_MODE_RING_BUFFER). It stops the recording when + * the specified number of events has been observed. This value can be larger + * than the buffer size, to allow for test of the "wrapping around" that occurs + * in ring buffer mode . A negative value (or no definition of this macro) + * disables this feature. + *****************************************************************************/ +#define STOP_AFTER_N_EVENTS -1 + +/****************************************************************************** + * USE_IMPLICIT_IFE_RULES + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 1. + * + * ### Instance Finish Events (IFE) ### + * + * For tasks with "infinite" main loops (non-terminating tasks), the concept + * of a task instance has no clear definition, it is an application-specific + * thing. Tracealyzer allows you to define Instance Finish Events (IFEs), + * which marks the point in a cyclic task when the "task instance" ends. + * The IFE is a blocking kernel call, typically in the main loop of a task + * which typically reads a message queue, waits for a semaphore or performs + * an explicit delay. + * + * If USE_IMPLICIT_IFE_RULES is one (1), the kernel macros (trcKernelPort.h) + * will define what kernel calls are considered by default to be IFEs. + * + * However, Implicit IFEs only applies to blocking kernel calls. If a + * service reads a message without blocking, it does not create a new + * instance since no blocking occurred. + * + * Moreover, the actual IFE might sometimes be another blocking call. We + * therefore allow for user-defined Explicit IFEs by calling + * + * vTraceTaskInstanceIsFinished() + * + * right before the kernel call considered as IFE. This does not create an + * additional event but instead stores the service code and object handle + * of the IFE call as properties of the task. + * + * If using Explicit IFEs and the task also calls an Implicit IFE, this may + * result in additional incorrect task instances. + * This is solved by disabling the Implicit IFEs for the task, by adding + * a call to + * + * vTraceTaskSkipDefaultInstanceFinishedEvents() + * + * in the very beginning of that task. This allows you to combine Explicit IFEs + * for some tasks with Implicit IFEs for the rest of the tasks, if + * USE_IMPLICIT_IFE_RULES is 1. + * + * By setting USE_IMPLICIT_IFE_RULES to zero (0), the implicit IFEs are disabled + * for all tasks. Tasks will then be considered to have a single instance only, + * covering all execution fragments, unless you define an explicit IFE in each + * task by calling vTraceTaskInstanceIsFinished before the blocking call. + *****************************************************************************/ +#define USE_IMPLICIT_IFE_RULES 1 + +/****************************************************************************** + * INCLUDE_SAVE_TO_FILE + * + * Macro which should be defined as either zero (0) or one (1). + * Default is 0. + * + * If enabled (1), the recorder will include code for saving the trace + * to a local file system. + ******************************************************************************/ +#ifdef WIN32 + #define INCLUDE_SAVE_TO_FILE 1 +#else + #define INCLUDE_SAVE_TO_FILE 0 +#endif + +/****************************************************************************** + * TRACE_PROGRESS_MONITOR_TASK_PRIORITY + * + * Macro which sets the priority of the "recorder status monitor" task. + * + * This task, vTraceMonitorTask in trcUser.c, periodically writes + * the recorder status using the vTraceConsoleMessage macro, which is to + * be mapped to your console "printf" routine. The task is named TraceMon but + * is intentionally excluded from the demo trace. + * + * Default is tskIDLE_PRIORITY + 1 + * Note that if your system constantly has a high CPU load from high-priority + * tasks, this might not be get a chance to execute. + * + * See vTraceMonitorTask in trcUser.c + *****************************************************************************/ +#define TRACE_PROGRESS_MONITOR_TASK_PRIORITY (tskIDLE_PRIORITY + 1) + +/****************************************************************************** + * TRACE_PROGRESS_MONITOR_TASK_STACKSIZE + * + * Macro which sets the stack size of the "recorder status monitor" task. + * + * This task, vTraceMonitorTask in trcUser.c, periodically writes + * the recorder status using the vTraceConsoleMessage macro, which is to + * be mapped to your console "printf" routine. The task is intentionally + * excluded from the demo trace. + * + * See vTraceMonitorTask in trcUser.c + *****************************************************************************/ +#define TRACE_PROGRESS_MONITOR_TASK_STACKSIZE 500 + +/****************************************************************************** + * TRACE_PROGRESS_MONITOR_TASK_PERIOD + * + * Macro which sets the period of the "recorder status monitor" task. + * + * This task, vTraceMonitorTask in trcUser.c, periodically writes + * the recorder status using the vTraceConsoleMessage macro, which is to + * be mapped to your console "printf" routine. The task is named TraceMon but + * is intentionally excluded from the demo trace. + * + * Default is 1000 ticks (typically 1 second). On the Windows port, a lower + * value is suggested since the Windows port runs very slowly, often 20-40 + * times slower than the simulated time. + * + * See vTraceMonitorTask in trcUser.c + *****************************************************************************/ +#ifdef WIN32 + #define TRACE_PROGRESS_MONITOR_TASK_PERIOD 100 +#else + #define TRACE_PROGRESS_MONITOR_TASK_PERIOD 1000 +#endif + +/****************************************************************************** + * TEAM_LICENSE_CODE + * + * Macro which defines a string - the team license code. + * If no team license is available, this should be an empty string "". + * This should be maximum 32 chars, including zero-termination. + *****************************************************************************/ +#define TEAM_LICENSE_CODE "" + +#endif + diff --git a/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcHardwarePort.h b/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcHardwarePort.h new file mode 100644 index 000000000..ac8347765 --- /dev/null +++ b/FreeRTOS/Demo/WIN32-MingW/Trace_Recorder_Configuration/trcHardwarePort.h @@ -0,0 +1,474 @@ +/******************************************************************************* + * Tracealyzer v2.4.1 Recorder Library + * Percepio AB, www.percepio.com + * + * trcHardwarePort.h + * + * Contains together with trcHardwarePort.c all hardware portability issues of + * the trace recorder library. + * + * Terms of Use + * This software is copyright Percepio AB. The recorder library is free for + * use together with Percepio products. You may distribute the recorder library + * in its original form, including modifications in trcPort.c and trcPort.h + * given that these modification are clearly marked as your own modifications + * and documented in the initial comment section of these source files. + * This software is the intellectual property of Percepio AB and may not be + * sold or in other ways commercially redistributed without explicit written + * permission by Percepio AB. + * + * Disclaimer + * The trace tool and recorder library is being delivered to you AS IS and + * Percepio AB makes no warranty as to its use or performance. Percepio AB does + * not and cannot warrant the performance or results you may obtain by using the + * software or documentation. Percepio AB make no warranties, express or + * implied, as to noninfringement of third party rights, merchantability, or + * fitness for any particular purpose. In no event will Percepio AB, its + * technology partners, or distributors be liable to you for any consequential, + * incidental or special damages, including any lost profits or lost savings, + * even if a representative of Percepio AB has been advised of the possibility + * of such damages, or for any claim by any third party. Some jurisdictions do + * not allow the exclusion or limitation of incidental, consequential or special + * damages, or the exclusion of implied warranties or limitations on how long an + * implied warranty may last, so the above limitations may not apply to you. + * + * Copyright Percepio AB, 2013. + * www.percepio.com + ******************************************************************************/ + +#ifndef TRCPORT_H +#define TRCPORT_H + +#include "trcKernelPort.h" + +/* If Win32 port */ +#ifdef WIN32 + + #undef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 + + /* Standard includes. */ + #include + #include + #include + +/******************************************************************************* + * The Win32 port by default saves the trace to file and then kills the + * program when the recorder is stopped, to facilitate quick, simple tests + * of the recorder. + ******************************************************************************/ + #define WIN32_PORT_SAVE_WHEN_STOPPED 1 + #define WIN32_PORT_EXIT_WHEN_STOPPED 1 + +#endif + +#define DIRECTION_INCREMENTING 1 +#define DIRECTION_DECREMENTING 2 + +/****************************************************************************** + * Supported ports + * + * PORT_HWIndependent + * A hardware independent fallback option for event timestamping. Provides low + * resolution timestamps based on the OS tick. + * This may be used on the Win32 port, but may also be used on embedded hardware + * platforms. All time durations will be truncated to the OS tick frequency, + * typically 1 KHz. This means that a task or ISR that executes in less than + * 1 ms get an execution time of zero. + * + * PORT_Win32 + * "Accurate" timestamping based on the Windows performance counter. Note that + * this gives the host machine time. + * + * Officially supported hardware timer ports: + * - PORT_Atmel_AT91SAM7 + * - PORT_Atmel_UC3A0 + * - PORT_ARM_CortexM + * - PORT_Renesas_RX600 + * - PORT_Microchip_dsPIC_AND_PIC24 + * + * We also provide several "unofficial" hardware-specific ports. There have + * been developed by external contributors, and have not yet been verified + * by Percepio AB. Let us know if you have problems getting these to work. + * + * Unofficial hardware specific ports provided are: + * - PORT_TEXAS_INSTRUMENTS_TMS570 + * - PORT_TEXAS_INSTRUMENTS_MSP430 + * - PORT_MICROCHIP_PIC32 + * - PORT_XILINX_PPC405 + * - PORT_XILINX_PPC440 + * - PORT_XILINX_MICROBLAZE + * - PORT_NXP_LPC210X + * + *****************************************************************************/ + +#define PORT_NOT_SET -1 + +/*** Officially supported hardware timer ports *******************************/ +#define PORT_HWIndependent 0 +#define PORT_Win32 1 +#define PORT_Atmel_AT91SAM7 2 +#define PORT_Atmel_UC3A0 3 +#define PORT_ARM_CortexM 4 +#define PORT_Renesas_RX600 5 +#define PORT_Microchip_dsPIC_AND_PIC24 6 + +/*** Unofficial ports, provided by external developers, not yet verified *****/ +#define PORT_TEXAS_INSTRUMENTS_TMS570 7 +#define PORT_TEXAS_INSTRUMENTS_MSP430 8 +#define PORT_MICROCHIP_PIC32 9 +#define PORT_XILINX_PPC405 10 +#define PORT_XILINX_PPC440 11 +#define PORT_XILINX_MICROBLAZE 12 +#define PORT_NXP_LPC210X 13 + +/*** Select your port here! **************************************************/ +#define SELECTED_PORT PORT_Win32 +/*****************************************************************************/ + +#if (SELECTED_PORT == PORT_NOT_SET) +#error "You need to define SELECTED_PORT here!" +#endif + +/******************************************************************************* + * IRQ_PRIORITY_ORDER + * + * Macro which should be defined as an integer of 0 or 1. + * + * This should be 0 if lower IRQ priority values implies higher priority + * levels, such as on ARM Cortex M. If the opposite scheme is used, i.e., + * if higher IRQ priority values means higher priority, this should be 1. + * + * This setting is not critical. It is used only to sort and colorize the + * interrupts in priority order, in case you record interrupts using + * the vTraceStoreISRBegin and vTraceStoreISREnd routines. + * + * We provide this setting for some hardware architectures below: + * - ARM Cortex M: 0 (lower IRQ priority values are more significant) + * - Atmel AT91SAM7x: 1 (higher IRQ priority values are more significant) + * - Atmel AVR32: 1 (higher IRQ priority values are more significant) + * - Renesas RX600: 1 (higher IRQ priority values are more significant) + * - Microchip PIC24: 0 (lower IRQ priority values are more significant) + * - Microchip dsPIC: 0 (lower IRQ priority values are more significant) + * - TI TMS570: 0 (lower IRQ priority values are more significant) + * - Freescale HCS08: 0 (lower IRQ priority values are more significant) + * - Freescale HCS12: 0 (lower IRQ priority values are more significant) + * - PowerPC 405: 0 (lower IRQ priority values are more significant) + * - PowerPC 440: 0 (lower IRQ priority values are more significant) + * - Freescale ColdFire: 1 (higher IRQ priority values are more significant) + * - NXP LPC210x: 0 (lower IRQ priority values are more significant) + * - MicroBlaze: 0 (lower IRQ priority values are more significant) + * + * If your chip is not on the above list, and you perhaps know this detail by + * heart, please inform us by e-mail to support@percepio.com. + * + ****************************************************************************** + * + * HWTC Macros + * + * These four HWTC macros provides a hardware isolation layer representing a + * generic hardware timer/counter used for driving the operating system tick, + * such as the SysTick feature of ARM Cortex M3/M4, or the PIT of the Atmel + * AT91SAM7X. + * + * HWTC_COUNT: The current value of the counter. This is expected to be reset + * a each tick interrupt. Thus, when the tick handler starts, the counter has + * already wrapped. + * + * HWTC_COUNT_DIRECTION: Should be one of: + * - DIRECTION_INCREMENTING - for hardware timer/counters of incrementing type + * such as the PIT on Atmel AT91SAM7X. + * When the counter value reach HWTC_PERIOD, it is reset to zero and the + * interrupt is signaled. + * - DIRECTION_DECREMENTING - for hardware timer/counters of decrementing type + * such as the SysTick on ARM Cortex M3/M4 chips. + * When the counter value reach 0, it is reset to HWTC_PERIOD and the + * interrupt is signaled. + * + * HWTC_PERIOD: The number of increments or decrements of HWTC_COUNT between + * two tick interrupts. This should preferably be mapped to the reload + * register of the hardware timer, to make it more portable between chips in the + * same family. The macro should in most cases be (reload register + 1). + * + * HWTC_DIVISOR: If the timer frequency is very high, like on the Cortex M chips + * (where the SysTick runs at the core clock frequency), the "differential + * timestamping" used in the recorder will more frequently insert extra XTS + * events to store the timestamps, which increases the event buffer usage. + * In such cases, to reduce the number of XTS events and thereby get longer + * traces, you use HWTC_DIVISOR to scale down the timestamps and frequency. + * Assuming a OS tick rate of 1 KHz, it is suggested to keep the effective timer + * frequency below 65 MHz to avoid an excessive amount of XTS events. Thus, a + * Cortex M chip running at 72 MHZ should use a HWTC_DIVISOR of 2, while a + * faster chip require a higher HWTC_DIVISOR value. + * + * The HWTC macros and vTracePortGetTimeStamp is the main porting issue + * or the trace recorder library. Typically you should not need to change + * the code of vTracePortGetTimeStamp if using the HWTC macros. + * + ******************************************************************************/ + +#if (SELECTED_PORT == PORT_Win32) + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (ulGetRunTimeCounterValue()) + #define HWTC_PERIOD 0 + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // Please update according to your hardware... + +#elif (SELECTED_PORT == PORT_HWIndependent) + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT 0 + #define HWTC_PERIOD 1 + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // Please update according to your hardware... + +#elif (SELECTED_PORT == PORT_Atmel_AT91SAM7) + + /* HWTC_PERIOD is hardcoded for AT91SAM7X256-EK Board (48 MHz) + A more generic solution is to get the period from pxPIT->PITC_PIMR */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF) + #define HWTC_PERIOD 2995 + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_Atmel_UC3A0) + + /* For Atmel AVR32 (AT32UC3A) */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT sysreg_read(AVR32_COUNT) + #define HWTC_PERIOD ( TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ ) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_ARM_CortexM) + + /* For all chips using ARM Cortex M cores */ + + #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING + #define HWTC_COUNT (*((uint32_t*)0xE000E018)) + #define HWTC_PERIOD ((*(uint32_t*)0xE000E014) + 1) + #define HWTC_DIVISOR 2 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_Renesas_RX600) + + #include "iodefine.h" + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (CMT0.CMCNT) + #define HWTC_PERIOD ((((TRACE_PERIPHERAL_CLOCK_HZ/TRACE_TICK_RATE_HZ)-1)/8)) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_Microchip_dsPIC_AND_PIC24) + + /* For Microchip PIC24 and dsPIC (16 bit) */ + + /* Note: The trace library was originally designed for 32-bit MCUs, and is slower + than intended on 16-bit MCUs. Storing an event on a PIC24 takes about 70 µs. + In comparison, 32-bit MCUs are often 10-20 times faster. If recording overhead + becomes a problem on PIC24, use the filters to exclude less interesting tasks + or system calls. */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (TMR1) + #define HWTC_PERIOD (PR1+1) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_NXP_LPC210X) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + /* Tested with LPC2106, but should work with most LPC21XX chips. */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT *((uint32_t *)0xE0004008 ) + #define HWTC_PERIOD ( TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ ) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_TMS570) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + #define RTIFRC0 *((uint32_t *)0xFFFFFC10) + #define RTICOMP0 *((uint32_t *)0xFFFFFC50) + #define RTIUDCP0 *((uint32_t *)0xFFFFFC54) + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (RTIFRC0 - (RTICOMP0 - RTIUDCP0)) + #define HWTC_PERIOD (RTIUDCP0) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_MSP430) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (TA0R) + #define HWTC_PERIOD TRACE_CPU_CLOCKS_PER_TICK + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_MICROCHIP_PIC32) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING + #define HWTC_COUNT (ReadTimer1()) /* Should be available in BSP */ + #define HWTC_PERIOD (ReadPeriod1()+1) /* Should be available in BSP */ + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_XILINX_PPC405) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING + #define HWTC_COUNT mfspr( 0x3db) + #define HWTC_PERIOD ( TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ ) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_XILINX_PPC440) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + /* This should work with most PowerPC chips */ + + #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING + #define HWTC_COUNT mfspr( 0x016 ) + #define HWTC_PERIOD ( TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ ) + #define HWTC_DIVISOR 1 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT == PORT_XILINX_MICROBLAZE) + /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */ + + /* This should work with most Microblaze configurations. + * It uses the AXI Timer 0 - the tick interrupt source. + * If an AXI Timer 0 peripheral is available on your hardware platform, no modifications are required. + */ + #include "xtmrctr_l.h" + + #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING + #define HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 ) + #define HWTC_PERIOD ( TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ ) + #define HWTC_DIVISOR 16 + + #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant + +#elif (SELECTED_PORT != PORT_NOT_SET) + + #error "SELECTED_PORT had unsupported value!" + #define SELECTED_PORT PORT_NOT_SET + +#endif + +#if (SELECTED_PORT != PORT_NOT_SET) + + #ifndef HWTC_COUNT_DIRECTION + #error "HWTC_COUNT_DIRECTION is not set!" + #endif + + #ifndef HWTC_COUNT + #error "HWTC_COUNT is not set!" + #endif + + #ifndef HWTC_PERIOD + #error "HWTC_PERIOD is not set!" + #endif + + #ifndef HWTC_DIVISOR + #error "HWTC_DIVISOR is not set!" + #endif + + #ifndef IRQ_PRIORITY_ORDER + #error "IRQ_PRIORITY_ORDER is not set!" + #elif (IRQ_PRIORITY_ORDER != 0) && (IRQ_PRIORITY_ORDER != 1) + #error "IRQ_PRIORITY_ORDER has bad value!" + #endif + + #if (HWTC_DIVISOR < 1) + #error "HWTC_DIVISOR must be a non-zero positive value!" + #endif + +#endif +/******************************************************************************* + * vTraceConsoleMessage + * + * A wrapper for your system-specific console "printf" console output function. + * This needs to be correctly defined to see status reports from the trace + * status monitor task (this is defined in trcUser.c). + ******************************************************************************/ +#if (SELECTED_PORT == PORT_Atmel_AT91SAM7) +/* Port specific includes */ +#include "console.h" +#endif + +#define vTraceConsoleMessage(x) + +/******************************************************************************* + * vTracePortGetTimeStamp + * + * Returns the current time based on the HWTC macros which provide a hardware + * isolation layer towards the hardware timer/counter. + * + * The HWTC macros and vTracePortGetTimeStamp is the main porting issue + * or the trace recorder library. Typically you should not need to change + * the code of vTracePortGetTimeStamp if using the HWTC macros. + * + ******************************************************************************/ +void vTracePortGetTimeStamp(uint32_t *puiTimestamp); + +/******************************************************************************* + * vTracePortEnd + * + * This function is called when the recorder is stopped due to full buffer. + * Mainly intended to show a message in the console. + * This is used by the Win32 port to store the trace to a file. The file path is + * set using vTracePortSetFileName. + ******************************************************************************/ +void vTracePortEnd(void); + +#if (INCLUDE_SAVE_TO_FILE == 1) + +/******************************************************************************* + * vTracePortSetOutFile + * + * Sets the filename/path used in vTracePortSave. + * This is set in a separate function, since the Win32 port calls vTracePortSave + * in vTracePortEnd if WIN32_PORT_SAVE_WHEN_STOPPED is set. + ******************************************************************************/ +void vTracePortSetOutFile(char* path); + +/****************************************************************************** + * vTracePortSave + * + * Saves the trace to a file on a target-side file system. The path is set in a + * separate function, vTracePortSetOutFile, since the Win32 port may call + * vTracePortSave in vTracePortEnd, if using WIN32_PORT_SAVE_WHEN_STOPPED. + ******************************************************************************/ +void vTracePortSave(void); + +#else + +#define vTraceConsoleMessage(x) +#define vTracePortSetOutFile(path) +#define vTracePortSave(void) + +#endif + +#endif diff --git a/FreeRTOS/Demo/WIN32-MingW/main.c b/FreeRTOS/Demo/WIN32-MingW/main.c index 35ad0939d..6d451b462 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main.c +++ b/FreeRTOS/Demo/WIN32-MingW/main.c @@ -63,172 +63,237 @@ 1 tab == 4 spaces! */ -/* +/****************************************************************************** + * This project provides two demo applications. A simple blinky style project, + * and a more comprehensive test and demo application. The + * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. + * The simply blinky demo is implemented and described in main_blinky.c. The + * more comprehensive test and demo application is implemented and described in + * main_full.c. + * + * This file implements the code that is not demo specific, including the + * hardware setup and FreeRTOS hook functions. + * ******************************************************************************* * -NOTE- The Win32 port is a simulation (or is that emulation?) only! Do not * expect to get real time behaviour from the Win32 port or this demo * application. It is provided as a convenient development and demonstration * test bed only. This was tested using Windows XP on a dual core laptop. * + * Windows will not be running the FreeRTOS simulator threads continuously, so + * the timing information in the FreeRTOS+Trace logs have no meaningful units. + * See the documentation page for the Windows simulator for an explanation of + * the slow timing: + * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT - ******************************************************************************* * - * main() creates all the demo application tasks, then starts the scheduler. - * The web documentation provides more details of the standard demo application - * tasks, which provide no particular functionality but do provide a good - * example of how to use the FreeRTOS API. - * - * In addition to the standard demo tasks, the following tasks and tests are - * defined and/or created within this file: - * - * "Check" task - This only executes every five seconds but has a high priority - * to ensure it gets processor time. Its main function is to check that all the - * standard demo tasks are still operational. While no errors have been - * discovered the check task will print out "OK" and the current simulated tick - * time. If an error is discovered in the execution of a task then the check - * task will print out an appropriate error message. - * */ - /* Standard includes. */ #include +#include +#include -/* Kernel includes. */ -#include +/* FreeRTOS kernel includes. */ +#include "FreeRTOS.h" #include "task.h" -#include "queue.h" - -/* Standard demo includes. */ -#include "BlockQ.h" -#include "integer.h" -#include "semtest.h" -#include "PollQ.h" -#include "GenQTest.h" -#include "QPeek.h" -#include "recmutex.h" -#include "flop.h" - -/* Priorities at which the tasks are created. */ -#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 ) -#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) -#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) -#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) -#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) -#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) -#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) -#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY ) -#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY ) - -/* Task function prototypes. */ -static void prvCheckTask( void *pvParameters ); + +/* This project provides two demo applications. A simple blinky style project, +and a more comprehensive test and demo application. The +mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. +The simply blinky demo is implemented and described in main_blinky.c. The more +comprehensive test and demo application is implemented and described in +main_full.c. */ +#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0 + +/* + * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1. + * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. + */ +extern void main_blinky( void ); +extern void main_full( void ); + +/* Some of the RTOS hook (callback) functions only need special processing when +the full demo is being used. The simply blinky demo has no special requirements, +so these functions are called from the hook functions defined in this file, but +are defined in main_full.c. */ +void vFullDemoTickHookFunction( void ); +void vFullDemoIdleFunction( void ); + +/* Prototypes for the standard FreeRTOS callback/hook functions implemented +within this file. */ +void vApplicationMallocFailedHook( void ); +void vApplicationIdleHook( void ); +void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName ); +void vApplicationTickHook( void ); + +/* + * Writes trace data to a disk file when the trace recording is stopped. + * This function will simply overwrite any trace files that already exist. + */ +static void prvSaveTraceFile( void ); + +/* The user trace event posted to the trace recording on each tick interrupt. +Note tick events will not appear in the trace recording with regular period +because this project runs in a Windows simulator, and does not therefore +exhibit deterministic behaviour. */ +traceLabel xTickTraceUserEvent; +static portBASE_TYPE xTraceRunning = pdTRUE; /*-----------------------------------------------------------*/ + int main( void ) { - /* Start the check task as described at the top of this file. */ - xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); - - /* Create the standard demo tasks. */ - vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); - vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); - vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); - vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY ); - vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); - vStartQueuePeekTasks(); - vStartMathTasks( mainFLOP_TASK_PRIORITY ); - vStartRecursiveMutexTasks(); - - /* Start the scheduler itself. */ - vTaskStartScheduler(); - - /* Should never get here unless there was not enough heap space to create - the idle and other system tasks. */ - return 0; + /* Initialise the trace recorder and create the label used to post user + events to the trace recording on each tick interrupt. */ + vTraceInitTraceData(); + xTickTraceUserEvent = xTraceOpenLabel( "tick" ); + + /* Start the trace recording - the recording is written to a file if + configASSERT() is called. */ + printf( "\r\nTrace started. Hit a key to dump trace file to disk.\r\n" ); + printf( "Note stdin does not work when using the Eclipse console with MingW.\r\n" ); + fflush( stdout ); + uiTraceStart(); + + /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top + of this file. */ + #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) + { + main_blinky(); + } + #else + { + main_full(); + } + #endif + + return 0; } /*-----------------------------------------------------------*/ -static void prvCheckTask( void *pvParameters ) +void vApplicationMallocFailedHook( void ) { -portTickType xNextWakeTime; -const portTickType xCycleFrequency = 2500 / portTICK_RATE_MS; -char *pcStatusMessage = "OK"; - - /* Just to remove compiler warning. */ - ( void ) pvParameters; - - /* Initialise xNextWakeTime - this only needs to be done once. */ - xNextWakeTime = xTaskGetTickCount(); + /* vApplicationMallocFailedHook() will only be called if + configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook + function that will get called if a call to pvPortMalloc() fails. + pvPortMalloc() is called internally by the kernel whenever a task, queue, + timer or semaphore is created. It is also called by various parts of the + demo application. If heap_1.c or heap_2.c are used, then the size of the + heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in + FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used + to query the size of free heap space that remains (although it does not + provide information on how the remaining heap might be fragmented). */ + vAssertCalled( __LINE__, __FILE__ ); +} +/*-----------------------------------------------------------*/ - for( ;; ) +void vApplicationIdleHook( void ) +{ + /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set + to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle + task. It is essential that code added to this hook function never attempts + to block in any way (for example, call xQueueReceive() with a block time + specified, or call vTaskDelay()). If the application makes use of the + vTaskDelete() API function (as this demo application does) then it is also + important that vApplicationIdleHook() is permitted to return to its calling + function, because it is the responsibility of the idle task to clean up + memory allocated by the kernel to any task that has since been deleted. */ + + /* The trace can be stopped with any key press. */ + if( kbhit() != pdFALSE ) { - /* Place this task in the blocked state until it is time to run again. */ - vTaskDelayUntil( &xNextWakeTime, xCycleFrequency ); - - /* Check the standard demo tasks are running without error. */ - if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: IntMath"; - } - else if( xAreGenericQueueTasksStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: GenQueue"; - } - else if( xAreQueuePeekTasksStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: QueuePeek"; - } - else if( xAreBlockingQueuesStillRunning() != pdTRUE ) + if( xTraceRunning == pdTRUE ) { - pcStatusMessage = "Error: BlockQueue"; - } - else if( xAreSemaphoreTasksStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: SemTest"; - } - else if( xArePollingQueuesStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: PollQueue"; - } - else if( xAreMathsTaskStillRunning() != pdPASS ) - { - pcStatusMessage = "Error: Flop"; - } - else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE ) - { - pcStatusMessage = "Error: RecMutex"; + vTraceStop(); + prvSaveTraceFile(); + xTraceRunning = pdFALSE; } + } - /* This is the only task that uses stdout so its ok to call printf() - directly. */ - printf( "%s - %d\r\n", pcStatusMessage, ( int ) xTaskGetTickCount() ); - fflush( stdout ); /* Required by Eclipse console. */ + #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 ) + { + /* Call the idle task processing used by the full demo. The simple + blinky demo does not use the idle task hook. */ + vFullDemoIdleFunction(); } + #endif } /*-----------------------------------------------------------*/ -void vApplicationIdleHook( void ) +void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName ) { -const unsigned long ulMSToSleep = 5; + ( void ) pcTaskName; + ( void ) pxTask; - /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are - tasks waiting to be terminated by the idle task. */ - Sleep( ulMSToSleep ); + /* Run time stack overflow checking is performed if + configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook + function is called if a stack overflow is detected. */ + vAssertCalled( __LINE__, __FILE__ ); } /*-----------------------------------------------------------*/ -void vApplicationMallocFailedHook( void ) +void vApplicationTickHook( void ) { - /* Can be implemented if required, but probably not required in this - environment and running this demo. */ + /* This function will be called by each tick interrupt if + configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be + added here, but the tick hook is called from an interrupt context, so + code must not attempt to block, and only the interrupt safe FreeRTOS API + functions can be used (those that end in FromISR()). */ + + #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 ) + { + vFullDemoTickHookFunction(); + } + #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */ + + /* Write a user event to the trace log. + Note tick events will not appear in the trace recording with regular period + because this project runs in a Windows simulator, and does not therefore + exhibit deterministic behaviour. Windows will run the simulator in + bursts. */ + vTraceUserEvent( xTickTraceUserEvent ); } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( void ) +void vAssertCalled( unsigned long ulLine, const char * const pcFileName ) { - /* Can be implemented if required, but not required in this - environment and running this demo. */ + /* Parameters are not used. */ + ( void ) ulLine; + ( void ) pcFileName; + + taskDISABLE_INTERRUPTS(); + __asm volatile( "int $3" ); + + /* Stop the trace recording. */ + if( xTraceRunning == pdTRUE ) + { + vTraceStop(); + prvSaveTraceFile(); + } + + taskENABLE_INTERRUPTS(); } +/*-----------------------------------------------------------*/ + +static void prvSaveTraceFile( void ) +{ +FILE* pxOutputFile; + pxOutputFile = fopen( "Trace.dump", "wb"); + + if( pxOutputFile != NULL ) + { + fwrite( RecorderDataPtr, sizeof( RecorderDataType ), 1, pxOutputFile ); + fclose( pxOutputFile ); + printf( "\r\nTrace output saved to Trace.dump\r\n" ); + fflush( stdout ); + } + else + { + printf( "\r\nFailed to create trace dump file\r\n" ); + fflush( stdout ); + } +} diff --git a/FreeRTOS/Demo/WIN32-MingW/main_blinky.c b/FreeRTOS/Demo/WIN32-MingW/main_blinky.c new file mode 100644 index 000000000..bc4191140 --- /dev/null +++ b/FreeRTOS/Demo/WIN32-MingW/main_blinky.c @@ -0,0 +1,253 @@ +/* + FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + 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. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +/****************************************************************************** + * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not + * expect to get real time behaviour from the Win32 port or this demo + * application. It is provided as a convenient development and demonstration + * test bed only. This was tested using Windows XP on a dual core laptop. + * + * Windows will not be running the FreeRTOS simulator threads continuously, so + * the timing information in the FreeRTOS+Trace logs have no meaningful units. + * See the documentation page for the Windows simulator for an explanation of + * the slow timing: + * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html + * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT - + * + * NOTE 2: This project provides two demo applications. A simple blinky style + * project, and a more comprehensive test and demo application. The + * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select + * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY + * in main.c. This file implements the simply blinky style version. + * + * NOTE 3: This file only contains the source code that is specific to the + * basic demo. Generic functions, such FreeRTOS hook functions, are defined + * in main.c. + ****************************************************************************** + * + * main_blinky() creates one queue, and two tasks. It then starts the + * scheduler. + * + * The Queue Send Task: + * The queue send task is implemented by the prvQueueSendTask() function in + * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly + * block for 200 (simulated as far as the scheduler is concerned, but in + * reality much longer - see notes above) milliseconds, before sending the + * value 100 to the queue that was created within main_blinky(). Once the + * value is sent, the task loops back around to block for another 200 + * (simulated) milliseconds. + * + * The Queue Receive Task: + * The queue receive task is implemented by the prvQueueReceiveTask() function + * in this file. prvQueueReceiveTask() sits in a loop where it repeatedly + * blocks on attempts to read data from the queue that was created within + * main_blinky(). When data is received, the task checks the value of the + * data, and if the value equals the expected 100, outputs a message. The + * 'block time' parameter passed to the queue receive function specifies that + * the task should be held in the Blocked state indefinitely to wait for data + * to be available on the queue. The queue receive task will only leave the + * Blocked state when the queue send task writes to the queue. As the queue + * send task writes to the queue every 200 (simulated - see notes above) + * milliseconds, the queue receive task leaves the Blocked state every 200 + * milliseconds, and therefore outputs a message every 200 milliseconds. + */ + +/* Standard includes. */ +#include + +/* Kernel includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" + +/* Priorities at which the tasks are created. */ +#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) + +/* The rate at which data is sent to the queue. The 200ms value is converted +to ticks using the portTICK_RATE_MS constant. */ +#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS ) + +/* The number of items the queue can hold. This is 1 as the receive task +will remove items as they are added, meaning the send task should always find +the queue empty. */ +#define mainQUEUE_LENGTH ( 1 ) + +/* Values passed to the two tasks just to check the task parameter +functionality. */ +#define mainQUEUE_SEND_PARAMETER ( 0x1111UL ) +#define mainQUEUE_RECEIVE_PARAMETER ( 0x22UL ) + +/*-----------------------------------------------------------*/ + +/* + * The tasks as described in the comments at the top of this file. + */ +static void prvQueueReceiveTask( void *pvParameters ); +static void prvQueueSendTask( void *pvParameters ); + +/*-----------------------------------------------------------*/ + +/* The queue used by both tasks. */ +static xQueueHandle xQueue = NULL; + +/*-----------------------------------------------------------*/ + +void main_blinky( void ) +{ + /* Create the queue. */ + xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) ); + + if( xQueue != NULL ) + { + /* Start the two tasks as described in the comments at the top of this + file. */ + xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */ + ( signed char * ) "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */ + configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */ + ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */ + mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */ + NULL ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL ); + + /* Start the tasks and timer running. */ + vTaskStartScheduler(); + } + + /* If all is well, the scheduler will now be running, and the following + line will never be reached. If the following line does execute, then + there was insufficient FreeRTOS heap memory available for the idle and/or + timer tasks to be created. See the memory management section on the + FreeRTOS web site for more details. */ + for( ;; ); +} +/*-----------------------------------------------------------*/ + +static void prvQueueSendTask( void *pvParameters ) +{ +portTickType xNextWakeTime; +const unsigned long ulValueToSend = 100UL; + + /* Remove compiler warning in the case that configASSERT() is not + defined. */ + ( void ) pvParameters; + + /* Check the task parameter is as expected. */ + configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER ); + + /* Initialise xNextWakeTime - this only needs to be done once. */ + xNextWakeTime = xTaskGetTickCount(); + + for( ;; ) + { + /* Place this task in the blocked state until it is time to run again. + The block time is specified in ticks, the constant used converts ticks + to ms. While in the Blocked state this task will not consume any CPU + time. */ + vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS ); + + /* Send to the queue - causing the queue receive task to unblock and + toggle the LED. 0 is used as the block time so the sending operation + will not block - it shouldn't need to block as the queue should always + be empty at this point in the code. */ + xQueueSend( xQueue, &ulValueToSend, 0U ); + } +} +/*-----------------------------------------------------------*/ + +static void prvQueueReceiveTask( void *pvParameters ) +{ +unsigned long ulReceivedValue; + + /* Remove compiler warning in the case that configASSERT() is not + defined. */ + ( void ) pvParameters; + + /* Check the task parameter is as expected. */ + configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER ); + + for( ;; ) + { + /* Wait until something arrives in the queue - this task will block + indefinitely provided INCLUDE_vTaskSuspend is set to 1 in + FreeRTOSConfig.h. */ + xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY ); + + /* To get here something must have been received from the queue, but + is it the expected value? If it is, toggle the LED. */ + if( ulReceivedValue == 100UL ) + { + /* Normally calling printf() from a task is not a good idea. Here + there is lots of stack space and only one task is using console IO + so it is ok. */ + printf( "Message received\r\n" ); + fflush( stdout ); + ulReceivedValue = 0U; + } + } +} +/*-----------------------------------------------------------*/ + diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c new file mode 100644 index 000000000..90fbe4e27 --- /dev/null +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -0,0 +1,555 @@ +/* + FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + 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. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +/* + ******************************************************************************* + * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not + * expect to get real time behaviour from the Win32 port or this demo + * application. It is provided as a convenient development and demonstration + * test bed only. This was tested using Windows XP on a dual core laptop. + * + * Windows will not be running the FreeRTOS simulator threads continuously, so + * the timing information in the FreeRTOS+Trace logs have no meaningful units. + * See the documentation page for the Windows simulator for an explanation of + * the slow timing: + * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html + * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT - + * + * NOTE 2: This project provides two demo applications. A simple blinky style + * project, and a more comprehensive test and demo application. The + * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select + * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY + * in main.c. This file implements the comprehensive test and demo version. + * + * NOTE 3: This file only contains the source code that is specific to the + * basic demo. Generic functions, such FreeRTOS hook functions, are defined in + * main.c. + ******************************************************************************* + * + * main() creates all the demo application tasks, then starts the scheduler. + * The web documentation provides more details of the standard demo application + * tasks, which provide no particular functionality but do provide a good + * example of how to use the FreeRTOS API. + * + * In addition to the standard demo tasks, the following tasks and tests are + * defined and/or created within this file: + * + * "Check" task - This only executes every five seconds but has a high priority + * to ensure it gets processor time. Its main function is to check that all the + * standard demo tasks are still operational. While no errors have been + * discovered the check task will print out "OK" and the current simulated tick + * time. If an error is discovered in the execution of a task then the check + * task will print out an appropriate error message. + * + */ + + +/* Standard includes. */ +#include +#include + +/* Kernel includes. */ +#include +#include "task.h" +#include "queue.h" +#include "timers.h" +#include "semphr.h" + +/* Standard demo includes. */ +#include "BlockQ.h" +#include "integer.h" +#include "semtest.h" +#include "PollQ.h" +#include "GenQTest.h" +#include "QPeek.h" +#include "recmutex.h" +#include "flop.h" +#include "TimerDemo.h" +#include "countsem.h" +#include "death.h" +#include "dynamic.h" +#include "QueueSet.h" +#include "QueueOverwrite.h" +#include "EventGroupsDemo.h" + +/* Priorities at which the tasks are created. */ +#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) +#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY ) + +#define mainTIMER_TEST_PERIOD ( 50 ) + +/* Task function prototypes. */ +static void prvCheckTask( void *pvParameters ); + +/* A task that is created from the idle task to test the functionality of +eTaskStateGet(). */ +static void prvTestTask( void *pvParameters ); + +/* + * Called from the idle task hook function to demonstrate a few utility + * functions that are not demonstrated by any of the standard demo tasks. + */ +static void prvDemonstrateTaskStateAndHandleGetFunctions( void ); + +/* + * A task to demonstrate the use of the xQueueSpacesAvailable() function. + */ +static void prvDemoQueueSpaceFunctions( void *pvParameters ); + +/*-----------------------------------------------------------*/ + +/* The variable into which error messages are latched. */ +static char *pcStatusMessage = "OK"; + +/* This semaphore is created purely to test using the vSemaphoreDelete() and +semaphore tracing API functions. It has no other purpose. */ +static xSemaphoreHandle xMutexToDelete = NULL; + +/*-----------------------------------------------------------*/ + +int main_full( void ) +{ + /* Start the check task as described at the top of this file. */ + xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + + /* Create the standard demo tasks. */ + vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); + vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); + vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); + vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY ); + vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); + vStartQueuePeekTasks(); + vStartMathTasks( mainFLOP_TASK_PRIORITY ); + vStartRecursiveMutexTasks(); + vStartCountingSemaphoreTasks(); + vStartDynamicPriorityTasks(); + vStartQueueSetTasks(); + vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); + xTaskCreate( prvDemoQueueSpaceFunctions, ( signed char * ) "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + vStartEventGroupTasks(); + + #if( configUSE_PREEMPTION != 0 ) + { + /* Don't expect these tasks to pass when preemption is not used. */ + vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); + } + #endif + + /* The suicide tasks must be created last as they need to know how many + tasks were running prior to their creation. This then allows them to + ascertain whether or not the correct/expected number of tasks are running at + any given time. */ + vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); + + /* Create the semaphore that will be deleted in the idle task hook. This + is done purely to test the use of vSemaphoreDelete(). */ + xMutexToDelete = xSemaphoreCreateMutex(); + + /* Start the scheduler itself. */ + vTaskStartScheduler(); + + /* Should never get here unless there was not enough heap space to create + the idle and other system tasks. */ + return 0; +} +/*-----------------------------------------------------------*/ + +static void prvCheckTask( void *pvParameters ) +{ +portTickType xNextWakeTime; +const portTickType xCycleFrequency = 2500 / portTICK_RATE_MS; + + /* Just to remove compiler warning. */ + ( void ) pvParameters; + + /* Initialise xNextWakeTime - this only needs to be done once. */ + xNextWakeTime = xTaskGetTickCount(); + + for( ;; ) + { + /* Place this task in the blocked state until it is time to run again. */ + vTaskDelayUntil( &xNextWakeTime, xCycleFrequency ); + + /* Check the standard demo tasks are running without error. */ + #if( configUSE_PREEMPTION != 0 ) + { + /* These tasks are only created when preemption is used. */ + if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE ) + { + pcStatusMessage = "Error: TimerDemo"; + } + } + #endif + + if( xAreEventGroupTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: EventGroup"; + } + else if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: IntMath"; + } + else if( xAreGenericQueueTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: GenQueue"; + } + else if( xAreQueuePeekTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: QueuePeek"; + } + else if( xAreBlockingQueuesStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: BlockQueue"; + } + else if( xAreSemaphoreTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: SemTest"; + } + else if( xArePollingQueuesStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: PollQueue"; + } + else if( xAreMathsTaskStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Flop"; + } + else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: RecMutex"; + } + else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: CountSem"; + } + else if( xIsCreateTaskStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: Death"; + } + else if( xAreDynamicPriorityTasksStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Dynamic"; + } + else if( xAreQueueSetTasksStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Queue set"; + } + else if( xIsQueueOverwriteTaskStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Queue overwrite"; + } + + /* This is the only task that uses stdout so its ok to call printf() + directly. */ + printf( ( char * ) "%s - %u\r\n", pcStatusMessage, ( unsigned int ) xTaskGetTickCount() ); + fflush( stdout ); + } +} +/*-----------------------------------------------------------*/ + +static void prvTestTask( void *pvParameters ) +{ +const unsigned long ulMSToSleep = 5; + + /* Just to remove compiler warnings. */ + ( void ) pvParameters; + + /* This task is just used to test the eTaskStateGet() function. It + does not have anything to do. */ + for( ;; ) + { + /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are + tasks waiting to be terminated by the idle task. */ + Sleep( ulMSToSleep ); + } +} +/*-----------------------------------------------------------*/ + +/* Called from vApplicationIdleHook(), which is defined in main.c. */ +void vFullDemoIdleFunction( void ) +{ +const unsigned long ulMSToSleep = 15; +const unsigned portBASE_TYPE uxConstQueueNumber = 0xaaU; +void *pvAllocated; + +/* These three functions are only meant for use by trace code, and not for +direct use from application code, hence their prototypes are not in queue.h. */ +extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned portBASE_TYPE uxQueueNumber ); +extern unsigned portBASE_TYPE uxQueueGetQueueNumber( xQueueHandle pxQueue ); +extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ); +extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ); +extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask ); + + /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are + tasks waiting to be terminated by the idle task. */ + Sleep( ulMSToSleep ); + + /* Demonstrate a few utility functions that are not demonstrated by any of + the standard demo tasks. */ + prvDemonstrateTaskStateAndHandleGetFunctions(); + + /* If xMutexToDelete has not already been deleted, then delete it now. + This is done purely to demonstrate the use of, and test, the + vSemaphoreDelete() macro. Care must be taken not to delete a semaphore + that has tasks blocked on it. */ + if( xMutexToDelete != NULL ) + { + /* Before deleting the semaphore, test the function used to set its + number. This would normally only be done from trace software, rather + than application code. */ + vQueueSetQueueNumber( xMutexToDelete, uxConstQueueNumber ); + + /* Before deleting the semaphore, test the functions used to get its + type and number. Again, these would normally only be done from trace + software, rather than application code. */ + configASSERT( uxQueueGetQueueNumber( xMutexToDelete ) == uxConstQueueNumber ); + configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX ); + vSemaphoreDelete( xMutexToDelete ); + xMutexToDelete = NULL; + } + + /* Exercise heap_4 a bit. The malloc failed hook will trap failed + allocations so there is no need to test here. */ + pvAllocated = pvPortMalloc( ( rand() % 100 ) + 1 ); + vPortFree( pvAllocated ); +} +/*-----------------------------------------------------------*/ + +/* Called by vApplicationTickHook(), which is defined in main.c. */ +void vFullDemoTickHookFunction( void ) +{ + /* Call the periodic timer test, which tests the timer API functions that + can be called from an ISR. */ + #if( configUSE_PREEMPTION != 0 ) + { + /* Only created when preemption is used. */ + vTimerPeriodicISRTests(); + } + #endif + + /* Call the periodic queue overwrite from ISR demo. */ + vQueueOverwritePeriodicISRDemo(); + + /* Write to a queue that is in use as part of the queue set demo to + demonstrate using queue sets from an ISR. */ + vQueueSetAccessQueueSetFromISR(); +} +/*-----------------------------------------------------------*/ + +static void prvDemonstrateTaskStateAndHandleGetFunctions( void ) +{ +xTaskHandle xIdleTaskHandle, xTimerTaskHandle; +const unsigned char ucConstTaskNumber = 0x55U; +signed char *pcTaskName; +static portBASE_TYPE xPerformedOneShotTests = pdFALSE; +xTaskHandle xTestTask; + + /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and + xTaskGetIdleTaskHandle() functions. Also try using the function that sets + the task number. */ + xIdleTaskHandle = xTaskGetIdleTaskHandle(); + xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle(); + vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber ); + configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber ); + + /* This is the idle hook, so the current task handle should equal the + returned idle task handle. */ + if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle ) + { + pcStatusMessage = "Error: Returned idle task handle was incorrect"; + } + + /* Check the timer task handle was returned correctly. */ + pcTaskName = pcTaskGetTaskName( xTimerTaskHandle ); + if( strcmp( ( char * ) pcTaskName, "Tmr Svc" ) != 0 ) + { + pcStatusMessage = "Error: Returned timer task handle was incorrect"; + } + + /* This task is running, make sure it's state is returned as running. */ + if( eTaskStateGet( xIdleTaskHandle ) != eRunning ) + { + pcStatusMessage = "Error: Returned idle task state was incorrect"; + } + + /* If this task is running, then the timer task must be blocked. */ + if( eTaskStateGet( xTimerTaskHandle ) != eBlocked ) + { + pcStatusMessage = "Error: Returned timer task state was incorrect"; + } + + /* Other tests that should only be performed once follow. The test task + is not created on each iteration because to do so would cause the death + task to report an error (too many tasks running). */ + if( xPerformedOneShotTests == pdFALSE ) + { + /* Don't run this part of the test again. */ + xPerformedOneShotTests = pdTRUE; + + /* Create a test task to use to test other eTaskStateGet() return values. */ + if( xTaskCreate( prvTestTask, ( const signed char * const ) "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS ) + { + /* If this task is running, the test task must be in the ready state. */ + if( eTaskStateGet( xTestTask ) != eReady ) + { + pcStatusMessage = "Error: Returned test task state was incorrect 1"; + } + + /* Now suspend the test task and check its state is reported correctly. */ + vTaskSuspend( xTestTask ); + if( eTaskStateGet( xTestTask ) != eSuspended ) + { + pcStatusMessage = "Error: Returned test task state was incorrect 2"; + } + + /* Now delete the task and check its state is reported correctly. */ + vTaskDelete( xTestTask ); + if( eTaskStateGet( xTestTask ) != eDeleted ) + { + pcStatusMessage = "Error: Returned test task state was incorrect 3"; + } + } + } +} +/*-----------------------------------------------------------*/ + +static void prvDemoQueueSpaceFunctions( void *pvParameters ) +{ +xQueueHandle xQueue = NULL; +const unsigned portBASE_TYPE uxQueueLength = 10; +unsigned portBASE_TYPE uxReturn, x; + + /* Remove compiler warnings. */ + ( void ) pvParameters; + + /* Create the queue that will be used. Nothing is actually going to be + sent or received so the queue item size is set to 0. */ + xQueue = xQueueCreate( uxQueueLength, 0 ); + configASSERT( xQueue ); + + for( ;; ) + { + for( x = 0; x < uxQueueLength; x++ ) + { + /* Ask how many messages are available... */ + uxReturn = uxQueueMessagesWaiting( xQueue ); + + /* Check the number of messages being reported as being available + is as expected, and force an assert if not. */ + if( uxReturn != x ) + { + /* xQueue cannot be NULL so this is deliberately causing an + assert to be triggered as there is an error. */ + configASSERT( xQueue == NULL ); + } + + /* Ask how many spaces remain in the queue... */ + uxReturn = uxQueueSpacesAvailable( xQueue ); + + /* Check the number of spaces being reported as being available + is as expected, and force an assert if not. */ + if( uxReturn != ( uxQueueLength - x ) ) + { + /* xQueue cannot be NULL so this is deliberately causing an + assert to be triggered as there is an error. */ + configASSERT( xQueue == NULL ); + } + + /* Fill one more space in the queue. */ + xQueueSendToBack( xQueue, NULL, 0 ); + } + + /* Perform the same check while the queue is full. */ + uxReturn = uxQueueMessagesWaiting( xQueue ); + if( uxReturn != uxQueueLength ) + { + configASSERT( xQueue == NULL ); + } + + uxReturn = uxQueueSpacesAvailable( xQueue ); + + if( uxReturn != 0 ) + { + configASSERT( xQueue == NULL ); + } + + /* The queue is full, start again. */ + xQueueReset( xQueue ); + + #if( configUSE_PREEMPTION == 0 ) + taskYIELD(); + #endif + } +} + +