Quellcode durchsuchen

feat:增加负载率测试程序

CN\guohui27 vor 1 Jahr
Ursprung
Commit
c15ca3a5a6

+ 1 - 1
User project/1.FrameLayer/Source/TimeTask_Event.c

@@ -416,7 +416,7 @@ void  Event_200ms(void)
             alm_stBikeIn.uwThrottleReg = adc_stUpOut.uwThrottleReg;
             alm_stBikeIn.blThrottleExistFlg = FALSE;
             alm_stBikeIn.blMotorNTCExistFlg = FALSE;
-//            alm_voDetec200MS(&alm_stBikeIn, &alm_stDetect200MSCoef);   
+            alm_voDetec200MS(&alm_stBikeIn, &alm_stDetect200MSCoef);   
         }
         
         if (switch_flg.SysFault_Flag == TRUE)

+ 6 - 1
User project/1.FrameLayer/Source/main.c

@@ -35,6 +35,8 @@
 #include "STLmain.h"
 #include "api_rt.h"
 #include "hwsetup.h"
+#include "profiler.h"
+
 /************************************************************************
  Exported Functions:
 ************************************************************************/
@@ -79,13 +81,16 @@ int main(void) /* parasoft-suppress GJB5369-4_2_1_10 "mismatch" */
     /* MCU Self Test Init */
     stl_voRunTimeChecksInit();
     /* Watchdog 1s */
-    hw_voIWDGInit(FWDGT_PSC_DIV32,1250);//1s  
+    hw_voIWDGInit(FWDGT_PSC_DIV32,1250);//1s 
+    /* Program load rate testing init */ 
+    profiler_init();
     /* Enable all interrupts */
     ENABLE_IRQ;
 
     /* Enter infinite loop */
     while (1)
     {
+        PROFILER_BG();
         AppLoop();
     }
 

+ 1 - 0
User project/1.FrameLayer/Source/sys_task.c

