英飞凌TC397移植FreeRTOS

一、准备工作

1.FreeRTOS源码

在这里插入图片描述

2.STM驱动代码

在这里插入图片描述

3.中断相关配置文件

中断配置文件

4.AURIX Developement Studio初始工程(包含SDK)

在这里插入图片描述

二、配置portmacro.h

1.主要接口配置

#define portYIELD()								__syscall( 0 )
/* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY. */
#define portDISABLE_INTERRUPTS()	{																									\
										uint32_t ulICR;																					\
										__disable();																						\
										ulICR = __mfcr(CPU_ICR); 		/* Get current ICR value. */									\
										ulICR &= ~portCCPN_MASK;	/* Clear down mask bits. */											\
										ulICR |= configMAX_SYSCALL_INTERRUPT_PRIORITY; /* Set mask bits to required priority mask. */	\
										__dsync(); \
										__mtcr(CPU_ICR, ulICR );		/* Write back updated ICR. */										\
										__isync();																						\
										__enable();																						\
									}

/* Clear ICR.CCPN to allow all interrupt priorities. */
#define portENABLE_INTERRUPTS()		{																	\
										uint32_t ulICR;													\
										__disable();														\
										ulICR = __mfcr(CPU_ICR);		/* Get current ICR value. */	\
										ulICR &= ~portCCPN_MASK;	/* Clear down mask bits. */			\
										__dsync(); \
										__mtcr(CPU_ICR, ulICR );		/* Write back updated ICR. */		\
										__isync();														\
										__enable();														\
									}

/* Set ICR.CCPN to uxSavedMaskValue. */
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedMaskValue ) 	\
									{																				\
										uint32_t ulICR;																\
										__disable();																	\
										ulICR = __mfcr(CPU_ICR);		/* Get current ICR value. */						\
										ulICR &= ~portCCPN_MASK;	/* Clear down mask bits. */								\
										ulICR |= uxSavedMaskValue;	/* Set mask bits to previously saved mask value. */		\
										__dsync(); \
										__mtcr(CPU_ICR, ulICR );		/* Write back updated ICR. */							\
										__isync();																			\
										__enable();																			\
									}
#define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) 						\
								if( xHigherPriorityTaskWoken != pdFALSE ) {	\
									uint32 cpu_index = __mfcr(CPU_CORE_ID);	\
									cpu_index = ((cpu_index < 5) ? cpu_index : 5);	\
									GPSR_list[cpu_index].B.SETR = 1; 				\
									__isync(); }

2.配置选项

#define configUSE_PREEMPTION				1
#define configUSE_IDLE_HOOK					1
/* CPU is actually 300MHz but FPIDIV is 2 meaning divide by 3 for the
peripheral clock. */
#define configCPU_CLOCK_HZ					( IFX_CFG_SCU_PLL_FREQUENCY )
#define configPERIPHERAL_CLOCK_HZ			( ( unsigned long ) configCPU_CLOCK_HZ / 3UL )
#define configTICK_RATE_HZ					( ( TickType_t ) 1000UL )
#define configMAX_PRIORITIES				( 8 )/* Task priority. */
#define configMINIMAL_STACK_SIZE			( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE				( ( size_t ) ( 64U * 1024U ) )
#define configMAX_TASK_NAME_LEN				( 16 )
#define configUSE_TRACE_FACILITY			0
#define configUSE_16_BIT_TICKS				0
#define configIDLE_SHOULD_YIELD				1
#define configUSE_MALLOC_FAILED_HOOK 		1
#define configCHECK_FOR_STACK_OVERFLOW		0
#define configUSE_TICK_HOOK					1
#define configUSE_COUNTING_SEMAPHORES 		1
#define configUSE_RECURSIVE_MUTEXES			0
#define configUSE_MUTEXES					1

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

/* Software timer configuration. */
#define configUSE_TIMERS					1
#define configTIMER_TASK_PRIORITY			( 4 )
#define configTIMER_QUEUE_LENGTH			( 5 )
#define configTIMER_TASK_STACK_DEPTH		configMINIMAL_STACK_SIZE

/* 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 configMAX_SYSCALL_INTERRUPT_PRIORITY	RTOS_SYSCALL_INT_PRIORITY_MAX /* Interrupt above priority 64 are not effected by critical sections, but cannot call interrupt safe FreeRTOS functions. */
#define configKERNEL_INTERRUPT_PRIORITY			RTOS_SYSTICK_INT_PRIORITY  /* This is defined here for clarity, but the value must not be changed from 2. */
#define configKERNEL_YIELD_PRIORITY				ROTS_TSW_INT_PRIORITY  /* This is defined here for clarity, but must not be changed from its default value of 1. */

/* Default definition of configASSERT(). */
#define configASSERT( x ) if( ( x ) == 0 ) 		{ portDISABLE_INTERRUPTS(); for( ;; ); }

3.遇到的问题

  • 注意__attribute__用法,前后两个下划线。
  • IfxCpu_Irq_installInterruptHandler编译不通过问题,可暂时注释掉,因为此函数涉及到回调函数的注册,若后续发现中断问题,请首先调查此处。
  • 程序中涉及到的寄存器操作指令,写法统一加上两个下划线且小写,例如:__mfcr;__isync;

三、结语

本次移植过程由于参考了第三方TASKING工程示例代码(目的是将TASKING项目转移到AURIX Development Studio项目),篇幅有限,故port接口中的详细内容没办法展示,移植FreeRTOS的主要思想就是port接口的几个关键API的实现,中断的配置等等,并不局限于哪款单片机,此次移植过程作为工作中的查错记录使用,关于TC3978问题可以和本人沟通,后续有相关内容会继续补充,加油,汽电人。

  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值