Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - function with 2d return type

 
Thread Tools Search this Thread
Old 01-08-2006, 09:48 PM   #1
Default function with 2d return type


Hello all,

I'm trying to code a function that initialize some vars from a file.
Function should reside in separate package and my intention is to use it for
different size and width of return type without manual correction whenever
design changes.
Something like:
load_hex_from_file(file_name:string; depth,bits:natural) return
2d_array_type;

2d_array_type should be parametrizable and should inherit type from variable
that receives data.
Do You have an idea how to accomplish this without special (custom) type
conversion functions?
At the moment variable in a separate package that needs init is defined like
this:
type ram_memory is array (0 to (2**(depth+1))-1) of std_logic_vector(bits-1
downto 0);
Any ideas?

Best regards,
M.

--
M. Veselic
Sigma Lab.




Maki - \(Remove 123 to mail me\)
  Reply With Quote
Old 01-11-2006, 01:48 AM   #2
Rob Dekker
 
Posts: n/a
Default Re: function with 2d return type

"Maki - (Remove 123 to mail me)" <> wrote in message news:dps1de$b2e$...
> Hello all,
>
> I'm trying to code a function that initialize some vars from a file.
> Function should reside in separate package and my intention is to use it for
> different size and width of return type without manual correction whenever
> design changes.
> Something like:
> load_hex_from_file(file_name:string; depth,bits:natural) return
> 2d_array_type;
>
> 2d_array_type should be parametrizable and should inherit type from variable
> that receives data.
> Do You have an idea how to accomplish this without special (custom) type
> conversion functions?
> At the moment variable in a separate package that needs init is defined like
> this:
> type ram_memory is array (0 to (2**(depth+1))-1) of std_logic_vector(bits-1
> downto 0);
> Any ideas?


Maki,

I assume that you want to use your 'load_hex_from_file' function to initialize a signal
of type 'ram_memory' ?

Well, since VHDL is strongly typed, the return type of the function should be 'ram_memory'.
With that, the index ranges of the returned value are defined and consistent with the
target signal that you want to initialize. Remember that if 'load_hex_from_file' returns
a value that does NOT have the exact number of elements needed for the target signal,
that your simulator will give an error any way. So let the function return 'ram_memory' type.

Does this help ?

Rob

>
> Best regards,
> M.
>
> --
> M. Veselic
> Sigma Lab.
>
>
>





Rob Dekker
  Reply With Quote
Old 01-11-2006, 10:09 AM   #3
Maki - \(Remove 123 to mail me\)
 
Posts: n/a
Default Re: function with 2d return type
"Rob Dekker" <> wrote in message
news:OtZwf.26407$ et...
>
> "Maki - (Remove 123 to mail me)" <> wrote in message

news:dps1de$b2e$...
> > Hello all,
> >
> > I'm trying to code a function that initialize some vars from a file.
> > Function should reside in separate package and my intention is to use it

for
> > different size and width of return type without manual correction

whenever
> > design changes.
> > Something like:
> > load_hex_from_file(file_name:string; depth,bits:natural) return
> > 2d_array_type;
> >
> > 2d_array_type should be parametrizable and should inherit type from

variable
> > that receives data.
> > Do You have an idea how to accomplish this without special (custom) type
> > conversion functions?
> > At the moment variable in a separate package that needs init is defined

like
> > this:
> > type ram_memory is array (0 to (2**(depth+1))-1) of

std_logic_vector(bits-1
> > downto 0);
> > Any ideas?

>
> Maki,
>
> I assume that you want to use your 'load_hex_from_file' function to

initialize a signal
> of type 'ram_memory' ?
>
> Well, since VHDL is strongly typed, the return type of the function should

be 'ram_memory'.
> With that, the index ranges of the returned value are defined and

consistent with the
> target signal that you want to initialize. Remember that if

'load_hex_from_file' returns
> a value that does NOT have the exact number of elements needed for the

target signal,
> that your simulator will give an error any way. So let the function return

'ram_memory' type.
>
> Does this help ?
>
> Rob
>


Hi Rob,
Thanks for Your answer
The problem is I don't want to peek into details of ram_memory type. It is
in a separate package on which I dont want to depend. Unfortunatly there is
no base standard type that is 2dim, so if I make my own type i have to
provide a package for conversion of that type to any other that I'm going to
use such as ram_memory or whatever.
I have tried an unconstrained array of (for example) std_logic_vector, but
the simulator is unhappy probably because standard does not allow such a
nonsense ). It would bi nice if I could to this :
load_hex_from_file(file_name:string; depth,bits:natural) return is array (0
to depth-1) of std_logic_vector(bits-1 downto 0) ;
Maybe I'm going to far with this. After all it is not such a big problem to
change those types to match.
Thanks anyway
Cheers,

--
M. Veselic
Sigma Lab.






Maki - \(Remove 123 to mail me\)
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: expected constructor, destructor or type conversion before '(' token suse Software 0 03-09-2009 03:25 AM
Eclipse - Axis2 - Java Webservices Error amanjsingh Software 1 10-09-2007 09:03 AM
Need help on Modelsim VHDL syntax? ASAP:) kaji General Help Related Topics 0 03-14-2007 10:43 PM
Need help on a Modelsim VHDL Syntax? ASAP:) kaji Software 0 03-14-2007 10:43 PM
Need Help on a Modelsim VHDL Syntax....ASAP:) kaji Hardware 0 03-14-2007 10:41 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46