06-03-2014 09:34 AM
In that case, it all depends on how you created the interface to your LVFPGA bitfile. I would recommend something like using a target-scoped FIFO, type U8, with some controls to control pushing data into/pulling data from the FIFO, and using the FPGA C API functionality to generate some tools to access the LVFPGA bitfile. Something like the following interface would do the trick:
C program | LabVIEW FPGA Bitfile
write_char -> (case structure to push into FIFO on rising-edge of write_char)
char_to_write => (input to FIFO)
char_read <= (output from FIFO)
read_char -> (case structure to pop from FIFO on rising-edge of read_char)
Of course, I am not really sure why you would want to do this, unless of course this is a class project.
06-03-2014 09:41 AM
Thanks!
So bascially can I just write it in the memory?
I write a single program,but it always appears segmentation fault,could you explain a liitle for me?
Really thanks!
#include "MyRio.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h> /* for fprintf */
#include <string.h> /* for memcpy */
#include <netinet/in.h>
#include <netdb.h>
int main(int argc,char **argv)
{
NiFpga_Status status;
status = MyRio_Open();
if (MyRio_IsNotSuccess(status))
{
return status;
}
unsigned char *pPacket=(unsigned char*)"FF00";
int num=0;
int i=0;
unsigned char *p;
p=(unsigned char *)100;
int len;
len=strlen(((const char*)pPacket))/2;
printf("%d\n",len);
//printf(num)
for(i=0;i<len;i++)
{
// Transmiting date
// *pPacket: data array pointer
*(p+i)=*pPacket;
pPacket++;
num++;
}
return 1;
// numPacket: number of data array
// Return: number of data transmitted. -1 is error.
/*
* Close the myRIO NiFpga Session.
* This function MUST be called after all other functions.
*/
status = MyRio_Close();
return status;
}
06-03-2014 10:02 AM
This code is a bit of a mess, and it's still not clear what you're trying to do. You open the MyRIO FPGA session and don't really do anything to interact with the default personality. Also, since we're talking about the default personality here, you can't really do any storage of data to the bitfile: its functionality is already defined.
A few other quick points:
"FF00" will result in pPacket pointing to {0x0 0x46 0x0 0x46 0x0 0x30 0x0 0x30} (the ASCII representation of the characters 'F', 'F', '0', '0', you are assigning the pointer to a string. char c = '\xF' or char c = 15 is not the same as char c = 'F')
*(p+i) is where you are likely getting your segfault. p is a pointer, i is iterating, this snippet is basically saying something like the following:
p points here > [X] [Y] [Z]
^p+i will point here if i = 3
What you're basically saying with *(p+i) = ... is to store something to the address Z. If Z is, for example, actually 0, then you'll get a segfault. There are many, many values that will cause issues since this code is not doing what you want it to (you don't want to dereference for storing data).
06-03-2014 10:09 AM
So the better way to transfer the data is using FIFO,right?
Is the logic that is create a FIFO by C and get read by Labview,because I find sth on the web,http://www.ni.com/white-paper/4534/en/.Is that helpful?
Thanks!
Sincerely,
John
06-03-2014 11:02 AM
That tutorial calls for changing the LabVIEW FPGA VI to have specific components and functionality. The code that you are writing is attempting to interface with the default personality (or a LabVIEW FPGA VI that has functionality that is wrapped for easy use of the I/O), and therefore you cannot talk to the FIFO since it's not in the FPGA VI.
I still don't quite understand why you need to do this.
06-03-2014 12:08 PM
Sorry I will try to explain what I want to do.
I have done the part that I can use Labview to read data from a certain memory in FPGA and then send them to a certain port to control a motor.But now I have met problems using C language to put the control packet into the memory,so the Labview part cannot get data and thus cannot send the packet.
What I want to do is just store the packet in somewhere in FPGA memory so as to let the Labview get my packet,so I was thinking if I can store the packet in FPGA memory.Since you have told me that many address in FPGA has already had its own functionality, can I get the address of the memory that is not used now(like a RAM) so that I can store that packet in it.
Sorry for the unclear statement that I made before,is that possible to achieve what I want?
Really thanks for your patience and help,looking forward to your reply!
Sincerely,
John
06-03-2014 03:06 PM
Similar question!
06-03-2014
04:18 PM
- last edited on
05-05-2025
12:28 PM
by
Content Cleaner
@saddadaa1 wrote:
...
I have done the part that I can use Labview to read data from a certain memory in FPGA and then send them to a certain port to control a motor.
...
I think the quickest way for me to understand what it is that you're trying to do is to post a screenshot of the VI that does this. Refer to this document
06-03-2014 04:47 PM
Thanks for your help!
You can find in the block diagram that I want to read the data from memory,and my packet is created through C language by Eclipse,so is there any solution?
Thanks again!
Sincerely,
John
06-04-2014 07:38 AM
I search for solutions in the Nifpga.h library,and I think maybe this function(NiFpga_Status NiFpga_WriteU8(NiFpga_Session session,uint32_t control, uint8_t value);)can be useful,can I also ask about the parameter control and session?Because I cannot understand them quite clearly and I tried but failed to find any tutorials online to use them.
Thanks!
Sincerely,
John