xQueueCreateStatic
[队列管理]
queue. h
QueueHandle_t xQueueCreateStatic(
UBaseType_t uxQueueLength,
UBaseType_t uxItemSize,
uint8_t *pucQueueStorageBuffer,
StaticQueue_t *pxQueueBuffer );
创建一个新队列并返回
可以引用该队列的句柄。
configSUPPORT_STATIC_ALLOCATION
必须在 FreeRTOSConfig.h 中设置为 1,该 RTOS API 函数才可用。
每个队列都需要 RAM,
用于保存队列状态和队列中包含的数据项(队列存储区域)。
如果使用 xQueueCreate() 创建队列,
则会自动从 FreeRTOS 堆中分配 RAM。
如果使用 xQueueCreateStatic() 创建队列,
则 RAM 由应用程序编写者提供,这会产生更多的参数,
但这样能够在编译时静态分配 RAM
。 请参阅静态分配与
动态分配页面了解详情。
-
参数:
-
uxQueueLength
|
队列可同时容纳的最大项目数
。
|
uxItemSize
|
存储队列中的每个数据项所需的大小(以字节为单位)。
数据项按副本排队,而不是按引用排队,
因此该值为每个排队项目将被复制的字节数。队列中每个数据项
的大小必须相同。
|
pucQueueStorageBuffer
|
如果 uxItemSize 非零,则 pucQueueStorageBuffer 必须
指向一个至少足够大的 uint8_t 数组,
以容纳队列中可以同时存在的最大项数,
即 (uxQueueLength * uxItemSize) 个字节。
如果 uxItemSize 为零,则 pucQueueStorageBuffer 可以为 Null。
|
pxQueueBuffer
|
必须指向 StaticQueue_t 类型的变量,
该变量将用于保存队列的数据结构体。
|
-
返回:
-
如果队列创建成功,则返回所创建队列的句柄
则返回已创建队列的句柄。 如果 pxQueueBuffer 为 NULL,则返回 NULL。
用法示例:
/* The queue is to be created to hold a maximum of 10 uint64_t
variables. */
#define QUEUE_LENGTH 10
#define ITEM_SIZE sizeof( uint64_t )
/* The variable used to hold the queue's data structure. */
static StaticQueue_t xStaticQueue;
/* The array to use as the queue's storage area. This must be at least
uxQueueLength * uxItemSize bytes. */
uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ];
void vATask( void *pvParameters )
{
QueueHandle_t xQueue;
/* Create a queue capable of containing 10 uint64_t values. */
xQueue = xQueueCreateStatic( QUEUE_LENGTH,
ITEM_SIZE,
ucQueueStorageArea,
&xStaticQueue );
/* pxQueueBuffer was not NULL so xQueue should not be NULL. */
configASSERT( xQueue );
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.