MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SFA: Signal Frequency Analyser

Overview

The MCUXpresso SDK provides a driver for the Signal Frequency Analyser (SFA) of MCUXpresso SDK devices.

Function groups

The SFA driver supports operating the module to measure clock frequency, clock period and time between triggers.

Initialization and Deinitialization

The function SFA_Init() enables the SFA clock. The function SFA_Deinit() clears each conters and status flags, disables SFA, gates the SFA clock. The function SFA_GetDefaultConfig() gets the default configurations. The function SFA_EnableCUTPin() controls the connection of the CUT to an external pin.

Status

Provides functions to get and clear the SFA status.

Interrupt

Provides functions to enable/disable SFA interrupts.

SFA measurement Operations

The function SFA_InstallCallback() installs the callback function to be called when measure finish. The function SFA_SetMeasureConfig() sets the measurement options. The function SFA_MeasureBlocking() starts measure sequence in blocking mode. The funciton SFA_MeasureNonBlocking() starts measure sequence in nonblocking mode. The function SFA_AbortMeasureSequence() aborts measure sequence. The funciton SFA_CalculateFrequencyOrPeriod() calculates the frequency or period based on the reference clock frequency.

Control CUT counter

The function SFA_GetCUTCounter() gets current counts of the CUT counter. The function SFA_SetCUTTargetCount() sets the target counts for the CUT. The function SFA_GetCUTTargetCount() gets the target counts of the CUT. The function SFA_SetCUTLowLimitClockCount() sets CUT low limit clock count. The function SFA_GetCUTLowLimitClockCount() Gets CUT low limit clock count. The function SFA_SetCUTHighLimitClockCount() sets CUT high limit clock count. The function SFA_GetCUTHighLimitClockCount() Gets CUT high limit clock count.

Control REF counter

The function SFA_GetREFCouner() get current counts of the REF counter. The function SFA_SetREFTargetCount() sets the target counts for the CUT. The function SFA_GetREFTargetCount() gets the target counts of the CUT. The function SFA_GetREFStartCount() gets the saved REF count when measurement starts. The function SFA_GetREFEndCount() gets the saved REF count when measurement ends. The function SFA_SetREFLowLimitClockCount() sets REF low limit clock count. The function SFA_GetREFLowLimitClockCount() Gets REF low limit clock count. The function SFA_SetREFHighLimitClockCount() sets REF high limit clock count. The function SFA_GetREFHighLimitClockCount() Gets REF high limit clock count.

Data Structures

struct  sfa_config_t
 Structure with setting to initialize the SFA module. More...
 

Typedefs

typedef void(* sfa_callback_t )(status_t status)
 sfa measure completion callback function pointer type More...
 

Enumerations

enum  {
  kStatus_SFA_MeasurementCompleted = MAKE_STATUS(kStatusGroup_SFA, 0U),
  kStatus_SFA_ReferenceCounterTimeout = MAKE_STATUS(kStatusGroup_SFA, 1U),
  kStatus_SFA_CUTCounterTimeout = MAKE_STATUS(kStatusGroup_SFA, 2U),
  kStatus_SFA_CUTClockFreqLessThanMinLimit = MAKE_STATUS(kStatusGroup_SFA, 3U),
  kStatus_SFA_CUTClockFreqGreaterThanMaxLimit = MAKE_STATUS(kStatusGroup_SFA, 4U)
}
 SFA status return codes. More...
 
enum  _sfa_status_flags {
  kSFA_RefStoppedFlag = SFA_CNT_STAT_REF_STOPPED_MASK,
  kSFA_CutStoppedFlag = SFA_CNT_STAT_CUT_STOPPED_MASK,
  kSFA_MeasurementStartedFlag = SFA_CNT_STAT_MEAS_STARTED_MASK,
  kSFA_ReferenceCounterTimeOutFlag = SFA_CNT_STAT_REF_CNT_TIMEOUT_MASK,
  kSFA_InterruptRequestFlag = SFA_CNT_STAT_SFA_IRQ_MASK,
  kSFA_FreqGreaterThanMaxInterruptFlag = SFA_CNT_STAT_FREQ_GT_MAX_IRQ_MASK,
  kSFA_FreqLessThanMinInterruptFlag = SFA_CNT_STAT_FREQ_LT_MIN_IRQ_MASK
}
 List of SFA status flags. More...
 
