当前位置:网站首页>【SOC FPGA】Peripheral KEY LED
【SOC FPGA】Peripheral KEY LED
2022-07-30 16:10:00 【Caixukun 001】
文章目录
一、添加LED和KEY的pio外设
1、黄金参考工程

2、配置pio外设
打开Plaform Designer,右侧搜索pio并双击.
(1)添加pio_KEY
我们使用key1和key2,所以选择2位.
连线:
(2)添加pio_LED
cyclone ⅤThe board has fourLED,所以选择4位.
连线:
默认给led和key分配的地址都是0,So click assign address to solve the error.
3、修改Verilog代码
Click when the connection is completeGenrate HDL,自动实例化.
在topInterfaces are defined in modules and instantiated

4、全编译
Perfect without mistakes
二、生成相应的文件,转移至sd卡内
1、更新dtb文件
打开SOC…Shell
进入黄金工程目录:
make dtb
更新dtb文件
See if the file time is updated successfully
2、更新rbf文件
运行命令:
cd output_files/
./sof_to_rbf.bat

See if the file time is updated successfully

3、更新hps_0.h文件
运行:
./generate_hps_qsys_header.sh

See if the file time is updated successfully
4、替换sd卡中的内容

三、编写C代码实现功能
打开eclipse
1、C工程准备
新建一个Cproject
导入库文件:
将黄金工程的hps_0.h放入工程中
2、C语言实现按键点灯
代码实现:
/* * pio_led.c * * Created on: 2022年7月19日 * Author: 哈哈 */
//标准头文件
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
//HPS厂家提供的底层定义头文件
#define soc_cv_av //开发平台Cyclone V 系列
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
//与用户具体的HPS 应用系统相关的硬件描述头文件
#include "hps_0.h"
#define HW_REGS_BASE (ALT_STM_OFST) //HPS外设地址段基地址
#define HW_REGS_SPAN (0x04000000) //HPS外设地址段地址空间 64MB大小
#define HW_REGS_MASK (HW_REGS_SPAN - 1) //HPS外设地址段地址掩码
static unsigned long *led_pio_virtual_base =NULL ;
static unsigned long *key_pio_virtual_base = NULL;
int led_init(int *virtual_base)
{
int fd;
void *perph_virtual_base;
//1.open打开
fd = open("/dev/mem",(O_RDWR | O_SYNC));
if(fd == -1)
{
printf("open failed..\n");
return 1;
}
//mmap 映射虚拟地址
perph_virtual_base = mmap(NULL,HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ),MAP_SHARED,fd,HW_REGS_BASE);
led_pio_virtual_base = perph_virtual_base +
(((unsigned)(ALT_LWFPGASLVS_OFST + PIO_LED_BASE))&(unsigned)(HW_REGS_MASK));
key_pio_virtual_base = perph_virtual_base +
(((unsigned)(ALT_LWFPGASLVS_OFST + PIO_KEY_BASE))&(unsigned)(HW_REGS_MASK));
*virtual_base = perph_virtual_base;
return fd;
}
int main()
{
int fd;
int i=0;
int virtual_base;
fd = led_init(&virtual_base);
while(1)
{
if(*(key_pio_virtual_base + 0) == 0x01)
{
*(led_pio_virtual_base + 0) = 0x01;
}
else if(*(key_pio_virtual_base + 0) == 0x02)
{
*(led_pio_virtual_base + 0) = 0x02;
}
/**(led_pio_virtual_base +0) = 1<<i; i=(i+1)%4; sleep(1); printf("LIGHT:%d ON\n",i);*/
}
//取消映射
if(munmap(virtual_base,HW_REGS_SPAN) == -1)
{
printf("fail\n");
}
close(fd);
return 0;
}
3、效果演示
FPGA之SOC按键点灯
边栏推荐
- How to use Redis for distributed applications in Golang
- C# List<T> 模板的案例
- tiup help
- 【HMS core】【FAQ】push kit、分析服务、视频编辑服务典型问题合集3
- Manage components using TiUP commands
- 新人学习小熊派网络应用开发
- Scheduling_Channel_Access_Based_on_Target_Wake_Time_Mechanism_in_802.11ax_WLANs
- php如何截取字符串的前几位
- Wuhan Star Sets Sail: Overseas warehouse infrastructure has become a major tool for cross-border e-commerce companies to go overseas
- Leetcode 119. 杨辉三角 II
猜你喜欢

SMI 与 Gateway API 的 GAMMA 倡议意味着什么?

Scheduling_Channel_Access_Based_on_Target_Wake_Time_Mechanism_in_802.11ax_WLANs

3D激光SLAM:LeGO-LOAM论文解读---实验对比

大型综合办公管理系统源码(OA+HR+CRM)源码免费分享

How to implement timing tasks for distributed applications in Golang

php如何查询字符串出现位置

STM32F407定时器输入捕获

3D激光SLAM:LeGO-LOAM论文解读---激光雷达里程计与建图

How to remove first character from php string

详解最实用的几种dll注入方式
随机推荐
yarn的安装及使用教程
RISC-V calling conventions
【AGC】Open Test Example
【SOC FPGA】外设KEY点LED
Windows MySQL 安装配置
Shell脚本的概念
vivo宣布延长产品保修期限 系统上线多种功能服务
How to do a good job in technology selection
新人学习小熊派网络应用开发
SMI 与 Gateway API 的 GAMMA 倡议意味着什么?
C#西门子S7 协议通过偏移量的方式读写PLC DB块
[flutter] What is MaterialApp and Material design
Flask introductory learning tutorial
[AGC] Quality Service 2 - Performance Management Example
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
为什么中年男人爱出轨?
STM32F407定时器输入捕获
配置Path环境变量
影像信息提取DEM
涨姿势了!原来这才是多线程正确实现方式