2025-04-26 16:03:23 +08:00

170 lines
5.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ##########################################################################
** Filename :
** Project :
** Module :
** Processor :
** Version :
** Compiler :
** Date/Time :
** Abstract :
** Contents :
** Note :
**
** (c) Copyright dmdz Co.,Ltd
** --------------------------------------------------------------------------
** R E V I S I O N H I S T O R Y
** --------------------------------------------------------------------------
** Date Ver Author Description
** -20230602- --V1.0-- --mingyea--- --修改--
** #########################################################################*/
#ifndef ADC_CFG_H__
#define ADC_CFG_H__
/*---------------------------------------------------------------------------
- I N C L U D E F I L E S
----------------------------------------------------------------------------*/
#include "common_cfg.h"
#include "cpu.h"
/*---------------------------------------------------------------------------
- D E F I N E S / M A C R O S
----------------------------------------------------------------------------*/
#define ADC_VREF1P2 1200u //mv
#define ADC_VREFH 5000u //mv
#define ADC_RESOLUTION_BIT 12u //分辨率
#define ADC_RESOLUTION_MASK 4096u //分辨率換算成的值
#define ADC_DEBUG_BY_SOFTWARE_TRIG 0
#define ADC_DEBUG_BY_TIMER_TRIG 1
#define ADC_DEBUG_BY_PWM_TRIG 2
#define ADC_DEBUG_BY_ANALOG_MONITOR 3
#define ADC_DEBUG_BY_TSENSOR_ADC 4
#define ADC_LOGIC_CHANNEL_VREF1P2 0u //1.2V
#define ADC_LOGIC_CHANNEL_NTC 1u //--13
#define ADC_LOGIC_CHANNEL_AD1 2u //--12
#define ADC_LOGIC_CHANNEL_AD2 3u //ad2 --7
#define ADC_LOGIC_CHANNEL_SNS 4u // --6
#define ADC_LOGIC_CHANNEL_AD3 5u //ad3 --5
#define ADC_LOGIC_CHANNEL_VBAT 6u //12V --1
#define ADC_LOGIC_CHANNEL_ADRH 7u //--0
#define ADC_LOGIC_CHANNEL_USE_START 1u //除了最前面的通道是给 1.2从1开始就是用户的
#define ADC_LOGIC_CHANNEL_START 0u
#define ADC_LOGIC_CHANNEL_END 7u
#define ADC_LOGIC_CHANNEL_MAX (ADC_LOGIC_CHANNEL_END-ADC_LOGIC_CHANNEL_START+1u) //又加1把VREF1P2放在buf0
//#define ADC_LOGIC_CHANNEL_ADD_VREF1P2_MAX (ADC_LOGIC_CHANNEL_MAX+1u)
//滤波
#define ADC0_CHANNEL_FILTER_TIME 10u //滤波的缓存次数,
//#define ADC0_CHANNEL_FILETER_EN 1u //使能滤波
/*****各通道***ADC manage的***/
#define ADC_LOGIC_MANAGE_CHANEL_1 0u //AD4,物理AN3, S14S15
#define ADC_LOGIC_MANAGE_CHANEL_2 1u //AD3,物理AN2, S12S13
#define ADC_LOGIC_MANAGE_CHANEL_3 2u //AD2,物理AN1, S10S11
#define ADC_LOGIC_MANAGE_CHANEL_4 3u //AD1,物理AN0, S8S9
#define ADC_LOGIC_MANAGE_CHANEL_5 4u //AD7,物理AN5,S4 S3 S1
#define ADC_LOGIC_MANAGE_CHANEL_6 5u //AD5,温度
#define ADC_LOGIC_MANAGE_CHANEL_7 6u //AD7,SNS
#define ADC_LOGIC_MANAGE_CHANEL_MAX 7u //
//实际配置,各通道的用处。
#define ADC0_LOGIC_CHN_NORMAL_KEY_MAX 5u //有几个通道用于按键
#define ADC0_LOGIC_CHN_FUNC_SAFE_KEY_MAX 2u //功能安全按键通道的起始id --其是就一个通道,分出,单独按,和同时多个按
#define ADC0_LOGIC_CHN_NORMAL_KEY_START ADC_LOGIC_MANAGE_CHANEL_1 //普通按键通道的起始id
#if 1 //测试用 //TEMP_CLOSE
#define ADC0_LOGIC_CHN_FUNC_SAFE_KEY_START ADC_LOGIC_MANAGE_CHANEL_1 //功能安全按键通道的起始id
#else
#define ADC0_LOGIC_CHN_FUNC_SAFE_KEY_START ADC_LOGIC_MANAGE_CHANEL_6 //功能安全按键通道的起始id
#endif
#define ADC_CHANNEL_SBAT ADC_LOGIC_CHANNEL_VBAT
#define ADC_SBAT_COEFFICIENT_DIV (680u+124u)/124u
#define ADC_SBAT_DIODE_DIFF 700u //mv
#define ADC_ENABLE_DMA_MODE 0u //改用DMA循环模式 0 单次 1 循环 //
#define ADC_TASK_PERIOD_TIME 1u
#define ADC_TASK_TIMEOUT (100u/ADC_TASK_PERIOD_TIME)
#define adc_manage_get_syspower adc_manage_get_sbat_voltage
#define ADC_DEBUG_EN 1u
/*---------------------------------------------------------------------------
- T Y P E D E F I N I T I O N S
----------------------------------------------------------------------------*/
typedef u8 ADC_ChannelType ;
typedef u16 ADC_SampleTimeType ;
typedef u16 adc_voltage_t;
typedef u16 adc_result_t;
typedef u16 adc_org_value_t;
typedef struct
{
ADC_Type* base;
ADC_ChannelType channel;
ADC_SampleTimeType sample_time;
u8 logic_id;
}adc_group_cfg_s;
/*---------------------------------------------------------------------------
- G L O B A L V A R I A B L E S
- only configuration table allowed here,variables are not allowed!
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/
extern const FL_ADC_CommonInitTypeDef g_ADC_CommonInitStruct;
extern const FL_ADC_InitTypeDef g_ADC_InitStruct ;
extern const u32 g_adc_drv_channel[ADC_LOGIC_CHANNEL_MAX] ;
/*---------------------------------------------------------------------------
- F U N C T I O N P R O T O T Y P E
----------------------------------------------------------------------------*/
/*****各通道***ADC原始的***/
void adc_callback(void *device, uint32_t wpara, uint32_t lpara);
void adc_dma_callback(void *device, uint32_t wpara, uint32_t lpara);
#if 0
extern const adc_group_cfg_s g_adc_reg_channel_table[ADC_LOGIC_CHANNEL_REG_MAX];
extern const adc_group_cfg_s g_adc_inj_channel_table[ADC_LOGIC_CHANNEL_INJ_MAX];
extern const ADC_ConfigType g_adc_config_table ;
extern const DMA_ConfigType g_adc_dma_cfg_table ;
extern const CTU_ConfigType g_ctu_cfg ;
#endif
adc_voltage_t adc_manage_get_voltage(u8 id);
adc_voltage_t adc_manage_get_sbat_voltage(void);
void adc_manage_task(void);
#endif /* __ADC_CFG_H__ */