FreeRTOS从入门到摔倒-FreeRTOSConfig.h解析

FreeRTOS 移植和配置

1.配置

FreeRTOSConfig.h文件是对整个FreeRTOS所需功能的宏做了定义,先来了解该宏的所有定义:

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/* Ensure stdint is only used by the compiler, and not the assembler. */
#ifdef __ICCARM__|| defined(__CC_ARM) || defined(__GNUC__)
	#include 
	extern uint32_t SystemCoreClock;
#endif

#define configUSE_PREEMPTION			1				//置1抢占式调度,置0时间片调度
#define configUSE_IDLE_HOOK				1				//空闲钩子函数,先置0
#define configUSE_TICK_HOOK				1				//时间片钩子函数,先置0
#define configCPU_CLOCK_HZ				( SystemCoreClock )		//CPU内核时钟频率
#define configTICK_RATE_HZ				( ( TickType_t ) 1000 )	//系统节拍中断频率,中断进行任务调度
#define configMAX_PRIORITIES			( 5 )					//可使用最大优先级
#define configMINIMAL_STACK_SIZE		( ( unsigned short ) 128 )		//任务最小堆栈大小,单位字(4字节)
#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 75 * 1024 ) )	//所有内存大小
#define configMAX_TASK_NAME_LEN			( 10 )			//任务名最大长度
#define configUSE_TRACE_FACILITY		1				//置1启用可视化跟踪调试,增加一些API
#define configUSE_16_BIT_TICKS			0				//系统节拍器变量数据类型,置1表示16位无符号整形,置0表示32位无符号整形
#define configIDLE_SHOULD_YIELD			1				//置0,空闲任务不会为同等优先级任务让出CPU使用权,置1,会让出
#define configUSE_MUTEXES				1				//置1使用互斥信号量
#define configQUEUE_REGISTRY_SIZE		8				//可注册的队列和信号量的最大数量
#define configCHECK_FOR_STACK_OVERFLOW	2				//堆栈溢出检测,置1,使用堆栈溢出检测方法1,使用堆栈溢出检测方法2

#define configUSE_RECURSIVE_MUTEXES		1				//置1使用递归互斥信号量
#define configUSE_MALLOC_FAILED_HOOK	1               //置1使用内存分配失败钩子函数,用户需要实现内存分配失败钩子函数

#define configUSE_APPLICATION_TASK_TAG	0				//置1,configUSE_APPLICATION_TASK_TAGF()和xTaskCallApplicationTaskHook()会被编译

#define configUSE_COUNTING_SEMAPHORES	1				//置1使用计数型信号量
#define configGENERATE_RUN_TIME_STATS	0				//置1开启时间统计功能

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 		    0				//置1启用协程
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )			//协程最大优先级

/* Software timer definitions. */
#define configUSE_TIMERS				1				//置1使用软件定时器
#define configTIMER_TASK_PRIORITY		( 2 )			//软件定时器任务优先级
#define configTIMER_QUEUE_LENGTH		10				//软件定时器命令队列长度

//定时器任务堆栈大小
#define configTIMER_TASK_STACK_DEPTH	( configMINIMAL_STACK_SIZE * 2 )

//使能相关API用的,一般不用改,全部置1就行
#define INCLUDE_vTaskPrioritySet		1				
#define INCLUDE_uxTaskPriorityGet		1				
#define INCLUDE_vTaskDelete				1				
#define INCLUDE_vTaskCleanUpResources	1
#define INCLUDE_vTaskSuspend			1
#define INCLUDE_vTaskDelayUntil			1
#define INCLUDE_vTaskDelay				1

/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
	/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
	#define configPRIO_BITS       		__NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4        /* 15 priority levels */
#endif

/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			0xf

/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5

/* Interrupt priorities used by the kernel port layer itself.  These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
	
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }	
	
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */

2. 移植

移植主要移植一下三种文件:

  • 核心源文件,即.c文件,有六个:list.c、queue.c、tasks.c、timer.c、croutine.c和event_groups.c,这些文件放在放在FreeRTOS源码的Source文件夹里面;
  • 对应头文件,就是FreeRTOS源码Source文件夹中的include文件夹里面,全部拷出来就行;
  • 内存管理和接口文件,这个在“FreeRTOSv9.0.0\FreeRTOS\Source\portable”目录下找到“MemMang”文件夹与“RVDS”文件夹中;

这三种功能文件夹整理完毕,拷贝出来放在裸机文件夹里面,再在main函数中#include FreeRTOS.h和所需要的头文件,并按照FreeRTOS专用的模板进行编程,就初步OK了,其他注意的点可自行百度。

你可能感兴趣的:(知识点总结)