天天看點

FreeRTOS系統配置

在使用FreeRTOS時我們需要根據自己的需求來配置FreeRTOS,不同MCU在使用的時候配置也不同。FreeRTOS的系統配置檔案為FreeRTOSConfig.h,在此配置檔案中可以完成FreeRTOS的裁剪和配置。

“INCLUDE_”開始的宏

使用INCLUDE_開頭的宏來表示使能或除能FreeRTOS中相應的API函數,作用就是用來配置FreeRTOS中的可選API函數。

“config”開始的宏

config開始的宏和INCLUDE_開始的宏一樣,都是用來完成FreeRTOS的配置和裁剪的。

configASSERT——斷言

類似于C标準庫中的assert()函數,調試代碼的時候可以檢查傳入的參數是否合理,

如:

//斷言
#define vAssertCalled(char,int) printf("Error:%s,%d\r\n",char,int)
#define configASSERT(x) if((x)==0) vAssertCalled(__FILE__,__LINE__)
           

當參數x錯誤時就會通過序列槽列印出發生錯誤的檔案名和所在行。

/*
    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
    All rights reserved

    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.

    This file is part of the FreeRTOS distribution.

    FreeRTOS is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License (version 2) as published by the
    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.

    ***************************************************************************
    >>!   NOTE: The modification to the GPL is included to allow you to     !<<
    >>!   distribute a combined work that includes FreeRTOS without being   !<<
    >>!   obliged to provide the source code for proprietary components     !<<
    >>!   outside of the FreeRTOS kernel.                                   !<<
    ***************************************************************************

    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  Full license text is available on the following
    link: http://www.freertos.org/a00114.html

    ***************************************************************************
     *                                                                       *
     *    FreeRTOS provides completely free yet professionally developed,    *
     *    robust, strictly quality controlled, supported, and cross          *
     *    platform software that is more than just the market leader, it     *
     *    is the industry's de facto standard.                               *
     *                                                                       *
     *    Help yourself get started quickly while simultaneously helping     *
     *    to support the FreeRTOS project by purchasing a FreeRTOS           *
     *    tutorial book, reference manual, or both:                          *
     *    http://www.FreeRTOS.org/Documentation                              *
     *                                                                       *
    ***************************************************************************

    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
    the FAQ page "My application does not run, what could be wrong?".  Have you
    defined configASSERT()?

    http://www.FreeRTOS.org/support - In return for receiving this top quality
    embedded software for free we request you assist our global community by
    participating in the support forum.

    http://www.FreeRTOS.org/training - Investing in training allows your team to
    be as productive as possible as early as possible.  Now you can receive
    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
    Ltd, and the world's leading authority on the world's leading RTOS.

    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
    including FreeRTOS+Trace - an indispensable productivity tool, a DOS
    compatible FAT file system, and our tiny thread aware UDP/IP stack.

    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.

    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
    licenses offer ticketed support, indemnification and commercial middleware.

    http://www.SafeRTOS.com - High Integrity Systems also provide a safety
    engineered and independently SIL3 certified version for use in safety and
    mission critical applications that require provable dependability.

    1 tab == 4 spaces!
*/


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "sys.h"
#include "usart.h"
//針對不同的編譯器調用不同的stdint.h檔案
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
    #include <stdint.h>
    extern uint32_t SystemCoreClock;
#endif

//斷言
#define vAssertCalled(char,int) printf("Error:%s,%d\r\n",char,int)
#define configASSERT(x) if((x)==0) vAssertCalled(__FILE__,__LINE__)

/***************************************************************************************************************/
/*                                        FreeRTOS基礎配置配置選項                                              */
/***************************************************************************************************************/
#define configUSE_PREEMPTION					1                       //1使用搶占式核心,0使用協程
#define configUSE_TIME_SLICING					1						//1使能時間片排程(預設式使能的)
#define configUSE_PORT_OPTIMISED_TASK_SELECTION	1                       //1啟用特殊方法來選擇下一個要運作的任務
                                                                        //一般是硬體計算前導零指令,如果所使用的
                                                                        //MCU沒有這些硬體指令的話此宏應該設定為0!
#define configUSE_TICKLESS_IDLE					0                       //1啟用低功耗tickless模式
#define configUSE_QUEUE_SETS					1                       //為1時啟用隊列
#define configCPU_CLOCK_HZ						(SystemCoreClock)       //CPU頻率
#define configTICK_RATE_HZ						(1000)                  //時鐘節拍頻率,這裡設定為1000,周期就是1ms
#define configMAX_PRIORITIES					(32)                    //可使用的最大優先級
#define configMINIMAL_STACK_SIZE				((unsigned short)130)   //空閑任務使用的堆棧大小
#define configMAX_TASK_NAME_LEN					(16)                    //任務名字字元串長度

