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.
|
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...
|
|
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.
bool sfa_config_t::enableCUTPin |
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
-
base | SFA peripheral base address. |
status | The runtime measurement status. kStatus_SFA_MeasurementCompleted: The measurement completes. kStatus_SFA_ReferenceCounterTimeout: Reference counter timeout happenes. kStatus_SFA_CUTCounterTimeout: CUT counter timeout happenes. |
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.
|
The default values are:
* config->cutSelect = kSFA_CUTSelect0;
* config->refSelect = kSFA_REFSelect0;
* config->prediv = 0U;
* config->trigStart = kSFA_TriggerStartSelect0;
* config->trigEnd = kSFA_TriggerEndSelect0;
* config->enableTrigMeasurement = false;
* config->enableCUTPin = false;
* config->cutTarget = 0xffffU;
* config->refTarget = 0xffffffffU;
*
- Parameters
-
config | Pointer to the user configuration structure. |
void SFA_Init |
( |
SFA_Type * |
base | ) |
|
- Parameters
-
base | SFA peripheral base address. |
void SFA_Deinit |
( |
SFA_Type * |
base | ) |
|
- Parameters
-
base | SFA peripheral base address. |
static void SFA_EnableCUTPin |
( |
SFA_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
enable | true: 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
-
base | SFA peripheral base address. |
void SFA_ClearStatusFlag |
( |
SFA_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | SFA peripheral base address. |
mask | SFA status flag mask (see _sfa_status_flags for bit definition). |
static void SFA_EnableInterrupts |
( |
SFA_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
static void SFA_DisableInterrupts |
( |
SFA_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
static uint8_t SFA_GetMode |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static uint8_t SFA_GetCUTPredivide |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
- Parameters
-
base | SFA peripheral base address. |
function | the SFA measure completed callback function. |
void SFA_SetMeasureConfig |
( |
SFA_Type * |
base, |
|
|
const sfa_config_t * |
config |
|
) |
| |
- Parameters
-
base | SFA peripheral base address. |
config | SFA configuration structure. |
status_t SFA_MeasureBlocking |
( |
SFA_Type * |
base | ) |
|
- Parameters
-
base | SFA peripheral base address. |
- Return values
-
kStatus_SFA_MeasurementCompleted | SFA measure completes. |
kStatus_SFA_ReferenceCounterTimeout | reference counter timeout error happens. |
kStatus_SFA_CUTCounterTimeout | CUT 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
-
base | SFA peripheral base address. |
void SFA_AbortMeasureSequence |
( |
SFA_Type * |
base | ) |
|
- Parameters
-
base | SFA peripheral base address. |
uint32_t SFA_CalculateFrequencyOrPeriod |
( |
SFA_Type * |
base, |
|
|
uint32_t |
refFrequency |
|
) |
| |
- Parameters
-
base | SFA peripheral base address. |
refFrequency | The reference clock frequency(BUS clock recommended). |
static uint32_t SFA_GetCUTCounter |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetCUTTargetCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | target count for CUT. |
static uint32_t SFA_GetCUTTargetCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetCUTLowLimitClockCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | low limit count for CUT clock. |
static uint32_t SFA_GetCUTLowLimitClockCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetCUTHighLimitClockCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | high limit count for CUT clock. |
static uint32_t SFA_GetCUTHighLimitClockCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static uint32_t SFA_GetREFCounter |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetREFTargetCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | target count for reference clock. |
static uint32_t SFA_GetREFTargetCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static uint32_t SFA_GetREFStartCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static uint32_t SFA_GetREFEndCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetREFLowLimitClockCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | low limit count for REF clock. |
static uint32_t SFA_GetREFLowLimitClockCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
static void SFA_SetREFHighLimitClockCount |
( |
SFA_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |
count | high limit count for REF clock. |
static uint32_t SFA_GetREFHighLimitClockCount |
( |
SFA_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | SFA peripheral base address. |