Impulse C generates an error when I try to use a structure as the parameter in a co_stream_read process that's in hardware (I don't get the error when I try using a struct as the parameter in the co_stream_write, but I assume that's because it's in software). That would be fine if this was C++, I would read it in as a co_uint64, which is the same size as the structure that I want, and then do a reinterpret cast. Unfortunately, this is not C++, so I tried to use a union, but I can't seem to get unions to work.
How am I supposed to pass a structure into hardware via a stream?
Transfering Structures via Streams
Started by Jonathan, Jun 03 2009 08:43 AM
4 replies to this topic
#1
Posted 03 June 2009 - 08:43 AM
#2
Posted 03 June 2009 - 12:03 PM
Hi Jonathan,
You can read the struct's data off the stream as a co_uint64, then shift and mask to populate a struct variable with data (example code attached).
Structs are not supported as parameters to co_stream_* functions in hardware, and unions are not supported in hardware. Please see the section "Programming for Hardware" in the Impulse C User Guide for more details.
Regards,
Ralph
You can read the struct's data off the stream as a co_uint64, then shift and mask to populate a struct variable with data (example code attached).
Structs are not supported as parameters to co_stream_* functions in hardware, and unions are not supported in hardware. Please see the section "Programming for Hardware" in the Impulse C User Guide for more details.
Regards,
Ralph
Attached File(s)
-
structMarshal.zip (3.62K)
Number of downloads: 15
Ralph Bodenner
Impulse Accelerated Technologies, Inc.
Impulse Accelerated Technologies, Inc.
#3
Posted 03 June 2009 - 12:17 PM
When compiled, is this as efficient as a a reinterpretation would be? All I care about is efficiency.
#4
Posted 03 June 2009 - 01:20 PM
A more efficient option would be to write a VHDL function (see doc on the "CO IMPLEMENTATION" pragma) that uses signal assignments to turn a co_uint64 into several smaller constituents. This would also be easily reusable.
Ralph Bodenner
Impulse Accelerated Technologies, Inc.
Impulse Accelerated Technologies, Inc.
#5
Posted 04 June 2009 - 11:37 AM
QUOTE (RalphBodenner @ Jun 3 2009, 05:20 PM) <{POST_SNAPBACK}>
A more efficient option would be to write a VHDL function (see doc on the "CO IMPLEMENTATION" pragma) that uses signal assignments to turn a co_uint64 into several smaller constituents. This would also be easily reusable.
Well, I found a way that is aesthetically more pleasing than marshaling the data with and-masks and shifts, and intuitively it seems like it should compile into hardware as efficiently as possible... Since all pointer arithmetic on the hardware must be between constants, can I assume that the following is performance wise equivalent to a reinterpretation cast or using a union type?
char buffer[1 gazzillion billion million];
struct struct_type_1* my_struct_1 = (struct_type_1*)&buffer;
struct struct_type_2* my_struct_2 = (struct_type_2*)&buffer;
Then all I have to do is read the data into the buffer, and I can interpret it either using struct_type_1 or struct_type_2. So the question is, is this as efficient as simply reinterpreting the bits?
Anyway, I tried it, but then somewhere in my code I had the following line:
prefetch->message_type
Which worked fine when compiling to software, but when compiling to hardware Impulse C threw the following error:
...: Pointers Not supported
What's the point of letting me do all the above if I can't even use the pointer?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












