1
0
mirror of https://github.com/j-core/j-core-ice40.git synced 2026-05-01 22:05:45 +00:00

With Lattice SPR memory, and memory test. Doesn't synth correctly, sim is correct.

This commit is contained in:
J
2019-03-25 21:50:49 -04:00
parent 520a01319c
commit d21f78598e
12 changed files with 781 additions and 329 deletions

54
cpu_bulk_sram.vhd Normal file
View File

@@ -0,0 +1,54 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.cpu2j0_pack.all;
entity cpu_bulk_sram is
port (
clk : in std_logic;
ibus_i : in cpu_instruction_o_t;
ibus_o : out cpu_instruction_i_t;
db_i : in cpu_data_o_t;
db_o : out cpu_data_i_t
);
end;
architecture struc of cpu_bulk_sram is
signal db_we : std_logic_vector(3 downto 0);
signal rd : std_logic_vector(31 downto 0);
signal ra : std_logic_vector(16 downto 2);
signal en : std_logic;
signal iclk : std_logic;
begin
db_we <= (db_i.wr and db_i.we(3)) &
(db_i.wr and db_i.we(2)) &
(db_i.wr and db_i.we(1)) &
(db_i.wr and db_i.we(0));
ra <= db_i.a(16 downto 2) when db_i.en = '1' else ibus_i.a(16 downto 2);
-- clk memory on negative edge to avoid wait states
iclk <= not clk;
en <= db_i.en or ibus_i.en;
r : entity work.bulk_ram
generic map (ADDR_WIDTH => 17)
port map(clk => iclk,
en => en,
we => db_we,
addr => ra,
di => db_i.d,
do => rd);
-- (too) simple output mux
db_o.d <= rd;
ibus_o.d <= rd(31 downto 16) when ibus_i.a(1) = '0' else rd(15 downto 0);
-- simply ack immediately. Should this simulate different delays?
db_o.ack <= db_i.en;
ibus_o.ack <= ibus_i.en when db_i.en = '0' else '0';
end architecture struc;

View File

