Browse Source

feat(Api_rt): 添加gpo抽象层,更新应用功能IO口抽象

CN\zhangkai71 2 years ago
parent
commit
96dca5231e

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

@@ -23,7 +23,8 @@
 #include "syspar.h"
 #include "user.h"
 #include "STLmain.h"
-#include "api_rt_adc.h"
+#include "api_rt.h"
+//#include "api.h"
 /******************************
  *
  *  Parameter
@@ -247,10 +248,11 @@ void  Event_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无
 
 }
 
+
 void Event_5ms(void)
 {
     /* Upper Computer Info Update */
-    Can_voMC_Run_5ms();
+    Can_voMC_Run_5ms();  
 }
 
 void Event_10ms(void)

+ 1 - 0
User project/3.BasicFunction/Include/bikebrake.h

@@ -15,6 +15,7 @@
 #ifndef BIKEBRAKE_H
 #define BIKEBRAKE_H
 
+#include "typedefine.h"
 /****************************************
  *
  *          Definitions & Macros

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

@@ -14,7 +14,7 @@
 *************************************************************************/
 #ifndef BIKELIGHT_H
 #define BIKELIGHT_H
-
+#include "api_rt.h"
 
 
 #ifdef BIKELIGHT_
@@ -27,19 +27,19 @@
 
 #endif
 
-
 //---------------------------------------
 /* 前灯控制IO on/off */
-#define IO_FORWARDLED_ON()             (GPIO_OCTL(GPIOC) |= 0x8000)//PC15
-#define IO_FORWARDLED_OFF()            (GPIO_OCTL(GPIOC) &= ~0x8000) //PC15
-#define IO_FORWARDLED_12V_ENABLE()     (GPIO_OCTL(GPIOC) |= 0x2000)//PC13
-#define IO_FORWARDLED_12V_DISABLE()    (GPIO_OCTL(GPIOC) &= ~0x2000)//PC13
+
+#define IO_FORWARDLED_ON()             iGpio_Write(HW_GPIO_FLIG_EN_PIN,iGpio_HighLevel)//PC15
+#define IO_FORWARDLED_OFF()            iGpio_Write(HW_GPIO_FLIG_EN_PIN,iGpio_LowLevel) //PC15
+#define IO_FORWARDLED_12V_ENABLE()     iGpio_Write(HW_GPIO_FLIG_6V_12V_EN_PIN,iGpio_HighLevel)//PC13
+#define IO_FORWARDLED_12V_DISABLE()    iGpio_Write(HW_GPIO_FLIG_6V_12V_EN_PIN,iGpio_LowLevel)//PC13
 
 /* 后灯控制IO on/off */
-#define IO_BACKLED_ON()             (GPIO_OCTL(GPIOC) |= 0x0100)//PC8
-#define IO_BACKLED_OFF()            (GPIO_OCTL(GPIOC) &= ~0x0100) //PC8
-#define IO_BACKLED_12V_ENABLE()     (GPIO_OCTL(GPIOC) |= 0x0080)//PC7
-#define IO_BACKLED_12V_DISABLE()    (GPIO_OCTL(GPIOC) &= ~0x0080)//PC7
+#define IO_BACKLED_ON()             iGpio_Write(HW_GPIO_BLIG_EN_PIN,iGpio_HighLevel)//PC8
+#define IO_BACKLED_OFF()            iGpio_Write(HW_GPIO_BLIG_EN_PIN,iGpio_LowLevel) //PC8
+#define IO_BACKLED_12V_ENABLE()     iGpio_Write(HW_GPIO_BLIG_6V_12V_EN_PIN,iGpio_HighLevel)//PC7
+#define IO_BACKLED_12V_DISABLE()    iGpio_Write(HW_GPIO_BLIG_6V_12V_EN_PIN,iGpio_LowLevel)//PC7
 
 //---------------------------------------
 #define    BikeLedAddCycle    8  //亮尾灯周期

