From 247c65c270891473bb0d0f53e4183b05ac832c5b Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Wed, 24 Mar 2021 16:03:44 +0000 Subject: [PATCH] add perf_counter --- .gitmodules | 3 ++ example/app_platform/app_platform.c | 28 ----------- example/build/mdk/Blinky.uvoptx | 48 ++++++++++++++----- example/build/mdk/Blinky.uvprojx | 10 ++++ example/build/mdk/EventRecorderStub.scvd | 9 ++++ sources/gmsi/arch/app_cfg.h | 35 ++++++++++++++ sources/gmsi/arch/arch.h | 44 +++++++++++++++++ sources/gmsi/arch/arm/app_cfg.h | 35 ++++++++++++++ sources/gmsi/arch/arm/cortex-m/app_cfg.h | 35 ++++++++++++++ .../gmsi/arch/arm/cortex-m/arch_cortex-m.c | 42 ++++++++++++++++ .../gmsi/arch/arm/cortex-m/arch_cortex-m.h | 40 ++++++++++++++++ sources/gmsi/arch/arm/cortex-m/perf_counter | 1 + sources/gmsi/gmsi.h | 7 +-- sources/gmsi/utilities/arm/arm_compiler.h | 2 + 14 files changed, 296 insertions(+), 43 deletions(-) create mode 100644 example/build/mdk/EventRecorderStub.scvd create mode 100644 sources/gmsi/arch/app_cfg.h create mode 100644 sources/gmsi/arch/arch.h create mode 100644 sources/gmsi/arch/arm/app_cfg.h create mode 100644 sources/gmsi/arch/arm/cortex-m/app_cfg.h create mode 100644 sources/gmsi/arch/arm/cortex-m/arch_cortex-m.c create mode 100644 sources/gmsi/arch/arm/cortex-m/arch_cortex-m.h create mode 160000 sources/gmsi/arch/arm/cortex-m/perf_counter diff --git a/.gitmodules b/.gitmodules index 6bb9e90..dcec0b9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "sources/gmsi/utilities/3rd-party/PLOOC"] path = sources/gmsi/utilities/3rd-party/PLOOC url = https://github.com/GorgonMeducer/PLOOC.git +[submodule "sources/gmsi/arch/arm/cortex-m/perf_counter"] + path = sources/gmsi/arch/arm/cortex-m/perf_counter + url = https://github.com/GorgonMeducer/perf_counter diff --git a/example/app_platform/app_platform.c b/example/app_platform/app_platform.c index e6b1611..46bd613 100644 --- a/example/app_platform/app_platform.c +++ b/example/app_platform/app_platform.c @@ -61,7 +61,6 @@ FILEHANDLE $Sub$$_sys_open(const char *name, int openmode) */ void app_platform_1ms_event_handler(void) { - counter_overflow(); STREAM_IN_1ms_event_handler(); } @@ -88,32 +87,5 @@ void app_platform_init( void ) NVIC_SystemReset(); } - -volatile static int32_t s_nCycleCounts = 0; - -/*! \brief start performance counter (cycle accurate) - */ -void start_counter(void) -{ - __IRQ_SAFE { - s_nCycleCounts = (int32_t)SysTick->VAL - (int32_t)SysTick->LOAD; - } -} - -static ALWAYS_INLINE void counter_overflow(void) -{ - s_nCycleCounts += SysTick->LOAD; -} - -/*! \brief stop performance counter (cycle accurate) - *! \retval cycle elapsed. - */ -int32_t stop_counter(void) -{ - __IRQ_SAFE { - s_nCycleCounts += (int32_t)SysTick->LOAD - (int32_t)SysTick->VAL; - } - return s_nCycleCounts; -} /* EOF */ diff --git a/example/build/mdk/Blinky.uvoptx b/example/build/mdk/Blinky.uvoptx index 4855877..2a03c5f 100644 --- a/example/build/mdk/Blinky.uvoptx +++ b/example/build/mdk/Blinky.uvoptx @@ -304,7 +304,7 @@ gmsi - 1 + 0 0 0 0 @@ -312,7 +312,7 @@ 3 6 1 - 1 + 0 0 0 ..\..\..\sources\gmsi\utilities\arm\signal.c @@ -872,17 +872,41 @@ 0 0 + + 3 + 53 + 1 + 0 + 0 + 0 + ..\..\..\sources\gmsi\arch\arm\cortex-m\arch_cortex-m.c + arch_cortex-m.c + 0 + 0 + + + 3 + 54 + 4 + 0 + 0 + 0 + ..\..\..\sources\gmsi\arch\arm\cortex-m\perf_counter\lib\perf_counter.lib + perf_counter.lib + 0 + 0 + app_platform - 0 + 1 0 0 0 4 - 53 + 55 5 0 0 @@ -894,7 +918,7 @@ 4 - 54 + 56 1 0 0 @@ -906,7 +930,7 @@ 4 - 55 + 57 1 0 0 @@ -918,7 +942,7 @@ 4 - 56 + 58 5 0 0 @@ -938,7 +962,7 @@ 0 5 - 57 + 59 5 0 0 @@ -950,7 +974,7 @@ 5 - 58 + 60 5 0 0 @@ -962,7 +986,7 @@ 5 - 59 + 61 5 0 0 @@ -974,7 +998,7 @@ 5 - 60 + 62 5 0 0 @@ -986,7 +1010,7 @@ 5 - 61 + 63 5 0 0 diff --git a/example/build/mdk/Blinky.uvprojx b/example/build/mdk/Blinky.uvprojx index 8a23416..038a271 100644 --- a/example/build/mdk/Blinky.uvprojx +++ b/example/build/mdk/Blinky.uvprojx @@ -704,6 +704,16 @@ 1 ..\..\..\sources\gmsi\utilities\delegate.c + + arch_cortex-m.c + 1 + ..\..\..\sources\gmsi\arch\arm\cortex-m\arch_cortex-m.c + + + perf_counter.lib + 4 + ..\..\..\sources\gmsi\arch\arm\cortex-m\perf_counter\lib\perf_counter.lib + diff --git a/example/build/mdk/EventRecorderStub.scvd b/example/build/mdk/EventRecorderStub.scvd new file mode 100644 index 0000000..2956b29 --- /dev/null +++ b/example/build/mdk/EventRecorderStub.scvd @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/sources/gmsi/arch/app_cfg.h b/sources/gmsi/arch/app_cfg.h new file mode 100644 index 0000000..31f3403 --- /dev/null +++ b/sources/gmsi/arch/app_cfg.h @@ -0,0 +1,35 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + + +//! \note do not move this pre-processor statement to other places +#include "..\app_cfg.h" + +#ifndef __ARCH_APP_CFG_H__ +#define __ARCH_APP_CFG_H__ + +/*============================ INCLUDES ======================================*/ +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ + + +#endif +/* EOF */ diff --git a/sources/gmsi/arch/arch.h b/sources/gmsi/arch/arch.h new file mode 100644 index 0000000..58c5848 --- /dev/null +++ b/sources/gmsi/arch/arch.h @@ -0,0 +1,44 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + +#ifndef __ARCH_H__ +#define __ARCH_H__ + +/*============================ INCLUDES ======================================*/ +#include ".\app_cfg.h" + +#ifndef __GMSI_ARCH_HEADER +# error no specified architecture +#endif + +#include __GMSI_ARCH_HEADER + +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ +/*! \note initialize architecture + * \param none + * \retval true initialization succeeded. + * \retval false initialization failed + */ +extern bool arch_init( void ); + +#endif +/* EOF */ diff --git a/sources/gmsi/arch/arm/app_cfg.h b/sources/gmsi/arch/arm/app_cfg.h new file mode 100644 index 0000000..226b5c5 --- /dev/null +++ b/sources/gmsi/arch/arm/app_cfg.h @@ -0,0 +1,35 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + + +//! \note do not move this pre-processor statement to other places +#include "..\app_cfg.h" + +#ifndef __ARCH_ARM_APP_CFG_H__ +#define __ARCH_ARM_APP_CFG_H__ + +/*============================ INCLUDES ======================================*/ +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ + + +#endif +/* EOF */ diff --git a/sources/gmsi/arch/arm/cortex-m/app_cfg.h b/sources/gmsi/arch/arm/cortex-m/app_cfg.h new file mode 100644 index 0000000..60563dc --- /dev/null +++ b/sources/gmsi/arch/arm/cortex-m/app_cfg.h @@ -0,0 +1,35 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + + +//! \note do not move this pre-processor statement to other places +#include "..\app_cfg.h" + +#ifndef __ARCH_CORTEX_M_APP_CFG_H__ +#define __ARCH_CORTEX_M_APP_CFG_H__ + +/*============================ INCLUDES ======================================*/ +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ + + +#endif +/* EOF */ diff --git a/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.c b/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.c new file mode 100644 index 0000000..7014e53 --- /dev/null +++ b/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.c @@ -0,0 +1,42 @@ +/**************************************************************************** +* 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 ======================================*/ +#include ".\app_cfg.h" + +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ +/*============================ IMPLEMENTATION ================================*/ + + +/*! \note initialize architecture + * \param none + * \retval true initialization succeeded. + * \retval false initialization failed + */ +bool arch_init( void ) +{ + //! add code here + + return true; +} + +/* EOF */ diff --git a/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.h b/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.h new file mode 100644 index 0000000..4639ab6 --- /dev/null +++ b/sources/gmsi/arch/arm/cortex-m/arch_cortex-m.h @@ -0,0 +1,40 @@ +/**************************************************************************** +* 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. * +* * +****************************************************************************/ + +#ifndef __ARCH_CORTEX_M_H__ +#define __ARCH_CORTEX_M_H__ + +/*============================ INCLUDES ======================================*/ +#include "./app_cfg.h" + +#include "./perf_counter/perf_counter.h" + +/*============================ MACROS ========================================*/ +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ +/*============================ PROTOTYPES ====================================*/ +/*! \note initialize architecture + * \param none + * \retval true initialization succeeded. + * \retval false initialization failed + */ +extern bool arch_init( void ); + +#endif +/* EOF */ diff --git a/sources/gmsi/arch/arm/cortex-m/perf_counter b/sources/gmsi/arch/arm/cortex-m/perf_counter new file mode 160000 index 0000000..9c080b0 --- /dev/null +++ b/sources/gmsi/arch/arm/cortex-m/perf_counter @@ -0,0 +1 @@ +Subproject commit 9c080b0c0188b7dd65ab80fccde247c99303b108 diff --git a/sources/gmsi/gmsi.h b/sources/gmsi/gmsi.h index 00875e4..4b24e00 100644 --- a/sources/gmsi/gmsi.h +++ b/sources/gmsi/gmsi.h @@ -20,9 +20,10 @@ /*============================ INCLUDES ======================================*/ -#include ".\app_cfg.h" -#include ".\hal\hal.h" -#include ".\service\service.h" +#include "./app_cfg.h" +#include "./arch/arch.h" +#include "./hal/hal.h" +#include "./service\/service.h" /*============================ MACROS ========================================*/ diff --git a/sources/gmsi/utilities/arm/arm_compiler.h b/sources/gmsi/utilities/arm/arm_compiler.h index 799b60d..0f05467 100644 --- a/sources/gmsi/utilities/arm/arm_compiler.h +++ b/sources/gmsi/utilities/arm/arm_compiler.h @@ -546,6 +546,8 @@ __attribute__((always_inline)) static inline void ____set_PRIMASK(uint32_t priMa # error Unsupported compiler detected. Please contact vsf team for support. #endif +#define __GMSI_ARCH_HEADER "arm/cortex-m/arch_cortex-m.h" + /*============================ TYPES =========================================*/ /*============================ INCLUDES ======================================*/