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

Subversion Repositories btc_dsha256

[/] [btc_dsha256/] [trunk/] [rtl/] [vhdl/] [TestBench/] [btc_dsha_TB.vhd] - Diff between revs 2 and 3

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 3
Line 1... Line 1...
 
------------------------------------------------------------------- 
 
--                                                               --
 
--  Copyright (C) 2013 Author and VariStream Studio              --
 
--  Author : Yu Peng                                             --
 
--                                                               -- 
 
--  This source file may be used and distributed without         -- 
 
--  restriction provided that this copyright statement is not    -- 
 
--  removed from the file and that any derivative work contains  -- 
 
--  the original copyright notice and the associated disclaimer. -- 
 
--                                                               -- 
 
--  This source file is free software; you can redistribute it   -- 
 
--  and/or modify it under the terms of the GNU Lesser General   -- 
 
--  Public License as published by the Free Software Foundation; -- 
 
--  either version 2.1 of the License, or (at your option) any   -- 
 
--  later version.                                               -- 
 
--                                                               -- 
 
--  This source is distributed in the hope that it will be       -- 
 
--  useful, but WITHOUT ANY WARRANTY; without even the implied   -- 
 
--  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      -- 
 
--  PURPOSE.  See the GNU Lesser General Public License for more -- 
 
--  details.                                                     -- 
 
--                                                               -- 
 
--  You should have received a copy of the GNU Lesser General    -- 
 
--  Public License along with this source; if not, download it   -- 
 
--  from http://www.opencores.org/lgpl.shtml                     -- 
 
--                                                               -- 
 
