Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the AFE HAL driver.

Data Structures

struct  afe_chn_set_t
 Defines the structure to configure the AFE Channel. More...
 
struct  afe_converter_config_t
 Defines the structure to configure the AFE converter. More...
 

Enumerations

enum  afe_status_t {
  kStatus_AFE_Success = 0U,
  kStatus_AFE_InvalidArgument = 1U,
  kStatus_AFE_Failed = 2U
}
 AFE status return codes. More...
 
enum  afe_chn_osr_mode_t {
  kAfeDecimOsrOf64 = 0U,
  kAfeDecimOsrOf128 = 1U,
  kAfeDecimOsrOf256 = 2U,
  kAfeDecimOsrOf512 = 3U,
  kAfeDecimOsrOf1024 = 4U,
  kAfeDecimOsrOf2048 = 5U
}
 AFE OSR modes. More...
 
enum  afe_pga_gain_mode_t {
  kAfePgaGainBy1 = 1U,
  kAfePgaGainBy2 = 2U,
  kAfePgaGainBy4 = 3U,
  kAfePgaGainBy8 = 4U,
  kAfePgaGainBy16 = 5U,
  kAfePgaGainBy32 = 6U
}
 AFE PGA modes. More...
 
enum  afe_result_format_mode_t {
  kAfeResultFormatLeft = 0U,
  kAfeResultFormatRight = 1U
}
 Defines the AFE result format modes. More...
 
enum  afe_clk_divider_mode_t {
  kAfeClkDividerInputOf1 = 0U,
  kAfeClkDividerInputOf2 = 1U,
  kAfeClkDividerInputOf4 = 2U,
  kAfeClkDividerInputOf8 = 3U,
  kAfeClkDividerInputOf16 = 4U,
  kAfeClkDividerInputOf32 = 5U,
  kAfeClkDividerInputOf64 = 6U,
  kAfeClkDividerInputOf128 = 7U,
  kAfeClkDividerInputOf256 = 8U
}
 Defines the AFE clock divider modes. More...
 
enum  afe_clk_src_mode_t {
  kAfeClkSrcClk0 = 0U,
  kAfeClkSrcClk1 = 1U,
  kAfeClkSrcClk2 = 2U,
  kAfeClkSrcClk3 = 3U
}
 Defines the AFE clock source modes. More...
 

AFE Channel Configurations

void AFE_HAL_ChnInit (AFE_Type *base, uint32_t chn)
 Resets the channel registers into a reset state. More...
 
static void AFE_HAL_SetIntEnableCmd (AFE_Type *base, uint32_t chn, bool enable)
 Sets the interrupt request on conversion complete event. More...
 
static void AFE_HAL_SetDmaEnableCmd (AFE_Type *base, uint32_t chn, bool enable)
 Sets the DMA request on conversion complete event. More...
 
static void AFE_HAL_SetDelayVal (AFE_Type *base, uint32_t chn, int32_t delay)
 Sets the delay value. More...
 
static int32_t AFE_HAL_GetDelayVal (AFE_Type *base, uint32_t chn)
 Gets the delay value. More...
 
static uint32_t AFE_HAL_GetResult (AFE_Type *base, uint32_t chn)
 Gets the measurement result. More...
 
static bool AFE_HAL_GetConvCompleteFlag (AFE_Type *base, uint32_t chn)
 Checks whether a conversion is completed. More...
 
static bool AFE_HAL_GetOverflowFlag (AFE_Type *base, uint32_t chn)
 Checks whether the selected channel has overflown. More...
 
static bool AFE_HAL_GetReadyFlag (AFE_Type *base, uint32_t chn)
 Checks whether the selected channel is ready for conversion. More...
 

AFE Common Configurations

void AFE_HAL_Init (AFE_Type *base)
 Resets all registers into a reset state for the AFE module. More...
 
static void AFE_HAL_SetMasterEnableCmd (AFE_Type *base, bool enable)
 Enables all ADCs and filters. More...
 
static void AFE_HAL_ChnSwTriggerCmd (AFE_Type *base, uint32_t chnMask)
 Triggers conversion on the AFE channels. More...
 
static void AFE_HAL_SetLowPowerCmd (AFE_Type *base, bool enable)
 Sets a low power mode. More...
 
