Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Analog-Front-End Controller

See Quickstart guide for SAM AFEC driver.

Driver for the Analog-Front-End Controller. This driver provides access to the main features of the AFEC controller.

Macros

#define AFEC_INTERRUPT_GAP2   (1UL)
 
#define AFEC_SEQ1_CHANNEL_NUM   (8UL)
 
#define AFEC_TEMP_INT_SOURCE_NUM   (15UL)
 
#define NUM_OF_AFEC   (1UL)
 

Functions

void AFEC0_Handler (void)
 Interrupt handler for AFEC0. More...
 
void AFEC1_Handler (void)
 Interrupt handler for AFEC1. More...
 
void afec_ch_get_config_defaults (struct afec_ch_config *const cfg)
 Get the AFEC channel default configurations. More...
 
void afec_ch_set_config (Afec *const afec, const enum afec_channel_num channel, struct afec_ch_config *config)
 Configure the AFEC channel. More...
 
void afec_configure_sequence (Afec *const afec, const enum afec_channel_num ch_list[], uint8_t uc_num)
 Configure conversion sequence. More...
 
void afec_disable (Afec *const afec)
 Disable AFEC Module. More...
 
void afec_disable_interrupt (Afec *const afec, enum afec_interrupt_source interrupt_source)
 Disable AFEC interrupts. More...
 
void afec_enable (Afec *const afec)
 Enable AFEC Module. More...
 
void afec_enable_interrupt (Afec *const afec, enum afec_interrupt_source interrupt_source)
 Enable AFEC interrupts. More...
 
static uint32_t afec_find_inst_num (Afec *const afec)
 Get AFEC instance number. More...
 
static uint32_t afec_find_pid (Afec *const afec)
 Get AFEC Peripheral ID. More...
 
void afec_get_config_defaults (struct afec_config *const cfg)
 Get the AFEC default configurations. More...
 
enum status_code afec_init (Afec *const afec, struct afec_config *config)
 Initialize the AFEC Module. More...
 
static void afec_interrupt (uint8_t inst_num, enum afec_interrupt_source source)
 Common AFEC interrupt handler. More...
 
static void afec_process_callback (Afec *const afec)
 Call the callback function if the corresponding interrupt is asserted. More...
 
void afec_set_callback (Afec *const afec, enum afec_interrupt_source source, afec_callback_t callback, uint8_t irq_level)
 Set callback for AFEC. More...
 
void afec_set_comparison_mode (Afec *const afec, const enum afec_cmp_mode mode, const enum afec_channel_num channel, uint8_t cmp_filter)
 Configure comparison mode. More...
 
static void afec_set_config (Afec *const afec, struct afec_config *config)
 Configure the AFEC Module. More...
 
void afec_set_power_mode (Afec *const afec, const enum afec_power_mode mode)
 Configure AFEC power mode. More...
 
void afec_temp_sensor_get_config_defaults (struct afec_temp_sensor_config *const cfg)
 Get the AFEC Temperature Sensor default configurations. More...
 
void afec_temp_sensor_set_config (Afec *const afec, struct afec_temp_sensor_config *config)
 Configure the AFEC temperature sensor. More...
 

Variables

afec_callback_t afec_callback_pointer [NUM_OF_AFEC][_AFEC_NUM_OF_INTERRUPT_SOURCE]
 

#define AFEC_INTERRUPT_GAP2   (1UL)
#define AFEC_SEQ1_CHANNEL_NUM   (8UL)

Referenced by afec_configure_sequence().

#define AFEC_TEMP_INT_SOURCE_NUM   (15UL)
#define NUM_OF_AFEC   (1UL)

void AFEC0_Handler ( void  )

Interrupt handler for AFEC0.

References afec_process_callback().

void AFEC1_Handler ( void  )

Interrupt handler for AFEC1.

References afec_process_callback().

void afec_ch_get_config_defaults ( struct afec_ch_config *const  cfg)

Get the AFEC channel default configurations.

Use to initialize the configuration structure to known default values.

