项目工程框架

项目驱动文件这个见过,三个main文件真的是开了眼,一个main代表一个核吗?
image.png
按照以往对实现LED闪烁的流程,一般是先配置时钟、再配置IO、延时,实现反转效果。

Blinky_LED.c

在驱动文件里:

  1. /*********************************************************************************************************************/
  2. /*-----------------------------------------------------Includes------------------------------------------------------*/
  3. /*********************************************************************************************************************/
  4. #include "IfxPort.h"
  5. #include "Bsp.h"
  6. /*********************************************************************************************************************/
  7. /*------------------------------------------------------Macros-------------------------------------------------------*/
  8. /*********************************************************************************************************************/
  9. #define LED &MODULE_P00,5 /* LED: Port, Pin definition */
  10. #define WAIT_TIME 500 /* Wait time constant in milliseconds */
  11. /*********************************************************************************************************************/
  12. /*---------------------------------------------Function Implementations----------------------------------------------*/
  13. /*********************************************************************************************************************/
  14. /* This function initializes the port pin which drives the LED */
  15. void initLED(void)
  16. {
  17. /* Initialization of the LED used in this example */
  18. IfxPort_setPinModeOutput(LED, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
  19. /* Switch OFF the LED (low-level active) */
  20. IfxPort_setPinHigh(LED);
  21. }
  22. /* This function toggles the port pin and wait 500 milliseconds */
  23. void blinkLED(void)
  24. {
  25. IfxPort_togglePin(LED); /* Toggle the state of the LED */
  26. waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME)); /* Wait 500 milliseconds */
  27. }

Bsp.h

这个看名字都可以猜出来,板级支持包。
默认系统定时器 MODULE_STM0 模式:

  1. #ifndef BSP_DEFAULT_TIMER
  2. /** Defined the default timer used */
  3. #define BSP_DEFAULT_TIMER (&MODULE_STM0)
  4. #endif

image.png
一些中断函数,使能或者不使能,甚至还可以返回中断的一些状态。

  1. IFX_INLINE boolean areInterruptsEnabled(void);
  2. IFX_INLINE boolean disableInterrupts(void);
  3. IFX_INLINE void enableInterrupts(void);
  4. IFX_INLINE void restoreInterrupts(boolean enabled);
  5. IFX_INLINE void forceDisableInterrupts(void);

还有一些系统定时器函数,非常有意思,有的可以查看你的程序运行了多长时间,有的可以查看程序距离结束还有多久……

  1. /** \addtogroup library_srvsw_sysse_bsp_bsp
  2. * \{ */
  3. /** \name Time APIs
  4. * \{ */
  5. IFX_INLINE Ifx_TickTime addTTime(Ifx_TickTime a, Ifx_TickTime b);
  6. IFX_INLINE Ifx_TickTime elapsed(Ifx_TickTime since);
  7. IFX_INLINE Ifx_TickTime getDeadLine(Ifx_TickTime timeout);
  8. IFX_INLINE Ifx_TickTime getTimeout(Ifx_TickTime deadline);
  9. IFX_EXTERN void initTime(void);
  10. IFX_INLINE boolean isDeadLine(Ifx_TickTime deadLine);
  11. IFX_INLINE Ifx_TickTime now(void);
  12. IFX_INLINE Ifx_TickTime nowWithoutCriticalSection(void);
  13. IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout);
  14. IFX_INLINE Ifx_TickTime timingNoInterruptEnd(Ifx_TickTime since, boolean interruptEnabled);
  15. IFX_INLINE Ifx_TickTime timingNoInterruptStart(boolean *interruptEnabled);
  16. IFX_INLINE void wait(Ifx_TickTime timeout);
  17. IFX_EXTERN void waitPoll(void);
  18. IFX_EXTERN void waitTime(Ifx_TickTime timeout);
  19. /** Prototype for wait() functions */
  20. typedef void (*WaitTimeFunction)(Ifx_TickTime timeout);

然后就是一些IO口的配置函数

  1. #define PIN_DRIVER_STRONG_SHARP IfxPort_PadDriver_cmosAutomotiveSpeed1
  2. #define Pin_setState(pin, mode) IfxPort_setPinState((pin)->port, (pin)->pinIndex, (mode))
  3. #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
  4. #define Pin_setMode(pin, mode) IfxPort_setPinMode((pin)->port, (pin)->pinIndex, (mode))
  5. #define Pin_setDriver(pin, mode) IfxPort_setPinPadDriver((pin)->port, (pin)->pinIndex, (mode))
  6. #define Pin_setStateHigh(pin) IfxPort_setPinHigh((pin)->port, (pin)->pinIndex)
  7. #define Pin_setStateLow(pin) IfxPort_setPinLow((pin)->port, (pin)->pinIndex)
  8. #define Pin_getState(pin) IfxPort_getPinState((pin)->port, (pin)->pinIndex)
  9. #define Pin_setGroupModeOutput(pin, mask, mode, outputIdx) IfxPort_setGroupModeOutput((pin)->port, (pin)->pinIndex, (mask), (mode), (outputIdx))
  10. #define Pin_setGroupModeInput(pin, mask, mode) IfxPort_setGroupModeInput((pin)->port, (pin)->pinIndex, (mask), (mode))
  11. #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
  12. #define Pin_getGroupState(pin, mask) IfxPort_getGroupState((pin)->port, (pin)->pinIndex, (mask))
  13. #define Pin_enableEmgStop(pin) IfxPort_enableEmergencyStop((pin)->port, (pin)->pinIndex)

