Analog-to-Digital Converter driver for SAM4L.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
#include "pdca.h"
#include "sysclk.h"
#include "sleepmgr.h"
#include "conf_adcife.h"
#include "status_codes.h"
Data Structures | |
struct | adc_cdma_config |
Parameters for the configuration of the PDCA word. More... | |
struct | adc_cdma_first_config |
Parameters for the configuration of the First CDMA register. More... | |
struct | adc_cdma_second_config |
Parameters for the configuration of the Second CDMA register. More... | |
struct | adc_ch_config |
Parameters for the configuration of the Sequencer. More... | |
struct | adc_config |
ADC Configuration structure. More... | |
struct | adc_dev_inst |
ADC driver software instance structure. More... | |
struct | adc_pdca_config |
Parameters for the configuration of the PDCA word. More... | |
struct | adc_seq_config |
Parameters for the configuration of the Sequencer. More... | |
Macros | |
#define | ADC_NUM_OF_ATTEMPTS 10000 |
Time out value (number of attempts) More... | |
Prescaler Rate Slection | |
#define | ADC_PRESCAL_DIV4 0 |
#define | ADC_PRESCAL_DIV8 1 |
#define | ADC_PRESCAL_DIV16 2 |
#define | ADC_PRESCAL_DIV32 3 |
#define | ADC_PRESCAL_DIV64 4 |
#define | ADC_PRESCAL_DIV128 5 |
#define | ADC_PRESCAL_DIV256 6 |
#define | ADC_PRESCAL_DIV512 7 |
Clock Selection for sequencer/ADC cell | |
#define | ADC_CLKSEL_GCLK 0 |
#define | ADC_CLKSEL_APBCLK 1 |
ADC current reduction | |
#define | ADC_SPEED_300K 0 |
#define | ADC_SPEED_225K 1 |
#define | ADC_SPEED_150K 2 |
#define | ADC_SPEED_75K 3 |
ADC Reference selection | |
#define | ADC_REFSEL_0 0 |
#define | ADC_REFSEL_1 1 |
#define | ADC_REFSEL_2 2 |
#define | ADC_REFSEL_3 3 |
#define | ADC_REFSEL_4 4 |
Zoom shift/unipolar reference source selection | |
#define | ADC_ZOOMRANGE_0 0 |
#define | ADC_ZOOMRANGE_1 1 |
#define | ADC_ZOOMRANGE_2 2 |
#define | ADC_ZOOMRANGE_3 3 |
#define | ADC_ZOOMRANGE_4 4 |
MUX selection on Negative ADC input channel | |
#define | ADC_MUXNEG_0 0 |
#define | ADC_MUXNEG_1 1 |
#define | ADC_MUXNEG_2 2 |
#define | ADC_MUXNEG_3 3 |
#define | ADC_MUXNEG_4 4 |
#define | ADC_MUXNEG_5 5 |
#define | ADC_MUXNEG_6 6 |
#define | ADC_MUXNEG_7 7 |
MUX selection on Positive ADC input channel | |
#define | ADC_MUXPOS_0 0 |
#define | ADC_MUXPOS_1 1 |
#define | ADC_MUXPOS_2 2 |
#define | ADC_MUXPOS_3 3 |
#define | ADC_MUXPOS_4 4 |
#define | ADC_MUXPOS_5 5 |
#define | ADC_MUXPOS_6 6 |
#define | ADC_MUXPOS_7 7 |
#define | ADC_MUXPOS_8 8 |
#define | ADC_MUXPOS_9 9 |
#define | ADC_MUXPOS_10 10 |
#define | ADC_MUXPOS_11 11 |
#define | ADC_MUXPOS_12 12 |
#define | ADC_MUXPOS_13 13 |
#define | ADC_MUXPOS_14 14 |
#define | ADC_MUXPOS_15 15 |
Internal Voltage Sources Selection | |
#define | ADC_INTERNAL_0 0 |
#define | ADC_INTERNAL_1 1 |
#define | ADC_INTERNAL_2 2 |
#define | ADC_INTERNAL_3 3 |
Resolution | |
#define | ADC_RES_8_BIT 1 |
#define | ADC_RES_12_BIT 0 |
Gain Compensation | |
#define | ADC_GCOMP_EN 1 |
#define | ADC_GCOMP_DIS 0 |
Bipolar Mode | |
#define | ADC_BIPOLAR_SINGLEENDED 0 |
#define | ADC_BIPOLAR_DIFFERENTIAL 1 |
Half Word Left Adjust | |
#define | ADC_HWLA_EN 1 |
#define | ADC_HWLA_DIS 0 |
Window Monitor Mode | |
#define | ADC_WM_OFF 0 |
#define | ADC_WM_MODE_1 1 |
#define | ADC_WM_MODE_2 2 |
#define | ADC_WM_MODE_3 3 |
#define | ADC_WM_MODE_4 4 |
Typedefs | |
typedef void(* | adc_callback_t )(void) |
typedef enum adc_interrupt_source | adc_interrupt_source_t |
ADC interrupt source type. More... | |
Enumerations | |
enum | adc_gain_t { ADC_GAIN_1X = 0, ADC_GAIN_2X, ADC_GAIN_4X, ADC_GAIN_8X, ADC_GAIN_16X, ADC_GAIN_32X, ADC_GAIN_64X, ADC_GAIN_HALF } |
Definitions for ADC gain. More... | |
enum | adc_interrupt_source { ADC_SEQ_SEOC = ADCIFE_IER_SEOC, ADC_SEQ_LOVR = ADCIFE_IER_LOVR, ADC_WINDOW_MONITOR = ADCIFE_IER_WM, ADC_SEQ_MTRG = ADCIFE_IER_SMTRG, ADC_TTO = ADCIFE_IER_TTO } |
ADC interrupt source type. More... | |
enum | adc_trigger_t { ADC_TRIG_SW = 0, ADC_TRIG_INTL_TIMER, ADC_TRIG_INTL_TRIG_SRC, ADC_TRIG_CON, ADC_TRIG_EXT_PIN_RISE, ADC_TRIG_EXT_PIN_FALL, ADC_TRIG_EXT_PIN_BOTH } |
Definitions for ADC trigger. More... | |
Functions | |
static void | adc_ch_get_config_defaults (struct adc_ch_config *const cfg) |
Initializes an ADC channel configuration structure to defaults. More... | |
void | adc_ch_set_config (struct adc_dev_inst *const dev_inst, struct adc_ch_config *cfg) |
Configure ADC channel with specified value. More... | |
static void | adc_clear_status (struct adc_dev_inst *const dev_inst, const uint32_t status_flags) |
Clear ADC status. More... | |
static void | adc_configure_calibration (struct adc_dev_inst *const dev_inst, const bool fcd, const bool biassel, const uint8_t biascal, const uint8_t calib) |
Configure ADC calibration mode with specified value. More... | |
static void | adc_configure_gain (struct adc_dev_inst *const dev_inst, const enum adc_gain_t gain) |
Configure ADC gain with specified value. More... | |
static void | adc_configure_itimer_period (struct adc_dev_inst *const dev_inst, const uint32_t period) |
Configure ADC internal timer with specified value. More... | |
static void | adc_configure_trigger (struct adc_dev_inst *const dev_inst, const enum adc_trigger_t trigger) |
Configure ADC trigger source with specified value. More... | |
static void | adc_configure_wm_mode (struct adc_dev_inst *const dev_inst, const uint8_t mode) |
Configure ADC window monitor mode with specified value. More... | |
static void | adc_configure_wm_threshold (struct adc_dev_inst *const dev_inst, const uint16_t low_threshold, const uint16_t high_threshold) |
Configure ADC window monitor threshold with specified value. More... | |
void | adc_disable (struct adc_dev_inst *const dev_inst) |
Disable ADC module. More... | |
static void | adc_disable_interrupt (struct adc_dev_inst *const dev_inst, const adc_interrupt_source_t interrupt_source) |
Disable ADC interrupt. More... | |
status_code_t | adc_enable (struct adc_dev_inst *const dev_inst) |
Enable ADC module. More... | |
static void | adc_enable_interrupt (struct adc_dev_inst *const dev_inst, const adc_interrupt_source_t interrupt_source) |
Enable ADC interrupt. More... | |
static void | adc_get_config_defaults (struct adc_config *const cfg) |
Initializes an ADC module configuration structure to defaults. More... | |
static adc_interrupt_source_t | adc_get_interrupt_mask (struct adc_dev_inst *const dev_inst) |
Get ADC interrupt mask. More... | |
static uint8_t | adc_get_last_conv_nchannel (struct adc_dev_inst *const dev_inst) |
Get last converted ADC negative channel. More... | |
static uint8_t | adc_get_last_conv_pchannel (struct adc_dev_inst *const dev_inst) |
Get last ADC converted positive channel. More... | |
static uint16_t | adc_get_last_conv_value (struct adc_dev_inst *const dev_inst) |
Get last ADC converted value. More... | |
static uint32_t | adc_get_status (struct adc_dev_inst *const dev_inst) |
Get ADC status. More... | |
static uint8_t | adc_get_wm_mode (struct adc_dev_inst *const dev_inst) |
Get ADC window monitor mode. More... | |
status_code_t | adc_init (struct adc_dev_inst *const dev_inst, Adcife *const adc, struct adc_config *const cfg) |
Initialize the ADC module. More... | |
static bool | adc_is_busy_itimer (struct adc_dev_inst *const dev_inst) |
Check if internal timer is busy. More... | |
static void | adc_pdca_get_config_defaults (struct adc_pdca_config *const cfg) |
Initializes an ADC PDCA configuration structure to defaults. More... | |
void | adc_pdca_set_config (struct adc_pdca_config *cfg) |
Configure ADC sequencer support multi-channel mode. More... | |
void | adc_set_callback (struct adc_dev_inst *const dev_inst, adc_interrupt_source_t source, adc_callback_t callback, uint8_t irq_line, uint8_t irq_level) |
Set callback for ADC. More... | |
void | adc_set_config (struct adc_dev_inst *const dev_inst, struct adc_config *cfg) |
Configure ADC with specified value. More... | |
static void | adc_start_itimer (struct adc_dev_inst *const dev_inst) |
Start the ADC internal timer. More... | |
static void | adc_start_software_conversion (struct adc_dev_inst *const dev_inst) |
Start ADC software trigger conversion. More... | |
static void | adc_stop_itimer (struct adc_dev_inst *const dev_inst) |
Stop the ADC internal timer. More... | |
#define ADC_BIPOLAR_DIFFERENTIAL 1 |
#define ADC_BIPOLAR_SINGLEENDED 0 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_CLKSEL_APBCLK 1 |
Referenced by adc_get_config_defaults(), and start_adc().
#define ADC_CLKSEL_GCLK 0 |
#define ADC_GCOMP_DIS 0 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_GCOMP_EN 1 |
#define ADC_HWLA_DIS 0 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_HWLA_EN 1 |
#define ADC_INTERNAL_0 0 |
#define ADC_INTERNAL_1 1 |
#define ADC_INTERNAL_2 2 |
#define ADC_INTERNAL_3 3 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_MUXNEG_0 0 |
#define ADC_MUXNEG_1 1 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_MUXNEG_2 2 |
#define ADC_MUXNEG_3 3 |
#define ADC_MUXNEG_4 4 |
#define ADC_MUXNEG_5 5 |
#define ADC_MUXNEG_6 6 |
#define ADC_MUXNEG_7 7 |
#define ADC_MUXPOS_0 0 |
#define ADC_MUXPOS_1 1 |
#define ADC_MUXPOS_10 10 |
#define ADC_MUXPOS_11 11 |
#define ADC_MUXPOS_12 12 |
#define ADC_MUXPOS_13 13 |
#define ADC_MUXPOS_14 14 |
#define ADC_MUXPOS_15 15 |
#define ADC_MUXPOS_2 2 |
Referenced by adc_ch_get_config_defaults().
#define ADC_MUXPOS_3 3 |
Referenced by start_adc().
#define ADC_MUXPOS_4 4 |
#define ADC_MUXPOS_5 5 |
#define ADC_MUXPOS_6 6 |
#define ADC_MUXPOS_7 7 |
#define ADC_MUXPOS_8 8 |
#define ADC_MUXPOS_9 9 |
#define ADC_NUM_OF_ATTEMPTS 10000 |
Time out value (number of attempts)
Referenced by adc_enable().
#define ADC_PRESCAL_DIV128 5 |
#define ADC_PRESCAL_DIV16 2 |
Referenced by adc_get_config_defaults(), and start_adc().
#define ADC_PRESCAL_DIV256 6 |
#define ADC_PRESCAL_DIV32 3 |
#define ADC_PRESCAL_DIV4 0 |
#define ADC_PRESCAL_DIV512 7 |
#define ADC_PRESCAL_DIV64 4 |
#define ADC_PRESCAL_DIV8 1 |
#define ADC_REFSEL_0 0 |
Referenced by start_adc().
#define ADC_REFSEL_1 1 |
Referenced by adc_get_config_defaults().
#define ADC_REFSEL_2 2 |
#define ADC_REFSEL_3 3 |
#define ADC_REFSEL_4 4 |
#define ADC_RES_12_BIT 0 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_RES_8_BIT 1 |
#define ADC_SPEED_150K 2 |
Referenced by adc_get_config_defaults(), and start_adc().
#define ADC_SPEED_225K 1 |
#define ADC_SPEED_300K 0 |
#define ADC_SPEED_75K 3 |
#define ADC_WM_MODE_1 1 |
#define ADC_WM_MODE_2 2 |
#define ADC_WM_MODE_3 3 |
#define ADC_WM_MODE_4 4 |
#define ADC_WM_OFF 0 |
#define ADC_ZOOMRANGE_0 0 |
Referenced by adc_ch_get_config_defaults(), and start_adc().
#define ADC_ZOOMRANGE_1 1 |
#define ADC_ZOOMRANGE_2 2 |
#define ADC_ZOOMRANGE_3 3 |
#define ADC_ZOOMRANGE_4 4 |
typedef void(* adc_callback_t)(void) |
typedef enum adc_interrupt_source adc_interrupt_source_t |
ADC interrupt source type.
enum adc_gain_t |
enum adc_interrupt_source |
enum adc_trigger_t |
|
inlinestatic |
Initializes an ADC channel configuration structure to defaults.
Initializes a given ADC channel configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
The default configuration is as follows:
cfg | ADC channel configuration structure to initialize to default value |
References ADC_BIPOLAR_SINGLEENDED, ADC_GAIN_1X, ADC_GCOMP_DIS, ADC_HWLA_DIS, ADC_INTERNAL_3, ADC_MUXNEG_1, ADC_MUXPOS_2, ADC_RES_12_BIT, ADC_TRIG_SW, ADC_ZOOMRANGE_0, Assert, adc_seq_config::bipolar, adc_seq_config::gain, adc_seq_config::gcomp, adc_ch_config::high_threshold, adc_seq_config::hwla, adc_seq_config::internal, adc_ch_config::internal_timer_max_count, adc_ch_config::low_threshold, adc_seq_config::muxneg, adc_seq_config::muxpos, adc_seq_config::res, adc_ch_config::seq_cfg, adc_seq_config::trgsel, adc_ch_config::window_mode, and adc_seq_config::zoomrange.
|
inlinestatic |
Clear ADC status.
dev_inst | Device structure pointer. |
status_flags | status flag. |
References adc_dev_inst::hw_dev.
Referenced by adcife_read_conv_result().
|
inlinestatic |
Configure ADC calibration mode with specified value.
dev_inst | Device structure pointer. |
fcd | Flash Calibration Done. |
biassel | Select bias mode. |
biascal | Bias calibration. |
calib | Calibration value. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Configure ADC gain with specified value.
dev_inst | Device structure pointer. |
gain | gain value. |
References adc_dev_inst::hw_dev.
Referenced by start_adc().
|
inlinestatic |
Configure ADC internal timer with specified value.
dev_inst | Device structure pointer. |
period | Internal Timer Max Counter |
References adc_dev_inst::hw_dev.
Referenced by start_adc().
|
inlinestatic |
Configure ADC trigger source with specified value.
dev_inst | Device structure pointer. |
trigger | trigger source selection. |
References adc_dev_inst::hw_dev.
Referenced by start_adc().
|
inlinestatic |
Configure ADC window monitor mode with specified value.
dev_inst | Device structure pointer. |
mode | Window Monitor Mode. |
References adc_dev_inst::hw_dev.
Referenced by adc_ch_set_config().
|
inlinestatic |
Configure ADC window monitor threshold with specified value.
dev_inst | Device structure pointer. |
low_threshold | Low Threshold value. |
high_threshold | HighThreshold value. |
References adc_dev_inst::hw_dev.
Referenced by adc_ch_set_config().
|
inlinestatic |
Disable ADC interrupt.
dev_inst | Device structure pointer. |
interrupt_source | interrupt source. |
References adc_dev_inst::hw_dev.
Referenced by main(), and start_adc().
|
inlinestatic |
Enable ADC interrupt.
dev_inst | Device structure pointer. |
interrupt_source | interrupt source. |
References adc_dev_inst::hw_dev.
Referenced by adc_set_callback().
|
inlinestatic |
Initializes an ADC module configuration structure to defaults.
Initializes a given ADC module configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
The default configuration is as follows:
cfg | ADC module configuration structure to initialize to default value |
References ADC_CLKSEL_APBCLK, ADC_PRESCAL_DIV16, ADC_REFSEL_1, ADC_SPEED_150K, Assert, adc_config::clksel, CONFIG_ADC_STARTUP, adc_config::prescal, adc_config::refsel, adc_config::speed, and adc_config::start_up.
|
inlinestatic |
Get ADC interrupt mask.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Get last converted ADC negative channel.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Get last ADC converted positive channel.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Get last ADC converted value.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
Referenced by adcife_read_conv_result().
|
inlinestatic |
Get ADC status.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
Referenced by adcife_read_conv_result().
|
inlinestatic |
Get ADC window monitor mode.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Check if internal timer is busy.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
|
inlinestatic |
Initializes an ADC PDCA configuration structure to defaults.
Initializes a given ADC PDCA configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
cfg | ADC PDCA configuration structure to initialize to default value |
References Assert, adc_pdca_config::buffer, adc_pdca_config::cdma_cfg, CONFIG_ADC_PDCA_RX_CHANNEL, CONFIG_ADC_PDCA_TX_CHANNEL, adc_pdca_config::nb_channels, adc_pdca_config::pdc_rx_channel, and adc_pdca_config::wm.
|
inlinestatic |
Start the ADC internal timer.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
Referenced by start_adc().
|
inlinestatic |
Start ADC software trigger conversion.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.
Referenced by main().
|
inlinestatic |
Stop the ADC internal timer.
dev_inst | Device structure pointer. |
References adc_dev_inst::hw_dev.