The default configuration is as follows:

  • Single Ended Mode
  • Gain value is 1
Parameters
cfgPointer to channel configuration structure to be initiated.

References AFEC_GAINVALUE_1, Assert, afec_ch_config::diff, and afec_ch_config::gain.

void afec_ch_set_config ( Afec *const  afec,
const enum afec_channel_num  channel,
struct afec_ch_config config 
)

Configure the AFEC channel.

Parameters
afecBase address of the AFEC
channelThe channel number
configConfiguration for the AFEC channel

References afec_ch_sanity_check(), afec_ch_config::diff, and afec_ch_config::gain.

void afec_configure_sequence ( Afec *const  afec,
const enum afec_channel_num  ch_list[],
uint8_t  uc_num 
)

Configure conversion sequence.

Parameters
afecBase address of the AFEC.
ch_listChannel sequence list.
uc_numNumber of channels in the list.

References AFEC_SEQ1_CHANNEL_NUM.

void afec_disable ( Afec *const  afec)

Disable AFEC Module.

Parameters
afecBase address of the AFEC

References afec_find_pid(), Assert, pmc_disable_periph_clk(), SLEEPMGR_SLEEP_WFI, and sleepmgr_unlock_mode().

void afec_disable_interrupt ( Afec *const  afec,
enum afec_interrupt_source  interrupt_source 
)

Disable AFEC interrupts.

Parameters
afecBase address of the AFEC.
interrupt_sourceInterrupts to be disabled.

References AFEC_INTERRUPT_GAP2, and AFEC_TEMP_INT_SOURCE_NUM.

Referenced by afec_set_comp_flag(), and afec_set_data_ready_flag().

void afec_enable ( Afec *const  afec)

Enable AFEC Module.

Parameters
afecBase address of the AFEC

References afec_find_pid(), Assert, pmc_enable_periph_clk(), sleepmgr_lock_mode(), and SLEEPMGR_SLEEP_WFI.

Referenced by main().

void afec_enable_interrupt ( Afec *const  afec,
enum afec_interrupt_source  interrupt_source 
)

Enable AFEC interrupts.

Parameters
afecBase address of the AFEC.
interrupt_sourceInterrupts to be enabled.

References AFEC_INTERRUPT_GAP2, and AFEC_TEMP_INT_SOURCE_NUM.

Referenced by afec_set_callback().

static uint32_t afec_find_inst_num ( Afec *const  afec)
static

Get AFEC instance number.

Parameters
afecBase address of the AFEC
Returns
AFEC instance number

Referenced by afec_process_callback(), and afec_set_callback().

static uint32_t afec_find_pid ( Afec *const  afec)
static

Get AFEC Peripheral ID.

Parameters
afecBase address of the AFEC
Returns
AFEC Peripheral ID

Referenced by afec_disable(), and afec_enable().

void afec_get_config_defaults ( struct afec_config *const  cfg)

Get the AFEC default configurations.

Use to initialize the configuration structure to known default values. This function should be called at the start of any AFEC initiation.

The default configuration is as follows:

  • 12 -bit resolution
  • AFEC clock frequency is 6MHz
  • Start Up Time is 64 periods AFEC clock, for SAMV71 is 24 periods AFEC clock
  • Analog Settling Time is 3 periods of AFEC clock
  • Tracking Time is 3 periods of AFEC clock
  • Transfer Period is 5 periods AFEC clock,for SAMV71 is 7 periods AFEC clock
  • Allows different analog settings for each channel
  • The controller converts channels in a simple numeric order
  • Appends the channel number to the conversion result in AFE_LDCR register
  • Only a Single Trigger is required to get an averaged value
  • AFE Bias Current Control value is 1
Parameters
cfgPointer to configuration structure to be initiated.

References AFEC_12_BITS, afec_config::afec_clock, AFEC_STARTUP_TIME_4, afec_config::anach, Assert, afec_config::ibctl, afec_config::mck, afec_config::resolution, afec_config::startup_time, afec_config::stm, sysclk_get_cpu_hz(), afec_config::tag, afec_config::tracktim, afec_config::transfer, and afec_config::useq.