#define configUSE_16_BIT_TICKS					0                       //系統節拍計數器變量資料類型,
                                                                        //1表示為16位無符号整形,0表示為32位無符号整形
#define configIDLE_SHOULD_YIELD					1                       //為1時空閑任務放棄CPU使用權給其他同優先級的使用者任務
#define configUSE_TASK_NOTIFICATIONS            1                       //為1時開啟任務通知功能,預設開啟
#define configUSE_MUTEXES						1                       //為1時使用互斥信号量
#define configQUEUE_REGISTRY_SIZE				8                       //不為0時表示啟用隊列記錄,具體的值是可以
                                                                        //記錄的隊列和信号量最大數目。
#define configCHECK_FOR_STACK_OVERFLOW			0                       //大于0時啟用堆棧溢出檢測功能,如果使用此功能
                                                                        //使用者必須提供一個棧溢出鈎子函數,如果使用的話
                                                                        //此值可以為1或者2,因為有兩種棧溢出檢測方法。
#define configUSE_RECURSIVE_MUTEXES				1                       //為1時使用遞歸互斥信号量
#define configUSE_MALLOC_FAILED_HOOK			0                       //1使用記憶體申請失敗鈎子函數
#define configUSE_APPLICATION_TASK_TAG			0                       
#define configUSE_COUNTING_SEMAPHORES			1                       //為1時使用計數信号量

/***************************************************************************************************************/
/*                                FreeRTOS與記憶體申請有關配置選項                                                */
/***************************************************************************************************************/
#define configSUPPORT_DYNAMIC_ALLOCATION        1                       //支援動态記憶體申請
#define configTOTAL_HEAP_SIZE					((size_t)(20*1024))     //系統所有總的堆大小

/***************************************************************************************************************/
/*                                FreeRTOS與鈎子函數有關的配置選項                                              */
/***************************************************************************************************************/
#define configUSE_IDLE_HOOK						0                       //1,使用空閑鈎子;0,不使用
#define configUSE_TICK_HOOK						0                       //1,使用時間片鈎子;0,不使用

/***************************************************************************************************************/
/*                                FreeRTOS與運作時間和任務狀态收集有關的配置選項                                 */
/***************************************************************************************************************/
#define configGENERATE_RUN_TIME_STATS	        0                       //為1時啟用運作時間統計功能
#define configUSE_TRACE_FACILITY				1                       //為1啟用可視化跟蹤調試
#define configUSE_STATS_FORMATTING_FUNCTIONS	1                       //與宏configUSE_TRACE_FACILITY同時為1時會編譯下面3個函數
                                                                        //prvWriteNameToBuffer(),vTaskList(),
                                                                        //vTaskGetRunTimeStats()
                                                                        
/***************************************************************************************************************/
/*                                FreeRTOS與協程有關的配置選項                                                  */
/***************************************************************************************************************/
#define configUSE_CO_ROUTINES 			        0                       //為1時啟用協程,啟用協程以後必須添加檔案croutine.c
#define configMAX_CO_ROUTINE_PRIORITIES         ( 2 )                   //協程的有效優先級數目

/***************************************************************************************************************/
/*                                FreeRTOS與軟體定時器有關的配置選項                                            */
/***************************************************************************************************************/
#define configUSE_TIMERS				        1                               //為1時啟用軟體定時器
#define configTIMER_TASK_PRIORITY		        (configMAX_PRIORITIES-1)        //軟體定時器優先級
#define configTIMER_QUEUE_LENGTH		        5                               //軟體定時器隊列長度
#define configTIMER_TASK_STACK_DEPTH	        (configMINIMAL_STACK_SIZE*2)    //軟體定時器任務堆棧大小

/***************************************************************************************************************/
/*                                FreeRTOS可選函數配置選項                                                      */
/***************************************************************************************************************/
#define INCLUDE_xTaskGetSchedulerState          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
#define INCLUDE_eTaskGetState			        1
#define INCLUDE_xTimerPendFunctionCall	        1

/***************************************************************************************************************/
/*                                FreeRTOS與中斷有關的配置選項                                                  */
/***************************************************************************************************************/
#ifdef __NVIC_PRIO_BITS
	#define configPRIO_BITS       		__NVIC_PRIO_BITS
#else
	#define configPRIO_BITS       		4                  
#endif

#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY			15                      //中斷最低優先級
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY	5                       //系統可管理的最高中斷優先級
#define configKERNEL_INTERRUPT_PRIORITY 		( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 	( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

/***************************************************************************************************************/
/*                                FreeRTOS與中斷服務函數有關的配置選項                                          */
/***************************************************************************************************************/
#define xPortPendSVHandler 	PendSV_Handler
#define vPortSVCHandler 	SVC_Handler

#endif /* FREERTOS_CONFIG_H */