Hueestory

08 PL with AXI 본문

FPGA(중단)/zynq

08 PL with AXI

히명 2023. 3. 14. 14:39

Vitis C Code

#include <stdio.h>
#include "xgpio.h"
#include "xgpiops.h"
#include "platform.h"

int main()
{
	static XGpio GPIOInstance_Ptr;
	static XGpioPs psGpioInstancePtr;
	XGpioPs_Config *GpioConfigPtr;
	u8 count = 0;
	int xStatus;
	int BtnPinDirection1 = 0, BtnPinNumber1 = 50;
	int Readstatus = 0, OldReadstatus = 0;

	init_platform();

	// Step 01 : AXI GPIO Initialization //
	xStatus = XGpio_Initialize(&GPIOInstance_Ptr, XPAR_AXI_GPIO_0_DEVICE_ID);
	if(XST_SUCCESS != xStatus)
		print("GPIO INIT FAILED \n\r");

	// Step 02 : AXI GPIO Set the Direction (OUTPUT) //
	XGpio_SetDataDirection(&GPIOInstance_Ptr, 1, 0);
	print("Hello World\n\r");

	// Step 03 : PS GPIO Initialization //
	GpioConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
	if(GpioConfigPtr == NULL)
		return XST_FAILURE;
	xStatus = XGpioPs_CfgInitialize(&psGpioInstancePtr, GpioConfigPtr, GpioConfigPtr -> BaseAddr);
	if(XST_SUCCESS != xStatus)
		print("PS GPIO INIT FAILED \n\r");

	// Step 04 : PS GPIO pin setting to Input //
	XGpioPs_SetDirectionPin(&psGpioInstancePtr, BtnPinNumber1, BtnPinDirection1);
	XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, BtnPinNumber1, 0);
	while(1)
	{
		Readstatus = XGpioPs_ReadPin(&psGpioInstancePtr, BtnPinNumber1);
		if((Readstatus == 1) && (OldReadstatus == 0))
		{
			print("BTN8(PB1-MI050) PUSH Button pressed \n\r");
			count++;
			XGpio_DiscreteWrite(&GPIOInstance_Ptr, 1, count);
		}
		OldReadstatus = Readstatus;
	}
	print("\r\n");
	print("***********\r\n");
	print("BYE \r\n");
	print("***********\r\n");
	cleanup_platform();
	return 0;
}

'FPGA(중단) > zynq' 카테고리의 다른 글

09 LED toggle  (0) 2023.03.22
07 PS MIO  (0) 2023.03.03
06 BRAM tutorial  (0) 2023.02.18
05 Keypad tutorial  (0) 2023.02.18
04 VGA tutorial  (0) 2023.02.18
Comments