VHDL standard layout & syntax for "header" file -
ide: quartus 15
i'm new vhdl programming there nuances not used (translating c++). whilst have found resources programming "source" files, i've struggled find "header" files.
in short, standard layout / syntax of vhdl "header" file?
to keep things simple, use cases i'm interested in declaring subtype
, function references use between "source" files.
i found following code snippet here has helped little, i'm still not sure of differences between package
, package body
are. i'm unsure of "work" comes from.
"header":
package defs constant major_version: integer := 0; constant minor_version: integer := 22; constant maxreg: integer := 52; type regs_type array (0 maxreg) of std_logic_vector(15 downto 0); function opndrn(inp: std_logic) return std_logic; end package defs; package body defs function opndrn(inp: std_logic) return std_logic begin case inp when '0' => return '0'; when others => return 'z'; end case; end; end package body defs;
"source":
library work; use work.defs.all;
any , appreciated.
thankfully, there no header files in vhdl.
what have there package, isn't ever "include"d in anything.
unlike header file, package seperately compiled - library, can "use" doing.
unlike header file, package creates own namespace. use work.defs.all;
imports entire namespace, using namespace defs
in c++. it's better practice write use work.defs;
allows selectively use namespace, , refer defs.major_version
in source, (a) keeping global namespace uncluttered, , (b) documenting major_version
defined.
unlike header file, package encourages proper separation of interface , implementation. source can access things exported package, i.e. declared in package not package body. allows information hiding, opaque types , better abstractions.
for example can declare major_version
in package hide actual value in body (see "deferred constants")
it's legal both package , package body (interface , implementation) in same file, if want enforce separation of interface , implementation, package body separate file.
then can modify package body (implementation) , recompile : nothing uses package needs recompilation (unless changed interface.
any customer of package has @ package file, not package body.
in short, doing looks pretty ok.
but can go further in information hiding.
and 1 thing beware of creating 1 all-purpose god package : far better separate bus constants, functions etc "bus" package, register types (and maybe enumeration of names) in "registers" package, instructions in "instructions" package etc.
Comments
Post a Comment