Channel Functions

group group_dmac_channel_functions

Functions

cy_en_dmac_status_t Cy_DMAC_Channel_Init(DMAC_Type *base, uint32_t channel, cy_stc_dmac_channel_config_t const *config)

Initializes the DMAC channel with a descriptor and other parameters.

Return

The status /ref cy_en_dmac_status_t.

Function Usage

    
    /* Scenario: Initialize a 1D descriptor */
    #define DATACNT (8UL)
    cy_stc_dmac_descriptor_t descriptor;
    cy_stc_dmac_descriptor_t nextDescriptor;
    uint32_t src[DATACNT];
    uint32_t dst[DATACNT];
    
    cy_stc_dmac_descriptor_config_t descriptor_cfg = 
    {
        .retrigger = CY_DMAC_RETRIG_IM,
        .interruptType = CY_DMAC_DESCR,
        .triggerOutType = CY_DMAC_DESCR,
        .channelState = CY_DMAC_CHANNEL_ENABLED,
        .triggerInType = CY_DMAC_DESCR,
        .dataSize = CY_DMAC_WORD,
        .srcTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .dstTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .descriptorType = CY_DMAC_1D_TRANSFER,
        .srcAddress = &src,
        .dstAddress = &dst,
        .srcXincrement = 1U,
        .dstXincrement = 1U,
        .xCount = DATACNT,
        .srcYincrement = 0U,
        .dstYincrement = 0U,
        .yCount = 1UL,
        .nextDescriptor = &nextDescriptor,
    };
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Descriptor_Init(&descriptor, &descriptor_cfg))
    {
        /* Insert error handling */
    }
    
    /* Scenario: Setup and enable the DMAC channel 0 */
    cy_stc_dmac_channel_config_t channelConfig;
    channelConfig.enable = false;
    channelConfig.bufferable = false;
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Channel_Init(DMAC, 0UL, &channelConfig))
    {
        /* Insert error handling */
    }
    
    Cy_DMAC_Channel_SetDescriptor(DMAC, 0UL, &descriptor);
    Cy_DMAC_Channel_SetPriority(DMAC, 0UL, 3UL);
    Cy_DMAC_Channel_Enable(DMAC, 0UL);
    
    Cy_DMAC_Enable(DMAC);
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: A channel number.

  • config: The structure that has the initialization information for the channel.

void Cy_DMAC_Channel_DeInit(DMAC_Type *base, uint32_t channel)

Clears the content of registers corresponding to the channel.

Function Usage

    
    /* Scenario: Disable the DMAC channel 0 if it's priority equals 3 */
    
    if (3UL == Cy_DMAC_Channel_GetPriority(DMAC, 0UL))
    {    
        if (0UL != Cy_DMAC_GetActiveChannel(DMAC))
        {
            Cy_DMAC_Channel_Disable(DMAC, 0UL);
            Cy_DMAC_Channel_DeInit(DMAC, 0UL);

            /* if needed (if there is only channel used) the whole block can be disabled */
            Cy_DMAC_Disable(DMAC);
        }
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: A channel number.

__STATIC_INLINE void Cy_DMAC_Channel_SetDescriptor (DMAC_Type *base, uint32_t channel, cy_stc_dmac_descriptor_t const *descriptor)

Sets a descriptor as current for the specified DMACchannel.

Function Usage

    
    /* Scenario: Initialize a 1D descriptor */
    #define DATACNT (8UL)
    cy_stc_dmac_descriptor_t descriptor;
    cy_stc_dmac_descriptor_t nextDescriptor;
    uint32_t src[DATACNT];
    uint32_t dst[DATACNT];
    
    cy_stc_dmac_descriptor_config_t descriptor_cfg = 
    {
        .retrigger = CY_DMAC_RETRIG_IM,
        .interruptType = CY_DMAC_DESCR,
        .triggerOutType = CY_DMAC_DESCR,
        .channelState = CY_DMAC_CHANNEL_ENABLED,
        .triggerInType = CY_DMAC_DESCR,
        .dataSize = CY_DMAC_WORD,
        .srcTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .dstTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .descriptorType = CY_DMAC_1D_TRANSFER,
        .srcAddress = &src,
        .dstAddress = &dst,
        .srcXincrement = 1U,
        .dstXincrement = 1U,
        .xCount = DATACNT,
        .srcYincrement = 0U,
        .dstYincrement = 0U,
        .yCount = 1UL,
        .nextDescriptor = &nextDescriptor,
    };
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Descriptor_Init(&descriptor, &descriptor_cfg))
    {
        /* Insert error handling */
    }
    
    /* Scenario: Setup and enable the DMAC channel 0 */
    cy_stc_dmac_channel_config_t channelConfig;
    channelConfig.enable = false;
    channelConfig.bufferable = false;
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Channel_Init(DMAC, 0UL, &channelConfig))
    {
        /* Insert error handling */
    }
    
    Cy_DMAC_Channel_SetDescriptor(DMAC, 0UL, &descriptor);
    Cy_DMAC_Channel_SetPriority(DMAC, 0UL, 3UL);
    Cy_DMAC_Channel_Enable(DMAC, 0UL);
    
    Cy_DMAC_Enable(DMAC);
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

  • descriptor: This is the descriptor to be associated with the channel.

__STATIC_INLINE void Cy_DMAC_Channel_Enable (DMAC_Type *base, uint32_t channel)

Enables a DMAC channel.

Function Usage

    
    /* Scenario: Initialize a 1D descriptor */
    #define DATACNT (8UL)
    cy_stc_dmac_descriptor_t descriptor;
    cy_stc_dmac_descriptor_t nextDescriptor;
    uint32_t src[DATACNT];
    uint32_t dst[DATACNT];
    
    cy_stc_dmac_descriptor_config_t descriptor_cfg = 
    {
        .retrigger = CY_DMAC_RETRIG_IM,
        .interruptType = CY_DMAC_DESCR,
        .triggerOutType = CY_DMAC_DESCR,
        .channelState = CY_DMAC_CHANNEL_ENABLED,
        .triggerInType = CY_DMAC_DESCR,
        .dataSize = CY_DMAC_WORD,
        .srcTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .dstTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .descriptorType = CY_DMAC_1D_TRANSFER,
        .srcAddress = &src,
        .dstAddress = &dst,
        .srcXincrement = 1U,
        .dstXincrement = 1U,
        .xCount = DATACNT,
        .srcYincrement = 0U,
        .dstYincrement = 0U,
        .yCount = 1UL,
        .nextDescriptor = &nextDescriptor,
    };
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Descriptor_Init(&descriptor, &descriptor_cfg))
    {
        /* Insert error handling */
    }
    
    /* Scenario: Setup and enable the DMAC channel 0 */
    cy_stc_dmac_channel_config_t channelConfig;
    channelConfig.enable = false;
    channelConfig.bufferable = false;
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Channel_Init(DMAC, 0UL, &channelConfig))
    {
        /* Insert error handling */
    }
    
    Cy_DMAC_Channel_SetDescriptor(DMAC, 0UL, &descriptor);
    Cy_DMAC_Channel_SetPriority(DMAC, 0UL, 3UL);
    Cy_DMAC_Channel_Enable(DMAC, 0UL);
    
    Cy_DMAC_Enable(DMAC);
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void Cy_DMAC_Channel_Disable (DMAC_Type *base, uint32_t channel)

Disables a DMACchannel.