+ 1 - 0
User project/3.BasicFunction/Include/spi_master.h

@@ -20,6 +20,7 @@
 #ifndef SPI_MASTER_H
 #define SPI_MASTER_H
 
+#include "typedefine.h"
 /************************************************************************
  Compiler Directives (N/A)
 *************************************************************************/

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

@@ -17,7 +17,7 @@
 #include "Cadence.h"
 #include "CodePara.h"
 #include "hwsetup.h"
-
+#include "api_rt.h"
 #ifdef RUN_ARCH_SIM
 #include "test_user.h"
 #endif
@@ -283,7 +283,7 @@ static void cadence_voCadenceBackword(UWORD source)
 ****************************************************************/
 static void cadence_voCadenceDir(void)
 {
-    if (IO_CANDANCEDIR_STATE == 0)
+    if (iGpio_Read(HW_GPIO_CadDir_PIN) == 0)
     {
         cadence_stFreGetOut.cadence_dir = CADENCE_DIR_FORWARD;
     }

+ 7 - 4
User project/3.BasicFunction/Source/bikebrake.c

@@ -13,9 +13,10 @@
  Beginning of File, do not put anything above here except notes
  Compiler Directives:
 *************************************************************************/
-#include "typedefine.h"
+//#include "typedefine.h"
 #include "bikebrake.h"
-#include "hwsetup.h"
+#include "api_rt.h"
+//#include "hwsetup.h"
 
 #ifdef RUN_ARCH_SIM
 #include "test_user.h"
@@ -53,7 +54,9 @@ void bikebrake_voBikeBrakeInit(void)
 ****************************************************************/
 void bikebrake_voBikeBrakeDetect(void)
 {
-    if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == FALSE && (IO_BIKEBRAKE_STATE == 0))
+  
+  
+    if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == FALSE && (iGpio_Read(HW_GPIO_BREAK_PIN) == 0))
     {
         bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
         if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
@@ -64,7 +67,7 @@ void bikebrake_voBikeBrakeDetect(void)
         }
     }
 
-    if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == TRUE && (IO_BIKEBRAKE_STATE != 0))
+    if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == TRUE && (iGpio_Read(HW_GPIO_BREAK_PIN) != 0))
     {
         bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
         if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)

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

@@ -618,8 +618,7 @@ void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-supp
                     SendData(ID_MC_TO_CDL, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
                 }
                 
-                IO_POWERLOCK_OFF;
-//                GPIOC->ODR &= ~(1 << POWER_LOCK_PORT);
+                iGpio_Write(HW_GPIO_POWERLOCK_PIN,iGpio_LowLevel);
             }
             break;
         }
@@ -639,8 +638,7 @@ void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-supp
                     SendData(ID_MC_TO_CDL, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
                 }
                 
-                IO_POWERLOCK_OFF;
-//                GPIOC->ODR &= ~(1 << POWER_LOCK_PORT);
+                iGpio_Write(HW_GPIO_POWERLOCK_PIN,iGpio_LowLevel);
             }
             break;
         }
@@ -702,8 +700,7 @@ void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-supp
                     SendData(ID_MC_TO_CDL, MODE_REPORT, 0xA903, (UBYTE *)"ACK");
                 }
                 
-                IO_POWERLOCK_OFF;
-//                GPIOC->ODR &= ~(1 << POWER_LOCK_PORT);
+                iGpio_Write(HW_GPIO_POWERLOCK_PIN,iGpio_LowLevel);
             }
             break;
         }

+ 8 - 6
User project/3.BasicFunction/Source/i2c_master.c

@@ -25,6 +25,7 @@
  Included File
 *************************************************************************/
 #include "i2c_master.h"
+#include "api_rt.h"
 #include "gd32f30x_dma.h"
 
 /*************************************************************************
@@ -62,7 +63,7 @@ void  i2c_voWaitEEReady(UBYTE SlaveAddr)
 //    while(!I2C_EE_ComuFltFlg)
 //    {
 //        /* write to EEPROM enable*/
