From d3ecc136d1b8fdebf88fb201e908fa82b2f7d3db Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Wed, 24 Mar 2021 14:44:46 +0000 Subject: [PATCH] Major update - introduce get_system_ticks() - rework on __cycleof__ - update other macros to support gcc extension: ({;;;;}) - update example --- .../_example_arm_compiler_6/RTE_Components.h | 48 +++++++++--------- example/RTE/_library/RTE_Components.h | 42 +++++++-------- example/example.uvoptx | 21 +------- example/example.uvprojx | 6 +-- example/main.c | 19 +++++-- lib/perf_counter.h | 41 ++++++++------- lib/perf_counter.lib | Bin 7216 -> 7782 bytes perf_counter.c | 15 +++++- perf_counter.h | 41 ++++++++------- 9 files changed, 128 insertions(+), 105 deletions(-) diff --git a/example/RTE/_example_arm_compiler_6/RTE_Components.h b/example/RTE/_example_arm_compiler_6/RTE_Components.h index 6acf1b9..d3e64f3 100644 --- a/example/RTE/_example_arm_compiler_6/RTE_Components.h +++ b/example/RTE/_example_arm_compiler_6/RTE_Components.h @@ -1,24 +1,24 @@ - -/* - * Auto generated Run-Time-Environment Configuration File - * *** Do not modify ! *** - * - * Project: 'example' - * Target: 'example_arm_compiler_6' - */ - -#ifndef RTE_COMPONENTS_H -#define RTE_COMPONENTS_H - - -/* - * Define the Device Header File: - */ -#define CMSIS_device_header "ARMCM3.h" - -/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */ -#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */ - #define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */ - - -#endif /* RTE_COMPONENTS_H */ + +/* + * Auto generated Run-Time-Environment Configuration File + * *** Do not modify ! *** + * + * Project: 'example' + * Target: 'example_arm_compiler_6' + */ + +#ifndef RTE_COMPONENTS_H +#define RTE_COMPONENTS_H + + +/* + * Define the Device Header File: + */ +#define CMSIS_device_header "ARMCM3.h" + +/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */ +#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */ + #define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */ + + +#endif /* RTE_COMPONENTS_H */ diff --git a/example/RTE/_library/RTE_Components.h b/example/RTE/_library/RTE_Components.h index ea23e9e..f90679d 100644 --- a/example/RTE/_library/RTE_Components.h +++ b/example/RTE/_library/RTE_Components.h @@ -1,21 +1,21 @@ - -/* - * Auto generated Run-Time-Environment Configuration File - * *** Do not modify ! *** - * - * Project: 'example' - * Target: 'library' - */ - -#ifndef RTE_COMPONENTS_H -#define RTE_COMPONENTS_H - - -/* - * Define the Device Header File: - */ -#define CMSIS_device_header "ARMCM0.h" - - - -#endif /* RTE_COMPONENTS_H */ + +/* + * Auto generated Run-Time-Environment Configuration File + * *** Do not modify ! *** + * + * Project: 'example' + * Target: 'library' + */ + +#ifndef RTE_COMPONENTS_H +#define RTE_COMPONENTS_H + + +/* + * Define the Device Header File: + */ +#define CMSIS_device_header "ARMCM0.h" + + + +#endif /* RTE_COMPONENTS_H */ diff --git a/example/example.uvoptx b/example/example.uvoptx index 72b2ad7..56ec574 100644 --- a/example/example.uvoptx +++ b/example/example.uvoptx @@ -150,27 +150,10 @@ 0 DLGUARM - + (105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0) - - - 0 - 0 - 108 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\main.c - - -
-
+ 0 diff --git a/example/example.uvprojx b/example/example.uvprojx index 1e62f7d..00d7676 100644 --- a/example/example.uvprojx +++ b/example/example.uvprojx @@ -10,7 +10,7 @@ example_arm_compiler_6 0x4 ARM-ADS - 6150000::V6.15::ARMCLANG + 6160000::V6.16::ARMCLANG 1 @@ -328,7 +328,7 @@ 1 1 0 - 3 + 4 3 1 1 @@ -529,7 +529,7 @@ library 0x4 ARM-ADS - 6150000::V6.15::ARMCLANG + 6160000::V6.16::ARMCLANG 1 diff --git a/example/main.c b/example/main.c index 181de79..717da26 100644 --- a/example/main.c +++ b/example/main.c @@ -80,6 +80,19 @@ int main (void) printf("Processing item with ID = %d\r\n", _->chID); } } + + int32_t iCycleResult = 0; + + /* measure cycles and store it in a dedicated variable without printf */ + __cycleof__("delay_us(1000ul)", + /* insert code to __cycleof__ body, "{}" can be omitted */ + { + iCycleResult = _; /*< "_" stores the result */ + }) { + delay_us(1000ul); + } + + printf("\r\n delay_us(1000ul) takes %d cycles\r\n", (int)iCycleResult); /*! demo of with block */ with(example_lv0_t, &s_tItem[0], pitem) { @@ -96,15 +109,15 @@ int main (void) //! demo of using clock() in timer.h do { - clock_t tStart = clock(); + int64_t tStart = get_system_ticks(); __IRQ_SAFE { printf("no interrupt \r\n"); } - printf("used clock cycle: %d", (int32_t)(clock() - tStart)); + printf("used clock cycle: %d", (int32_t)(get_system_ticks() - tStart)); } while(0); while (1) { - printf("hello world\r\n"); + printf("\r\nhello world\r\n"); delay_us(1000000); } } diff --git a/lib/perf_counter.h b/lib/perf_counter.h index 0ec98ce..c431e11 100644 --- a/lib/perf_counter.h +++ b/lib/perf_counter.h @@ -24,6 +24,10 @@ #include #include +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcompound-token-split-by-macro" +#endif + /*============================ MACROS ========================================*/ #ifndef __PLOOC_VA_NUM_ARGS_IMPL @@ -103,21 +107,21 @@ #define __using2(__declare, __on_leave_expr) \ for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define __using3(__declare, __on_enter_expr, __on_leave_expr) \ for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \ ((__on_enter_expr),1) : 0; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \ for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \ ((__on_enter_expr),1) : 0; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define using(...) \ @@ -131,7 +135,7 @@ #define __with2(__type, __addr) \ using(__type *_=(__addr)) #define __with3(__type, __addr, __item) \ - using(__type *_=(__addr), *__item = _, _=_, ) + using(__type *_=(__addr), *__item = _, _=_,_=_ ) #define with(...) \ CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__) @@ -179,19 +183,19 @@ /*============================ MACROFIED FUNCTIONS ===========================*/ -#define __cycleof__(__STR) \ - for (int32_t nCycles = 0, \ - CONNECT2(__cycle_count_s_, __LINE__) = 1; \ - CONNECT2(__cycle_count_s_, __LINE__)-- ? \ - (start_cycle_counter(),1) : \ - ( \ - printf( "\r\n-[Cycle Report]" \ - "--------------------------------------------\r\n" \ - __STR \ - " total cycle count: %d [%08x]\r\n", nCycles, nCycles) \ - ,0); \ - nCycles = stop_cycle_counter() \ - ) +#define __cycleof__(__STR, ...) \ + using(int64_t _ = get_system_ticks(), { \ + _ = get_system_ticks() - _; \ + if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \ + printf("\r\n"); \ + printf("-[Cycle Report]"); \ + printf("--------------------------------------------\r\n"); \ + printf(__STR " total cycle count: %d [%08x]\r\n", \ + (int)_, (int)_); \ + } else { \ + __VA_ARGS__ \ + }; \ + }) /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ @@ -245,6 +249,9 @@ __attribute__((nothrow)) extern int64_t clock(void); #endif +__attribute__((nothrow)) +extern int64_t get_system_ticks(void); + /*----------------------------------------------------------------------------* * Please ignore the following APIs unless you have encountered some known * diff --git a/lib/perf_counter.lib b/lib/perf_counter.lib index 65bae6ff2f71bf6ec5e93d4714ce497988644933..c49f730807c763e0c2894e757f33f9df0ce7f458 100644 GIT binary patch delta 2881 zcmaJ@ZERCz6h6J}=(a2E`n^#`JJ{B(Lc1}#4h9O234=|MErSSH##&(7!NLlHS<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4XYu@V>@wSPt+Fw^TTbF#E4)3w}lO;=ZX=*ng;n9R^|76~?S~eeRP8k0Ja%AHY diff --git a/perf_counter.c b/perf_counter.c index b36056a..f50180c 100644 --- a/perf_counter.c +++ b/perf_counter.c @@ -334,7 +334,7 @@ void delay_us(int32_t iUs) *! and 2) do not include system header file *! */ -_ARMABI +__attribute__((nothrow)) int64_t clock(void) { int64_t lTemp = 0; @@ -345,3 +345,16 @@ int64_t clock(void) return lTemp; } + + +__attribute__((nothrow)) +int64_t get_system_ticks(void) +{ + int64_t lTemp = 0; + + __IRQ_SAFE { + lTemp = check_systick() + s_lSystemClockCounts; + } + + return lTemp; +} diff --git a/perf_counter.h b/perf_counter.h index 0ec98ce..c431e11 100644 --- a/perf_counter.h +++ b/perf_counter.h @@ -24,6 +24,10 @@ #include #include +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wcompound-token-split-by-macro" +#endif + /*============================ MACROS ========================================*/ #ifndef __PLOOC_VA_NUM_ARGS_IMPL @@ -103,21 +107,21 @@ #define __using2(__declare, __on_leave_expr) \ for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define __using3(__declare, __on_enter_expr, __on_leave_expr) \ for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \ ((__on_enter_expr),1) : 0; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \ for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \ CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \ ((__on_enter_expr),1) : 0; \ - __on_leave_expr \ + (__on_leave_expr) \ ) #define using(...) \ @@ -131,7 +135,7 @@ #define __with2(__type, __addr) \ using(__type *_=(__addr)) #define __with3(__type, __addr, __item) \ - using(__type *_=(__addr), *__item = _, _=_, ) + using(__type *_=(__addr), *__item = _, _=_,_=_ ) #define with(...) \ CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__) @@ -179,19 +183,19 @@ /*============================ MACROFIED FUNCTIONS ===========================*/ -#define __cycleof__(__STR) \ - for (int32_t nCycles = 0, \ - CONNECT2(__cycle_count_s_, __LINE__) = 1; \ - CONNECT2(__cycle_count_s_, __LINE__)-- ? \ - (start_cycle_counter(),1) : \ - ( \ - printf( "\r\n-[Cycle Report]" \ - "--------------------------------------------\r\n" \ - __STR \ - " total cycle count: %d [%08x]\r\n", nCycles, nCycles) \ - ,0); \ - nCycles = stop_cycle_counter() \ - ) +#define __cycleof__(__STR, ...) \ + using(int64_t _ = get_system_ticks(), { \ + _ = get_system_ticks() - _; \ + if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \ + printf("\r\n"); \ + printf("-[Cycle Report]"); \ + printf("--------------------------------------------\r\n"); \ + printf(__STR " total cycle count: %d [%08x]\r\n", \ + (int)_, (int)_); \ + } else { \ + __VA_ARGS__ \ + }; \ + }) /*============================ TYPES =========================================*/ /*============================ GLOBAL VARIABLES ==============================*/ @@ -245,6 +249,9 @@ __attribute__((nothrow)) extern int64_t clock(void); #endif +__attribute__((nothrow)) +extern int64_t get_system_ticks(void); + /*----------------------------------------------------------------------------* * Please ignore the following APIs unless you have encountered some known *