Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
11 years ago

how to define a function in quatus?

I created a file named user_defs.vhl, the contents as below:

LIBRARY ieee;

USE ieee.std_logic_1164.all;

PACKAGE user_defs IS

Type Clock is (int, ext);

Type Trig is (manual, auto);

function spi_adc_wr_rd(input_dat: bit_vector(15 downto 0); input_clk: std_logic) return bit_vector(15 downto 0);

END user_defs;

PACKAGE BODY user_defs IS

Function SPI_ADC_wr_RD(Input_dat: bit_vector(15 downto 0); Input_clk: std_LOGIC) return bit_vector(15 downto 0) is

variable tmp: bit_vector(Input_dat'rang);

begin

tmp <= Input_dat;

return tmp;

end;

END user_defs;

I want to invole this function of SPI_ADC_wr_RD in another VHDL file,

...

USE work.user_defs.all

...

but when I compile this project,

it always displays error as below, even I do not invole this function.

10479 VHDL error at user_defs(9): indexed name type is used but not declared.

I am using 32-bit Quartus 13.1,

please give me support.

thanks!

Br

jjl3

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Is that the full code? it has a typo in it:

    you need input_dat'range not rang

    Also, what are you expecting this function to do? currently. it does nothing except return the input. And the clock parameter does nothing.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Apart from the typo (rang -> range) and also tmp being assigned as a signal rather than a variable, the source of the error message given by Quartus is probably that you define the return type as a bit_vector(15 downto 0). This is interpreted as an array of bit_vectors (thus the mentioning of indexed name type). If you remove (15 downto 0) from the return clauses this compilation error should be cleared. That is:

    ...

    Function SPI_ADC_wr_RD(Input_dat: bit_vector(15 downto 0); Input_clk: std_LOGIC) return bit_vector;

    END user_defs;

    PACKAGE BODY user_defs IS

    Function SPI_ADC_wr_RD(Input_dat: bit_vector(15 downto 0); Input_clk: std_LOGIC) return bit_vector is

    ...

    /J
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    Apart from the typo (rang -> range) and also tmp being assigned as a signal rather than a variable, the source of the error message given by Quartus is probably that you define the return type as a bit_vector(15 downto 0). This is interpreted as an array of bit_vectors (thus the mentioning of indexed name type). If you remove (15 downto 0) from the return clauses this compilation error should be cleared. That is:

    ...

    Function SPI_ADC_wr_RD(Input_dat: bit_vector(15 downto 0); Input_clk: std_LOGIC) return bit_vector;

    END user_defs;

    PACKAGE BODY user_defs IS

    Function SPI_ADC_wr_RD(Input_dat: bit_vector(15 downto 0); Input_clk: std_LOGIC) return bit_vector is

    ...

    /J

    --- Quote End ---

    Thanks! you are right!