Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Cancel DMA operation.

How to cancel DMA operation for alt_dma_rx_chan?

DMA sequence:

1. alt_dma_rxchan_open

2. alt_dma_rxchan_ioctl ( ALT_DMA_SET_MODE_32 )

3. alt_dma_rxchan_ioctl ( ALT_DMA_RX_ONLY_ON )

4. alt_dma_rxchan_prepare

5. wait completion with a time-out

For example: stream device is UART.

If data have not been sent (by host to nios based system) during the time-out interval then time-out occured.

How correctly to do "Cancel" operation for DMA channel?

If programm simple call the alt_dma_close function then a next step sequence 1-5 will be failed.

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I've met a problem associats with DMA, i want to receive data from UART through DMA, and store the data into a buffer in on_chipram.

    As the handbook says, the alt_dma_rxchan_ioctl() function must been called correctly before can receive data. downside is my program, i don't know is it proper to call the function in that way, at least it doesn't work!

    --- Quote Start ---

    #include <stdio.h># include <stddef.h># include <stdlib.h># include "sys/alt_dma.h"# include "alt_types.h"# include <system.h>

    /* flag used to indicate the transaction is complete */

    volatile int dma_complete = 0;

    /* function that is called when the transaction completes */

    void dma_done (void* handle, void* data)

    {

    dma_complete = 1;

    }

    int main (void)

    {

    alt_u8 buffer[32];

    alt_dma_rxchan rx;

    FILE *fp;

    fp=fopen("dev/uart","r");

    /* Obtain a handle for the device */

    if ((rx = alt_dma_rxchan_open ("/dev/dma")) == NULL)

    {

    printf ("Error: failed to open device\n");

    exit (1);

    }

    else

    {

    /* Post the receive request */

    if (alt_dma_rxchan_ioctl(rx,ALT_DMA_RX_ONLY_ON ,NULL)<0)

    printf("error set\n");

    if (alt_dma_rxchan_prepare (rx, buffer, 32, dma_done, NULL) < 0)

    {

    printf ("Error: failed to post receive request\n");

    exit (1);

    }

    /* Wait for the transaction to complete */

    while (!dma_complete);

    printf ("Transaction complete\n");

    alt_dma_rxchan_close (rx);

    }

    return 0;

    }

    --- Quote End ---