Referenced by main().

enum status_code afec_init ( Afec *const  afec,
struct afec_config config 
)

Initialize the AFEC Module.

Parameters
afecBase address of the AFEC
configConfiguration for the AFEC
Return values
STATUS_OKInitialization is finished.
STATUS_ERR_BUSYInitialization failed.

References afec_callback_pointer, afec_get_interrupt_status(), afec_set_config(), Assert, STATUS_ERR_BUSY, and STATUS_OK.

Referenced by main().

static void afec_interrupt ( uint8_t  inst_num,
enum afec_interrupt_source  source 
)
static

Common AFEC interrupt handler.

The optional callback used by the interrupt handler is set by the afec_set_callback() function.

Parameters
inst_numAFEC instance number to handle interrupt for
sourceInterrupt source number

References afec_callback_pointer.

Referenced by afec_process_callback().

static void afec_process_callback ( Afec *const  afec)
static

Call the callback function if the corresponding interrupt is asserted.

Parameters
afecBase address of the AFEC.

References afec_find_inst_num(), afec_get_interrupt_mask(), afec_get_interrupt_status(), afec_interrupt(), AFEC_INTERRUPT_GAP2, and AFEC_TEMP_INT_SOURCE_NUM.

Referenced by AFEC0_Handler(), and AFEC1_Handler().

void afec_set_callback ( Afec *const  afec,
enum afec_interrupt_source  source,
afec_callback_t  callback,
uint8_t  irq_level 
)

Set callback for AFEC.

Parameters
afecBase address of the AFEC
sourceInterrupt source
callbackCallback function pointer
irq_levelInterrupt level

References afec_callback_pointer, afec_enable_interrupt(), afec_find_inst_num(), Assert, and irq_register_handler.

Referenced by run_afec_comp_test(), and run_afec_tc_trig_test().

void afec_set_comparison_mode ( Afec *const  afec,
const enum afec_cmp_mode  mode,
const enum afec_channel_num  channel,
uint8_t  cmp_filter 
)

Configure comparison mode.

Parameters
afecBase address of the AFEC.
modeComparison mode.
channelComparison Selected Channel.
cmp_filterCompare Event Filtering.

References afec_ch_sanity_check().

Referenced by run_afec_comp_test().

static void afec_set_config ( Afec *const  afec,
struct afec_config config 
)
static
void afec_set_power_mode ( Afec *const  afec,
const enum afec_power_mode  mode 
)

Configure AFEC power mode.

Parameters
afecBase address of the AFEC.
modeAFEC power mode value.

References AFEC_POWER_MODE_0, AFEC_POWER_MODE_1, and AFEC_POWER_MODE_2.

void afec_temp_sensor_get_config_defaults ( struct afec_temp_sensor_config *const  cfg)

Get the AFEC Temperature Sensor default configurations.

Use to initialize the configuration structure to known default values.

The default configuration is as follows:

  • The temperature sensor measure is not triggered by RTC event
  • Generates an event when the converted data is in the comparison window
  • The window range is 0xFF ~ 0xFFF
Parameters
cfgPointer to temperature sensor configuration structure to be initiated.

References AFEC_TEMP_CMP_MODE_2, Assert, afec_temp_sensor_config::high_threshold, afec_temp_sensor_config::low_threshold, afec_temp_sensor_config::mode, and afec_temp_sensor_config::rctc.

void afec_temp_sensor_set_config ( Afec *const  afec,
struct afec_temp_sensor_config config 
)

Configure the AFEC temperature sensor.

Parameters
afecBase address of the AFEC
configConfiguration for the AFEC temperature sensor

References Assert, afec_temp_sensor_config::high_threshold, afec_temp_sensor_config::low_threshold, afec_temp_sensor_config::mode, and afec_temp_sensor_config::rctc.

afec_callback_t afec_callback_pointer[NUM_OF_AFEC][_AFEC_NUM_OF_INTERRUPT_SOURCE]