Forráskód Böngészése

feat(cap): 优化捕获逻辑,待测试

CN\zhangkai71 2 éve
szülő
commit
39d09df1e4

+ 0 - 1
MSTLibraries/SelfTestLib/src/STLmain.c

@@ -38,7 +38,6 @@
 #include "hwsetup.h"
 //#include "adc.h"
 #include "api.h"
-#include "api_rt.h"
 #if defined STL_EVAL_MODE
   #ifdef STM32F30X
     #include "stm32303c_eval.h"

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

@@ -33,7 +33,7 @@
 #include "torquesensor.h"
 #include "power.h"
 #include "STLmain.h"
-//#include "api_rt.h"
+#include "api.h"
 /************************************************************************
  Exported Functions:
 ************************************************************************/

+ 0 - 1
User project/2.MotorDrive/Source/adc.c

@@ -29,7 +29,6 @@ Revising History (ECL of this file):
 #include "user.h"
 #include "Temp.h"
 #include "api.h"
-#include "api_rt.h"
 
 /************************************************************************
  Constant Table:

+ 1 - 1
User project/2.MotorDrive/Source/packed

@@ -1 +1 @@
-Subproject commit 658c0be0c2234c4c1a8ede5edb87e178ed843552
+Subproject commit 723ff2a3e6931847527419a7bf116182ef7c380c

+ 2 - 2
User project/3.BasicFunction/Include/bikelight.h

@@ -14,8 +14,8 @@
 *************************************************************************/
 #ifndef BIKELIGHT_H
 #define BIKELIGHT_H
-#include "api_rt.h"
-
+#include "api.h"
+#include "board_config.h"
 
 #ifdef BIKELIGHT_
 

+ 2 - 43
User project/3.BasicFunction/Source/Cadence.c

@@ -16,7 +16,8 @@
 #include "syspar.h"
 #include "Cadence.h"
 #include "CodePara.h"
-#include "api_rt.h"
+#include "api.h"
+#include "board_config.h"
 #ifdef RUN_ARCH_SIM
 #include "test_user.h"
 #endif
