一、试验任务
通过自定义一个 LED IP 核,通过 PS 端的程序来控制底板上 PL 端 LED1 呈现呼吸
灯的效果,并且 PS 可以通过 AXI 接口来控制呼吸灯的开关和呼吸的频率。
二、创建IP核
三、创建工程,调用IP
#include "stdio.h"
#include "xparameters.h"
#include "breath_led_ip.h"
#include "xil_io.h"
#include "sleep.h"#define LED_IP_BASEADDR XPAR_BREATH_LED_IP_0_S0_AXI_BASEADDR
#define LED_IP_REG0 BREATH_LED_IP_S0_AXI_SLV_REG0_OFFSET
#define LED_IP_REG1 BREATH_LED_IP_S0_AXI_SLV_REG1_OFFSETint main(){int freq_flag = 0;int led_status = 0;while(1){if(freq_flag == 0){BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG1,0x80000001);freq_flag = 1;}else{BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG1,0x80000009);freq_flag = 0;}led_status = BREATH_LED_IP_mReadReg(LED_IP_BASEADDR,LED_IP_REG0);if(led_status == 0){//打开呼吸灯开关BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG0,1);sleep(5);}led_status = BREATH_LED_IP_mReadReg(LED_IP_BASEADDR,LED_IP_REG0);if(led_status == 1){//关闭呼吸灯开关BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG0,0);sleep(1);}}return 0;
}
四、上板验证
五、对以有IP核进行编译
重新生成bit流与硬件信息
更改vitis平台硬件信息见xilinx vitis 更换硬件平台——ZYNQ学习笔记5_vitis升级硬件平台-CSDN博客
#include "stdio.h"
#include "xparameters.h"
#include "breath_led_ip.h"
#include "xil_io.h"
#include "sleep.h"#define LED_IP_BASEADDR XPAR_BREATH_LED_IP_0_S0_AXI_BASEADDR
#define LED_IP_REG0 BREATH_LED_IP_S0_AXI_SLV_REG0_OFFSET
#define LED_IP_REG1 BREATH_LED_IP_S0_AXI_SLV_REG1_OFFSET
#define LED_IP_REG2 BREATH_LED_IP_S0_AXI_SLV_REG2_OFFSETint main(){int freq_flag = 0;int led_status = 0;int test_data = 0;while(1){if(freq_flag == 0){BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG1,0x80000001);freq_flag = 1;}else{BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG1,0x80000009);freq_flag = 0;}led_status = BREATH_LED_IP_mReadReg(LED_IP_BASEADDR,LED_IP_REG0);if(led_status == 0){//打开呼吸灯开关BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG0,1);sleep(3);}led_status = BREATH_LED_IP_mReadReg(LED_IP_BASEADDR,LED_IP_REG0);if(led_status == 1){//关闭呼吸灯开关BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG0,0);sleep(1);}test_data = BREATH_LED_IP_mReadReg(LED_IP_BASEADDR,LED_IP_REG2);if(test_data != 0 ){BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG1,0x80000005);BREATH_LED_IP_mWriteReg(LED_IP_BASEADDR,LED_IP_REG0,1);sleep(8);test_data = 0;}}return 0;
}