Browse Source

feat(gpio): 抽象GPIO编译未通过

CN\zhangkai71 2 years ago
parent
commit
ecdac1312b

+ 6 - 1
.gitignore

@@ -18,4 +18,9 @@ Release/**
 
 # Xmake cache
 .xmake/
-build/
+build/
+
+build/
+
+# Generated Fingerprint File
+fp.def

+ 4 - 2
MSTLibraries/SelfTestLib/src/STLmain.c

@@ -36,7 +36,9 @@
 #include "tbc.h" 
 #include "alarm.h"
 #include "hwsetup.h"
-#include "adc.h"
+//#include "adc.h"
+#include "api.h"
+#include "api_rt.h"
 #if defined STL_EVAL_MODE
   #ifdef STM32F30X
     #include "stm32303c_eval.h"
@@ -312,7 +314,7 @@ if(test)
         }
 
       /* IBUS */ /* 70A*0.002*16 = 2.24V ÓàÁ¿·Åµ½2.5v(3103) */
-        AdcReg = adc_uwADDMAPhase1;
+        AdcReg = iAdc_GetResultPointer(2)[HW_ADC_IDC_CH];
         if(AdcReg>3103)
         {
             AdcIBUSErrorCnt++;

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

@@ -52,7 +52,7 @@ static BOOL Event_pvt_blBikeThroFlg = FALSE, Event_pvt_blBikeThroFlgZ1 = FALSE;
  ******************************/
 void  Event_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
-    AdcLow_Init();
+   
     /* 1st FSM control */
     FSM_1st_Main();
     FSM1st_Sys_state.Event_hook();

+ 13 - 8
User project/1.FrameLayer/Source/gd32f30x_it.c

@@ -17,6 +17,7 @@
 #include "TimeTask_Event.h"
 #include "can.h"
 #include "FSM_1st.h"
+#include "api_rt.h"
 /******************************
  *  Parameter
  ******************************/
@@ -160,9 +161,12 @@ void ADC0_1_IRQHandler(void)
     {
         if (ADC_STAT(ADC0) & ADC_INT_FLAG_EOIC)
         {         
-            adc_uwRdsonUReg = ADC_IDATA0(ADC0);
-            adc_uwRdsonVReg = ADC_IDATA1(ADC0);
-            adc_uwRdsonWReg = ADC_IDATA2(ADC0);  
+//            adc_uwRdsonUReg = ADC_IDATA0(ADC0);
+//            adc_uwRdsonVReg = ADC_IDATA1(ADC0);
+//            adc_uwRdsonWReg = ADC_IDATA2(ADC0);
+            Adcs[1].Results[HW_ADC_IA_CH] = ADC_IDATA0(ADC0);
+            Adcs[1].Results[HW_ADC_IB_CH] = ADC_IDATA1(ADC0);
+            Adcs[1].Results[HW_ADC_IC_CH] = ADC_IDATA2(ADC0);  
                             
             /* ADC0 disable */
             ADC_CTL1(ADC0) &= ~((uint32_t)ADC_CTL1_ADCON);
@@ -177,8 +181,8 @@ void ADC0_1_IRQHandler(void)
         {         
             if (pwm_stGenOut.blSampleCalibFlag == TRUE)
             {
-                adc_uwADDMAPhase1 = ADC_IDATA0(ADC1);
-            }            
+                 Adcs[2].Results[HW_ADC_IDC_CH] = ADC_IDATA0(ADC1);
+            }           
 
             /* ADC1 disable */
             ADC_CTL1(ADC1) &= ~((uint32_t)ADC_CTL1_ADCON);
@@ -233,10 +237,11 @@ void TIMER0_UP_TIMER9_IRQHandler(void)
                 
                 /* ADC0 trigger set */
                 TIMER_CH3CV(TIMER0) = (uint32_t) pwm_stGenOut.uwRDSONTrig;
-                adc_enable(ADC0);
+//                adc_enable(ADC0);
+                iAdc_Enable(0);
                 /* Software trigger for regular sampling*/
-                adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL); 
-                
+//                adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL); 
+                iAdc_Convert(0);                
                 /* Compara value load */    
                 hw_uwPWMCmpr[0] = pwm_stGenOut.uwNewTIM1COMPR[0];
                 hw_uwPWMCmpr[1] = pwm_stGenOut.uwNewTIM1COMPR[1];

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

@@ -51,6 +51,8 @@ int main(void) /* parasoft-suppress GJB5369-4_2_1_10 "mismatch" */
     DISABLE_IRQ; 
     /* MCU Core and GPIO configuration */
     hw_voHardwareSetup1();
+    /* Api Init*/
+    iRt_Init();
     /* Code Para Init */
     CodeParaInit();
     /* AssitPara Init */

+ 28 - 25
User project/2.MotorDrive/Source/adc.c

@@ -28,6 +28,8 @@ Revising History (ECL of this file):
 #include "syspar.h"
 #include "user.h"
 #include "Temp.h"
+#include "api.h"
+#include "api_rt.h"
 /************************************************************************
  Constant Table:
 *************************************************************************/
@@ -62,10 +64,11 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
                 pwm_stGenOut.blSampleCalibFlag = TRUE;
                 if (out1->uwADCCalibCt < (1 << ADC_CALIB_INDEX))
                 {
-                    out1->ulIdcRegSum += adc_uwADDMAPhase1;
-                    out1->ulIaRegSum += adc_uwRdsonUReg;
-                    out1->ulIbRegSum += adc_uwRdsonVReg;
-                    out1->ulIcRegSum += adc_uwRdsonWReg;
+                    out1->ulIdcRegSum += iAdc_GetResultPointer(2)[HW_ADC_IDC_CH];
+
+                    out1->ulIaRegSum += iAdc_GetResultPointer(1)[HW_ADC_IA_CH];
+                    out1->ulIbRegSum += iAdc_GetResultPointer(1)[HW_ADC_IB_CH];
+                    out1->ulIcRegSum += iAdc_GetResultPointer(1)[HW_ADC_IC_CH];
                     out1->uwADCCalibCt++;
                 }
                 else
@@ -93,7 +96,7 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
             {
                 if (out1->uwADCCalibCt < (1 << ADC_CALIB_INDEX))
                 {
-                    out1->ulIdcRegSum += adc_uwADDMAPhase1 + adc_uwADDMAPhase2;
+                    out1->ulIdcRegSum += iAdc_GetResultPointer(2)[HW_ADC_IDC_CH] + adc_uwADDMAPhase2;
                     out1->uwADCCalibCt++;
                 }
                 else if (out2->uwADCCalibCt < (1 << ADC_CALIB_INDEX))
@@ -115,9 +118,9 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
             {
                 if (out1->uwADCCalibCt < (1 << ADC_CALIB_INDEX))
                 {
-                    out1->ulIaRegSum += adc_uwRdsonUReg;
-                    out1->ulIbRegSum += adc_uwRdsonVReg;
-                    out1->ulIcRegSum += adc_uwRdsonWReg;
+                    out1->ulIaRegSum += iAdc_GetResultPointer(1)[HW_ADC_IA_CH];
+                    out1->ulIbRegSum += iAdc_GetResultPointer(1)[HW_ADC_IB_CH];
+                    out1->ulIcRegSum += iAdc_GetResultPointer(1)[HW_ADC_IC_CH];
                     out1->uwADCCalibCt++;
                 }
                 else
@@ -159,9 +162,9 @@ void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out) /* parasoft-suppres
 
     if(cp_stFlg.CurrentSampleModelSelect == COMBINATION)
     {
-        out->uwIaReg = adc_uwRdsonUReg;
-        out->uwIbReg = adc_uwRdsonVReg;
-        out->uwIcReg = adc_uwRdsonWReg;
+        out->uwIaReg = iAdc_GetResultPointer(1)[HW_ADC_IA_CH];
+        out->uwIbReg = iAdc_GetResultPointer(1)[HW_ADC_IB_CH];
+        out->uwIcReg = iAdc_GetResultPointer(1)[HW_ADC_IC_CH];
 
         out->slSampIaPu = -(((SWORD)out->uwIaReg - (SWORD)cof->uwIaOffset) * (SLONG)cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
         out->slSampIbPu = -(((SWORD)out->uwIbReg - (SWORD)cof->uwIbOffset) * (SLONG)cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
@@ -176,7 +179,7 @@ void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out) /* parasoft-suppres
         SWORD tmp_swIphase1, tmp_swIphase2, tmp_swIphase3;
 
         /* Register value */
-        out->uwFirstCurREG = adc_uwADDMAPhase1;  // Q12
+        out->uwFirstCurREG = iAdc_GetResultPointer(2)[HW_ADC_IDC_CH];  // Q12
         out->uwSecondCurREG = adc_uwADDMAPhase2; // Q12
 
         tmp_swIphase1 = (SWORD)out->uwFirstCurREG - (SWORD)cof->uwIdcOffset;
@@ -229,9 +232,9 @@ void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out) /* parasoft-suppres
     else if(cp_stFlg.CurrentSampleModelSelect == RDSON)
     {
        SWORD tmp_swIphase1, tmp_swIphase2, tmp_swIphase3;
-        out->uwIaReg = adc_uwRdsonUReg;
-        out->uwIbReg = adc_uwRdsonVReg;
-        out->uwIcReg = adc_uwRdsonWReg;
+        out->uwIaReg = iAdc_GetResultPointer(1)[HW_ADC_IA_CH];
+        out->uwIbReg = iAdc_GetResultPointer(1)[HW_ADC_IB_CH];
+        out->uwIcReg = iAdc_GetResultPointer(1)[HW_ADC_IC_CH];
 
         tmp_swIphase1 = (SWORD)-(((SWORD)out->uwIaReg - (SWORD)cof->uwIaOffset) * (SLONG)cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
         tmp_swIphase2 = (SWORD)-(((SWORD)out->uwIbReg - (SWORD)cof->uwIbOffset) * (SLONG)cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
@@ -317,13 +320,13 @@ void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out) /* parasoft-suppres
 void adc_voSampleUp(const ADC_COF *cof, ADC_UP_OUT *out)
 {
     /* Register value */
-    out->uwVdcReg = hw_uwADC0[0];
-    out->uwU6VReg = hw_uwADC0[1];
-    out->uwU5VReg = hw_uwADC0[2];
-    out->PCBTempReg = hw_uwADC0[3];
-    out->TorqTempReg = hw_uwADC0[4];
-    out->uwU12VReg = hw_uwADC0[5];
-    out->uwThrottleReg = hw_uwADC0[6];
+    out->uwVdcReg = iAdc_GetResultPointer(0)[HW_ADC_UDC_CH]; 
+    out->uwU6VReg = iAdc_GetResultPointer(0)[HW_ADC_U6V_CH]; 
+    out->uwU5VReg = iAdc_GetResultPointer(0)[HW_ADC_U5V_CH]; 
+    out->PCBTempReg = iAdc_GetResultPointer(0)[HW_ADC_PCBTEMP_CH]; 
+    out->TorqTempReg = iAdc_GetResultPointer(0)[HW_ADC_MOTTEMP_CH]; 
+    out->uwU12VReg = iAdc_GetResultPointer(0)[HW_ADC_U12V_CH]; 
+    out->uwThrottleReg = iAdc_GetResultPointer(0)[HW_ADC_THRO_CH]; 
 
     out->uwVdcPu = (UWORD)((ULONG)out->uwVdcReg * cof->uwVdcReg2Pu >> 10); // Q14=Q24-Q10
     /* Vdc LPF */
@@ -346,13 +349,13 @@ void adc_voSampleUp(const ADC_COF *cof, ADC_UP_OUT *out)
             out->swCalibIcPu = 0;
             break;
         case SampleA:
-            out->swCalibIaPu = -(SWORD)((((SWORD)adc_uwADDMAPhase1 - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
+            out->swCalibIaPu = -(SWORD)((((SWORD)iAdc_GetResultPointer(2)[HW_ADC_IDC_CH] - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
             break;
         case SampleB:
-            out->swCalibIbPu = -(SWORD)((((SWORD)adc_uwADDMAPhase1 - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
+            out->swCalibIbPu = -(SWORD)((((SWORD)iAdc_GetResultPointer(2)[HW_ADC_IDC_CH] - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
             break;
         case SampleC:
-            out->swCalibIcPu = -(SWORD)((((SWORD)adc_uwADDMAPhase1 - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
+            out->swCalibIcPu = -(SWORD)((((SWORD)iAdc_GetResultPointer(2)[HW_ADC_IDC_CH] - (SWORD)cof->uwIdcOffset) * (SLONG)cof->uwCurIdcReg2Pu) >> 10); // Q14=Q24-Q10
             break;
         default:
             break;

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

@@ -18,7 +18,8 @@
 #include "mathtool.h"
 #include "hwsetup.h"
 #include "bikethrottle.h"
-
+#include "api.h"
+#include "api_rt.h"
 /******************************
  *
  * static Parameter
@@ -110,7 +111,7 @@ void bikethrottle_voBikeThrottleADC(void) // need to match ADC_StartConversion(A
     }
     else
     {
-        bikethrottle_stBikeThrottleOut.uwThrottleVolReg = hw_uwADC0[6]; //hw_uwADC2[6]; 
+        bikethrottle_stBikeThrottleOut.uwThrottleVolReg = iAdc_GetResultPointer(0)[HW_ADC_THRO_CH]; //hw_uwADC2[6]; 
         bikethrottle_stBikeThrottleOut.uwThrottleVolPu =
         		 (UWORD)(((ULONG)bikethrottle_stBikeThrottleOut.uwThrottleVolReg * bikethrottle_stBikeThrottleCof.uwThrottleVolReg2Pu) >> 10); // Q14
         mth_voLPFilter((SWORD)bikethrottle_stBikeThrottleOut.uwThrottleVolPu, &scm_stBikeThrottleLpf);

+ 6 - 5
User project/3.BasicFunction/Source/can.c

@@ -34,7 +34,8 @@ Revising History (ECL of this file):
 #include "flash_master.h"
 #include "i2c_master.h"
 #include "power.h"
-
+#include "api.h"
+#include "api_rt.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,
@@ -792,25 +793,25 @@ void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-supp
             if (SAVETemp[0] == 1)
             {
                 MC_UpcInfo.stSensorInfo.uwBikeTor1StepRealNm = SAVETemp[1];
-                MC_UpcInfo.stSensorInfo.uwBikeTor1StepADC = hw_uwADC0[7]; //hw_uwADC1[0];//torsensor_stTorSensorOut.uwTorqueReg;
+                MC_UpcInfo.stSensorInfo.uwBikeTor1StepADC = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
                 SendData(ID_MC_BC, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
             }
             else if (SAVETemp[0] == 2)
             {
                 MC_UpcInfo.stSensorInfo.uwBikeTor2StepRealNm = SAVETemp[1];
-                MC_UpcInfo.stSensorInfo.uwBikeTor2StepADC = hw_uwADC0[7];//hw_uwADC1[0];//torsensor_stTorSensorOut.uwTorqueReg;
+                MC_UpcInfo.stSensorInfo.uwBikeTor2StepADC = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
                 SendData(ID_MC_BC, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
             }
             else if (SAVETemp[0] == 3)
             {
                 MC_UpcInfo.stSensorInfo.uwBikeTor3StepRealNm = SAVETemp[1];
-                MC_UpcInfo.stSensorInfo.uwBikeTor3StepADC = hw_uwADC0[7]; //hw_uwADC1[0];//torsensor_stTorSensorOut.uwTorqueReg;
+                MC_UpcInfo.stSensorInfo.uwBikeTor3StepADC = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
                 SendData(ID_MC_BC, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
             }
             else if (SAVETemp[0] == 4)
             {
                 MC_UpcInfo.stSensorInfo.uwBikeTor4StepRealNm = SAVETemp[1];
-                MC_UpcInfo.stSensorInfo.uwBikeTor4StepADC = hw_uwADC0[7]; //hw_uwADC1[0];//torsensor_stTorSensorOut.uwTorqueReg;
+                MC_UpcInfo.stSensorInfo.uwBikeTor4StepADC = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
                 SendData(ID_MC_BC, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
             }
             else

+ 10 - 8
User project/3.BasicFunction/Source/torquesensor.c

@@ -21,6 +21,8 @@
 #include "CodePara.h"
 #include "canAppl.h"
 #include "FuncLayerAPI.h"
+#include "api.h"
+#include "api_rt.h"
 /******************************
  *
  * static  Parameter
@@ -107,7 +109,7 @@ void torsensor_voTorSensorCof(void)
         #if (TORSENSOR_USEMOL == TORSENSOR_USEDEFAULT)
         torsensor_stTorSensorCof.uwTorqueOffset = TORQUE_VOLTAGE_MIN_RANGE * 4096 / 3300;
         #elif (TORSENSOR_USEMOL == TORSENSOR_USEEE)
-         torsensor_stTorSensorCof.uwTorqueOffsetPowerUp = hw_uwADC0[7]; 
+         torsensor_stTorSensorCof.uwTorqueOffsetPowerUp = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
         //torsensor_stTorSensorCof.uwTorqueOffsetPowerUp = PowerUpOffset;
 
         if(torsensor_stTorSensorCof.uwTorqueOffsetNow1 != 0 && torsensor_stTorSensorCof.uwTorqueOffsetNow2 != 0
@@ -273,8 +275,8 @@ void torsensor_voTorSensorInit(void)
     torsensor_stTorSensorOut.blTorqueCaliFlg = FALSE;
     torsensor_stTorSensorOut.blTorqueErrorFlg = FALSE;
     mth_voLPFilterCoef(1000000 / 1, EVENT_1MS_HZ, &tst_dynOffsetLpf.uwKx); //25Hz  
-    tstdynOffset= hw_uwADC0[7];
-    tst_dynOffsetLpf.slY.sw.hi =  (SWORD)hw_uwADC0[7];
+    tstdynOffset= iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
+    tst_dynOffsetLpf.slY.sw.hi =  (SWORD)iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; 
         /* Torque Sensor limit coef */
    
 }
@@ -303,9 +305,9 @@ void torsensor_voDynamicOffset(void)
    if(cadence_stFreGetOut.uwLPFFrequencyPu != 0)
    {
      tstDynCalibflg = TRUE;
-     if(tsttorqMin > hw_uwADC0[7])
+     if(tsttorqMin > iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH])
      {
-        tsttorqMin = hw_uwADC0[7];
+        tsttorqMin = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH];
      }
      if(tsttorqCadCnt == ((cadence_stFreGetCof.uwNumbersPulses>>1) -1))
      {       
@@ -316,7 +318,7 @@ void torsensor_voDynamicOffset(void)
    {
      if( tstDynCalibflg == TRUE && TorqValuePu <= 500)
      {
-        tstdynOffset = hw_uwADC0[7];
+        tstdynOffset = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH];
         tstDynCalibflg = FALSE;
      }
    }
@@ -471,7 +473,7 @@ void torsensor_voTorADC(void) // need to match ADC_StartConversion(ADC1);
     if (torsensor_stTorSensorOut.blTorqueErrorFlg == TRUE)
     {
         torsensor_stTorSensorOut.uwTorquePu = 0;
-        torsensor_stTorSensorOut.uwTorqueReg = hw_uwADC0[7];
+        torsensor_stTorSensorOut.uwTorqueReg = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH];
         if (torsensor_stTorSensorOut.uwTorqueReg < 4000 && torsensor_stTorSensorOut.uwTorqueReg > 10) // output 0mv - 3000mv
         {
             torsensor_stTorSensorOut.uwTorqueErrorCnt++;
@@ -488,7 +490,7 @@ void torsensor_voTorADC(void) // need to match ADC_StartConversion(ADC1);
     }
     else
     {
-        torsensor_stTorSensorOut.uwTorqueReg = hw_uwADC0[7]; // TorSensor_uwDMAReg;
+        torsensor_stTorSensorOut.uwTorqueReg = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH]; // TorSensor_uwDMAReg;
 #if (TORSENSOR_USEMOL == TORSENSOR_USEDEFAULT)
         torsensor_stTorSensorOut.uwTorquePu =
             (((SQWORD)abs((SWORD)(torsensor_stTorSensorOut.uwTorqueReg) - torsensor_stTorSensorCof.uwTorqueOffset)) *

+ 56 - 24
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/board_config.h

@@ -1,7 +1,7 @@
 /**
  * @file board_config.h
  * @author Xiao Lifan (xiaolf6@midea.com)
- * @brief 纭�欢鐩稿叧鍙傛暟閰嶇疆
+ * @brief 硬件相关参数配置
  * @version 0.1
  * @date 2023-05-06
  *
@@ -10,7 +10,7 @@
  */
 
 /* ========================================================================== */
-/* ================================= 閲囨牱鑼冨洿閰嶇疆 ================================= */
+/* ================================= 采样范围配置 ================================= */
 /* ========================================================================== */
 
 #define HW_VBUS_MEASMAX_V   6419 /**< Vdc measure max 424.6(0.1V) */
@@ -19,14 +19,23 @@
 #define HW_I_MEASMAX_A      825  /**< Current measure max(peak2peak) (0.01A) */
 
 /* ========================================================================== */
-/* ================================= 纭�欢鍙傛暟閰嶇疆 ================================= */
+/* ================================= 硬件参数配置 ================================= */
 /* ========================================================================== */
 
-/* --------------------------------- 鐢靛姏绯荤粺鍙傛暟 --------------------------------- */
+/* ---------------------------------- 系统RAM --------------------------------- */
+
+#define HW_RAM_START_ADDRESS 0x20001fffUL
+#define HW_RAM_END_ADDRESS   0x20001fffUL
+
+/* ---------------------------------- 系统时钟 ---------------------------------- */
+
+#define HW_MCU_CLOCK_HZ 64000000UL
+
+/* --------------------------------- 电力系统参数 --------------------------------- */
 
 #define HW_UAC_FREQ_HZ 50
 
-/* --------------------------------- PWM棰戠巼閰嶇疆 -------------------------------- */
+/* --------------------------------- PWM频率配置 -------------------------------- */
 
 #define HW_TIM_CLOCK_HZ  64000000UL
 #define HW_TIM_CLOCK_MHZ (HW_TIM_CLOCK_HZ / 1000000UL)
@@ -42,42 +51,65 @@
 #define HW_INIT_HHPWM_PERIOD  (HW_INIT_PWM_PERIOD >> 2)
 #define HW_INIT_HHHPWM_PERIOD (HW_INIT_PWM_PERIOD >> 3)
 
-/* --------------------------------- PWM姝诲尯鍙傛暟 -------------------------------- */
+/* --------------------------------- PWM死区参数 -------------------------------- */
 
-#define HW_DEADBAND_TIME HW_TIM_CLOCK_MHZ /**< 姝诲尯鏃堕棿锛屽崟浣�: 鏃堕挓Tick */
+#define HW_DEADBAND_TIME HW_TIM_CLOCK_MHZ /**< 死区时间,单位: 时钟Tick */
 
-/* ---------------------------------- adc鍙傛暟 --------------------------------- */
+/* ---------------------------------- adc参数 --------------------------------- */
 
-#define HW_SAMPLE_BEFORE_UPDATE_CNTS 100 /**< 閲囨牱鐩稿�浜嶱WM椤跺簳鐐规彁鍓嶇殑鍛ㄦ湡鏁帮紝鍗曚綅: 鏃堕挓Tick */
+#define HW_SAMPLE_BEFORE_UPDATE_CNTS 100 /**< 采样相对于PWM顶底点提前的周期数,单位: 时钟Tick */
 
-/* ---------------------------------- 鍏呯數缁х數鍣� --------------------------------- */
+/* ---------------------------------- 充电继电器 --------------------------------- */
 
-#define HW_RLY_VOL_V     1600 /**< 姣嶇嚎鍏呯數闄愬€肩數鍘嬶紝鍗曚綅: 0.1V */
-#define HW_RLY_VOL_MS    1000 /**< 姣嶇嚎鍏呮椂闂达紝鍗曚綅: MS */
+#define HW_RLY_VOL_V     1600 /**< 母线充电限值电压,单位: 0.1V */
+#define HW_RLY_VOL_MS    1000 /**< 母线充时间,单位: MS */
 #define HW_RLYON_OVER_MS 200
 
-/* ---------------------------------- 杈撳叆鎹曡幏 ---------------------------------- */
+/* ---------------------------------- 输入捕获 ---------------------------------- */
 
 #define HW_PWM_CAP_HZ 1600000L
 
 /* ========================================================================== */
-/* ================================ API鎺ュ彛搴忓彿瀹氫箟 =============================== */
+/* ================================ API接口序号定义 =============================== */
 /* ========================================================================== */
 
 #define HW_TBS_TIMER     0
 #define HW_SYSTICK_TIMER 1
 
-#define HW_ADC_VC_CH   0
-#define HW_ADC_VB_CH   1
-#define HW_ADC_VA_CH   2
-#define HW_ADC_IA_CH   4
-#define HW_ADC_IB_CH   3
-#define HW_ADC_UDC_CH  5
-#define HW_ADC_TEMP_CH 6
-#define HW_ADC_UAC_CH  7
+#define TBS_TIMER                       0
+#define SYSTICK_TIMER                   1
+      
+#define HW_ADC_IA_CH                       0
+#define HW_ADC_IB_CH                       1
+#define HW_ADC_IC_CH                       2 
+      
+#define HW_ADC_IDC_CH                      0
+
+#define HW_ADC_UDC_CH                      0
+#define HW_ADC_U6V_CH                      1
+#define HW_ADC_U5V_CH                      2
+#define HW_ADC_PCBTEMP_CH                  3
+#define HW_ADC_MOTTEMP_CH                  4
+#define HW_ADC_U12V_CH                     5
+#define HW_ADC_THRO_CH                     6
+#define HW_ADC_TORQ_CH                     7
+  
+#define HW_GPIO_LED_PIN                    0
+#define HW_GPIO_CAP_PIN                    1    
+
+#define HW_GPIO_TX_PIN 0
+#define HW_GPIO_RX_PIN 1
 
 #define HW_ADC_IBUS_1ST_CH 0
 #define HW_ADC_IBUS_2ND_CH 1
 
-#define HW_GPIO_TX_PIN 0
-#define HW_GPIO_RX_PIN 1
+#define HW_ADC_SP_CHANNEL   0
+#define HW_ADC_TEMP_CHANNEL 1
+#define HW_ADC_IU_CHANNEL   2
+#define HW_ADC_IV_CHANNEL   3
+#define HW_ADC_UDC_CHANNEL  4
+#define HW_ADC_UW_CHANNEL   5
+#define HW_ADC_UV_CHANNEL   6
+#define HW_ADC_UU_CHANNEL   7
+
+/* Api Device Index Definations */

+ 2 - 1
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Source/hwsetup.c

@@ -27,6 +27,7 @@
 #include "user.h"
 #include "FuncLayerAPI.h"
 #include "can.h"
+#include "api_rt.h"
 /************************************************************************
  Constant Table (N/A)
 *************************************************************************/
@@ -365,7 +366,7 @@ void hw_voInitDMA(void)
     /* initialize DMA single data mode */
     dma_init_struct.periph_addr  = (uint32_t)(&ADC_RDATA(ADC0));
     dma_init_struct.periph_inc   = DMA_PERIPH_INCREASE_DISABLE;
-    dma_init_struct.memory_addr  = (uint32_t)(hw_uwADC0);
+    dma_init_struct.memory_addr  = (uint32_t)(Adcs[0].Results);
     dma_init_struct.memory_inc   = DMA_MEMORY_INCREASE_ENABLE;
     dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
     dma_init_struct.memory_width = DMA_MEMORY_WIDTH_16BIT;  

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

@@ -456,6 +456,25 @@ Update Time
 // #define HFI_PLL_CROSS_FREQ_HZ                  20      // unit: Hz, Pll cross frequency
 // #define HFI_SPD_LPF_HZ                         8      // unit: Hz, Cut-off frequency of spd lpf
 // #define HFI_MAG_SATR_AP                        240      // unit: 0.01A, Magnetic saturation current
+/*==============================================================================
+                      Deadband Compensation parameters define
+==============================================================================*/
+/* Api Device Index Definations */
+#define TBS_TIMER                       0
+#define SYSTICK_TIMER                   1
+      
+#define ADC_IA_CH                       0
+#define ADC_IB_CH                       1
+#define ADC_IC_CH                       2 
+      
+#define ADC_IDC_CH                      0
+
+#define ADC_UDC_CH                      0
+#define ADC_TEMP_CH                     1
+#define ADC_UAC_CH                      2
+
+#define GPIO_LED_PIN                    0
+#define GPIO_CAP_PIN                    1      
 /************************************************************************
  TypeDefs & Structure defines
 *************************************************************************/

+ 10 - 0
User project/5.Api_rt/api_rt.c

@@ -0,0 +1,10 @@
+#include "api_rt.h"
+
+void iRt_Init()
+{
+    iRtGpio_Init();
+//    iRtTimer_Init();
+//    iRtUart_Init();
+//    iRtPwm_Init();
+    iRtAdc_Init();
+}

+ 21 - 0
User project/5.Api_rt/api_rt.h

@@ -0,0 +1,21 @@
+#include "api_config.h"
+#include "api_board_support.h"
+#include "board_config.h"
+#include "api_rt_gpio.h"
+//#include "api_rt_uart.h"
+//#include "api_rt_timer.h"
+//#include "api_rt_pwm.h"
+#include "api_rt_adc.h"
+
+#ifndef _API_RT_H_
+#define _API_RT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif

+ 11 - 12
User project/5.Api_rt/api_rt_adc.c

@@ -1,11 +1,10 @@
-#include "api.h"
 #include "api_rt_adc.h"
 #include "gd32f30x.h"
 
-Adc_Handle Adcs[2];
+Adc_Handle Adcs[3];
 
 
-void AdcLow_Init(void)
+void iRtAdc_Init(void)
 {
     // ADC0 Regular
     Adcs[0].AdcBase = ADC0;
@@ -19,10 +18,10 @@ void AdcLow_Init(void)
     Adcs[1].AdcBase = ADC0;
     for (int i = 1; i < ADC_RESULT_SIZE; i++)
     {
-        Adcs[1].Results[i] = 1;
+        Adcs[1].Results[i] = 0;
     }
     // ADC1 Injected
-    Adcs[2].AdcBase = ADC0;
+    Adcs[2].AdcBase = ADC1;
     for (int i = 0; i < ADC_RESULT_SIZE; i++)
     {
         Adcs[2].Results[i] = 0;
@@ -46,33 +45,33 @@ uint16_t* iAdc_GetResultPointer(uint8_t devIndex)
 void iAdc_Enable(uint8_t devIndex)
 {
 //    ASSERT_LESS(devIndex, 1);
-    if(RESET == (ADC_CTL1(devIndex) & ADC_CTL1_ADCON)){
-        ADC_CTL1(devIndex) |= (uint32_t)ADC_CTL1_ADCON;
+    if(RESET == (ADC_CTL1(Adcs[devIndex].AdcBase) & ADC_CTL1_ADCON)){
+        ADC_CTL1(Adcs[devIndex].AdcBase) |= (uint32_t)ADC_CTL1_ADCON;
     }   
 }
 
 void iAdc_Disable(uint8_t devIndex)
 {
 //    ASSERT_LESS(devIndex, 1);
-    ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
+    ADC_CTL1(Adcs[devIndex].AdcBase) &= ~((uint32_t)ADC_CTL1_ADCON);
 }
 
 ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
 {
-     if (ADC_STAT(devIndex) & ADC_STAT_EOC != 0)
+     if (ADC_STAT(Adcs[devIndex].AdcBase) & ADC_STAT_EOC != 0)
     {
-        return Adc_End;
+        return ApiAdc_End;
     }
     else
     {
-        return Adc_Converting;
+        return ApiAdc_Converting;
     }
 }
 
 void iAdc_Convert(uint8_t devIndex)
 {
   //for regular only
-    ADC_CTL1(devIndex) |= ADC_CTL1_SWRCST;
+    ADC_CTL1(Adcs[devIndex].AdcBase) |= ADC_CTL1_SWRCST;
 }
 
 void iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)

+ 4 - 3
User project/5.Api_rt/api_rt_adc.h

@@ -2,6 +2,7 @@
 #define _API_RT_ADC_H_
 
 #include <stdint.h>
+#include "api_adc.h"
 #include "gd32f30x.h"
 
 #define ADC_DEVICE_COUNT        1
@@ -16,9 +17,9 @@ typedef struct
 
 }  Adc_Handle;
 
-extern Adc_Handle Adcs[2];
+extern Adc_Handle Adcs[3];
 
-void AdcLow_Init(void);
-void AdcLow_CompleteIsr(uint8_t devIndex);
+void iRtAdc_Init(void);
+void iRtAdc_CompleteIsr(uint8_t devIndex);
 
 #endif

+ 66 - 0
User project/5.Api_rt/api_rt_gpio.c

@@ -0,0 +1,66 @@
+#include "api_rt_gpio.h"
+#include "gd32f30x.h"
+
+Gpio_Handle const Gpios[GPIO_PIN_COUNT] = {
+    [0] = {.GpioBase = GPIOB, .Index = 4},
+    [1] = {.GpioBase = GPIOB, .Index = 5},
+    [2] = {.GpioBase = GPIOB, .Index = 9},
+};
+
+void iRtGpio_Init()
+{
+
+}
+
+void iGpio_SetMode(uint16_t pin, ApiGpio_PinMode mode)
+{
+    const Gpio_Handle *const gpio = &Gpios[pin];
+
+    switch (mode)
+    {
+    case ApiGpio_Input:
+         GPIO_CTL0(gpio->GpioBase) &=  GPIO_MODE_SET(pin, mode);
+//        gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
+        break;
+    case ApiGpio_Output:
+//        gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
+//        gpio->GpioBase->MODER |= (((uint32_t)0x00000001UL) << (2 * gpio->Index));
+        break;
+    case ApiGpio_AlternateFunction:
+//        gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
+//        gpio->GpioBase->MODER |= (((uint32_t)0x00000002UL) << (2 * gpio->Index));
+        break;
+    default:
+        break;
+    }
+}
+
+iGpio_Level iGpio_Read(uint16_t pin)
+{
+//    ASSERT_LESS(pin, GPIO_PIN_COUNT);
+//    const Gpio_Handle *const gpio = &Gpios[pin];
+//
+//    iGpio_Level level = iGpio_LowLevel;
+//
+//    if (gpio->GpioBase->IDR & (((uint32_t)0x00000001UL) << gpio->Index))
+//    {
+//        level = iGpio_HighLevel;
+//    }
+
+//    return level;
+}
+
+void iGpio_Write(uint16_t pin, iGpio_Level level)
+{
+//    ASSERT_LESS(pin, GPIO_PIN_COUNT);
+//    const Gpio_Handle *const gpio = &Gpios[pin];
+//
+//    if (level == iGpio_HighLevel)
+//    {
+//        gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << gpio->Index);
+//    }
+//    else
+//    {
+//        gpio->GpioBase->BSRR = (((uint32_t)0x00000001UL) << (gpio->Index + 16));
+//    }
+}

+ 27 - 0
User project/5.Api_rt/api_rt_gpio.h

@@ -0,0 +1,27 @@
+#ifndef _API_RT_GPIO_H_
+#define _API_RT_GPIO_H_
+
+#include "api_gpio.h"
+#include "gd32f30x.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#define GPIO_PIN_COUNT 3
+
+typedef struct
+{
+    uint32_t      GpioBase;
+    uint8_t       Index;
+} Gpio_Handle;
+
+extern Gpio_Handle const Gpios[GPIO_PIN_COUNT];
+
+void iRtGpio_Init();
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif

+ 15 - 0
WLMCP.ewp

@@ -2740,6 +2740,9 @@
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\api_config.h</name>
                     </file>
+                    <file>
+                        <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\board_config.h</name>
+                    </file>
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\bootloader.h</name>
                     </file>
@@ -2814,12 +2817,24 @@
         </group>
         <group>
             <name>5.api_rt</name>
+            <file>
+                <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>
+            </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>
             </file>
+            <file>
+                <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>
+            </file>
         </group>
         <group>
             <name>api</name>