CN\zhangkai71 2 лет назад
Родитель
Сommit
7132e78d12

+ 3 - 0
.gitmodules

@@ -1,3 +1,6 @@
 [submodule "User project/2.MotorDrive/Source/packed"]
 	path = User project/2.MotorDrive/Source/packed
 	url = ../ebike_zhongzhi_gd_packed
+[submodule "User project/api"]
+	path = User project/api
+	url = https://git.midea.com/DEP-MITBG/dep-mt/digitization-group/McuApi.git

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

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

+ 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

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

@@ -0,0 +1,83 @@
+/**
+ * @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) */
+
+/* ========================================================================== */
+/* ================================= 硬件参数配置 ================================= */
+/* ========================================================================== */
+
+/* --------------------------------- 电力系统参数 --------------------------------- */
+
+#define HW_UAC_FREQ_HZ 50
+
+/* --------------------------------- 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_FTBC_TICK 1
+#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
+
+/* ========================================================================== */
+/* ================================ API接口序号定义 =============================== */
+/* ========================================================================== */
+
+#define HW_TBS_TIMER     0
+#define HW_SYSTICK_TIMER 1
+
+#define HW_ADC_VC_CH   0
+#define HW_ADC_VB_CH   1
+#define HW_ADC_VA_CH   2
+#define HW_ADC_IA_CH   4
+#define HW_ADC_IB_CH   3
+#define HW_ADC_UDC_CH  5
+#define HW_ADC_TEMP_CH 6
+#define HW_ADC_UAC_CH  7
+
+#define HW_ADC_IBUS_1ST_CH 0
+#define HW_ADC_IBUS_2ND_CH 1
+
+#define HW_GPIO_TX_PIN 0
+#define HW_GPIO_RX_PIN 1

+ 88 - 0
User project/5.Api_rt/api_rt_adc.c

@@ -0,0 +1,88 @@
+#include "api.h"
+#include "api_rt_adc.h"
+#include "gd32f30x.h"
+
+Adc_Handle Adcs[2];
+
+
+void AdcLow_Init(void)
+{
+    // ADC0 Regular
+    Adcs[0].AdcBase = ADC0;
+    Adcs[0].DmaBase = DMA0;
+    Adcs[0].DmaChannelBase = DMA_CH0;
+    for (int i = 0; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[0].Results[i] = 0;
+    }
+    // ADC0 Injected
+    Adcs[1].AdcBase = ADC0;
+    for (int i = 1; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[1].Results[i] = 1;
+    }
+    // ADC1 Injected
+    Adcs[2].AdcBase = ADC0;
+    for (int i = 0; i < ADC_RESULT_SIZE; i++)
+    {
+        Adcs[2].Results[i] = 0;
+    }
+
+};
+//void AdcLow_CompleteIsr(uint8_t devIndex);
+
+uint16_t iAdc_GetResult(uint8_t devIndex, uint8_t channelIndex)
+{
+//    ASSERT_LESS(devIndex, 1);
+    return Adcs[devIndex].Results[channelIndex];
+}
+
+uint16_t* iAdc_GetResultPointer(uint8_t devIndex)
+{
+  //    ASSERT_LESS(devIndex, 1);
+    return Adcs[devIndex].Results;
+}
+
+void iAdc_Enable(uint8_t devIndex)
+{
+//    ASSERT_LESS(devIndex, 1);
+    if(RESET == (ADC_CTL1(devIndex) & ADC_CTL1_ADCON)){
+        ADC_CTL1(devIndex) |= (uint32_t)ADC_CTL1_ADCON;
+    }   
+}
+
+void iAdc_Disable(uint8_t devIndex)
+{
+//    ASSERT_LESS(devIndex, 1);
+    ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
+}
+
+ApiAdc_Status iAdc_GetStatus(uint8_t devIndex)
+{
+     if (ADC_STAT(devIndex) & ADC_STAT_EOC != 0)
+    {
+        return Adc_End;
+    }
+    else
+    {
+        return Adc_Converting;
+    }
+}
+
+void iAdc_Convert(uint8_t devIndex)
+{
+  //for regular only
+    ADC_CTL1(devIndex) |= ADC_CTL1_SWRCST;
+}
+
+void iAdc_ChannelGroupSwitch(uint8_t devIndex, uint8_t groupIndex)
+{
+}
+
+void iAdc_EnableConversionInterrupt(uint8_t devIndex)
+{
+
+}
+
+void iAdc_EnableHardwareTrigger(uint8_t devIndex);
+void iAdc_DisableHardwareTrigger(uint8_t devIndex);

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

@@ -0,0 +1,24 @@
+#ifndef _API_RT_ADC_H_
+#define _API_RT_ADC_H_
+
+#include <stdint.h>
+#include "gd32f30x.h"
+
+#define ADC_DEVICE_COUNT        1
+#define ADC_RESULT_SIZE         16
+
+typedef struct
+{
+    uint32_t AdcBase;
+    uint32_t DmaBase;
+    dma_channel_enum *DmaChannelBase;
+    uint16_t Results[ADC_RESULT_SIZE];
+
+}  Adc_Handle;
+
+extern Adc_Handle Adcs[2];
+
+void AdcLow_Init(void);
+void AdcLow_CompleteIsr(uint8_t devIndex);
+
+#endif

+ 1 - 0
User project/api

@@ -0,0 +1 @@
+Subproject commit cb277ecfcbc3f19d9312b9eef96c72e91be14ab6

+ 56 - 0
WLMCP.ewp

@@ -355,6 +355,8 @@
                     <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$\User project\5.api_rt</state>
+                    <state>$PROJ_DIR$\User project\api</state>
                 </option>
                 <option>
                     <name>CCStdIncCheck</name>
@@ -2732,6 +2734,12 @@
                 <name>1.BasicHardwLayer</name>
                 <group>
                     <name>Include</name>
+                    <file>
+                        <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\api_board_support.h</name>
+                    </file>
+                    <file>
+                        <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\api_config.h</name>
+                    </file>
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\1.BasicHardwLayer\Include\bootloader.h</name>
                     </file>
@@ -2804,5 +2812,53 @@
                 </group>
             </group>
         </group>
+        <group>
+            <name>5.api_rt</name>
+            <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>
+        </group>
+        <group>
+            <name>api</name>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_adc.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_cap.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_delay.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_fault.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_gpio.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_i2c.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_pwm.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_scheduler.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_test_probe.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_timer.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\api\api_uart.h</name>
+            </file>
+        </group>
     </group>
 </project>