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.

[参考译文] CC3220SF:为什么 UART.h 读取回调失败?

Guru**** 2538930 points
Other Parts Discussed in Thread: CC3220SF

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

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1049724/cc3220sf-why-read-callback-fail-with-uart-h

器件型号:CC3220SF

您好、支持团队、

 

我们的产品使用 CC3220SF SoC。 SimpleLink-SDK 版本:simplelink_cc32xx_sdk_4_30_00_06。

在演示代码"AT_commands"(路径:C:\ti\simplelink_cc32xx_sdk_4_30_00_06\examples\rtos\CC3220SF_LAUNCHXL_demos\at_commands\tirtos\ccs)中,使用 UART.h 而不是 UART2.h

 

我使用示例代码“uartecho”并修改"uartecho.c"代码,然后在 Launchpad 中运行代码。

我的问题:

  1. 回调函数是 ISR (中断服务例程)?
  2. 第112行、如果没有 UART_READ (UART、INPUT、1)、则回调函数不起作用、为什么?
  3. 我同时通过 Terminal v1.9v 程序发送“$4C$53$31$32$33$34$35$23”,但我从未收到“RightMatch”消息。
  4. 无法在 UART.h 中使用 readcallback 函数? 因为我没有看到任何示例或演示代码将 readcallback 函数与 UART.h 一同使用

 

/*
 * Copyright (c) 2015-2020, Texas Instruments Incorporated
 * All rights reserved.
 *
 * 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.
 */

/*
 *  ======== uartecho.c ========
 */
#include <stdint.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>

/* Driver configuration */
#include "ti_drivers_config.h"

volatile char g_ucInput = 0;
volatile char g_ucRxDBuf[8] = {0};
volatile char g_ucTestLEDFlag = 0;

UART_Handle uart;
UART_Params uartParams;

void readcallback_LS (UART_Handle handle, void *buf, size_t count)
{
  char i;
  char i_input;
  UART_read(uart, &i_input, 1);
  g_ucInput = i_input;
  for(i=7; i>=1; i--)
  {
    g_ucRxDBuf[i] = g_ucRxDBuf[i-1];
  }
  g_ucRxDBuf[0]=g_ucInput;
} // End void readcallback_LS (UART_Handle handle, void *buf, size_t count)


/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    char        input;
    const char  echoPrompt[] = "Echoing characters:\r\n";
    const char  RightMatch[] = "Match J-MEX command\r\n";


    /* Call driver init functions */
    GPIO_init();
    UART_init();

    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.writeMode = UART_MODE_BLOCKING;
    uartParams.readCallback = readcallback_LS;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;
    uartParams.dataLength = UART_LEN_8;
    uartParams.stopBits = UART_STOP_ONE;
    uartParams.parityType = UART_PAR_NONE;

    uart = UART_open(CONFIG_UART_0, &uartParams);

    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }

    /* Turn on user LED to indicate successful initialization */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    UART_control(uart, UART_CMD_RXENABLE, NULL);

    UART_read(uart, &input, 1);

    /* Loop forever echoing */
    while (1) {
      // Lishen add[S]

      if( (g_ucRxDBuf[7]==0x4C) && (g_ucRxDBuf[6]==0x53) && (g_ucRxDBuf[0]==0x23) )
      {
        UART_write(uart, RightMatch, sizeof(RightMatch));
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
      }
      else
      {
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
      }
    }
}

谢谢、

Lishen

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

    您好!

    1. 回调函数是 ISR (中断服务例程)?

    是的、 上下文是硬件中断

    1. 第112行、如果没有 UART_READ (UART、INPUT、1)、则回调函数不起作用、为什么?

    应通过调用 read()或 write()来触发回调函数。

    读取或写入完成后、UART 驱动 程序应调用用户的回调函数。

    1. 我同时通过 Terminal v1.9v 程序发送“$4C$53$31$32$33$34$35$23”,但我从未收到“RightMatch”消息。

    您得到的结果是什么?

    1. 无法在 UART.h 中使用 readcallback 函数? 因为我没有看到任何示例或演示代码将 readcallback 函数与 UART.h 一同使用

    您说得对、虽然 UART 可以正常工作、但没有示例。

    Shlomi

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

    尊敬的 Shlomi:

    我参考 uart2callback 示例代码、我修改并测试此代码对我来说很好。 接下来、我将创建一个新线程、以便在(1){...}时为其提供服务 并获取24字节 RX 数据。 感谢你的帮助。

    /*
     * Copyright (c) 2015-2020, Texas Instruments Incorporated
     * All rights reserved.
     *
     * 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.
     */
    
    /*
     *  ======== uartecho.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* POSIX Header files */
    #include <semaphore.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    volatile char g_ucInput = 0;
    //volatile char g_ucRxDBuf[8] = {0};
    volatile char g_ucRxDBuf[24] = {0};
    volatile char g_ucTestLEDFlag = 0;
    
    
    static sem_t sem_UartRxCallBack;
    
    #if (0)
    void readcallback_LS (UART_Handle handle, void *buf, size_t count)
    {
      char i;
      char i_input;
      UART_read(uart, &i_input, 1);
      g_ucInput = i_input;
      for(i=7; i>=1; i--)
      {
        g_ucRxDBuf[i] = g_ucRxDBuf[i-1];
      }
      g_ucRxDBuf[0]=g_ucInput;
    } // End void readcallback_LS (UART_Handle handle, void *buf, size_t count)
    #endif
    
    void readcallback_LS (UART_Handle handle, void *buf, size_t count)
    {
      sem_post(&sem_UartRxCallBack);
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        unsigned char i;
        char        input;
        const char  echoPrompt[] = "Echoing characters:\r\n";
        const char  RightMatch[] = "Match J-MEX WiFi-Moti command\r\n";
        UART_Params uartParams;
        UART_Handle uart;
    
        /* Call driver init functions */
        GPIO_init();
        UART_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* Create semaphore */
        sem_init(&sem_UartRxCallBack, 0, 0);
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.writeMode = UART_MODE_BLOCKING;
        uartParams.readCallback = readcallback_LS;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
        uartParams.dataLength = UART_LEN_8;
        uartParams.stopBits = UART_STOP_ONE;
        uartParams.parityType = UART_PAR_NONE;
    
        uart = UART_open(CONFIG_UART_0, &uartParams);
    
        if (uart == NULL) {
            /* UART_open() failed */
            while (1);
        }
    
        /* Turn on user LED to indicate successful initialization */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
        UART_control(uart, UART_CMD_RXENABLE, NULL);      //callback function will work. so this is enable RX interrupt.
        //UART_control(uart, UART_CMD_RXDISABLE, NULL);     //callback function will not working. so this is disable RX interrupt.
    
        /* Loop forever echoing */
        while (1)
        {
          UART_read(uart, &input, 1);
          /* until read callback executes */
          sem_wait(&sem_UartRxCallBack);
          for(i=23; i>=1; i--)
          {
            g_ucRxDBuf[i] = g_ucRxDBuf[i-1];
          }
          g_ucRxDBuf[0]=input;
    
          if( (g_ucRxDBuf[23]==0x4C) && (g_ucRxDBuf[22]==0x53) && (g_ucRxDBuf[21]==0x14) && (g_ucRxDBuf[0]==0x23) )
          {
            UART_write(uart, RightMatch, sizeof(RightMatch));
            GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
            for(i=0; i<=23; i++)
            {
              g_ucRxDBuf[i] = 0;    // reset all UART RxD command Buffer
            }
          }
          else
          {
            GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
          }
        }
    }
    

    此致、

    Lishen