@@ -7,6 +7,7 @@
 
 void SysTask1Ms()
 {
+    profiler_server();
     cp_ulSystickCnt ++;
     /* MCU Self Check*/
     clas_ubSystickFlg = 1; 

+ 2 - 1
User project/1.FrameLayer/Source/tbs.c

@@ -22,6 +22,7 @@ Revising History (ECL of this file):
 *************************************************************************/
 #include "user.h"
 #include "FSM_1st.h"
+#include "profiler.h"
 /************************************************************************
  Constant Table (N/A)
 *************************************************************************/
@@ -41,7 +42,7 @@ Revising History (ECL of this file):
 void tbs_voIsr(void)
 {
     /* Alarm detect */
-//    alm_voDetecTBS(&alm_stIn, &alm_stDetectTbsCoef);
+    alm_voDetecTBS(&alm_stIn, &alm_stDetectTbsCoef);
 
     /* 1st FSM */
     FSM1st_Sys_state.Tbs_hook();

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/user.h

@@ -47,7 +47,7 @@ Update Time
 #define MOTOR_WELLING_CITY_48V    0x30
 #define MOTOR_WELLING_MTB_48V     0x31
 
-#define MOTOR_ID_SEL              MOTOR_WELLING_CITY_48V  
+#define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V  
 
 /*======================================================================*
    ADC Maximum Value

+ 9 - 5
User project/5.Api_rt/api_rt_pwm.c

@@ -6,7 +6,7 @@
 #include <stdint.h>
 #include "api_rt_adc.h"
 #include "classB.h"
-
+#include "profiler.h"
 ApiRtPwm_Handle Pwms[1];
 
 /* ========================================================================== */
@@ -74,11 +74,14 @@ void iRtPwm_UpdateIsr(uint8_t devIndex)
     {           
         if((TIMER_CTL0(base) & TIMER_CTL0_DIR) == 0) // When Counting Up
         { 
+            PROFILER_START(1);
             /* TBC Up interrupt */
-            iRtPwm_CountZeroIsr(devIndex);             
+            iRtPwm_CountZeroIsr(devIndex);   
+            PROFILER_END(1);
         }
         else
-        {               
+        {      
+            PROFILER_START(2);
             /* Reset Timer6 counts*/
             iTimer_Reset(HW_TBC_HALF_UPDATE_TIMER); 
             /* TBC Down interrupt */
@@ -97,9 +100,10 @@ void iRtPwm_UpdateIsr(uint8_t devIndex)
             /* Software trigger for regular sampling*/
             iAdc_Convert(0);                
             /* Compara value load */   
-            iRtPwm_ActivateCompareValues(0);             
+            iRtPwm_ActivateCompareValues(0);   
             timer_dma_enable(base,TIMER_DMA_UPD);
-            dma_channel_enable(DMA0,DMA_CH4);  
+            dma_channel_enable(DMA0,DMA_CH4);      
+            PROFILER_END(2);
         }
     } 
     /* Timer0 update interrupt flag clear */

+ 1 - 5
User project/5.Api_rt/api_rt_uart.c

@@ -107,15 +107,11 @@ int16_t iUart_Write(uint8_t devIndex, uint8_t *data, int16_t count)
         while (writeCount < count)
         {
             USART_DATA(Uarts[devIndex].UartBase) = data[writeCount];
+            writeCount++;
             while ((USART_STAT0(Uarts[devIndex].UartBase) & 0x80) == 0)
             {
                 ;
             }
-//            Uarts[devIndex].UartBase->TDR = data[writeCount];
-//            while ((Uarts[devIndex].UartBase->ISR & 0x80) == 0)
-//            {
-//                ;
-//            }
         }
     }
     return writeCount;

+ 183 - 0
User project/5.Api_rt/profiler.c

@@ -0,0 +1,183 @@
+#include "profiler.h"
+#include "profiler_port.h"
+#include <stdint.h>
+
+typedef struct
+{
+    uint8_t level;
+    uint32_t counter;
+} ProfilerEvent;
+
+uint32_t ProfilerDurationTicks;
+
+#if PROFILER_TYPE == PROFILER_TYPE_STATISTICS
+
+uint32_t ProfilerTime[PROFILER_MAX_LEVEL + 1];
+
+uint32_t ProfilerCounts[PROFILER_MAX_LEVEL + 1];
+
+uint8_t ProfilerStack[PROFILER_MAX_LEVEL + 1];
+
+uint8_t ProfilerSp;
+
+ProfilerEvent ProfilerBuffer;
+
+uint32_t ProfilerStartTicks = 0;
+
+#endif
+
+uint8_t ProfilerEnable = 0;
+
+uint8_t ProfilerRunning = 0;
+
+int8_t ProfilerError = 0;
+
+void profiler_init()
+{
+    ProfilerEnable = 0;
+    ProfilerError = 0;
+
+    ProfilerDurationTicks = PROFILER_CLOCK * (float)PROFILER_DURATION;
+
+#if PROFILER_TYPE == PROFILER_TYPE_STATISTICS
+    for (int i = 0; i < PROFILER_MAX_LEVEL; i++)
+    {
+        ProfilerTime[i] = 0;
+        ProfilerCounts[i] = 0;
+    }
+
+    ProfilerSp = 0;
+#elif PROFILER_TYPE == PROFILER_TYPE_TRACE
+
+#endif
+
+    profiler_init_hw();
+}
+
+void profiler_enable()
+{
+    ProfilerEnable = 1;
+
+    profiler_enable_hw();
+}
+
+void profiler_bg()
+{
+#if PROFILER_TYPE == PROFILER_TYPE_STATISTICS
+    if (!ProfilerEnable)
+    {
+        return;
+    }
+    else
+    {
+        PROFILER_DISABLE_IRQ();
+        uint32_t ticks = profiler_getTicks();
+        if (!ProfilerRunning)
+        {
+            /* If counter overflow, return directly */
+            if (ticks + 2 * ProfilerDurationTicks > ticks)
+            {
+                ProfilerSp = 0;
+                ProfilerStack[ProfilerSp] = 0;
+                ProfilerSp += 1;
+                ProfilerCounts[0] += 1;
+                ProfilerBuffer.counter = ticks;
+                ProfilerBuffer.level = 0;
+                ProfilerStartTicks = ticks;
+                ProfilerRunning = 1;
+            }
+        }
+        else
+        {
+            uint32_t ticks = profiler_getTicks();
+            int32_t delta = ticks - ProfilerBuffer.counter;
+            if(delta<0)
+            {
+                delta+=72000;
+            }
+            ProfilerTime[0] += delta;
+            ProfilerBuffer.counter = ticks;
+            ProfilerBuffer.level = 0;
+            if (ticks > ProfilerStartTicks + ProfilerDurationTicks)
+            {
+                ProfilerRunning = 0;
+                ProfilerEnable = 0;
+            }
+            else
+            {
+                ProfilerCounts[0] += 1;
+                ProfilerBuffer.counter = ticks;
+                ProfilerBuffer.level = 0;
+            }
+            if (ProfilerSp != 1)
+            {
+                ProfilerError = -1;
+            }
+        }
+        PROFILER_ENABLE_IRQ();
+    }
+#elif PROFILER_TYPE == PROFILER_TYPE_TRACE
+
+#endif
+}
+
+void  profiler_start(uint8_t lv)
+{
+#if PROFILER_TYPE == PROFILER_TYPE_STATISTICS
+    if (!ProfilerRunning)
+    {
+        return;
+    }
+    if (lv <= 0 || lv > PROFILER_MAX_LEVEL)
+    {
+        return;
+    }
+
+    PROFILER_DISABLE_IRQ();
+    uint32_t ticks = profiler_getTicks();
+    int32_t delta = ticks - ProfilerBuffer.counter;
+    if(delta<0)
+    {
+        delta+=72000;
+    }
+    ProfilerTime[ProfilerStack[ProfilerSp - 1]] += delta;
+    ProfilerCounts[lv] += 1;
+    ProfilerStack[ProfilerSp] = lv;
+    ProfilerSp += 1;
+    ProfilerBuffer.counter = ticks;
+    ProfilerBuffer.level = lv;
+    PROFILER_ENABLE_IRQ();
+
+#elif PROFILER_TYPE == PROFILER_TYPE_TRACE
+
+#endif
+}
+
+void profiler_end(uint8_t lv)
+{
+#if PROFILER_TYPE == PROFILER_TYPE_STATISTICS
+    if (!ProfilerRunning)
+    {
+        return;
+    }
+    if (lv <= 0 || lv > PROFILER_MAX_LEVEL)
+    {
+        return;
+    }
+
+    PROFILER_DISABLE_IRQ();
+    uint32_t ticks = profiler_getTicks();
+    int32_t delta = ticks - ProfilerBuffer.counter;
+    if(delta<0)
+    {
+        delta+=72000;
+    }
+    ProfilerTime[ProfilerStack[ProfilerSp - 1]] += delta;
+    ProfilerSp -= 1;
+    ProfilerBuffer.counter = ticks;
+    ProfilerBuffer.level = lv;
+    PROFILER_ENABLE_IRQ();
+#elif PROFILER_TYPE == PROFILER_TYPE_TRACE
+
+#endif
+}

+ 105 - 0
User project/5.Api_rt/profiler.h

@@ -0,0 +1,105 @@
+/**
+ * @file profiler.h
+ * @author Xiao Lifan (xiaolf6@midea.com)
+ * @brief 
+ * @version 0.1
+ * @date 2022-03-15
+ * 
+ * @copyright Copyright (c) 2022
+ * 
+ * @details Mcu profiling tool, only for none-RTOS platform
+ * 
+ */
+
+#ifndef _PROFILER_H_
+#define _PROFILER_H_
+
+#include <stdint.h>
+#include "profiler_port.h"
+
+/**
+ * @brief The clock of profiler counter
+ * 
+ */
+
+#define PROFILER_TYPE_TRACE         2
+#define PROFILER_TYPE_STATISTICS    1
+#define PROFILER_TYPE_NONE          0
+
+/**
+ * @brief Profile type
+ * 
+ */
+#define PROFILER_TYPE               PROFILER_TYPE_STATISTICS
+
+/**
+ * @brief Profile duration
+ * @note Profile will automaticlly stop after duration
+ * 
+ */
+#define PROFILER_DURATION           1
+
+/**
+ * @brief The maximum profiling event id
+ * 
+ */
+#define PROFILER_MAX_LEVEL          8
+
+/**
+ * @brief Profile background task macro, should be call in the main loop
+ * 
+ */
+#define PROFILER_BG()               profiler_bg()
+
+/**
+ * @brief Profile start macro
+ * 
+ */
+#define PROFILER_START(X)           profiler_start(X)  
+
+/**
+ * @brief profile end macro
+ * 
+ */
+#define PROFILER_END(X)             profiler_end(X)  
+
+/**
+ * @brief Enable profile
+ * @note The profile will actually start at next calling of PROFILER_BG().
+ * 
+ */
+void profiler_enable();
+
+/**
+ * @brief Initialize profile data structure
+ * 
+ */
+void profiler_init();
+
+/**
+ * @brief Profiling background task, should be call in the main loop
+ * 
+ */
+void profiler_bg();
+
+/**
+ * @brief Start profile of level lv, the delta ticks between "start" and "end" will be calculated 
+ * 
+ * @param lv profiling level
+ */
+void profiler_start(uint8_t lv);
+
+/**
+ * @brief End profile of level lv
+ * 
+ * @param lv profiling level
+ */
+void profiler_end(uint8_t lv);
+
+extern uint32_t ProfilerTime[PROFILER_MAX_LEVEL + 1];
+
+extern uint32_t ProfilerCounts[PROFILER_MAX_LEVEL + 1];
+
+extern int8_t ProfilerError;
+
+#endif

+ 125 - 0
User project/5.Api_rt/profiler_port.c

@@ -0,0 +1,125 @@
+#include "profiler_port.h"
+
+#include "gd32f30x.h"
+
+#ifdef x86
+
+uint32_t Win32_Ticks = 0;
+
+void profiler_server()
+{
+    Win32_Ticks += 1;
+}
+
+uint32_t profiler_getTicks()
+{
+    return Win32_Ticks;
+}
+
+void profiler_disable_irq()
+{
+
+}
+
+void profiler_enable_irq()
+{
+    
+}
+
+#endif
+
+#if defined __CORTEX_M && (__CORTEX_M == 4U)
+
+/**
+ * @brief Debug Exception and Monitor Control Register Base Address
+ *
+ */
+#define CORTEX_DEMCR (*(uint32_t *) 0xE000EDFC)
+
+/**
+ * @brief Data Watchpoint and Trace Register Control Register Base Address
+ *
+ */
+#define CORTEX_DWT_CTRL (*(uint32_t *) 0xE0001000)
+
+/**
+ * @brief Data Watchpoint and Trace Register Cycle Count Register Address
+ *
+ */
+#define CORTEX_DWT_CYCCNT (*(volatile uint32_t *) 0xE0001004)
+
+void profiler_init_hw()
+{
+//	CORTEX_DEMCR |= (1 << 24);
+//	CORTEX_DWT_CTRL |= (1 << 0);
+//	CORTEX_DWT_CYCCNT = 0;
+}
+
+void profiler_enable_hw()
+{
+//	CORTEX_DWT_CYCCNT = 0;
+}
+
+uint32_t profilerServrCnt=0;
+void profiler_server()
+{
+    profilerServrCnt++;
+}
+
+uint32_t profiler_getTicks()
+{
+//	return CORTEX_DWT_CYCCNT;
+   return (((72000-SysTick->VAL) * 14) >> 10)+ profilerServrCnt*1000;
+  
+}
+
+void profiler_disable_irq()
+{
+	__disable_irq();
+}
+
+void profiler_enable_irq()
+{
+	__enable_irq();
+}
+
+#endif
+
+
+#if defined __CORTEX_M && (__CORTEX_M == 3U)
+
+
+
+void profiler_init_hw()
+{
+
+}
+
+void profiler_enable_hw()
+{
+}
+
+uint32_t profilerServrCnt=0;
+
+void profiler_server()
+{
+    profilerServrCnt++;
+
+}
+
+uint32_t profiler_getTicks()
+{
+    return (((72000-SysTick->VAL) * 14) >> 10)+ profilerServrCnt*1000;
+}
+
+void profiler_disable_irq()
+{
+	__disable_irq();
+}
+
+void profiler_enable_irq()
+{
+	__enable_irq();
+}
+
+#endif

+ 24 - 0
User project/5.Api_rt/profiler_port.h

@@ -0,0 +1,24 @@
+#ifndef _PROFILER_PORT_H_
+#define _PROFILER_PORT_H_       
+
+#include <stdint.h>
+
+#define PROFILER_CLOCK              1000000UL
+
+#define PROFILER_DISABLE_IRQ()      profiler_disable_irq()
+
+#define PROFILER_ENABLE_IRQ()       profiler_enable_irq()
+
+void profiler_init_hw();
+
+void profiler_enable_hw();
+
+void profiler_server();
+
+uint32_t profiler_getTicks();
+
+void profiler_disable_irq();
+
+void profiler_enable_irq();
+
+#endif

+ 20 - 8
WLMCP.ewp

@@ -2878,19 +2878,19 @@
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_adc.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_adc.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_adc.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_cap.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_cap.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_cap.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_dbg.c</name>
@@ -2902,31 +2902,43 @@
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_gpio.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_gpio.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_gpio.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_i2c.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_i2c.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_i2c.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_pwm.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_pwm.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_pwm.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_timer.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_timer.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_timer.h</name>
             </file>
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_uart.c</name>
             </file>
             <file>
-                <name>$PROJ_DIR$\User project\5.api_rt\api_rt_uart.h</name>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_uart.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler_port.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler_port.h</name>
             </file>
         </group>
     </group>