Interrupt Functions

group group_sar_functions_interrupt

This set of functions are related to SAR interrupts.

Functions

__STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatus (const SAR_Type *base)

Return the interrupt register status.


/* ISR function to handle all SAR interrupts. 
 * This same routine gets called when any of the enabled SAR interrupt sources
 * are enabled (EOS, overflow, FW collision, saturation detection, or range detection). */
void SAR_Interrupt(void)
{
    uint32_t intr_status = 0u;

    /* Read interrupt status register. */
    intr_status = Cy_SAR_GetInterruptStatus(SAR);

    /* Check what triggered the interrupt. */
    if ((intr_status & (uint32_t) CY_SAR_INTR_EOS) == (uint32_t) CY_SAR_INTR_EOS)
    {
        /* An end of scan occured, retrieve the ADC result and do something with it here. */
    }

    /* Check for the saturation detection status, if enabled. */

    /* Check for the range detection status, if enabled. */

    /* Clear the handled interrupt. */
    Cy_SAR_ClearInterrupt(SAR, intr_status);
}
Return

Interrupt status

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_SAR_ClearInterrupt (SAR_Type *base, uint32_t intrMask)

Clear the interrupt.

The interrupt must be cleared with this function so that the hardware can set subsequent interrupts and those interrupts can be forwarded to the interrupt controller, if enabled.

Return

None

Parameters

__STATIC_INLINE void Cy_SAR_SetInterrupt (SAR_Type *base, uint32_t intrMask)

Trigger an interrupt with software.

Return

None

Parameters

__STATIC_INLINE void Cy_SAR_SetInterruptMask (SAR_Type *base, uint32_t intrMask)

Enable which interrupts can trigger the CPU interrupt controller.

    /* Scenario: Enable the EOS, overflow, and firmware collision interrupt sources.
     * Make sure to assign an ISR to handle the SAR interrupts. */

    Cy_SAR_SetInterruptMask(SAR, (uint32_t) (CY_SAR_INTR_EOS | CY_SAR_INTR_OVERFLOW | CY_SAR_INTR_FW_COLLISION));
    
Return

None

Function Usage

Parameters

__STATIC_INLINE uint32_t Cy_SAR_GetInterruptMask (const SAR_Type *base)

Return which interrupts can trigger the CPU interrupt controller as configured by Cy_SAR_SetInterruptMask.

    /* Scenario: Check whether a specific interrupt source is enabled. */
    
    uint32_t intrMask;
    intrMask = Cy_SAR_GetInterruptMask(SAR);
    
    if ((uint32_t) CY_SAR_INTR_EOS == (intrMask & (uint32_t) CY_SAR_INTR_EOS))
    {
        /* EOS interrupt was enabled. */
    }
Return

Interrupt mask. Compare this value with masks in Interrupt Masks.

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetInterruptStatusMasked (const SAR_Type *base)

Return the bitwise AND between the interrupt request and mask registers.

See Cy_SAR_GetInterruptStatus and Cy_SAR_GetInterruptMask.

Return

Bitwise AND of the interrupt request and mask registers

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatus (const SAR_Type *base)

Return the range interrupt register status.

If the status bit is low for a channel, the channel may not be enabled (Cy_SAR_SetChanMask), range detection is not enabled for the channel (Cy_SAR_SetRangeInterruptMask), or range detection was not triggered for the channel.

    /* Scenario: Range detection has been enabled for at least one channel.
     * Check the range interrupt status in the ISR when an interrupt occurs. */
    
    uint32_t intr_status = 0u;
    
    /* Read the range detection interrupt status register. */
    intr_status = Cy_SAR_GetRangeInterruptStatus(SAR);

    if (intr_status > 0u)
    {
        /* One or more channels triggered the range detection interrupt, do something here. */
    }

    /* Clear the handled range interrupt. */
    Cy_SAR_ClearRangeInterrupt(SAR, intr_status);

    /* Perform a dummy read of the range interrupt status register for buffered writes. */
    (void)Cy_SAR_GetRangeInterruptStatus(SAR);
Return

The range interrupt status for all channels. Bit 0 is for channel 0, etc.

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_SAR_ClearRangeInterrupt (SAR_Type *base, uint32_t chanMask)

Clear the range interrupt for the specified channel mask.

The interrupt must be cleared with this function so that the hardware can set subset interrupts and those interrupts can be forwarded to the interrupt controller, if enabled.

Return

None

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc. Typically, this is the value returned from Cy_SAR_GetRangeInterruptStatus.

__STATIC_INLINE void Cy_SAR_SetRangeInterrupt (SAR_Type *base, uint32_t chanMask)

Trigger a range interrupt with software for the specific channel mask.

Return

None

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc.

__STATIC_INLINE void Cy_SAR_SetRangeInterruptMask (SAR_Type *base, uint32_t chanMask)

