Results 1 to 4 of 4

Thread: using typedef intput argument for function

  1. #1
    Join Date
    Jun 2016
    Posts
    14
    Rep Power
    1

    Default using typedef intput argument for function

    Hi

    I want to pass a signal with a defined typedef into a function, however I got this error:
    10476: type identifier "data" does nto agree with its usage as "int_array" type.
    10559: actual formal parameter "data" must be a signal

    and I couldn't find an answer for it. My code is as followed.

    Code:
    -------------- Sub function ---------------------
    package function_list is
        --* typedef 
        type    int_array    is    array    (integer range <>) of integer;
        
        --* functions
        function sum(signal data: int_array(0 to 9)) return integer;
    end function_list;
    
    
    package body function_list is
        function sum(signal data: int_array(0 to 9)) return integer is
            variable sum_val:    integer range 0 to 255    :=0;
        begin
            for i in 0 to 9 loop
                sum_val:= sum_val + data(i);
            end loop;
            return sum_val;
        end sum;
    end function_list;
    
    
    
    --------------- Main file --------
    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;
    use ieee.numeric_std.all;
    use work.function_list.all;
    
    
    architecture rtl of main is
        type    int_array    is    array    (integer range <>) of integer;
        signal    data:    int_array(0 to 9);
    
    begin
        sum_process: process(sum_flag,clk)
            variable sum_val: integer range 0 to 255;
        begin
            if rising_edge(clk) then
                if sum_flag = '1' then 
                    sum_val:= sum(data); 
                end if;
            end if;
        end process;    
    
    end rtl;

  2. #2
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    5,651
    Rep Power
    1

    Default Re: using typedef intput argument for function

    This is because of the strong typing in VHDL.
    The int_array type in the function_list package is not the same type as the one you declared in the "main" entity.
    Hence the missmatch when you call the sum function, as data is int_array, while the function wants work.function_list.int_array

    The fix here is to remove the type declaration from the main file. You dont need it as it is already declared in the included function_list package.

    note: VHDL 2008 includes the integer_vector type that is an array of integers.

  3. #3
    Join Date
    Jun 2016
    Posts
    14
    Rep Power
    1

    Default Re: using typedef intput argument for function

    Thanks Tricky.
    It get it now. Just one more question regarding to "integer_vector":
    - How to use / which package do I have to include so that I can use this "integer_vector" type ? Since it gives no suggestion for this type when I'm typing. I tried to search for answer but couldn't find.
    Thanks

  4. #4
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Posts
    5,651
    Rep Power
    1

    Default Re: using typedef intput argument for function

    First of all, integer_vector requires that you use VHDL 2008. Quartus does not have full 2008 support unless you use Quartus Pro 17+, so it may not be supported.
    integer_vector is part of the std.standard package that is included in all VHDL files by default, so no package inclusion is necessary.

Similar Threads

  1. Out entity parameter as function argument
    By yuklimov in forum VHDL
    Replies: 3
    Last Post: February 17th, 2015, 10:17 PM
  2. system verilog typedef
    By anishjoseph007 in forum General Altera Discussion
    Replies: 1
    Last Post: May 16th, 2012, 06:38 AM
  3. C-Typedef struct with µClinux
    By papyenfurie in forum Linux Forum
    Replies: 2
    Last Post: July 17th, 2009, 06:36 AM
  4. typedef enum
    By SHL in forum Quartus II and EDA Tools Discussion
    Replies: 1
    Last Post: August 17th, 2007, 11:12 AM
  5. Why: typedef unsigned int OS_STK;
    By David_Cai in forum General Software Forum
    Replies: 3
    Last Post: July 28th, 2006, 06:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •