Realize UART (Serial Port) communication by using S3C2440 mini 2440 DMA

Source: Internet
Author: User

After a long time, the DMA method was finally completed for serial communication. It is not difficult to use DMA, mainly because dconn is difficult to configure and understand several modes.

DMA service mode: Single Service & whole service. In the previous mode, one DMA request completes an atomic operation and the value of transfer count is reduced by 1. In the latter mode, a DMA request completes a batch of atomic operations until the value of transfer count is 0, indicating that the overall service is completed. Dcon [27].

 

DMA dreq/Dack Protocol: There are two protocols for DMA requests and responses: Demond mode and handshake mode. The two have different time series definitions for request and ACK:

In Demond mode, if the request is still valid after the DMA completes a request, the DMA considers it as the next DMA request and starts the next transmission immediately;

In handshake mode, wait for the request signal to be invalid after the DMA completes a request. If the request is invalid, the DMA will be invalid for the ACK two clock cycles, and then wait for the next request.

/*************************************** ********************************

Function: Achieve serial transmission using DMA,
Pass the string data to utxh0 through the dma0 channel, and then
Display. After data transmission, dma0 is interrupted and led1 is on.
**************************************** ********************************
Mini2440 debugging passed
2012-08-05
**************************************** *****************************/
# Include "2440addr. H"
# Define mdiv 92
# Define sdiv 1
# Define pdiv 1
# Define hdivn 2
# Define pdivn 1
# Define pclk-50000000
# Define ledbench on () {rgpbdat & = (~ (1 <5 ));}

Char * sendbuffer = "Hello world! "; // Source data

******************** ****************/
Void led_init ()
{
Rgpbcon & = ~ (3 <10) | (3 <12) | (3 <14) | (3 <16) | (3 <0 ));
Rgpbcon | = (1 <10) | (1 <12) | (1 <14) | (1 <16) | (1 <0 ));
Rgpbup & = ~ (1 <5) | (1 <6) | (1 <7) | (1 <8) | (1 <0 ));
Rgpbdat = 0 xfffe;
}

/**************** Uart0 IO port initialization ****************** **********/
Void uart0_io_init () // uart io port
{
Rgphcon = 0xa0; // gph2, gph3 used for txd0, rxd0.
Rgphup = 0x0; // enable the pull up Function
}

/*************************** Uart0 configuration ********** ******************/
Void uart0_init (INT bandrate)
{
Rulcon0 | = 0x3; // 8-bit data, 1bit stop
Rucon0 | = (1 <0) | (1 <3) | (2 <10); // used pclk as the clock, transmit use DMA mode, receive use polling Mode
Rubrdiv0 = (INT) (pclk _/(bandrate * 16)-1; // bandrate is 115200

}

********** **********************************/
Void clk_init ()
{
Rclkcon | = (1 <10); // enable uart0 used pclk
Rlocktime = 0 xFFFF; // locktime
Rclkcon | = (1 <13); // gpio enable pclk
Rclkdivn = (pdivn <0) | (hdivn <1 ); //
Rmpllcon | = (mdiv <12) | (pdiv <4) | (sdiv <0); // f_out = 400 MHz
// _ ASM {
// MRC P15, 0, R1, C1, C0, 0
// Orr R1, R1, #0xc0000000
// MCR P15, 0, R1, C1, C0, 0
//}
}

/***************************** DMA initialization ******** *******************************/
Void dma_init ()
{
Rgpbcon | = (1 <19) | (1 <21); // gpb9, 10 used for nxdack0, nxdreq0
Rdisrc0 = (u32) sendbuffer; // source data address
Rdisrcc0 | = (0 <1) | (0 <0); // address increment, the source is in the AHB
Rdidst0 = (u32) utxh0; // destination is utxh0
Rdidstc0 | = (0 <2) | (1 <1) | (1 <0); // address not change, APB, enable interrupt


Rdcon0 | = (1 <31) | (0 <30) | (1 <29) | (0 <28) | (0 <27) | (1 <24) | (1 <23) | (1 <22) | (0 <20) | (12 );
// Handshake mode, pclk synchronization, enable DMA interrupt, unit transfer, single service,
// Uart0 is the request source, H/W request mode, disable auto reload, byte transmit, 12 byte data
Rdmasktrig0 = (0 <2) | (1 <1) | (0 <0); // start DMA transmit
}

/********************* DMA interrupt initialization ************** *************************/
Void dma_eint ()
{
Rintmsk & = ~ (1 <17); // open the dma0 interrupt
}

/*********************** DMA interrupt service function *********** **********************/
Void _ IRQ dma_isr ()
{
Rsrcpnd | = (1 <17); // clear the srcpnd
Rintpnd | = (1 <17); // clear the int PND
Ledbench on ();
}

Int main ()
{
Clk_init ();
Led_init ();
Uart0_io_init ();
Uart0_init (115200 );
Dma_eint ();
Pisr_dma0 = (u32) dma_isr;
Dma_init ();
While (1)
{
;
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.