@@ -120,48 +121,6 @@ static void cadence_voCadenceHighFrequencyWork(UWORD source)
     if (source == 1 && cadence_stFreGetOut.uwCaputureNumCnt == 1)
     {
         cadence_stFreGetOut.uwCaputureOverflowCnt++;
-        if (timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_CH2) != 0)
-        {
-            cadence_stFreGetOut.uwCaputure2Cnt =(UWORD)iCap_GetCaptureValue(0, CAP_CH(2));
-            if(cadence_stFreGetOut.uwCaputure2Cnt > 9000) // TIMER1 half Period 
-            {
-                cadence_stFreGetOut.uwOverflowfirst= 1;
-                testcadc=1;
-            }
-            else
-            {
-                cadence_stFreGetOut.uwOverflowfirst= 2;
-                testcadc=2;
-            }   
-            ulCaputureCntErrLast = ulCaputureCntErr;
-            if(cadence_stFreGetOut.uwOverflowfirst == 1)
-            {
-                cadence_stFreGetOut.uwCaputureOverflowCnt -=1;
-                ulCaputureCntErr = ((ULONG)cadence_stFreGetOut.uwCaputureOverflowCnt * HW_TIM1CLK_KHZ * cadence_stFreGetCof.uwTimerUnit) + cadence_stFreGetOut.uwCaputure2Cnt 
-                                    -cadence_stFreGetOut.uwCaputure1Cnt;
-                cadence_stFreGetOut.uwCaputureOverflowCnt = 1; 
-                cadence_stFreGetOut.uwOverflowfirst = 0;
-                
-            }
-            else
-            {
-                ulCaputureCntErr = ((ULONG)cadence_stFreGetOut.uwCaputureOverflowCnt * HW_TIM1CLK_KHZ * cadence_stFreGetCof.uwTimerUnit) + cadence_stFreGetOut.uwCaputure2Cnt 
-                                    -cadence_stFreGetOut.uwCaputure1Cnt;
-                cadence_stFreGetOut.uwCaputureOverflowCnt = 0;
-                cadence_stFreGetOut.uwOverflowfirst = 0;
-            }
-
-            /* Cadence Freq Cal */
-            cad_pvt_ulCadFreqPu = (ULONG)(((UQWORD)HW_TIM1CLK_KHZ * 1000 << 20) / ((((UQWORD)ulCaputureCntErr + (UQWORD)ulCaputureCntErrLast)>>1)* cadence_stFreGetCof.uwNumbersPulses * FBASE));
-
-            cadence_stFreGetOut.uwCaputureNumCnt = 1;
-            cadence_stFreGetOut.uwCaputure1Cnt = cadence_stFreGetOut.uwCaputure2Cnt; 
-            timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_CH2);
-        }
-        else
-        {
-            cadence_stFreGetOut.uwOverflowfirst= 0;
-        }
     }
     else if (source == 2)
     {

+ 2 - 2
User project/3.BasicFunction/Source/bikebrake.c

@@ -14,8 +14,8 @@
  Compiler Directives:
 *************************************************************************/
 #include "bikebrake.h"
-#include "api_rt.h"
-
+#include "api.h"
+#include "board_config.h"
 /******************************
  *
  *  Parameter

+ 3 - 42
User project/3.BasicFunction/Source/bikespeed.c

@@ -16,7 +16,8 @@
 #include "syspar.h"
 #include "bikespeed.h"
 #include "CodePara.h"
-#include "api_rt.h"
+#include "api.h"
+#include "board_config.h"
 #ifdef RUN_ARCH_SIM
 #include "test_user.h"
 #endif
@@ -118,47 +119,7 @@ static void bikespeed_voBikeSpeedWork(UWORD source)
     ULONG ulCaputureCntErr = 0;
     if (source == 1 && bikespeed_stFreGetOut.uwCaputureNumCnt == 1)
     {
-        bikespeed_stFreGetOut.uwCaputureOverflowCnt++;
-        if (timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_CH3) != 0)
-        {
-            bikespeed_stFreGetOut.uwCaputure2Cnt =(UWORD)iCap_GetCaptureValue(0, CAP_CH(3));
-            if(bikespeed_stFreGetOut.uwCaputure2Cnt > 9000) // TIMER1 half Period 
-            {
-                bikespeed_stFreGetOut.uwOverflowfirst= 1;
-            }
-            else
-            {
-                bikespeed_stFreGetOut.uwOverflowfirst= 2;
-            }   
-
-            if(bikespeed_stFreGetOut.uwOverflowfirst == 1)
-            {
-                bikespeed_stFreGetOut.uwCaputureOverflowCnt -=1;
-                ulCaputureCntErr = ((ULONG)bikespeed_stFreGetOut.uwCaputureOverflowCnt * HW_TIM1CLK_KHZ * bikespeed_stFreGetCof.uwTimerUnit) + bikespeed_stFreGetOut.uwCaputure2Cnt 
-                                    -bikespeed_stFreGetOut.uwCaputure1Cnt;
-                bikespeed_stFreGetOut.uwCaputureOverflowCnt = 1; 
-                bikespeed_stFreGetOut.uwOverflowfirst = 0;
-                
-            }
-            else
-            {
-                ulCaputureCntErr = ((ULONG)bikespeed_stFreGetOut.uwCaputureOverflowCnt * HW_TIM1CLK_KHZ * bikespeed_stFreGetCof.uwTimerUnit) + bikespeed_stFreGetOut.uwCaputure2Cnt 
-                                    -bikespeed_stFreGetOut.uwCaputure1Cnt;
-                bikespeed_stFreGetOut.uwCaputureOverflowCnt = 0;
-                bikespeed_stFreGetOut.uwOverflowfirst = 0;
-            }
-
-            /* BikeSpeed Freq Cal */
-            bikespeed_pvt_FreqPu = (ULONG)(((UQWORD)720000 << 20) / ((UQWORD)ulCaputureCntErr * bikespeed_stFreGetCof.uwNumbersPulses * FBASE));
-
-            bikespeed_stFreGetOut.uwCaputureNumCnt = 1;
-            bikespeed_stFreGetOut.uwCaputure1Cnt = bikespeed_stFreGetOut.uwCaputure2Cnt; 
-            timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_CH3);
-        }
-        else
-        {
-            bikespeed_stFreGetOut.uwOverflowfirst= 0;
-        }
+        bikespeed_stFreGetOut.uwCaputureOverflowCnt++;    
     }
     else if (source == 3)
     {

+ 1 - 1
User project/3.BasicFunction/Source/can.c

@@ -57,7 +57,7 @@ ULONG    CRC32_Calculate(const UBYTE pData[], UWORD Length)
 #include "power.h"
 #include "torquesensor.h"
 #include "api.h"
-#include "api_rt.h"
+#include "api.h"
 static const ULONG Crc32Table[256] = {
     0x00000000U, 0x04C11DB7U, 0x09823B6EU, 0x0D4326D9U, 0x130476DCU, 0x17C56B6BU, 0x1A864DB2U, 0x1E475005U, 0x2608EDB8U, 0x22C9F00FU, 0x2F8AD6D6U, 0x2B4BCB61U,
     0x350C9B64U, 0x31CD86D3U, 0x3C8EA00AU, 0x384FBDBDU, 0x4C11DB70U, 0x48D0C6C7U, 0x4593E01EU, 0x4152FDA9U, 0x5F15ADACU, 0x5BD4B01BU, 0x569796C2U, 0x52568B75U,

+ 2 - 1
User project/3.BasicFunction/Source/power.c

@@ -16,7 +16,8 @@
 #include "typedefine.h"
 #include "power.h"
 #include "can.h"
-#include "api_rt.h"
+#include "api.h"
+#include "board_config.h"
 /******************************
  *
  *  Parameter

+ 1 - 1
User project/3.BasicFunction/Source/spi_master.c

@@ -44,7 +44,7 @@ void spi_voReadWriteSeneorReg(void)
 
 #include "user.h"
 #include "spi_master.h"
-#include "api_rt.h"
+#include "api.h"
 /*************************************************************************
  Exported Functions (N/A)
 *************************************************************************/

+ 44 - 13
User project/5.Api_rt/api_rt_cap.c

@@ -27,26 +27,57 @@ void iRtCap_Init(void)
 void iRtCap_Isr(uint8_t devIndex)
 {   
     uint32_t base = Caps[devIndex].CapBase;
-    if (TIMER_INTF(base) & 0x01)
+    uint8_t  capValues[5]={0,0,0,0,0};
+    uint8_t  results[5]={0,1,2,3,4};
+    uint16_t tmpIntf;
+    
+    tmpIntf = TIMER_INTF(base);   
+    for (int i = 1; i < 5; i++)
     {
-        if (Caps[devIndex].CountMaxISR.Enable && Caps[devIndex].CountMaxISR.Action != 0)
+        if (tmpIntf & (0x01 << i ))
         {
-            Caps[devIndex].CountMaxISR.Action();
+            capValues[i] = iCap_GetCaptureValue(devIndex,(i));
         }
-        TIMER_INTF(base) &= ~0x01;
+    }
+    if (tmpIntf & 0x01)
+    {      
+        capValues[0] = iCap_GetPeriod(devIndex) >> 1;
     }
 
-    for (int i = 0; i < 4; i++)
-    {
-        if (TIMER_INTF(base) & (0x01 << (i + 1)))
+    for(int i = 0; i < 4; i++)
+    { 
+        for(int j = 0;j < (4-i); j++)
         {
-            if (Caps[devIndex].ChannelISR[i].Enable && Caps[devIndex].ChannelISR[i].Action != 0)
-            {
-                Caps[devIndex].ChannelISR[i].Action();
-            }
-            TIMER_INTF(base) &= ~(0x01 << (i + 1));
+           if(capValues[results[j]]< capValues[results[j + 1]])
+           {
+               uint8_t tmp = results[j];
+               results[j] = results[j + 1];
+               results[j + 1] = tmp;
+           }
         }
-        
+    }
+    for(int i = 0; i < 5; i++)
+    { 
+          if (tmpIntf & (0x01 << results[i]))
+          {
+              if(results[i]==0)
+              {
+                  if (Caps[devIndex].CountMaxISR.Enable && Caps[devIndex].CountMaxISR.Action != 0)
+                  {
+                      Caps[devIndex].CountMaxISR.Action();
+                  }
+                  TIMER_INTF(base) &= ~0x01;
+              }
+              else
+              {
+                    if (Caps[devIndex].ChannelISR[results[i]-1].Enable && Caps[devIndex].ChannelISR[results[i]-1].Action != 0)
+                    {
+                        Caps[devIndex].ChannelISR[results[i]-1].Action();
+                    }
+                    TIMER_INTF(base) &= ~(0x01 << results[i]);
+              }
+              
+          }
     }
 }
 

+ 1 - 0
User project/5.Api_rt/api_rt_cap.h

@@ -6,6 +6,7 @@
 #include "api_rt_common.h"
 #include "gd32f30x.h"
 
+#define APIRT_CAP_CH_NUM 2
 typedef struct 
 {
     uint32_t            CapBase;

+ 6 - 0
tests/unit_test/test_bikelight.cpp

@@ -0,0 +1,6 @@
+#include "gtest/gtest.h"
+#include <gtest/gtest.h>
+#include <tuple>
+#include "scope.h"
+#include "test_user.h"
+