Parcourir la source

feat:添加i2c抽象层,实验测试通过

CN\guohui27 il y a 2 ans
Parent
commit
edd8905fca

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

@@ -32,6 +32,7 @@
 #include "canAppl.h"
 #include "flash_master.h"
 #include "STLmain.h"
+//#include "api_rt.h"
 /************************************************************************
  Exported Functions:
 ************************************************************************/
@@ -51,6 +52,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 */

+ 2 - 0
User project/3.BasicFunction/Include/canAppl.h

@@ -16,7 +16,9 @@
 #define CANAPPL_H
 
 #include "typedefine.h"
+#ifndef RUN_ARCH_SIM
 #include "gd32f30x.h"
+#endif
 
 #ifdef __cplusplus
 extern "C" {

+ 2 - 0
User project/3.BasicFunction/Include/classB.h

@@ -20,6 +20,8 @@ WLBDM_M0_SR_20170814-new FSM1.1, by cyf, create this file;
 *************************************************************************/
 #ifndef CLASSB_H
 #define CLASSB_H
+
+#include "typedefine.h"
 /************************************************************************
  Compiler Directives (N/A)
 *************************************************************************/

+ 284 - 242
User project/3.BasicFunction/Source/i2c_master.c

@@ -26,7 +26,7 @@
 *************************************************************************/
 #include "i2c_master.h"
 #include "gd32f30x_dma.h"
-
+#include "api.h"
 /*************************************************************************
  Exported Functions (N/A)
 *************************************************************************/
@@ -562,7 +562,7 @@ static void i2c_voBufferWrite2EE(const UBYTE *pBuffer, UBYTE SlaveAddr, UBYTE Wr
     UBYTE ubNPages = 0, ubNSingleBytes = 0, ubAddr = 0, ubCnt = 0, ubTemp = 0;
     
     ubAddr = WriteAddr % I2C_EE_PAGESIZE_NBYTES;
-    ubCnt = I2C_EE_PAGESIZE_NBYTES - 1 - ubAddr; // Cnt datas away from page alignment
+    ubCnt = I2C_EE_PAGESIZE_NBYTES - ubAddr; // Cnt datas away from page alignment
     ubNPages = NBytesToWrite / I2C_EE_PAGESIZE_NBYTES;
     ubNSingleBytes = NBytesToWrite % I2C_EE_PAGESIZE_NBYTES;    
 
@@ -678,7 +678,8 @@ void i2c_voInfoWrite2EE(const I2C_TX_COF *coef, I2C_TX_OUT *out)
         {
             ubSlaveAddr = I2C_SLAVEADDR_BLOCK1;
         }
-        i2c_voBufferWrite2EE(I2C_pWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
+        //i2c_voBufferWrite2EE(I2C_pWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
+        iI2C_Write(0, ubSlaveAddr, ubWriteAddr, 8, I2C_pWriteBuffer, ubNBytes);
     }
 
     if ((ubReTX1 == 0) && (I2C_EE_ComuFltFlg != TRUE))
@@ -727,7 +728,9 @@ void i2c_voHistoryWrite2EE(const I2C_TX_COF *coef, I2C_TX_OUT *out)
         {
             ubSlaveAddr = I2C_SLAVEADDR_BLOCK3;
         }
-        i2c_voBufferWrite2EE(I2C_pHistoryWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
+        
+        //i2c_voBufferWrite2EE(I2C_pHistoryWriteBuffer, ubSlaveAddr, ubWriteAddr, ubNBytes);
+        iI2C_Write(0, ubSlaveAddr, ubWriteAddr, 8, I2C_pHistoryWriteBuffer, ubNBytes);
     }
     if ((ubReTX2 == 0) && (I2C_EE_ComuFltFlg != TRUE))
     {
@@ -796,263 +799,302 @@ void i2c_bus_reset(void)
  Subroutine Call:
  Reference:
 *************************************************************************/
-void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
-{
+//  void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
+//  {
   
-    UWORD timeout = 0;
-    UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
-    UBYTE state = (UBYTE)I2C_START;
-    UBYTE read_cycle = 0;
-    UBYTE ubRdCnt = 2;
+//      UWORD timeout = 0;
+//      UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
+//      UBYTE state = (UBYTE)I2C_START;
+//      UBYTE read_cycle = 0;
+//      UBYTE ubRdCnt = 2;
    
-    UBYTE i2c_timeout_flag = 0;
-    UBYTE *p_buffer;
+//      UBYTE i2c_timeout_flag = 0;
+//      UBYTE *p_buffer;
     
-     while(ubRdCnt != 0)
-     {
-    	 ubRdCnt--;
+//       while(ubRdCnt != 0)
+//       {
+//      	 ubRdCnt--;
 
-        if (ubRdCnt == 1)
-        {
-            ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
-            ubRdAddr = 0x00;
-            ubRdNBytes = I2C_RX1_NBYTES;           
-            p_buffer = I2C_ubReadBuffer[0];
-            i2c_timeout_flag = 0;
-        }
-        else if (ubRdCnt == 0)
-        {
-            ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
-            ubRdAddr = 0x00;
-            ubRdNBytes = I2C_RX2_NBYTES;
-            p_buffer = I2C_ubReadBuffer[1];
-            i2c_timeout_flag = 0;
-        }
-        else
-        {
-        	//do nothing
-        }
+//          if (ubRdCnt == 1)
+//          {
+//              ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
+//              ubRdAddr = 0x00;
+//              ubRdNBytes = I2C_RX1_NBYTES;           
+//              p_buffer = I2C_ubReadBuffer[0];
+//              i2c_timeout_flag = 0;
+//          }
+//          else if (ubRdCnt == 0)
+//          {
+//              ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
+//              ubRdAddr = 0x00;
+//              ubRdNBytes = I2C_RX2_NBYTES;
+//              p_buffer = I2C_ubReadBuffer[1];
+//              i2c_timeout_flag = 0;
+//          }
+//          else
+//          {
+//          	//do nothing
+//          }
         
-        /* enable acknowledge */
-        i2c_ack_config(I2C0, I2C_ACK_ENABLE);
+//          /* enable acknowledge */
+//          i2c_ack_config(I2C0, I2C_ACK_ENABLE);
         
-        while(i2c_timeout_flag ==0)
-        {
-            switch(state) 
-            {
-            case I2C_START:
-                if(RESET == read_cycle) 
-                {
-                    /* disable I2C0 */
-                    i2c_disable(I2C0);
-                    /* enable I2C0 */
-                    i2c_enable(I2C0);
-                    /* enable acknowledge */
-                    i2c_ack_config(I2C0, I2C_ACK_ENABLE);
-                    /* i2c master sends start signal only when the bus is idle */
-                    while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (timeout < I2C_SHORT_TIMEOUT))
-                    {
-                        timeout++;
-                    }
+//          while(i2c_timeout_flag ==0)
+//          {
+//              switch(state) 
+//              {
+//              case I2C_START:
+//                  if(RESET == read_cycle) 
+//                  {
+//                      /* disable I2C0 */
+//                      i2c_disable(I2C0);
+//                      /* enable I2C0 */
+//                      i2c_enable(I2C0);
+//                      /* enable acknowledge */
+//                      i2c_ack_config(I2C0, I2C_ACK_ENABLE);
+//                      /* i2c master sends start signal only when the bus is idle */
+//                      while((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) != 0) && (timeout < I2C_SHORT_TIMEOUT))
+//                      {
+//                          timeout++;
+//                      }
                     
-                    if(timeout < I2C_SHORT_TIMEOUT) 
-                    {
-                        /* send the start signal */
-                        i2c_start_on_bus(I2C0);
-                        timeout = 0;
-                        state = (UBYTE)I2C_SEND_ADDRESS;
-                    } 
-                    else 
-                    {
-                        i2c_bus_reset();
-                        timeout = 0;
-                        state = (UBYTE)I2C_START;
-                    }
-                } 
-                else 
-                {
-                    i2c_start_on_bus(I2C0);
-                    timeout = 0;
-                    state = (UBYTE)I2C_SEND_ADDRESS;
-                }
-                break;
-            case I2C_SEND_ADDRESS:
-                /* i2c master sends START signal successfully */
-                while((i2c_flag_get(I2C0, I2C_FLAG_SBSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
-                {
-                    timeout++;
-                }
-                if(timeout < I2C_SHORT_TIMEOUT) 
-                {
-                    if(RESET == read_cycle) 
-                    {
-                        i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_TRANSMITTER);
-                        state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
-                    } 
-                    else 
-                    {
-                        i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_RECEIVER);
-                        state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
-                    }
-                    timeout = 0;
-                } 
-                else 
-                {
-                    timeout = 0;
-                    state = (UBYTE)I2C_START;
-                    read_cycle = 0;
-                }
-                break;
-            case I2C_CLEAR_ADDRESS_FLAG:
-                /* address flag set means i2c slave sends ACK */
-                while((i2c_flag_get(I2C0, I2C_FLAG_ADDSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
-                {
-                    timeout++;
-                }
-                if(timeout < I2C_SHORT_TIMEOUT) 
-                {
-                    i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
-                    timeout = 0;
-                    state = (UBYTE)I2C_TRANSMIT_DATA;
-                } 
-                else 
-                {
-                    timeout = 0;
-                    state = (UBYTE)I2C_START;
-                    read_cycle = 0;   
-                }
-                break;
-            case I2C_TRANSMIT_DATA:
-                if(RESET == read_cycle) 
-                {
-                    /* wait until the transmit data buffer is empty */
-                    while((i2c_flag_get(I2C0, I2C_FLAG_TBE) == 0) && (timeout < I2C_SHORT_TIMEOUT))
-                    {
-                        timeout++;
-                    }
-                    if(timeout < I2C_SHORT_TIMEOUT) 
-                    {
-                        /* send the EEPROM's internal address to write to : only one byte address */
-                        i2c_data_transmit(I2C0, ubRdAddr);
-                        timeout = 0;
-                    } 
-                    else 
-                    {
-                        timeout = 0;
-                        state = (UBYTE)I2C_START;
-                        read_cycle = 0;    
-                    }
-                    /* wait until BTC bit is set */
-                    while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
-                    {
-                        timeout++;
-                    }
-                    if(timeout < I2C_SHORT_TIMEOUT) 
-                    {
-                        timeout = 0;
-                        state = (UBYTE)I2C_START;
-                        read_cycle++;
-                    }
-                    else 
-                    {
-                        timeout = 0;
-                        state = (UBYTE)I2C_START;
-                        read_cycle = 0;
-                    }
-                } 
-                else 
-                {
-                    /* one byte master reception procedure (polling) */
-                    if(ubRdNBytes < 2) 
-                    {
-                        /* disable acknowledge */
-                        i2c_ack_config(I2C0, I2C_ACK_DISABLE);
-                        /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register (I2C_STAT0 has already been read) */
-                        i2c_flag_get(I2C0, I2C_FLAG_ADDSEND);
-                        /* send a stop condition to I2C bus*/
-                        i2c_stop_on_bus(I2C0);
-                        /* wait for the byte to be received */
-                        while(i2c_flag_get(I2C0, I2C_FLAG_RBNE) == 0)
-                        {
-                        	// do nothing
-                        }
-                        /* read the byte received from the EEPROM */
-                        *p_buffer = i2c_data_receive(I2C0);
-                        /* decrement the read bytes counter */
-                        ubRdNBytes--;
-                        timeout = 0;
-                        state = (UBYTE)I2C_STOP;
-                    } 
-                    else 
-                    {  /* more than one byte master reception procedure (DMA) */                   
+//                      if(timeout < I2C_SHORT_TIMEOUT) 
+//                      {
+//                          /* send the start signal */
+//                          i2c_start_on_bus(I2C0);
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_SEND_ADDRESS;
+//                      } 
+//                      else 
+//                      {
+//                          i2c_bus_reset();
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_START;
+//                      }
+//                  } 
+//                  else 
+//                  {
+//                      i2c_start_on_bus(I2C0);
+//                      timeout = 0;
+//                      state = (UBYTE)I2C_SEND_ADDRESS;
+//                  }
+//                  break;
+//              case I2C_SEND_ADDRESS:
+//                  /* i2c master sends START signal successfully */
+//                  while((i2c_flag_get(I2C0, I2C_FLAG_SBSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
+//                  {
+//                      timeout++;
+//                  }
+//                  if(timeout < I2C_SHORT_TIMEOUT) 
+//                  {
+//                      if(RESET == read_cycle) 
+//                      {
+//                          i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_TRANSMITTER);
+//                          state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
+//                      } 
+//                      else 
+//                      {
+//                          i2c_master_addressing(I2C0, ubRdSlaveAddr, I2C_RECEIVER);
+//                          state = (UBYTE)I2C_CLEAR_ADDRESS_FLAG;
+//                      }
+//                      timeout = 0;
+//                  } 
+//                  else 
+//                  {
+//                      timeout = 0;
+//                      state = (UBYTE)I2C_START;
+//                      read_cycle = 0;
+//                  }
+//                  break;
+//              case I2C_CLEAR_ADDRESS_FLAG:
+//                  /* address flag set means i2c slave sends ACK */
+//                  while((i2c_flag_get(I2C0, I2C_FLAG_ADDSEND) == 0) && (timeout < I2C_SHORT_TIMEOUT))
+//                  {
+//                      timeout++;
+//                  }
+//                  if(timeout < I2C_SHORT_TIMEOUT) 
+//                  {
+//                      i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
+//                      timeout = 0;
+//                      state = (UBYTE)I2C_TRANSMIT_DATA;
+//                  } 
+//                  else 
+//                  {
+//                      timeout = 0;
+//                      state = (UBYTE)I2C_START;
+//                      read_cycle = 0;   
+//                  }
+//                  break;
+//              case I2C_TRANSMIT_DATA:
+//                  if(RESET == read_cycle) 
+//                  {
+//                      /* wait until the transmit data buffer is empty */
+//                      while((i2c_flag_get(I2C0, I2C_FLAG_TBE) == 0) && (timeout < I2C_SHORT_TIMEOUT))
+//                      {
+//                          timeout++;
+//                      }
+//                      if(timeout < I2C_SHORT_TIMEOUT) 
+//                      {
+//                          /* send the EEPROM's internal address to write to : only one byte address */
+//                          i2c_data_transmit(I2C0, ubRdAddr);
+//                          timeout = 0;
+//                      } 
+//                      else 
+//                      {
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_START;
+//                          read_cycle = 0;    
+//                      }
+//                      /* wait until BTC bit is set */
+//                      while((i2c_flag_get(I2C0, I2C_FLAG_BTC) == 0) && (timeout < I2C_SHORT_TIMEOUT))
+//                      {
+//                          timeout++;
+//                      }
+//                      if(timeout < I2C_SHORT_TIMEOUT) 
+//                      {
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_START;
+//                          read_cycle++;
+//                      }
+//                      else 
+//                      {
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_START;
+//                          read_cycle = 0;
+//                      }
+//                  } 
+//                  else 
+//                  {
+//                      /* one byte master reception procedure (polling) */
+//                      if(ubRdNBytes < 2) 
+//                      {
+//                          /* disable acknowledge */
+//                          i2c_ack_config(I2C0, I2C_ACK_DISABLE);
+//                          /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register (I2C_STAT0 has already been read) */
+//                          i2c_flag_get(I2C0, I2C_FLAG_ADDSEND);
+//                          /* send a stop condition to I2C bus*/
+//                          i2c_stop_on_bus(I2C0);
+//                          /* wait for the byte to be received */
+//                          while(i2c_flag_get(I2C0, I2C_FLAG_RBNE) == 0)
+//                          {
+//                          	// do nothing
+//                          }
+//                          /* read the byte received from the EEPROM */
+//                          *p_buffer = i2c_data_receive(I2C0);
+//                          /* decrement the read bytes counter */
+//                          ubRdNBytes--;
+//                          timeout = 0;
+//                          state = (UBYTE)I2C_STOP;
+//                      } 
+//                      else 
+//                      {  /* more than one byte master reception procedure (DMA) */                   
                       
-                        dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);        
-                        DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
+//                          dma_transfer_number_config(DMA0, DMA_CH6, ubRdNBytes);        
+//                          DMA_CH6MADDR(DMA0) = (ULONG)p_buffer;
                       
-                        i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
-                        /* enable I2C0 DMA */
-                        i2c_dma_config(I2C0, I2C_DMA_ON);
-                        /* enable DMA0 channel5 */
-                        dma_channel_enable(DMA0, DMA_CH6);
-                        /* wait until BTC bit is set */
-                        while(dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF) == 0)
-                        {
-                        	// do nothing
-                        }
-
-                        state = (UBYTE)I2C_STOP;
-                    }
-                }
-                break;
-            case I2C_STOP:
-                /* send a stop condition to I2C bus */
-                i2c_stop_on_bus(I2C0);
-                /* i2c master sends STOP signal successfully */
-                while((I2C_CTL0(I2C0) & I2C_CTL0_STOP) && (timeout < I2C_SHORT_TIMEOUT)) 
-                {
-                    timeout++;
-                }
-
-                if(timeout < I2C_SHORT_TIMEOUT)
-                {
-                    timeout = 0;                 
-                    i2c_timeout_flag = 1;
-                    state = (UBYTE)I2C_START;
-                    read_cycle = 0;
+//                          i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON);
+//                          /* enable I2C0 DMA */
+//                          i2c_dma_config(I2C0, I2C_DMA_ON);
+//                          /* enable DMA0 channel5 */
+//                          dma_channel_enable(DMA0, DMA_CH6);
+//                          /* wait until BTC bit is set */
+//                          while(dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF) == 0)
+//                          {
+//                          	// do nothing
+//                          }
+
+//                          state = (UBYTE)I2C_STOP;
+//                      }
+//                  }
+//                  break;
+//              case I2C_STOP:
+//                  /* send a stop condition to I2C bus */
+//                  i2c_stop_on_bus(I2C0);
+//                  /* i2c master sends STOP signal successfully */
+//                  while((I2C_CTL0(I2C0) & I2C_CTL0_STOP) && (timeout < I2C_SHORT_TIMEOUT)) 
+//                  {
+//                      timeout++;
+//                  }
+
+//                  if(timeout < I2C_SHORT_TIMEOUT)
+//                  {
+//                      timeout = 0;                 
+//                      i2c_timeout_flag = 1;
+//                      state = (UBYTE)I2C_START;
+//                      read_cycle = 0;
                    
-                    /* disable DMA0 CH6 */
-                    dma_channel_disable(DMA0, DMA_CH6);
-                    /* disable I2C0 DMA */
-                    i2c_dma_config(I2C0, I2C_DMA_OFF); 
-                    i2c_dma_last_transfer_config(I2C0, I2C_DMALST_OFF);
-                } 
-                else 
-                {
-                     timeout = 0;
-                    //state = I2C_START;
-                     state = (UBYTE)I2C_STOP;
-                     read_cycle = 0;
-                }
+//                      /* disable DMA0 CH6 */
+//                      dma_channel_disable(DMA0, DMA_CH6);
+//                      /* disable I2C0 DMA */
+//                      i2c_dma_config(I2C0, I2C_DMA_OFF); 
+//                      i2c_dma_last_transfer_config(I2C0, I2C_DMALST_OFF);
+//                  } 
+//                  else 
+//                  {
+//                       timeout = 0;
+//                      //state = I2C_START;
+//                       state = (UBYTE)I2C_STOP;
+//                       read_cycle = 0;
+//                  }
                                               
-                break;
-            default:
-                state = (UBYTE)I2C_START;
-                read_cycle = 0;
-                i2c_timeout_flag = 1;
-                timeout = 0;
+//                  break;
+//              default:
+//                  state = (UBYTE)I2C_START;
+//                  read_cycle = 0;
+//                  i2c_timeout_flag = 1;
+//                  timeout = 0;
                 
-                break;
-            }
-        }
+//                  break;
+//              }
+//          }
         
-     }
+//       }
     
+//      i2c_voReadBufferCRC(out);
+
+//      i2c_voGetValueFrmBuffer(out);
+
+//      out->ReadFinishFlg = TRUE;
+    
+//  }
+
+void i2c_voSysparaReadFromEE(I2C_RXCRC_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
+{
+   UBYTE ubRdNBytes = 0, ubRdSlaveAddr = 0, ubRdAddr = 0;
+   UBYTE ubRdCnt = 2;
+   UBYTE *p_buffer;
+   
+    while(ubRdCnt != 0)
+    {
+   	 ubRdCnt--;
+
+       if (ubRdCnt == 1)
+       {
+           ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK1;
+           ubRdAddr = 0x00;
+           ubRdNBytes = I2C_RX1_NBYTES;           
+           p_buffer = I2C_ubReadBuffer[0];
+       }
+       else if (ubRdCnt == 0)
+       {
+           ubRdSlaveAddr = I2C_SLAVEADDR_BLOCK3;
+           ubRdAddr = 0x00;
+           ubRdNBytes = I2C_RX2_NBYTES;
+           p_buffer = I2C_ubReadBuffer[1];
+       }
+       else
+       {
+       	//do nothing
+       }
+
+       iI2C_Read(0, ubRdSlaveAddr, ubRdAddr, 8, p_buffer, ubRdNBytes);
+   }
+
     i2c_voReadBufferCRC(out);
 
     i2c_voGetValueFrmBuffer(out);
 
     out->ReadFinishFlg = TRUE;
-    
 }
 /*************************************************************************
  Function:

+ 26 - 0
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/api_board_support.h

@@ -0,0 +1,26 @@
+/**
+ * @file api_board_support.h
+ * @author Xiao Lifan (xiaolf6@midea.com)
+ * @brief
+ * @version 0.1
+ * @date 2022-05-10
+ *
+ * @copyright Copyright (c) 2022
+ *
+ * @details 控制器硬件定义文件,用于表明控制器硬件实际支持的硬件抽象
+ *
+ */
+
+#define API_SUPPORT   1
+#define API_NOSUPPORT 0
+
+#define API_FUNCTION_PWM_MULTI_COMPARE_VALUE    API_SUPPORT
+#define API_FUNCTION_PWM_COUNTDOWN              API_SUPPORT
+#define API_FUNCTION_PWM_CHANNEL_OUTPUT_CONTROL API_SUPPORT
+#define API_FUNCTION_PWM_COMPARE_TRIGGER        API_SUPPORT
+#define API_FUNCTION_PWM_FORCE_OUTPUT           API_SUPPORT
+#define API_FUNCTION_PWM_SYNC_MULTI_SAMPLING    API_SUPPORT
+
+#define API_FUNCTION_ADC_HARDWARE_TRIGGER API_SUPPORT
+
+#define API_FUNCTION_UART_ASYNC API_SUPPORT

+ 16 - 0
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/api_config.h

@@ -0,0 +1,16 @@
+/**
+ * @file api_config.h
+ * @author Xiao Lifan (xiaolf6@midea.com)
+ * @brief
+ * @version 0.1
+ * @date 2022-05-18
+ *
+ * @copyright Copyright (c) 2022
+ *
+ */
+
+#define SCHEDULER_TIMEBASE1MS   0
+#define SCHEDULER_TIMEBASE100US 1
+#define SCHEDULER_TIMEBASE10MS  2
+
+#define SCHEDULER_TIMEBASE SCHEDULER_TIMEBASE1MS

+ 0 - 68
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/app_tasks.h

@@ -1,68 +0,0 @@
-/**
- * @file tasks.h
- * @author Xiao, Lifan (xiaolf6@midea.com)
- * @brief
- * @version 0.1
- * @date 2021-08-06
- *
- * @copyright Copyright (c) 2021
- *
- */
-
-#ifndef _TASKS_H_
-#define _TASKS_H_
-
-/****************************************************************
- *
- *                     Standard Interface
- *
- * *************************************************************/
-
-/* Driver Layer Interface */
-/* The following function will be called by platfrom layer */
-
-/**
- * @brief Init pwm task
- *
- */
-void App_Task_InitTaskPwm();
-
-/**
- * @brief Pwm task called in pwm isr
- *
- */
-void App_Task_TaskPwm();
-
-/**
- * @brief Init adc task
- *
- */
-void App_Task_InitTaskAdcCplt();
-
-/**
- * @brief Adc task called in adc complete isr
- *
- */
-void App_Task_TaskAdcCplt();
-
-/**
- * @brief Init task 1
- *
- */
-void App_Task_InitTask1();
-
-/**
- * @brief Task 1 called by period timer
- *
- */
-void App_Task_Task1();
-
-void App_Task_InitTask2();
-
-void App_Task_Task2();
-
-void App_Task_InitTaskBg();
-
-void App_Task_TaskBg();
-
-#endif

+ 131 - 0
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/board_config.h

@@ -0,0 +1,131 @@
+/**
+ * @file board_config.h
+ * @author Xiao Lifan (xiaolf6@midea.com)
+ * @brief 硬件相关参数配置
+ * @version 0.1
+ * @date 2023-05-06
+ *
+ * @copyright Copyright (c) 2023
+ *
+ */
+
+/* ========================================================================== */
+/* ================================= 采样范围配置 ================================= */
+/* ========================================================================== */
+
+#define HW_VBUS_MEASMAX_V   6419 /**< Vdc measure max 424.6(0.1V) */
+#define HW_VAC_MEASMAX_V    4950 /**< Vac measure max 495.0(0.1V) */
+#define HW_VPHASE_MEASMAX_V 4290 /**< Terminal Voltage measure max 429.0(0.1V) */
+#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 72000000UL
+
+/* --------------------------------- 电力系统参数 --------------------------------- */
+
+#define HW_UAC_FREQ_HZ 50
+
+/* --------------------------------- PWM频率配置 -------------------------------- */
+
+#define HW_TIM_CLOCK_HZ  72000000UL
+#define HW_TIM_CLOCK_MHZ (HW_TIM_CLOCK_HZ / 1000000UL)
+
+#define HW_INIT_FPWM_HZ   16000
+#define HW_INIT_FTBC_TICK 2
+#define HW_INIT_FTBS_TICK 4
+#define HW_INIT_FTBC_HZ   (HW_INIT_FPWM_HZ / HW_INIT_FTBC_TICK)
+#define HW_INIT_FTBS_HZ   (HW_INIT_FPWM_HZ / HW_INIT_FTBS_TICK)
+
+#define HW_INIT_PWM_PERIOD    (HW_TIM_CLOCK_HZ / HW_INIT_FPWM_HZ)
+#define HW_INIT_HPWM_PERIOD   (HW_INIT_PWM_PERIOD >> 1)
+#define HW_INIT_HHPWM_PERIOD  (HW_INIT_PWM_PERIOD >> 2)
+#define HW_INIT_HHHPWM_PERIOD (HW_INIT_PWM_PERIOD >> 3)
+
+/* --------------------------------- PWM死区参数 -------------------------------- */
+
+#define HW_DEADBAND_TIME HW_TIM_CLOCK_MHZ /**< 死区时间,单位: 时钟Tick */
+
+/* ---------------------------------- adc参数 --------------------------------- */
+
+#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_RLYON_OVER_MS 200
+
+/* ---------------------------------- 输入捕获 ---------------------------------- */
+
+#define HW_PWM_CAP_HZ 1600000L
+
+/* ---------------------------------- EEPROM参数 ---------------------------------- */
+
+#define HW_I2C_EE_PAGESIZE_BYTE 16
+#define HW_I2C_EE_ADDR_BLOCK1   0xA0
+#define HW_I2C_EE_ADDR_BLOCK2   0xA2
+#define HW_I2C_EE_ADDR_BLOCK3   0xA4
+#define HW_I2C_EE_ADDR_BLOCK4   0xA6
+
+
+
+/* ========================================================================== */
+/* ================================ API接口序号定义 =============================== */
+/* ========================================================================== */
+#define HW_PWMCNT_TIMER                 0
+#define HW_TBS_TIMER                    1
+#define HW_EVENT1MS_TIMER               2
+#define HW_SYSTICK_TIMER                3
+
+#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
+#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
+  
+/* 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
+
+/* TIMER */
+#define HW_TIMER_CANDANCE_PIN             0  ///> TIMER1  CH2
+#define HW_TIMER_BIKESPD_PIN              1  ///> TIMER1  CH3
+/* Api Device Index Definations */

+ 0 - 84
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/hal_adc.h

@@ -1,84 +0,0 @@
-/**
- * @file hal_adc.h
- * @author Xiao, Lifan (xiaolf6@midea.com)
- * @brief
- * @version 0.1
- * @date 2021-08-09
- *
- * @copyright Copyright (c) 2021
- *
- */
-
-#ifndef _HAL_ADC_H_
-#define _HAL_ADC_H_
-
-#include "hal_config.h"
-
-/****************************************************************
- *
- *                     Standard Interface
- *
- * *************************************************************/
-
-/******************************/
-/* Global Interface Variables */
-/******************************/
-
-/* !!!Important!!! */
-/* Interface Variable Should Not Be Modified By Application */
-
-/**
- * @brief The raw sampling results
- *
- */
-extern uint16_t *Hal_Adc_RawResults;
-
-/**
- * @brief The scaled sampling results, calculated by y=a(x+b)
- *
- */
-extern int32_t *Hal_Adc_ScaledResults;
-
-/*************************/
-/* Global Interface Hook */
-/*************************/
-
-/**
- * @brief Function hook called at the end of the sampling
- *
- */
-extern void (*Hal_Adc_SamplingCompleteHook)();
-
-/**************************************/
-/* Platform Layer Interface Functions */
-/**************************************/
-
-/**
- * @brief Init adc module
- *
- */
-void Hal_Adc_Init();
-
-/**
- * @brief Read sampling results from the adc peripheral
- *
- */
-void Hal_Adc_Read();
-
-/**
- * @brief Set the scale of the specified channel
- *
- * @param scale in format q17.15
- * @param channel channel index
- */
-void Hal_Adc_SetScale(int32_t scale, uint8_t channel);
-
-/**
- * @brief Set the offset of the specified channel
- *
- * @param offset in range 0...4096
- * @param channel channel index
- */
-void Hal_Adc_SetOffset(int16_t offset, uint8_t channel);
-
-#endif

+ 0 - 65
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/hal_dio.h

@@ -1,65 +0,0 @@
-/**
- * @file hal_dio.h
- * @author Wang, Tong (wangtong7@midea.com)
- * @brief
- * @version 0.1
- * @date 2021-10-10
- *
- * @copyright Copyright (c) 2021
- *
- */
-
-#ifndef _HAL_DIO_H_
-#define _HAL_DIO_H_
-
-#include "hal_config.h"
-
-/****************************************************************
- *
- *                     Standard Interface
- *
- * *************************************************************/
-
-/********************/
-/* Type definations */
-/********************/
-
-#define DIO_LEVEL_HIGH 1
-#define DIO_LEVEL_LOW  0
-
-/******************************/
-/* Global Interface Variables */
-/******************************/
-
-/* !!!Important!!! */
-/* Interface Variable Should Not Be Modified By Application */
-
-/**
- * @brief Activate pin (with pre-defined active level)
- *
- * @param index Pin number defined in hal_config.h
- */
-void Hal_Dio_ActivatePin(uint8_t index);
-
-/**
- * @brief Deactivate Pin (with pre-defined active level)
- *
- * @param index Pin number defined in hal_config.h
- */
-void Hal_Dio_DeactivatePin(uint8_t index);
-
-/**
- * @brief Set pin level
- *
- * @param index Pin index
- * @param level Pin level
- */
-void Hal_Dio_SetPinLevel(uint8_t index, uint8_t level);
-
-/**
- * @brief Init Dio module
- *
- */
-void Hal_Dio_Init();
-
-#endif

+ 0 - 108
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/hal_harderr.h

@@ -1,108 +0,0 @@
-/**
- * @file hal_harderr.h
- * @author Xiao Lifan (xiaolf6@midea.com)
- * @brief
- * @version 0.1
- * @date 2021-09-26
- *
- * @copyright Copyright (c) 2021
- *
- * @details The interface of system hard error detect and handling
- *
- */
-
-#ifndef _HAL_HARDERR_H_
-#define _HAL_HARDERR_H_
-
-#include "hal_config.h"
-
-/****************************************************************
- *
- *                     Standard Interface
- *
- * *************************************************************/
-
-/********************/
-/* Type definations */
-/********************/
-
-// typedef union
-// {
-//     uint32_t all;
-//     struct bit
-//     {
-//         uint32_t bit0:1;
-//         uint32_t bit0:1;
-//     };
-
-// } Hal_Harderr_FlagType;
-
-/******************************/
-/* Global Interface Variables */
-/******************************/
-
-/* !!!Important!!! */
-/* Interface Variable Should Not Be Modified By Application */
-
-/**
- * @brief The flag of triggered hardware error
- *
- */
-extern uint32_t Hal_HardErr_Flags;
-
-/*************************/
-/* Global Interface Hook */
-/*************************/
-
-/**
- * @brief Function called when hardware error are triggered
- *
- */
-extern void (*Hal_HardErr_TriggerHook)();
-
-/**
- * @brief Function called when hardware error are cleared
- *
- * @note The clear of the hardware err may lag
- *
- */
-extern void (*Hal_HardErr_ClearHook)();
-
-/*****************************************/
-/* Application Layer Interface Functions */
-/*****************************************/
-
-/**
- * @brief Get specified bit of hardware error flags
- *
- * @param bit bit index
- * @return uint8_t error status 0 - no error, 1 - error occurs
- */
-uint8_t Hal_HardErr_GetFlagStatus(uint8_t bit);
-
-/**
- * @brief Try clear hardware error
- *
- * @return uint8_t result of clear action 0 - success, 1 - falied
- */
-uint8_t Hal_HardErr_TryClearHardErr();
-
-/**************************************/
-/* Platform Layer Interface Functions */
-/**************************************/
-
-/**
- * @brief Init hardware error detection
- *
- */
-void Hal_HardErr_Init();
-
-/**
- * @brief Set the specified bit of hardware error flag
- *
- * @param bit bit index
- * @param state flag state
- */
-void Hal_HardErr_SetFlagStatus(uint8_t bit, uint8_t state);
-
-#endif

+ 0 - 296
User project/4.BasicHardwSoftwLayer/1.BasicHardwLayer/Include/hal_pwm.h

@@ -1,296 +0,0 @@
-/**
- * @file hal_pwm.h
- * @author Xiao, Lifan (xiaolf6@midea.com)
- * @brief
- * @version 0.1
- * @date 2021-08-09
- *
- * @copyright Copyright (c) 2021
- *
- * @details The interface of PWM module
- *
- */
-
-#ifndef _HAL_PWM_H_
-#define _HAL_PWM_H_
-
-#include "hal_config.h"
-
-/****************************************************************
- *
- *                     Standard Interface
- *
- * *************************************************************/
-
-/********************/
-/* Type definations */
-/********************/
-
-/**
- * @brief The PWM wave type
- * @note Four type of PWM wave is supported, as
- *
- * RightAligned:
- *       ┌──────
- *       │
- *       │
- * ──────┘
- *
- * LeftAligned:
- * ──────┐
- *       │
- *       │
- *       └──────
- *
- * CenterAligned:
- *     ┌───┐
- *     │   │
- *     │   │
- * ────┘   └────
- *
- * CenterAlignedInverse:
- * ────┐   ┌────
- *     │   │
- *     │   │
- *     └───┘
- *
- */
-
-typedef enum
-{
-    RightAligned,
-    LeftAligned,
-    CenterAligned,
-    CenterAlignedInverse,
-    EdgeAlignedAutoReverse,
-#if HAL_PWM_SUPPORT_CUSTOM_VECTOR_TYPE
-    Custom,
-#endif
-} Hal_Pwm_WaveModeEnum;
-
-typedef enum
-{
-    VectorTypeUp,
-    VectorTypeDown,
-    VectorTypeUpDown,
-    VectorTypeDownUp,
-} Hal_Pwm_VectorType;
-
-/******************************/
-/* Global Interface Variables */
-/******************************/
-
-/* !!!Important!!! */
-/* Interface Variable Should Not Be Modified By Application */
-
-/**
- * @brief The clock of the pwm module (in unit Hz)
- *
- */
-extern uint32_t Hal_Pwm_Clock;
-
-/**
- * @brief The period of the pwm module (in unit Ticks)
- *
- */
-extern uint32_t Hal_Pwm_PeriodTicks;
-
-/**
- * @brief The period of the pwm module (in unit us)
- *
- */
-extern uint32_t Hal_Pwm_PeriodUs;
-
-/**
- * @brief Avaliable pwm channel number
- *
- */
-extern const uint32_t Hal_Pwm_ChannelNum;
-
-/**
- * @brief Actual phase duty cycle (in unit ticks)
- *
- */
-extern uint32_t *Hal_Pwm_ActualDutyCycleTicks;
-
-/**
- * @brief Drive pwm output status
- *
- */
-extern int8_t Hal_Pwm_DriveOutputEnable;
-
-/*************************/
-/* Global Interface Hook */
-/*************************/
-
-/**
- * @brief Function hook called at Zero Interrupt
- *
- */
-extern void (*Hal_Pwm_ZeroIsrHook)();
-
-/**
- * @brief Function hook called at Period Interrupt
- *
- */
-extern void (*Hal_Pwm_PeriodIsrHook)();
-
-/*****************************************/
-/* Application Layer Interface Functions */
-/*****************************************/
-
-/**
- * @brief Set the duty cycle for all channel (in q15 format)
- *
- * @param da Pointer to the list of duty cycles
- * @param channels The number of channel to set duty cycle
- *
- * @note If current PWM mode is EdgeAlignedAutoReverse, the modulation mode will reverse after calling this function
- */
-void Hal_Pwm_SetDutyCycle(int32_t *da, int8_t channels);
-
-/**
- * @brief Set the duty cycle for specified channel (in q15 format)
- *
- * @param duty duty cycle
- * @param chindex The index of channel to set duty cycle
- *
- * @note Calling this function will not affect PWM mode
- */
-void Hal_Pwm_SetChannelDutyCycle(int32_t duty, int8_t chindex);
-
-/**
- * @brief Set the pwm period (in ticks)
- *
- * @param ticks Pwm period
- */
-void Hal_Pwm_SetPeriod(int32_t ticks);
-
-/**
- * @brief Set the Wave Mode
- *
- * @param mode Target mode
- */
-void Hal_Pwm_SetWaveMode(Hal_Pwm_WaveModeEnum mode);
-
-/**
- * @brief Set the pwm output deadband
- *
- * @param ticks Deadband length
- */
-void Hal_Pwm_SetDeadband(int32_t ticks);
-
-/**
- * @brief Enable drive pwm immediately
- *
- */
-void Hal_Pwm_EnableDriveOutput();
-
-/**
- * @brief Disable drive pwm output immediately
- *
- */
-void Hal_Pwm_DisableDriveOutput();
-
-/**
- * @brief Enable channel pwm immediately
- *
- * @param ch_index Channel index
- */
-void Hal_Pwm_EnableChannelOutput(uint8_t ch_index);
-
-/**
- * @brief Disable channel pwm immediately
- *
- * @param ch_index Channel index
- */
-void Hal_Pwm_DisableChannelOutput(uint8_t ch_index);
-
-/**
- * @brief Enable standard hooks, function address for enable, 0 for disable
- *
- * @param zeroHook Zero interrupt hook address
- * @param prdHook Period interrupt hook address
- */
-void Hal_Pwm_EnableStdHooks(void *zeroHook, void *prdHook);
-
-/**************************************/
-/* Platform Layer Interface Functions */
-/**************************************/
-
-/**
- * @brief Init pwm module
- *
- */
-void Hal_Pwm_Init();
-
-#if HAL_PWM_SUPPORT_CUSTOM_VECTOR_TYPE
-
-/****************************************************************
- *
- *                    Extended Interface
- *            Support Custom Modulation Like TSPWM
- *         Different Vector Type On Different Channel
- *
- * *************************************************************/
-
-void Hal_Pwm_Ext_SetCustomVectorType(Hal_Pwm_VectorType *type, uint8_t channels);
-
-#endif
-
-#if HAL_PWM_SUPPORT_SINGLE_RESISTOR_SAMPLING
-
-/****************************************************************
- *
- *                    Extended Interface
- *              Support Single Resistor Sampling
- *
- * *************************************************************/
-
-/*************************/
-/* Global Interface Hook */
-/*************************/
-
-/**
- * @brief Function hook for pwm sampling trigger
- *
- */
-void (*Hal_Pwm_Ext_SamplingTriggerHook)();
-
-/*****************************************/
-/* Application Layer Interface Functions */
-/*****************************************/
-
-/**
- * @brief Set the duty cycle of the extra channel, affect the
- * sampling trigger moment
- *
- * @param dutycycle Duty cycle in q15 format
- */
-void Hal_Pwm_Ext_SetSamplingDutyCycle(uint32_t dutycycle);
-
-/**************************************/
-/* Platform Layer Interface Functions */
-/**************************************/
-
-/**
- * @brief Extra init process to support single resistor sampling
- * @note
- * An extra channel will be used to trigger sampling at attribute time.
- * The counter of extra channel always runs counting up mode for
- * controlling the sampling trigger time
- *
- */
-void Hal_Pwm_Ext_Init();
-
-#endif
-
-#if HAL_PWM_SUPPORT_COMPLEMENTARY_PULSE_GENERATION
-
-#endif
-
-#if HAL_PWM_SUPPORT_HALF_PULSE_GENERATION
-
-#endif
-
-#endif

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

@@ -21,7 +21,9 @@
 #ifndef HWSETUP_H
 #define HWSETUP_H
 
+#ifndef RUN_ARCH_SIM
 #include "gd32f30x_libopt.h"
+#endif
 #include "STLmain.h"
 #include "syspar.h"
 

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

@@ -7,4 +7,6 @@ void iRt_Init()
 //    iRtUart_Init();
     iRtPwm_Init();
     iRtAdc_Init();
+    
+    iRtI2C_Init();
 }

+ 597 - 0
User project/5.Api_rt/api_rt_i2c.c

@@ -0,0 +1,597 @@
+#include "api_rt_i2c.h"
+#include "api_rt_dbg.h"
+#include "board_config.h"
+#include "gd32f30x.h"
+#include <stdint.h>
+
+ApiRtI2C_Handle I2Cs[1];
+
+/* ========================================================================== */
+/* ============================ Api RT Functions ============================ */
+/* ========================================================================== */
+
+void iRtI2C_Init()
+{
+    I2Cs[0].I2CBase = I2C0;
+}
+
+
+int iRtI2C_BusReset(uint8_t devIndex)
+{
+    i2c_deinit(I2Cs[devIndex].I2CBase);
+    /* Configure SDA/SCL for GPIO */
+    GPIO_BC(GPIOB) |= GPIO_PIN_6;
+    GPIO_BC(GPIOB) |= GPIO_PIN_7;
+    gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
+    gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
+    __NOP();
+    __NOP();
+    __NOP();
+    __NOP();
+    __NOP();
+    GPIO_BOP(GPIOB) |= GPIO_PIN_6;
+    __NOP();
+    __NOP();
+    __NOP();
+    __NOP();
+    __NOP();
+    GPIO_BOP(GPIOB) |= GPIO_PIN_7;
+    /* Connect I2C_SCL_PIN to I2C_SCL */
+    /* Connect I2C_SDA_PIN to I2C_SDA */
+    gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
+    gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
+
+    /* configure I2Cs[devIndex].I2CBase clock */
+    i2c_clock_config(I2Cs[devIndex].I2CBase, 100000, I2C_DTCY_2);
+    
+    /* Configure I2C address */
+    i2c_mode_addr_config(I2Cs[devIndex].I2CBase, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, HW_I2C_EE_ADDR_BLOCK1);
+    
+    /* Enable acknowledge */
+    i2c_ack_config(I2Cs[devIndex].I2CBase, I2C_ACK_ENABLE);
+    
+    /* Enable I2C_DMA */
+//    i2c_dma_config(I2Cs[devIndex].I2CBase, I2C_DMA_ON); 
+       
+    /* Enable I2C */
+    i2c_enable(I2Cs[devIndex].I2CBase);
+
+    return 1;
+}
+
+void iRtI2C_WaitEEReady()
+{
+    uint16_t cnt1 = 0, cnt2 = 0;
+
+    /* Wait at least 5ms after writing a page */
+    while (cnt2 < 2)
+    {
+        cnt1++;
+        if (cnt1 == 10000)
+        {
+            cnt2++;
+            cnt1 = 0;
+        }
+    }
+}
+
+int iRtI2C_PageWrite2EE(uint8_t devIndex, uint16_t devAddr, uint16_t memAddr, uint8_t *data, uint8_t count)
+{
+    uint8_t state = (uint8_t)I2C_START;
+    uint16_t timeoutCnt = 0;
+    uint8_t i2c_timeout_flag = 0;
+    uint8_t i2cBusResetCnt = 0;
+
+    /* Write to EEPROM enable*/
+    GPIO_OCTL(GPIOC) &= ~0x1000;
+
+    /* Enable acknowledge */
+    i2c_ack_config(I2Cs[devIndex].I2CBase , I2C_ACK_ENABLE);
+
+    while(!(i2c_timeout_flag)) 
+    {
+        /* I2C process */
+        switch(state) 
+        {
+        case I2C_START:
+            /* I2C master sends start signal only when the bus is idle */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_I2CBSY) != 0)  && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT)
+            {
+                i2c_start_on_bus(I2Cs[devIndex].I2CBase);
+                timeoutCnt = 0;
+                state = I2C_SEND_ADDRESS;
+            } 
+            else 
+            {
+                i2cBusResetCnt += iRtI2C_BusReset(devIndex);
+                timeoutCnt = 0;
+                state = I2C_START;
+                //printf("i2c bus is busy in WRITE!\n");
+            }
+            break;
+
+        case I2C_SEND_ADDRESS:
+            /* I2C master sends START signal successfully */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_SBSEND) == 0) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT)
+            {
+                i2c_master_addressing(I2Cs[devIndex].I2CBase, devAddr, I2C_TRANSMITTER);
+                timeoutCnt = 0;
+                state = I2C_CLEAR_ADDRESS_FLAG;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = I2C_START;
+                printf("i2c master sends start signal timeoutCnt in WRITE!\n");
+            }
+            break;
+
+        case I2C_CLEAR_ADDRESS_FLAG:
+            /* address flag set means i2c slave sends ACK */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_ADDSEND) == 0) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT)
+            {
+                i2c_flag_clear(I2Cs[devIndex].I2CBase, I2C_FLAG_ADDSEND);
+                timeoutCnt = 0;
+                state = I2C_TRANSMIT_DATA;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = I2C_START;
+                //printf("i2c master clears address flag timeoutCnt in WRITE!\n");
+            }
+            break;
+
+        case I2C_TRANSMIT_DATA:
+            /* wait until the transmit data buffer is empty */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_TBE) == 0) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT) {
+                /* send the EEPROM's internal address to write to : only one byte address */
+                i2c_data_transmit(I2Cs[devIndex].I2CBase, memAddr);
+                timeoutCnt = 0;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = I2C_START;
+                //printf("i2c master sends EEPROM's internal address timeoutCnt in WRITE!\n");
+            }
+
+            /* wait until BTC bit is set */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_BTC) == 0) && (timeoutCnt < I2C_TIME_OUT)){
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT) 
+            {
+                timeoutCnt = 0;
+            }
+            else 
+            {
+                timeoutCnt = 0;
+                state = I2C_START;
+                //printf("i2c master sends data timeoutCnt in WRITE!\n");
+            }
+
+            while(count != 0)
+            {
+                count --;
+                i2c_data_transmit(I2Cs[devIndex].I2CBase, *data);
+                /* Point to the next byte to be written */
+                data++;
+                /* wait until BTC bit is set */
+                while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_BTC) == 0) && (timeoutCnt < I2C_TIME_OUT))
+                {
+                    timeoutCnt++;
+                }
+
+                if(timeoutCnt < I2C_TIME_OUT) 
+                {
+                    timeoutCnt = 0;
+                } 
+                else 
+                {
+                    timeoutCnt = 0;
+                    state = I2C_START;
+                    //printf("i2c master sends data timeoutCnt in WRITE!\n");
+                }
+            }
+
+            timeoutCnt = 0;
+            state = I2C_STOP;
+            break;
+
+        case I2C_STOP:
+            /* send a stop condition to I2C bus */
+            i2c_stop_on_bus(I2Cs[devIndex].I2CBase);
+
+            /* I2C master sends STOP signal successfully */
+            while((I2C_CTL0(I2Cs[devIndex].I2CBase) & I2C_CTL0_STOP) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT) 
+            {
+                timeoutCnt = 0;
+                state = I2C_COMPLETE;
+                i2c_timeout_flag = 1;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = I2C_START;
+                //printf("i2c master sends stop signal timeoutCnt in WRITE!\n");
+            }
+            break;
+
+        default:
+            state = I2C_START;
+            i2c_timeout_flag = 1;
+            timeoutCnt = 0;
+            //printf("i2c master sends start signal in WRITE.\n");
+            break;
+        }
+
+        if(i2cBusResetCnt > 2 )
+        {
+            break;
+        }
+    }
+
+    /* Write to EEPROM disable */
+    GPIO_OCTL(GPIOC) |= 0x1000;
+
+    if(state == I2C_COMPLETE)
+    {
+        return count;
+    }
+    else 
+    {
+        return 0;
+    }
+}
+
+/* ========================================================================== */
+/* ============================== API Functions ============================= */
+/* ========================================================================== */
+
+int iI2C_Write(uint8_t devIndex, uint16_t devAddr, uint16_t memAddr, uint8_t memAddrSize, uint8_t* data, uint16_t count)
+{
+    uint8_t addr = 0, misalignedDataCnt = 0, pageCnt = 0, singleDataCnt = 0;
+    uint16_t writeCompCnt = 0;
+    
+    if(memAddrSize == 0x8)
+    {
+        memAddr = memAddr & 0xFF;
+    }
+    addr = memAddr % HW_I2C_EE_PAGESIZE_BYTE;
+    misalignedDataCnt = HW_I2C_EE_PAGESIZE_BYTE - addr; 
+    pageCnt = count / HW_I2C_EE_PAGESIZE_BYTE;
+    singleDataCnt = count % HW_I2C_EE_PAGESIZE_BYTE;    
+
+    /* If memAddr is HW_I2C_EE_PAGESIZE_BYTE aligned */
+    if (addr == 0)
+    {
+        while (pageCnt != 0)
+        {
+            pageCnt--;
+            writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, HW_I2C_EE_PAGESIZE_BYTE);
+            iRtI2C_WaitEEReady();
+            memAddr += HW_I2C_EE_PAGESIZE_BYTE;
+            data += HW_I2C_EE_PAGESIZE_BYTE;  
+        }
+
+        if (singleDataCnt != 0)
+        {
+            writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, singleDataCnt);
+            iRtI2C_WaitEEReady();
+        }
+    }
+    else
+    {
+        /* If memAddr is not HW_I2C_EE_PAGESIZE_BYTE aligned */
+        if(count < misalignedDataCnt)
+        {
+            writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, count);
+            iRtI2C_WaitEEReady();
+        }
+        else 
+        {
+            count -= misalignedDataCnt;
+            pageCnt = count / HW_I2C_EE_PAGESIZE_BYTE;
+            singleDataCnt = count % HW_I2C_EE_PAGESIZE_BYTE;
+
+            /* Write misaligned data */
+            if(misalignedDataCnt != 0)  
+            {
+                writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, misalignedDataCnt);
+                iRtI2C_WaitEEReady();
+                memAddr += misalignedDataCnt;
+                data += misalignedDataCnt; 
+            }
+
+            /* Write page data */
+            while(pageCnt != 0)
+            {
+                pageCnt --;
+                writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, HW_I2C_EE_PAGESIZE_BYTE);
+                iRtI2C_WaitEEReady();
+                memAddr += HW_I2C_EE_PAGESIZE_BYTE;
+                data += HW_I2C_EE_PAGESIZE_BYTE; 
+            }
+
+            /* Write single data */
+            if (singleDataCnt != 0)
+            {
+                writeCompCnt += iRtI2C_PageWrite2EE(devIndex, devAddr, memAddr, data, singleDataCnt);
+                iRtI2C_WaitEEReady();
+            }
+        }
+    }
+
+    return writeCompCnt;
+}
+
+int iI2C_Read(uint8_t devIndex, uint16_t devAddr, uint16_t memAddr, uint8_t memAddrSize, uint8_t* data, uint16_t count)
+{
+    uint8_t state = (uint8_t)I2C_START;
+    uint8_t read_cycle = 0;
+    uint16_t timeoutCnt = 0;
+    uint8_t i2c_timeout_flag = 0;
+    uint8_t i2cBusResetCnt = 0;
+
+    /* enable acknowledge */
+    i2c_ack_config(I2Cs[devIndex].I2CBase, I2C_ACK_ENABLE);
+    
+    while(i2c_timeout_flag ==0)
+    {
+        switch(state) 
+        {
+        case I2C_START:
+            if(RESET == read_cycle) 
+            {
+                /* Disable I2C0 */
+                i2c_disable(I2Cs[devIndex].I2CBase);
+                /* Enable I2C0 */
+                i2c_enable(I2Cs[devIndex].I2CBase);
+                /* Enable acknowledge */
+                i2c_ack_config(I2Cs[devIndex].I2CBase, I2C_ACK_ENABLE);
+                /* I2C master sends start signal only when the bus is idle */
+                while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_I2CBSY) != 0) && (timeoutCnt < I2C_TIME_OUT))
+                {
+                    timeoutCnt++;
+                }
+                
+                if(timeoutCnt < I2C_TIME_OUT) 
+                {
+                    /* Send the start signal */
+                    i2c_start_on_bus(I2Cs[devIndex].I2CBase);
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_SEND_ADDRESS;
+                } 
+                else 
+                {
+                    i2cBusResetCnt += i2c_bus_reset();
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_START;
+                }
+            } 
+            else 
+            {
+                i2c_start_on_bus(I2Cs[devIndex].I2CBase);
+                timeoutCnt = 0;
+                state = (uint8_t)I2C_SEND_ADDRESS;
+            }
+            break;
+        case I2C_SEND_ADDRESS:
+            /* I2C master sends START signal successfully */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_SBSEND) == 0) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+            if(timeoutCnt < I2C_TIME_OUT) 
+            {
+                if(RESET == read_cycle) 
+                {
+                    i2c_master_addressing(I2Cs[devIndex].I2CBase, devAddr, I2C_TRANSMITTER);
+                    state = (uint8_t)I2C_CLEAR_ADDRESS_FLAG;
+                } 
+                else 
+                {
+                    i2c_master_addressing(I2Cs[devIndex].I2CBase, devAddr, I2C_RECEIVER);
+                    state = (uint8_t)I2C_CLEAR_ADDRESS_FLAG;
+                }
+                timeoutCnt = 0;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = (uint8_t)I2C_START;
+                read_cycle = 0;
+            }
+            break;
+        case I2C_CLEAR_ADDRESS_FLAG:
+            /* Address flag set means i2c slave sends ACK */
+            while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_ADDSEND) == 0) && (timeoutCnt < I2C_TIME_OUT))
+            {
+                timeoutCnt++;
+            }
+            if(timeoutCnt < I2C_TIME_OUT) 
+            {
+                i2c_flag_clear(I2Cs[devIndex].I2CBase, I2C_FLAG_ADDSEND);
+                timeoutCnt = 0;
+                state = (uint8_t)I2C_TRANSMIT_DATA;
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = (uint8_t)I2C_START;
+                read_cycle = 0;   
+            }
+            break;
+        case I2C_TRANSMIT_DATA:
+            if(RESET == read_cycle) 
+            {
+                /* Wait until the transmit data buffer is empty */
+                while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_TBE) == 0) && (timeoutCnt < I2C_TIME_OUT))
+                {
+                    timeoutCnt++;
+                }
+                if(timeoutCnt < I2C_TIME_OUT) 
+                {
+                    /* Send the EEPROM's internal address to write to : only one byte address */
+                    i2c_data_transmit(I2Cs[devIndex].I2CBase, memAddr);
+                    timeoutCnt = 0;
+                } 
+                else 
+                {
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_START;
+                    read_cycle = 0;    
+                }
+                /* Wait until BTC bit is set */
+                while((i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_BTC) == 0) && (timeoutCnt < I2C_TIME_OUT))
+                {
+                    timeoutCnt++;
+                }
+                if(timeoutCnt < I2C_TIME_OUT) 
+                {
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_START;
+                    read_cycle++;
+                }
+                else 
+                {
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_START;
+                    read_cycle = 0;
+                }
+            } 
+            else 
+            {
+                /* One byte master reception procedure (polling) */
+                if(count < 2) 
+                {
+                    /* Disable acknowledge */
+                    i2c_ack_config(I2Cs[devIndex].I2CBase, I2C_ACK_DISABLE);
+                    /* Clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register (I2C_STAT0 has already been read) */
+                    i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_ADDSEND);
+                    /* Send a stop condition to I2C bus*/
+                    i2c_stop_on_bus(I2Cs[devIndex].I2CBase);
+                    /* Wait for the byte to be received */
+                    while(i2c_flag_get(I2Cs[devIndex].I2CBase, I2C_FLAG_RBNE) == 0)
+                    {
+                        // do nothing
+                    }
+                    /* Read the byte received from the EEPROM */
+                    *data = i2c_data_receive(I2Cs[devIndex].I2CBase);
+                    /* Decrement the read bytes counter */
+                    count--;
+                    timeoutCnt = 0;
+                    state = (uint8_t)I2C_STOP;
+                } 
+                else 
+                {  /* More than one byte master reception procedure (DMA) */                   
+                    
+                    dma_transfer_number_config(DMA0, DMA_CH6, count);        
+                    DMA_CH6MADDR(DMA0) = (uint32_t)data;
+                    
+                    i2c_dma_last_transfer_config(I2Cs[devIndex].I2CBase, I2C_DMALST_ON);
+                    /* Enable I2Cs[devIndex].I2CBase DMA */
+                    i2c_dma_config(I2Cs[devIndex].I2CBase, I2C_DMA_ON);
+                    /* Enable DMA0 channel5 */
+                    dma_channel_enable(DMA0, DMA_CH6);
+                    /* Wait until BTC bit is set */
+                    while(dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF) == 0 && (timeoutCnt < I2C_TIME_OUT))
+                    {
+                        timeoutCnt++;
+                    }
+
+                    if(timeoutCnt < I2C_TIME_OUT) 
+                    {
+                        timeoutCnt = 0;
+                        state = (uint8_t)I2C_STOP;
+                    } 
+                    else 
+                    {
+                        i2c_timeout_flag = 1;
+                        break;
+                    }
+                }
+            }
+            break;
+        case I2C_STOP:
+            /* Send a stop condition to I2C bus */
+            i2c_stop_on_bus(I2Cs[devIndex].I2CBase);
+            /* I2C master sends STOP signal successfully */
+            while((I2C_CTL0(I2Cs[devIndex].I2CBase) & I2C_CTL0_STOP) && (timeoutCnt < I2C_TIME_OUT)) 
+            {
+                timeoutCnt++;
+            }
+
+            if(timeoutCnt < I2C_TIME_OUT)
+            {
+                timeoutCnt = 0;                 
+                i2c_timeout_flag = 1;
+                state = (uint8_t)I2C_COMPLETE;
+                read_cycle = 0;
+                
+                /* Disable DMA0 CH6 */
+                dma_channel_disable(DMA0, DMA_CH6);
+                /* Disable I2Cs[devIndex].I2CBase DMA */
+                i2c_dma_config(I2Cs[devIndex].I2CBase, I2C_DMA_OFF); 
+                i2c_dma_last_transfer_config(I2Cs[devIndex].I2CBase, I2C_DMALST_OFF);
+            } 
+            else 
+            {
+                timeoutCnt = 0;
+                state = (uint8_t)I2C_START;
+                read_cycle = 0;
+            }
+                                            
+            break;
+        default:
+            state = (uint8_t)I2C_START;
+            read_cycle = 0;
+            i2c_timeout_flag = 1;
+            timeoutCnt = 0;
+            
+            break;
+        }
+
+        if(i2cBusResetCnt > 1)
+        {
+            break;
+        }
+    }
+
+    if(state == I2C_COMPLETE)
+    {
+        return count;
+    }
+    else 
+    {
+        return 0;
+    }
+}
+

