From 92177196c046fff5a8c5ab9d00a1d00c17c3ae50 Mon Sep 17 00:00:00 2001 From: David Banks Date: Wed, 23 Sep 2015 14:56:31 +0100 Subject: [PATCH] Experimental AtomFast6502 with a different clocking arrangement Change-Id: Ic6f5275bc0982254e9b5508ec79f0365712657de --- AtomFast6502.xise | 378 +++++++++++++++++++++++++++++++++++++++++++ src/AtomFast6502.ucf | 78 +++++++++ src/AtomFast6502.vhd | 254 +++++++++++++++++++++++++++++ src/DCM/DCM2.vhd | 59 +++++++ 4 files changed, 769 insertions(+) create mode 100644 AtomFast6502.xise create mode 100644 src/AtomFast6502.ucf create mode 100644 src/AtomFast6502.vhd create mode 100644 src/DCM/DCM2.vhd diff --git a/AtomFast6502.xise b/AtomFast6502.xise new file mode 100644 index 0000000..b20c55c --- /dev/null +++ b/AtomFast6502.xise @@ -0,0 +1,378 @@ + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/AtomFast6502.ucf b/src/AtomFast6502.ucf new file mode 100644 index 0000000..cdf6f04 --- /dev/null +++ b/src/AtomFast6502.ucf @@ -0,0 +1,78 @@ + +NET "clock49" LOC="P89" | IOSTANDARD = LVCMOS33 | PERIOD = 20.35ns ; # 49.152 MHz Oscillator + +#NET "VSS" LOC="P16" | IOSTANDARD = LVCMOS33 ; # 6502 pin 1 +NET "Rdy" LOC="P95" | IOSTANDARD = LVCMOS33 ; # 6502 pin 2 +NET "Phi1" LOC="P18" | IOSTANDARD = LVCMOS33 ; # 6502 pin 3 +NET "IRQ_n" LOC="P17" | IOSTANDARD = LVCMOS33 | PULLUP ; # 6502 pin 4 +#NET "NC" LOC="P94" | IOSTANDARD = LVCMOS33 ; # 6502 pin 5 +NET "NMI_n" LOC="P22" | IOSTANDARD = LVCMOS33 | PULLUP ; # 6502 pin 6 +NET "Sync" LOC="P23" | IOSTANDARD = LVCMOS33 ; # 6502 pin 7 +#NET "VCC" LOC="P33" | IOSTANDARD = LVCMOS33 ; # 6502 pin 8 +NET "Addr<0>" LOC="P32" | IOSTANDARD = LVCMOS33 ; # 6502 pin 9 +NET "Addr<1>" LOC="P34" | IOSTANDARD = LVCMOS33 ; # 6502 pin 10 +NET "Addr<2>" LOC="P40" | IOSTANDARD = LVCMOS33 ; # 6502 pin 11 +NET "Addr<3>" LOC="P41" | IOSTANDARD = LVCMOS33 ; # 6502 pin 12 +NET "Addr<4>" LOC="P36" | IOSTANDARD = LVCMOS33 ; # 6502 pin 13 +NET "Addr<5>" LOC="P35" | IOSTANDARD = LVCMOS33 ; # 6502 pin 14 +NET "Addr<6>" LOC="P53" | IOSTANDARD = LVCMOS33 ; # 6502 pin 15 +NET "Addr<7>" LOC="P54" | IOSTANDARD = LVCMOS33 ; # 6502 pin 16 +NET "Addr<8>" LOC="P57" | IOSTANDARD = LVCMOS33 ; # 6502 pin 17 +NET "Addr<9>" LOC="P58" | IOSTANDARD = LVCMOS33 ; # 6502 pin 18 +NET "Addr<10>" LOC="P60" | IOSTANDARD = LVCMOS33 ; # 6502 pin 19 +NET "Addr<11>" LOC="P61" | IOSTANDARD = LVCMOS33 ; # 6502 pin 20 + +#NET "VSS" LOC="P67" | IOSTANDARD = LVCMOS33 ; # 6502 pin 21 +NET "Addr<12>" LOC="P68" | IOSTANDARD = LVCMOS33 ; # 6502 pin 22 +NET "Addr<13>" LOC="P70" | IOSTANDARD = LVCMOS33 ; # 6502 pin 23 +NET "Addr<14>" LOC="P71" | IOSTANDARD = LVCMOS33 ; # 6502 pin 24 +NET "Addr<15>" LOC="P86" | IOSTANDARD = LVCMOS33 ; # 6502 pin 25 +NET "Data<7>" LOC="P84" | IOSTANDARD = LVCMOS33 ; # 6502 pin 26 +NET "Data<6>" LOC="P83" | IOSTANDARD = LVCMOS33 ; # 6502 pin 27 +NET "Data<5>" LOC="P78" | IOSTANDARD = LVCMOS33 ; # 6502 pin 28 +NET "Data<4>" LOC="P79" | IOSTANDARD = LVCMOS33 ; # 6502 pin 29 +NET "Data<3>" LOC="P85" | IOSTANDARD = LVCMOS33 ; # 6502 pin 30 +NET "Data<2>" LOC="P92" | IOSTANDARD = LVCMOS33 ; # 6502 pin 31 +NET "Data<1>" LOC="P98" | IOSTANDARD = LVCMOS33 ; # 6502 pin 32 +NET "Data<0>" LOC="P3" | IOSTANDARD = LVCMOS33 ; # 6502 pin 33 +NET "R_W_n" LOC="P2" | IOSTANDARD = LVCMOS33 ; # 6502 pin 34 +#NET "NC" LOC="P4" | IOSTANDARD = LVCMOS33 ; # 6502 pin 35 +#NET "NC" LOC="P5" | IOSTANDARD = LVCMOS33 ; # 6502 pin 36 +NET "Phi0" LOC="P90" | IOSTANDARD = LVCMOS33 | PERIOD = 500.0 ; # 6502 pin 37 +NET "SO_n" LOC="P9" | IOSTANDARD = LVCMOS33 ; # 6502 pin 38 +NET "Phi2" LOC="P10" | IOSTANDARD = LVCMOS33 ; # 6502 pin 39 +NET "Res_n" LOC="P11" | IOSTANDARD = LVCMOS33 ; # 6502 pin 40 + +NET "led3" LOC="P43" | IOSTANDARD = LVCMOS33 ; # Red LED (near SW1) +NET "led6" LOC="P25" | IOSTANDARD = LVCMOS33 ; # Red LED (just left of FPGA) +NET "led8" LOC="P47" | IOSTANDARD = LVCMOS33 ; # Green LED (near SW1) +NET "sw1" LOC="P39" | IOSTANDARD = LVCMOS33 ; # Bottom Switch +NET "nsw2" LOC="P69" | IOSTANDARD = LVCMOS33 | PULLUP ; # Top Switch + +# I/O's for test connector +NET test<0> LOC=P48 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<1> LOC=P49 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<2> LOC=P27 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<3> LOC=P44 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<4> LOC=P50 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<5> LOC=P42 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; +NET test<6> LOC=P99 | IOSTANDARD = LVCMOS33 | DRIVE=16 ; + +NET "avr_TxD" LOC="P26" | IOSTANDARD = LVCMOS33 ; +NET "avr_RxD" LOC="P15" | IOSTANDARD = LVCMOS33 ; + +NET "trig<0>" LOC="P62" | IOSTANDARD = LVCMOS33 ; +NET "trig<1>" LOC="P63" | IOSTANDARD = LVCMOS33 ; + +NET "fakeTube_n" LOC="P65" | IOSTANDARD = LVCMOS33 ; + +# NET "" LOC="P48" | IOSTANDARD = LVCMOS33 ; # connector pin E2 +# NET "" LOC="P49" | IOSTANDARD = LVCMOS33 ; # connector pin E3 +# NET "" LOC="P27" | IOSTANDARD = LVCMOS33 ; # connector pin E4 +# NET "" LOC="P44" | IOSTANDARD = LVCMOS33 ; # connector pin E5 +# NET "" LOC="P50" | IOSTANDARD = LVCMOS33 ; # connector pin E6 +# NET "" LOC="P42" | IOSTANDARD = LVCMOS33 ; # connector pin E7 +# NET "" LOC="P99" | IOSTANDARD = LVCMOS33 ; # connector pin E8 + + + \ No newline at end of file diff --git a/src/AtomFast6502.vhd b/src/AtomFast6502.vhd new file mode 100644 index 0000000..5a1fec7 --- /dev/null +++ b/src/AtomFast6502.vhd @@ -0,0 +1,254 @@ +-------------------------------------------------------------------------------- +-- Copyright (c) 2015 David Banks +-- +-------------------------------------------------------------------------------- +-- ____ ____ +-- / /\/ / +-- /___/ \ / +-- \ \ \/ +-- \ \ +-- / / Filename : AtomBusMon.vhd +-- /___/ /\ Timestamp : 30/05/2015 +-- \ \ / \ +-- \___\/\___\ +-- +--Design Name: AtomBusMon +--Device: XC3S250E + +library ieee; +use ieee.std_logic_1164.all; +use ieee.std_logic_unsigned.all; +use ieee.numeric_std.all; +use work.OhoPack.all ; + + +entity AtomFast6502 is + generic ( + UseT65Core : boolean := true; + UseAlanDCore : boolean := false + ); + port ( + clock49 : in std_logic; + + -- 6502 Signals + Rdy : in std_logic; + Phi0 : in std_logic; + Phi1 : out std_logic; + Phi2 : out std_logic; + IRQ_n : in std_logic; + NMI_n : in std_logic; + Sync : out std_logic; + Addr : out std_logic_vector(15 downto 0); + R_W_n : out std_logic; + Data : inout std_logic_vector(7 downto 0); + SO_n : in std_logic; + Res_n : inout std_logic; + + -- External trigger inputs + trig : in std_logic_vector(1 downto 0); + + -- Jumpers + fakeTube_n : in std_logic; + + -- Serial Console + avr_RxD : in std_logic; + avr_TxD : out std_logic; + + -- GODIL Switches + sw1 : in std_logic; + nsw2 : in std_logic; + + -- GODIL LEDs + led3 : out std_logic; + led6 : out std_logic; + led8 : out std_logic; + + test : out std_logic_vector(6 downto 0) + + ); +end AtomFast6502; + +architecture behavioral of AtomFast6502 is + + signal Din : std_logic_vector(7 downto 0); + signal Dout : std_logic_vector(7 downto 0); + + -- Signal from the internal core + signal Dout0 : std_logic_vector(7 downto 0); + signal Addr0 : std_logic_vector(15 downto 0); + signal R_W_n0 : std_logic; + signal Sync0 : std_logic; + + -- Delayed signals for the outside world + signal Dout1 : std_logic_vector(7 downto 0); + signal Addr1 : std_logic_vector(15 downto 0); + signal R_W_n1 : std_logic; + signal Sync1 : std_logic; + + signal cpu_addr_us: unsigned (15 downto 0); + signal cpu_dout_us: unsigned (7 downto 0); + + signal clock_16x : std_logic; + signal cpu_clk : std_logic; + signal R_W_n_int : std_logic; + + signal cpu_clken : std_logic; + signal cpu_dataen : std_logic; + + signal clk_div : std_logic_vector(3 downto 0); + + signal Phi1_int : std_logic; + signal Phi2_int : std_logic; + signal dcm_reset : std_logic; + signal dcm_count : std_logic_vector(9 downto 0); + signal dcm_locked : std_logic; + signal edge0 : std_logic; + signal edge1 : std_logic; + + +begin + + GenT65Core: if UseT65Core generate + inst_t65: entity work.T65 port map ( + mode => "00", + Abort_n => '1', + SO_n => SO_n, + Res_n => Res_n, + Enable => cpu_clken, + Clk => clock_16x, + Rdy => Rdy, + IRQ_n => IRQ_n, + NMI_n => NMI_n, + R_W_n => R_W_n0, + Sync => Sync0, + A(23 downto 16) => open, + A(15 downto 0) => Addr0, + DI => Din, + DO => Dout0, + Regs => open + ); + end generate; + + GenAlanDCore: if UseAlanDCore generate + inst_r65c02: entity work.r65c02 port map ( + reset => RES_n, + clk => clock_16x, + enable => cpu_clken, + nmi_n => NMI_n, + irq_n => IRQ_n, + di => unsigned(Din), + do => cpu_dout_us, + addr => cpu_addr_us, + nwe => R_W_n0, + sync => Sync0, + sync_irq => open, + Regs => open + ); + Dout0 <= std_logic_vector(cpu_dout_us); + Addr0 <= std_logic_vector(cpu_addr_us); + end generate; + + + inst_dcm2 : entity work.DCM2 port map( + CLKIN_IN => Phi0, + CLKFX_OUT => clock_16x, + LOCKED => dcm_locked, + RESET => dcm_reset + ); + + process(clock49) + begin + if rising_edge(clock49) then + edge0 <= clk_div(0); + edge1 <= edge0; + -- Look for an edge on the clock + if (edge0 /= edge1) then + dcm_count <= (others => '0'); + elsif (dcm_count = "1111001111") then + dcm_reset <= '0'; + elsif (dcm_count = "1000000000") then + dcm_reset <= '1'; + dcm_count <= dcm_count + 1; + else + dcm_count <= dcm_count + 1; + end if; + end if; + end process; + +-- -- for some reason this did not work reliably.... +-- process(clock49) +-- begin +-- if rising_edge(clock49) then +-- edge0 <= dcm_locked; +-- edge1 <= edge0; +-- if (dcm_count = "0000000000") then +-- dcm_reset <= '0'; +-- if (edge0 = '0' and edge1 = '1') then +-- dcm_count <= dcm_count + 1; +-- end if; +-- else +-- dcm_reset <= '1'; +-- dcm_count <= dcm_count + 1; +-- end if; +-- end if; +-- end process; + + process(clock_16x) + begin + if rising_edge(clock_16x) then + -- internal clock running 16x Phi0 + clk_div <= clk_div + 1; + -- clock the CPU on cycle 0 + if (clk_div = "1111") then + cpu_clken <= '1'; + else + cpu_clken <= '0'; + end if; + -- toggle Phi1/2 on cycles 0 and 8 + if (clk_div = "0000") then + Phi1_int <= '1'; + Phi2_int <= '0'; + elsif (clk_div = "1000") then + Phi1_int <= '0'; + Phi2_int <= '1'; + end if; + -- Skew address by one cycles, and hold for a complete cycle + if (clk_div = "0001") then + Addr1 <= Addr0; + R_W_n1 <= R_W_n0; + Sync1 <= Sync0; + end if; + -- Skew data by one cycle + if (clk_div = "1011") then + cpu_dataen <= not R_W_n0; + Dout1 <= Dout0; + elsif (clk_div = "0001") then + cpu_dataen <= '0'; + Dout1 <= (others => '1'); + end if; + end if; + end process; + + Phi1 <= Phi1_int; + Phi2 <= Phi2_int; + Din <= Data; + Addr <= Addr1; + R_W_n <= R_W_n1; + Sync <= Sync1; + Data <= Dout1 when cpu_dataen = '1' else "ZZZZZZZZ"; + + led3 <= '1'; + led6 <= '1'; + led8 <= '1'; + avr_TxD <= '1'; + + test(0) <= clock_16x; + test(1) <= Phi1_int; + test(2) <= Phi2_int; + test(3) <= dcm_locked; + test(4) <= dcm_reset; + test(5) <= R_W_n1; + test(6) <= '1'; + +end behavioral; + diff --git a/src/DCM/DCM2.vhd b/src/DCM/DCM2.vhd new file mode 100644 index 0000000..549a0a0 --- /dev/null +++ b/src/DCM/DCM2.vhd @@ -0,0 +1,59 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +library UNISIM; +use UNISIM.Vcomponents.all; + +entity DCM2 is + port (CLKIN_IN : in std_logic; + RESET : in std_logic; + CLKFX_OUT : out std_logic; + LOCKED : out std_logic); +end DCM2; + +architecture BEHAVIORAL of DCM2 is + signal CLKFX_BUF : std_logic; + signal CLKIN_IBUFG : std_logic; + signal GND_BIT : std_logic; +begin + + GND_BIT <= '0'; + CLKFX_BUFG_INST : BUFG + port map (I => CLKFX_BUF, O => CLKFX_OUT); + + DCM_INST : DCM + generic map(CLK_FEEDBACK => "NONE", + CLKDV_DIVIDE => 4.0, + CLKFX_DIVIDE => 1, + CLKFX_MULTIPLY => 16, + CLKIN_DIVIDE_BY_2 => false, + CLKIN_PERIOD => 1000.00, + CLKOUT_PHASE_SHIFT => "NONE", + DESKEW_ADJUST => "SYSTEM_SYNCHRONOUS", + DFS_FREQUENCY_MODE => "LOW", + DLL_FREQUENCY_MODE => "LOW", + DUTY_CYCLE_CORRECTION => true, + FACTORY_JF => x"C080", + PHASE_SHIFT => 0, + STARTUP_WAIT => false) + port map (CLKFB => GND_BIT, + CLKIN => CLKIN_IN, + DSSEN => GND_BIT, + PSCLK => GND_BIT, + PSEN => GND_BIT, + PSINCDEC => GND_BIT, + RST => RESET, + CLKDV => open, + CLKFX => CLKFX_BUF, + CLKFX180 => open, + CLK0 => open, + CLK2X => open, + CLK2X180 => open, + CLK90 => open, + CLK180 => open, + CLK270 => open, + LOCKED => LOCKED, + PSDONE => open, + STATUS => open); + +end BEHAVIORAL;