Function Usage

    
    /* Scenario: Disable the DMAC channel 0 if it's priority equals 3 */
    
    if (3UL == Cy_DMAC_Channel_GetPriority(DMAC, 0UL))
    {    
        if (0UL != Cy_DMAC_GetActiveChannel(DMAC))
        {
            Cy_DMAC_Channel_Disable(DMAC, 0UL);
            Cy_DMAC_Channel_DeInit(DMAC, 0UL);

            /* if needed (if there is only channel used) the whole block can be disabled */
            Cy_DMAC_Disable(DMAC);
        }
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void Cy_DMAC_Channel_SetPriority (DMAC_Type *base, uint32_t channel, uint32_t priority)

The function is used to set a priority for the DMAC channel.

Function Usage

    
    /* Scenario: Initialize a 1D descriptor */
    #define DATACNT (8UL)
    cy_stc_dmac_descriptor_t descriptor;
    cy_stc_dmac_descriptor_t nextDescriptor;
    uint32_t src[DATACNT];
    uint32_t dst[DATACNT];
    
    cy_stc_dmac_descriptor_config_t descriptor_cfg = 
    {
        .retrigger = CY_DMAC_RETRIG_IM,
        .interruptType = CY_DMAC_DESCR,
        .triggerOutType = CY_DMAC_DESCR,
        .channelState = CY_DMAC_CHANNEL_ENABLED,
        .triggerInType = CY_DMAC_DESCR,
        .dataSize = CY_DMAC_WORD,
        .srcTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .dstTransferSize = CY_DMAC_TRANSFER_SIZE_WORD,
        .descriptorType = CY_DMAC_1D_TRANSFER,
        .srcAddress = &src,
        .dstAddress = &dst,
        .srcXincrement = 1U,
        .dstXincrement = 1U,
        .xCount = DATACNT,
        .srcYincrement = 0U,
        .dstYincrement = 0U,
        .yCount = 1UL,
        .nextDescriptor = &nextDescriptor,
    };
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Descriptor_Init(&descriptor, &descriptor_cfg))
    {
        /* Insert error handling */
    }
    
    /* Scenario: Setup and enable the DMAC channel 0 */
    cy_stc_dmac_channel_config_t channelConfig;
    channelConfig.enable = false;
    channelConfig.bufferable = false;
    
    if (CY_DMAC_SUCCESS != Cy_DMAC_Channel_Init(DMAC, 0UL, &channelConfig))
    {
        /* Insert error handling */
    }
    
    Cy_DMAC_Channel_SetDescriptor(DMAC, 0UL, &descriptor);
    Cy_DMAC_Channel_SetPriority(DMAC, 0UL, 3UL);
    Cy_DMAC_Channel_Enable(DMAC, 0UL);
    
    Cy_DMAC_Enable(DMAC);
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

  • priority: The priority to be set for the DMAC channel. The allowed values are 0,1,2,3.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetPriority (DMAC_Type const *base, uint32_t channel)

Returns the priority of the DMAC channel.

Return

The priority of the channel.