static void AFE_HAL_SetSwResetCmd (AFE_Type *base, bool enable)
 Sets the software reset. More...
 
static void AFE_HAL_SetDelayOkCmd (AFE_Type *base)
 Asserts the delay OK. More...
 
static void AFE_HAL_SetResultFormatMode (AFE_Type *base, afe_result_format_mode_t mode)
 Selects the result format mode. More...
 
static afe_result_format_mode_t AFE_HAL_GetResultFormatMode (AFE_Type *base)
 Gets the conversion resolution mode. More...
 
static void AFE_HAL_SetStartUpDelayVal (AFE_Type *base, int32_t startDelay)
 Sets the start up count value. More...
 
static void AFE_HAL_SetClkDividerMode (AFE_Type *base, afe_clk_divider_mode_t mode)
 Selects the clock divider mode. More...
 
static void AFE_HAL_SetClkSourceMode (AFE_Type *base, afe_clk_src_mode_t mode)
 Selects the input clock source for the AFE module. More...
 
static void AFE_HAL_SetDmaIntReq (AFE_Type *base, uint32_t data)
 Sets the DMA and interrupt requests for all channels. More...
 
void AFE_HAL_ConfigChn (AFE_Type *base, uint32_t chn, afe_chn_set_t *chnStructPtr)
 Configures the AFE channel. More...
 
void AFE_HAL_ConfigConverter (AFE_Type *base, afe_converter_config_t *converterStructPtr)
 Configures the AFE converter. More...
 

Data Structure Documentation

struct afe_chn_set_t

Data Fields

bool hwTriggerEnable
 Enable triggering by hardware. More...
 
bool continuousConvEnable
 Enable continuous conversion mode. More...
 
bool bypassEnable
 Enable bypass mode that modulator and PGA of this channel are disabled. More...
 
afe_pga_gain_mode_t pgaGainSel
 Select the analog gain applied to the input signal. More...
 
bool pgaEnable
 Enable the analog gain. More...
 
afe_chn_osr_mode_t decimOSR
 Select the over sampling ration. More...
 
bool modulatorEnable
 Enable sigma delta modulator. More...
 
bool decimFilterEnable
 Enable decimation filter.
 
bool decimNegedgeEnable
 Enable falling edge for decimator input.
 
bool externClockEnable
 Enable external clock for decimator.
 

Field Documentation

bool afe_chn_set_t::hwTriggerEnable
bool afe_chn_set_t::continuousConvEnable
bool afe_chn_set_t::bypassEnable
afe_pga_gain_mode_t afe_chn_set_t::pgaGainSel
bool afe_chn_set_t::pgaEnable
afe_chn_osr_mode_t afe_chn_set_t::decimOSR
bool afe_chn_set_t::modulatorEnable
struct afe_converter_config_t

Data Fields

uint8_t startupCnt
 Set startup delay of modulators. More...
 
afe_result_format_mode_t resultFormat
 Select the result format. More...
 
bool delayOk
 Confirm delay registers. More...
 
bool swReset
 Do a software reset. More...
 
bool lowPowerEnable
 Enable low power mode. More...
 
bool swTriggChn0
 Trigger conversion on channel 0. More...
 
bool swTriggChn1
 Trigger conversion on channel 1. More...
 
bool swTriggChn2
 Trigger conversion on channel 2. More...
 
bool masterEnable
 Enable all ADCs and filters simultaneously whose modulatorEnable and decimFilterEnable is asserted. More...
 

Field Documentation

uint8_t afe_converter_config_t::startupCnt
afe_result_format_mode_t afe_converter_config_t::resultFormat
bool afe_converter_config_t::delayOk
bool afe_converter_config_t::swReset
bool afe_converter_config_t::lowPowerEnable
bool afe_converter_config_t::swTriggChn0
bool afe_converter_config_t::swTriggChn1
bool afe_converter_config_t::swTriggChn2
bool afe_converter_config_t::masterEnable

Enumeration Type Documentation

Enumerator
kStatus_AFE_Success 

Success.

kStatus_AFE_InvalidArgument 

Invalid argument existed.

kStatus_AFE_Failed 

Execution failed.

Enumerator
kAfeDecimOsrOf64 

Decimator over sampling ratio is 64.

kAfeDecimOsrOf128 

Decimator over sampling ratio is 128.

kAfeDecimOsrOf256 

Decimator over sampling ratio is 256.

kAfeDecimOsrOf512 

Decimator over sampling ratio is 512.

kAfeDecimOsrOf1024 

Decimator over sampling ratio is 1024.

kAfeDecimOsrOf2048 

Decimator over sampling ratio is 2048.

Enumerator
kAfePgaGainBy1 

Input gained by 1.

kAfePgaGainBy2 

Input gained by 2.

kAfePgaGainBy4 

Input gained by 4.

kAfePgaGainBy8 

Input gained by 8.

kAfePgaGainBy16 

Input gained by 16.

kAfePgaGainBy32 

Input gained by 32.

Enumerator
kAfeResultFormatLeft 

Left justified result format.

kAfeResultFormatRight 

Right justified result format.

Enumerator
kAfeClkDividerInputOf1 

Clock divided by 1.

kAfeClkDividerInputOf2 

Clock divided by 2.

kAfeClkDividerInputOf4 

Clock divided by 4.

kAfeClkDividerInputOf8 

Clock divided by 8.

kAfeClkDividerInputOf16 

Clock divided by 16.

kAfeClkDividerInputOf32 

Clock divided by 32.

kAfeClkDividerInputOf64 

Clock divided by 64.

kAfeClkDividerInputOf128 

Clock divided by 128.

kAfeClkDividerInputOf256 

Clock divided by 256.

Enumerator
kAfeClkSrcClk0 

Modulator clock source 0.

kAfeClkSrcClk1 

Modulator clock source 1.

kAfeClkSrcClk2 

Modulator clock source 2.

kAfeClkSrcClk3 

Modulator clock source 3.

Function Documentation

void AFE_HAL_ChnInit ( AFE_Type *  base,
uint32_t  chn 
)

This function resets the channel registers into a reset state. This state is defined in the chip Reference Manual.

Parameters
baseRegister base address for the module.
chnAFE Channel.
static void AFE_HAL_SetIntEnableCmd ( AFE_Type *  base,
uint32_t  chn,
bool  enable 
)
inlinestatic

This function sets the interrupt request on conversion complete event. Once enabled, the conversion complete interrupt request is asserted for the desired channel when INTENx and COCx bits are set.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
enableBool value for enabling or disabling interrupt function.
static void AFE_HAL_SetDmaEnableCmd ( AFE_Type *  base,
uint32_t  chn,
bool  enable 
)
inlinestatic

This function sets the DMA request on conversion complete event. Once enabled, the DMA request is asserted when the INTENx and the COCx bits are set.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
enableBool value for enabling or disabling DMA function.
static void AFE_HAL_SetDelayVal ( AFE_Type *  base,
uint32_t  chn,
int32_t  delay 
)
inlinestatic

This function sets the delay value. This delay is inserted into the trigger response of the decimation filters in order to provide phase compensation between AFE channels.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
delayDelay value.
static int32_t AFE_HAL_GetDelayVal ( AFE_Type *  base,
uint32_t  chn 
)
inlinestatic

This function gets the delay value.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
Returns
Delay value.
static uint32_t AFE_HAL_GetResult ( AFE_Type *  base,
uint32_t  chn 
)
inlinestatic

This function gets the measurement result. The result can be represented in left justified twos complement 32-bit or right justified twos complement 32-bit format. See the "AFE_HAL_SetResultFormatMode()" for format setting.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
Returns
result.
static bool AFE_HAL_GetConvCompleteFlag ( AFE_Type *  base,
uint32_t  chn 
)
inlinestatic

This function checks whether the conversion is completed. When the result is read (see the "AFE_HAL_GetResult()"), the corresponding bit is cleared.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
Returns
Conversion is completed (true) or not (false).
static bool AFE_HAL_GetOverflowFlag ( AFE_Type *  base,
uint32_t  chn 
)
inlinestatic

This function checks whether the selected channel has overflown. This function returns true when new data has already arrived but previous data has not been read. The corresponding bit is cleared when the result is read (see the "AFE_HAL_GetResult()").

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
Returns
Channel is overflowed (true) or not (false).
static bool AFE_HAL_GetReadyFlag ( AFE_Type *  base,
uint32_t  chn 
)
inlinestatic

This function checks whether the selected channel is ready for conversion.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
Returns
Channel is ready to initiate conversions (true) or is disabled or has not completed its start up period (false).
void AFE_HAL_Init ( AFE_Type *  base)