-------------------------------------------------------------------
 
 
library hotan;
library hotan;
use hotan.sha_256_pkg.all;
use hotan.sha_256_pkg.all;
library ieee;
library ieee;
use ieee.NUMERIC_STD.all;
use ieee.NUMERIC_STD.all;
use ieee.STD_LOGIC_UNSIGNED.all;
use ieee.STD_LOGIC_UNSIGNED.all;
Line 24... Line 52...
                iClkProcess : in STD_LOGIC;
                iClkProcess : in STD_LOGIC;
                iRst_async : in STD_LOGIC;
                iRst_async : in STD_LOGIC;
                iValid_p : in STD_LOGIC;
                iValid_p : in STD_LOGIC;
                ivAddr : in STD_LOGIC_VECTOR(3 downto 0);
                ivAddr : in STD_LOGIC_VECTOR(3 downto 0);
                ivData : in STD_LOGIC_VECTOR(31 downto 0);
                ivData : in STD_LOGIC_VECTOR(31 downto 0);
                oReachEnd : out STD_LOGIC;
                oReachEnd_p : out STD_LOGIC;
                oFoundNonce : out STD_LOGIC;
                oFoundNonce_p : out STD_LOGIC;
                ovNonce : out STD_LOGIC_VECTOR(31 downto 0);
                ovNonce : out STD_LOGIC_VECTOR(31 downto 0);
                ovDigest : out tDwordArray(0 to 7) );
                ovDigest : out tDwordArray(0 to 7) );
        end component;
        end component;
 
 
        component sha_256_chunk
        component sha_256_chunk
        generic(
        generic(
                gMSG_IS_CONSTANT : std_logic_vector(0 to 15) := (others=>'1');
                gMSG_IS_CONSTANT : std_logic_vector(0 to 15) := (others=>'1');
                gH_IS_CONST : std_logic_vector(0 to 7) := (others=>'1');
                gH_IS_CONST : std_logic_vector(0 to 7) := (others=>'1');
                gBASE_DELAY : integer := 1
                gBASE_DELAY : integer := 3;
 
                gOUT_VALID_GEN : boolean := false;
 
                gUSE_BRAM_AS_LARGE_SHIFTREG : boolean := false
        );
        );
        port(
        port(
                iClk : in STD_LOGIC;
                iClk : in STD_LOGIC;
                iRst_async : in STD_LOGIC;
                iRst_async : in STD_LOGIC;
                iValid : in STD_LOGIC;
                iValid : in STD_LOGIC;
Line 56... Line 86...
                ovH2 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH2 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH3 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH3 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH4 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH4 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH5 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH5 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH6 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH6 : out STD_LOGIC_VECTOR(31 downto 0);
                ovH7 : out STD_LOGIC_VECTOR(31 downto 0) );
                ovH7 : out STD_LOGIC_VECTOR(31 downto 0);
 
                oValid : out std_logic);
        end component;
        end component;
 
 
        component pipelines_without_reset IS
        component pipelines_without_reset IS
                GENERIC (gBUS_WIDTH : integer := 1; gNB_PIPELINES: integer range 1 to 255 := 2);
                GENERIC (gBUS_WIDTH : integer := 1; gNB_PIPELINES: integer range 1 to 255 := 2);
                PORT(
                PORT(
Line 78... Line 109...
        signal iRst_async : STD_LOGIC := '1';
        signal iRst_async : STD_LOGIC := '1';
        signal iValid_p : STD_LOGIC := '0';
        signal iValid_p : STD_LOGIC := '0';
        signal ivAddr : STD_LOGIC_VECTOR(3 downto 0) := (others=>'0');
        signal ivAddr : STD_LOGIC_VECTOR(3 downto 0) := (others=>'0');
        signal ivData : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
        signal ivData : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
        -- Observed signals - signals mapped to the output ports of tested entity
        -- Observed signals - signals mapped to the output ports of tested entity
        signal oReachEnd : STD_LOGIC := '0';
        signal oReachEnd_p : STD_LOGIC := '0';
        signal oFoundNonce : STD_LOGIC := '0';
        signal oFoundNonce_p : STD_LOGIC := '0';
        signal ovNonce : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
        signal ovNonce : STD_LOGIC_VECTOR(31 downto 0) := (others=>'0');
        signal ovDigest : tDwordArray(0 to 7) := (others=>(others=>'0'));
        signal ovDigest : tDwordArray(0 to 7) := (others=>(others=>'0'));
 
 
        -- Add your code here ...
        -- Add your code here ...
 
        constant cREG_CLK_PERIOD : time := 30 ns; -- 33M Register Clock
 
        constant cPROC_CLK_PERIOD : time := 10 ns; -- 100M Processing Clock
 
        constant cRESET_INTERVAL : time := 71 ns;
 
        constant cSTRAT_TEST : integer := 25;
 
 
        constant cCMD_ADDR : std_logic_vector(3 downto 0) := X"D";
        constant cCMD_ADDR : std_logic_vector(3 downto 0) := X"D";
        constant cCMD_IDLE : std_logic_vector(15 downto 0) := X"0000";
        constant cCMD_NOP : std_logic_vector(15 downto 0) := X"0000";
        constant cCMD_RESET : std_logic_vector(15 downto 0) := X"CAFE";
 
        constant cCMD_START : std_logic_vector(15 downto 0) := X"0001";
        constant cCMD_START : std_logic_vector(15 downto 0) := X"0001";
 
 
        signal svWork : tDwordArray(0 to 31) := (others=>(others=>'0'));
        signal svWork : tDwordArray(0 to 31) := (others=>(others=>'0'));
 
 
        signal siWriteCnt : std_logic_vector(31 downto 0) := (others => '0');
        signal svWriteCnt : std_logic_vector(31 downto 0) := (others => '0');
 
 
        signal sHashMidStateValidIn : std_logic := '0';
        signal sHashMidStateValidIn : std_logic := '0';
        signal sHashMidStateValidOut : std_logic := '0';
        signal sHashMidStateValidOut : std_logic := '0';
        signal svHashMidStateDataOut : tDwordArray(0 to 7) := (others=>(others=>'0'));
        signal svHashMidStateDataOut : tDwordArray(0 to 7) := (others=>(others=>'0'));
        signal svMidState : tDwordArray(0 to 7) := (others=>(others=>'0'));
        signal svMidState : tDwordArray(0 to 7) := (others=>(others=>'0'));
Line 114... Line 149...
                        iClkProcess => iClkProcess,
                        iClkProcess => iClkProcess,
                        iRst_async => iRst_async,
                        iRst_async => iRst_async,
                        iValid_p => iValid_p,
                        iValid_p => iValid_p,
                        ivAddr => ivAddr,
                        ivAddr => ivAddr,
                        ivData => ivData,
                        ivData => ivData,
                        oReachEnd => oReachEnd,
                        oReachEnd_p => oReachEnd_p,
                        oFoundNonce => oFoundNonce,
                        oFoundNonce_p => oFoundNonce_p,
                        ovNonce => ovNonce,
                        ovNonce => ovNonce,
                        ovDigest => ovDigest
                        ovDigest => ovDigest
                );
                );
 
 
        -- Add your stimulus here ...
        -- Add your stimulus here ...
 
 
        iClkReg <= not iClkReg after 5 ns;
        iClkReg <= not iClkReg after (cREG_CLK_PERIOD / 2);
        iClkProcess <= not iClkProcess after 5 ns;
        iClkProcess <= not iClkProcess after (cPROC_CLK_PERIOD / 2);
        iRst_async <= '0' after 71 ns;
        iRst_async <= '0' after cRESET_INTERVAL;
 
 
        svWork(0) <= X"02000000" after 251 ns;
        -- This test vector is derive from block 266243, notice the endianess changment of converting JSON data to test vector
        svWork(1) <= X"ea144059" after 251 ns;
        -- blockId: 266243
        svWork(2) <= X"2a8b0d36" after 251 ns;
        -- blockHash: 000000000000000399572203a6035acb2d68944c9c047435a5e9f11d40daa4ee
        svWork(3) <= X"b2e5f8a4" after 251 ns;
        -- merkleroot: 0e4cdeacdeaee092dcbb702887e323a036f6bd60d003448e965528adb5ffdf11
        svWork(4) <= X"85db1c04" after 251 ns;
        -- nonce: 3064385291
        svWork(5) <= X"ca9290ca" after 251 ns;
        -- previousblockhash: 0000000000000005f2c7bd05ca9092ca041cdb85a4f8e5b2360d8b2a594014ea
        svWork(6) <= X"05bdc7f2" after 251 ns;
        -- hash: 000000000000000399572203a6035acb2d68944c9c047435a5e9f11d40daa4ee
        svWork(7) <= X"05000000" after 251 ns;
        -- version: 2
        svWork(8) <= X"00000000" after 251 ns;
        -- height: 266243
        svWork(9) <= X"11dfffb5" after 251 ns;
        -- difficulty: 390928787.63808584
        svWork(10) <= X"ad285596" after 251 ns;
        -- confirmations: 1
        svWork(11) <= X"8e4403d0" after 251 ns;
        -- time: 1382820355
        svWork(12) <= X"60bdf636" after 251 ns;
        -- bits: 190afc85
        svWork(13) <= X"a023e387" after 251 ns;
        -- size: 227682
        svWork(14) <= X"2870bbdc" after 251 ns;
        svWork(0) <= X"02000000" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
        svWork(15) <= X"92e0aede" after 251 ns;
        svWork(1) <= X"ea144059" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
        svWork(16) <= X"acde4c0e" after 251 ns;
        svWork(2) <= X"2a8b0d36" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
        svWork(17) <= X"032A6C52" after 251 ns;
        svWork(3) <= X"b2e5f8a4" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
        svWork(18) <= X"85fc0a19" after 251 ns;
        svWork(4) <= X"85db1c04" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
        svWork(19) <= X"0BCFA6B6" after 251 ns;
        svWork(5) <= X"ca9290ca" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(6) <= X"05bdc7f2" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(7) <= X"05000000" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(8) <= X"00000000" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(9) <= X"11dfffb5" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(10) <= X"ad285596" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(11) <= X"8e4403d0" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(12) <= X"60bdf636" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(13) <= X"a023e387" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(14) <= X"2870bbdc" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(15) <= X"92e0aede" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
 
 
        svWork(16) <= X"acde4c0e" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(17) <= X"032A6C52" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(18) <= X"85fc0a19" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
        svWork(19) <= X"0BCFA6B6" after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns);
 
 
 
 
        process(iClkReg, iRst_async)
        process(iClkReg, iRst_async)
        begin
        begin
                if iRst_async = '1' then
                if iRst_async = '1' then
                        siWriteCnt <= (others => '0');
                        svWriteCnt <= (others => '0');
                        iValid_p <= '0';
                        iValid_p <= '0';
                elsif rising_edge(iClkReg) then
                elsif rising_edge(iClkReg) then
                        if sMidStateValid = '1' then
                        if sMidStateValid = '1' then
                                siWriteCnt <= siWriteCnt + '1';
                                svWriteCnt <= svWriteCnt + '1';
                        end if;
                        end if;
 
 
                        if siWriteCnt(3 downto 0) = X"F" and siWriteCnt(15 downto 4) <= conv_std_logic_vector(13, 12) then
                        if svWriteCnt(3 downto 0) = X"F" and svWriteCnt(15 downto 4) <= conv_std_logic_vector(13, 12) then
                                iValid_p <= '1';
                                iValid_p <= '1';
                        else
                        else
                                iValid_p <= '0';
                                iValid_p <= '0';
                        end if;
                        end if;
                end if;
                end if;