enum  _sfa_interrupts_enable {
  kSFA_InterruptEnable = SFA_CTRL_SFA_IRQ_EN_MASK,
  kSFA_FreqGreaterThanMaxInterruptEnable = SFA_CTRL2_FREQ_GT_MAX_IRQ_EN_MASK,
  kSFA_FreqLessThanMinInterruptEnable = SFA_CTRL2_FREQ_LT_MIN_IRQ_EN_MASK
}
 List of SFA interrupt. More...
 
enum  sfa_measurement_mode_t {
  kSFA_FrequencyMeasurement0 = 0U,
  kSFA_FrequencyMeasurement1 = 1U,
  kSFA_CUTPeriodMeasurement = 2U,
  kSFA_TriggerBasedMeasurement = 3U
}
 List of SFA measurement mode(Please check the mode configuration according to the manual). More...
 
enum  sfa_cut_select_t
 List of CUT which is connected to the CUT counter (Please refer to the manual for configuration).
 
enum  sfa_ref_select_t
 List of REF which is connected to the REF counter (Please refer to the manual for configuration).
 
enum  sfa_trigger_start_select_t
 List of Signal MUX for Trigger Based Measurement Start.
 
enum  sfa_trigger_end_select_t
 List of Signal MUX for Trigger Based Measurement End.
 
enum  sfa_trigger_start_polarity_t {
  kSFA_TriggerStartPolarityRiseEdge = 0U,
  kSFA_TriggerStartPolarityFallEdge = 1U
}
 List of Trigger Start Polarity. More...
 
enum  sfa_trigger_end_polarity_t {
  kSFA_TriggerEndPolarityRiseEdge = 0U,
  kSFA_TriggerEndPolarityFallEdge = 1U
}
 List of Trigger End Polarity. More...
 

Driver version

#define FSL_SFA_DRVIER_VERSION   (MAKE_VERSION(2, 1, 0))
 SFA driver version 2.1.0.
 

Initialization and Deinitialization.

void SFA_GetDefaultConfig (sfa_config_t *config)
 Fill the SFA configuration structure with default settings. More...
 
void SFA_Init (SFA_Type *base)
 Initialize SFA. More...
 
void SFA_Deinit (SFA_Type *base)
 Clear counter, disable SFA and gate the SFA clock. More...
 
static void SFA_EnableCUTPin (SFA_Type *base, bool enable)
 Control the connection of the clock under test to an external pin. More...
 

Status Interface

static uint32_t SFA_GetStatusFlags (SFA_Type *base)
 Get SFA status flags. More...
 
void SFA_ClearStatusFlag (SFA_Type *base, uint32_t mask)
 Clear the SFA status flags. More...
 

Interrupts Interface

static void SFA_EnableInterrupts (SFA_Type *base, uint32_t mask)
 Enable the selected SFA interrupt. More...
 
static void SFA_DisableInterrupts (SFA_Type *base, uint32_t mask)
 Disable the selected SFA interrupt. More...
 

Control SFA Measurement sequence.

static uint8_t SFA_GetMode (SFA_Type *base)
 Get SFA measurement mode. More...
 
static uint8_t SFA_GetCUTPredivide (SFA_Type *base)
 Get CUT predivide value. More...
 
void SFA_InstallCallback (SFA_Type *base, sfa_callback_t function)
 Install the callback function to be called when IRQ happens or measurement completes. More...
 
void SFA_SetMeasureConfig (SFA_Type *base, const sfa_config_t *config)
 Set Measurement options with the passed in configuration structure. More...
 
status_t SFA_MeasureBlocking (SFA_Type *base)
 Start SFA measurement in blocking mode. More...
 
void SFA_MeasureNonBlocking (SFA_Type *base)
 Start measure sequence in NonBlocking mode. More...
 
void SFA_AbortMeasureSequence (SFA_Type *base)
 Abort SFA measurement sequence. More...
 
uint32_t SFA_CalculateFrequencyOrPeriod (SFA_Type *base, uint32_t refFrequency)
 Calculate the frequency or period. More...
 

Control CUT counter

static uint32_t SFA_GetCUTCounter (SFA_Type *base)
 Get current count of the clock under test. More...
 
static void SFA_SetCUTTargetCount (SFA_Type *base, uint32_t count)
 Set the target count for the clock under test. More...
 
static uint32_t SFA_GetCUTTargetCount (SFA_Type *base)
 Get the target count of the clock under test. More...
 
static void SFA_SetCUTLowLimitClockCount (SFA_Type *base, uint32_t count)
 Set CUT low limit clock count. More...
 
static uint32_t SFA_GetCUTLowLimitClockCount (SFA_Type *base)
 Get CUT low limit clock count. More...
 
static void SFA_SetCUTHighLimitClockCount (SFA_Type *base, uint32_t count)
 Set CUT high limit clock count. More...
 
static uint32_t SFA_GetCUTHighLimitClockCount (SFA_Type *base)
 Get CUT high limit clock count. More...
 

Control REF counter

static uint32_t SFA_GetREFCounter (SFA_Type *base)
 Get current count of the reference clock. More...
 
static void SFA_SetREFTargetCount (SFA_Type *base, uint32_t count)
 Set the target count for the reference clock. More...
 
static uint32_t SFA_GetREFTargetCount (SFA_Type *base)
 Get the target count of the reference clock. More...
 
static uint32_t SFA_GetREFStartCount (SFA_Type *base)
 Get saved reference clock counter which is loaded when measurement start. More...
 
static uint32_t SFA_GetREFEndCount (SFA_Type *base)
 Get saved reference clock counter which is loaded when measurement complete. More...
 
static void SFA_SetREFLowLimitClockCount (SFA_Type *base, uint32_t count)
 Set REF low limit clock count. More...
 
static uint32_t SFA_GetREFLowLimitClockCount (SFA_Type *base)
 Get REF low limit clock count. More...
 
static void SFA_SetREFHighLimitClockCount (SFA_Type *base, uint32_t count)
 Set REF high limit clock count. More...
 
static uint32_t SFA_GetREFHighLimitClockCount (SFA_Type *base)
 Get REF high limit clock count. More...
 

Data Structure Documentation

struct sfa_config_t

This structure holds configuration setting for the SFA peripheral. To initialize this structure to reasonable defaults, call the SFA_GetDefaultConfig() function and pass a pointer to your configuration structure instance.

Data Fields

sfa_measurement_mode_t mode
 measurement mode
 
sfa_cut_select_t cutSelect
 Select clock connected to the clock under test counter.
 
sfa_ref_select_t refSelect
 Selcet REF connected the bus clock.
 
uint8_t prediv
 Integer divide of the Input CUT signal.
 
sfa_trigger_start_select_t trigStart
 Select the signal will be used to end a trigger based measurement.
 
sfa_trigger_start_polarity_t startPolarity
 Select the polarity of the start trigger signal.
 
sfa_trigger_end_select_t trigEnd
 Select the signal will be used to commence a trigger based measurement.
 
sfa_trigger_end_polarity_t endPolarity
 Select the polarity of the end trigger signal.
 
bool enableTrigMeasurement
 false: The measurement will start by default with a dummy write to the CUT counter; true : The measurement will start after receiving a dummy write to the REF_CNT followed by receiving the trigger edge
 
