{"id":862,"date":"2024-08-14T17:21:44","date_gmt":"2024-08-14T09:21:44","guid":{"rendered":"http:\/\/8.153.64.192\/?page_id=862"},"modified":"2024-08-16T14:15:20","modified_gmt":"2024-08-16T06:15:20","slug":"%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_uart_dmairq","status":"publish","type":"page","link":"http:\/\/www.agm-support.com.cn\/index.php\/sample-page\/%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_uart_dmairq\/","title":{"rendered":"\u9a71\u52a8\u8865\u5145\uff1aexample_uart_dmaIrq"},"content":{"rendered":"\n<p>\/\/example_uart_dmaIrq.c<\/p>\n\n\n\n<p>include \"example.h\"<\/p>\n\n\n\n<p>\/*<br>\u6837\u4f8b\u8bf4\u660e\uff1a<br>\u4ee5\u4e0b\u6837\u4f8b\u91cc\u8fb9\uff0c\u7528\u4e86\u4e32\u53e30\u548c\u4e32\u53e31.<\/p>\n\n\n\n<p>\u4e32\u53e30\u662f\u6253\u5370log\u7684\uff0c\u5c31\u662fprintf\u7684\u51fa\u53e3\u3002\u53ea\u662f\u7528\u6765\u68c0\u6d4b\u4e0b\u8fd0\u884c\u7ed3\u679c\u3002<br><br>\u4e32\u53e31\u662f\u6d4b\u8bd5dma\u6536\u548cdma\u53d1\u3002<br>\u4f7f\u7528\u65f6\uff0c\u9700\u8981\u5728ve\u91cc\u5b9a\u4e49\u4e32\u53e31\u7684\u4e24\u4e2a\u5f15\u811a\uff0c\u7136\u540ePC\u7aef\u63a5\u4e32\u53e31\uff0c\u6765\u8fdb\u884c\u6536\u53d1\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p>*\/<br>\/\/<br>\/\/\u8fd9\u91cc\u7684\u5b9e\u73b0\u65b9\u5f0f\u662f\uff1adma\u53d1\u9001 + dma-tc\u4e2d\u65ad\u3002<br>\/\/\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u7528\u4e8e\u4e0d\u592a\u7cbe\u786e\u7684\u53d1\u9001\u5b8c\u6210\u5b9a\u4f4d\u3002<br>\/\/<br>\/\/\u56e0\u4e3a\u4ece\u7ec6\u8282\u6765\u8bf4\uff0cdma\u53d1\u9001\u5b8c\uff0c\u5e76\u4e0d\u662f\u771f\u6b63\u7684\u201ctx\u7ebf\u4e0a\u7684\u6ce2\u5f62\u201d\u53d1\u9001\u5b8c\u3002<br>\/\/\u53d1\u9001\u4e00\u4e2a\u5b57\u8282\u7684\u6d41\u7a0b\u662f\uff1a\u3010\u5f00\u59cb\u3011dma\u628a\u4e00\u4e2a\u6570\u636e\u642c\u5230uart fifo -&gt; \u4e32\u53e3\u6a21\u5757\u4ecefifo\u53d6\u5230\u6570\u636e\u5f00\u59cb\u4ea7\u751ftx\u6ce2\u5f62 -&gt; \u5168\u90e8\u6ce2\u5f62\u53d1\u9001\u5b8c\u6bd5\u3010\u7ed3\u675f\u3011<br>\/\/\u5bf9\u4e8e DMA-TXTC\u4e2d\u65ad\u6765\u8bf4\uff0c\u7b2c\u4e00\u6b65\u7ed3\u675f\u5c31\u4ea7\u751f\u4e2d\u65ad\u4e86\u3002\u800c\u771f\u6b63\u7684\u6570\u636e\u53d1\u9001\u5b8c\u662f\u5230\u7b2c\u4e09\u6b65\u7ed3\u675f\u3002<br>\/\/\u6240\u4ee5\uff0c\u5982\u679c\u662f\u4e00\u822c\u4f7f\u7528\uff0c\u4e0d\u4ecb\u610f\u6700\u540e\u4e00\u4e2a\u5b57\u8282\u7684\u65f6\u95f4\u7684\uff0c\u8fd9\u4e2a\u4e2d\u65ad\u662f\u53ef\u4ee5\u4f7f\u7528\u7684\u3002<br>\/\/<br>\/\/\u4f46\u5982\u679c\u662f\u7528\u4e8e485\u4f20\u8f93\uff0c\u9700\u8981\u7cbe\u786e\u5b9a\u4f4d\u5230\u201c\u5f7b\u5e95\u53d1\u9001\u5b8c\u7684\u90a3\u4e2a\u70b9\u201d\u4ea7\u751f\u4e2d\u65ad\uff0c\u90a3\u4e48\u4ee5\u4e0a\u65b9\u5f0f\u662f\u4e0d\u884c\u7684\u3002\u9700\u8981\u4f7f\u7528uart-tc\u4e2d\u65ad\u6765\u66ff\u6362dma-tc\u4e2d\u65ad\u3002<br>\/\/\u5373\uff0c\u5b9e\u73b0\u65b9\u5f0f\u4e3a\uff1admaTx + uartTC\u4e2d\u65ad<br>\/\/\u5728dma\u7684\u8fde\u7eed\u53d1\u9001\u4e2d\uff0c\u662f\u4e0d\u4f1a\u4ea7\u751f\u7684 uartTC\u4e2d\u65ad\u7684\uff0c\u76f4\u5230\u5168\u90e8\u53d1\u9001\u5b8c\uff0c\u624d\u4ea7\u751f\u8be5\u4e2d\u65ad\u3002<br>\/\/<\/p>\n\n\n\n<p>volatile int txIqrFlag = 0, rxIqrFlag = 0;<br>void DMAC0_INTTC_isr(void)<br>{<br>    if (DMAC_IsChannelRawIntErrorActive(DMAC_CHANNEL0))<br>    {<br>        \/\/error code<br>        DMAC_ClearChannelIntError(DMAC_CHANNEL0);<br>    }<br>    else if (DMAC_IsChannelRawIntTCActive(DMAC_CHANNEL0))<br>    {<br>        \/\/clear flag<br>        DMAC_ClearChannelIntTC(DMAC_CHANNEL0);<\/p>\n\n\n\n<p>        \/\/ to do...<br>        txIqrFlag = 1;<\/p>\n\n\n\n<p>    }<br>    else if (DMAC_IsChannelRawIntTCActive(DMAC_CHANNEL1))<br>    {<br>        \/\/clear flag<br>        DMAC_ClearChannelIntTC(DMAC_CHANNEL1);<\/p>\n\n\n\n<p>        \/\/ to do...<br>        rxIqrFlag = 1;<\/p>\n\n\n\n<p>    }<br>}<\/p>\n\n\n\n<p>void TestUartDMAIqr(void)<br>{<br>    GPIO_AF_ENABLE(UART1_UARTRXD)<br>    GPIO_AF_ENABLE(UART1_UARTTXD);<br>    SYS_EnableAPBClock(APB_MASK_UART1);<\/p>\n\n\n\n<p>    \/\/tx buff<br>    const char txbuf[] = \"This quick brown fox jumps over the lazy dog!\\n\";<br>    const volatile uint32_t txLen = sizeof(txbuf) - 1; \/\/ Strip the ending '0'<\/p>\n\n\n\n<p>    \/\/rx buff<br>    char rxbuf[256] = {0};<br>    int rxLen = 30;<\/p>\n\n\n\n<p>    SYS_EnableAHBClock(AHB_MASK_DMAC0);<br>    DMAC_Init();<\/p>\n\n\n\n<p>    UART_Init(UART1, 115200, UART_LCR_DATABITS_8, UART_LCR_STOPBITS_1, UART_LCR_PARITY_NONE, UART_LCR_FIFO_16);<br>    UART_SetDmaMode(UART1, UART_DMA_RX_TX);<\/p>\n\n\n\n<p>    uint8_t tx_dma_req = UART1_TX_DMA_REQ;<br>    uint8_t rx_dma_req = UART1_RX_DMA_REQ;<\/p>\n\n\n\n<p>    \/\/set tx dma<br>    DMAC_Config(DMAC_CHANNEL0, (uint32_t)txbuf, (uint32_t)&amp;UART1->DR,<br>        DMAC_ADDR_INCR_ON, DMAC_ADDR_INCR_OFF,<br>        DMAC_WIDTH_8_BIT, DMAC_WIDTH_8_BIT,<br>        DMAC_BURST_1, DMAC_BURST_1,<br>        txLen, DMAC_MEM_TO_PERIPHERAL_DMA_CTRL,<br>        0, tx_dma_req);<\/p>\n\n\n\n<p>    \/\/set rx dma<br>    DMAC_Config(DMAC_CHANNEL1, (uint32_t)&amp;UART1->DR, (uint32_t)rxbuf,<br>        DMAC_ADDR_INCR_OFF, DMAC_ADDR_INCR_ON,<br>        DMAC_WIDTH_8_BIT, DMAC_WIDTH_8_BIT,<br>        DMAC_BURST_1, DMAC_BURST_1,<br>        rxLen, DMAC_PERIPHERAL_TO_MEM_DMA_CTRL, rx_dma_req, 0);<\/p>\n\n\n\n<p>    \/\/enable interrupt<br>    INT_EnableIRQ(DMAC0_INTTC_IRQn, PLIC_MAX_PRIORITY);<\/p>\n\n\n\n<p>    \/\/test<br>    while(1)<br>    {<br>        UTIL_IdleUs(100e3);<\/p>\n\n\n\n<p>        if (rxIqrFlag == 1)<br>        {<br>          rxIqrFlag = 0;<br>          printf(\"rx:%s\\r\\n\", rxbuf);<br><br>          \/\/set dma for NEXT receive.<br>          memset(rxbuf, sizeof(rxbuf), 0);<br>          DMAC_Config(DMAC_CHANNEL1, (uint32_t)&amp;UART1->DR, (uint32_t)rxbuf,<br>              DMAC_ADDR_INCR_OFF, DMAC_ADDR_INCR_ON,<br>              DMAC_WIDTH_8_BIT, DMAC_WIDTH_8_BIT,<br>              DMAC_BURST_1, DMAC_BURST_1,<br>              rxLen, DMAC_PERIPHERAL_TO_MEM_DMA_CTRL, rx_dma_req, 0);<br>        }<br>        if (txIqrFlag == 1)<br>        {<br>          txIqrFlag = 0;<br>          printf(\"tx over\\r\\n\");<br>        }<\/p>\n\n\n\n<p>    }<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/example_uart_dmaIrq.c include \"example.h\" \/*\u6837\u4f8b\u8bf4\u660e\uff1a\u4ee5\u4e0b\u6837\u4f8b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","footnotes":""},"class_list":["post-862","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=862"}],"version-history":[{"count":4,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/862\/revisions"}],"predecessor-version":[{"id":866,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/862\/revisions\/866"}],"up":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}