Function Usage

    
    /* Scenario: Disable the DMAC channel 0 if it's priority equals 3 */
    
    if (3UL == Cy_DMAC_Channel_GetPriority(DMAC, 0UL))
    {    
        if (0UL != Cy_DMAC_GetActiveChannel(DMAC))
        {
            Cy_DMAC_Channel_Disable(DMAC, 0UL);
            Cy_DMAC_Channel_DeInit(DMAC, 0UL);

            /* if needed (if there is only channel used) the whole block can be disabled */
            Cy_DMAC_Disable(DMAC);
        }
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void * Cy_DMAC_Channel_GetCurrentSrcAddress (DMAC_Type const *base, uint32_t channel)

Returns the source address being used for the current transfer.

Return

Returns the pointer to the source of transfer.

Function Usage

    
    /* Scenario: Make sure the arrays are not in use before reading/modifying */
    
    uint32_t src[16];
    uint32_t dst[16];
    
    if (((void*) src != Cy_DMAC_Channel_GetCurrentSrcAddress(DMAC, 0UL)) &&
        ((void*) dst != Cy_DMAC_Channel_GetCurrentDstAddress(DMAC, 0UL)))
    {    
        /* Read the dst/modify the src arrays content here */
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void * Cy_DMAC_Channel_GetCurrentDstAddress (DMAC_Type const *base, uint32_t channel)

Returns the destination address being used for the current transfer.

Return

Returns the pointer to the destination of transfer.

Function Usage

    
    /* Scenario: Make sure the arrays are not in use before reading/modifying */
    
    uint32_t src[16];
    uint32_t dst[16];
    
    if (((void*) src != Cy_DMAC_Channel_GetCurrentSrcAddress(DMAC, 0UL)) &&
        ((void*) dst != Cy_DMAC_Channel_GetCurrentDstAddress(DMAC, 0UL)))
    {    
        /* Read the dst/modify the src arrays content here */
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetCurrentXloopIndex (DMAC_Type const *base, uint32_t channel)

Returns the current transfer X-loop index.

Return

Returns the current transfer X-loop index.

Function Usage

    
    /* Scenario: Make sure the current indexes are greater than a desired 
     * data source item before modifying.
     */
    
    uint32_t src[16][16];
    uint32_t x = 7;
    uint32_t y = 8;
    
    if (((void*) src == Cy_DMAC_Channel_GetCurrentSrcAddress(DMAC, 0UL)) &&
                   (x < Cy_DMAC_Channel_GetCurrentXloopIndex(DMAC, 0UL)) &&
                   (y < Cy_DMAC_Channel_GetCurrentYloopIndex(DMAC, 0UL)))
    {    
        /* Modify the src arrays content here */
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetCurrentYloopIndex (DMAC_Type const *base, uint32_t channel)

Returns the current transfer X-loop index.

Return

Returns the current transfer X-loop index.

Function Usage

    
    /* Scenario: Make sure the current indexes are greater than a desired 
     * data source item before modifying.
     */
    
    uint32_t src[16][16];
    uint32_t x = 7;
    uint32_t y = 8;
    
    if (((void*) src == Cy_DMAC_Channel_GetCurrentSrcAddress(DMAC, 0UL)) &&
                   (x < Cy_DMAC_Channel_GetCurrentXloopIndex(DMAC, 0UL)) &&
                   (y < Cy_DMAC_Channel_GetCurrentYloopIndex(DMAC, 0UL)))
    {    
        /* Modify the src arrays content here */
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE cy_stc_dmac_descriptor_t * Cy_DMAC_Channel_GetCurrentDescriptor (DMAC_Type const *base, uint32_t channel)

Returns the descriptor that is active in the channel.

Return

The pointer to the descriptor associated with the channel.

Function Usage

    /* Scenario: Disable a descriptor */
    if (&descriptor != Cy_DMAC_Channel_GetCurrentDescriptor(DMAC, 0UL)) /* Make sure it is not in use */
    {
        Cy_DMAC_Descriptor_DeInit(&descriptor);
    }
    

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetInterruptStatus (DMAC_Type const *base, uint32_t channel)

Returns the interrupt status of the specified channel.

Return

The interrupt status, see Interrupt Masks.

Function Usage

    /* Scenario: Need to check the  interrupt status regardless of whether it is enabled (masked) or not */
    if (CY_DMAC_INTR_MASK == Cy_DMAC_Channel_GetInterruptStatus (DMAC, 0UL))
    {
        /* The DMAC channel 0 interrupt is pending */
    }

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void Cy_DMAC_Channel_ClearInterrupt (DMAC_Type *base, uint32_t channel, uint32_t interrupt)

Clears the interrupt status of the specified channel.

Function Usage

    /* Scenario: Inside the interrupt service routine for DMAC channel 0: */    
    uint32_t interrupt = Cy_DMAC_Channel_GetInterruptStatusMasked(DMAC, 0UL);

    if (CY_DMAC_INTR_COMPLETION == interrupt)
    {
        /* Insert completion interrupt handling */
    }

    /* Check for other interrupts */

    /* Clear interrupts */
    Cy_DMAC_Channel_ClearInterrupt(DMAC, 0UL, interrupt);

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

  • interrupt: The interrupt mask, see Interrupt Masks.

__STATIC_INLINE void Cy_DMAC_Channel_SetInterrupt (DMAC_Type *base, uint32_t channel, uint32_t interrupt)

Sets the interrupt for the specified channel.

Function Usage

    /* Scenario: Enable interrupts for channel 0 */
    Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, CY_DMAC_INTR_MASK);
    
    /* Scenario: Test the interrupt for channel 0 */
    Cy_DMAC_Channel_SetInterrupt(DMAC, 0UL, CY_DMAC_INTR_COMPLETION);
    /* Now the interrupt should occur (if it is enabled, of course) */

    /* Scenario: Disable interrupts for DMAC channel 0 if it is enabled */
    if (CY_DMAC_INTR_MASK == Cy_DMAC_Channel_GetInterruptMask(DMAC, 0UL))
    {
        Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, 0UL);
    }

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

  • interrupt: The interrupt mask. See Interrupt Masks.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetInterruptMask (DMAC_Type const *base, uint32_t channel)

Returns the interrupt mask value of the specified channel.

Return

The interrupt mask value. See Interrupt Masks.

Function Usage

    /* Scenario: Enable interrupts for channel 0 */
    Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, CY_DMAC_INTR_MASK);
    
    /* Scenario: Test the interrupt for channel 0 */
    Cy_DMAC_Channel_SetInterrupt(DMAC, 0UL, CY_DMAC_INTR_COMPLETION);
    /* Now the interrupt should occur (if it is enabled, of course) */

    /* Scenario: Disable interrupts for DMAC channel 0 if it is enabled */
    if (CY_DMAC_INTR_MASK == Cy_DMAC_Channel_GetInterruptMask(DMAC, 0UL))
    {
        Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, 0UL);
    }

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

__STATIC_INLINE void Cy_DMAC_Channel_SetInterruptMask (DMAC_Type *base, uint32_t channel, uint32_t interrupt)

Sets an interrupt mask value for the specified channel.

Function Usage

    /* Scenario: Enable interrupts for channel 0 */
    Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, CY_DMAC_INTR_MASK);
    
    /* Scenario: Test the interrupt for channel 0 */
    Cy_DMAC_Channel_SetInterrupt(DMAC, 0UL, CY_DMAC_INTR_COMPLETION);
    /* Now the interrupt should occur (if it is enabled, of course) */

    /* Scenario: Disable interrupts for DMAC channel 0 if it is enabled */
    if (CY_DMAC_INTR_MASK == Cy_DMAC_Channel_GetInterruptMask(DMAC, 0UL))
    {
        Cy_DMAC_Channel_SetInterruptMask (DMAC, 0UL, 0UL);
    }

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.

  • interrupt: The interrupt mask, see Interrupt Masks.

__STATIC_INLINE uint32_t Cy_DMAC_Channel_GetInterruptStatusMasked (DMAC_Type const *base, uint32_t channel)

Returns the logical AND of the corresponding INTR and INTR_MASK fields in a single-load operation.

Return

The masked interrupt status. See Interrupt Masks.

Function Usage

    /* Scenario: Inside the interrupt service routine for DMAC channel 0: */    
    uint32_t interrupt = Cy_DMAC_Channel_GetInterruptStatusMasked(DMAC, 0UL);

    if (CY_DMAC_INTR_COMPLETION == interrupt)
    {
        /* Insert completion interrupt handling */
    }

    /* Check for other interrupts */

    /* Clear interrupts */
    Cy_DMAC_Channel_ClearInterrupt(DMAC, 0UL, interrupt);

Parameters
  • base: The pointer to the hardware DMAC block.

  • channel: The channel number.