Sfoglia il codice sorgente

Major update

- introduce get_system_ticks()
- rework on __cycleof__
- update other macros to support gcc extension: ({;;;;})
- update example
Gabriel Wang 5 anni fa
parent
commit
d3ecc136d1

+ 24 - 24
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 */

+ 21 - 21
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 */

+ 2 - 19
example/example.uvoptx

@@ -150,27 +150,10 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>DLGUARM</Key>
-          <Name></Name>
+          <Name>(105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
-      <Breakpoint>
-        <Bp>
-          <Number>0</Number>
-          <Type>0</Type>
-          <LineNumber>108</LineNumber>
-          <EnabledFlag>1</EnabledFlag>
-          <Address>0</Address>
-          <ByteObject>0</ByteObject>
-          <HtxType>0</HtxType>
-          <ManyObjects>0</ManyObjects>
-          <SizeOfObject>0</SizeOfObject>
-          <BreakByAccess>0</BreakByAccess>
-          <BreakIfRCount>0</BreakIfRCount>
-          <Filename>.\main.c</Filename>
-          <ExecCommand></ExecCommand>
-          <Expression></Expression>
-        </Bp>
-      </Breakpoint>
+      <Breakpoint/>
       <WatchWindow1>
         <Ww>
           <count>0</count>

+ 3 - 3
example/example.uvprojx

@@ -10,7 +10,7 @@
       <TargetName>example_arm_compiler_6</TargetName>
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
-      <pCCUsed>6150000::V6.15::ARMCLANG</pCCUsed>
+      <pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
       <uAC6>1</uAC6>
       <TargetOption>
         <TargetCommonOption>
@@ -328,7 +328,7 @@
             <uC99>1</uC99>
             <uGnu>1</uGnu>
             <useXO>0</useXO>
-            <v6Lang>3</v6Lang>
+            <v6Lang>4</v6Lang>
             <v6LangP>3</v6LangP>
             <vShortEn>1</vShortEn>
             <vShortWch>1</vShortWch>
@@ -529,7 +529,7 @@
       <TargetName>library</TargetName>
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
-      <pCCUsed>6150000::V6.15::ARMCLANG</pCCUsed>
+      <pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
       <uAC6>1</uAC6>
       <TargetOption>
         <TargetCommonOption>

+ 16 - 3
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);
     }
 }

+ 24 - 17
lib/perf_counter.h

@@ -24,6 +24,10 @@
 #include <stdbool.h>
 #include <stdint.h>
 
+#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    *

BIN
lib/perf_counter.lib


+ 14 - 1
perf_counter.c

@@ -334,7 +334,7 @@ void delay_us(int32_t iUs)
  *!           and 2) do not include system header file <time.h>
  *!
  */
-_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;
+}

+ 24 - 17
perf_counter.h

@@ -24,6 +24,10 @@
 #include <stdbool.h>
 #include <stdint.h>
 
+#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    *