下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

FreeRTOS_read()

[FreeRTOS-Plus-IO API]

FreeRTOS_IO.h
size_t FreeRTOS_read( Peripheral_Descriptor_t const pxPeripheral, 
                      void * const pvBuffer, 
                      const size_t xBytes );
		

从打开的外围设备读取一个或多个字节。

板级支持包 定义了可以打开的外围设备。 FreeRTOS_ioctl() 用于在中断驱动读取模式和轮询读取模式之间进行选择。

参数:

pxPeripheral   与外围设备相关联的描述符, 从该设备中读取字节。 描述符将 从用于开启外围设备的 FreeRTOS_open() 调用中返回。
pvBuffer   存放读取数据的缓冲区。
xBytes   请求的总字节数。

当使用中断驱动传输模式时, 如果请求的总数在外围设备读取超时值逾时前无法获取, 则实际读取的字节总数 将小于 请求的总数 。 FreeRTOS_ioctl() 用于 设置读取超时值。

返回:

读取的字节总数。 如果请求的字节数在外围设备读取超时值逾时前无法读取,那么读取的字节总数 将小于由 xBytes 参数请求的 字节数 。 FreeRTOS_ioctl() 用于设置 读取超时值。

用法示例:

示例 1 代码片段演示了当外围设备 被配置为使用轮询传输模式时,应如何进行读取操作。 打开外围设备时 默认采用轮询模式。


/* By default the port is opened in polled mode. Read sizeof( ucBuffer ) bytes into
ucBuffer using polled mode. */

xBytesRead = FreeRTOS_read( xPort, ucBuffer, sizeof( ucBuffer ) );

/* The port is currently in polled mode, so FreeRTOS_read() will only have
returned once all the requested bytes had been read (barring any errors on
the peripheral). Note that, because polling mode is being used, the task
making the FreeRTOS_read() call will not have entered the Blocked
state if it had to wait for the requested number of bytes. */

configASSERT( xBytes == sizeof( ucBuffer ) );

Example 1: Reading bytes from a peripheral that is configured to use the polled transfer mode.


示例 2 代码片段演示了当外围设备 被配置为使用中断驱动字符队列或 传输模式, 或中断驱动的循环缓冲区传输模式时,应如何进行读取操作。 在这些模式下,执行 FreeRTOS_read() 调用的任务 维持在阻塞状态(不使用任何 CPU 时间),直到已读取请求字节数量, 或读取超时值已逾期。 FreeRTOS_ioctl() 使用 iocltSET_RX_TIMEOUT 请求代码来配置 读取超时值。

    
/* Read some bytes in one of the interrupt driven transfer modes. If the
character queue transfer mode is being used, this will remove bytes from the
queue that had previously been placed into the queue by the FreeRTOS-Plus-IO interrupt
service routine. If the circular buffer transfer mode is being used, this will
remove bytes from the circular buffer that had previously been placed into the
buffer by the FreeRTOS-Plus-IO interrupt service routine. In both cases, read bytes
are placed in ucBuffer. */

xBytesRead = FreeRTOS_read( xPort, ucBuffer, sizeof( ucBuffer ) );

if( xBytesRead < sizeof( ucBuffer ) )
{
/* The Rx timeout must have expired before sizeof( ucBuffer ) bytes could
be read. xBytesRead number of bytes will have been placed into ucBuffer. */

}
else
{
/* The requested number of bytes were read before the read timeout expired.
All the requested bytes have been placed in ucBuffer. */

}

Example 2: Reading bytes from a peripheral that is configured to used either the

interrupt driven character queue transfer mode, or the interrupt driven circular

buffer transfer mode.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.