使用VisualStudio读写NI FPGA板卡实例(基于FPGA Interface C API Generator)
2017-07-16 04:43
393 查看
实验平台说明:安装了NI LabVIEW 2015 32bit版本,安装了NI FPGA Interface C API Generator,安装了硬件PCIe-7842R;安装了Visual Studio 2015(下载的C API Generator说明是针对VS2013,不过实验测试发现vs2015可以使用);按照官网给的例子进行实验http://www.ni.com/tutorial/8638/en/,只测试了FPGA板卡模拟输入功能,没有写模拟输出功能。官网例子是采用NI公司的LabWindows/CVI上位机软件。
实验步骤:
在LabVIEW中新建FPGA工程,命名为FPGA.vi
此工程中,FPGA和上位机有四个接口:3个参数输入接口(Samples等等),1个数据读取接口(FIFO),接口通信通过PCIe进行。编译该工程,得到bitfile文件
2.打开FPGA Interface C API Generator,导入之前用LabVIEW编译生成的FPGA bitfile,点击generate,生成了几个个文件:1.FPGA bitfile; 2.NiFpga.c;3.NiFpga.h;4.NiFpga_FPGA.h;
其中NiFpga_FPGA.h包含了应用程序中函数调用需要的常量,和上述读写结构的地址信息
NiFpga.c和NiFpga.h对所有工程都是一样的,包含了调用NI FPGA的各种系统函数。
3.新建visual studio控制台应用程序,添加上述几个文件
4.NiFpga.c设置编译属性,选择No Precompile,如下。(如果不这样设置,编译的时候会因C/C++编译问题而报错)
5.编译上位机程序,主要是打开FPGA(完成下载bitfile到FPGA的任务),按照地址读写FPGA中的接口,关闭FPGA等操作。测试程序如下:
参考文献:
官网给出的R系列FPGA的C API用法说明http://www.ni.com/tutorial/8638/en/
电脑上给出的FPGA Interface C API Generator的example
实验步骤:
在LabVIEW中新建FPGA工程,命名为FPGA.vi
此工程中,FPGA和上位机有四个接口:3个参数输入接口(Samples等等),1个数据读取接口(FIFO),接口通信通过PCIe进行。编译该工程,得到bitfile文件
2.打开FPGA Interface C API Generator,导入之前用LabVIEW编译生成的FPGA bitfile,点击generate,生成了几个个文件:1.FPGA bitfile; 2.NiFpga.c;3.NiFpga.h;4.NiFpga_FPGA.h;
其中NiFpga_FPGA.h包含了应用程序中函数调用需要的常量,和上述读写结构的地址信息
NiFpga.c和NiFpga.h对所有工程都是一样的,包含了调用NI FPGA的各种系统函数。
3.新建visual studio控制台应用程序,添加上述几个文件
4.NiFpga.c设置编译属性,选择No Precompile,如下。(如果不这样设置,编译的时候会因C/C++编译问题而报错)
5.编译上位机程序,主要是打开FPGA(完成下载bitfile到FPGA的任务),按照地址读写FPGA中的接口,关闭FPGA等操作。测试程序如下:
// ConsoleApplication1.cpp : Defines the entry point for the console application. // // NIFPGATest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "NiFpga_FPGA.h" #include <malloc.h> int main() { /* must be called before any other calls */ printf("Initializing...\n"); NiFpga_Status status = NiFpga_Initialize(); if (NiFpga_IsNotError(status)) { NiFpga_Session session; /* opens a session, downloads the bitstream, and runs the FPGA */ printf("Opening a session...\n"); /* opens a session, downloads the bitstream, but does not run the FPGA */ NiFpga_MergeStatus(&status, NiFpga_Open(NiFpga_FPGA_Bitfile, NiFpga_FPGA_Signature, "RIO0", NiFpga_OpenAttribute_NoRun, &session)); if (NiFpga_IsNotError(status)) { /* declare variables for output and input */ double numSamples, aorate, airate; uint16_t threshold = 0; uint32_t r, timeout = 10000/* 10 seconds */; NiFpga_Bool overLimit; int16_t *data = NULL; numSamples = 10; airate = 1000; /* allocate size for the samples to read */ data = (int16_t*)malloc(sizeof(int16_t) * numSamples); /* write the number of samples and loop rate to the FPGA VI */ NiFpga_MergeStatus(&status, NiFpga_WriteI32(session, NiFpga_FPGA_ControlI32_Samples, numSamples)); NiFpga_MergeStatus(&status, NiFpga_WriteU32(session, NiFpga_FPGA_ControlU32_LoopPeriod, airate)); NiFpga_MergeStatus(&status, NiFpga_WriteI16(session, NiFpga_FPGA_ControlI16_Threshold, threshold)); /* run the FPGA application */ printf("Running the FPGA...\n"); NiFpga_MergeStatus(&status, NiFpga_Run(session, 0)); /* read the DMA FIFO */ NiFpga_MergeStatus(&status, NiFpga_ReadFifoI16(session, NiFpga_FPGA_TargetToHostFifoI16_FIFO, data, numSamples, timeout, &r)); /* read the Over Limit? boolean */ NiFpga_MergeStatus(&status, NiFpga_ReadBool(session, NiFpga_FPGA_IndicatorBool_OverLimit, &overLimit)); /* close the session now that we're done */ printf("Closing the session...\n"); NiFpga_MergeStatus(&status, NiFpga_Close(session, 0)); } /* must be called after all other calls */ printf("Finalizing...\n"); NiFpga_MergeStatus(&status, NiFpga_Finalize()); } /* check if anything went wrong */ if (NiFpga_IsError(status)) { printf("Error %d!\n", status); printf("Press <Enter> to quit...\n"); getchar(); } return status; }
参考文献:
官网给出的R系列FPGA的C API用法说明http://www.ni.com/tutorial/8638/en/
电脑上给出的FPGA Interface C API Generator的example
相关文章推荐
- java使用RandomAccessFile类基于指针读写文件实例代码
- Linux下使用Eclipse开发基于nms板卡的c/c++程序
- 使用gSOAP开发实例(7) 基于HTTPS的基本认证(Basic Authentication)
- jQuery EasyUI 中文API Button使用实例
- 使用WCF web API测试基于REST的WCF Service
- Windows Azure Drive(一): 在云端使用了NTFS 本地文件系统读写API
- VB 使用API读写INI
- java中读写锁的实现及使用读写锁简单实现缓存系统的实例
- 使用Myeclipse 8.5开发基于JAX-WS的Web service实例
- 使用c#创建windows窗口(基于api)
- 原创基于标签的表单验证插件,有源码,有注释,有实例,使用超级方便。
- C#使用StreamWriter类和StreamReader类读写文件综合实例
- tcpdump使用实例——基于ip统计流量
- android数据库存储方法(一)---------------SharedPreferences(实例)记录应用程序使用次数(二)读写写他应用程序
- Spring:使用JdbcTemplate的简单实例-基于注释
- 基于1553B总线的ARINC 661指令传输(二)--HT-6306板卡提供的API性能测试
- 使用hdfsAPI读写hdfs
- Spring:使用JdbcTemplate的简单实例-基于XML文件配置
- 第4章 ISE开发环境使用指南[FPGA开发实用教程]——第3节 基于ISE的开发流程
- 语义Web服务的API使用实例:OWL-S API结合matchmaker、推理机(Jena、Pellet)进行语义转换、匹配、组合及调用web服务