(1)
Dma_1: memory to periheral
Read_master: Address of the array in SDRAM
Write_master: UART txdtxddata address
(2) uart ip Customization
(3)
Dma ip Customization
According to the DMA ds, at least two times the read_master depth is required. Otherwise, an error will occur (1024 is prepared here, so an increase of 11: bit is generated)
The number of times is the length of the data register, that is, the number, not the width.
The following is the custom DMA Ip's byte enabling option that allows transmission. In theory, UART only needs byte, but in fact it does not work, which will lead to transmission failure. I don't understand it. I can only select all at will, no errors
CodeThe original cactor is counterfeited as follows:
Http://blog.ednchina.com/chactor/185802/message.aspx
# Include <stdio. h>
# Include <stdlib. h>
# Include "sys/alt_dma.h"
# Include "system. H"
# Include "alt_types.h"
# Include "../INC/mcu_uart.h"
# Define char_length 1024
Static volatile int tx_done = 0;
Volatile static alt_u8 CHR [char_length];
// Callback function
Static void done (void * handle)
{
Tx_done ++;
}
Int main ()
{
// Output destination address space data through the serial port
Int I;
For (I = 0; I <char_length; I ++)
{
* (CHR + I) = I;
}
// Create a DMA receiving Channel
Alt_dma_txchan txchan;
// Source Address
Void * source_buff_ptr = (void *) CHR;
// Target address uart_base + 2, because the UART txdata register is after rxdata, the offset is the length of a rxdata (16 bits, 2 bits)
Void * destination_buff_ptr = (void *) (uart_base + 2 );
//-----------------------------------------------------------
/* Open the sending channel */
If (txchan = alt_dma_txchan_open ("/dev/dma_1") = NULL)
{
Printf ("failed to open transmit channel \ n ");
Exit (1 );
}
Else
Printf ("Open sending channel. \ n ");
// send
// set to send one byte each time, that is, eight bits, because UART sends only eight bits each time.
If (alt_dma_txchan_ioctl (txchan,
alt_dma_set_mode_8,
null) <0)
{< br> printf ("failed to set Mode 8 \ n ");
exit (1);
}< br> else
printf ("sets the 8-byte transmission mode. \ n ");
// configure
/* set the target address to fixed */
If (alt_dma_txchan_ioctl (txchan,
alt_dma_tx_only_on,
destination_buff_ptr) <0)
{< br> printf ("failed to set IOCTL. \ n ");
exit (1);
}< br> else
printf (" set the destination address to be fixed. \ n ");
//-----------------------------------------------------------
/* Start sending */
If (alt_dma_txchan_send (txchan,
Source_buff_ptr,
Char_length,
Done,
Null) <0)
{
Printf ("failed to post transmit request. \ n ");
Exit (1 );
}
Else
Printf ("start sending. \ n ");
//-----------------------------------------------------------
/* Wait until sending ends */
While (! Tx_done );
Printf ("transfer successful! \ N ");
//-----------------------------------------------------------
// Disable the DMA receiving Channel
Alt_dma_txchan_close (txchan );
Return 0;
}
Summary:
(1) The dma ip address is customized to enable the byte enabling option for transmission. In theory, UART only needs byte, but actually it does not work, which will lead to transmission failure. I don't understand, you can only select all options at will without errors. I don't know why, no matter whether I re-enable mode 9 in the code or not
(2) void * destination_buff_ptr = (void *) (uart_base + 2); ioaddr_altera_avalon_uart_txdata (uart_base) cannot be written here; because a word is aligned, an address is an address, I cannot explain it clearly, but the chactor is wrong here. Who can help me explain clearly.
(3) solve the basic architecture and continue with my video_capture