mirror of
https://github.com/GorgonMeducer/perf_counter.git
synced 2025-01-17 19:13:03 +08:00
Add support for FreeRTOS
This commit is contained in:
parent
e039a3031d
commit
11f13aaf88
@ -3,7 +3,7 @@
|
||||
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
|
||||
<vendor>GorgonMeducer</vendor>
|
||||
<name>perf_counter</name>
|
||||
<description>A dedicated performance counter for Cortex-M systick. It shares the SysTick with users' original SysTick function without interfere it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h</description>
|
||||
<description>A dedicated performance counter for the Cortex-M Systick. It shares the SysTick with users' original SysTick function without interfering with it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h</description>
|
||||
<url>https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/</url>
|
||||
<supportContact>https://github.com/GorgonMeducer/perf_counter/issues</supportContact>
|
||||
<license>lib/LICENSE</license>
|
||||
@ -16,6 +16,10 @@
|
||||
<repository type="git">https://github.com/GorgonMeducer/perf_counter.git</repository>
|
||||
|
||||
<releases>
|
||||
<release date="2021-12-22" version="1.7.1" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.1.7.1.pack">
|
||||
- Add support for FreeRTOS
|
||||
- Other minor update
|
||||
</release>
|
||||
<release date="2021-12-20" version="1.7.0" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.1.7.0.pack">
|
||||
- Add new feature for RTOS. Now you can get cycle information for the current thread.
|
||||
- Other minor update
|
||||
@ -81,9 +85,16 @@
|
||||
<require Cclass="CMSIS" Cgroup="CORE"/>
|
||||
</condition>
|
||||
|
||||
<condition id="RTX5">
|
||||
<condition id="RTX5 Patch">
|
||||
<description>Require RTX5 Support</description>
|
||||
<accept Cclass="CMSIS" Cgroup="RTOS2" Csub="Keil RTX5" Cvariant="Source"/>
|
||||
<require Cclass="Utilities" Cgroup="perf_counter" Csub="Core"/>
|
||||
</condition>
|
||||
|
||||
<condition id="FreeRTOS Patch">
|
||||
<description>Require FreeRTOS Support</description>
|
||||
<accept Cbundle="FreeRTOS" Cclass="RTOS" Cversion="10.3.1"/>
|
||||
<require Cclass="Utilities" Cgroup="perf_counter" Csub="Core"/>
|
||||
</condition>
|
||||
|
||||
<condition id="Cortex-M Arm GCC">
|
||||
@ -143,35 +154,67 @@
|
||||
-->
|
||||
|
||||
<components>
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="perf_counter" Cvariant="Library" Cversion="1.7.0" isDefaultVariant="true">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="library" name="lib/perf_counter.lib" condition="Cortex-M Arm Compiler"/>
|
||||
<file category="library" name="lib/libperf_counter_gcc.a" condition="Cortex-M Arm GCC"/>
|
||||
</files>
|
||||
</component>
|
||||
<bundle Cbundle="Performance Counter" Cclass="Utilities" Cversion="1.7.1">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<doc></doc>
|
||||
<component Cgroup="perf_counter" Csub="Core" Cvariant="Library" isDefaultVariant="true">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="library" name="lib/perf_counter.lib" condition="Cortex-M Arm Compiler"/>
|
||||
<file category="library" name="lib/libperf_counter_gcc.a" condition="Cortex-M Arm GCC"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="perf_counter" Cvariant="Source" Cversion="1.7.0" condition="CMSIS-CORE">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="source" name="perf_counter.c" />
|
||||
<file category="source" name="systick_wrapper_ual.s" condition="Cortex-M Arm Compiler CMSIS-CORE"/>
|
||||
<file category="source" name="systick_wrapper_gcc.s" condition="Cortex-M Arm GCC CMSIS-CORE"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="RTX5 Patch" Cversion="1.7.0" condition="RTX5">
|
||||
<description>A Patch for RTX5</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_rtx5.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
<component Cgroup="perf_counter" Csub="Core" Cvariant="Source" condition="CMSIS-CORE">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="source" name="perf_counter.c" />
|
||||
<file category="source" name="systick_wrapper_ual.s" condition="Cortex-M Arm Compiler CMSIS-CORE"/>
|
||||
<file category="source" name="systick_wrapper_gcc.s" condition="Cortex-M Arm GCC CMSIS-CORE"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
|
||||
<description>A Patch for RTX5</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_rtx5.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
//! \brief Enable RTOS Patch for perf_counter
|
||||
#define __PERF_CNT_USE_RTOS__
|
||||
</Pre_Include_Global_h>
|
||||
</component>
|
||||
</Pre_Include_Global_h>
|
||||
</component>
|
||||
|
||||
<component Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="FreeRTOS Patch">
|
||||
<description>A Patch for FreeRTOS</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_freertos.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
//! \brief Enable RTOS Patch for perf_counter
|
||||
#define __PERF_CNT_USE_RTOS__
|
||||
</Pre_Include_Global_h>
|
||||
<RTE_Components_h>
|
||||
#define traceTASK_SWITCHED_OUT_DISABLE
|
||||
#define traceTASK_SWITCHED_IN_DISABLE
|
||||
|
||||
#if defined(MPU_WRAPPERS_INCLUDED_FROM_API_FILE)
|
||||
|
||||
|
||||
extern void __freertos_evr_on_task_switched_out (void *ptTCB);
|
||||
extern void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) ;
|
||||
|
||||
# define traceTASK_SWITCHED_OUT() \
|
||||
__freertos_evr_on_task_switched_out(pxCurrentTCB)
|
||||
# define traceTASK_SWITCHED_IN() \
|
||||
__freertos_evr_on_task_switched_in(pxCurrentTCB, uxTopReadyPriority)
|
||||
|
||||
#endif
|
||||
</RTE_Components_h>
|
||||
</component>
|
||||
</bundle>
|
||||
</components>
|
||||
|
||||
<!-- optional taxonomy section for defining new component Class and Group names -->
|
||||
|
@ -1,2 +1,2 @@
|
||||
# perf_counter
|
||||
A dedicated performance counter for Cortex-M systick. It shares the SysTick with users' original SysTick function without interfere it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h
|
||||
A dedicated performance counter for Cortex-M systick. It shares the SysTick with users' original SysTick function without interfering with it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h.
|
||||
|
BIN
cmsis-pack/GorgonMeducer.perf_counter.1.7.1.pack
Normal file
BIN
cmsis-pack/GorgonMeducer.perf_counter.1.7.1.pack
Normal file
Binary file not shown.
@ -3,7 +3,7 @@
|
||||
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
|
||||
<vendor>GorgonMeducer</vendor>
|
||||
<name>perf_counter</name>
|
||||
<description>A dedicated performance counter for Cortex-M systick. It shares the SysTick with users' original SysTick function without interfere it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h</description>
|
||||
<description>A dedicated performance counter for the Cortex-M Systick. It shares the SysTick with users' original SysTick function without interfering with it. This library will bring new functionalities, such as performance counter, delay_us and clock() service defined in time.h</description>
|
||||
<url>https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/</url>
|
||||
<supportContact>https://github.com/GorgonMeducer/perf_counter/issues</supportContact>
|
||||
<license>lib/LICENSE</license>
|
||||
@ -16,6 +16,10 @@
|
||||
<repository type="git">https://github.com/GorgonMeducer/perf_counter.git</repository>
|
||||
|
||||
<releases>
|
||||
<release date="2021-12-22" version="1.7.1" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.1.7.1.pack">
|
||||
- Add support for FreeRTOS
|
||||
- Other minor update
|
||||
</release>
|
||||
<release date="2021-12-20" version="1.7.0" url="https://raw.githubusercontent.com/GorgonMeducer/perf_counter/CMSIS-Pack/cmsis-pack/GorgonMeducer.perf_counter.1.7.0.pack">
|
||||
- Add new feature for RTOS. Now you can get cycle information for the current thread.
|
||||
- Other minor update
|
||||
@ -81,9 +85,16 @@
|
||||
<require Cclass="CMSIS" Cgroup="CORE"/>
|
||||
</condition>
|
||||
|
||||
<condition id="RTX5">
|
||||
<condition id="RTX5 Patch">
|
||||
<description>Require RTX5 Support</description>
|
||||
<accept Cclass="CMSIS" Cgroup="RTOS2" Csub="Keil RTX5" Cvariant="Source"/>
|
||||
<require Cclass="Utilities" Cgroup="perf_counter" Csub="Core"/>
|
||||
</condition>
|
||||
|
||||
<condition id="FreeRTOS Patch">
|
||||
<description>Require FreeRTOS Support</description>
|
||||
<accept Cbundle="FreeRTOS" Cclass="RTOS" Cversion="10.3.1"/>
|
||||
<require Cclass="Utilities" Cgroup="perf_counter" Csub="Core"/>
|
||||
</condition>
|
||||
|
||||
<condition id="Cortex-M Arm GCC">
|
||||
@ -143,35 +154,67 @@
|
||||
-->
|
||||
|
||||
<components>
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="perf_counter" Cvariant="Library" Cversion="1.7.0" isDefaultVariant="true">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="library" name="lib/perf_counter.lib" condition="Cortex-M Arm Compiler"/>
|
||||
<file category="library" name="lib/libperf_counter_gcc.a" condition="Cortex-M Arm GCC"/>
|
||||
</files>
|
||||
</component>
|
||||
<bundle Cbundle="Performance Counter" Cclass="Utilities" Cversion="1.7.1">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<doc></doc>
|
||||
<component Cgroup="perf_counter" Csub="Core" Cvariant="Library" isDefaultVariant="true">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="library" name="lib/perf_counter.lib" condition="Cortex-M Arm Compiler"/>
|
||||
<file category="library" name="lib/libperf_counter_gcc.a" condition="Cortex-M Arm GCC"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="perf_counter" Cvariant="Source" Cversion="1.7.0" condition="CMSIS-CORE">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="source" name="perf_counter.c" />
|
||||
<file category="source" name="systick_wrapper_ual.s" condition="Cortex-M Arm Compiler CMSIS-CORE"/>
|
||||
<file category="source" name="systick_wrapper_gcc.s" condition="Cortex-M Arm GCC CMSIS-CORE"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cclass="Utilities" Cgroup="Performance" Csub="RTX5 Patch" Cversion="1.7.0" condition="RTX5">
|
||||
<description>A Patch for RTX5</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_rtx5.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
<component Cgroup="perf_counter" Csub="Core" Cvariant="Source" condition="CMSIS-CORE">
|
||||
<description>A dedicated performance counter for Cortex-M systick.</description>
|
||||
<files>
|
||||
<file category="header" name="lib/perf_counter.h"/>
|
||||
<file category="source" name="perf_counter.c" />
|
||||
<file category="source" name="systick_wrapper_ual.s" condition="Cortex-M Arm Compiler CMSIS-CORE"/>
|
||||
<file category="source" name="systick_wrapper_gcc.s" condition="Cortex-M Arm GCC CMSIS-CORE"/>
|
||||
</files>
|
||||
</component>
|
||||
|
||||
<component Cgroup="perf_counter" Csub="RTX5 Patch" condition="RTX5 Patch">
|
||||
<description>A Patch for RTX5</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_rtx5.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
//! \brief Enable RTOS Patch for perf_counter
|
||||
#define __PERF_CNT_USE_RTOS__
|
||||
</Pre_Include_Global_h>
|
||||
</component>
|
||||
</Pre_Include_Global_h>
|
||||
</component>
|
||||
|
||||
<component Cgroup="perf_counter" Csub="FreeRTOS Patch" condition="FreeRTOS Patch">
|
||||
<description>A Patch for FreeRTOS</description>
|
||||
<files>
|
||||
<file category="source" name="lib/perf_os_patch_freertos.c"/>
|
||||
</files>
|
||||
<Pre_Include_Global_h>
|
||||
//! \brief Enable RTOS Patch for perf_counter
|
||||
#define __PERF_CNT_USE_RTOS__
|
||||
</Pre_Include_Global_h>
|
||||
<RTE_Components_h>
|
||||
#define traceTASK_SWITCHED_OUT_DISABLE
|
||||
#define traceTASK_SWITCHED_IN_DISABLE
|
||||
|
||||
#if defined(MPU_WRAPPERS_INCLUDED_FROM_API_FILE)
|
||||
|
||||
|
||||
extern void __freertos_evr_on_task_switched_out (void *ptTCB);
|
||||
extern void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) ;
|
||||
|
||||
# define traceTASK_SWITCHED_OUT() \
|
||||
__freertos_evr_on_task_switched_out(pxCurrentTCB)
|
||||
# define traceTASK_SWITCHED_IN() \
|
||||
__freertos_evr_on_task_switched_in(pxCurrentTCB, uxTopReadyPriority)
|
||||
|
||||
#endif
|
||||
</RTE_Components_h>
|
||||
</component>
|
||||
</bundle>
|
||||
</components>
|
||||
|
||||
<!-- optional taxonomy section for defining new component Class and Group names -->
|
||||
|
@ -54,6 +54,7 @@ PACK_BASE_FILES="
|
||||
systick_wrapper_gcc.s
|
||||
systick_wrapper_ual.s
|
||||
perf_os_patch_rtx5.c
|
||||
perf_os_patch_freertos.c
|
||||
LICENSE
|
||||
README.md
|
||||
"
|
||||
@ -139,6 +140,7 @@ fi
|
||||
cp -f ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_BUILD}
|
||||
|
||||
cp -f ./perf_os_patch_rtx5.c ./lib
|
||||
cp -f ./perf_os_patch_freertos.c ./lib
|
||||
cp -f ./perf_counter.h ./lib
|
||||
|
||||
# directories
|
||||
|
@ -341,7 +341,7 @@ extern void start_task_cycle_counter(void);
|
||||
*/
|
||||
extern int32_t stop_task_cycle_counter(void);
|
||||
|
||||
#else
|
||||
#elif !defined(__IMPLEMENT_PERF_COUNTER)
|
||||
|
||||
# define start_task_cycle_counter start_cycle_counter
|
||||
# define stop_task_cycle_counter stop_cycle_counter
|
||||
|
Binary file not shown.
231
lib/perf_os_patch_freertos.c
Normal file
231
lib/perf_os_patch_freertos.c
Normal file
@ -0,0 +1,231 @@
|
||||
/****************************************************************************
|
||||
* Copyright 2021 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*============================ INCLUDES ======================================*/
|
||||
|
||||
|
||||
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
|
||||
all the API functions to use the MPU wrappers. That should only be done when
|
||||
task.h is included from an application file. */
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "stack_macros.h"
|
||||
|
||||
/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
|
||||
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
||||
for the header files above, but not in this file, in order to generate the
|
||||
correct privileged Vs unprivileged linkage and placement. */
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */
|
||||
|
||||
#include "perf_counter.h"
|
||||
#include "cmsis_compiler.h"
|
||||
|
||||
/*============================ MACROS ========================================*/
|
||||
|
||||
#undef __WRAP_FUNC
|
||||
#undef WRAP_FUNC
|
||||
#if defined(__IS_COMPILER_ARM_COMPILER__) && __IS_COMPILER_ARM_COMPILER__
|
||||
|
||||
# define __WRAP_FUNC(__NAME) $Sub$$##__NAME
|
||||
# define __ORIG_FUNC(__NAME) $Super$$##__NAME
|
||||
|
||||
#elif (defined(__IS_COMPILER_LLVM__) && __IS_COMPILER_LLVM__) \
|
||||
|| (defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__)
|
||||
|
||||
# define __WRAP_FUNC(__NAME) __wrap_##__NAME
|
||||
# define __ORIG_FUNC(__NAME) __real_##__NAME
|
||||
|
||||
#endif
|
||||
#define WRAP_FUNC(__NAME) __WRAP_FUNC(__NAME)
|
||||
#define ORIG_FUNC(__NAME) __ORIG_FUNC(__NAME)
|
||||
|
||||
struct __task_cycle_info_t {
|
||||
uint64_t dwLastTimeStamp;
|
||||
task_cycle_info_t tInfo;
|
||||
} ;
|
||||
|
||||
/*============================ TYPES =========================================*/
|
||||
|
||||
/*
|
||||
* Task control block. A task control block (TCB) is allocated for each task,
|
||||
* and stores task state information, including a pointer to the task's context
|
||||
* (the task's run time environment, including register values)
|
||||
*/
|
||||
typedef struct tskTaskControlBlock /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */
|
||||
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
|
||||
#endif
|
||||
|
||||
ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
|
||||
ListItem_t xEventListItem; /*< Used to reference a task from an event list. */
|
||||
UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */
|
||||
StackType_t *pxStack; /*< Points to the start of the stack. */
|
||||
char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
|
||||
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
|
||||
StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */
|
||||
#endif
|
||||
|
||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */
|
||||
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
|
||||
UBaseType_t uxMutexesHeld;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
|
||||
TaskHookFunction_t pxTaskTag;
|
||||
#endif
|
||||
|
||||
#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
|
||||
void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
|
||||
#endif
|
||||
|
||||
#if( configGENERATE_RUN_TIME_STATS == 1 )
|
||||
uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_NEWLIB_REENTRANT == 1 )
|
||||
/* Allocate a Newlib reent structure that is specific to this task.
|
||||
Note Newlib support has been included by popular demand, but is not
|
||||
used by the FreeRTOS maintainers themselves. FreeRTOS is not
|
||||
responsible for resulting newlib operation. User must be familiar with
|
||||
newlib and must provide system-wide implementations of the necessary
|
||||
stubs. Be warned that (at the time of writing) the current newlib design
|
||||
implements a system-wide malloc() that must be provided with locks.
|
||||
|
||||
See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html
|
||||
for additional information. */
|
||||
struct _reent xNewLib_reent;
|
||||
#endif
|
||||
|
||||
#if( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
volatile uint32_t ulNotifiedValue;
|
||||
volatile uint8_t ucNotifyState;
|
||||
#endif
|
||||
|
||||
/* See the comments in FreeRTOS.h with the definition of
|
||||
tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */
|
||||
#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
|
||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */
|
||||
#endif
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
uint8_t ucDelayAborted;
|
||||
#endif
|
||||
|
||||
#if( configUSE_POSIX_ERRNO == 1 )
|
||||
int iTaskErrno;
|
||||
#endif
|
||||
|
||||
} tskTCB;
|
||||
|
||||
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name
|
||||
below to enable the use of older kernel aware debuggers. */
|
||||
typedef tskTCB TCB_t;
|
||||
|
||||
/*lint -save -e956 A manual analysis and inspection has been used to determine
|
||||
which static variables must be declared volatile. */
|
||||
PRIVILEGED_DATA
|
||||
extern TCB_t * volatile pxCurrentTCB;
|
||||
|
||||
/*
|
||||
#define traceTASK_SWITCHED_OUT_DISABLE
|
||||
#define traceTASK_SWITCHED_IN_DISABLE
|
||||
|
||||
#if defined(MPU_WRAPPERS_INCLUDED_FROM_API_FILE)
|
||||
|
||||
|
||||
extern void __freertos_evr_on_task_switched_out (void *ptTCB);
|
||||
extern void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) ;
|
||||
|
||||
# define traceTASK_SWITCHED_OUT() \
|
||||
__freertos_evr_on_task_switched_out(pxCurrentTCB)
|
||||
# define traceTASK_SWITCHED_IN() \
|
||||
__freertos_evr_on_task_switched_in(pxCurrentTCB, uxTopReadyPriority)
|
||||
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
extern void __on_context_switch_in(uint32_t *pwStack);
|
||||
extern void __on_context_switch_out(uint32_t *pwStack);
|
||||
|
||||
/*============================ IMPLEMENTATION ================================*/
|
||||
|
||||
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
|
||||
# include "EventRecorder.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define EvtFreeRTOSTasksNo (0xF0U)
|
||||
|
||||
#define EvtFreeRTOSTasks_TaskSwitchedOut \
|
||||
EventID(EventLevelOp, EvtFreeRTOSTasksNo, 0x0BU)
|
||||
#define EvtFreeRTOSTasks_TaskSwitchedIn \
|
||||
EventID(EventLevelOp, EvtFreeRTOSTasksNo, 0x0CU)
|
||||
|
||||
void __freertos_evr_on_task_switched_out (void *ptTCB) {
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
EventRecord2(EvtFreeRTOSTasks_TaskSwitchedOut, (uint32_t)ptTCB, 0U);
|
||||
#else
|
||||
(void)pxCurrentTCB;
|
||||
#endif
|
||||
|
||||
__on_context_switch_out(((TCB_t *)ptTCB)->pxStack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) {
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
EventRecord2(EvtFreeRTOSTasks_TaskSwitchedIn, (uint32_t)ptTCB, uxTopPriority);
|
||||
#else
|
||||
(void)pxCurrentTCB;
|
||||
(void)uxTopPriority;
|
||||
#endif
|
||||
|
||||
__on_context_switch_in(((TCB_t *)ptTCB)->pxStack);
|
||||
}
|
||||
|
||||
|
||||
task_cycle_info_t * get_rtos_task_cycle_info(void)
|
||||
{
|
||||
return &(((struct __task_cycle_info_t *)pxCurrentTCB->pxStack)->tInfo);
|
||||
}
|
@ -52,43 +52,20 @@ struct __task_cycle_info_t {
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
extern void __on_context_switch_in(uint32_t *pwStack);
|
||||
extern void __on_context_switch_out(uint32_t *pwStack);
|
||||
|
||||
/*============================ IMPLEMENTATION ================================*/
|
||||
|
||||
|
||||
/*! \brief wrapper function for rtos context switching */
|
||||
void __on_context_switch (osRtxThread_t *thread)
|
||||
{
|
||||
if (NULL != osRtxInfo.thread.run.curr) {
|
||||
__on_context_switch_out(osRtxInfo.thread.run.curr->stack_mem);
|
||||
}
|
||||
|
||||
//assert(NULL != ptThread);
|
||||
|
||||
do {
|
||||
struct __task_cycle_info_t *ptFrame = NULL;
|
||||
uint64_t dwTimeStamp;
|
||||
osRtxThread_t *curr = osRtxInfo.thread.run.curr;
|
||||
if (curr == thread) {
|
||||
break;
|
||||
}
|
||||
|
||||
//! get current system ticks
|
||||
dwTimeStamp = get_system_ticks();
|
||||
|
||||
if (NULL != curr) {
|
||||
ptFrame = (struct __task_cycle_info_t *)curr->stack_mem;
|
||||
|
||||
ptFrame->tInfo.dwUsedRecent = dwTimeStamp - ptFrame->dwLastTimeStamp;
|
||||
ptFrame->tInfo.dwUsedTotal += ptFrame->tInfo.dwUsedRecent;
|
||||
}
|
||||
|
||||
//! inital target thread
|
||||
|
||||
ptFrame = (struct __task_cycle_info_t *)thread->stack_mem;
|
||||
|
||||
if (0 == ptFrame->tInfo.dwStart) {
|
||||
ptFrame->tInfo.dwStart = dwTimeStamp;
|
||||
}
|
||||
ptFrame->dwLastTimeStamp = dwTimeStamp;
|
||||
ptFrame->tInfo.wActiveCount++;
|
||||
} while(0);
|
||||
__on_context_switch_in(thread->stack_mem);
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
@ -117,22 +94,3 @@ task_cycle_info_t * get_rtos_task_cycle_info(void)
|
||||
return &(((struct __task_cycle_info_t *)curr->stack_mem)->tInfo);
|
||||
}
|
||||
|
||||
void start_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
ptInfo->dwUsedTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t stop_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
return (int32_t)ptInfo->dwUsedTotal;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_compiler.h"
|
||||
|
||||
#define __IMPLEMENT_PERF_COUNTER
|
||||
#include "perf_counter.h"
|
||||
|
||||
#if defined(__IS_COMPILER_GCC__)
|
||||
@ -153,6 +155,11 @@ typedef struct
|
||||
__IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
|
||||
} SCB_Type;
|
||||
|
||||
struct __task_cycle_info_t {
|
||||
uint64_t dwLastTimeStamp;
|
||||
task_cycle_info_t tInfo;
|
||||
} ;
|
||||
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
@ -379,3 +386,54 @@ int64_t get_system_ticks(void)
|
||||
|
||||
return lTemp;
|
||||
}
|
||||
|
||||
|
||||
__WEAK
|
||||
task_cycle_info_t * get_rtos_task_cycle_info(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void __on_context_switch_in(uint32_t *pwStack)
|
||||
{
|
||||
|
||||
struct __task_cycle_info_t *ptFrame = (struct __task_cycle_info_t *)pwStack;
|
||||
uint64_t dwTimeStamp = get_system_ticks();
|
||||
|
||||
if (0 == ptFrame->tInfo.dwStart) {
|
||||
ptFrame->tInfo.dwStart = dwTimeStamp;
|
||||
}
|
||||
ptFrame->dwLastTimeStamp = dwTimeStamp;
|
||||
ptFrame->tInfo.wActiveCount++;
|
||||
|
||||
}
|
||||
|
||||
void __on_context_switch_out(uint32_t *pwStack)
|
||||
{
|
||||
|
||||
uint64_t dwTimeStamp = get_system_ticks();
|
||||
struct __task_cycle_info_t *ptFrame = (struct __task_cycle_info_t *)pwStack;
|
||||
|
||||
ptFrame->tInfo.dwUsedRecent = dwTimeStamp - ptFrame->dwLastTimeStamp;
|
||||
ptFrame->tInfo.dwUsedTotal += ptFrame->tInfo.dwUsedRecent;
|
||||
|
||||
}
|
||||
|
||||
void start_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
ptInfo->dwUsedTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t stop_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
return (int32_t)ptInfo->dwUsedTotal;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ extern void start_task_cycle_counter(void);
|
||||
*/
|
||||
extern int32_t stop_task_cycle_counter(void);
|
||||
|
||||
#else
|
||||
#elif !defined(__IMPLEMENT_PERF_COUNTER)
|
||||
|
||||
# define start_task_cycle_counter start_cycle_counter
|
||||
# define stop_task_cycle_counter stop_cycle_counter
|
||||
|
231
perf_os_patch_freertos.c
Normal file
231
perf_os_patch_freertos.c
Normal file
@ -0,0 +1,231 @@
|
||||
/****************************************************************************
|
||||
* Copyright 2021 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*============================ INCLUDES ======================================*/
|
||||
|
||||
|
||||
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
|
||||
all the API functions to use the MPU wrappers. That should only be done when
|
||||
task.h is included from an application file. */
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "stack_macros.h"
|
||||
|
||||
/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
|
||||
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
||||
for the header files above, but not in this file, in order to generate the
|
||||
correct privileged Vs unprivileged linkage and placement. */
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */
|
||||
|
||||
#include "perf_counter.h"
|
||||
#include "cmsis_compiler.h"
|
||||
|
||||
/*============================ MACROS ========================================*/
|
||||
|
||||
#undef __WRAP_FUNC
|
||||
#undef WRAP_FUNC
|
||||
#if defined(__IS_COMPILER_ARM_COMPILER__) && __IS_COMPILER_ARM_COMPILER__
|
||||
|
||||
# define __WRAP_FUNC(__NAME) $Sub$$##__NAME
|
||||
# define __ORIG_FUNC(__NAME) $Super$$##__NAME
|
||||
|
||||
#elif (defined(__IS_COMPILER_LLVM__) && __IS_COMPILER_LLVM__) \
|
||||
|| (defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__)
|
||||
|
||||
# define __WRAP_FUNC(__NAME) __wrap_##__NAME
|
||||
# define __ORIG_FUNC(__NAME) __real_##__NAME
|
||||
|
||||
#endif
|
||||
#define WRAP_FUNC(__NAME) __WRAP_FUNC(__NAME)
|
||||
#define ORIG_FUNC(__NAME) __ORIG_FUNC(__NAME)
|
||||
|
||||
struct __task_cycle_info_t {
|
||||
uint64_t dwLastTimeStamp;
|
||||
task_cycle_info_t tInfo;
|
||||
} ;
|
||||
|
||||
/*============================ TYPES =========================================*/
|
||||
|
||||
/*
|
||||
* Task control block. A task control block (TCB) is allocated for each task,
|
||||
* and stores task state information, including a pointer to the task's context
|
||||
* (the task's run time environment, including register values)
|
||||
*/
|
||||
typedef struct tskTaskControlBlock /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */
|
||||
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
|
||||
#endif
|
||||
|
||||
ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
|
||||
ListItem_t xEventListItem; /*< Used to reference a task from an event list. */
|
||||
UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */
|
||||
StackType_t *pxStack; /*< Points to the start of the stack. */
|
||||
char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
|
||||
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
|
||||
StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */
|
||||
#endif
|
||||
|
||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */
|
||||
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
|
||||
UBaseType_t uxMutexesHeld;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
|
||||
TaskHookFunction_t pxTaskTag;
|
||||
#endif
|
||||
|
||||
#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
|
||||
void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
|
||||
#endif
|
||||
|
||||
#if( configGENERATE_RUN_TIME_STATS == 1 )
|
||||
uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_NEWLIB_REENTRANT == 1 )
|
||||
/* Allocate a Newlib reent structure that is specific to this task.
|
||||
Note Newlib support has been included by popular demand, but is not
|
||||
used by the FreeRTOS maintainers themselves. FreeRTOS is not
|
||||
responsible for resulting newlib operation. User must be familiar with
|
||||
newlib and must provide system-wide implementations of the necessary
|
||||
stubs. Be warned that (at the time of writing) the current newlib design
|
||||
implements a system-wide malloc() that must be provided with locks.
|
||||
|
||||
See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html
|
||||
for additional information. */
|
||||
struct _reent xNewLib_reent;
|
||||
#endif
|
||||
|
||||
#if( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
volatile uint32_t ulNotifiedValue;
|
||||
volatile uint8_t ucNotifyState;
|
||||
#endif
|
||||
|
||||
/* See the comments in FreeRTOS.h with the definition of
|
||||
tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */
|
||||
#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
|
||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */
|
||||
#endif
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
uint8_t ucDelayAborted;
|
||||
#endif
|
||||
|
||||
#if( configUSE_POSIX_ERRNO == 1 )
|
||||
int iTaskErrno;
|
||||
#endif
|
||||
|
||||
} tskTCB;
|
||||
|
||||
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name
|
||||
below to enable the use of older kernel aware debuggers. */
|
||||
typedef tskTCB TCB_t;
|
||||
|
||||
/*lint -save -e956 A manual analysis and inspection has been used to determine
|
||||
which static variables must be declared volatile. */
|
||||
PRIVILEGED_DATA
|
||||
extern TCB_t * volatile pxCurrentTCB;
|
||||
|
||||
/*
|
||||
#define traceTASK_SWITCHED_OUT_DISABLE
|
||||
#define traceTASK_SWITCHED_IN_DISABLE
|
||||
|
||||
#if defined(MPU_WRAPPERS_INCLUDED_FROM_API_FILE)
|
||||
|
||||
|
||||
extern void __freertos_evr_on_task_switched_out (void *ptTCB);
|
||||
extern void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) ;
|
||||
|
||||
# define traceTASK_SWITCHED_OUT() \
|
||||
__freertos_evr_on_task_switched_out(pxCurrentTCB)
|
||||
# define traceTASK_SWITCHED_IN() \
|
||||
__freertos_evr_on_task_switched_in(pxCurrentTCB, uxTopReadyPriority)
|
||||
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
extern void __on_context_switch_in(uint32_t *pwStack);
|
||||
extern void __on_context_switch_out(uint32_t *pwStack);
|
||||
|
||||
/*============================ IMPLEMENTATION ================================*/
|
||||
|
||||
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
|
||||
# include "EventRecorder.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define EvtFreeRTOSTasksNo (0xF0U)
|
||||
|
||||
#define EvtFreeRTOSTasks_TaskSwitchedOut \
|
||||
EventID(EventLevelOp, EvtFreeRTOSTasksNo, 0x0BU)
|
||||
#define EvtFreeRTOSTasks_TaskSwitchedIn \
|
||||
EventID(EventLevelOp, EvtFreeRTOSTasksNo, 0x0CU)
|
||||
|
||||
void __freertos_evr_on_task_switched_out (void *ptTCB) {
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
EventRecord2(EvtFreeRTOSTasks_TaskSwitchedOut, (uint32_t)ptTCB, 0U);
|
||||
#else
|
||||
(void)pxCurrentTCB;
|
||||
#endif
|
||||
|
||||
__on_context_switch_out(((TCB_t *)ptTCB)->pxStack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void __freertos_evr_on_task_switched_in(void *ptTCB, uint32_t uxTopPriority) {
|
||||
#if defined(RTE_Compiler_EventRecorder)
|
||||
EventRecord2(EvtFreeRTOSTasks_TaskSwitchedIn, (uint32_t)ptTCB, uxTopPriority);
|
||||
#else
|
||||
(void)pxCurrentTCB;
|
||||
(void)uxTopPriority;
|
||||
#endif
|
||||
|
||||
__on_context_switch_in(((TCB_t *)ptTCB)->pxStack);
|
||||
}
|
||||
|
||||
|
||||
task_cycle_info_t * get_rtos_task_cycle_info(void)
|
||||
{
|
||||
return &(((struct __task_cycle_info_t *)pxCurrentTCB->pxStack)->tInfo);
|
||||
}
|
@ -52,43 +52,20 @@ struct __task_cycle_info_t {
|
||||
/*============================ GLOBAL VARIABLES ==============================*/
|
||||
/*============================ LOCAL VARIABLES ===============================*/
|
||||
/*============================ PROTOTYPES ====================================*/
|
||||
extern void __on_context_switch_in(uint32_t *pwStack);
|
||||
extern void __on_context_switch_out(uint32_t *pwStack);
|
||||
|
||||
/*============================ IMPLEMENTATION ================================*/
|
||||
|
||||
|
||||
/*! \brief wrapper function for rtos context switching */
|
||||
void __on_context_switch (osRtxThread_t *thread)
|
||||
{
|
||||
if (NULL != osRtxInfo.thread.run.curr) {
|
||||
__on_context_switch_out(osRtxInfo.thread.run.curr->stack_mem);
|
||||
}
|
||||
|
||||
//assert(NULL != ptThread);
|
||||
|
||||
do {
|
||||
struct __task_cycle_info_t *ptFrame = NULL;
|
||||
uint64_t dwTimeStamp;
|
||||
osRtxThread_t *curr = osRtxInfo.thread.run.curr;
|
||||
if (curr == thread) {
|
||||
break;
|
||||
}
|
||||
|
||||
//! get current system ticks
|
||||
dwTimeStamp = get_system_ticks();
|
||||
|
||||
if (NULL != curr) {
|
||||
ptFrame = (struct __task_cycle_info_t *)curr->stack_mem;
|
||||
|
||||
ptFrame->tInfo.dwUsedRecent = dwTimeStamp - ptFrame->dwLastTimeStamp;
|
||||
ptFrame->tInfo.dwUsedTotal += ptFrame->tInfo.dwUsedRecent;
|
||||
}
|
||||
|
||||
//! inital target thread
|
||||
|
||||
ptFrame = (struct __task_cycle_info_t *)thread->stack_mem;
|
||||
|
||||
if (0 == ptFrame->tInfo.dwStart) {
|
||||
ptFrame->tInfo.dwStart = dwTimeStamp;
|
||||
}
|
||||
ptFrame->dwLastTimeStamp = dwTimeStamp;
|
||||
ptFrame->tInfo.wActiveCount++;
|
||||
} while(0);
|
||||
__on_context_switch_in(thread->stack_mem);
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
@ -117,22 +94,3 @@ task_cycle_info_t * get_rtos_task_cycle_info(void)
|
||||
return &(((struct __task_cycle_info_t *)curr->stack_mem)->tInfo);
|
||||
}
|
||||
|
||||
void start_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
ptInfo->dwUsedTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t stop_task_cycle_counter(void)
|
||||
{
|
||||
task_cycle_info_t * ptInfo = get_rtos_task_cycle_info();
|
||||
if (NULL != ptInfo) {
|
||||
return (int32_t)ptInfo->dwUsedTotal;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user