bool enableCUTPin
 Control the connection of the clock under test to an external pin. More...
 
uint32_t refTarget
 Reference counter target counts.
 
uint32_t cutTarget
 CUT counter target counts.
 

Field Documentation

bool sfa_config_t::enableCUTPin

Typedef Documentation

typedef void(* sfa_callback_t)(status_t status)

This callback can be used in non blocking IRQHandler. Specify the callback you want in the call to SFA_InstallCallback().

Parameters
baseSFA peripheral base address.
statusThe runtime measurement status. kStatus_SFA_MeasurementCompleted: The measurement completes. kStatus_SFA_ReferenceCounterTimeout: Reference counter timeout happenes. kStatus_SFA_CUTCounterTimeout: CUT counter timeout happenes.

Enumeration Type Documentation

anonymous enum

enumeration _sfa_status

Enumerator
kStatus_SFA_MeasurementCompleted 

Measurement completed.

kStatus_SFA_ReferenceCounterTimeout 

Reference counter timeout.

kStatus_SFA_CUTCounterTimeout 

CUT counter timeout.

kStatus_SFA_CUTClockFreqLessThanMinLimit 

CUT clock frequency less than minimum limit.

kStatus_SFA_CUTClockFreqGreaterThanMaxLimit 

CUT clock frequency greater than maximum limit.

The following status register flags can be cleared on any write to REF_CNT.

  • kSFA_RefStoppedFlag
  • kSFA_CutStoppedFlag
  • kSFA_MeasurementStartedFlag
  • kSFA_ReferenceCounterTimeOutFlag
  • kSFA_InterruptRequestFlag
  • kSFA_FreqGreaterThanMaxInterruptFlag
  • kSFA_FreqLessThanMinInterruptFlag
Note
These enums are meant to be OR'd together to from a bit mask.
Enumerator
kSFA_RefStoppedFlag 

Reference counter stopped flag.

kSFA_CutStoppedFlag 

CUT counter stopped flag.

kSFA_MeasurementStartedFlag 

Measurement Started flag.

kSFA_ReferenceCounterTimeOutFlag 

Reference counter time out flag.

kSFA_InterruptRequestFlag 

SFA interrupt request flag.

kSFA_FreqGreaterThanMaxInterruptFlag 

FREQ_GT_MAX interrupt flag.

kSFA_FreqLessThanMinInterruptFlag 

FREQ_LT_MIN interrupt flag.

Enumerator
kSFA_InterruptEnable 

SFA interrupt enable.

kSFA_FreqGreaterThanMaxInterruptEnable 

FREQ_GT_MAX interrupt enable.

kSFA_FreqLessThanMinInterruptEnable 

FREQ_LT_MIN interrupt enable.

Enumerator
kSFA_FrequencyMeasurement0 

Frequency measurement performed with REF frequency > CUT frequency.

kSFA_FrequencyMeasurement1 

Frequency measurement performed with REF frequency < CUT frequency.

kSFA_CUTPeriodMeasurement 

CUT period measurement performed.

kSFA_TriggerBasedMeasurement 

Trigger based measurement performed.

Enumerator
kSFA_TriggerStartPolarityRiseEdge 

Rising edge will begin the measurement sequence.

kSFA_TriggerStartPolarityFallEdge 

Falling edge will begin the measurement sequence.

Enumerator
kSFA_TriggerEndPolarityRiseEdge 

Rising edge will end the measurement sequence.

kSFA_TriggerEndPolarityFallEdge 

Falling edge will end the measurement sequence.

Function Documentation

void SFA_GetDefaultConfig ( sfa_config_t config)

The default values are:

