本篇文章介绍了使用HighTec工具集成英飞凌提供的开源底层驱动库来实现LED闪烁的完整过程。
文章首先从iLLD底层驱动库讲起,帮助读者对iLLD有一个概念上的认识。然后再一步步介绍使用HighTec工具集成iLLD来搭建一个最小基础工程的完整过程。最后在这个基础工程之上,再集成英飞凌提供的LED灯闪烁Demo来实现LED灯闪烁的功能,并以此进一步介绍了iLLD中PORTS模块的使用。
众所周知,在AUTOSAR架构中BSW是使用MCAL来完成对芯片外设的驱动的,MCAL尽可能的实现在不同芯片之间能够提供一套统一的”配置“来让用户完成底层驱动的使用。但是笔者在工作中使用MCAL配置过英飞凌以及瑞萨两种芯片,不同芯片的配置经历并没有使我在芯片切换的过程中快速上手,反而经常陷入”经验主义“的陷阱,在一些非常小的问题上耗费大量的时间。长期的使用MCAL使得笔者对驱动的实现只停留在知其然,并不知其所以然的状态,并且MCAL本身为了”统一“限制了很多芯片能够提供功能,用户不能通过MCAL使用这些功能。笔者认为,使用iLLD来替换掉MCAL,不仅能降低后续的运营成本,还能从根本上解决掉很多驱动相关的问题。
目录
iLLD介绍
iLLD(Infineon Low Level Driver)是英飞凌提供的为其微控制器的集成外设提供访问和配置功能的开源底层驱动库,可以帮助用户快速完成从一个简单的定时器实现到三相PWM驱动器的应用。其在一个产品固件工程中的位置如下图:

其易于集成到多种集成开发环境中,并包含多种片内外设驱动Demo, 让片内外设的配置/初始化/使用更简单。下图为其包含的Demo内容:

可以看到,常见的多路CAN,网口,FLASH以及I2C等片内外设都有对应的Demo,用户可以很方便的参考Demo完成片内外设的驱动,进而可以更加集中在用户业务代码的实现。
iLLD提供了完整的底层驱动,包括对应的函数,结构体,以及寄存器地址定义。其可以分为以下三个层次:
- Special Function Register Level:通过名字访问片内寄存器相应位域。
- Driver Level :将寄存器的操作封装为最小功能函数,更易执行。
- Function Level:用户业务层可以直接调用的初始化, 配置, 启动, 停止任何AURIX外设的函数。
这个底层驱动库可以任意无缝集成到任何开发环境中:

下面是使用iLLD来驱动I2C的一个实例:

可以看到,调用iLLD体用的结构体和函数完成对应外设的配置和初始化之后,就可以进一步的使用了。
iLLD中的对应模块的函数、结构体、使用等等说明内容都可以在对应的帮助文件找到。比如我们在安装了iLLD-TC3-v1.20.0.exe之后,就可以在对应的文件找到iLLD_UM_TC3xx.chm帮助,各位可以结合对应模块Demo和帮助文件来快速上手iLLD的使用。

使用HighTec集成iLLD搭建最小的基础工程
首先,我们需要从英飞凌下载我们使用芯片对应的iLLD库,我们这里使用的是3系列芯片,点击这里跳转下载:

下载并解压完成之后,分别完成iLLD-TC3-v1.20.0.exe以及BaseProjects_TC3xx_V1_20_0.exe的安装。

安装完成之后,我们可以在~\Infineon\Aurix2G_Workspace_V1_20_0目录下找到我们芯片对应的BaseFramework,这里我后边要用的是BaseFramework_TC39B和Libraries。

可以看到,下边有很多指导文档,来提供用户参考。英飞凌指导文档中是使用eclipse作为集成开发环境,我这边是使用HighTec,所以下面先使用HighTec来建立一个TC3系列的空工程,如下图所示:

建立好了之后,将之前准备好的"~\Infineon\Aurix2G_Workspace_V1_20_0\BaseFramework_TC39B"目录下的“0_Src”和“1_ToolEnv”文件夹,以及"~\Infineon\Aurix2G_Workspace_V1_20_0\”目录下的“Librariesw”文件夹拷贝到新建好的工程中,将默认的文件删除,如下:

