当前位置:网站首页>【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按键点灯
边栏推荐
- Flask introductory learning tutorial
- [AGC] Quality Service 1 - Example of Crash Service
- 静态网页和动态网页的不同之处;该如何选择服务器呢
- Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
- php如何截取字符串的前几位
- [AGC] Quality Service 2 - Performance Management Example
- Redis 复习计划 - Redis 数据结构和持久化机制
- The case of five little pigs (five little pigs compare the size of the body weight)
- 【AGC】开放式测试示例
- Pytorch 训练技巧
猜你喜欢
(Popular Science) What is Fractional NFT (Fractional NFT)
动态规划 --- 状态压缩DP 详细解释
影像信息提取DEM
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
【HMS core】【FAQ】push kit、分析服务、视频编辑服务典型问题合集3
rhce笔记2
Jetpack Compose 到底优秀在哪里?| 开发者说·DTalk
【HMS core】【FAQ】A collection of typical questions about Account, IAP, Location Kit and HarmonyOS 1
php如何截取字符串的前几位
Back waves are coming!Ali produced the "second generation" container technical manual and brain map, which is too fragrant
随机推荐
rscsa笔记八
tiup list
php如何去除字符串最后一位字符
[HMS core] [FAQ] A collection of typical questions about push kit, analysis services, and video editing services 3
【AGC】质量服务2-性能管理示例
[NCTF2019]Fake XML cookbook-1|XXE漏洞|XXE信息介绍
php如何查询字符串出现位置
【SOC FPGA】外设KEY点LED
[flutter]什么是MaterialApp和Material design
FME's scheme and operation process for reading and writing cass data
Flask之路由(app.route)详解
481-82 (105, 24, 82, 34, 153),
开源WebGIS架构
arcpy使用教程
【SOC】经典输出hello world
经典实例分割模型Mask RCNN原理与测试
Scheduling_Channel_Access_Based_on_Target_Wake_Time_Mechanism_in_802.11ax_WLANs
如何在分面中添加数学表达式标签?
影像信息提取DEM
Shell脚本的概念