source: Hardware/WARP_v3/Rev1.1/Config_CPLD/src/spi_boot_OpenCores_src/bench/vhdl/tb_pack-p.vhd

Last change on this file was 1799, checked in by murphpo, 12 years ago

Adding WARP v3 hardware files (schematics, FPGA pinout, configuration CPLD source)

File size: 2.1 KB
Line 
1-------------------------------------------------------------------------------
2--
3-- SD/MMC Bootloader
4--
5-- $Id: tb_pack-p.vhd 77 2009-04-01 19:53:14Z arniml $
6--
7-------------------------------------------------------------------------------
8
9library ieee;
10use ieee.std_logic_1164.all;
11use ieee.numeric_std.all;
12
13package tb_pack is
14
15  function calc_crc(payload : in std_logic_vector) return std_logic_vector;
16  function calc_crc(payload : in unsigned) return unsigned;
17
18  function to_string(value : in integer) return string;
19
20end tb_pack;
21
22
23package body tb_pack is
24
25  function calc_crc(payload : in std_logic_vector) return std_logic_vector is
26
27    variable crc_v  : std_logic_vector(6 downto 0);
28    variable temp_v : std_logic;
29
30  begin
31
32    crc_v := (others => '0');
33
34    for i in payload'high downto payload'low loop
35      temp_v := payload(i) xor crc_v(6);
36
37      crc_v(6 downto 4) := crc_v(5 downto 3);
38      crc_v(3) := crc_v(2) xor temp_v;
39      crc_v(2 downto 1) := crc_v(1 downto 0);
40      crc_v(0) := temp_v;
41    end loop;
42
43    return crc_v;
44  end calc_crc;
45
46  function calc_crc(payload : in unsigned) return unsigned is
47  begin
48    return unsigned(calc_crc(std_logic_vector(payload)));
49  end calc_crc;
50
51  function to_string(value : in integer) return string is
52    variable str: string (11 downto 1);
53    variable val: integer := value;
54    variable digit: natural;
55    variable index: natural := 0;
56  begin
57    -- Taken from:
58    --  textio package body.  This file is part of GHDL.
59    --  Copyright (C) 2002 Tristan Gingold.
60    --  Note: the absolute value of VAL cannot be directly taken, since
61    --  it may be greather that the maximum value of an INTEGER.
62    loop
63      --  LRM93 7.2.6
64      --  (A rem B) has the sign of A and an absolute value less then
65      --   the absoulte value of B.
66      digit := abs (val rem 10);
67      val := val / 10;
68      index := index + 1;
69      str (index) := character'val(48 + digit);
70      exit when val = 0;
71    end loop;
72    if value < 0 then
73      index := index + 1;
74      str(index) := '-';
75    end if;
76
77    return str;
78  end to_string;
79
80end tb_pack;
Note: See TracBrowser for help on using the repository browser.