Enable which channels can trigger a range interrupt.

    /* Scenario: Enable the range detection interrupt for channel 0 only.
     * Make sure to assign an ISR to handle the SAR interrupts. */
    uint32_t chanMask = 1UL;
    Cy_SAR_SetRangeInterruptMask(SAR, chanMask);
    
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc.

__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptMask (const SAR_Type *base)

Return which interrupts can trigger a range interrupt as configured by Cy_SAR_SetRangeInterruptMask.

Return

The range interrupt mask

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetRangeInterruptStatusMasked (const SAR_Type *base)

Return the bitwise AND between the range interrupt request and mask registers.

See Cy_SAR_GetRangeInterruptStatus and Cy_SAR_GetRangeInterruptMask.

Return

Bitwise AND between of range interrupt request and mask

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatus (const SAR_Type *base)

Return the saturate interrupt register status.

If the status bit is low for a channel, the channel may not be enabled (Cy_SAR_SetChanMask), saturation detection is not enabled for the channel (Cy_SAR_SetSatInterruptMask), or saturation detection was not triggered for the channel.

    /* Scenario: Saturation detection has been enabled for at least one channel.
     * Check the saturation interrupt status in the ISR when an interrupt occurs. */
    
    uint32_t intr_status = 0u;
    
    /* Read the saturation detection interrupt status register. */
    intr_status = Cy_SAR_GetSatInterruptStatus(SAR);

    if (intr_status > 0u)
    {
        /* One or more channel saturated (the sampled value is equal to the
         * minimum or maximum, do something here. */
    }

    /* Clear the handled saturation interrupt. */
    Cy_SAR_ClearSatInterrupt(SAR, intr_status);

    /* Perform a dummy read of the saturation interrupt status register for buffered writes. */
    (void)Cy_SAR_GetSatInterruptStatus(SAR);
Return

The saturate interrupt status for all channels. Bit 0 is for channel 0, etc.

Function Usage

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE void Cy_SAR_ClearSatInterrupt (SAR_Type *base, uint32_t chanMask)

Clear the saturate interrupt for the specified channel mask.

The interrupt must be cleared with this function so that the hardware can set subsequent interrupts and those interrupts can be forwarded to the interrupt controller, if enabled.

Return

None

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc. Typically, this is the value returned from Cy_SAR_GetSatInterruptStatus.

__STATIC_INLINE void Cy_SAR_SetSatInterrupt (SAR_Type *base, uint32_t chanMask)

Trigger a saturate interrupt with software for the specific channel mask.

Return

None

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc.

__STATIC_INLINE void Cy_SAR_SetSatInterruptMask (SAR_Type *base, uint32_t chanMask)

Enable which channels can trigger a saturate interrupt.

    /* Scenario: Enable the saturation detection interrupt for all 16 channels.
     * Only enabled channels, see Cy_SAR_SetChanMask(), are scanned. 
     * Make sure to assign an ISR to handle the SAR interrupts. */
    
    uint32_t chanMask = 0xFFFFUL;
    Cy_SAR_SetSatInterruptMask(SAR, chanMask);
Return

None

Function Usage

Parameters
  • base: Pointer to structure describing registers

  • chanMask: The channel mask. Bit 0 is for channel 0, etc.

__STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptMask (const SAR_Type *base)

Return which interrupts can trigger a saturate interrupt as configured by Cy_SAR_SetSatInterruptMask.

Return

The saturate interrupt mask. Bit 0 is for channel 0, etc.

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetSatInterruptStatusMasked (const SAR_Type *base)

Return the bitwise AND between the saturate interrupt request and mask registers.

See Cy_SAR_GetSatInterruptStatus and Cy_SAR_GetSatInterruptMask.

Return

Bitwise AND of the saturate interrupt request and mask

Parameters
  • base: Pointer to structure describing registers

__STATIC_INLINE uint32_t Cy_SAR_GetInterruptCause (const SAR_Type *base)

Return the cause of the interrupt.

The interrupt routine can be called due to one of the following events:

  • End of scan (EOS)

  • Overflow

  • Firmware collision

  • Saturation detected on one or more channels

  • Range detected on one or more channels

Return

Mask of what caused the interrupt. Compare this value with one of these masks:

  • SAR_INTR_CAUSE_EOS_MASKED_MIR_Msk : EOS caused the interrupt

  • SAR_INTR_CAUSE_OVERFLOW_MASKED_MIR_Msk : Overflow caused the interrupt

  • SAR_INTR_CAUSE_FW_COLLISION_MASKED_MIR_Msk : Firmware collision cause the interrupt

  • SAR_INTR_CAUSE_SATURATE_MASKED_RED_Msk : Saturation detection on one or more channels caused the interrupt

  • SAR_INTR_CAUSE_RANGE_MASKED_RED_Msk : Range detection on one or more channels caused the interrupt

Parameters
  • base: Pointer to structure describing registers