Line 172... Line 222...
        begin
        begin
                if iRst_async = '1' then
                if iRst_async = '1' then
                        ivAddr <= (others=>'0');
                        ivAddr <= (others=>'0');
                        ivData <= (others=>'0');
                        ivData <= (others=>'0');
                elsif rising_edge(iClkReg) then
                elsif rising_edge(iClkReg) then
                        if siWriteCnt(3 downto 0) = X"F" then
                        if svWriteCnt(3 downto 0) = X"F" then
                                case siWriteCnt(15 downto 4) is
                                case svWriteCnt(15 downto 4) is
                                        when X"000" =>
                                        when X"000" =>
                                        ivAddr <= X"0";
                                        ivAddr <= X"0";
                                        ivData <= svMidState(0);
                                        ivData <= svMidState(0);
 
 
                                        when X"001" =>
                                        when X"001" =>
Line 224... Line 274...
                                        ivAddr <= X"B";
                                        ivAddr <= X"B";
                                        ivData <= svWork(19) - X"20";
                                        ivData <= svWork(19) - X"20";
 
 
                                        when X"00C" =>
                                        when X"00C" =>
                                        ivAddr <= X"C";
                                        ivAddr <= X"C";
                                        ivData <= svWork(19); -- + X"02";
                                        ivData <= svWork(19) + X"20";
 
 
                                        when X"00D" =>
                                        when X"00D" =>
                                        ivAddr <= cCMD_ADDR;
                                        ivAddr <= cCMD_ADDR;
                                        ivData <= X"0000" & cCMD_START;
                                        ivData <= X"0000" & cCMD_START;
 
 
                                        when others =>
                                        when others =>
                                        ivAddr <= cCMD_ADDR;
                                        ivAddr <= cCMD_ADDR;
                                        ivData <= X"0000" & cCMD_IDLE;
                                        ivData <= X"0000" & cCMD_NOP;
                                end case;
                                end case;
                        end if;
                        end if;
                end if;
                end if;
        end process;
        end process;
 
 
 
 
        sHashMidStateValidIn <= '1' after 251 ns, '0' after 261 ns;
        sHashMidStateValidIn <= '1' after (cSTRAT_TEST * cPROC_CLK_PERIOD + 1 ns), '0' after (cSTRAT_TEST * cPROC_CLK_PERIOD + cPROC_CLK_PERIOD + 1 ns);
 
 
        sha_256_chunk_inst_HashMidState : sha_256_chunk
        sha_256_chunk_inst_HashMidState : sha_256_chunk
                generic map(
                generic map(
                        gMSG_IS_CONSTANT => (others=>'0'),
                        gMSG_IS_CONSTANT => (others=>'0'),
                        gH_IS_CONST => (others=>'1'),
                        gH_IS_CONST => (others=>'1'),
                        gBASE_DELAY => gBASE_DELAY
                        gBASE_DELAY => gBASE_DELAY,
 
                        gOUT_VALID_GEN => true
                )
                )
                port map (
                port map (
                        iClk => iClkProcess,
                        iClk => iClkProcess,
                        iRst_async => iRst_async,
                        iRst_async => iRst_async,
                        iValid => sHashMidStateValidIn,
                        iValid => sHashMidStateValidIn,
Line 270... Line 321...
                        ovH2 => svHashMidStateDataOut(2),
                        ovH2 => svHashMidStateDataOut(2),
                        ovH3 => svHashMidStateDataOut(3),
                        ovH3 => svHashMidStateDataOut(3),
                        ovH4 => svHashMidStateDataOut(4),
                        ovH4 => svHashMidStateDataOut(4),
                        ovH5 => svHashMidStateDataOut(5),
                        ovH5 => svHashMidStateDataOut(5),
                        ovH6 => svHashMidStateDataOut(6),
                        ovH6 => svHashMidStateDataOut(6),
                        ovH7 => svHashMidStateDataOut(7)
                        ovH7 => svHashMidStateDataOut(7),
                );
 
 
 
        pipelines_without_reset_Valid : pipelines_without_reset
                        oValid => sHashMidStateValidOut
                GENERIC map(gBUS_WIDTH => 1, gNB_PIPELINES => (64 * gBASE_DELAY + 1))
 
                PORT map(
 
                        iClk => iClkProcess,
 
                        iInput => sHashMidStateValidIn,
 
                        ivInput => (others=>'0'),
 
                        oDelayed_output => sHashMidStateValidOut,
 
                        ovDelayed_output => open
 
                );
                );
 
 
 
--      pipelines_without_reset_Valid : pipelines_without_reset
 
--              GENERIC map(gBUS_WIDTH => 1, gNB_PIPELINES => (64 * gBASE_DELAY + 1))
 
--              PORT map(
 
--                      iClk => iClkProcess,
 
--                      iInput => sHashMidStateValidIn,
 
--                      ivInput => (others=>'0'),
 
--                      oDelayed_output => sHashMidStateValidOut,
 
--                      ovDelayed_output => open
 
--              );
 
 
        process(iClkProcess)
        process(iClkProcess)
        begin
        begin
                if rising_edge(iClkProcess) then
                if rising_edge(iClkProcess) then
                        if sHashMidStateValidOut = '1' then
                        if sHashMidStateValidOut = '1' then
                                svMidState <= svHashMidStateDataOut;
                                svMidState <= svHashMidStateDataOut;

powered by: WebSVN 2.1.0

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