This function resets all registers into a reset state for the AFE module. This state is defined in the chip Reference Manual.

Parameters
baseRegister base address for the module.
static void AFE_HAL_SetMasterEnableCmd ( AFE_Type *  base,
bool  enable 
)
inlinestatic

This function enables all ADCs and filters. The only ADCs that have asserted are SD_MOD_EN (only when AFE channel is not bypassed) and DEC_EN () are enabled by setting this bit.

Parameters
baseRegister base address for the AFE module.
enableBool value for enabling or disabling ADCs and filters simultaneously.
static void AFE_HAL_ChnSwTriggerCmd ( AFE_Type *  base,
uint32_t  chnMask 
)
inlinestatic

This function sets the software trigger conversion on the desired AFE channels. To trigger more channels simultaneously, use the red enumeration members.

Parameters
baseRegister base address for the AFE module.
chnMaskChannels which will be triggered.
static void AFE_HAL_SetLowPowerCmd ( AFE_Type *  base,
bool  enable 
)
inlinestatic

This function sets an AFE low power mode. The maximal modulator clock in low power mode is bellow 1 MHz.

Parameters
baseRegister base address for the AFE module.
enableBool value for enabling or disabling low power mode.
static void AFE_HAL_SetSwResetCmd ( AFE_Type *  base,
bool  enable 
)
inlinestatic

This function sets the software reset which is used to reset all ADCs, decimation filters, and clock configuration bits.

Parameters
baseRegister base address for the AFE module.
enableIf this value is true, all ADCs, PGAs and decimation filters are enabled. Otherwise, are disabled.
static void AFE_HAL_SetDelayOkCmd ( AFE_Type *  base)
inlinestatic

This function asserts the delay OK. When all delay registers are loaded, the delay OK bit should be asserted.

Parameters
baseRegister base address for the AFE module.
static void AFE_HAL_SetResultFormatMode ( AFE_Type *  base,
afe_result_format_mode_t  mode 
)
inlinestatic

This function selects the result format mode.

Parameters
baseRegister base address for the AFE module.
modeSelection of mode enumeration. See to " afe_result_format_mode_t".
static afe_result_format_mode_t AFE_HAL_GetResultFormatMode ( AFE_Type *  base)
inlinestatic

This function gets the conversion resolution mode.

Parameters
baseRegister base address for the AFE module.
Returns
Current conversion resolution mode.
static void AFE_HAL_SetStartUpDelayVal ( AFE_Type *  base,
int32_t  startDelay 
)
inlinestatic

This function sets the start up count value. A minimum value is two. This value should be greater than 20 µs. To compute the 20 µs value use, such as startDelay = (CLOCK_FREQ / DIV_factor)*20E-6

Parameters
baseRegister base address for the AFE module.
startDelayValue for start up count.
static void AFE_HAL_SetClkDividerMode ( AFE_Type *  base,
afe_clk_divider_mode_t  mode 
)
inlinestatic

This function selects the clock divider mode.

Parameters
baseRegister base address for the AFE module.
modeSelection of mode enumeration. See to "afe_clk_divider_mode_t".
static void AFE_HAL_SetClkSourceMode ( AFE_Type *  base,
afe_clk_src_mode_t  mode 
)
inlinestatic

This function selects the input clock source for the AFE module.

Parameters
baseRegister base address for the AFE module.
modeSelection of mode enumeration. See to "afe_clk_src_mode_t".
static void AFE_HAL_SetDmaIntReq ( AFE_Type *  base,
uint32_t  data 
)
inlinestatic

This function sets a DMA and Interrupt requests for all channels.

Parameters
baseRegister base address for the AFE module.
datawhich will be written to register.
void AFE_HAL_ConfigChn ( AFE_Type *  base,
uint32_t  chn,
afe_chn_set_t chnStructPtr 
)

This function configures the AFE channel.

Parameters
baseRegister base address for the AFE module.
chnAFE Channel.
chnStructPtrChannel configuration structure.
void AFE_HAL_ConfigConverter ( AFE_Type *  base,
afe_converter_config_t converterStructPtr 
)

This function configures an AFE converter.

Parameters
baseRegister base address for the AFE module.
converterStructPtrConverter configuration structure.