-//        IO_WRITE2EE_ENABLE;
+//        iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_LowLevel);
 //        /* wait until I2C bus is idle */
 //        while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (++ulTimeCnt < I2C_SHORT_TIMEOUT));
 //        if(ulTimeCnt == I2C_SHORT_TIMEOUT)
@@ -136,7 +137,7 @@ void  i2c_voWaitEEReady(UBYTE SlaveAddr)
 //        }        
 //    }
 //    /* write to EEPROM disable */
-//    IO_WRITE2EE_DISABLE;
+//    iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_LowLevel);
     
 }
 
@@ -333,7 +334,7 @@ void i2c_voHistoryWriteBuffer(void)
 //    if(!I2C_EE_ComuFltFlg)
 //    {
 //        /* write to EEPROM enable*/
-//        IO_WRITE2EE_ENABLE;
+//        iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_LowLevel);
 //        /* wait until I2C bus is idle */
 //        while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (ulTimeCnt< I2C_SHORT_TIMEOUT))
 //    	{
@@ -416,7 +417,7 @@ void i2c_voHistoryWriteBuffer(void)
 //        }
 //        ulTimeCnt = 0;
 //        /* write to EEPROM disable */
-//        IO_WRITE2EE_DISABLE;
+//        iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_LowLevel);
 //
 //        /* I2C EEPROM communication timeout fault */
 //        if(uwTimeoutNum > 0)
@@ -444,7 +445,7 @@ void i2c_voPageWrite2EE(const UBYTE *pBuffer, UBYTE SlaveAddr, UBYTE WriteAddr,
     if(!I2C_EE_ComuFltFlg)
     {
         /* write to EEPROM enable*/
-        IO_WRITE2EE_ENABLE;
+        iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_HighLevel);
         /* wait until I2C bus is idle */
         while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (ulTimeCnt < I2C_SHORT_TIMEOUT))
     	{
@@ -543,7 +544,8 @@ void i2c_voPageWrite2EE(const UBYTE *pBuffer, UBYTE SlaveAddr, UBYTE WriteAddr,
            I2C_EE_ComuFltFlg = TRUE;
         }  
         /* write to EEPROM disable */
-        IO_WRITE2EE_DISABLE;
+        
+        iGpio_Write(HW_GPIO_I2CWP_PIN,iGpio_LowLevel);
     }
     else
     {}

+ 6 - 8
User project/3.BasicFunction/Source/power.c

@@ -14,10 +14,9 @@
  Compiler Directives:
 *************************************************************************/
 #include "typedefine.h"
-#include "hwsetup.h"
 #include "power.h"
 #include "can.h"
