| 1 |
4 |
doru |
-- <File header>
|
| 2 |
|
|
-- Project
|
| 3 |
|
|
-- pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
|
| 4 |
|
|
-- AVR core, but about 3x faster in terms of both clock frequency and MIPS.
|
| 5 |
|
|
-- The increase in speed comes from a relatively deep pipeline. The original
|
| 6 |
|
|
-- AVR core has only two pipeline stages (fetch and execute), while pAVR has
|
| 7 |
|
|
-- 6 pipeline stages:
|
| 8 |
|
|
-- 1. PM (read Program Memory)
|
| 9 |
|
|
-- 2. INSTR (load Instruction)
|
| 10 |
|
|
-- 3. RFRD (decode Instruction and read Register File)
|
| 11 |
|
|
-- 4. OPS (load Operands)
|
| 12 |
|
|
-- 5. ALU (execute ALU opcode or access Unified Memory)
|
| 13 |
|
|
-- 6. RFWR (write Register File)
|
| 14 |
|
|
-- Version
|
| 15 |
|
|
-- 0.32
|
| 16 |
|
|
-- Date
|
| 17 |
|
|
-- 2002 August 07
|
| 18 |
|
|
-- Author
|
| 19 |
|
|
-- Doru Cuturela, doruu@yahoo.com
|
| 20 |
|
|
-- License
|
| 21 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 22 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 23 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
| 24 |
|
|
-- (at your option) any later version.
|
| 25 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 26 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 27 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 28 |
|
|
-- GNU General Public License for more details.
|
| 29 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 30 |
|
|
-- along with this program; if not, write to the Free Software
|
| 31 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 32 |
|
|
-- </File header>
|
| 33 |
|
|
|
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
|
|
-- <File info>
|
| 37 |
|
|
-- Test pAVR's ALU.
|
| 38 |
|
|
-- Note that the ALU is an asynchronous device.
|
| 39 |
|
|
-- Check ALU output and flags output for all ALU opcodes, one by one, for all of
|
| 40 |
|
|
-- these situations:
|
| 41 |
|
|
-- - carry in = 0
|
| 42 |
|
|
-- - carry in = 1
|
| 43 |
|
|
-- - additions generate overflow
|
| 44 |
|
|
-- - substractions generate overflow
|
| 45 |
|
|
-- There are 26 ALU opcodes to be checked for each situation.
|
| 46 |
|
|
-- </File info>
|
| 47 |
|
|
|
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
-- <File body>
|
| 51 |
|
|
library ieee;
|
| 52 |
|
|
use ieee.std_logic_1164.all;
|
| 53 |
|
|
library work;
|
| 54 |
|
|
use work.std_util.all;
|
| 55 |
|
|
use work.pavr_util.all;
|
| 56 |
|
|
use work.pavr_constants.all;
|
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
entity test_alu is
|
| 60 |
|
|
end;
|
| 61 |
|
|
|
| 62 |
|
|
|
| 63 |
|
|
architecture test_alu_arch of test_alu is
|
| 64 |
|
|
signal clk: std_logic;
|
| 65 |
|
|
-- ALU inputs
|
| 66 |
|
|
signal alu_op1: std_logic_vector(15 downto 0);
|
| 67 |
|
|
signal alu_op2: std_logic_vector(7 downto 0);
|
| 68 |
|
|
signal alu_opcode: std_logic_vector(pavr_alu_opcode_w - 1 downto 0);
|
| 69 |
|
|
signal alu_flagsin: std_logic_vector(5 downto 0);
|
| 70 |
|
|
-- ALU outputs
|
| 71 |
|
|
signal alu_out: std_logic_vector(15 downto 0);
|
| 72 |
|
|
signal alu_flagsout: std_logic_vector(5 downto 0);
|
| 73 |
|
|
|
| 74 |
|
|
-- Declare the ALU.
|
| 75 |
|
|
component pavr_alu
|
| 76 |
|
|
port(
|
| 77 |
|
|
pavr_alu_op1: in std_logic_vector(15 downto 0);
|
| 78 |
|
|
pavr_alu_op2: in std_logic_vector(7 downto 0);
|
| 79 |
|
|
pavr_alu_out: out std_logic_vector(15 downto 0);
|
| 80 |
|
|
pavr_alu_opcode: in std_logic_vector(pavr_alu_opcode_w - 1 downto 0);
|
| 81 |
|
|
pavr_alu_flagsin: in std_logic_vector(5 downto 0);
|
| 82 |
|
|
pavr_alu_flagsout: out std_logic_vector(5 downto 0)
|
| 83 |
|
|
);
|
| 84 |
|
|
end component;
|
| 85 |
|
|
for all: pavr_alu use entity work.pavr_alu(pavr_alu_arch);
|
| 86 |
|
|
|
| 87 |
|
|
begin
|
| 88 |
|
|
|
| 89 |
|
|
-- Instantiate the ALU.
|
| 90 |
|
|
pavr_alu_instance1: pavr_alu
|
| 91 |
|
|
port map(
|
| 92 |
|
|
alu_op1,
|
| 93 |
|
|
alu_op2,
|
| 94 |
|
|
alu_out,
|
| 95 |
|
|
alu_opcode,
|
| 96 |
|
|
alu_flagsin,
|
| 97 |
|
|
alu_flagsout
|
| 98 |
|
|
);
|
| 99 |
|
|
|
| 100 |
|
|
|
| 101 |
|
|
generate_clock:
|
| 102 |
|
|
process
|
| 103 |
|
|
begin
|
| 104 |
|
|
clk <= '1';
|
| 105 |
|
|
wait for 50 ns;
|
| 106 |
|
|
clk <= '0';
|
| 107 |
|
|
wait for 50 ns;
|
| 108 |
|
|
end process generate_clock;
|
| 109 |
|
|
|
| 110 |
|
|
|
| 111 |
|
|
test_main:
|
| 112 |
|
|
process
|
| 113 |
|
|
begin
|
| 114 |
|
|
wait for 10 ns;
|
| 115 |
|
|
|
| 116 |
|
|
-- For each of the following test patterns, check each of:
|
| 117 |
|
|
-- - input 1, input 2, flags input
|
| 118 |
|
|
-- - output, flags output
|
| 119 |
|
|
|
| 120 |
|
|
-- Test ALU output, for all ALU opcodes; carry in = 1.
|
| 121 |
|
|
for i in 0 to 25 loop
|
| 122 |
|
|
alu_op1 <= int_to_std_logic_vector(16#44F9#, alu_op1'length);
|
| 123 |
|
|
alu_op2 <= int_to_std_logic_vector(16#0A#, alu_op2'length);
|
| 124 |
|
|
alu_opcode <= int_to_std_logic_vector(i, alu_opcode'length);
|
| 125 |
|
|
alu_flagsin <= "000001";
|
| 126 |
|
|
wait until clk'event and clk='1';
|
| 127 |
|
|
end loop;
|
| 128 |
|
|
|
| 129 |
|
|
-- Test ALU output, for all ALU opcodes; carry in = 0.
|
| 130 |
|
|
for i in 0 to 25 loop
|
| 131 |
|
|
alu_op1 <= int_to_std_logic_vector(16#44F5#, alu_op1'length);
|
| 132 |
|
|
alu_op2 <= int_to_std_logic_vector(16#03#, alu_op2'length);
|
| 133 |
|
|
alu_opcode <= int_to_std_logic_vector(i, alu_opcode'length);
|
| 134 |
|
|
alu_flagsin <= "000000";
|
| 135 |
|
|
wait until clk'event and clk='1';
|
| 136 |
|
|
end loop;
|
| 137 |
|
|
|
| 138 |
|
|
-- Test ALU output, for all ALU opcodes; carry in = 1. Additions (on both 8 bits and 16 bits) will generate carry out = 1.
|
| 139 |
|
|
for i in 0 to 25 loop
|
| 140 |
|
|
alu_op1 <= int_to_std_logic_vector(16#FFF8#, alu_op1'length);
|
| 141 |
|
|
alu_op2 <= int_to_std_logic_vector(16#0C#, alu_op2'length);
|
| 142 |
|
|
alu_opcode <= int_to_std_logic_vector(i, alu_opcode'length);
|
| 143 |
|
|
alu_flagsin <= "000001";
|
| 144 |
|
|
wait until clk'event and clk='1';
|
| 145 |
|
|
end loop;
|
| 146 |
|
|
|
| 147 |
|
|
-- Test ALU output, for all ALU opcodes; carry in = 1. Substractions (on both 8 bits and 16 bits) will generate carry out = 1.
|
| 148 |
|
|
for i in 0 to 25 loop
|
| 149 |
|
|
alu_op1 <= int_to_std_logic_vector(16#0005#, alu_op1'length);
|
| 150 |
|
|
alu_op2 <= int_to_std_logic_vector(16#0C#, alu_op2'length);
|
| 151 |
|
|
alu_opcode <= int_to_std_logic_vector(i, alu_opcode'length);
|
| 152 |
|
|
alu_flagsin <= "000001";
|
| 153 |
|
|
wait until clk'event and clk='1';
|
| 154 |
|
|
end loop;
|
| 155 |
|
|
|
| 156 |
|
|
end process test_main;
|
| 157 |
|
|
|
| 158 |
|
|
end;
|
| 159 |
|
|
-- </File body>
|