8 #ifndef HPM_ADC16_DRV_H
9 #define HPM_ADC16_DRV_H
12 #include "hpm_adc16_regs.h"
13 #include "hpm_soc_feature.h"
23 #if defined (ADC16_SOC_TEMP_CH_EN) && ADC16_SOC_TEMP_CH_EN
24 #define ADC16_IS_CHANNEL_INVALID(CH) (CH > ADC16_SOC_MAX_CH_NUM && CH != ADC16_SOC_TEMP_CH_NUM)
26 #define ADC16_IS_CHANNEL_INVALID(CH) (CH > ADC16_SOC_MAX_CH_NUM)
30 #define ADC16_IS_CHANNEL_SAMPLE_CYCLE_INVALID(CYC) (CYC == 0)
33 #define ADC16_IS_TRIG_CH_INVLAID(CH) (CH > ADC_SOC_MAX_TRIG_CH_NUM)
36 #define ADC16_IS_TRIG_LEN_INVLAID(TRIG_LEN) (TRIG_LEN > ADC_SOC_MAX_TRIG_CH_LEN)
39 #define ADC16_IS_SEQ_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_SEQ_MAX_LEN))
42 #define ADC16_IS_SEQ_DMA_BUFF_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_SEQ_MAX_DMA_BUFF_LEN_IN_4BYTES))
45 #define ADC16_IS_PMT_DMA_BUFF_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_PMT_MAX_DMA_BUFF_LEN_IN_4BYTES))
116 #if defined(HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE) && HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE
119 adc16_diff_pos_mode_differential = 0,
120 adc16_diff_pos_mode_single_ended
121 } adc16_diff_pos_mode_t;
161 #if defined(ADC_SOC_IP_VERSION) && (ADC_SOC_IP_VERSION < 2)
168 uint32_t cycle_bit :1;
181 #if defined(ADC_SOC_IP_VERSION) && (ADC_SOC_IP_VERSION < 2)
189 uint32_t cycle_bit :1;
233 #if defined(HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE) && HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE
236 uint8_t full_resolution;
237 uint8_t position_mode;
239 } adc16_diff_config_t;
265 #if defined(HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE) && HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE
272 void adc16_get_default_diff_mode_config(
ADC16_Type *ptr, adc16_diff_config_t *config);
319 #if defined (ADC_SOC_BUSMODE_ENABLE_CTRL_SUPPORT) && ADC_SOC_BUSMODE_ENABLE_CTRL_SUPPORT
325 void adc16_enable_oneshot_mode(
ADC16_Type *ptr);
332 void adc16_disable_oneshot_mode(
ADC16_Type *ptr);
403 #if defined(HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE) && HPM_IP_FEATURE_ADC16_HAS_DIFF_MODE
410 void adc16_enable_diff_mode(
ADC16_Type *ptr, adc16_diff_config_t *config);
417 void adc16_disable_diff_mode(
ADC16_Type *ptr);
675 #if defined(ADC16_SOC_TEMP_CH_EN) && ADC16_SOC_TEMP_CH_EN
681 void adc16_enable_temp_sensor(
ADC16_Type *ptr);
688 void adc16_disable_temp_sensor(
ADC16_Type *ptr);
696 #if defined(HPM_IP_FEATURE_ADC16_HAS_MOT_EN) && HPM_IP_FEATURE_ADC16_HAS_MOT_EN
697 static inline void adc16_enable_motor(
ADC16_Type *ptr)
#define ADC_SOC_SEQ_MAX_LEN
Definition: hpm_soc_feature.h:94
#define ADC_SOC_MAX_TRIG_CH_LEN
Definition: hpm_soc_feature.h:96
#define ADC16_INT_STS_SEQ_CMPT_MASK
Definition: hpm_adc16_regs.h:620
#define ADC16_SEQ_DMA_CFG_STOP_POS_SET(x)
Definition: hpm_adc16_regs.h:335
#define ADC16_TRG_DMA_ADDR_TRG_DMA_ADDR_MASK
Definition: hpm_adc16_regs.h:161
#define ADC16_BUF_CFG0_WAIT_DIS_MASK
Definition: hpm_adc16_regs.h:229
#define ADC16_INT_STS_READ_CFLCT_MASK
Definition: hpm_adc16_regs.h:581
#define ADC16_SEQ_CFG0_HW_TRIG_EN_MASK
Definition: hpm_adc16_regs.h:300
#define ADC16_INT_STS_TRIG_CMPT_MASK
Definition: hpm_adc16_regs.h:553
#define ADC16_INT_STS_SEQ_SW_CFLCT_MASK
Definition: hpm_adc16_regs.h:591
#define ADC16_ANA_CTRL0_MOTO_EN_MASK
Definition: hpm_adc16_regs.h:790
#define ADC16_INT_STS_SEQ_HW_CFLCT_MASK
Definition: hpm_adc16_regs.h:600
#define ADC16_INT_STS_DMA_FIFO_FULL_MASK
Definition: hpm_adc16_regs.h:640
#define ADC16_BUF_CFG0_WAIT_DIS_GET(x)
Definition: hpm_adc16_regs.h:232
#define ADC16_BUF_CFG0_WAIT_DIS_SET(x)
Definition: hpm_adc16_regs.h:231
#define ADC16_BUS_RESULT_VALID_GET(x)
Definition: hpm_adc16_regs.h:200
#define ADC16_SEQ_DMA_CFG_STOP_POS_MASK
Definition: hpm_adc16_regs.h:333
#define ADC16_INT_STS_TRIG_HW_CFLCT_MASK
Definition: hpm_adc16_regs.h:571
#define ADC16_INT_STS_TRIG_SW_CFLCT_MASK
Definition: hpm_adc16_regs.h:562
#define ADC16_INT_STS_SEQ_DMAABT_MASK
Definition: hpm_adc16_regs.h:610
#define ADC16_INT_STS_SEQ_CVC_MASK
Definition: hpm_adc16_regs.h:630
adc16_clock_divider_t
Define ADC16 Clock Divider.
Definition: hpm_adc16_drv.h:64
adc16_conversion_mode_t
Define ADC16 conversion modes.
Definition: hpm_adc16_drv.h:56
hpm_stat_t adc16_get_oneshot_result(ADC16_Type *ptr, uint8_t ch, uint16_t *result)
Get the result in oneshot mode.
Definition: hpm_adc16_drv.c:452
static void adc16_enable_busywait(ADC16_Type *ptr)
Set value of the WAIT_DIS bit. ADC blocks access to the associated peripheral bus until the ADC compl...
Definition: hpm_adc16_drv.h:525
hpm_stat_t adc16_trigger_seq_by_sw(ADC16_Type *ptr)
Trigger ADC conversions by software in sequence mode.
Definition: hpm_adc16_drv.c:325
static bool adc16_is_nonblocking_mode(ADC16_Type *ptr)
Judge whether the current setting is none-blocking mode or not.
Definition: hpm_adc16_drv.h:561
hpm_stat_t adc16_init(ADC16_Type *ptr, adc16_config_t *config)
Initialize an ADC16 instance.
Definition: hpm_adc16_drv.c:154
static uint32_t adc16_get_status_flags(ADC16_Type *ptr)
Get all ADC16 status flags.
Definition: hpm_adc16_drv.h:501
static void adc16_set_blocking_read(ADC16_Type *ptr)
Set blocking read in oneshot mode.
Definition: hpm_adc16_drv.h:547
adc16_resolution_t
Define ADC16 resolutions.
Definition: hpm_adc16_drv.h:48
static bool adc16_get_conv_valid_status(ADC16_Type *ptr, uint8_t ch)
Get the status of a conversion validity.
Definition: hpm_adc16_drv.h:575
hpm_stat_t adc16_set_pmt_queue_enable(ADC16_Type *ptr, uint8_t trig_ch, bool enable)
Set the queue enable control.
Definition: hpm_adc16_drv.c:400
static void adc16_seq_enable_hw_trigger(ADC16_Type *ptr)
Enable the hw trigger control for the sequence mode.
Definition: hpm_adc16_drv.h:432
static void adc16_enable_interrupts(ADC16_Type *ptr, uint32_t mask)
Enable interrupts.
Definition: hpm_adc16_drv.h:607
void adc16_get_default_config(adc16_config_t *config)
Get a default configuration for an ADC16 instance.
Definition: hpm_adc16_drv.c:11
hpm_stat_t adc16_get_prd_result(ADC16_Type *ptr, uint8_t ch, uint16_t *result)
Get the result in the period mode.
Definition: hpm_adc16_drv.c:474
void adc16_get_channel_default_config(adc16_channel_config_t *config)
Get a default configuration for an ADC16 Channel.
Definition: hpm_adc16_drv.c:22
hpm_stat_t adc16_set_seq_config(ADC16_Type *ptr, adc16_seq_config_t *config)
Configure the sequence mode for an ADC16 instance.
Definition: hpm_adc16_drv.c:336
static void adc16_init_pmt_dma(ADC16_Type *ptr, uint32_t addr)
Configure the start address of DMA write operation for the preemption mode.
Definition: hpm_adc16_drv.h:471
static void adc16_set_seq_stop_pos(ADC16_Type *ptr, uint16_t stop_pos)
Configure the stop position offset in the specified memory of DMA write operation for the sequence mo...
Definition: hpm_adc16_drv.h:459
static void adc16_disable_interrupts(ADC16_Type *ptr, uint32_t mask)
Disable interrupts.
Definition: hpm_adc16_drv.h:618
hpm_stat_t adc16_get_channel_threshold(ADC16_Type *ptr, uint8_t ch, adc16_channel_threshold_t *config)
Get thresholds of an ADC16 channel.
Definition: hpm_adc16_drv.c:232
adc16_irq_event_t
Define ADC16 irq events.
Definition: hpm_adc16_drv.h:84
static void adc16_seq_disable_hw_trigger(ADC16_Type *ptr)
Disable the hw trigger control for the sequence mode.
Definition: hpm_adc16_drv.h:442
hpm_stat_t adc16_enable_pmt_queue(ADC16_Type *ptr, uint8_t trig_ch)
Enable the specified preemption queue.
Definition: hpm_adc16_drv.c:419
hpm_stat_t adc16_deinit(ADC16_Type *ptr)
De-initialize an ADC16 instance.
Definition: hpm_adc16_drv.c:146
hpm_stat_t adc16_trigger_pmt_by_sw(ADC16_Type *ptr, uint8_t trig_ch)
Trigger ADC conversions by software in preemption mode.
Definition: hpm_adc16_drv.c:363
hpm_stat_t adc16_init_channel(ADC16_Type *ptr, adc16_channel_config_t *config)
Initialize an ADC16 channel.
Definition: hpm_adc16_drv.c:203
hpm_stat_t adc16_set_prd_config(ADC16_Type *ptr, adc16_prd_config_t *config)
Configure the the period mode for an ADC16 instance.
Definition: hpm_adc16_drv.c:302
static void adc16_set_nonblocking_read(ADC16_Type *ptr)
Set nonblocking read in oneshot mode.
Definition: hpm_adc16_drv.h:536
static void adc16_clear_status_flags(ADC16_Type *ptr, uint32_t mask)
Clear the status flags.
Definition: hpm_adc16_drv.h:589
hpm_stat_t adc16_set_pmt_config(ADC16_Type *ptr, adc16_pmt_config_t *config)
Configure the preemption mode for an ADC16 instance.
Definition: hpm_adc16_drv.c:370
hpm_stat_t adc16_disable_pmt_queue(ADC16_Type *ptr, uint8_t trig_ch)
Disable the specified preemption queue.
Definition: hpm_adc16_drv.c:435
static void adc16_disable_busywait(ADC16_Type *ptr)
Set value of the WAIT_DIS bit. The ADC does not block access to the associated peripheral bus until t...
Definition: hpm_adc16_drv.h:513
hpm_stat_t adc16_init_seq_dma(ADC16_Type *ptr, adc16_dma_config_t *config)
Configure the start address of DMA write operation for the sequence mode.
Definition: hpm_adc16_drv.c:258
@ adc16_clock_divider_9
Definition: hpm_adc16_drv.h:73
@ adc16_clock_divider_4
Definition: hpm_adc16_drv.h:68
@ adc16_clock_divider_3
Definition: hpm_adc16_drv.h:67
@ adc16_clock_divider_7
Definition: hpm_adc16_drv.h:71
@ adc16_clock_divider_1
Definition: hpm_adc16_drv.h:65
@ adc16_clock_divider_10
Definition: hpm_adc16_drv.h:74
@ adc16_clock_divider_13
Definition: hpm_adc16_drv.h:77
@ adc16_clock_divider_15
Definition: hpm_adc16_drv.h:79
@ adc16_clock_divider_12
Definition: hpm_adc16_drv.h:76
@ adc16_clock_divider_8
Definition: hpm_adc16_drv.h:72
@ adc16_clock_divider_6
Definition: hpm_adc16_drv.h:70
@ adc16_clock_divider_5
Definition: hpm_adc16_drv.h:69
@ adc16_clock_divider_11
Definition: hpm_adc16_drv.h:75
@ adc16_clock_divider_14
Definition: hpm_adc16_drv.h:78
@ adc16_clock_divider_2
Definition: hpm_adc16_drv.h:66
@ adc16_clock_divider_16
Definition: hpm_adc16_drv.h:80
@ adc16_conv_mode_preemption
Definition: hpm_adc16_drv.h:60
@ adc16_conv_mode_period
Definition: hpm_adc16_drv.h:58
@ adc16_conv_mode_sequence
Definition: hpm_adc16_drv.h:59
@ adc16_conv_mode_oneshot
Definition: hpm_adc16_drv.h:57
@ adc16_res_8_bits
Definition: hpm_adc16_drv.h:49
@ adc16_res_12_bits
Definition: hpm_adc16_drv.h:51
@ adc16_res_16_bits
Definition: hpm_adc16_drv.h:52
@ adc16_res_10_bits
Definition: hpm_adc16_drv.h:50
@ adc16_event_seq_sw_conflict
Definition: hpm_adc16_drv.h:98
@ adc16_event_dma_fifo_full
Definition: hpm_adc16_drv.h:113
@ adc16_event_trig_hw_conflict
Definition: hpm_adc16_drv.h:92
@ adc16_event_seq_dma_abort
Definition: hpm_adc16_drv.h:104
@ adc16_event_seq_single_complete
Definition: hpm_adc16_drv.h:110
@ adc16_event_seq_full_complete
Definition: hpm_adc16_drv.h:107
@ adc16_event_seq_hw_conflict
Definition: hpm_adc16_drv.h:101
@ adc16_event_read_conflict
Definition: hpm_adc16_drv.h:95
@ adc16_event_trig_sw_conflict
Definition: hpm_adc16_drv.h:89
@ adc16_event_trig_complete
Definition: hpm_adc16_drv.h:86
uint32_t hpm_stat_t
Definition: hpm_common.h:123
Definition: hpm_adc16_regs.h:12
__RW uint32_t ANA_CTRL0
Definition: hpm_adc16_regs.h:43
__RW uint32_t BUF_CFG0
Definition: hpm_adc16_regs.h:19
__RW uint32_t TRG_DMA_ADDR
Definition: hpm_adc16_regs.h:14
__RW uint32_t INT_EN
Definition: hpm_adc16_regs.h:41
__RW uint32_t SEQ_DMA_CFG
Definition: hpm_adc16_regs.h:24
__RW uint32_t INT_STS
Definition: hpm_adc16_regs.h:40
__RW uint32_t SEQ_CFG0
Definition: hpm_adc16_regs.h:21
__R uint32_t BUS_RESULT[16]
Definition: hpm_adc16_regs.h:17
ADC16 channel configuration struct.
Definition: hpm_adc16_drv.h:136
uint32_t sample_cycle
Definition: hpm_adc16_drv.h:142
bool wdog_int_en
Definition: hpm_adc16_drv.h:140
uint8_t ch
Definition: hpm_adc16_drv.h:137
uint16_t thshdh
Definition: hpm_adc16_drv.h:138
uint16_t thshdl
Definition: hpm_adc16_drv.h:139
uint8_t sample_cycle_shift
Definition: hpm_adc16_drv.h:141
ADC16 channel configuration struct.
Definition: hpm_adc16_drv.h:146
uint16_t thshdl
Definition: hpm_adc16_drv.h:149
uint8_t ch
Definition: hpm_adc16_drv.h:147
uint16_t thshdh
Definition: hpm_adc16_drv.h:148
ADC16 common configuration struct.
Definition: hpm_adc16_drv.h:125
bool sel_sync_ahb
Definition: hpm_adc16_drv.h:131
uint8_t res
Definition: hpm_adc16_drv.h:126
bool adc_ahb_en
Definition: hpm_adc16_drv.h:132
bool wait_dis
Definition: hpm_adc16_drv.h:130
bool port3_realtime
Definition: hpm_adc16_drv.h:129
uint8_t conv_mode
Definition: hpm_adc16_drv.h:127
uint32_t adc_clk_div
Definition: hpm_adc16_drv.h:128
ADC16 DMA configuration struct.
Definition: hpm_adc16_drv.h:153
uint32_t buff_len_in_4bytes
Definition: hpm_adc16_drv.h:155
uint32_t stop_pos
Definition: hpm_adc16_drv.h:156
bool stop_en
Definition: hpm_adc16_drv.h:157
uint32_t * start_addr
Definition: hpm_adc16_drv.h:154
ADC16 trigger configuration struct for the preemption mode.
Definition: hpm_adc16_drv.h:226
uint8_t trig_len
Definition: hpm_adc16_drv.h:230
uint8_t trig_ch
Definition: hpm_adc16_drv.h:229
ADC16 DMA configuration struct for the preemption mode.
Definition: hpm_adc16_drv.h:192
uint32_t cycle_bit
Definition: hpm_adc16_drv.h:198
uint32_t adc_ch
Definition: hpm_adc16_drv.h:195
uint32_t trig_ch
Definition: hpm_adc16_drv.h:196
uint32_t seq_num
Definition: hpm_adc16_drv.h:197
uint32_t result
Definition: hpm_adc16_drv.h:193
ADC16 configuration struct for the period mode.
Definition: hpm_adc16_drv.h:203
uint8_t prescale
Definition: hpm_adc16_drv.h:205
uint8_t ch
Definition: hpm_adc16_drv.h:204
uint8_t period_count
Definition: hpm_adc16_drv.h:206
ADC16 configuration struct for the sequence mode.
Definition: hpm_adc16_drv.h:216
bool hw_trig_en
Definition: hpm_adc16_drv.h:221
bool sw_trig_en
Definition: hpm_adc16_drv.h:220
bool cont_en
Definition: hpm_adc16_drv.h:219
uint8_t seq_len
Definition: hpm_adc16_drv.h:222
bool restart_en
Definition: hpm_adc16_drv.h:218
ADC16 DMA configuration struct for the sequence mode.
Definition: hpm_adc16_drv.h:171
uint32_t adc_ch
Definition: hpm_adc16_drv.h:174
uint32_t result
Definition: hpm_adc16_drv.h:172
uint32_t cycle_bit
Definition: hpm_adc16_drv.h:176
uint32_t seq_num
Definition: hpm_adc16_drv.h:173
ADC16 queue configuration struct for the sequence mode.
Definition: hpm_adc16_drv.h:210
bool seq_int_en
Definition: hpm_adc16_drv.h:211
uint8_t ch
Definition: hpm_adc16_drv.h:212