实验内容:控制MIO端口的LED闪烁,闪烁次数16次。 主函数:
int main(void)
{
int Status;
u32 InputData;
printf("GPIO Polled Mode Example Test \r\n");
Status = GpioPolledExample(GPIO_DEVICE_ID, &InputData);
if (Status != XST_SUCCESS) {
printf("GPIO Polled Mode Example Test Failed\r\n");
return XST_FAILURE;
}
printf("Data read from GPIO Input is 0x%x \n\r", (int)InputData);
printf("Successfully ran GPIO Polled Mode Example Test\r\n");
return XST_SUCCESS;
}
函数解析: int GpioPolledExample(u16 DeviceId, u32 *DataRead):
case XPLAT_ZYNQ:
Input_Pin = 14;
Output_Pin = 0; //控制输出引脚MIO O ,即LED的输出
break;
}
输出函数:
static int GpioOutputExample(void)
{
u32 Data;
volatile int Delay;
u32 LedLoop;
/*
* Set the direction for the pin to be output and引脚设置为输出
* Enable the Output enable for the LED Pin.使能 里面就是在配置寄存器
*/
XGpioPs_SetDirectionPin(&Gpio, Output_Pin, 1);
XGpioPs_SetOutputEnablePin(&Gpio, Output_Pin, 1);
/* Set the GPIO output to be low. 低电平为亮 */
XGpioPs_WritePin(&Gpio, Output_Pin, 0x0);
/* 16次循环 */
for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop ++) {
#ifndef __SIM__
/* Wait a small amount of time so the LED is visible. */
for (Delay = 0; Delay < LED_DELAY; Delay++);
#endif
/* Set the GPIO Output to High. */
XGpioPs_WritePin(&Gpio, Output_Pin, 0x1);
/*
* Read the state of the data and verify. If the data
* read back is not the same as the data written then
* return FAILURE.
*/
Data = XGpioPs_ReadPin(&Gpio, Output_Pin);
if (Data != 1 ) {
return XST_FAILURE;
}
#ifndef __SIM__
/* Wait a small amount of time so the LED is visible. */
for (Delay = 0; Delay < LED_DELAY; Delay++);
#endif
/* Clear the GPIO Output. */
XGpioPs_WritePin(&Gpio, Output_Pin, 0x0);
/*
* Read the state of the data and verify. If the data
* read back is not the same as the data written then
* return FAILURE.
*/
Data = XGpioPs_ReadPin(&Gpio, Output_Pin);
if (Data != 0) {
return XST_FAILURE;
}
}
return XST_SUCCESS;
}
EMIO:
和PS端的原理差不多,PL端相当于外设的扩展的一部分。需要额外在ZYNQ核上添加,然后经过OUTPUT PRODUCTS 后,顶层文件会有相当的引脚。需要我们对PL端的引脚进行约束。然后SDK 中修改对应的端口地址即可。
|