This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] AM2634:DMA 模式下的 UART 接收中断

Guru**** 2460380 points
Other Parts Discussed in Thread: AM2634

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1481250/am2634-uart-receive-interrupt-in-dma-mode

器件型号:AM2634

工具与软件:

大家好、团队成员:

我使用的是 AM2634评估板、并尝试在 DMA 模式下接收 UART 上的数据、可以在现有代码示例中正常工作、但只运行一次、

我想持续使用它、请告诉我最好的方法

我也尝试过这个,但不起作用

DMA 接收回调函数。

void RxCallback (UART_Handle handle、UART_Transaction * TRANS)


/*读取8个字符*/
gNumBytesRead = 0u;
Trans->buf =&gUartReceiveBuffer[0U];
TRANS->COUNT = APP_UART_RECEIVE_BUFSIZE;
UART_Transaction_init (trans);
CacheP_WBInv ((void *)&gUartReceiveBuffer[0U]、APP_UART_RECEIVE_BUFSIZE、CacheP_TYPE_ALL);
transferOKrx = UART_read (gUartHandle[CONFIG_UART_CONSOLE]、TRANS);
APP_UART_ASSERT_ON_FAILURE (transferOKrx、trans);
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Rohal:

    您能否解释一下在这里为 UART_read API 使用 while 循环时"持续"的含义?

    此致、

    Anil

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    连续意味着在获得8个字节(阈值设置值)后、它应该准备好接收接下来的8个字节、依此类推、因为现有示例代码仅在我需要它一定程度时有效一次。

    请告诉我如何 在 UART 上接收可变长度数据、因为根据我的应用、用户可以发送 可变大小的数据、这意味着有时他可以发送10、20或50个字节   

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Rohal:

    连续意味着在获得8字节(阈值设定值)后、它应该准备好接收下一个8字节、依此类推、因为现有示例代码仅在我有限需要时运行一次。

    目前、该应用旨在从用户获取8B 输入、然后回显相同的8B 并退出应用、因此您必须修改该应用、以保持接收数据(例如在 while 循环中、继续接收数据)。

    此致、
    Shaunak

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我也尝试了该功能、但它在获得8个字节后未接收到任何中断、因此我们是否需要清除所有中断标志以使其再次运行

     CacheP_WBInv ((void *)&gUartReceiveBuffer[0U]、APP_UART_RECEIVE_BUFSIZE、CacheP_TYPE_ALL);  

    上述 API 阻止了我的过程、请告诉我如何删除高速缓存、并在每次接收字节时获取中断  

    我们是否可以使用 具有中断平均值的 DMA 在发送所有数据后执行传输 Get 中断、在获取数据后执行接收 Get 中断(仅 DMA 执行所有传输和接收)  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Rohal:

    我相信你的同事也在这里提出同样的问题: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1479707/am2634-uart-dma-receive-callback-reinitialization
    我已经给出了代码片段、我可以测试多个 UART 读取和写入。

    并且请告诉我如何 在 UART 上接收可变长度数据、因为根据我的应用程序、用户可以发送 可变大小的数据意味着有时他可以发送10、20或50字节  

    关于这一点、让我稍后再带步回到这里。

    此致、
    Shaunak

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    是的、请尽快查看此内容、

    这里还注意到一个问题、

    我在 DMA 模式下配置5字节接收中断、它仅在5个字节内正常工作、如果用户发送的字节超过5、则让6停止接收中断、  

    我将共享该代码、也请检查

    /*
     *  Copyright (C) 2021 Texas Instruments Incorporated
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /* This example demonstrates the UART RX and TX operation by echoing char
     * that it recieves in blocking, interrupt mode of operation.
     * When user types 'quit', the application ends.
     */
    
    #include <string.h>
    #include <kernel/dpl/DebugP.h>
    #include "ti_drivers_config.h"
    #include "ti_drivers_open_close.h"
    #include "ti_board_open_close.h"
    
    
    #define APP_UART_BUFSIZE              (200U)
    #define APP_UART_RECEIVE_BUFSIZE      (20U)
    
    uint8_t gUartBuffer[APP_UART_BUFSIZE] __attribute__((aligned(CacheP_CACHELINE_ALIGNMENT)));
    uint8_t gUartReceiveBuffer[APP_UART_RECEIVE_BUFSIZE] __attribute__((aligned(CacheP_CACHELINE_ALIGNMENT)));
    volatile uint32_t gNumBytesRead = 0U, gNumBytesWritten = 0U;
    
    #define APP_UART_ASSERT_ON_FAILURE(transferOK, transaction) \
        do { \
            if((SystemP_SUCCESS != (transferOK)) || (UART_TRANSFER_STATUS_SUCCESS != transaction.status)) \
            { \
                DebugP_assert(FALSE); /* UART TX/RX failed!! */ \
            } \
        } while(0) \
    
    
    static SemaphoreP_Object gUartWriteDoneSem;
    static SemaphoreP_Object gUartReadDoneSem;
    static uint8_t rxcomplete=0;
    void uart_echo_dma(void *args)
    {
        int32_t          transferOK, status;
        UART_Transaction trans;
        UART_Transaction transRx;
    
        Drivers_open();
        Board_driversOpen();
    
        DebugP_log("[UART] Echo example DMA mode started ...\r\n");
    
        status = SemaphoreP_constructBinary(&gUartWriteDoneSem, 0);
        DebugP_assert(SystemP_SUCCESS == status);
    
        status = SemaphoreP_constructBinary(&gUartReadDoneSem, 0);
        DebugP_assert(SystemP_SUCCESS == status);
        UART_Transaction_init(&trans);
        UART_Transaction_init(&transRx);
    
        /* Send entry string */
        gNumBytesWritten = 0U;
        trans.buf   = &gUartBuffer[0U];
        strncpy(trans.buf,"This is uart echo test DMA blocking mode\r\nReceives 8 characters then echo's back. Please input..\r\n", APP_UART_BUFSIZE);
        trans.count = strlen(trans.buf);
        CacheP_wb((void *)trans.buf, trans.count, CacheP_TYPE_ALL);
        transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
    
        APP_UART_ASSERT_ON_FAILURE(transferOK, trans);
        SemaphoreP_pend(&gUartWriteDoneSem, SystemP_NO_WAIT);
    
        CacheP_wbInv((void *)&gUartReceiveBuffer[0U], APP_UART_RECEIVE_BUFSIZE, CacheP_TYPE_ALL);
        /* Read 8 chars */
        gNumBytesRead = 0U;
        transRx.buf   = &gUartReceiveBuffer[0U];
        transRx.count = 5;
        transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &transRx);
        APP_UART_ASSERT_ON_FAILURE(transferOK, transRx);
        SemaphoreP_pend(&gUartReadDoneSem, SystemP_NO_WAIT);
    
        /* Echo chars entered */
    
        while(1)
        {
            if(rxcomplete==1)
            {
                gNumBytesWritten = 0U;
                trans.buf   = &gUartReceiveBuffer[0U];
                trans.count = transRx.count;
                transferOK = UART_write(gUartHandle[CONFIG_UART_CONSOLE], &trans);
                APP_UART_ASSERT_ON_FAILURE(transferOK, trans);
                SemaphoreP_pend(&gUartWriteDoneSem, SystemP_NO_WAIT);
                rxcomplete=0;
    
                gNumBytesRead = 0U;
                transRx.buf   = &gUartReceiveBuffer[0U];
                transRx.count = 5;
                transferOK = UART_read(gUartHandle[CONFIG_UART_CONSOLE], &transRx);
                APP_UART_ASSERT_ON_FAILURE(transferOK, transRx);
                SemaphoreP_pend(&gUartReadDoneSem, SystemP_NO_WAIT);
            }
        }
        /* Send exit string */
    
        return;
    }
    void RxCallback(UART_Handle handle, UART_Transaction *transaction)
    {
        DebugP_assertNoLog(UART_TRANSFER_STATUS_SUCCESS == transaction->status);
        gNumBytesRead = transaction->count;
        SemaphoreP_post(&gUartReadDoneSem);
        rxcomplete=1;
    //        (void)RTI_counterEnable(CONFIG_RTI0_BASE_ADDR, RTI_TMR_CNT_BLK_INDEX_0);
    
    
    }
    
    void TxCallBack(UART_Handle handle, UART_Transaction *transaction)
    {
        DebugP_assertNoLog(UART_TRANSFER_STATUS_SUCCESS == transaction->status);
           gNumBytesWritten = transaction->count;
           SemaphoreP_post(&gUartWriteDoneSem);
    }
    uint8_t timer1ms;
    void TimerCallback()
    {
        timer1ms++;
    //    rxcomplete = 1;
        (void)RTI_counterDisable(CONFIG_RTI0_BASE_ADDR, RTI_TMR_CNT_BLK_INDEX_0);
    
    }
    
     

    请建议还如何处理 UART 错误(帧错误和过度运行错误)

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Rohal:

    一个问题、

    在 example.syscfg 中、您在 UART 模块中配置的值是多少? 默认情况下、触发级别设为8

    这意味着一旦 Rx FIFO 具有8个字节、它就会触发一个中断。

    此致、
    Shaunak