+ 58 - 0
User project/5.Api_rt/api_rt_i2c.h

@@ -0,0 +1,58 @@
+#ifndef _API_I2C_LOW_H_
+#define _API_I2C_LOW_H_
+
+#include <stdint.h>
+#include "api_i2c.h"
+#include "api_rt_common.h"
+#include "gd32f30x.h"
+
+#define I2C_TIME_OUT    (uint16_t)(10000)
+
+typedef struct
+{
+    uint32_t I2CBase;
+} ApiRtI2C_Handle;
+
+extern ApiRtI2C_Handle I2Cs[1];
+
+typedef enum
+{
+    I2C_START = 0,
+    I2C_SEND_ADDRESS,
+    I2C_CLEAR_ADDRESS_FLAG,
+    I2C_TRANSMIT_DATA,
+    I2C_STOP,
+    I2C_COMPLETE
+} ApiRtI2C_Process;
+
+/**
+ * @brief I2C初始化
+ */
+void iRtI2C_Init();
+
+/**
+ * @brief I2C等待EE可写入
+ */
+void iRtI2C_WaitEEReady();
+
+/**
+ * @brief I2C总线复位
+ *
+ * @return 总线复位次数
+ */
+int iRtI2C_BusReset(uint8_t devIndex);
+
+/**
+ * @brief I2C同步页写入EE
+ * 
+ * @param devIndex 外设序号
+ * @param devAddr 设备地址
+ * @param memAddr 内存地址
+ * @param memAddrSize 内存地址宽度
+ * @param data 写入数据Buffer
+ * @param count 写入数据长度
+ * @return 写入结果
+ */
+int iRtI2C_PageWrite2EE(uint8_t devIndex, uint16_t devAddr, uint16_t memAddr, uint8_t *data, uint8_t count);
+
+#endif