然后我们可以根据"~\1_ToolEnv\0_Build\1_Config\Config_Tricore_Hightec"目录下的Makefile
完成编译和链接等项目配置。
###############################################################################
# #
# Copyright (c) 2018 Infineon Technologies AG. All rights reserved. #
# #
# #
# IMPORTANT NOTICE #
# #
# #
# Infineon Technologies AG (Infineon) is supplying this file for use #
# exclusively with Infineon抯 microcontroller products. This file can be #
# freely distributed within development tools that are supporting such #
# microcontroller products. #
# #
# THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED #
# OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF #
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.#
# INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,#
# OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. #
# #
###############################################################################
B_HIGHTEC_TRICORE_PATH:= C:\Tools\Compilers\HIGHTEC\toolchains\tricore\v9.1.2
B_HIGHTEC_TRICORE_CC_OPTIONS= -fdata-sections -ffunction-sections -fno-common \
-march=tc162 -O2 -std=c99 -Wall -g -gdwarf-2
B_HIGHTEC_TRICORE_ASM_OPTIONS= $(B_HIGHTEC_TRICORE_CC_OPTIONS)
B_HIGHTEC_TRICORE_LD_OPTIONS= -Wl,--gc-sections -march=tc162 -Wl,-n
#Include path for library directories. Add each path with following format as shown below.
#Each path prefixed with -L and separated by a space.
#B_HIGHTEC_TRICORE_LIB_INC=-Wl,-L<path>[ -Wl,-L<path>][..]
B_HIGHTEC_TRICORE_LIB_INC=
#Libraries to include shall be listed with option -l, with following format.
#B_HIGHTEC_TRICORE_LIBS=-l<lib name>[ -l<lib name>][..]
B_HIGHTEC_TRICORE_LIBS=-lc++
首先通过:Project → Properties,然后再选择:C/C++ Build → Settings完成必要的配置:

其中我们主要需要修改TriCore C Compiler以及TriCore C Linker两个部分里边的内容。首先,我们TriCore C Compiler → General中把0_Src中的内容添加到InClude Paths中。

然后,我们在TriCore C Compiler → Symbols中根据当前使用的编译器和芯片以及封装类型添加对应的宏定义。

然后,我们再修改TriCore C Linker里的配置,首先是链接文件,在TriCore C Linker → General中选择“~\1_ToolEnv\0_Build\1_Config\Config_Tricore_Gnuc”目录下的Lcf_Gnuc_Tricore_Tc.lsl。

最后,我们再根据Makefile配置一个链接选项。

至此,我们已经完成了工程的配置和集成工作,但是要编译成功,还需要我们根据当前的芯片类型和封装来删除一些文件,首先需要我们在“~\0_Src\Libraries\Infra\Sfr”只留下芯片对应的文件夹,其中包含了芯片的寄存器地址定义。

最后,我们在“~0_Src\Libraries\iLLD\TC3xx\Tricore\_PinMap”文件下,只留下每个芯片外设对应封装的引脚映射,如下图所示:

至此,所有搭建工作已经完毕,编译完成之后即可生成对应的elf文件,如需生成hex文件则在Pos-Build Steps中添加Generate hex步骤即可,编译成功如下图所示:

GPIO驱动
Demo的使用
首先,在“\Infineon\Aurix2G_Workspace_V1_20_0\_Examples_TC3xx\BlinkyLed_TC39x\0_Src\AppSw\Tricore”目录下找到“Demo_BlinkeyLed”目录,并将其拷贝到工程的"~\0_Src\AppSw\Tricore"目录下,如下图所示:

