【FreeRTOS】FreeRTOS结构

概念:

FreeRTOS,先了解几个概念,任务,临界区,阻塞,优先级,时间片。

临界区:可以这样理解,在多任务系统中,有几个任务独立运行,但是有这几个任务需要访问全局变量,当然不可能同时访问。所以需要对其保护(如何保护暂且不说,最简单的保护就是通过信号量)。这几个全局变量所在区域就是临界区(内存区域)。

任务,阻塞,优先级,时间片,参考:

文件:

配置文件FreeRTOSConfig.h,前人栽树,后人乘凉。

野火的配置文件注释,该文件有省略。

/****************************************************************
            FreeRTOS与中断服务函数有关的配置选项                         
****************************************************************/
#define xPortPendSVHandler 	PendSV_Handler
#define vPortSVCHandler 	SVC_Handler


/* 以下为使用Percepio Tracealyzer需要的东西,不需要时将 configUSE_TRACE_FACILITY 定义为 0 */
#if ( configUSE_TRACE_FACILITY == 1 )
//#include "trcRecorder.h"
//#define INCLUDE_xTaskGetCurrentTaskHandle               1   // 启用一个可选函数(该函数被 Trace源码使用,默认该值为0 表示不用)
#endif


#endif /* FREERTOS_CONFIG_H */
/**************************************************************** FreeRTOS与中断服务函数有关的配置选项 ****************************************************************/ #define xPortPendSVHandler PendSV_Handler #define vPortSVCHandler SVC_Handler /* 以下为使用Percepio Tracealyzer需要的东西,不需要时将 configUSE_TRACE_FACILITY 定义为 0 */ #if ( configUSE_TRACE_FACILITY == 1 ) //#include "trcRecorder.h" //#define INCLUDE_xTaskGetCurrentTaskHandle 1 // 启用一个可选函数(该函数被 Trace源码使用,默认该值为0 表示不用) #endif #endif /* FREERTOS_CONFIG_H */

也可以去看安富莱,正点原子的。最后再去看看源码配置文件,很重要!很重要!

TCB ,ECB:

TCB:/* * Task control block. A task control block (TCB) is allocated for each task, * and stores task state information, including a pointer to the tasks context * (the tasks run time environment, including register values) */

ListItem_t			xStateListItem;	
/*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked,
	Suspended ). */
ListItem_t			xEventListItem;	
	/*< Used to reference a task from an event list. */

一个是任务的状态,几种状态关系参考。

一个将任务假如事件列表中(在任务管理中任务控制块(TCB)承载了任务的相关信息。在事件管理中,这个载体就变成了事件控制块(ECB));简单点就是说TCB最终由ECB控制管理。

任务事件组。

typedef struct xEventGroupDefinition
{
	EventBits_t uxEventBits;
	List_t xTasksWaitingForBits;		/*< List of tasks waiting for a bit to be set. */

	#if( configUSE_TRACE_FACILITY == 1 )
		UBaseType_t uxEventGroupNumber;
	#endif

	#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
		uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
	#endif
} EventGroup_t;

prvTestWaitCondition 函数,就是确定任务是动态内存创建还是静态内存创建。动态内存系统自动分配,静态内存用户自己分配。

static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits,
 const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
经验分享 程序员 微信小程序 职场和发展