IfxPort.h

这个也是,看名字就可以大致猜出来,Port端口,关于端口的一些结构体参数、功能定义什么的。
如:
输入模式:

  1. /** \brief Ifx_P output modification modes definition.
  2. */
  3. typedef enum
  4. {
  5. IfxPort_InputMode_undefined = -1,//不定义
  6. IfxPort_InputMode_noPullDevice = 0 << 3,//?
  7. IfxPort_InputMode_pullDown = 1U << 3,//下拉
  8. IfxPort_InputMode_pullUp = 2U << 3 //上拉 /**< \brief */
  9. } IfxPort_InputMode;

输出模式:

  1. /** \brief Pin output mode definition
  2. */
  3. typedef enum
  4. {
  5. IfxPort_OutputMode_pushPull = 0x10U << 3,
  6. IfxPort_OutputMode_openDrain = 0x18U << 3,
  7. IfxPort_OutputMode_none = 0
  8. } IfxPort_OutputMode;

初始化的:

  1. /** \addtogroup IfxLld_Port_Std_DataStructures
  2. * \{ */
  3. /** \brief Defines a pin
  4. */
  5. typedef struct
  6. {
  7. Ifx_P *port;
  8. uint8 pinIndex;
  9. } IfxPort_Pin;
  10. /** \brief To configure pins
  11. */
  12. typedef struct
  13. {
  14. Ifx_P *port;
  15. uint8 pinIndex;
  16. IfxPort_OutputIdx mode;
  17. IfxPort_PadDriver padDriver;
  18. } IfxPort_Pin_Config;

等等……
还有各种函数,非常细,具体的可以去查看这个头文件。

Cpu0_Main.c

  1. *********************************************************************************************************************/
  2. /*\title Blinky LED
  3. * \abstract An LED is blinking based on the timing given by a wait function.
  4. * \description A wait function is used to add delays between switching on and switching off an LED
  5. * on port pin P00.5.
  6. *
  7. * \name Blinky_LED_1_KIT_TC275_LK
  8. * \version V1.0.2
  9. * \board AURIX TC275 lite Kit, KIT_AURIX_TC275_LITE, TC27xTP_D-Step
  10. * \keywords AURIX, Blinky_LED_1, Blinky, LED, Lite
  11. * \documents https://www.infineon.com/aurix-expert-training/Infineon-AURIX_Blinky_LED_1_KIT_TC275_LK-TR-v01_00_02-EN.pdf
  12. * \documents https://www.infineon.com/aurix-expert-training/TC27D_iLLD_UM_1_0_1_12_0.chm
  13. * \lastUpdated 2021-06-29
  14. *********************************************************************************************************************/
  15. #include "Ifx_Types.h"
  16. #include "IfxCpu.h"
  17. #include "IfxScuWdt.h"
  18. #include "Blinky_LED.h"
  19. IfxCpu_syncEvent g_cpuSyncEvent = 0;//用于事件同步
  20. int core0_main(void)
  21. {
  22. IfxCpu_enableInterrupts();
  23. /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
  24. * Enable the watchdogs and service them periodically if it is required
  25. */
  26. IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
  27. IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
  28. /* Wait for CPU sync event 等待CPU进行事件同步*/
  29. IfxCpu_emitEvent(&g_cpuSyncEvent); //CPU发起事件
  30. IfxCpu_waitEvent(&g_cpuSyncEvent, 1); //等待事件
  31. initLED(); /* Initialize the LED port pin */
  32. while(1)
  33. {
  34. blinkLED(); /* Make the LED blink */
  35. }
  36. return (1);//返回1,也是我没想到的
  37. }

IfxCpu.h

CPU基本功能
如:
CPU状态模式

  1. /** \addtogroup IfxLld_Cpu_Std_Enum
  2. * \{ */
  3. /** \brief Enumeration for the Cpu mode
  4. */
  5. typedef enum
  6. {
  7. IfxCpu_CoreMode_halt,//挂起
  8. IfxCpu_CoreMode_run,//运行
  9. IfxCpu_CoreMode_idle,//待机
  10. IfxCpu_CoreMode_sleep,//睡眠
  11. IfxCpu_CoreMode_stby,//?
  12. IfxCpu_CoreMode_unknown//未知
  13. } IfxCpu_CoreMode;

先去看看手册,有些功能不是很懂

测试

编译和烧录

image.png

LED闪烁
c970ef1f856a33b5bc1d73974dcfc78.jpg