1 Reply Latest reply on Jun 8, 2017 10:06 PM by AnkitaS_51

    switching between 2 DMA channels

      Hi ,


      I am having problems with unpredictable DMA transfers. sometimes everything works, sometimes it seems that the DMA is either not working at all or running over data structures in memory.  


      I have a SPI-Slave connected to 2 different DMA components. each responsible for copying data from the SPIS to a different buffer. 
      the idea is to switch the active DMA between the two allowing time to handle the data in the other buffer without losing data. since the packet size is dynamic, a mechanism is in place to get the position of the DMA destination address so a packet size could be calculated.


      setting the DMA is using (example for one of the channels):


      channel_rx_1 = DMA_Rx_1_DmaInitialize(1,1, HI16((uint32)SPIS_RXDATA_PTR), HI16((uint32)(slaveRxDataBuffer_1) );
      TD_rx_1= CyDmaTdAllocate();
      CyDmaTdSetAddress(TD_rx_1, LO16(((uint32)SPIS_RXDATA_PTR)), LO16(((uint32)slaveRxDataBuffer_1));
      CyDmaTdSetConfiguration(TD_rx_1,MAX_BUFFER_SIZE, 0xFF,TD_INC_DST_ADR);
      CyDmaChSetInitialTd(channel_rx_1, TD_rx_1);
      CyDmaChEnable(channel_rx_1, 0)


      stopping (when packet is over) using :


      CyDmaTdGetConfiguration(TD_rx_1,&dma_location,0,0); //get size of packet


      this repeats (enabling and disabling) every time a packet is received. jumping from DMA A to DMA B as the active one.
      only the drq on the active one will be triggered.


      is this the best way to jump between 2 DMA channels ? is there something wrong with the setup/stopping of the DMA ?