X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=FreeRTOS%2FDemo%2FCORTEX_SmartFusion2_M2S050_SoftConsole%2FRTOSDemo%2FRunTimeStatsTimer.c;h=faa3d43477f353dd6746010307ab99f5201efe79;hb=4c4a171cb817e52f4e9c57c314f039df5b65efa3;hp=0ce8bc6308d7942a6647e2b563189f5dbf377bb2;hpb=72bffdda8070ab84bd1b69ba9cf1987e5c7f5d75;p=freertos diff --git a/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/RunTimeStatsTimer.c b/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/RunTimeStatsTimer.c index 0ce8bc630..faa3d4347 100644 --- a/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/RunTimeStatsTimer.c +++ b/FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/RunTimeStatsTimer.c @@ -1,48 +1,37 @@ /* - FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd. + FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT - http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * - * FreeRTOS tutorial books are available in pdf and paperback. * - * Complete, revised, and edited pdf reference manuals are also * - * available. * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * * * - * Purchasing FreeRTOS documentation will not only help you, by * - * ensuring you get running as quickly as possible and with an * - * in-depth knowledge of how to use FreeRTOS, it will also help * - * the FreeRTOS project to continue with its mission of providing * - * professional grade, cross platform, de facto standard solutions * - * for microcontrollers - completely free of charge! * + * 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 * * * - * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * - * * - * Thank you for using FreeRTOS, and thank you for your support! * + * 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. + 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. + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. You should have received a copy of the GNU General Public License - and the FreeRTOS license exception along with FreeRTOS; if not it can be - viewed here: http://www.freertos.org/a00114.html and also obtained by - writing to Real Time Engineers Ltd., contact details for whom are available - on the FreeRTOS WEB site. + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html 1 tab == 4 spaces! @@ -55,84 +44,92 @@ * * *************************************************************************** - 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, and our new - fully thread aware and reentrant UDP/IP stack. + 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, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. + 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! */ /* FreeRTOS includes. */ #include "FreeRTOS.h" -#include "task.h" /* Utility functions to implement run time stats on Cortex-M CPUs. The collected run time data can be viewed through the CLI interface. See the following URL for more information on run time stats: http://www.freertos.org/rtos-run-time-stats.html */ -/* Used in the run time stats calculations. */ -static uint32_t ulClocksPer10thOfAMilliSecond = 0UL; +/* Addresses of registers in the Cortex-M debug hardware. */ +#define rtsDWT_CYCCNT ( *( ( volatile unsigned long * ) 0xE0001004 ) ) +#define rtsDWT_CONTROL ( *( ( volatile unsigned long * ) 0xE0001000 ) ) +#define rtsSCB_DEMCR ( *( ( volatile unsigned long * ) 0xE000EDFC ) ) +#define rtsTRCENA_BIT ( 0x01000000UL ) +#define rtsCOUNTER_ENABLE_BIT ( 0x01UL ) + +/* Simple shift divide for scaling to avoid an overflow occurring too soon. The +number of bits to shift depends on the clock speed. */ +#define runtimeSLOWER_CLOCK_SPEEDS ( 70000000UL ) +#define runtimeSHIFT_13 13 +#define runtimeOVERFLOW_BIT_13 ( 1UL << ( 32UL - runtimeSHIFT_13 ) ) +#define runtimeSHIFT_14 14 +#define runtimeOVERFLOW_BIT_14 ( 1UL << ( 32UL - runtimeSHIFT_14 ) ) +/*-----------------------------------------------------------*/ void vConfigureTimerForRunTimeStats( void ) { - /* How many clocks are there per tenth of a millisecond? */ - ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL; + /* Enable TRCENA. */ + rtsSCB_DEMCR = rtsSCB_DEMCR | rtsTRCENA_BIT; + + /* Reset counter. */ + rtsDWT_CYCCNT = 0; + + /* Enable counter. */ + rtsDWT_CONTROL = rtsDWT_CONTROL | rtsCOUNTER_ENABLE_BIT; } /*-----------------------------------------------------------*/ uint32_t ulGetRunTimeCounterValue( void ) { -uint32_t ulSysTickCounts, ulTickCount, ulReturn; -const uint32_t ulSysTickReloadValue = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; -volatile uint32_t * const pulCurrentSysTickCount = ( ( volatile uint32_t *) 0xe000e018 ); -volatile uint32_t * const pulInterruptCTRLState = ( ( volatile uint32_t *) 0xe000ed04 ); -const uint32_t ulSysTickPendingBit = 0x04000000UL; +static unsigned long ulLastCounterValue = 0UL, ulOverflows = 0; +unsigned long ulValueNow; - /* NOTE: There are potentially race conditions here. However, it is used - anyway to keep the examples simple, and to avoid reliance on a separate - timer peripheral. */ + ulValueNow = rtsDWT_CYCCNT; - - /* The SysTick is a down counter. How many clocks have passed since it was - last reloaded? */ - ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; - - /* How many times has it overflowed? */ - ulTickCount = xTaskGetTickCountFromISR(); - - /* Is there a SysTick interrupt pending? */ - if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL ) + /* Has the value overflowed since it was last read. */ + if( ulValueNow < ulLastCounterValue ) { - /* There is a SysTick interrupt pending, so the SysTick has overflowed - but the tick count not yet incremented. */ - ulTickCount++; - - /* Read the SysTick again, as the overflow might have occurred since - it was read last. */ - ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount; + ulOverflows++; } + ulLastCounterValue = ulValueNow; - /* Convert the tick count into tenths of a millisecond. THIS ASSUMES - configTICK_RATE_HZ is 1000! */ - ulReturn = ( ulTickCount * 10UL ) ; + /* Cannot use configCPU_CLOCK_HZ directly as it may itself not be a constant + but instead map to a variable that holds the clock speed. */ - /* Add on the number of tenths of a millisecond that have passed since the - tick count last got updated. */ - ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond ); + /* There is no prescale on the counter, so simulate in software. */ + if( configCPU_CLOCK_HZ < runtimeSLOWER_CLOCK_SPEEDS ) + { + ulValueNow >>= runtimeSHIFT_13; + ulValueNow += ( runtimeOVERFLOW_BIT_13 * ulOverflows ); + } + else + { + ulValueNow >>= runtimeSHIFT_14; + ulValueNow += ( runtimeOVERFLOW_BIT_14 * ulOverflows ); + } - return ulReturn; + return ulValueNow; } /*-----------------------------------------------------------*/