-
+#include "api_rt.h"
 /******************************
  *
  *  Parameter
@@ -67,13 +66,12 @@ void power_voPowerManagement(ULONG ulAutoPowerOffDelayTime, ULONG SysTickCnt, UL
     {
         case POWER_START: //��Դ�����£�����1s����POWER ON
         {
-            if(IO_POWER_STATE != 0)
+            if(iGpio_Read(HW_GPIO_POWERSTATE_PIN) != 0)
             {
                 power_stPowStateOut.uwPowerStartupCnt++;
                 if (power_stPowStateOut.uwPowerStartupCnt == power_stPowStateCof.uwPowerStartTouchTimeCnt)
                 {
-                    IO_POWERLOCK_ON;
-//                    GPIOC->ODR |= (1 << POWER_LOCK_PORT);
+                    iGpio_Write(HW_GPIO_POWERLOCK_PIN,iGpio_HighLevel);
                     power_stPowStateOut.powerstate = POWER_ON;
                     power_stPowStateOut.uwPowerOn2OffCnt = 0;
                 }
@@ -86,7 +84,7 @@ void power_voPowerManagement(ULONG ulAutoPowerOffDelayTime, ULONG SysTickCnt, UL
             power_stPowStateOut.uwPowerOn2OffCnt++;
             if (power_stPowStateOut.uwPowerOn2OffCnt >= power_stPowStateCof.uwPowerOn2OffTimeCnt)
             {
-                if(IO_POWER_STATE == 0)
+                if(iGpio_Read(HW_GPIO_POWERSTATE_PIN) == 0)
                 {
                     power_stPowStateOut.powerstate = POWER_ON_END;
                     power_stPowStateOut.blPowerStartupFlg = TRUE;
@@ -99,7 +97,7 @@ void power_voPowerManagement(ULONG ulAutoPowerOffDelayTime, ULONG SysTickCnt, UL
         case POWER_ON_END: //��Դ�����½���POWER_OFF��������趨ʱ����Զ�����POWER_OFF
         {
             //The key pushed down for "uwPowerShutTouchTimeCnt" to POWER_OFF
-            if (IO_POWER_STATE != 0)
+            if (iGpio_Read(HW_GPIO_POWERSTATE_PIN) != 0)
             {
                 power_stPowStateOut.uwPowerShutdnCnt++;
                 if (power_stPowStateOut.uwPowerShutdnCnt >= power_stPowStateCof.uwPowerShutTouchTimeCnt)
@@ -149,7 +147,7 @@ void power_voPowerManagement(ULONG ulAutoPowerOffDelayTime, ULONG SysTickCnt, UL
                 power_stPowStateOut.blPowerShutdownFlg = TRUE;
                 power_stPowStateOut.uwPowerShutdnCnt = 0;
                 
-                IO_POWERLOCK_OFF;
+                iGpio_Write(HW_GPIO_POWERLOCK_PIN,iGpio_LowLevel);
             }
             break;
         }

+ 25 - 23
User project/3.BasicFunction/Source/spi_master.c

@@ -25,7 +25,8 @@
  Included File
 *************************************************************************/
 #include "user.h"
-
+#include "spi_master.h"
+#include "api_rt.h"
 /*************************************************************************
  Exported Functions (N/A)
 *************************************************************************/
@@ -293,14 +294,15 @@ void  spi_voResolver(const SPI_RESOLVER_COEF *coef, SPI_RESOLVER_OUT *out)
 void spi_voResolverLock(void)
 {
     /* CS signal enable */
-    IO_SPI2_NSS_ENABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
     {}
     spi_i2s_data_transmit(SPI2,0x0550);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TRANS) != RESET)
     {}
     /* CS signal disable */
-    IO_SPI2_NSS_DISABLE;    
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
 }
 /*************************************************************************
  Function:
@@ -318,45 +320,45 @@ void spi_voReadWriteSeneorReg(void) /* parasoft-suppress METRICS-28 "本项目
     UWORD SPI_DelayCnt1 = 0, SPI_DelayCnt2 = 0;
 
     /* Read the BCT register value */
-    IO_SPI2_NSS_ENABLE; /*!< CS signal enable,for data update */
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel); /*!< CS signal enable,for data update */
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
     {}
     spi_i2s_data_transmit(SPI2, 0x4200); //comp value
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TRANS) != RESET)
     {}
-    IO_SPI2_NSS_DISABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
     {}
     uwReadBCTReg = spi_i2s_data_receive(SPI2); /*!< Read the first time */
-    IO_SPI2_NSS_ENABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
     {}
     spi_i2s_data_transmit(SPI2, 0x0000); /*!< Write the second time */
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TRANS) != RESET)
     {}
-    IO_SPI2_NSS_DISABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
     {}
     uwReadBCTReg = spi_i2s_data_receive(SPI2); /*!< Read the BCT register value */
 
     /* Read the ETX ETY value */
-    IO_SPI2_NSS_ENABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
     {}
     spi_i2s_data_transmit(SPI2, 0x4300); //comp direction 
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TRANS) != RESET)
     {}