* config->mode = kSFA_FrequencyMeasurement0;
* config->cutSelect = kSFA_CUTSelect0;
* config->refSelect = kSFA_REFSelect0;
* config->prediv = 0U;
* config->trigStart = kSFA_TriggerStartSelect0;
* config->startPolarity = kSFA_TriggerStartPolarityRiseEdge;
* config->trigEnd = kSFA_TriggerEndSelect0;
* config->endPolarity = kSFA_TriggerEndPolarityRiseEdge;
* config->enableTrigMeasurement = false;
* config->enableCUTPin = false;
* config->cutTarget = 0xffffU;
* config->refTarget = 0xffffffffU;
*
Parameters
configPointer to the user configuration structure.
void SFA_Init ( SFA_Type *  base)
Parameters
baseSFA peripheral base address.
void SFA_Deinit ( SFA_Type *  base)
Parameters
baseSFA peripheral base address.
static void SFA_EnableCUTPin ( SFA_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSFA peripheral base address.
enabletrue: connect the clock under test and external pin. false: Disconnect the clock under test and external pin.
static uint32_t SFA_GetStatusFlags ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
void SFA_ClearStatusFlag ( SFA_Type *  base,
uint32_t  mask 
)
Parameters
baseSFA peripheral base address.
maskSFA status flag mask (see _sfa_status_flags for bit definition).
static void SFA_EnableInterrupts ( SFA_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSFA peripheral base address.
maskThe interrupt to enable (see _sfa_interrupts_enable for definition).
static void SFA_DisableInterrupts ( SFA_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSFA peripheral base address.
maskThe interrupt to disable (see _sfa_interrupts_enable for definition).
static uint8_t SFA_GetMode ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static uint8_t SFA_GetCUTPredivide ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
void SFA_InstallCallback ( SFA_Type *  base,
sfa_callback_t  function 
)
Parameters
baseSFA peripheral base address.
functionthe SFA measure completed callback function.
void SFA_SetMeasureConfig ( SFA_Type *  base,
const sfa_config_t config 
)
Parameters
baseSFA peripheral base address.
configSFA configuration structure.
status_t SFA_MeasureBlocking ( SFA_Type *  base)
Parameters
baseSFA peripheral base address.
Return values
kStatus_SFA_MeasurementCompletedSFA measure completes.
kStatus_SFA_ReferenceCounterTimeoutreference counter timeout error happens.
kStatus_SFA_CUTCounterTimeoutCUT counter time out happens.
void SFA_MeasureNonBlocking ( SFA_Type *  base)

This function performs nonblocking measurement by enabling sfa interrupt (Please enable the FreqGreaterThanMax and FreqLessThanMin interrupts individually as needed). The callback function must be installed before invoking this function.

Note
This function has different functions for different instances.
Parameters
baseSFA peripheral base address.
void SFA_AbortMeasureSequence ( SFA_Type *  base)
Parameters
baseSFA peripheral base address.
uint32_t SFA_CalculateFrequencyOrPeriod ( SFA_Type *  base,
uint32_t  refFrequency 
)
Parameters
baseSFA peripheral base address.
refFrequencyThe reference clock frequency(BUS clock recommended).
static uint32_t SFA_GetCUTCounter ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetCUTTargetCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
counttarget count for CUT.
static uint32_t SFA_GetCUTTargetCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetCUTLowLimitClockCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
countlow limit count for CUT clock.
static uint32_t SFA_GetCUTLowLimitClockCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetCUTHighLimitClockCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
counthigh limit count for CUT clock.
static uint32_t SFA_GetCUTHighLimitClockCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static uint32_t SFA_GetREFCounter ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetREFTargetCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
counttarget count for reference clock.
static uint32_t SFA_GetREFTargetCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static uint32_t SFA_GetREFStartCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static uint32_t SFA_GetREFEndCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetREFLowLimitClockCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
countlow limit count for REF clock.
static uint32_t SFA_GetREFLowLimitClockCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.
static void SFA_SetREFHighLimitClockCount ( SFA_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseSFA peripheral base address.
counthigh limit count for REF clock.
static uint32_t SFA_GetREFHighLimitClockCount ( SFA_Type *  base)
inlinestatic
Parameters
baseSFA peripheral base address.