Freertos 的移植中 “FreeRTOSConfig.h“ 的配置

    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 "time.h"
#include <stdio.h>
/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
 *
 * See http://www.freertos.org/a00110.html.
 *----------------------------------------------------------*/

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

#define configUSE_PREEMPTION			            1                               //1使用抢占式内核,0使用协程
/******************************************FreeRTOS与钩子函数有关的配置选项****************************************************/
#define configUSE_IDLE_HOOK				                0                    //定义为0                    //1空闲任务钩子函数
#define configUSE_TICK_HOOK				                0                    //定义为0                   //1使用时间片钩子
/***************************************************************************************************************************/
#define configCPU_CLOCK_HZ				       ( SystemCoreClock )            //CPU频率
#define configTICK_RATE_HZ				     ( ( TickType_t ) 1000 )          //时钟节拍频率(1ms)
#define configMAX_PRIORITIES			             ( 32 )                   //可使用的最大的优先级(使用stm32引荐的话最多32,软件的话不受限制
                                                                             //(configUSE_PORT_OPTIMISED_TASK_SELECTION 有关))
#define configMINIMAL_STACK_SIZE		    ( ( unsigned short ) 130 )       //空闲任务使用的堆栈大小
//#define configTOTAL_HEAP_SIZE			   ( ( size_t ) ( 75 * 1024 ) )      //系统所有总堆的大小
#define configMAX_TASK_NAME_LEN			             ( 32 )                  //任务名字字符串长度
//#define configUSE_TRACE_FACILITY		                1
#define configUSE_16_BIT_TICKS			                0                   //系统节拍计时器变量数据类型
#define configIDLE_SHOULD_YIELD			                1                   //1表示为16位无符号整形,0表示为32位无符号整型
#define configUSE_MUTEXES				                1                   //为1时使用互斥信号量
#define configQUEUE_REGISTRY_SIZE		                8                   //不为0时表示启用队列记录,具体的值是可以记录的队列和信号量最大数目
#define configCHECK_FOR_STACK_OVERFLOW	                0  //定义为0        //大于0时启用堆栈溢出钩子函数,
#define configUSE_RECURSIVE_MUTEXES		                1                   //为1时使用递归互斥信号量
#define configUSE_MALLOC_FAILED_HOOK	                0   //定义为0       //1使用内存申请失败钩子函数
#define configUSE_APPLICATION_TASK_TAG	                0
#define configUSE_COUNTING_SEMAPHORES	                1                   //为1使用计数信号量

//#define configGENERATE_RUN_TIME_STATS	                0

/************************************************************************************************************/
#define configUSE_TIME_SLICING                          1                   //使能时间片调度(默认式使能)
#define configUSE_PORT_OPTIMISED_TASK_SELECTION         0                   //一般是硬件计算前导零指令,如果所使用的
                                                    //MCU没有这些硬件指令的话此宏应置0!
#define configUSE_TICKLESS_IDLE                         0                   //1启动低功耗tickless
#define configUSE_QUEUE_SETS                            1                   //1启用队列集
#define configUSE_TASK_NOTIFICATIONS                    1                   //为1时开启任务通知功能,默认开启


/******************************FreeRTOS与内存申请有关的配置选项*******************************************/
#define configSUPPORT_DYNAMIC_ALLOCATION                1                   //支持动态内存申请            
#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 75 * 1024 ) )        //系统所有总堆的大小

/******************************************************************************************************/
/******************************FreeRTOS与运行时间的任务状态收集有关的配置选项*****************************/
//#define configGENERATE_RUN_TIME_STATS                   1                   

#define configUSE_TRACE_FACILITY                        1                    //为1时启用可视化的追踪条调试
#define configUSE_STATS_FORMATTING_FUNCTIONS            1
 
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()        ConfigureTimeForRunTimeStats()//需自己要实现(用于初始化TIM定时器)
//#define portALT_GET_RUN_TIME_COUNTER_VALUE(Time)        
#define portGET_RUN_TIME_COUNTER_VALUE()                  FreeRTOSRunTimerTicks       //这值在定时器中断服务自己++;
#define configGENERATE_RUN_TIME_STATS	                1                   //为1时启用运行时间统计  


/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 		                    0
#define configMAX_CO_ROUTINE_PRIORITIES               ( 2 )

/* Software timer definitions. */                                           //(FreeRTOS与软件定时器有关的配置选项)
#define configUSE_TIMERS				                1                   //为1是启用软件定时器
#define configTIMER_TASK_PRIORITY		              ( 2 )                 //软件定时器的优先级
#define configTIMER_QUEUE_LENGTH		                10
#define configTIMER_TASK_STACK_DEPTH	( configMINIMAL_STACK_SIZE * 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#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_xTimerPendFunctionCall                  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( ;; ); }	

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

	
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler             //这三个函数是FreeRTOS与MCU库函数的对接口;这三个函数不定义操作系统不能工作(Date:2021620)
#define xPortPendSVHandler PendSV_Handler 
#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */
FreeRTOS的库与MCU对接的函数就是文中最后三个宏函数,上面的设置就是为了开启FreeRTOS所需的功能。
断言部分可以根据自己的平台来写

如果想要使用统计运行任务状态函数 [vTaskList(),  vTaskGetRunTimeStats() ], 需要开启一个定时器来自增FreeRTOSRunTimerTicks的值,同时开启宏(上述代码中有说明)
/******************************FreeRTOS与运行时间的任务状态收集有关的配置选项*****************************/
volatile unsigned long long FreeRTOSRunTimerTicks;

void TMR6_GLOBAL_IRQHandler(void)
{
  if (TMR_GetINTStatus(TMR6, TMR_INT_Overflow) == SET)
  {
    FreeRTOSRunTimerTicks++;
    TMR_ClearITPendingBit(TMR6, TMR_INT_Overflow);
  }
}

void ConfigureTimeForRunTimeStats(void)
{
  FreeRTOSRunTimerTicks = 0;
  MX_TIM6_Init();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
移植 FreeRTOSSTM32F103C8T6 上时,需要进行 FreeRTOSConfig.h 文件的配置。以下是一些常见的配置选项: 1. 配置时钟频率:根据你的实际情况,设置 configCPU_CLOCK_HZ 宏定义为 STM32F103C8T6 的时钟频率。 2. 配置优先级:根据你的应用需求,设置 configMAX_PRIORITIES 宏定义为需要支持的最大任务优先级。 3. 配置堆栈大小:根据你的应用需求,设置 configMINIMAL_STACK_SIZE 宏定义为你期望的最小任务堆栈大小。 4. 配置空闲任务堆栈大小:设置 configIDLE_STACK_SIZE 宏定义为空闲任务的堆栈大小。 5. 配置时钟节拍:设置 configTICK_RATE_HZ 宏定义为你希望的 FreeRTOS 时钟节拍频率。 6. 配置内存管理器:根据你的应用需求,选择使用 heap_1.c、heap_2.c、heap_3.c 或 heap_4.c 的一个作为内存管理器。 7. 配置断嵌套:如果你的应用需要使用断嵌套,设置 configKERNEL_INTERRUPT_PRIORITY 宏定义为内核断优先级的值,同时设置 configMAX_SYSCALL_INTERRUPT_PRIORITY 宏定义为用于系统调用的最高优先级。 8. 配置其他选项:根据你的应用需求,可以配置其他的 FreeRTOS 选项,如任务调度器的算法、任务队列长度等。 以上是一些常见的 FreeRTOSConfig.h 配置选项,你可以根据你的应用需求进行相应的修改和调整。同时,还需要根据你的硬件平台进行其他的移植工作,如配置断和时钟等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值