-    IO_SPI2_NSS_DISABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
     {}
     uwReadETXY = spi_i2s_data_receive(SPI2); /*!< Read the first time */
-    IO_SPI2_NSS_ENABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
     {}
     spi_i2s_data_transmit(SPI2, 0x0000); /*!< Write the second time */
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_TRANS) != RESET)
     {}
-    IO_SPI2_NSS_DISABLE;
+    iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
     while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
     {}
     uwReadETXY = spi_i2s_data_receive(SPI2); /*!< Read the ETX ETY value */
@@ -374,14 +376,14 @@ void spi_voReadWriteSeneorReg(void) /* parasoft-suppress METRICS-28 "本项目
     //if (spi_blWriteRegFinishFlg == FALSE)
     {
         /* Write and Read BCT value*/
-        IO_SPI2_NSS_ENABLE;   // Data update
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);   // Data update
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)// Discontinuous transmission, can not indicate send complete
         {}
         spi_i2s_data_transmit(SPI2, 0x8230); // LSB,BCT=48
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteBCTReg = spi_i2s_data_receive(SPI2);       
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         /* Delay at least 22ms */
         while (SPI_DelayCnt2 < 20)
         {
@@ -392,23 +394,23 @@ void spi_voReadWriteSeneorReg(void) /* parasoft-suppress METRICS-28 "本项目
                 SPI_DelayCnt1 = 0;
             }
         }
-        IO_SPI2_NSS_ENABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
         {}
         spi_i2s_data_transmit(SPI2, 0x0000);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteBCTReg = spi_i2s_data_receive(SPI2);
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         /* Write and Read ETX or ETY */
-        IO_SPI2_NSS_ENABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
         {}
         spi_i2s_data_transmit(SPI2, 0x8301);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteETXY = spi_i2s_data_receive(SPI2);
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         /* Delay at least 22ms */
         SPI_DelayCnt2 = 0;
         while (SPI_DelayCnt2 < 20)
@@ -420,24 +422,24 @@ void spi_voReadWriteSeneorReg(void) /* parasoft-suppress METRICS-28 "本项目
                 SPI_DelayCnt1 = 0;
             }
         }
-        IO_SPI2_NSS_ENABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
         {}
         spi_i2s_data_transmit(SPI2, 0x0000);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteETXY = spi_i2s_data_receive(SPI2);
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         
         /* Write and Read RD value*/
-        IO_SPI2_NSS_ENABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
         {}
         spi_i2s_data_transmit(SPI2, 0x8980); // RD=1,Counterclockwise,8980; RD=0,Clockwise,8900
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteRD = spi_i2s_data_receive(SPI2);
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         /* Delay at least 22ms */
         SPI_DelayCnt2 = 0;
         while (SPI_DelayCnt2 < 20)
@@ -449,14 +451,14 @@ void spi_voReadWriteSeneorReg(void) /* parasoft-suppress METRICS-28 "本项目
                 SPI_DelayCnt1 = 0;
             }
         }
-        IO_SPI2_NSS_ENABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_HighLevel);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_TBE) != SET)
         {}
         spi_i2s_data_transmit(SPI2, 0x0000);
         while (spi_i2s_flag_get(SPI2, SPI_FLAG_RBNE) != SET)
         {}
         uwWriteRD = spi_i2s_data_receive(SPI2);
-        IO_SPI2_NSS_DISABLE;
+        iGpio_Write(HW_GPIO_SPICS_PIN,iGpio_LowLevel);
         
         if (uwWriteBCTReg == 0x3000 && uwWriteETXY == 0x0100 && uwWriteRD == 0x8000) // MSB
         {

+ 38 - 36
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,28 +19,28 @@
 #define HW_I_MEASMAX_A      825  /**< Current measure max(peak2peak) (0.01A) */
 
 /* ========================================================================== */
-/* ================================= 硬件参数配置 ================================= */
+/* ================================= 纭�欢鍙傛暟閰嶇疆 ================================= */
 /* ========================================================================== */
 
-/* ---------------------------------- 系统RAM --------------------------------- */
+/* ---------------------------------- 绯荤粺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)
 
-#define HW_INIT_FPWM_HZ   8000
+#define HW_INIT_FPWM_HZ   5000
 #define HW_INIT_FTBC_TICK 1
 #define HW_INIT_FTBS_TICK 4
 #define HW_INIT_FTBC_HZ   (HW_INIT_FPWM_HZ / HW_INIT_FTBC_TICK)
@@ -51,26 +51,26 @@
 #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 /**< 采样相对于PWM顶底点提前的周期数,单位: 时钟Tick */
+#define HW_SAMPLE_BEFORE_UPDATE_CNTS 100 /**< 閲囨牱鐩稿�浜嶱WM椤跺簳鐐规彁鍓嶇殑鍛ㄦ湡鏁帮紝鍗曚綅: 鏃堕挓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
@@ -78,13 +78,16 @@
 
 #define TBS_TIMER                       0
 #define SYSTICK_TIMER                   1
-      
+
+/* ADC0 injected group*/      
 #define HW_ADC_IA_CH                       0
 #define HW_ADC_IB_CH                       1
 #define HW_ADC_IC_CH                       2 
-      
+
+/* ADC1 injected group*/       
 #define HW_ADC_IDC_CH                      0
 
+/* ADC0 regular group*/  
 #define HW_ADC_UDC_CH                      0
 #define HW_ADC_U6V_CH                      1
 #define HW_ADC_U5V_CH                      2
@@ -94,22 +97,21 @@
 #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_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
+/* GPIO*/
+#define HW_GPIO_POWERSTATE_PIN             0  ///> GPIOC  PIN0
+#define HW_GPIO_POWERLOCK_PIN              1  ///> GPIOC  PIN1 
+#define HW_GPIO_BLIG_EN_PIN                2  ///> GPIOC  PIN7 
+#define HW_GPIO_BLIG_6V_12V_EN_PIN         3  ///> GPIOC  PIN8 
+#define HW_GPIO_FLIG_EN_PIN                4  ///> GPIOC  PIN15 
+#define HW_GPIO_FLIG_6V_12V_EN_PIN         5  ///> GPIOC  PIN13
+#define HW_GPIO_BREAK_PIN                  6  ///> GPIOC  PIN14 
+#define HW_GPIO_UARTTX_PIN                 7  ///> GPIOC  PIN10 
+#define HW_GPIO_UARTRX_PIN                 8  ///> GPIOC  PIN11 
+#define HW_GPIO_SPICS_PIN                  9  ///> GPIOD  PIN2
+#define HW_GPIO_CANTX_PIN                  10 ///> GPIOB  PIN9 
+#define HW_GPIO_CANRX_PIN                  11 ///> GPIOB  PIN8 
+#define HW_GPIO_CANSTB_PIN                 12 ///> GPIOA  PIN12 
+#define HW_GPIO_I2CWP_PIN                  13 ///> GPIOC  PIN12 
+#define HW_GPIO_CadDir_PIN                  14 ///> GPIOB  PIN2
 
 /* Api Device Index Definations */

+ 21 - 21
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/hwsetup.h

@@ -70,27 +70,27 @@
 #define MCU_BRKIN_FLG_CLR (TIMER_INTF(TIMER0) &= ~0x0080)
 #define MCU_POEN_FLG_EN   (TIMER_CCHP(TIMER0) |= 0x00008000)
 /* SPI CS enable */
-#define IO_SPI2_NSS_DISABLE  (GPIO_OCTL(GPIOD)|= 0x0004)          
-#define IO_SPI2_NSS_ENABLE   (GPIO_OCTL(GPIOD)&= ~0x0004)  
-/* I2C Write2EE enable */
-#define IO_WRITE2EE_DISABLE (GPIO_OCTL(GPIOC)|= 0x1000)
-#define IO_WRITE2EE_ENABLE  (GPIO_OCTL(GPIOC) &= ~0x1000)
-/* Bike brake state */
-#define IO_BIKEBRAKE_STATE  (GPIO_ISTAT(GPIOC) & 0x4000)
-#define IO_CANDANCEDIR_STATE  (GPIO_ISTAT(GPIOB) & 0x0004)
-/* Bike light on/off */
-#define IO_BIKELIGHT_FRONT_ON (GPIO_OCTL(GPIOC) |= 0x8000)
-#define IO_BIKELIGHT_FRONT_OFF (GPIO_OCTL(GPIOC) &= ~0x8000)
-#define IO_BIKELIGHT_FRONT_12V_ENABLE (GPIO_OCTL(GPIOC) |= 0x2000)
-#define IO_BIKELIGHT_FRONT_12V_DISABLE (GPIO_OCTL(GPIOC) &= ~0x2000)
-#define IO_BIKELIGHT_REAR_ON (GPIO_OCTL(GPIOC) |= 0x0100)
-#define IO_BIKELIGHT_REAR_OFF (GPIO_OCTL(GPIOC) &= ~0x0100)
-#define IO_BIKELIGHT_REAR_12V_ENABLE (GPIO_OCTL(GPIOC) |= 0x0080)
-#define IO_BIKELIGHT_REAR_12V_DISABLE (GPIO_OCTL(GPIOC) &= ~0x0080)
-/* Power lock on/off */
-#define IO_POWERLOCK_ON (GPIO_OCTL(GPIOC) |= 0x0002)
-#define IO_POWERLOCK_OFF (GPIO_OCTL(GPIOC) &= ~0x0002)
-#define IO_POWER_STATE  (GPIO_ISTAT(GPIOC) & 0x0001)
+//#define IO_SPI2_NSS_DISABLE  (GPIO_OCTL(GPIOD)|= 0x0004)          
+//#define IO_SPI2_NSS_ENABLE   (GPIO_OCTL(GPIOD)&= ~0x0004)  
+///* I2C Write2EE enable */
+//#define IO_WRITE2EE_DISABLE (GPIO_OCTL(GPIOC)|= 0x1000)
+//#define IO_WRITE2EE_ENABLE  (GPIO_OCTL(GPIOC) &= ~0x1000)
+///* Bike brake state */
+//#define IO_BIKEBRAKE_STATE  (GPIO_ISTAT(GPIOC) & 0x4000)
+//#define IO_CANDANCEDIR_STATE  (GPIO_ISTAT(GPIOB) & 0x0004)
+///* Bike light on/off */
+//#define IO_BIKELIGHT_FRONT_ON (GPIO_OCTL(GPIOC) |= 0x8000)
+//#define IO_BIKELIGHT_FRONT_OFF (GPIO_OCTL(GPIOC) &= ~0x8000)
+//#define IO_BIKELIGHT_FRONT_12V_ENABLE (GPIO_OCTL(GPIOC) |= 0x2000)
+//#define IO_BIKELIGHT_FRONT_12V_DISABLE (GPIO_OCTL(GPIOC) &= ~0x2000)
+//#define IO_BIKELIGHT_REAR_ON (GPIO_OCTL(GPIOC) |= 0x0100)
+//#define IO_BIKELIGHT_REAR_OFF (GPIO_OCTL(GPIOC) &= ~0x0100)
+//#define IO_BIKELIGHT_REAR_12V_ENABLE (GPIO_OCTL(GPIOC) |= 0x0080)
+//#define IO_BIKELIGHT_REAR_12V_DISABLE (GPIO_OCTL(GPIOC) &= ~0x0080)
+///* Power lock on/off */
+//#define IO_POWERLOCK_ON (GPIO_OCTL(GPIOC) |= 0x0002)
+//#define IO_POWERLOCK_OFF (GPIO_OCTL(GPIOC) &= ~0x0002)
+//#define IO_POWER_STATE  (GPIO_ISTAT(GPIOC) & 0x0001)
 /* TIMER1 capture value */
 #define TIMER1_CAP_BIKESPD  TIMER_CH3CV(TIMER1)
 #define TIMER1_CAP_CANDANCE  TIMER_CH2CV(TIMER1)

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

@@ -21,6 +21,7 @@ Revising History (ECL of this file):
 #ifndef GLBCOF_H
 #define GLBCOF_H
 
+#include "typedefine.h"
 /************************************************************************
  Compiler Directives (N/A)
 *************************************************************************/

+ 41 - 31
User project/5.Api_rt/api_rt_gpio.c

@@ -2,9 +2,21 @@
 #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},
+    [0] = {.GpioBase = GPIOC, .Index = 0},
+    [1] = {.GpioBase = GPIOC, .Index = 1},
+    [2] = {.GpioBase = GPIOC, .Index = 7},
+    [3] = {.GpioBase = GPIOC, .Index = 8},
+    [4] = {.GpioBase = GPIOC, .Index = 15},
+    [5] = {.GpioBase = GPIOC, .Index = 13},
+    [6] = {.GpioBase = GPIOC, .Index = 14},
+    [7] = {.GpioBase = GPIOC, .Index = 10},
+    [8] = {.GpioBase = GPIOC, .Index = 11},
+    [9] = {.GpioBase = GPIOC, .Index = 2},
+    [10] = {.GpioBase = GPIOB, .Index = 9},
+    [11] = {.GpioBase = GPIOB, .Index = 8},
+    [12] = {.GpioBase = GPIOA, .Index = 12},
+    [13] = {.GpioBase = GPIOC, .Index = 12},
+    [14] = {.GpioBase = GPIOB, .Index = 2},
 };
 
 void iRtGpio_Init()
