下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

xCoRoutineCreate
[协程专用]

croutine.h
BaseType_t xCoRoutineCreate ( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex );

新建协程,将其添加到已做好运行准备的协程的列表中 。

参数:
pxCoRoutineCode 指向协程函数的指针。 协程函数需要使用特殊语法。详情请参阅网络文档中的协程部分。
uxPriority 协程运行时相对于其他协程的优先级。
uxIndex 用于区分执行相同函数的不同协程。 详情请参阅下文示例和网络文档中的协程部分。
返回:
如成功创建协程并将其添加到准备运行的协程列表中,则返回 pdPASS,否则返回使用 ProjDefs.h 定义的错误代码。

用法示例:

 // Co-routine to be created.
 void vFlashCoRoutine( 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.
 static const char cLedToFlash[ 2 ] = { 5, 6 };
 static const TickType_t uxFlashRates[ 2 ] = { 200, 400 };

     // Must start every co-routine with a call to crSTART();
     crSTART( xHandle );

     for( ;; )
     {
         // This co-routine just delays for a fixed period, then toggles
         // an LED.  Two co-routines are created using this function, so
         // the uxIndex parameter is used to tell the co-routine which
         // LED to flash and how long to delay.  This assumes xQueue has
         // already been created.
         vParTestToggleLED( cLedToFlash[ uxIndex ] );
         crDELAY( xHandle, uxFlashRates[ uxIndex ] );
     }

     // Must end every co-routine with a call to crEND();
     crEND();
 }

 // Function that creates two co-routines.
 void vOtherFunction( void )
 {
 unsigned char ucParameterToPass;
 TaskHandle_t xHandle;
		
     // Create two co-routines at priority 0.  The first is given index 0
     // so (from the code above) toggles LED 5 every 200 ticks.  The second
     // is given index 1 so toggles LED 6 every 400 ticks.
     for( uxIndex = 0; uxIndex < 2; uxIndex++ )
     {
         xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
     }  
 }
 


CoRoutineHandle_t

引用协程的类型。 协程句柄会自动传递给所有协程函数。






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