ADC,Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器。是将连续变量的模拟信号转换为离散的数字信号的器件。真实世界的模拟信号,例如温度、压力、声音或者图像等,需要转换成更容易储存、处理和发射的数字形式。模/数转换器可以实现这个功能,典型的模拟数字转换器将模拟信号转换为表示一定比例电压值的数字信号。
adc控制器驱动提供了adc的控制访问方法,
驱动相关的源文件包括
.
├── fadc_g.c
├── fadc_hw.c
├── fadc_hw.h
├── fadc_intr.c
├── fadc_sinit.c
├── fadc.c
└── fadc.h
以下部分将指导您完成 fadc 驱动的软件配置:
fadc控制数据
typedef struct
{
FAdcConfig config;/* adc config */
FAdcConvertConfig convert_config; /* adc convert config */
FAdcThresholdConfig threshold_config; /* adc channel threshold config */
u32 is_ready;/* adc init ready flag */
u16 value[FADC_CHANNEL_NUM]; /* adc value */
boolean convert_complete[FADC_CHANNEL_NUM]; /*!< Specifies whether the conversion is complete> */
FAdcIntrEventHandler event_handler[FADC_INTR_EVENT_NUM]; /* event handler for interrupt */
void *event_param[FADC_INTR_EVENT_NUM]; /* parameters of event handler */
}FAdcCtrl;
fadc配置数据,FAdcConfig主要是adc控制器id、基地址和中断号,FAdcConvertConfig主要包括用户可配置的参数,包括转换间隔时间、转换模式、通道模式等,FAdcThresholdConfig主要包含具体通道的结果阈值
typedef struct
{
u32 instance_id;/* adc id */
uintptr base_addr;/* adc control register base address*/
u32 irq_num;/* adc interrupt number */
u32 irq_prority;/* adc interrupt priority*/
const char *instance_name;/* instance name */
} FAdcConfig;
typedef struct
{
u32 convert_interval; /* convert interval time */
u32 clk_div; /* clock divider */
FAdcConvertMode convert_mode;/*!< convert mode */
FAdcChannelMode channel_mode;/*!< channel mode */
} FAdcConvertConfig;
typedef struct
{
u16 high_threshold[FADC_CHANNEL_NUM]; /*!< Configures the ADC analog high threshold value.
This parameter must be a 10-bit value. */
u16 low_threshold[FADC_CHANNEL_NUM]; /*!< Configures the ADC analog low threshold value.
This parameter must be a 10-bit value. */
} FAdcThresholdConfig;
fadc转换模式,单次转换和连续转换
typedef enum
{
FADC_CONTINUOUS_CONVERT = 0,/* continuous conversion*/
FADC_SINGLE_CONVERT = 1, /* single conversion*/
FADC_CONVERT_MODE_NUM
} FAdcCovertMode;
fadc通道模式,多通道顺序转换和固定通道转换
typedef enum
{
FADC_MULTI_CHANNEL = 0, /* multi channel conversion*/
FADC_FIXED_CHANNEL = 1, /* fixed channel conversion*/
FADC_CHANNEL_MODE_NUM
} FAdcChannelMode;
fadc中断事件类型
typedef enum
{
FADC_INTR_EVENT_COVFIN = 0, /**< Handler type for convert finish interrupt */
FADC_INTR_EVENT_DLIMIT = 1, /**< Handler type for low limit interrupt*/
FADC_INTR_EVENT_ULIMIT = 2, /**< Handler type for high limit interrupt*/
FADC_INTR_EVENT_ERROR = 3, /**< Handler type for error interrupt*/
FADC_INTR_EVENT_NUM
} FAdcIntrEventType;
获取fadc控制器默认配置
const FAdcConfig *FAdcLookupConfig(FAdcInstance instance_id);
Note:
Input:
Return:
初始化fadc控制器, 使之可以使用
FError FAdcCfgInitialize(FAdcCtrl *pctrl, const FAdcConfig *input_config_p);
Note:
Input:
Return:
设置adc可配置参数
FError FAdcVariableConfig(FAdcCtrl *pctrl, u8 channel, FAdcConvertConfig *convert_config,
FAdcThresholdConfig *threshold_config);
Note:
Input:
Return:
设置adc通道的转换结果阈值,使能该通道
FError FAdcChannelThresholdSet(FAdcCtrl *pctrl, u8 channel, FAdcThresholdConfig *threshold_config);
Note:
Input:
Return:
设置adc控制器转换开始
FError FAdcConvertStart(FAdcCtrl *pctrl);
Note:
Input:
Return:
使能adc通道的中断
FError FAdcInterruptEnable(FAdcCtrl *pctrl, u8 channel, FAdcIntrEventType event_type);
Note:
Input:
Return:
读adc通道的转换结果
FError FAdcReadConvertResult(FAdcCtrl *pctrl, u8 channel, u16 *val);
Note:
Input:
Return:
注册adc中断事件函数
void FAdcRegisterInterruptHandler(FAdcCtrl *instance_p, FAdcIntrEventType event_type,
FAdcIntrEventHandler handler, void *param);
Note:
Input:
Return:
adc中断处理函数入口
void FAdcIntrHandler(s32 vector, void *args);
Note:
Input:
Return: