RA Flexible Software Package Documentation  Release v5.5.0

 
ADC Interface

Detailed Description

Interface for A/D Converters.

Summary

The ADC interface provides standard ADC functionality including one-shot mode (single scan), continuous scan and group scan. It also allows configuration of hardware and software triggers for starting scans. After each conversion an interrupt can be triggered, and if a callback function is provided, the call back is invoked with the appropriate event information.

Data Structures

struct  adc_status_t
 
struct  adc_callback_args_t
 
struct  adc_info_t
 
struct  adc_cfg_t
 
struct  adc_api_t
 
struct  adc_instance_t
 

Typedefs

typedef void adc_ctrl_t
 

Enumerations

enum  adc_mode_t
 
enum  adc_resolution_t
 
enum  adc_alignment_t
 
enum  adc_trigger_t
 
enum  adc_event_t
 
enum  adc_channel_t
 
enum  adc_group_id_t
 
enum  adc_group_mask_t
 
enum  adc_state_t
 

Data Structure Documentation

◆ adc_status_t

struct adc_status_t

ADC status.

Data Fields
adc_state_t state Current state.

◆ adc_callback_args_t

struct adc_callback_args_t

ADC callback arguments definitions

Data Fields
uint16_t unit ADC device in use.
adc_event_t event ADC callback event.
void const * p_context Placeholder for user data.
adc_channel_t channel Channel of conversion result.
uint64_t channel_mask Channel mask for conversion result. Only valid for r_adc_b and r_sdadc_b.
adc_group_mask_t group_mask Group Mask.

◆ adc_info_t

struct adc_info_t

ADC Information Structure for Transfer Interface

Data Fields
__I void * p_address The address to start reading the data from.
uint32_t length The total number of transfers to read.
transfer_size_t transfer_size The size of each transfer.
elc_peripheral_t elc_peripheral Name of the peripheral in the ELC list.
elc_event_t elc_event Name of the ELC event for the peripheral.
uint32_t calibration_data Temperature sensor calibration data (0xFFFFFFFF if unsupported) for reference voltage.
int16_t slope_microvolts Temperature sensor slope in microvolts/degrees C.
bool calibration_ongoing Calibration is in progress.

◆ adc_cfg_t

struct adc_cfg_t

ADC general configuration

Data Fields

uint16_t unit
 ADC unit to be used.
 
adc_mode_t mode
 ADC operation mode.
 
adc_resolution_t resolution
 ADC resolution.
 
adc_alignment_t alignment
 Specify left or right alignment; ignored if addition used.
 
adc_trigger_t trigger
 Default and Group A trigger source.
 
IRQn_Type scan_end_irq
 Scan end IRQ number.
 
IRQn_Type scan_end_b_irq
 Scan end group B IRQ number.
 
IRQn_Type scan_end_c_irq
 Scan end group C IRQ number.
 
uint8_t scan_end_ipl
 Scan end interrupt priority.
 
uint8_t scan_end_b_ipl
 Scan end group B interrupt priority.
 
uint8_t scan_end_c_ipl
 Scan end group C interrupt priority.
 
void(* p_callback )(adc_callback_args_t *p_args)
 Callback function; set to NULL for none.
 
void const * p_context
 Placeholder for user data. Passed to the user callback in adc_callback_args_t.
 
void const * p_extend
 Extension parameter for hardware specific settings.
 

◆ adc_api_t

struct adc_api_t

ADC functions implemented at the HAL layer will follow this API.

Data Fields

fsp_err_t(* open )(adc_ctrl_t *const p_ctrl, adc_cfg_t const *const p_cfg)
 
fsp_err_t(* scanCfg )(adc_ctrl_t *const p_ctrl, void const *const p_extend)
 
fsp_err_t(* scanStart )(adc_ctrl_t *const p_ctrl)
 
fsp_err_t(* scanGroupStart )(adc_ctrl_t *p_ctrl, adc_group_mask_t group_mask)
 
fsp_err_t(* scanStop )(adc_ctrl_t *const p_ctrl)
 
fsp_err_t(* scanStatusGet )(adc_ctrl_t *const p_ctrl, adc_status_t *p_status)
 
fsp_err_t(* read )(adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data)
 
fsp_err_t(* read32 )(adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data)
 
fsp_err_t(* calibrate )(adc_ctrl_t *const p_ctrl, void const *p_extend)
 
fsp_err_t(* offsetSet )(adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t const offset)
 
fsp_err_t(* callbackSet )(adc_ctrl_t *const p_ctrl, void(*p_callback)(adc_callback_args_t *), void const *const p_context, adc_callback_args_t *const p_callback_memory)
 
fsp_err_t(* close )(adc_ctrl_t *const p_ctrl)
 
fsp_err_t(* infoGet )(adc_ctrl_t *const p_ctrl, adc_info_t *const p_adc_info)
 

Field Documentation

◆ open

fsp_err_t(* adc_api_t::open) (adc_ctrl_t *const p_ctrl, adc_cfg_t const *const p_cfg)

Initialize ADC Unit; apply power, set the operational mode, trigger sources, interrupt priority, and configurations common to all channels and sensors.

Precondition
Configure peripheral clocks, ADC pins and IRQs prior to calling this function.
Parameters
[in]p_ctrlPointer to control handle structure
[in]p_cfgPointer to configuration structure

◆ scanCfg

fsp_err_t(* adc_api_t::scanCfg) (adc_ctrl_t *const p_ctrl, void const *const p_extend)

Configure the scan including the channels, groups, and scan triggers to be used for the unit that was initialized in the open call. Some configurations are not supported for all implementations. See implementation for details.

Parameters
[in]p_ctrlPointer to control handle structure
[in]p_extendSee implementation for details

◆ scanStart

fsp_err_t(* adc_api_t::scanStart) (adc_ctrl_t *const p_ctrl)

Start the scan (in case of a software trigger), or enable the hardware trigger.

Parameters
[in]p_ctrlPointer to control handle structure

◆ scanGroupStart

fsp_err_t(* adc_api_t::scanGroupStart) (adc_ctrl_t *p_ctrl, adc_group_mask_t group_mask)

Start the scan group (in case of a software trigger), or enable the hardware trigger.

Parameters
[in]p_ctrlPointer to control handle structure
[in]group_maskMask of groups to start

◆ scanStop

fsp_err_t(* adc_api_t::scanStop) (adc_ctrl_t *const p_ctrl)

Stop the ADC scan (in case of a software trigger), or disable the hardware trigger.

Parameters
[in]p_ctrlPointer to control handle structure

◆ scanStatusGet

fsp_err_t(* adc_api_t::scanStatusGet) (adc_ctrl_t *const p_ctrl, adc_status_t *p_status)

Check scan status.

Parameters
[in]p_ctrlPointer to control handle structure
[out]p_statusPointer to store current status in

◆ read

fsp_err_t(* adc_api_t::read) (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data)

Read ADC conversion result.

Parameters
[in]p_ctrlPointer to control handle structure
[in]reg_idADC channel to read (see enumeration adc_channel_t)
[in]p_dataPointer to variable to load value into.

◆ read32

fsp_err_t(* adc_api_t::read32) (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data)

Read ADC conversion result into a 32-bit word.

Parameters
[in]p_ctrlPointer to control handle structure
[in]reg_idADC channel to read (see enumeration adc_channel_t)
[in]p_dataPointer to variable to load value into.

◆ calibrate

fsp_err_t(* adc_api_t::calibrate) (adc_ctrl_t *const p_ctrl, void const *p_extend)

Calibrate ADC or associated PGA (programmable gain amplifier). The driver may require implementation specific arguments to the p_extend input. Not supported for all implementations. See implementation for details.

Parameters
[in]p_ctrlPointer to control handle structure
[in]p_extendPointer to implementation specific arguments

◆ offsetSet

fsp_err_t(* adc_api_t::offsetSet) (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t const offset)

Set offset for input PGA configured for differential input. Not supported for all implementations. See implementation for details.

Parameters
[in]p_ctrlPointer to control handle structure
[in]reg_idADC channel to read (see enumeration adc_channel_t)
[in]offsetSee implementation for details.

◆ callbackSet

fsp_err_t(* adc_api_t::callbackSet) (adc_ctrl_t *const p_ctrl, void(*p_callback)(adc_callback_args_t *), void const *const p_context, adc_callback_args_t *const p_callback_memory)

Specify callback function and optional context pointer and working memory pointer.

Parameters
[in]p_ctrlPointer to the ADC control block.
[in]p_callbackCallback function
[in]p_contextPointer to send to callback function
[in]p_working_memoryPointer to volatile memory where callback structure can be allocated. Callback arguments allocated here are only valid during the callback.

◆ close

fsp_err_t(* adc_api_t::close) (adc_ctrl_t *const p_ctrl)

Close the specified ADC unit by ending any scan in progress, disabling interrupts, and removing power to the specified A/D unit.

Parameters
[in]p_ctrlPointer to control handle structure

◆ infoGet

fsp_err_t(* adc_api_t::infoGet) (adc_ctrl_t *const p_ctrl, adc_info_t *const p_adc_info)

Return the ADC data register address of the first (lowest number) channel and the total number of bytes to be read in order for the DTC/DMAC to read the conversion results of all configured channels. Return the temperature sensor calibration and slope data.

Parameters
[in]p_ctrlPointer to control handle structure
[out]p_adc_infoPointer to ADC information structure

◆ adc_instance_t

struct adc_instance_t

This structure encompasses everything that is needed to use an instance of this interface.

Data Fields
adc_ctrl_t * p_ctrl Pointer to the control structure for this instance.
adc_cfg_t const * p_cfg Pointer to the configuration structure for this instance.
void const * p_channel_cfg Pointer to the channel configuration structure for this instance.
adc_api_t const * p_api Pointer to the API structure for this instance.

Typedef Documentation

◆ adc_ctrl_t

typedef void adc_ctrl_t

ADC control block. Allocate using driver instance control structure from driver instance header file.

Enumeration Type Documentation

◆ adc_mode_t

enum adc_mode_t

ADC operation mode definitions

Enumerator
ADC_MODE_SINGLE_SCAN 

Single scan - one or more channels.

ADC_MODE_GROUP_SCAN 

Two trigger sources to trigger scan for two groups which contain one or more channels.

ADC_MODE_CONTINUOUS_SCAN 

Continuous scan - one or more channels.

◆ adc_resolution_t

enum adc_resolution_t

ADC data resolution definitions

Enumerator
ADC_RESOLUTION_10_BIT 

10 bit resolution

ADC_RESOLUTION_8_BIT 

8 bit resolution

ADC_RESOLUTION_12_BIT 

12 bit resolution

ADC_RESOLUTION_12_BIT 

12 bit resolution

ADC_RESOLUTION_10_BIT 

10 bit resolution

ADC_RESOLUTION_8_BIT 

8 bit resolution

ADC_RESOLUTION_14_BIT 

14 bit resolution

ADC_RESOLUTION_16_BIT 

16 bit resolution

ADC_RESOLUTION_24_BIT 

24 bit resolution

◆ adc_alignment_t

ADC data alignment definitions

Enumerator
ADC_ALIGNMENT_RIGHT 

Data alignment right.

ADC_ALIGNMENT_LEFT 

Data alignment left.

◆ adc_trigger_t

ADC trigger mode definitions

Enumerator
ADC_TRIGGER_SOFTWARE 

Software trigger; not for group modes.

ADC_TRIGGER_SYNC_ELC 

Synchronous trigger via ELC.

ADC_TRIGGER_ASYNC_EXTERNAL 

External asynchronous trigger; not for group modes.

◆ adc_event_t

ADC callback event definitions

Enumerator
ADC_EVENT_SCAN_COMPLETE 

Normal/Group A scan complete.

ADC_EVENT_SCAN_COMPLETE_GROUP_B 

Group B scan complete.

ADC_EVENT_SCAN_COMPLETE_GROUP_C 

Group C scan complete.

ADC_EVENT_CALIBRATION_COMPLETE 

Calibration complete.

ADC_EVENT_CONVERSION_COMPLETE 

Conversion complete.

ADC_EVENT_CALIBRATION_REQUEST 

Calibration requested.

ADC_EVENT_CONVERSION_ERROR 

Scan error.

ADC_EVENT_OVERFLOW 

Overflow occurred.

ADC_EVENT_LIMIT_CLIP 

Limiter clipping occurred.

ADC_EVENT_FIFO_READ_REQUEST 

FIFO read requested.

ADC_EVENT_FIFO_OVERFLOW 

FIFO overflow occurred.

ADC_EVENT_WINDOW_COMPARE_A 

Window A comparison condition met.

ADC_EVENT_WINDOW_COMPARE_B 

Window B comparison condition met.

ADC_EVENT_ZERO_CROSS_DETECTION 

Zero-cross detection interrupt.

◆ adc_channel_t

enum adc_channel_t

ADC channels

Enumerator
ADC_CHANNEL_0 

ADC channel 0.

ADC_CHANNEL_1 

ADC channel 1.

ADC_CHANNEL_2 

ADC channel 2.

ADC_CHANNEL_3 

ADC channel 3.

ADC_CHANNEL_4 

ADC channel 4.

ADC_CHANNEL_5 

ADC channel 5.

ADC_CHANNEL_6 

ADC channel 6.

ADC_CHANNEL_7 

ADC channel 7.

ADC_CHANNEL_8 

ADC channel 8.

ADC_CHANNEL_9 

ADC channel 9.

ADC_CHANNEL_10 

ADC channel 10.

ADC_CHANNEL_11 

ADC channel 11.

ADC_CHANNEL_12 

ADC channel 12.

ADC_CHANNEL_13 

ADC channel 13.

ADC_CHANNEL_14 

ADC channel 14.

ADC_CHANNEL_15 

ADC channel 15.

ADC_CHANNEL_16 

ADC channel 16.

ADC_CHANNEL_17 

ADC channel 17.

ADC_CHANNEL_18 

ADC channel 18.

ADC_CHANNEL_19 

ADC channel 19.

ADC_CHANNEL_20 

ADC channel 20.

ADC_CHANNEL_21 

ADC channel 21.

ADC_CHANNEL_22 

ADC channel 22.

ADC_CHANNEL_23 

ADC channel 23.

ADC_CHANNEL_24 

ADC channel 24.

ADC_CHANNEL_25 

ADC channel 25.

ADC_CHANNEL_26 

ADC channel 26.

ADC_CHANNEL_27 

ADC channel 27.

ADC_CHANNEL_28 

ADC channel 28.

ADC_CHANNEL_SELF_DIAGNOSIS 

Self-Diagnosis channel.

ADC_CHANNEL_TEMPERATURE 

Temperature sensor output.

ADC_CHANNEL_VOLT 

Internal reference voltage.

ADC_CHANNEL_DA0 

D/A Converter Channel 0.

ADC_CHANNEL_DA1 

D/A Converter Channel 1.

ADC_CHANNEL_DA2 

D/A Converter Channel 2.

ADC_CHANNEL_DA3 

D/A Converter Channel 3.

ADC_CHANNEL_0 

Channel 0 for select mode or channel 0 to 3 for scan mode.

ADC_CHANNEL_1 

Channel 1 for select mode or channel 1 to 4 for scan mode.

ADC_CHANNEL_2 

Channel 2 for select mode or channel 2 to 5 for scan mode.

ADC_CHANNEL_3 

Channel 3 for select mode or channel 3 to 6 for scan mode.

ADC_CHANNEL_4 

Channel 4 for select mode or channel 4 to 7 for scan mode.

ADC_CHANNEL_5 

Channel 5 for select mode.

ADC_CHANNEL_6 

Channel 6 for select mode.

ADC_CHANNEL_7 

Channel 7 for select mode.

ADC_CHANNEL_21 

Channel 21 for select mode.

ADC_CHANNEL_22 

Channel 22 for select mode.

