TI中文支持网
TI专业的中文技术问题搜集分享网站

LAUNCHXL-CC1310: CC1310 串口配置参数readTimeout生效条件

Part Number:LAUNCHXL-CC1310

UART_Params_init(&params);
params.baudRate = 9600;
params.readMode = UART_MODE_CALLBACK;
params.writeMode = UART_MODE_CALLBACK;
params.readCallback = UART0_Read_Callback;
params.writeCallback = UART0_Write_Callback;
params.readTimeout = 1;
params.writeTimeout = 1;

readMode 设置为UART_MODE_CALLBACK时,readCallback 参数是否生效?

Alex Zhang:

可以生效的,请参照uart的api函数说明。

Non-blocking and will return immediately. When UART_write() or UART_read() has finished, the callback function is called from either the caller's context or from an interrupt context.

我在这里为您提供了链接:

https://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_4_20_02_07/docs/tidrivers/doxygen/html/_u_a_r_t_8h.html#a5b0b54681a2ee6ed54e5b24f49324173ae6b6bd5d2d5df859ad6724e89e605ebf

请参照以上文档。

,

genyi liu:

例如params.readTimeout = 1;是超时1ms还是1s ?

,

genyi liu:

§ readTimeout

uint32_t UART_Params_::readTimeout

Timeout for read calls in blocking mode.

这不是说在阻塞时才生效吗?

,

Alex Zhang:

genyi liu said:readMode 设置为UART_MODE_CALLBACK时

非阻塞并且会立即返回。当UART_write()或UART_read()完成时,将从调用者上下文或中断上下文中调用回调函数。

在启用中断的情况下从 UART 读取数据的函数。

UART_read() 从 UART 控制器读取数据。目的地由buffer指定,要读取的字节数由size给出。

在UART_MODE_BLOCKING中,UART_read() 会阻止任务执行,直到读取缓冲区中的所有数据。

在UART_MODE_CALLBACK中,UART_read() 不会阻止任务执行。相反,当传输完成时,将调用UART_Params::readCallback指定的回调函数。回调函数可以发生在调用者的上下文中或 HWI 或 SWI 上下文中,具体取决于设备特定的实现。在调用UART_close()之前,必须始终使用UART_readCancel()取消未完成的异步读取操作。

UART_read() 与UART_readPolling()互斥。对于打开的 UART 外设,可以使用UART_read() 或UART_readPolling() ,但不能同时使用两者。

警告
当处于UART_MODE_CALLBACK状态时,请勿从其自己的回调函数中调用 UART_read() 。

,

Alex Zhang:

genyi liu said:例如params.readTimeout = 1;是超时1ms还是1s ?

1ms

,

Alex Zhang:

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1071472/am5726-uart-driver-uart_write-call-never-returns-writemode-uart_mode_blocking-writetimeout-100?tisearch=e2e-sitesearch&keymatch=params.readTimeout#

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/946369/ccs-lp-cc2652rb-how-to-receive-uart-input-into-a-variable/3499026?tisearch=e2e-sitesearch&keymatch=params.readTimeout#3499026

为您提供了两个链接,希望对您这边有一定的帮助。

另外因为都是使用uart,属于硬件侧。有个例程您这边可以参考这个是cc26x2sdk中demo中的我在下面附上了代码部分示例

/** Copyright (c) 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.*//**======== uart2callback.c ========*/
#include <stdint.h>
#include <stddef.h>/* POSIX Header files */
#include <semaphore.h>/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART2.h>/* Driver configuration */
#include "ti_drivers_config.h"static sem_t sem;
static volatile size_t numBytesRead;/**======== callbackFxn ========*/
void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{if (status != UART2_STATUS_SUCCESS){/* RX error occured in UART2_read() */while (1) {}}numBytesRead = count;sem_post(&sem);
}/**======== mainThread ========*/
void *mainThread(void *arg0)
{char input;const char echoPrompt[] = "Echoing characters:\r\n";UART2_Handle uart;UART2_Params uartParams;int32_t semStatus;uint32_t status = UART2_STATUS_SUCCESS;/* Call driver init functions */GPIO_init();/* Configure the LED pin */GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);/* Create semaphore */semStatus = sem_init(&sem, 0, 0);if (semStatus != 0){/* Error creating semaphore */while (1) {}}/* Create a UART in CALLBACK read mode */UART2_Params_init(&uartParams);uartParams.readMode= UART2_Mode_CALLBACK;uartParams.readCallback = callbackFxn;uartParams.baudRate= 115200;uart = UART2_open(CONFIG_UART2_0, &uartParams);if (uart == NULL){/* UART2_open() failed */while (1) {}}/* Turn on user LED to indicate successful initialization */GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);/* Pass NULL for bytesWritten since it's not used in this example */UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);/* Loop forever echoing */while (1){numBytesRead = 0;/* Pass NULL for bytesRead since it's not used in this example */status = UART2_read(uart, &input, 1, NULL);if (status != UART2_STATUS_SUCCESS){/* UART2_read() failed */while (1) {}}/* Do not write until read callback executes */sem_wait(&sem);if (numBytesRead > 0){status = UART2_write(uart, &input, 1, NULL);if (status != UART2_STATUS_SUCCESS){/* UART2_write() failed */while (1) {}}}}
}

,

genyi liu:

在UART_MODE_CALLBACK中params.readTimeout是无效参数的意思吗

,

Alex Zhang:

genyi liu said:readMode 设置为UART_MODE_CALLBACK时,readCallback 参数是否生效?

会生效的。

,

Alex Zhang:

我不太明白您的意思。

,

Alex Zhang:

Alex Zhang said:另外因为都是使用uart,属于硬件侧。有个例程您这边可以参考这个是cc26x2sdk中demo中的我在下面附上了代码部分示例

您可以参考一下这个

,

Alex Zhang:

genyi liu said:在UART_MODE_CALLBACK中params.readTimeout是无效参数的意思吗

是的,因为他用于blocking

,

Alex Zhang:

genyi liu said:§ readTimeout

uint32_t UART_Params_::readTimeout

Timeout for read calls in blocking mode.

这不是说在阻塞时才生效吗?

您说的是正确的

赞(0)
未经允许不得转载:TI中文支持网 » LAUNCHXL-CC1310: CC1310 串口配置参数readTimeout生效条件
分享到: 更多 (0)