下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

轮询传输模式

[FreeRTOS-Plus-IO 传输模式]

数据方向

轮询模式可以与 FreeRTOS_read() 和 FreeRTOS_write() 同时使用。


说明

在轮询模式下,数据传输是通过对外设状态位的忙碌等待来 执行的。 未使用中断。

轮询传输模式
优点 缺点
  • 非常简单的使用模型
  • 在大多数情况下,FreeRTOS_read() 或 FreeRTOS_write() 操作只有在分别读取或写入所有数据后才会返回 。
  • FreeRTOS-Plus-IO 驱动程序不需要任何 RAM 进行 数据缓冲。
  • 执行读取或写入操作的任务在读取或写入期间会保持在 “就绪”或“正在运行”状态, 即便没有待执行操作 (原因是外设状态位自上次轮询以来未发生更改) 时也是如此。 结果是, 轮询任务浪费了 CPU 时间, 耽搁了另一个本可以立即执行处理操作的任务。
  • 无内置的互斥方法。 如果 多个任务需要访问同一个外围设备, 则应用程序编写者必须保证采用互斥(例如, 使用互斥锁)。
  • 目前(还)不可能更改读取 或写超时。

开启外围设备后默认启用轮询模式。 并非所有外围设备都会提供一种方法, 以便在退出轮询模式后返回轮询模式。

轮询写入仅在所有字节均已写入外围设备后返回, 发生错误时除外。

轮询读取仅在从外围设备读取请求的字节数后返回, 发生错误时除外。


示例用法


/* FreeRTO+IO includes. */
#include "FreeRTOS_IO.h"

void vAFunction( void )
{
/* The Peripheral_Descriptor_t type is the FreeRTOS-Plus-IO equivalent of a descriptor. */
Peripheral_Descriptor_t xOpenedPort;
BaseType_t xBytesTransferred;

/* Open the SPI port identified in the board support package as using the
path string "/SPI2/". The second parameter is not currently used and can
be set to anything, although, for future compatibility, it is recommneded
that it is set to NULL. */

xOpenedPort = FreeRTOS_open( "/SPI2/", NULL );

if( xOpenedPort != NULL )
{
/* xOpenedPort now contains a valid descriptor that can be used with
other FreeRTOS-Plus-IO API functions.

Peripherals default to using Polled mode for both reads and writes, so
the following FreeRTOS_write() call will write 10 bytes from the
ucBuffer array to the SPI2 peripheral. The ucBuffer declaration is not
shown, and assumed to be outside of this example function. */

xBytesTransferred = FreeRTOS_write( xOpenedPort, ucBuffer, 10 );

/* As polled mode is being used, xBytesTransferred should be 10, unless
an error occurred. */

configASSERT( xBytesTransferred == 10 );

/* The transfer mode has not been changed, so the following read will
also use polled mode. It will read 10 bytes into ucBuffer. */

xBytesTransferred = FreeRTOS_read( xOpenedPort, ucBuffer, 10 );

/* Again, as polled mode is used, the call to FreeRTOS_read() will have
returned all of the 10 requested bytes unless an error occurred. */

configASSERT( xBytesTransferred == 10 );
}
else
{
/* The port was not opened successfully. */
}
}

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