AnsweredAssumed Answered

Using DMA for transferring data of unknown size ?

Question asked by Amit Kumar on Sep 12, 2014
Latest reply on Sep 22, 2014 by jeremyzhou

Hi

I am using K60, 100Mhz uc, CW10.6 with PE. I have configured DMA at UART. The data coming in the UART is of variable length and is in hex format. I am able to receive and parse the data of fix length but for variable length i am not able to do anything. I need your suggestion for going further and make this work.

 

since the data is in hex format, I cant use some function like

while(data[i] != '\n')

{

          new_data[i] = data[i];

          i++;

}

 

currently the data coming is something like

DATA [ 0 ]  ,  DATA [ 1 ]DATA [ 2 ]DATA [ 3 ]...............DATA [ 3 + n ]
IDLENGTH OF DATA     (n)Varying DATA depending on LENGTH

 

the length of data can vary from 1 - 255.

 

What I have done is :

 

DMA config

 

dm.jpg

 

when the packet size is 24(i.e fixed data size) it is working fine.

In final run I have set this transfer count to 255 from 24

 

In Events.C

 

void DMAT1_OnComplete(LDD_TUserData *UserDataPtr)

{

      Data_Get();

}


in main.c


void Data_Get()

{

     WAIT1_Waitus(1000);               // I don't know why but without this DMA is flagged multiple times and this function doesn't work

      if((Data[0] == 0x41) && (Data[1] == 0x42)) // ID Check

      {

           uint8_t lt = Data[2];

           for(i=0;i<lt;i++)

           {

                NEW_Data[i] = Data[3+i];

           }

           DMAT1_SetDestinationAddress(dmap, &Data[0]);

 

      }

      else

      {

           DMAT1_SetDestinationAddress(dmap, &Data[0]);

      }

}


The above function works fine for fixed length packet


for variable length I want to implement the following


void Data_Get()

{

      WAIT1_Waitus(1000);          // Remove this delay and make it work

      if((Data[0] == 0x41) && (Data[1] == 0x42))      // ID Check

      {

           uint8_t lt = Data[2];

           for(i=0;i<lt;i++)

           {

                NEW_Data[i] = Data[3+i];

           }

           DMAT1_SetDestinationAddress(dmap, &Data[0]);

           /* RESET the DMA transfer counter to 0 */

 

      }

      else

      {

           DMAT1_SetDestinationAddress(dmap, &Data[0]);

            /* RESET the DMA transfer counter to 0 */

      }

}


I tried DMAT1_SetTransferCount(dmap, 0);

but with this the total no. of data to be counted got changed and dma started flagging randomly.

I just want to reset the current value of the counter not the final value to be counted.


I hope I was able to explain my problem.


Kind Regards

Amit Kumar

Outcomes