+ 88 - 0
WLMCP.ewp

@@ -355,6 +355,7 @@
                     <state>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Include</state>
                     <state>$PROJ_DIR$\MSTLibraries\MISC\inc</state>
                     <state>$PROJ_DIR$\MSTLibraries\SelfTestLib\inc</state>
+                    <state>$PROJ_DIR$\api</state>
                 </option>
                 <option>
                     <name>CCStdIncCheck</name>
@@ -2112,6 +2113,45 @@
             <data />
         </settings>
     </configuration>
+    <group>
+        <name>api</name>
+        <file>
+            <name>$PROJ_DIR$\api\api.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_adc.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_cap.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_delay.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_fault.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_gpio.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_i2c.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_pwm.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_scheduler.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_test_probe.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_timer.h</name>
+        </file>
+        <file>
+            <name>$PROJ_DIR$\api\api_uart.h</name>
+        </file>
+    </group>
     <group>
         <name>MSTLibraries</name>
         <group>
@@ -2804,5 +2844,53 @@
                 </group>
             </group>
         </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_common.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_dbg.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_dbg.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>
+            <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>
+            </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>
+            </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>
+            </file>
+        </group>
     </group>
 </project>

+ 0 - 0
tests/unit_test/gd32f30x.h


+ 0 - 0
tests/unit_test/gd32f30x_libopt.h


+ 2 - 0
xmake.lua

@@ -1,3 +1,5 @@
+--includes("tests/sim/sim_board")
+
 add_rules("mode.debug", "mode.release", "mode.coverage")
 
 add_requires("gtest")