项目工程框架
项目驱动文件这个见过,三个main文件真的是开了眼,一个main代表一个核吗?
按照以往对实现LED闪烁的流程,一般是先配置时钟、再配置IO、延时,实现反转效果。
Blinky_LED.c
在驱动文件里:
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "IfxPort.h"
#include "Bsp.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define LED &MODULE_P00,5 /* LED: Port, Pin definition */
#define WAIT_TIME 500 /* Wait time constant in milliseconds */
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* This function initializes the port pin which drives the LED */
void initLED(void)
{
/* Initialization of the LED used in this example */
IfxPort_setPinModeOutput(LED, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
/* Switch OFF the LED (low-level active) */
IfxPort_setPinHigh(LED);
}
/* This function toggles the port pin and wait 500 milliseconds */
void blinkLED(void)
{
IfxPort_togglePin(LED); /* Toggle the state of the LED */
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME)); /* Wait 500 milliseconds */
}
Bsp.h
这个看名字都可以猜出来,板级支持包。
默认系统定时器 MODULE_STM0 模式:
#ifndef BSP_DEFAULT_TIMER
/** Defined the default timer used */
#define BSP_DEFAULT_TIMER (&MODULE_STM0)
#endif
一些中断函数,使能或者不使能,甚至还可以返回中断的一些状态。
IFX_INLINE boolean areInterruptsEnabled(void);
IFX_INLINE boolean disableInterrupts(void);
IFX_INLINE void enableInterrupts(void);
IFX_INLINE void restoreInterrupts(boolean enabled);
IFX_INLINE void forceDisableInterrupts(void);
还有一些系统定时器函数,非常有意思,有的可以查看你的程序运行了多长时间,有的可以查看程序距离结束还有多久……
/** \addtogroup library_srvsw_sysse_bsp_bsp
* \{ */
/** \name Time APIs
* \{ */
IFX_INLINE Ifx_TickTime addTTime(Ifx_TickTime a, Ifx_TickTime b);
IFX_INLINE Ifx_TickTime elapsed(Ifx_TickTime since);
IFX_INLINE Ifx_TickTime getDeadLine(Ifx_TickTime timeout);
IFX_INLINE Ifx_TickTime getTimeout(Ifx_TickTime deadline);
IFX_EXTERN void initTime(void);
IFX_INLINE boolean isDeadLine(Ifx_TickTime deadLine);
IFX_INLINE Ifx_TickTime now(void);
IFX_INLINE Ifx_TickTime nowWithoutCriticalSection(void);
IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout);
IFX_INLINE Ifx_TickTime timingNoInterruptEnd(Ifx_TickTime since, boolean interruptEnabled);
IFX_INLINE Ifx_TickTime timingNoInterruptStart(boolean *interruptEnabled);
IFX_INLINE void wait(Ifx_TickTime timeout);
IFX_EXTERN void waitPoll(void);
IFX_EXTERN void waitTime(Ifx_TickTime timeout);
/** Prototype for wait() functions */
typedef void (*WaitTimeFunction)(Ifx_TickTime timeout);
然后就是一些IO口的配置函数
#define PIN_DRIVER_STRONG_SHARP IfxPort_PadDriver_cmosAutomotiveSpeed1
#define Pin_setState(pin, mode) IfxPort_setPinState((pin)->port, (pin)->pinIndex, (mode))
#define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
#define Pin_setMode(pin, mode) IfxPort_setPinMode((pin)->port, (pin)->pinIndex, (mode))
#define Pin_setDriver(pin, mode) IfxPort_setPinPadDriver((pin)->port, (pin)->pinIndex, (mode))
#define Pin_setStateHigh(pin) IfxPort_setPinHigh((pin)->port, (pin)->pinIndex)
#define Pin_setStateLow(pin) IfxPort_setPinLow((pin)->port, (pin)->pinIndex)
#define Pin_getState(pin) IfxPort_getPinState((pin)->port, (pin)->pinIndex)
#define Pin_setGroupModeOutput(pin, mask, mode, outputIdx) IfxPort_setGroupModeOutput((pin)->port, (pin)->pinIndex, (mask), (mode), (outputIdx))
#define Pin_setGroupModeInput(pin, mask, mode) IfxPort_setGroupModeInput((pin)->port, (pin)->pinIndex, (mask), (mode))
#define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
#define Pin_getGroupState(pin, mask) IfxPort_getGroupState((pin)->port, (pin)->pinIndex, (mask))
#define Pin_enableEmgStop(pin) IfxPort_enableEmergencyStop((pin)->port, (pin)->pinIndex)
IfxPort.h
这个也是,看名字就可以大致猜出来,Port端口,关于端口的一些结构体参数、功能定义什么的。
如:
输入模式:
/** \brief Ifx_P output modification modes definition.
*/
typedef enum
{
IfxPort_InputMode_undefined = -1,//不定义
IfxPort_InputMode_noPullDevice = 0 << 3,//?
IfxPort_InputMode_pullDown = 1U << 3,//下拉
IfxPort_InputMode_pullUp = 2U << 3 //上拉 /**< \brief */
} IfxPort_InputMode;
输出模式:
/** \brief Pin output mode definition
*/
typedef enum
{
IfxPort_OutputMode_pushPull = 0x10U << 3,
IfxPort_OutputMode_openDrain = 0x18U << 3,
IfxPort_OutputMode_none = 0
} IfxPort_OutputMode;
初始化的:
/** \addtogroup IfxLld_Port_Std_DataStructures
* \{ */
/** \brief Defines a pin
*/
typedef struct
{
Ifx_P *port;
uint8 pinIndex;
} IfxPort_Pin;
/** \brief To configure pins
*/
typedef struct
{
Ifx_P *port;
uint8 pinIndex;
IfxPort_OutputIdx mode;
IfxPort_PadDriver padDriver;
} IfxPort_Pin_Config;
Cpu0_Main.c
*********************************************************************************************************************/
/*\title Blinky LED
* \abstract An LED is blinking based on the timing given by a wait function.
* \description A wait function is used to add delays between switching on and switching off an LED
* on port pin P00.5.
*
* \name Blinky_LED_1_KIT_TC275_LK
* \version V1.0.2
* \board AURIX TC275 lite Kit, KIT_AURIX_TC275_LITE, TC27xTP_D-Step
* \keywords AURIX, Blinky_LED_1, Blinky, LED, Lite
* \documents https://www.infineon.com/aurix-expert-training/Infineon-AURIX_Blinky_LED_1_KIT_TC275_LK-TR-v01_00_02-EN.pdf
* \documents https://www.infineon.com/aurix-expert-training/TC27D_iLLD_UM_1_0_1_12_0.chm
* \lastUpdated 2021-06-29
*********************************************************************************************************************/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Blinky_LED.h"
IfxCpu_syncEvent g_cpuSyncEvent = 0;//用于事件同步
int core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event 等待CPU进行事件同步*/
IfxCpu_emitEvent(&g_cpuSyncEvent); //CPU发起事件
IfxCpu_waitEvent(&g_cpuSyncEvent, 1); //等待事件
initLED(); /* Initialize the LED port pin */
while(1)
{
blinkLED(); /* Make the LED blink */
}
return (1);//返回1,也是我没想到的
}
IfxCpu.h
CPU基本功能
如:
CPU状态模式
/** \addtogroup IfxLld_Cpu_Std_Enum
* \{ */
/** \brief Enumeration for the Cpu mode
*/
typedef enum
{
IfxCpu_CoreMode_halt,//挂起
IfxCpu_CoreMode_run,//运行
IfxCpu_CoreMode_idle,//待机
IfxCpu_CoreMode_sleep,//睡眠
IfxCpu_CoreMode_stby,//?
IfxCpu_CoreMode_unknown//未知
} IfxCpu_CoreMode;
测试
LED闪烁