@@ -13,7 +13,6 @@ use sb_ice40_components_syn.components.all;
entity cpu_up5k is port (
x : inout std_logic_vector(6 downto 1);
x1 : inout std_logic_vector(7 downto 0);
y : inout std_logic_vector(7 downto 1);
pon : inout std_logic;
mfcs: inout std_logic;
@@ -23,6 +22,7 @@ entity cpu_up5k is port (
mso : inout std_logic;
mio2: inout std_logic;
mio3: inout std_logic;
x1 : inout std_logic_vector(7 downto 0);
lcs : inout std_logic;
la0 : inout std_logic;
lscl : inout std_logic;
@@ -40,6 +40,19 @@ architecture behaviour of cpu_up5k is
return r;
end function to_open_drain;
function to_hex_string(s: in std_logic_vector) return string is
constant hex : string (1 to 16) := "0123456789ABCDEF";
variable ss : std_logic_vector(31 downto 0) := (others => '0');
variable ret : string (1 to ss'left/4+1);
begin
ss(s'range) := s;
for i in 0 to ss'left/4 loop
ret(i+1) := hex(to_integer(unsigned(ss(ss'left - i*4 downto ss'left - i*4 -3)))+1);
end loop;
return ret;
end to_hex_string;
type instrd_bus_i_t is array(instr_bus_device_t'left to instr_bus_device_t'right) of cpu_data_i_t;
type instrd_bus_o_t is array(instr_bus_device_t'left to instr_bus_device_t'right) of cpu_data_o_t;
@@ -124,7 +137,7 @@ begin
-- data_slaves_i(DEV_SPI) <= loopback_bus(data_slaves_o(DEV_SPI));
data_slaves_i(DEV_UART0) <= loopback_bus(data_slaves_o(DEV_UART0));
data_slaves_i(DEV_DDR) <= loopback_bus(data_slaves_o(DEV_DDR));
-- data_slaves_i(DEV_DDR) <= loopback_bus(data_slaves_o(DEV_DDR));
-- Keyboard readback
pio_data_i.d(31 downto 8) <= (others => '0');
@@ -146,8 +159,8 @@ begin
INSERT when "10",
CONTINUE when others;
splice_instr_data_bus(instr_slaves_o(DEV_DDR), instr_slaves_i(DEV_DDR),
instrd_slaves_o(DEV_DDR), instrd_slaves_i(DEV_DDR));
-- splice_instr_data_bus(instr_slaves_o(DEV_DDR), instr_slaves_i(DEV_DDR),
-- instrd_slaves_o(DEV_DDR), instrd_slaves_i(DEV_DDR));
cpu1: cpu
port map(clk => clk, rst => rst,
@@ -163,6 +176,13 @@ begin
db_i => data_slaves_o(DEV_SRAM),
db_o => data_slaves_i(DEV_SRAM));
bram : entity work.cpu_bulk_sram
port map(clk => clk,
ibus_i => instr_slaves_o(DEV_DDR),
ibus_o => instr_slaves_i(DEV_DDR),
db_i => data_slaves_o(DEV_DDR),
db_o => data_slaves_i(DEV_DDR));
lcd : disp_drv port map (clk => clk, rst => rst, a => lcd_d_i, y => lcd_d_o, yl => lcd_o);
lcd_d_i.d <= data_slaves_o(DEV_SPI).d;
lcd_d_i.a <= data_slaves_o(DEV_SPI).a(3 downto 2);
@@ -201,19 +221,41 @@ begin
x <= to_open_drain(pio_data_o.d(5 downto 0));
end if;
x1 <= pio_data_o.d(7 downto 0);
-- x1 <= x"55"; -- pio_data_o.d(7 downto 0);
end if;
if data_slaves_o(DEV_UART0).wr = '1' and data_slaves_o(DEV_UART0).a = x"ABCD0104" then
-- c := character'val(to_integer(unsigned(data_slaves_o(DEV_UART0).d(7 downto 0))));
-- if character'pos(c) = 10 then -- newline
-- writeline(output, uart_line);
-- else
-- write(uart_line, c);
-- if c = ';' then
-- hack to better display the gdb remote protocol messages
-- writeline(output, uart_line);
-- end if;
-- end if;
c := character'val(to_integer(unsigned(data_slaves_o(DEV_UART0).d(7 downto 0))));
if character'pos(c) = 10 then -- newline
writeline(output, uart_line);
else
write(uart_line, c);
if c = ';' then
-- hack to better display the gdb remote protocol messages
writeline(output, uart_line);
end if;
end if;
end if;
if data_slaves_o(DEV_DDR).en = '1' then
if data_slaves_o(DEV_DDR).wr = '1' then
write(l, string'("SPRAM: Write:"));
write(l, to_hex_string(data_slaves_o(DEV_DDR).a));
write(l, string'(" <= "));
write(l, to_hex_string(data_slaves_o(DEV_DDR).d));
write(l, string'(" "));
if data_slaves_o(DEV_DDR).we(3) = '1' then write(l, string'("1")); else write(l, string'("0")); end if;
if data_slaves_o(DEV_DDR).we(2) = '1' then write(l, string'("1")); else write(l, string'("0")); end if;
if data_slaves_o(DEV_DDR).we(1) = '1' then write(l, string'("1")); else write(l, string'("0")); end if;
if data_slaves_o(DEV_DDR).we(0) = '1' then write(l, string'("1")); else write(l, string'("0")); end if;
else
write(l, string'("SPRAM: Read :"));
write(l, to_hex_string(data_slaves_o(DEV_DDR).a));
write(l, string'(" => "));
write(l, to_hex_string(data_slaves_i(DEV_DDR).d));
end if;
writeline(output, l);
end if;
end if;
end process;

View File

@@ -1,31 +1,36 @@
set_io x[1] 42
set_io x[2] 38
set_io x[3] 37
set_io x[4] 36
set_io x[5] 35
set_io x[6] 34
#set_io x[1] 42
#set_io x[2] 38
#set_io x[3] 37
#set_io x[4] 36
#set_io x[5] 35
#set_io x[6] 34
#
#set_io y[1] 32
#set_io y[2] 31
#set_io y[3] 28
#set_io y[4] 27
#set_io y[5] 26
#set_io y[6] 25
#set_io y[7] 23
#
#set_io pon 43
#
#set_io lcs 21
#set_io lscl 19
#set_io lsi 18
#set_io la0 20
#
set_io lcs 45
set_io lscl 47
set_io lsi 46
set_io la0 2
set_io y[1] 32
set_io y[2] 31
set_io y[3] 28
set_io y[4] 27
set_io y[5] 26
set_io y[6] 25
set_io y[7] 23
set_io x1[0] 26
set_io x1[1] 27
set_io x1[2] 32
set_io x1[3] 35
set_io x1[4] 31
set_io x1[5] 37
set_io x1[6] 34
set_io x1[7] 43
set_io pon 43
set_io lcs 21
set_io lscl 19
set_io lsi 18
set_io la0 20
set_io mfcs 16
set_io msck 15
set_io msi 17
set_io mso 14
set_io mrcs 6
set_io mio2 11
set_io mio3 12

View File

@@ -4,7 +4,7 @@ rm *.o *.cf
ghdl -a cpu2j0_pkg.vhd components_pkg.vhd mult_pkg.vhd decode_pkg.vhd decode_body.vhd datapath_pkg.vhd cpu.vhd decode.vhd decode_core.vhd decode_table.vhd decode_table_reverse.vhd datapath.vhd register_file_sync.vhd mult.vhd
ghdl -a data_bus_pkg.vhd monitor_pkg.vhd ram_init.vhd lattice_ebr.vhd bus_monitor.vhd timeout_cnt.vhd cpu_simple_sram.vhd
ghdl -a data_bus_pkg.vhd monitor_pkg.vhd ram_init.vhd lattice_ebr.vhd lattice_spr.vhd bus_monitor.vhd timeout_cnt.vhd cpu_simple_sram.vhd cpu_bulk_sram.vhd
ghdl -a --work=sb_ice40_components_syn clk_sim.vhd

51
lattice_spr.vhd Normal file
View File

@@ -0,0 +1,51 @@
-- A simple non initalized bulk RAM.
-- single 32 bit read/write port.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity bulk_ram is
generic (
-- 32-bit read/write port. ADDR_WIDTH is in bytes, not words.
ADDR_WIDTH : integer := 17 -- default 128k
);
port (
clk : in std_logic;
en : in std_logic;
addr : in std_logic_vector(ADDR_WIDTH - 3 downto 0);
do : out std_logic_vector(31 downto 0);
we : in std_logic_vector(3 downto 0);
di : in std_logic_vector(31 downto 0)
);
end bulk_ram;
architecture behavioral of bulk_ram is
constant NUM_WORDS : integer := 2**(ADDR_WIDTH - 2);
type ram_t is array (0 to NUM_WORDS-1) of std_logic_vector(31 downto 0);
signal ram : ram_t;
begin
process (clk, en)
begin
if clk'event and clk = '1' and en = '1' then
if we = "0000" then
do <= ram(to_integer(unsigned(addr)));
else
if we(3) = '1' then
ram(to_integer(unsigned(addr)))(31 downto 24) <= di(31 downto 24);
end if;
if we(2) = '1' then
ram(to_integer(unsigned(addr)))(23 downto 16) <= di(23 downto 16);
end if;
if we(1) = '1' then
ram(to_integer(unsigned(addr)))(15 downto 8 ) <= di(15 downto 8 );
end if;
if we(0) = '1' then
ram(to_integer(unsigned(addr)))(7 downto 0 ) <= di(7 downto 0 );
end if;
end if;
end if;
end process;
end behavioral;

72
lattice_spr_wrap.vhd Normal file
View File

@@ -0,0 +1,72 @@
-- A simple non initalized bulk RAM.
-- single 32 bit read/write port.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity bulk_ram is
generic (
-- 32-bit read/write port. ADDR_WIDTH is in bytes, not words.
ADDR_WIDTH : integer := 17 -- default 128k
);
port (
clk : in std_logic;
en : in std_logic;
addr : in std_logic_vector(ADDR_WIDTH - 3 downto 0);
do : out std_logic_vector(31 downto 0);
we : in std_logic_vector(3 downto 0);
di : in std_logic_vector(31 downto 0)
);
end bulk_ram;
architecture behavioral of bulk_ram is
component SB_SPRAM256KA is
Port ( CLOCK : in std_logic ;
ADDRESS : in std_logic_vector(13 downto 0);
DATAIN : in std_logic_vector(15 downto 0);
MASKWREN : in std_logic_vector(3 downto 0);
WREN : in std_logic;
CHIPSELECT: in std_logic ;
STANDBY : in std_logic := 'L' ;
SLEEP : in std_logic := 'L' ;
POWEROFF: in std_logic := 'H' ; -- Note : 1'b0 to POWEROFF RAM , 1'b1 to POWERON RAM block at wrapper level.
DATAOUT : out std_logic_vector(15 downto 0)
);
end component;
signal wren : std_logic;
signal cs0, cs1 : std_logic;
signal rd0 : std_logic_vector(31 downto 0);
signal rd1 : std_logic_vector(31 downto 0);
begin
cs0 <= en and not addr(14);
cs1 <= en and addr(14);
wren <= we(3) or we(2) or we(1) or we(0);
r0 : SB_SPRAM256KA port map (clock => clk, address => addr(13 downto 0), datain => di(31 downto 16),
maskwren => we(3) & we(3) & we(2) & we(2),
wren => wren, chipselect => cs0, dataout => rd0(31 downto 16),
standby => '0', sleep => '0', poweroff => '1');
r1 : SB_SPRAM256KA port map (clock => clk, address => addr(13 downto 0), datain => di(15 downto 0),
maskwren => we(1) & we(1) & we(0) & we(0),
wren => wren, chipselect => cs0, dataout => rd0(15 downto 0),
standby => '0', sleep => '0', poweroff => '1');
r2 : SB_SPRAM256KA port map (clock => clk, address => addr(13 downto 0), datain => di(31 downto 16),
maskwren => we(3) & we(3) & we(2) & we(2),
wren => wren, chipselect => cs1, dataout => rd1(31 downto 16),
standby => '0', sleep => '0', poweroff => '1');
r3 : SB_SPRAM256KA port map (clock => clk, address => addr(13 downto 0), datain => di(15 downto 0),
maskwren => we(1) & we(1) & we(0) & we(0),
wren => wren, chipselect => cs1, dataout => rd1(15 downto 0),
standby => '0', sleep => '0', poweroff => '1');
do <= rd0 when addr(14) = '0' else rd1;
end behavioral;

BIN
ram.img

Binary file not shown.

View File

@@ -6,70 +6,73 @@ use ieee.numeric_std.all;
package bootrom is
type rom_t is array (0 to 2047) of std_logic_vector(31 downto 0);
constant rom : rom_t := (
x"000003dc",
x"000004ac",
x"00001ffc",
x"000003dc",
x"000004ac",
x"00001ffc",
x"00001012",
x"00000ff2",
x"00001012",
x"00000ff2",
x"00000ff2",
x"00001022",
x"00001022",
x"00001002",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000fb4",
x"00000fca",
x"00000fe6",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"00000ff2",
x"0000124e",
x"0000122e",
x"0000124e",
x"0000122e",
x"0000122e",
x"0000125e",
x"0000125e",
x"0000123e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"000011f0",
x"00001206",
x"00001222",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"0000122e",
x"d1012142",
x"000b0009",
x"abcd0000",
x"2f866843",
x"2f962fa6",
x"d9094f22",
@@ -82,22 +85,31 @@ package bootrom is
x"60804f26",
x"6af669f6",
x"000b68f6",
x"00001320",
x"92197ffc",
x"d10c2122",
x"0000155c",
x"2f869223",
x"d1124f22",
x"21227ffc",
x"e1002f12",
x"e26361f2",
x"e20961f2",
x"31278904",
x"61f27101",
x"2f12aff8",
x"0009d106",
x"0009d80c",
x"d40c480b",
x"0009d109",
x"e2002122",
x"6012c97f",
x"887f89fb",
x"9203d102",
x"2122000b",
x"7f0400c0",
x"d408480b",
x"00099205",
x"d1032122",
x"7f044f26",
x"000b68f6",
x"00c00009",
x"abcd0000",
x"0000010c",
x"00001638",
x"00001644",
x"92317ffc",
x"d1182122",
x"e1002f12",
@@ -138,7 +150,7 @@ package bootrom is
x"73fce000",
x"8068d001",
x"000b68f6",
x"000017e0",
x"00001ac8",
x"d1036012",
x"c8018bfc",
x"d1012142",
@@ -165,7 +177,7 @@ package bootrom is
x"4f2669f6",
x"412b68f6",
x"00b00009",
x"00000228",
x"00000258",
x"2f86e700",
x"2f966943",
x"2fa62fb6",
@@ -196,31 +208,43 @@ package bootrom is
x"4f266bf6",
x"6af669f6",
x"412b68f6",
x"000013b0",
x"00000214",
x"0000165c",
x"00000244",
x"2f862f96",
x"d0234f22",
x"d823400b",
x"7ffcd423",
x"2fa6d84b",
x"918bd04b",
x"4f222812",
x"400b7ffc",
x"9186e600",
x"e5032812",
x"d847d448",
x"480b0009",
x"d422480b",
x"0009e100",
x"d8219938",
x"2f1260f2",
x"018c611c",
x"31908d0a",
x"e50160f2",
x"d11d048c",
x"88ff8f0f",
x"e601d445",
x"480be503",
x"88ff8f0c",
x"e602d442",
x"480be503",
x"88ff8d07",
x"e8509870",
x"a005e100",
x"986ea002",
x"e100986c",
x"e100d93c",
x"9a6a2f12",
x"60f2019c",
x"611c31a0",
x"890960f2",
x"d138049c",
x"410b644c",
x"61f27101",
x"2f12aff0",
x"0009d11a",
x"410be400",
x"d119d41a",
x"410be807",
x"e100d919",
x"2f1261f2",
x"31878918",
x"2f12aff1",
x"0009d135",
x"d435410b",
x"e907e100",
x"da342f12",
x"61f23197",
x"8d19e100",
x"66f2e101",
x"67f26413",
x"62f27708",
@@ -230,21 +254,49 @@ package bootrom is
x"426d247b",
x"242b6233",
x"7218412d",
x"490b241b",
x"4a0b241b",
x"61f27101",
x"2f12afe4",
x"0009affe",
x"000900ff",
x"00001380",
x"00000100",
x"00001384",
x"00001634",
x"00001620",
x"00000228",
x"00000240",
x"00000280",
x"000013a4",
x"00000214",
x"2f12afe3",
x"00099236",
x"2f1261f2",
x"31278904",
x"61f27101",
x"2f12aff8",
x"0009d118",
x"922b2182",
x"e1002f12",
x"61f23127",
x"8d05e700",
x"61f27101",
x"2f12aff7",
x"0009d111",
x"921ed619",
x"21222f72",
x"63f23367",
x"890463f2",
x"73012f32",
x"aff80009",
x"21822f72",
x"63f23367",
x"890463f2",
x"73012f32",
x"aff80009",
x"2122afea",
x"000900c0",
x"00e100e4",
x"00e200e3",
x"00ff031f",
x"00aa0009",
x"abcd0000",
x"000015bc",
x"00000570",
x"10000000",
x"000018d8",
x"00000258",
x"0000010c",
x"00001650",
x"00000244",
x"00124f7f",
x"d027d124",
x"2102d327",
x"432a0009",
@@ -278,30 +330,121 @@ package bootrom is
x"d002400b",
x"0009c320",
x"00090009",
x"00000494",
x"00000820",
x"000003bc",
x"000003ca",
x"00000564",
x"00000a5c",
x"0000048c",
x"0000049a",
x"abcd0000",
x"000000ff",
x"0000004f",
x"00000011",
x"000003ea",
x"000004ba",
x"d1042f86",
x"684c4f22",
x"410b6483",
x"60834f26",
x"000b68f6",
x"00001320",
x"0000155c",
x"d0034f22",
x"400b0009",
x"4f26000b",
x"00090009",
x"00001338",
x"00001574",
x"000b0009",
x"d101412b",
x"00090009",
x"00000300",
x"00000330",
x"2f866153",
x"2f963168",
x"2fa66a43",
x"2fb62fc6",
x"2fd62fe6",
x"4f227fe0",
x"62f3d34f",
x"7214d54f",
x"430b6423",
x"e401441d",
x"de4d6063",
x"61434008",
x"71ff022e",
x"416d31ac",
x"68231f11",
x"4211e500",
x"8d2a7801",
x"a028e801",
x"8f2b6063",
x"605301ec",
x"611c1f13",
x"e0006117",
x"1f14e907",
x"2f02e701",
x"60f2e1ff",
x"52f17001",
x"2f02c802",
x"8d022709",
x"62a3e101",
x"e301237a",
x"ebe43bfc",
x"416d4308",
x"470833bc",
x"37bc6b43",
x"1f127b01",
x"e1004b10",
x"8b134910",
x"8be37501",
x"48108fd5",
x"2668a047",
x"e0ff8801",
x"8f056053",
x"d22e300c",
x"012dafd0",
x"611ddb2d",
x"4008afcc",
x"01be60f2",
x"88018d25",
x"26688b10",
x"5c7a6d20",
x"6ccc6ddc",
x"3dc08d31",
x"88074108",
x"361c4608",
x"4608356c",
x"60f24508",
x"355ca02e",
x"305c6063",
x"88018f08",
x"88025c7a",
x"6d216ccd",
x"6ddd3dc0",
x"8beba01e",
x"60f28be8",
x"6d225c7a",
x"3dc0890a",
x"afe44108",
x"8f025c3a",
x"a00a22c0",
x"60638801",
x"8b05a005",
x"22c160f2",
x"88078901",
x"5c3a22c2",
x"71015cf2",
x"afaf32cc",
x"a0070009",
x"89f8afeb",
x"5c3a8807",
x"89f4afec",
x"5c3a7f20",
x"4f266ef6",
x"6df66cf6",
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"00001628",
x"0000183c",
x"0000190c",
x"00001900",
x"000018e8",
x"614c6213",
x"729f622c",
x"e3053236",
@@ -332,7 +475,7 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"000004a0",
x"000006dc",
x"2f86e000",
x"2f96e903",
x"2fa62fb6",
@@ -376,7 +519,7 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"000015e4",
x"0000189c",
x"2f86e800",
x"2f966953",
x"2fa66a53",
@@ -391,7 +534,7 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"00000464",
x"00000534",
x"2f862f96",
x"2fa66a43",
x"2fb62fc6",
@@ -420,10 +563,10 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"00000464",
x"000005cc",
x"000015e4",
x"0000047c",
x"00000534",
x"00000808",
x"0000189c",
x"0000054c",
x"2f862f96",
x"2fa62fb6",
x"6b632fc6",
@@ -486,8 +629,8 @@ package bootrom is
x"6cf66bf6",
x"6af669f6",
x"000b68f6",
x"000004a0",
x"0000131c",
x"000006dc",
x"00001558",
x"2f862f96",
x"2fa66a53",
x"2fb62fc6",
@@ -522,10 +665,10 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"00000464",
x"000005cc",
x"00001590",
x"000015e4",
x"00000534",
x"00000808",
x"00001848",
x"0000189c",
x"2f862f96",
x"2fa62fb6",
x"2fc62fd6",
@@ -711,23 +854,23 @@ package bootrom is
x"1f75490b",
x"1f16afe5",
x"56f60009",
x"000012bc",
x"000004a0",
x"0000047c",
x"00000464",
x"00000608",
x"0000159c",
x"00001074",
x"000004d8",
x"00000688",
x"000011c8",
x"0000051c",
x"000005cc",
x"00001594",
x"000015e4",
x"000012a4",
x"00001238",
x"00001074",
x"000014f8",
x"000006dc",
x"0000054c",
x"00000534",
x"00000844",
x"00001854",
x"000012b0",
x"00000714",
x"000008c4",
x"00001404",
x"00000758",
x"00000808",
x"0000184c",
x"0000189c",
x"000014e0",
x"00001474",
x"000012b0",
x"1fc77a01",
x"e90064a4",
x"6043883d",
@@ -817,16 +960,16 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"000011c8",
x"00000688",
x"00001238",
x"00000608",
x"000015a0",
x"000013a0",
x"000004d8",
x"00001080",
x"0000131c",
x"0000159c",
x"00001404",
x"000008c4",
x"00001474",
x"00000844",
x"00001858",
x"0000164c",
x"00000714",
x"000012bc",
x"00001558",
x"00001854",
x"2f862448",
x"2f962fa6",
x"2fb62fc6",
@@ -894,15 +1037,15 @@ package bootrom is
x"6bf66af6",
x"69f6000b",
x"68f60009",
x"00000464",
x"000005cc",
x"0000160c",
x"000015f8",
x"0000051c",
x"000015b4",
x"000015b8",
x"000015e4",
x"00000820",
x"00000534",
x"00000808",
x"000018c4",
x"000018b0",
x"00000758",
x"0000186c",
x"00001870",
x"0000189c",
x"00000a5c",
x"2f866043",
x"2f964009",
x"2fa64009",
@@ -986,12 +1129,12 @@ package bootrom is
x"6cf66bf6",
x"6af669f6",
x"000b68f6",
x"00000464",
x"000015e4",
x"000011c8",
x"0000047c",
x"00000820",
x"00001032",
x"00000534",
x"0000189c",
x"00001404",
x"0000054c",
x"00000a5c",
x"0000126e",
x"d01151f4",
x"201251f3",
x"201661f3",
@@ -1009,8 +1152,8 @@ package bootrom is
x"40134022",
x"d00164f2",
x"400b0009",
x"00000e04",
x"000016dc",
x"00001040",
x"000019c4",
x"2f062f16",
x"e0f0400e",
x"e0052f06",
@@ -1058,7 +1201,7 @@ package bootrom is
x"70c05101",
x"6002002b",
x"00090009",
x"00001684",
x"0000196c",
x"ef046ff2",
x"e0006002",
x"402b0009",
@@ -1131,19 +1274,19 @@ package bootrom is
x"f80007ff",
x"402b400b",
x"c3200009",
x"000016c4",
x"000019ac",
x"0000fb00",
x"00008900",
x"00008b00",
x"0000f000",
x"0000a000",
x"0000f0ff",
x"00001684",
x"0000196c",
x"0000b000",
x"0000ff00",
x"0000c300",
x"000017ea",
x"00001032",
x"00001ad2",
x"0000126e",
x"e1163416",
x"8d2de000",
x"6243c702",
@@ -1170,8 +1313,8 @@ package bootrom is
x"5116e004",
x"2512000b",
x"00090009",
x"00001684",
x"000016c4",
x"0000196c",
x"000019ac",
x"e1163416",
x"8d2ce000",
x"6243c702",
@@ -1197,25 +1340,25 @@ package bootrom is
x"1154d103",
x"1156e004",
x"000b0009",
x"00001684",
x"000016c4",
x"0000196c",
x"000019ac",
x"24488901",
x"d1021145",
x"d102412b",
x"00090009",
x"000016c4",
x"00001032",
x"000019ac",
x"0000126e",
x"d1056211",
x"22288904",
x"d3045335",
x"2321e200",
x"2121000b",
x"00090009",
x"000017ea",
x"000016c4",
x"00001ad2",
x"000019ac",
x"d001402b",
x"00090009",
x"00000cd4",
x"00000f10",
x"d2096122",
x"21188d03",
x"e33271ff",
@@ -1226,8 +1369,8 @@ package bootrom is
x"91032212",
x"2312000b",
x"00090088",
x"00001630",
x"00001680",
x"00001918",
x"00001968",
x"abcd0000",
x"000b0009",
x"d104644c",
@@ -1248,24 +1391,52 @@ package bootrom is
x"64036083",
x"4f26000b",
x"68f60009",
x"00001338",
x"00001320",
x"00001574",
x"0000155c",
x"d102e202",
x"1123000b",
x"00090009",
x"abcd0100",
x"000b0009",
x"47444220",
x"53747562",
x"20666f72",
x"2048532d",
x"324a3020",
x"53483220",
x"524f4d0a",
x"4f224608",
x"b01d505c",
x"505f76c0",
x"140f2668",
x"505e8909",
x"140e4615",
x"505d7540",
x"140d7440",
x"890ec714",
x"306c402b",
x"4f26140e",
x"505d000b",
x"140d0009",
x"505f140f",
x"505e140e",
x"505d140d",
x"505c140c",
x"505b140b",
x"505a140a",
x"50591409",
x"50581408",
x"50571407",
x"50561406",
x"50551405",
x"50541404",
x"50531403",
x"50521402",
x"50511401",
x"5050000b",
x"14000009",
x"6b657920",
x"77616974",
x"2e2e2e00",
x"20646574",
x"6563740a",
x"00000000",
x"48697420",
x"61204b65",
x"79210000",
x"4c434420",
x"696e6974",
x"0a000000",
x"00000000",
x"0000005f",
x"00000007",
@@ -1386,6 +1557,9 @@ package bootrom is
x"08002010",
x"20100000",
x"00070507",
x"0000000c",
x"00000005",
x"00000006",
x"4f000000",
x"4f666673",
x"65747300",
@@ -1417,32 +1591,44 @@ package bootrom is
x"00000006",
x"00000007",
x"00000007",
x"000015bc",
x"000015c4",
x"000015cc",
x"000015d4",
x"000015dc",
x"00001874",
x"0000187c",
x"00001884",
x"0000188c",
x"00001894",
x"40a1c0a6",
x"a22ff800",
x"23811fac",
x"00afff00",
x"ffffffff",
x"55555555",
x"33333333",
x"0f0f0f0f",
x"00ff00ff",
x"0000ffff",
x"ffff5555",
x"33330f0f",
x"00ff0000",
x"ff55330f",
x"01020408",
x"10204080",
x"00000032",
x"72657669",
x"73696f6e",
x"3a206368",
x"616e6765",
x"7365743a",
x"20202031",
x"393a3332",
x"62626133",
x"30346661",
x"34300a62",
x"20202032",
x"313a3362",
x"30613139",
x"39653735",
x"39310a62",
x"75696c64",
x"3a205475",
x"65204d61",
x"72203139",
x"2031353a",
x"31313a31",
x"3a204d6f",
x"6e204d61",
x"72203235",
x"2031383a",
x"33313a30",
x"31204544",
x"54203230",
x"31390a00",

View File

@@ -1,4 +1,4 @@
OBJS := entry.o gdb.o sh2.o version.o
OBJS := entry.o march.o gdb.o sh2.o version.o
OBJS += uartlite.o
#OBJS += uart16550.o

View File

@@ -11,6 +11,12 @@ extern char version_string[];
char ram0[256]; /* working ram for CPU tests */
void
led(unsigned long v)
{
KEYPORT = v;
}
void
putstr (char *str)
{
@@ -22,74 +28,17 @@ putstr (char *str)
}
}
#ifndef NO_DDR
#define DDR_BASE 0x10000000
#define MemoryRead(A) (*(volatile int*)(A))
#define MemoryWrite(A,V) *(volatile int*)(A)=(V)
//SD_A <= address_reg(25 downto 13); --address row
//SD_BA <= address_reg(12 downto 11); --bank_address
//cmd := address_reg(6 downto 4); --bits RAS & CAS & WE
int DdrInitData[] = {
// AddressLines Bank Command
#ifndef LPDDR
(0x000 << 13) | (0 << 11) | (7 << 4), //CKE=1; NOP="111"
(0x400 << 13) | (0 << 11) | (2 << 4), //A10=1; PRECHARGE ALL="010"
(0x001 << 13) | (1 << 11) | (0 << 4), //EMR disable DLL; BA="01"; LMR="000"
#ifndef DDR_BL4
(0x121 << 13) | (0 << 11) | (0 << 4), //SMR reset DLL, CL=2, BL=2; LMR="000"
#else
(0x122 << 13) | (0 << 11) | (0 << 4), //SMR reset DLL, CL=2, BL=4; LMR="000"
#endif
(0x400 << 13) | (0 << 11) | (2 << 4), //A10=1; PRECHARGE ALL="010"
(0x000 << 13) | (0 << 11) | (1 << 4), //AUTO REFRESH="001"
(0x000 << 13) | (0 << 11) | (1 << 4), //AUTO REFRESH="001
#ifndef DDR_BL4
(0x021 << 13) | (0 << 11) | (0 << 4) //clear DLL, CL=2, BL=2; LMR="000"
#else
(0x022 << 13) | (0 << 11) | (0 << 4) //clear DLL, CL=2, BL=4; LMR="000"
#endif
#else // LPDDR
(0x000 << 13) | (0 << 11) | (7 << 4), //CKE=1; NOP="111"
(0x000 << 13) | (0 << 11) | (7 << 4), //NOP="111" after 200 uS
(0x400 << 13) | (0 << 11) | (2 << 4), //A10=1; PRECHARGE ALL="010"
(0x000 << 13) | (0 << 11) | (1 << 4), //AUTO REFRESH="001"
(0x000 << 13) | (0 << 11) | (1 << 4), //AUTO REFRESH="001"
(0x021 << 13) | (0 << 11) | (0 << 4), //SMR CL=2, BL=2; LMR="000"
(0x000 << 13) | (1 << 11) | (0 << 4), //EMR BA="01"; LMR="000" Full strength full array
(0x000 << 13) | (0 << 11) | (7 << 4) //NOP="111" after ? uS
#endif
};
int
ddr_init (void)
{
volatile int i, j, k = 0;
for (i = 0; i < sizeof (DdrInitData) / sizeof (int); ++i)
{
MemoryWrite (DDR_BASE + DdrInitData[i], 0);
for (j = 0; j < 4; ++j)
++k;
}
for (j = 0; j < 100; ++j)
++k;
k += MemoryRead (DDR_BASE); //Enable DDR
return k;
}
#endif /* NO_DDR */
void
key_wait()
{
volatile int i;
KEYPORT = KEY_PRECHARGE;
for (i=0; i<100; i++) {}
for (i=0; i<10; i++) {}
putstr("key wait...");
KEYPORT = 0;
while((KEYPORT & 0x7f) == 0x7f) {}
putstr(" detect\n");
KEYPORT = KEY_PRECHARGE;
}
@@ -168,35 +117,49 @@ lcd_puts(char *s)
unsigned char lcd_init[] = { 0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x23, 0x81, 0x1F, 0xAC, 0x00, 0xAF, 0xFF };
int march(void *base, int addrs, int sz);
void
main_sh (void)
{
volatile int i;
unsigned int stat = 0x50;
KEYPORT = KEY_PRECHARGE;
uart_set_baudrate ();
#ifndef NO_TESTS
putstr ("CPU tests passed\n");
#endif
#ifndef NO_DDR
putstr ("DDR Init\n");
ddr_init ();
#endif /* NO_DDR */
putstr ("GDB Stub for HS-2J0 SH2 ROM\n");
putstr (version_string);
#endif
led(0xe1);
if (march((void *)0x10000000, 3, 0) != -1) stat = 0xe2;
else if (march((void *)0x10000000, 3, 1) != -1) stat = 0xe3;
else if (march((void *)0x10000000, 3, 2) != -1) stat = 0xe4;
// for (i=0; i<1200000; i++) {}
for (i=0; lcd_init[i] != 0xff; i++) lcd_inst(lcd_init[i]);
putstr ("LCD init\n");
#if 0
lcd_loc(0, 1);
lcd_puts("Hit a Key!");
#if 0
putstr ("LCD Welcome\n");
key_wait();
key();
lcd_loc(0, 1);
lcd_puts("Hello 123!");
#endif
#if 0
lcd_loc(0, 0); lcd_puts(hex(0x123ab678));
#endif
@@ -207,11 +170,22 @@ main_sh (void)
(1<<(i+16)) |
(1<<(i+24)));
}
for (i=0; i<800; i++) {}
led(stat);
for (i=0; i<800; i++) {}
led(0xaa);
for (;;) {
for (i=0; i<1200000; i++) {}
led(stat);
for (i=0; i<1200000; i++) {}
led(0xaa);
}
#if 0
for (;;) {
key_wait();
lcd_loc(0,1); lcd_puts("Key...");
lcd_loc(0,2); lcd_puts(hex(key()));
#endif
}
#endif
}

68
testrom/march.c Normal file
View File

@@ -0,0 +1,68 @@
/* A WOM March-C- algorithm. Put in the base address and # of address bits, returns 0 if ok or fault addr */
#define SZ_BYTE 0
#define SZ_WORD 1
#define SZ_LONG 2
unsigned char patterns_b[] = {0xff, 0x55, 0x33, 0x0f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
unsigned short patterns_w[] = {0xffff, 0x5555, 0x3333, 0x0f0f, 0x00ff};
unsigned long patterns_l[] = {0xffffffff, 0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, 0x0000ffff};
unsigned march(void *base, int addrs, int sz)
{
volatile void *p = base;
unsigned long i, pat[2];
int len = 1<<(addrs-sz);
int r, m, k, q, j;
int patlen[3] = {sizeof(patterns_b), sizeof(patterns_w)/2, sizeof(patterns_l)/4};
for (r=0; r<patlen[sz]; r++) {
pat[0] = (sz == SZ_BYTE) ? patterns_b[r] : (sz==SZ_WORD) ? patterns_w[r] : patterns_l[r];
pat[1] = ~*pat;
// alternate down/up sweeps (duuddu) swapping pat with nat, test previous
// results first for all but first and last passes
for (j=0; j<7;) {
k = 2&++j;
m = j&1;
p = k ? base : base + (len-1) * (1<<sz);
for (i=0; i<len; i++) {
if (j!=1) {
if (sz==SZ_BYTE && *((unsigned char *)p) == (unsigned char) pat[m]);
else if (sz==SZ_WORD && *((unsigned short *)p) == (unsigned short)pat[m]);
else if (sz==SZ_LONG && *((unsigned long *)p) == pat[m]);
else return (((((i<<2)+sz)<<4)+r)<<3)+j;
}
if (j!=7) {
q = pat[m^1];
if (sz==SZ_BYTE) *((unsigned char *)p) = (unsigned char) q;
else if (sz==SZ_WORD) *((unsigned short *)p) = (unsigned short)q;
else *((unsigned long *)p) = q;
}
p += (1<<sz) * (k ? 1 : -1);
}
}
}
return ~0;
}
#if 0
int march(void *base, int addrs)
{
int ret;
if ((ret = _march(base, addrs, SZ_BYTE)) != -1) return ret;
if ((ret = _march(base, addrs, SZ_WORD)) != -1) return ret;
return _march(base, addrs, SZ_LONG);
}
char mem[1<<17];
int
main(int argc, char *argv[])
{
printf("March on memory at 0x%p returned %d\n", mem, march(mem, 3));
}
#endif

View File

@@ -53,7 +53,7 @@ signal x1 : std_logic_vector(7 downto 0);
k0: process
begin
y(3) <= 'H';
wait for 400 us;
wait for 650 us;
while true loop
y(3) <= x(2);
wait until x'event;