如下为GPIO的简单是引脚操作函数:
设置引脚MODE:
void IfxPort_setPinModeInput(Ifx_P *port, uint8 pinIndex, IfxPort_InputMode mode);
void IfxPort_setPinModeOutput(Ifx_P *port, uint8 pinIndex, IfxPort_InputMode mode);
IfxPort_setPinModeInput(&MODULE_P33, 0, IfxPort_InputMode_pullUp);
IfxPort_setPinModeOutput(&MODULE_P33, 0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
设置引脚电平:
void IfxPort_setPinHigh(Ifx_P *port, uint8 pinIndex);
void IfxPort_setPinLow(Ifx_P *port, uint8 pinIndex);
IfxPort_setPinLow(&MODULE_P33, 0);
设置引脚状态:
void IfxPort_setPinState(Ifx_P *port, uint8 pinIndex, IfxPort_State action)
设置引脚翻转:
void IfxPort_togglePin(Ifx_P *port, uint8 pinIndex);
读取引脚状态:
boolean IfxPort_getPinState(Ifx_P *port, uint8 pinIndex)
API详细参见:IfxPort.h
延时函数:
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME)); /* Wait 500 milliseconds
如下点灯:
Blinky LED文件:
#include "IfxPort.h"
#include "Bsp.h"
#define LED_D107 &MODULE_P13,0 /* LED D107: Port, Pin definition */
#define WAIT_TIME 500 /* Wait time constant in milliseconds */
/* This function initializes the port pin which drives the LED */
void initLED(void)
{
IfxPort_setPinModeOutput(LED_D107, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinHigh(LED_D107);
}
void blinkLED(void)
{
IfxPort_togglePin(LED_D107); /* Toggle the state of the LED */
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME)); /* Wait 500 milliseconds */
}
main.c
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Blinky_LED.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
void 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 */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
initLED(); /* Initialize the LED port pin */
while(1)
{
blinkLED(); /* Make the LED blink */
}
}
————————————————
版权声明:本文为CSDN博主「IOT-Power」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/a15236617777/article/details/131634000
|