下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

FreeRTOS 滴答代码
[RTOS 实现构建基块]

FreeRTOS AVR 移植使用的实际源代码与前文的示例略有不同。 vPortYieldFromTick() 本身是作为一个“裸”函数实现的, 且上下文在 vPortYieldFromTick() 中存储和恢复。之所以这么做是为了实现非抢占式上下文切换(在这种情况下,任务阻塞了自己) ——这里不做描述。

因此,RTOS 滴答的 FreeRTOS 实现如下所示(请参阅源代码段注释以了解更多详情)

void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void vPortYieldFromTick( void ) __attribute__ ( ( naked ) );

/*--------------------------------------------------*/

/* Interrupt service routine for the RTOS tick. */ void SIG_OUTPUT_COMPARE1A( void ) { /* Call the tick function. */ vPortYieldFromTick();

/* Return from the interrupt. If a context switch has occurred this will return to a different task. */ asm volatile ( "reti" ); } /*--------------------------------------------------*/

void vPortYieldFromTick( void ) { /* This is a naked function so the context is saved. */ portSAVE_CONTEXT();

/* Increment the tick count and check to see if the new tick value has caused a delay period to expire. This function call can cause a task to become ready to run. */ vTaskIncrementTick();

/* See if a context switch is required. Switch to the context of a task made ready to run by vTaskIncrementTick() if it has a priority higher than the interrupted task. */ vTaskSwitchContext();

/* Restore the context. If a context switch has occurred this will restore the context of the task being resumed. */ portRESTORE_CONTEXT();

/* Return from this naked function. */ asm volatile ( "ret" ); } /*--------------------------------------------------*/



下一节: RTOS 实现 - AVR 上下文

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