Hueestory

09 LED toggle 본문

FPGA(중단)/zynq

09 LED toggle

히명 2023. 3. 22. 14:36

Vivado를 사용해 Zynq IP 생성 → Vitis를 사용해 C 코딩

1. LED on / 'LED is ON' 출력

2. sleep 1s

3. LED off / 'LED is OFF' 출력

4. sleep 1s

 

* while을 통해 무한루프

* sleep 함수는 vitis에서 이용할 수 없으므로 sleep.h의 usleep 사용

(usleep은 micro second 단위를 사용하므로 usleep(1000000) → 1초 대기)

 

Vitis C Code

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


int main()
{
    static XGpioPs psGpioInstancePtr;
    XGpioPs_Config * GpioConfigPtr;
    int xStatus;
    int LedPinDirection = 1, LedPinNumber = 7;

    init_platform();

    print("Hello World\n\r");
    // 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");
    // LED Output //
    XGpioPs_SetDirectionPin(&psGpioInstancePtr, LedPinNumber, LedPinDirection);
    XGpioPs_SetOutputEnablePin(&psGpioInstancePtr, LedPinNumber, 1);

    xStatus = 0;
    while(1)
    {
		XGpioPs_WritePin(&psGpioInstancePtr, LedPinNumber, 1);
		print("LED(LD9) is ON\r\n");
		usleep(1000000);
		XGpioPs_WritePin(&psGpioInstancePtr, LedPinNumber, 0);
		print("LED(LD9) is OFF\r\n");
		usleep(1000000);
    }
    cleanup_platform();
    return 0;
}

 

01 LED on off

reference)

Xilinx gpiops API documents - https://xilinx.github.io/embeddedsw.github.io/gpiops/doc/html/api/xgpiops_8h.html

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

08 PL with AXI  (0) 2023.03.14
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