用户自定义IP核——ZYNQ学习笔记6
一、试验任务
通过自定义一个 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_REG0BREATH_LED_IP_S0_AXI_SLV_REG0_OFFSET
#define LED_IP_REG1BREATH_LED_IP_S0_AXI_SLV_REG1_OFFSET
int 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_REG0BREATH_LED_IP_S0_AXI_SLV_REG0_OFFSET
#define LED_IP_REG1BREATH_LED_IP_S0_AXI_SLV_REG1_OFFSET
#define LED_IP_REG2BREATH_LED_IP_S0_AXI_SLV_REG2_OFFSET
int 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;
}
原文地址:https://blog.csdn.net/m0_69082048/article/details/143816833
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!