vhdl: compile-time assert?

Discussion in 'VHDL' started by ra, Sep 30, 2004.

  1. ra

    ra Guest

    Hi,
    I'm defining a component with some generic constants in VHDL. I'd like
    to make synthesis fail with an error if the value given to one of the
    constants doesn't satisfy some conditions. Is there any way to do this?

    Thanks,
    RA
    ra, Sep 30, 2004
    #1
    1. Advertising

  2. ra wrote:

    > Hi,
    > I'm defining a component with some generic constants in VHDL. I'd like
    > to make synthesis fail with an error if the value given to one of the
    > constants doesn't satisfy some conditions. Is there any way to do this?


    I haven't tried this myself but something like this *should* work:

    entity test is
    generic ( a : integer := ...; b : integer := ...);
    ....
    architecture ... test

    -- if the result of the calculation is negative, this
    -- should cause an error
    constant verify : natural := (some function of a and b);

    --
    Tim Hubberstey, P.Eng. . . . . . Hardware/Software Consulting Engineer
    Marmot Engineering . . . . . . . VHDL, ASICs, FPGAs, embedded systems
    Vancouver, BC, Canada . . . . . . . . . . . http://www.marmot-eng.com
    Tim Hubberstey, Sep 30, 2004
    #2
    1. Advertising

  3. ra

    cristian Guest

    Tim Hubberstey <> wrote in message news:<mqK6d.5527$Du2.4366@edtnps89>...
    > ra wrote:
    >
    > > Hi,
    > > I'm defining a component with some generic constants in VHDL. I'd like
    > > to make synthesis fail with an error if the value given to one of the
    > > constants doesn't satisfy some conditions. Is there any way to do this?

    >
    > I haven't tried this myself but something like this *should* work:
    >
    > entity test is
    > generic ( a : integer := ...; b : integer := ...);
    > ...
    > architecture ... test
    >
    > -- if the result of the calculation is negative, this
    > -- should cause an error
    > constant verify : natural := (some function of a and b);


    I am not quite sure if you can do what you want to do.
    A constant is a data object that is declared in either the entity, the
    architecture (declarative part), a process (declarative part), a
    block, a procedure, a function or a package. When you declare a data
    object of class constant you have to assign a specific value to the
    data object and that value can not be changed by any VHDL statement.
    The only exception to that rule is when you declare constant in a
    package and you do not assign a value in the declaration. But, you do
    (have to ) assign a value in the package body. This is what is called
    constant deferred declaration.
    In resume contant can not get a new value in your code. So, if you are
    looking for checking specific conditions, you can use constant value
    to be compared with the value you want to check and assign the result
    to a boolean for instance.

    regards,

    cristian
    cristian, Sep 30, 2004
    #3
  4. cristian a écrit:
    > Tim Hubberstey <> wrote in message news:<mqK6d.5527$Du2.4366@edtnps89>...
    >>I haven't tried this myself but something like this *should* work:
    >>
    >>entity test is
    >>generic ( a : integer := ...; b : integer := ...);
    >>...
    >>architecture ... test
    >>
    >>-- if the result of the calculation is negative, this
    >>-- should cause an error
    >>constant verify : natural := (some function of a and b);

    >
    >
    > I am not quite sure if you can do what you want to do.


    Sure he can.


    > A constant is a data object that is declared in either the entity, the
    > architecture (declarative part), a process (declarative part), a
    > block, a procedure, a function or a package. When you declare a data
    > object of class constant you have to assign a specific value to the
    > data object and that value can not be changed by any VHDL statement.


    The constant is assigned a value computed on *generic* parameters, i.e.
    constants. This is perfectly legal (and works absolutely fine)

    I still don't see how this would make syntesis fail but that's another
    question :eek:)

    --
    ____ _ __ ___
    | _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le -
    | | | | | (_| |_| | Invalid return address: remove the -
    |_| |_|_|\__|\___/
    Nicolas Matringe, Sep 30, 2004
    #4
  5. Re: compile-time assert?

    "ra" <> wrote in message
    news:kwJ6d.1$...

    > I'm defining a component with some generic constants in VHDL. I'd like
    > to make synthesis fail with an error if the value given to one of the
    > constants doesn't satisfy some conditions. Is there any way to do this?


    The way I check the consistency of generics with each other or with design
    assumptions is:

    entity ClkPrescaler
    is generic (gPrescalerlength : integer := 2;
    gPrescalerValue : integer := 1;
    ...)
    port (...);
    end ClkPrescaler;

    architecture synthesisable of ClkPrescaler
    is
    subtype tPrescaler is Unsigned (gPrescalerLength-1 downto 0);
    constant cPrescalerMaximum : tPrescaler :=
    to_unsigned(2**gPrescalerlength-1, gPrescalerLength);
    ...

    begin
    ...
    assert 1 <= gPrescalerValue and gPrescalerValue <= cPrescalerMaximum
    report "gPrescalerValue (" & integer'image(gPrescalerValue)
    & ") is out of range : 1..2**gPrescalerLength-1 ("
    & integer'image(to_integer(cPrescalerMaximum)) & ")"
    severity Failure;
    ...
    end synthesisable;

    HTH

    If you wish to clean up the function soup used to generate integer text,
    define some functions.
    Sadly, I don't know of a better way - but live in hope of enlightenment.

    I know from experience that the above assertion will fire in ModelSim,
    Synplicity and LeonardoSpectrum.

    However, the assertion doesn't always work in Xilinx XST; based on back to
    back testing with ModelSim. gPrescalerValue = 0 -> assertion raised, =
    16 -> assertion not raised (erroneous behaviour). Additionally, XST doesn't
    output the fancy messages; you get "Assert statement with non static report"
    substituted for the error message; so you stick to dumb text. (I'll open a
    case with Xilinx regarding these issues; caveat XST).

    A broader issue raised, by this and other 'experiences' with tools, is to
    question whether it is not time that VHDL grew some
    verification/certification test suites (like Ada and C) and if necessary
    standardised implementation subsets to define/verify which language features
    have been implemented by a tool.

    Martin
    Martin Bishop, Sep 30, 2004
    #5
  6. ra

    cristian Guest

    Nicolas Matringe <> wrote in message news:<>...
    > cristian a écrit:
    > > Tim Hubberstey <> wrote in message news:<mqK6d.5527$Du2.4366@edtnps89>...
    > >>I haven't tried this myself but something like this *should* work:
    > >>
    > >>entity test is
    > >>generic ( a : integer := ...; b : integer := ...);
    > >>...
    > >>architecture ... test
    > >>
    > >>-- if the result of the calculation is negative, this
    > >>-- should cause an error
    > >>constant verify : natural := (some function of a and b);

    > >
    > >
    > > I am not quite sure if you can do what you want to do.

    >
    > Sure he can.
    >
    >
    > > A constant is a data object that is declared in either the entity, the
    > > architecture (declarative part), a process (declarative part), a
    > > block, a procedure, a function or a package. When you declare a data
    > > object of class constant you have to assign a specific value to the
    > > data object and that value can not be changed by any VHDL statement.

    >
    > The constant is assigned a value computed on *generic* parameters, i.e.
    > constants. This is perfectly legal (and works absolutely fine)
    >
    > I still don't see how this would make syntesis fail but that's another
    > question :eek:)


    Nicolas, I do agree with you and that is what I refer to in my first
    sentence: how to make the synthesis tool to fail. . .
    cristian, Sep 30, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Brewer
    Replies:
    1
    Views:
    486
    bsmith
    Nov 7, 2004
  2. Thomas Guettler

    assert 0, "foo" vs. assert(0, "foo")

    Thomas Guettler, Feb 23, 2005, in forum: Python
    Replies:
    3
    Views:
    2,519
    Carl Banks
    Feb 23, 2005
  3. Alex Vinokur

    assert(x) and '#define ASSERT(x) assert(x)'

    Alex Vinokur, Nov 25, 2004, in forum: C Programming
    Replies:
    5
    Views:
    911
    Keith Thompson
    Nov 25, 2004
  4. Francois Grieu

    more portable compile-time assert()

    Francois Grieu, Jan 11, 2008, in forum: C Programming
    Replies:
    12
    Views:
    648
    Ark Khasin
    Jan 17, 2008
  5. ImpalerCore

    To assert or not to assert...

    ImpalerCore, Apr 27, 2010, in forum: C Programming
    Replies:
    79
    Views:
    1,658
    Richard Bos
    May 17, 2010
Loading...

Share This Page