@@ -15,52 +27,50 @@ 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));
+         gpio_init(gpio->GpioBase, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, BIT(gpio->Index));
         break;
     case ApiGpio_Output:
-//        gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
-//        gpio->GpioBase->MODER |= (((uint32_t)0x00000001UL) << (2 * gpio->Index));
+         gpio_init(gpio->GpioBase, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, BIT(gpio->Index));
         break;
     case ApiGpio_AlternateFunction:
-//        gpio->GpioBase->MODER &= ~(((uint32_t)0x00000003UL) << (2 * gpio->Index));
-//        gpio->GpioBase->MODER |= (((uint32_t)0x00000002UL) << (2 * gpio->Index));
+         gpio_init(gpio->GpioBase, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, BIT(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;
-//    }
+    const Gpio_Handle *const gpio = &Gpios[pin];
+
+    iGpio_Level level = iGpio_LowLevel;
+
+    if ((uint32_t)RESET != (GPIO_ISTAT(gpio->GpioBase)&((uint32_t)((uint32_t)0x01U << gpio->Index))))
+    {
+        level = iGpio_HighLevel;
+    }
 
-//    return level;
+    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));
-//    }
+    const Gpio_Handle *const gpio = &Gpios[pin];
+
+    if (level == iGpio_HighLevel)
+    {
+      GPIO_OCTL(gpio->GpioBase) |= ((uint32_t)((uint32_t)0x01U << gpio->Index));
+    }
+    else
+    {
+      GPIO_OCTL(gpio->GpioBase) &= ~((uint32_t)((uint32_t)0x01U << gpio->Index));
+    }
 }

+ 1 - 1
User project/5.Api_rt/api_rt_gpio.h

@@ -8,7 +8,7 @@
 extern "C" {
 #endif // __cplusplus
 
-#define GPIO_PIN_COUNT 3
+#define GPIO_PIN_COUNT 15
 
 typedef struct
 {