ADC_CHANNEL_TEMPERATURE 

Temperature sensor output voltage for select mode.

ADC_CHANNEL_VOLT 

Internal reference voltage for select mode.

ADC_CHANNEL_POSITIVE_SIDE_VREF 

Select positive reference voltage as target conversion.

ADC_CHANNEL_NEGATIVE_SIDE_VREF 

Select negative reference voltage as target conversion.

ADC_CHANNEL_0 

ADC channel 0.

ADC_CHANNEL_1 

ADC channel 1.

ADC_CHANNEL_2 

ADC channel 2.

ADC_CHANNEL_3 

ADC channel 3.

ADC_CHANNEL_4 

ADC channel 4.

ADC_CHANNEL_5 

ADC channel 5.

ADC_CHANNEL_6 

ADC channel 6.

ADC_CHANNEL_7 

ADC channel 7.

ADC_CHANNEL_8 

ADC channel 8.

ADC_CHANNEL_9 

ADC channel 9.

ADC_CHANNEL_10 

ADC channel 10.

ADC_CHANNEL_11 

ADC channel 11.

ADC_CHANNEL_12 

ADC channel 12.

ADC_CHANNEL_13 

ADC channel 13.

ADC_CHANNEL_14 

ADC channel 14.

ADC_CHANNEL_15 

ADC channel 15.

ADC_CHANNEL_16 

ADC channel 16.

ADC_CHANNEL_17 

ADC channel 17.

ADC_CHANNEL_18 

ADC channel 18.

ADC_CHANNEL_19 

ADC channel 19.

ADC_CHANNEL_20 

ADC channel 20.

ADC_CHANNEL_21 

ADC channel 21.

ADC_CHANNEL_22 

ADC channel 22.

ADC_CHANNEL_23 

ADC channel 23.

ADC_CHANNEL_24 

ADC channel 24.

ADC_CHANNEL_25 

ADC channel 25.

ADC_CHANNEL_26 

ADC channel 26.

ADC_CHANNEL_27 

ADC channel 27.

ADC_CHANNEL_28 

ADC channel 28.

ADC_CHANNEL_DUPLEX_A 

Data duplexing register A.

ADC_CHANNEL_DUPLEX_B 

Data duplexing register B.

ADC_CHANNEL_DUPLEX 

Data duplexing register.

ADC_CHANNEL_TEMPERATURE 

Temperature sensor output.

ADC_CHANNEL_VOLT 

Internal reference voltage.

◆ adc_group_id_t

Enumerator
ADC_GROUP_ID_0 

Group ID 0.

ADC_GROUP_ID_1 

Group ID 1.

ADC_GROUP_ID_2 

Group ID 2.

ADC_GROUP_ID_3 

Group ID 3.

ADC_GROUP_ID_4 

Group ID 4.

ADC_GROUP_ID_5 

Group ID 5.

ADC_GROUP_ID_6 

Group ID 6.

ADC_GROUP_ID_7 

Group ID 7.

ADC_GROUP_ID_8 

Group ID 8.

◆ adc_group_mask_t

Enumerator
ADC_GROUP_MASK_NONE 

Group Mask Unknown or None.

ADC_GROUP_MASK_0 

Group Mask 0.

ADC_GROUP_MASK_1 

Group Mask 1.

ADC_GROUP_MASK_2 

Group Mask 2.

ADC_GROUP_MASK_3 

Group Mask 3.

ADC_GROUP_MASK_4 

Group Mask 4.

ADC_GROUP_MASK_5 

Group Mask 5.

ADC_GROUP_MASK_6 

Group Mask 6.

ADC_GROUP_MASK_7 

Group Mask 7.

ADC_GROUP_MASK_8 

Group Mask 8.

ADC_GROUP_MASK_ALL 

All Groups.

◆ adc_state_t

ADC states.

Enumerator
ADC_STATE_IDLE 

ADC is idle.

ADC_STATE_SCAN_IN_PROGRESS 

ADC scan in progress.

ADC_STATE_CALIBRATION_IN_PROGRESS 

ADC calibration in progress - Not used by all ADC instances.