I will continue with the rest of the code and the questions here.
This was the first function i made, because in the future project in hich I want to use DMA I think i will need integers.
void
int_tx_rx()
{
int send={1,2,3,4,5,6,7,8,9,10,11,12};
int length=sizeof(send)/sizeof(int);
printf("length=%i\n", length);
int rc;
alt_dma_txchan txchan;
alt_dma_rxchan rxchan;
void* rx_buffer = (void*) (ONCHIP_MEMORY2_1_BASE); /* pointer to rx buffer */
/* Create the transmit channel */
if ((txchan = alt_dma_txchan_open("/dev/dma_0")) == NULL)
{
printf ("Failed to open transmit channel\n");
exit (1);
}
else
{
if( alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_32,NULL) <0 )
printf("failed to set RX_MODE_32\n");
}
/* Create the receive channel */
if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == NULL)
{
printf ("Failed to open receive channel\n");
exit (1);
}
else
{
if( alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_32,NULL) <0)
printf("failed to set TX_MODE_32\n");
}
/* Post the receive request */
if ((rc = alt_dma_rxchan_prepare (rxchan,rx_buffer,length*sizeof(int),done_rx,NULL)) < 0)
{
printf ("Failed to post read request, reason = %i\n", rc);
exit (1);
}
/* Post the transmit request */
if ((rc = alt_dma_txchan_send (txchan,send,length*sizeof(int),done_tx ,NULL)) < 0)
{
printf ("Failed to post transmit request, reason = %i\n", rc);
exit (1);
}
/* wait for transfer to complete */
while (!rx_done);
printf("send \n");
int i;
for(i=0;i<length;i++)
printf ("%i \r",send);
int *p;
//p=(void*) ONCHIP_MEMORY2_1_BASE;
p=rx_buffer;
printf("\nreceived \n");
for(i=0;i<length;i++)
printf ("%i \r",*(p+i));
alt_dma_rxchan_close(rxchan);
alt_dma_txchan_close(txchan);
}
Here I have some serious problems. The code is sometimes working, but only in this configuration, when I transmit exactly 12 int's(any int value).
The questions here are:
1) Apparently I'm not setting the data transfer to 32bites. I deduced this from the need to multiply the length by the size of int.
2) when it worked( earlier today, when my boss came in and I tryed to run the program, it didn't work :oops: ) if I modified the length of the string, I encountered some unexpected transfers(the first or the second half was transfered well, and the other one it had some unknown values).
Does anyone got an ideea about these problems?
Thanks, alex