然后根据Demo的Ifx_Cfg.h修改一下工程内的Ifx_Cfg.h配置,其中主要包含了芯片外部晶振的频率,PLL出来的频率,以及几个核心的使能状态,如下图所示:
/**
* \file Ifx_Cfg.h
* \brief Project configuration file.
*
* \copyright Copyright (c) 2018 Infineon Technologies AG. All rights reserved.
*
*
*
* IMPORTANT NOTICE
*
* Use of this file is subject to the terms of use agreed between (i) you or
* the company in which ordinary course of business you are acting and (ii)
* Infineon Technologies AG or its licensees. If and as long as no such terms
* of use are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer, must
* be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are
* solely in the form of machine-executable object code generated by a source
* language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#ifndef IFX_CFG_H
#define IFX_CFG_H 1
/******************************************************************************/
/*______________________________________________________________________________
** Configuration for IfxScu_cfg.h
**____________________________________________________________________________*/
#define IFX_CFG_SCU_XTAL_FREQUENCY (20000000) /**< */
#define IFX_CFG_SCU_PLL_FREQUENCY (300000000) /**< */
/*______________________________________________________________________________
** Configuration for Software managed interrupt
**____________________________________________________________________________*/
//#define IFX_USE_SW_MANAGED_INT
/*______________________________________________________________________________
** Configuration for Trap Hook Functions' Extensions
**____________________________________________________________________________*/
//#define IFX_CFG_EXTEND_TRAP_HOOKS
/*______________________________________________________________________________
** Configuration CPU enable / disable
**____________________________________________________________________________*/
#define IFX_CFG_SSW_ENABLE_TRICORE0 (1U)
#define IFX_CFG_SSW_ENABLE_TRICORE1 (1U)
#define IFX_CFG_SSW_ENABLE_TRICORE2 (1U)
#define IFX_CFG_SSW_ENABLE_TRICORE3 (1U)
#define IFX_CFG_SSW_ENABLE_TRICORE4 (1U)
#define IFX_CFG_SSW_ENABLE_TRICORE5 (1U)
/*______________________________________________________________________________
** Constant which for CPU Synchronization Event
**____________________________________________________________________________*/
#define IFXCPU_CFG_ALLCORE_DONE ( \
(IFX_CFG_SSW_ENABLE_TRICORE0 << 0U) | \
(IFX_CFG_SSW_ENABLE_TRICORE1 << 1U) | \
(IFX_CFG_SSW_ENABLE_TRICORE2 << 2U) | \
(IFX_CFG_SSW_ENABLE_TRICORE3 << 3U) | \
(IFX_CFG_SSW_ENABLE_TRICORE4 << 4U) | \
(IFX_CFG_SSW_ENABLE_TRICORE5 << 6U))
/*______________________________________________________________________________
** Configuration for CPU Caches enable / disable
**____________________________________________________________________________*/
#define IFX_CFG_SSW_ENABLE_TRICORE0_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE0_DCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE1_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE1_DCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE2_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE2_DCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE3_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE3_DCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE4_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE4_DCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE5_PCACHE 1
#define IFX_CFG_SSW_ENABLE_TRICORE5_DCACHE 1
/******************************************************************************/
#endif /* IFX_CFG_H */
然后,根据Demo修改一下每个核心的Main函数,Demo是在核0完成的初始化,并在每个核心中频繁实现Led闪烁功能,下面是CPU0的Main函数。
/**
* \file Cpu0_Main.c
* \brief Main function definition for Cpu core 0 .
*
* \copyright Copyright (c) 2018 Infineon Technologies AG. All rights reserved.
*
*
*
* IMPORTANT NOTICE
*
* Use of this file is subject to the terms of use agreed between (i) you or
* the company in which ordinary course of business you are acting and (ii)
* Infineon Technologies AG or its licensees. If and as long as no such terms
* of use are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer, must
* be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are
* solely in the form of machine-executable object code generated by a source
* language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Ifx_Cfg_Ssw.h"
IFX_ALIGN(4)
IfxCpu_syncEvent cpuSyncEvent = 0;
volatile uint32 ledBlink0 = 0;
#if !defined(IFX_CFG_SSW_RETURN_FROM_MAIN)
void core0_main(void)
{
#else
int core0_main(void)
{
#endif
IfxCpu_enableInterrupts();
/*
* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdog in the demo if it is required and also service the watchdog periodically
* */
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
extern void BlinkeyLedExample_init(void);
BlinkeyLedExample_init();
/* Cpu sync event wait*/
IfxCpu_emitEvent(&cpuSyncEvent);
IfxCpu_waitEvent(&cpuSyncEvent, 1);
#if !defined(IFX_CFG_SSW_RETURN_FROM_MAIN)
while (1)
{
extern void BlinkLed(void);
BlinkLed();
}
#else
return 0;
#endif
}
如果想要编译通过,还需要在BlinkeyLedExample.c中包含必要的头文件,包括#include "IfxPort_reg.h"和#include "IfxCpu_cfg_TC39xB.h"。下面是BlinkeyLedExample.c的完整内容:
/**
* \file BlinkeyLedExample.c
* \brief An example for blinking LEDs.
*
* \copyright Copyright (c) 2018 Infineon Technologies AG. All rights reserved.
*
*
*
* IMPORTANT NOTICE
*
* Use of this file is subject to the terms of use agreed between (i) you or
* the company in which ordinary course of business you are acting and (ii)
* Infineon Technologies AG or its licensees. If and as long as no such terms
* of use are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer, must
* be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are
* solely in the form of machine-executable object code generated by a source
* language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "IfxSrc.h"
#include "IfxStm.h"
#include "IfxPort.h"
#include "IfxCpu.h"
#include "IfxCpu_Irq.h"
#include "Ifx_Cfg.h"
#include "IfxPort_reg.h"
#include "IfxCpu_cfg_TC39xB.h"
#define LED0_BLINK_INTERVAL_IN_SECONDS (1)
extern volatile uint32 ledBlink0;
#if (IFXCPU_NUM_MODULES > 1)
extern volatile uint32 ledBlink1;
#if (IFXCPU_NUM_MODULES > 2)
extern volatile uint32 ledBlink2;
#if (IFXCPU_NUM_MODULES > 3)
extern volatile uint32 ledBlink3;
#if (IFXCPU_NUM_MODULES > 4)
extern volatile uint32 ledBlink4;
#if (IFXCPU_NUM_MODULES > 5)
extern volatile uint32 ledBlink5;
#endif /*#if (IFXCPU_NUM_MODULES > 5)*/
#endif /*#if (IFXCPU_NUM_MODULES > 4)*/
#endif /*#if (IFXCPU_NUM_MODULES > 3)*/
#endif /*#if (IFXCPU_NUM_MODULES > 2)*/
#endif /*#if (IFXCPU_NUM_MODULES > 1)*/
void BlinkLed(void)
{
switch (IfxCpu_getCoreIndex())
{
case IfxCpu_ResourceCpu_0:
IfxPort_setPinState(&MODULE_P33, 4, ledBlink0 ? IfxPort_State_high : IfxPort_State_low);
break;
#if (IFXCPU_NUM_MODULES > 1)
case IfxCpu_ResourceCpu_1:
IfxPort_setPinState(&MODULE_P33, 5, ledBlink1 ? IfxPort_State_high : IfxPort_State_low);
break;
#if (IFXCPU_NUM_MODULES > 2)
case IfxCpu_ResourceCpu_2:
IfxPort_setPinState(&MODULE_P33, 6, ledBlink2 ? IfxPort_State_high : IfxPort_State_low);
break;
#if (IFXCPU_NUM_MODULES > 3)
case IfxCpu_ResourceCpu_3:
IfxPort_setPinState(&MODULE_P33, 7, ledBlink3 ? IfxPort_State_high : IfxPort_State_low);
break;
#if (IFXCPU_NUM_MODULES > 4)
case IfxCpu_ResourceCpu_4:
IfxPort_setPinState(&MODULE_P20, 11, ledBlink4 ? IfxPort_State_high : IfxPort_State_low);
break;
#if (IFXCPU_NUM_MODULES > 5)
case IfxCpu_ResourceCpu_5:
IfxPort_setPinState(&MODULE_P20, 12, ledBlink5 ? IfxPort_State_high : IfxPort_State_low);
break;
#endif /*#if (IFXCPU_NUM_MODULES > 5)*/
#endif /*#if (IFXCPU_NUM_MODULES > 4)*/
#endif /*#if (IFXCPU_NUM_MODULES > 3)*/
#endif /*#if (IFXCPU_NUM_MODULES > 2)*/
#endif /*#if (IFXCPU_NUM_MODULES > 1)*/
default:
break;
}
}
#define STM0_ISR_PRIORITY 10
void Initialize_StmTicks(void)
{
IfxStm_CompareConfig stmCompareConfig;
// test_var= 1;
// suspend by debugger enabled
IfxStm_enableOcdsSuspend(&MODULE_STM0);
#if defined(IFX_USE_SW_MANAGED_INT)
void Stm0_Isr(void);
IfxCpu_Irq_installInterruptHandler(Stm0_Isr, STM0_ISR_PRIORITY);
#endif
// Call the constructor of configuration
IfxStm_initCompareConfig(&stmCompareConfig);
// Modify only the number of ticks and enable the trigger output
stmCompareConfig.ticks = 1000; /*Interrupt after 1000 ticks from now */
stmCompareConfig.triggerPriority = STM0_ISR_PRIORITY;
stmCompareConfig.typeOfService = IfxSrc_Tos_cpu0;
// Now Compare functionality is initialized
IfxStm_initCompare(&MODULE_STM0, &stmCompareConfig);
}
void BlinkeyLedExample_init(void)
{
P33_OUT.B.P4 = 1;
IfxPort_setPinMode(&MODULE_P33, 4, IfxPort_Mode_outputPushPullGeneral);
#if (IFXCPU_NUM_MODULES > 1)
P33_OUT.B.P5 = 1;
IfxPort_setPinMode(&MODULE_P33, 5, IfxPort_Mode_outputPushPullGeneral);
#if (IFXCPU_NUM_MODULES > 2)
P33_OUT.B.P6 = 1;
IfxPort_setPinMode(&MODULE_P33, 6, IfxPort_Mode_outputPushPullGeneral);
#if (IFXCPU_NUM_MODULES > 3)
P33_OUT.B.P7 = 1;
IfxPort_setPinMode(&MODULE_P33, 7, IfxPort_Mode_outputPushPullGeneral);
#if (IFXCPU_NUM_MODULES > 4)
P20_OUT.B.P11 = 1;
IfxPort_setPinMode(&MODULE_P20, 11, IfxPort_Mode_outputPushPullGeneral);
#if (IFXCPU_NUM_MODULES > 5)
P20_OUT.B.P12 = 1;
IfxPort_setPinMode(&MODULE_P20, 12, IfxPort_Mode_outputPushPullGeneral);
#endif /*#if (IFXCPU_NUM_MODULES > 5)*/
#endif /*#if (IFXCPU_NUM_MODULES > 4)*/
#endif /*#if (IFXCPU_NUM_MODULES > 3)*/
#endif /*#if (IFXCPU_NUM_MODULES > 2)*/
#endif /*#if (IFXCPU_NUM_MODULES > 1)*/
Initialize_StmTicks();
}
IFX_INTERRUPT(Stm0_Isr, 0, STM0_ISR_PRIORITY)
{
uint32 stmTicks;
__enable();
stmTicks = (uint32)(LED0_BLINK_INTERVAL_IN_SECONDS * IfxStm_getFrequency(&MODULE_STM0));
IfxStm_updateCompare(&MODULE_STM0, IfxStm_Comparator_0, IfxStm_getCompare(&MODULE_STM0, IfxStm_Comparator_0) + stmTicks);
if (ledBlink0 == 1)
{
ledBlink0 = 0;
#if (IFXCPU_NUM_MODULES > 1)
ledBlink1 = 0;
#if (IFXCPU_NUM_MODULES > 2)
ledBlink2 = 0;
#if (IFXCPU_NUM_MODULES > 3)
ledBlink3 = 0;
#if (IFXCPU_NUM_MODULES > 4)
ledBlink4 = 0;
#if (IFXCPU_NUM_MODULES > 5)
ledBlink5 = 0;
#endif /*#if (IFXCPU_NUM_MODULES > 5)*/
#endif /*#if (IFXCPU_NUM_MODULES > 4)*/
#endif /*#if (IFXCPU_NUM_MODULES > 3)*/
#endif /*#if (IFXCPU_NUM_MODULES > 2)*/
#endif /*#if (IFXCPU_NUM_MODULES > 1)*/
}
else
{
ledBlink0 = 1;
#if (IFXCPU_NUM_MODULES > 1)
ledBlink1 = 1;
#if (IFXCPU_NUM_MODULES > 2)
ledBlink2 = 1;
#if (IFXCPU_NUM_MODULES > 3)
ledBlink3 = 1;
#if (IFXCPU_NUM_MODULES > 4)
ledBlink4 = 1;
#if (IFXCPU_NUM_MODULES > 5)
ledBlink5 = 1;
#endif /*#if (IFXCPU_NUM_MODULES > 5)*/
#endif /*#if (IFXCPU_NUM_MODULES > 4)*/
#endif /*#if (IFXCPU_NUM_MODULES > 3)*/
#endif /*#if (IFXCPU_NUM_MODULES > 2)*/
#endif /*#if (IFXCPU_NUM_MODULES > 1)*/
}
}
GPIO驱动分析
GPIO的驱动相对简单,首先是配置,我们可以通过iLLD提供的IfxPort_setPinMode()函数完成。函数的定义如下图。

