crDELAY
[协程专用]
croutine.h
void crDELAY( CoRoutineHandle_t xHandle,
TickType_t xTicksToDelay )
crDELAY 是一个宏。 上面原型中的数据类型仅供参考。
将协程延迟一段固定时间。
crDELAY 只能从协程函数本身调用 - 不能
从协程函数调用的函数中调用。 这是因为
协程无法维持自己的堆栈。
- 参数:
-
xHandle | 要推迟协程的句柄。 这是协程函数的 xHandle 参数。 |
xTickToDelay | 协程应延迟的 tick 数 。 实际所需的时间由 configTICK_RATE_HZ(在 FreeRTOSConfig.h 中设置)定义。 常量 portTICK_PERIOD_MS 可以用于将 tick 转换为毫秒。 |
用法示例:
// Co-routine to be created.
void vACoRoutine( CoRoutineHandle_t xHandle,
UBaseType_t uxIndex )
{
// Variables in co-routines must be declared static if they must maintain
// value across a blocking call. This may not be necessary for const
// variables. We are to delay for 200ms.
static const xTickType xDelayTime = 200 / portTICK_PERIOD_MS;
// Must start every co-routine with a call to crSTART();
crSTART( xHandle );
for( ;; )
{
// Delay for 200ms.
crDELAY( xHandle, xDelayTime );
// Do something here.
}
// Must end every co-routine with a call to crEND();
crEND();
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|