OpenCores
URL https://opencores.org/ocsvn/spi_boot/spi_boot/trunk

Subversion Repositories spi_boot

[/] [spi_boot/] [trunk/] [bench/] [vhdl/] [tb_pack-p.vhd] - Blame information for rev 77

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 arniml
-------------------------------------------------------------------------------
2
--
3
-- SD/MMC Bootloader
4
--
5 77 arniml
-- $Id: tb_pack-p.vhd 77 2009-04-01 19:53:14Z arniml $
6 4 arniml
--
7
-------------------------------------------------------------------------------
8
 
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
 
13
package 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 34 arniml
  function to_string(value : in integer) return string;
19
 
20 4 arniml
end tb_pack;
21
 
22
 
23
package 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 34 arniml
  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
 
80 4 arniml
end tb_pack;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.