可以看到,我们通过Port和Pinindex来锁定我们要配置的引脚,使用mode来配置引脚的模式,例如:IfxPort_setPinMode(&MODULE_P33, 4, IfxPort_Mode_outputPushPullGeneral)这句话,就可以将P33.4配置为推挽输出,英飞凌引脚的可配置模式有很多,这里就不一一赘述了,有兴趣的读者可以结合着芯片手册来理解。
然后,我们就可以通过IfxPort_setPinState()函数来完成GPIO的输出状态控制。函数定义如下图:

可以看到,我们通过Port和Pinindex来锁定我们要驱动的引脚,然后通过action来配置引脚输出的高低,例如IfxPort_setPinState(&MODULE_P33, 4,IfxPort_State_high)这句话,就可以将刚才配置好的P33.4输出为高。
iLLD中的Port模块提供了不止上述提到的两个函数,它提供了丰富的功能函数来帮助我们更好的实现我们的业务代码,这里就不一一赘述了,有兴趣的读者可以从您使用芯片的iLLD_UM_TCxxx.chm中获得相应的说明。
十六宿舍 原创作品,转载必须标注原文链接。
©2023 Yang Li. All rights reserved.
欢迎关注 『十六宿舍』,大家喜欢的话,给个👍,更多关于嵌入式相关技术的内容持续更新中。
基于iLLD实现LED闪烁
5460

被折叠的 条评论
为什么被折叠?



