728x90
반응형
CoraZ7 보드를 이용하여 GPIO 테스트를 해보았다. Vivado에서 Block은 AXI 두개를 연결했고 버튼이 2개 있는데 일부러 사용자 지정으로 해서 해보았다. BTN0와 BTN1은 Custom으로 지정하여 XDC 파일에서 연결하였다.
이 후 Vitis에서 작업한 내용을 보면 GPIO를 셋업하고 GPIO를 사용하기 쉽게 define해 주었다.
코드 내용은 버튼 1을 누르면 RGB LED가 RGB1이 순차적으로 0.5초 딜레이를 가지고 변화한다. 버튼 2는 RGB2가 순차적으로 변화한다. 상태변화가 귀찮아서 그냥 슬립함수에 슬립을 사용해서 구현했다.
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/*
* helloworld.c: simple test application
*
* This application configures UART 16550 to baud rate 9600.
* PS7 UART (Zynq) is not initialized by this application, since
* bootrom/bsp configures it to baud rate 115200
*
* ------------------------------------------------
* | UART TYPE BAUD RATE |
* ------------------------------------------------
* uartns550 9600
* uartlite Configurable only in HW design
* ps7_uart 115200 (configured by bootrom/bsp)
*/
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xparameters.h"
#include "xgpio.h"
#include "sleep.h" // Sleep
// User Function Prototype
int Zynq_Init();
// User
XGpio RGB_Gpio;
XGpio BTN_Gpio;
XGpio BTN_Gpio;
/* Definitions */
#define ZYNQ_CLK 50000000
#define BTN_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_ID /* GPIO device that BTN are connected to */
#define RGB_DEVICE_ID XPAR_AXI_GPIO_1_DEVICE_ID /* GPIO device that RGB are connected to */
#define BTN0_CH XGPIO_IR_CH1_MASK // CH1 MASK 0x01
#define BTN1_CH XGPIO_IR_CH2_MASK // CH2 MASK 0x02
#define RGB_CH XGPIO_IR_CH1_MASK // CH1 MASK 0x01
#define RGB1_R_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x01));
#define RGB1_R_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x01));
#define RGB1_G_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x02));
#define RGB1_G_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x02));
#define RGB1_B_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x04));
#define RGB1_B_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x04));
#define RGB2_R_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x08));
#define RGB2_R_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x08));
#define RGB2_G_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x10));
#define RGB2_G_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x10));
#define RGB2_B_ON XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))|0x20));
#define RGB2_B_OFF XGpio_DiscreteWrite(&RGB_Gpio, RGB_CH, ((XGpio_DiscreteRead(&RGB_Gpio, RGB_CH))&~0x20));
#define BTNS0_STATE XGpio_DiscreteRead(&BTN_Gpio, BTN0_CH)&0x01
#define BTNS1_STATE XGpio_DiscreteRead(&BTN_Gpio, BTN1_CH)&0x01
int main()
{
int btn0_count=0, btn1_count=0;
init_platform();
print("Hello World\n\r");
print("Successfully ran Hello World application");
cleanup_platform();
Zynq_Init();
while(1)
{
if(BTNS0_STATE)
{
usleep(500000);
RGB1_R_OFF;
RGB1_G_OFF;
RGB1_B_OFF;
switch(btn0_count++)
{
case 1:
RGB1_R_ON;
break;
case 2:
RGB1_G_ON;
break;
case 3:
btn0_count=0;
RGB1_B_ON;
break;
default:
break;
}
}
if(BTNS1_STATE)
{
usleep(500000);
RGB2_R_OFF;
RGB2_G_OFF;
RGB2_B_OFF;
switch(btn1_count++)
{
case 1:
RGB2_R_ON;
break;
case 2:
RGB2_G_ON;
break;
case 3:
btn1_count=0;
RGB2_B_ON;
break;
default:
break;
}
}
}
return 0;
}
int Zynq_Init()
{
/* GPIO driver initialisation */
XGpio_Initialize(&RGB_Gpio, RGB_DEVICE_ID);
XGpio_Initialize(&BTN_Gpio, BTN_DEVICE_ID);
/*Set the direction for the LEDs to output. */
XGpio_SetDataDirection(&RGB_Gpio, RGB_CH, 0x00);
XGpio_SetDataDirection(&BTN_Gpio, BTN0_CH, 0xFF);
XGpio_SetDataDirection(&BTN_Gpio, BTN1_CH, 0xFF);
return XST_SUCCESS;
}
728x90
반응형
'전자 이야기 > Zynq' 카테고리의 다른 글
[Zynq] Vivado 테스트 보드 교체 방법 및 절차 (0) | 2022.11.09 |
---|---|
[Zynq] CoraZ7 MicroSD Boot (0) | 2022.10.16 |
[Vitis] Vitis 한글 주석 사용하기 (0) | 2022.09.17 |
[Zynq] ZyboZ7-20 Uart Interrupt (0) | 2022.09.15 |
[Zynq] Zybo 보드 플래쉬 프로그램 (0) | 2022.09.08 |