Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL function calling problem

Status
Not open for further replies.

ruwan2

Member level 5
Member level 5
Joined
Nov 29, 2011
Messages
90
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
2,141
Hi,

When I write a CRC VHDL code based on a online snippet. It has an error:

** Error: C:\Users\Jeff\crc_ccitt.vhd(15):
(vcom-1115) Subtype indication found where type mark is required.


I guess that there are two overloading crc_shift function in previous post
causing error. Then I explicitly define two crc_shift(0) function inside the
package. It has a new error:



Could anybody help me on what is wrong? Thanks,





Code:
library IEEE; 
use IEEE.std_logic_1164.all; 
    
use IEEE.numeric_std.all; 
    

package                        crc_package is 
    function crc_shift 
    -- Mike Treseler 
    -- parallel data version 
       (constant X_load : in unsigned (15 downto 0); 
        constant D_vec  : in unsigned (15 downto 0); 
        constant Poly   : in unsigned := x"3223")  --Poly_16_12_5) 
        return unsigned (15 downto 0); 
end                package        crc_package; 

package body crc_package is 
     function crc_shift0 
    -- Mike Treseler 
    -- serial data version, see overload for parallel data below 
    -- Purpose  : Single bit shift for a CRC register using any polynomial. 
    -- Inputs   : X_load   : Current CRC vector. 
    --            D_bit    : Data to shift into CRC vector. 
    --            Poly     : CRC polynomial. Default is Frame Relay. 
    -- 
    -- Outputs  : CRC vector after CRC shift. 
       ( 
       constant X_load : in unsigned;  -- register start value 
       constant D_bit  : in std_ulogic := '0';         -- input bit 
       constant Poly   : in unsigned  := x"3223" --Poly_16_12_5 -- poly bits 
       ) 
       return unsigned is 
       variable X_out : unsigned(X_load'range);  -- CRC register 
    begin ---------------------------------------------------------------------- 
          -- we assume that X and Poly are in downto format 
          -- to match the textbook definition of LSFR 
          -- and to match the CCITT FCS bit assigments 
          -- for frame relay, note that X(15) becomes the lsb of octet n-2 
          --                   and that X(7 ) becomes the lsb of octet n-1 
          ---------------------------------------------------------------------- 
          -- Procedure: Left shift a '0' into the current X0 
          --            and the previous X(14) into the current X15 etc. 
          --            if the original  X15 is '1' or the data is '1' 
          --            but not both, then invert the poly bit locations 
          ---------------------------------------------------------------------- 
          -- Sample Invocation: 
          -- crc_shift(    "0001000100010001", '1')); 
          -- SLL            0010001000100010    -- shift the variable 
          -- D (not X15)   [   !      !    !]   -- invert poly locations? 
          -- expect("shift1 0011001000000011"); -- expected result 
          ---------------------------------------------------------------------- 
       assert X_load'length = Poly'length 
          report "crc_shift: Vectors X_load and Poly must be of equal length." 
          severity error; 
       X_out := X_load sll 1; 
       if (X_load(X_load'left) xor D_bit) = '1' then 
          X_out := X_out xor Poly; 
       end if; 
       return unsigned(X_out);                  -- returns each shift 
       end function crc_shift0; 

----------------------------------------------- 


    function crc_shift 
    -- Mike Treseler 
    -- parallel data version 
       (constant X_load : in unsigned (15 downto 0); 
        constant D_vec  : in unsigned (15 downto 0); 
        constant Poly   : in unsigned := x"3223")  --Poly_16_12_5) 
       return unsigned is 
       variable X_out : unsigned(X_load'range); 
    begin 
       X_out := X_load; 
       for I in D_vec'range loop -- call serial version for each bit 
          X_out := crc_shift0(X_out, D_vec(I), Poly); 
       end loop; 
       return X_out; 
    end function crc_shift; 
    
end        package body crc_package;                                          

library IEEE; 
use IEEE.std_logic_1164.all; 
use WORK.crc_package.all; 

entity tb is 
end tb; 

architecture structural of tb is 

signal internal_carry : std_logic; 
signal sum1: unsigned (15 downto 0);
 
Last edited by a moderator:

The good point with most error messages is that they refer to a specific line of code. Did you already identify the error line?
 

There is no clear which line is wrong. It looks like the first crc_shift function call has problems now. Even I comment out the internal (serial) crc_shift function in the package, it still complains the same problem.
 

You never say what the error is after you changed the serial version of the function to crc_shift0.

Doesn't VHDL require that all the function definitions in the package body be declared in the package?

- - - Updated - - -

There is no clear which line is wrong. It looks like the first crc_shift function call has problems now. Even I comment out the internal (serial) crc_shift function in the package, it still complains the same problem.

You don't call the function anywhere in this code? You declare the function in the package but you aren't using it in the posted code.
 

I see only one syntax error in the code, crc_shift return type in function body (unsigned) is different from declaration (unsigned (15 downto 0)).
 

I see only one syntax error in the code, crc_shift return type in function body (unsigned) is different from declaration (unsigned (15 downto 0)).

FvM, I was wondering if that was correct or not. I don't use VHDL that much so I'm never sure about those pesky type conversions.
 

Hi,

After I explicitly add type range, see below. It works now.


package crc_package is
function crc_shift
-- Mike Treseler
-- parallel data version
(constant X_load : in unsigned (15 downto 0);
constant D_vec : in unsigned (15 downto 0);
constant Poly : in unsigned := x"1021") --Poly_16_12_5)
return unsigned; -- (15 downto 0);


The new problem is that my results are different from a website on several CCITT variant formats.

I can run this routine through simulation. In the same time, my Matlab can generate the same results with CCITT (x^16+x^12+x^5+1). The initial generator
states are all '0'. When the message bits are 0x8000, the checksum is 0x1B98.

When I check website:

https://www.lammertbies.nl/comm/info/crc-calculation.html

There are several kinds of CCITT, such as xModem, 0xFFFF etc. I have tried
different kinds of initial states, byte order etc., but no one can generate
the same results of the simulation program and Matlab result. Could you tell me
what format can result in the differences?





Thanks,
 

Yes, 0x1B98 is right for XMODEM CRC, as also shown on the linked website. So what's the problem?

After I explicitly add type range
Or remove the ranges - in declaration and body.
 
  • Like
Reactions: ruwan2

    ruwan2

    Points: 2
    Helpful Answer Positive Rating
  • Like
Reactions: ruwan2

    ruwan2

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top