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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [toplevel.v] - Diff between revs 9 and 18

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 18
`timescale 10ns / 100ps
`timescale 10ns / 100ps
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
// Filename:    toplevel.v
// Filename:    toplevel.v
//
//
// Project:     XuLA2 board
// Project:     XuLA2 board
//
//
// Purpose:     This is the _top_level_ verilog file for the XuLA2-LX25
// Purpose:     This is the _top_level_ verilog file for the XuLA2-LX25
//              SoC project.  Everything else fits underneath here (logically).
//              SoC project.  Everything else fits underneath here (logically).
//      This is also the only file that will not go through Verilator.  Specific
//      This is also the only file that will not go through Verilator.  Specific
//      to this file are the Xilinx primitives necessary to build for the
//      to this file are the Xilinx primitives necessary to build for the
//      XuLA2 board--with the only exception being the ICAPE_SPARTAN6 interface.
//      XuLA2 board--with the only exception being the ICAPE_SPARTAN6 interface.
//
//
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015, Gisselquist Technology, LLC
// Copyright (C) 2015, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
//
//
// `define      HELLO_WORLD
// `define      HELLO_WORLD
// `define      ECHO_TEST
// `define      ECHO_TEST
//
//
module toplevel(i_clk_12mhz,
module toplevel(i_clk_12mhz,
                i_ram_feedback_clk,
                i_ram_feedback_clk,
                o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
                o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
                o_ram_clk, o_ram_cke, o_ram_cs_n, o_ram_ras_n, o_ram_cas_n,
                o_ram_clk, o_ram_cke, o_ram_cs_n, o_ram_ras_n, o_ram_cas_n,
                o_ram_we_n, o_ram_bs, o_ram_addr, o_ram_udqm, o_ram_ldqm,
                o_ram_we_n, o_ram_bs, o_ram_addr, o_ram_udqm, o_ram_ldqm,
                io_ram_data,
                io_ram_data,
                i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart);
                i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart);
        input           i_clk_12mhz;
        input           i_clk_12mhz;
        input           i_ram_feedback_clk;
        input           i_ram_feedback_clk;
        //
        //
        // SPI connection(s): Flash and SD Card
        // SPI connection(s): Flash and SD Card
        output  wire    o_sf_cs_n;
        output  wire    o_sf_cs_n;
        output  wire    o_sd_cs_n;
        output  wire    o_sd_cs_n;
        output  wire    o_spi_sck;
        output  wire    o_spi_sck;
        output  wire    o_spi_mosi;
        output  wire    o_spi_mosi;
        input           i_spi_miso;
        input           i_spi_miso;
        //
        //
        // SD RAM
        // SD RAM
        output  wire    o_ram_clk, o_ram_cke;
        output  wire    o_ram_clk, o_ram_cke;
        output  wire    o_ram_cs_n, o_ram_ras_n, o_ram_cas_n, o_ram_we_n;
        output  wire    o_ram_cs_n, o_ram_ras_n, o_ram_cas_n, o_ram_we_n;
        output  wire    [1:0]    o_ram_bs;
        output  wire    [1:0]    o_ram_bs;
        output  wire    [12:0]   o_ram_addr;
        output  wire    [12:0]   o_ram_addr;
        output  wire            o_ram_udqm, o_ram_ldqm;
        output  wire            o_ram_udqm, o_ram_ldqm;
        inout   wire    [15:0]   io_ram_data;
        inout   wire    [15:0]   io_ram_data;
        //
        //
        // General purpose I/O
        // General purpose I/O
        // output       [31:0]  io_chan;
        // output       [31:0]  io_chan;
        input           [13:0]   i_gpio;
        input           [13:0]   i_gpio;
        output  wire    [14:0]   o_gpio;
        output  wire    [14:0]   o_gpio;
        output  wire            o_pwm;
        output  wire            o_pwm;
        input                   i_rx_uart;
        input                   i_rx_uart;
        output  wire            o_tx_uart;
        output  wire            o_tx_uart;
 
 
/////
/////
        wire    [7:0]    rx_data, tx_data;
        wire    [7:0]    rx_data, tx_data;
        wire            rx_stb, tx_stb, tx_busy;
        wire            rx_stb, tx_stb, tx_busy;
        wire            clk_s, reset_s, intermediate_clk, intermediate_clk_n,
        wire            clk_s, reset_s, intermediate_clk, intermediate_clk_n,
                        ck_zero_0;
                        ck_zero_0;
        wire    ck_zero_1;
        wire    ck_zero_1;
 
 
        DCM_SP #(
        DCM_SP #(
                .CLKDV_DIVIDE(2.0),
                .CLKDV_DIVIDE(2.0),
                .CLKFX_DIVIDE(3),
                .CLKFX_DIVIDE(3),
                .CLKFX_MULTIPLY(19),
                .CLKFX_MULTIPLY(20),
                .CLKIN_DIVIDE_BY_2("FALSE"),
                .CLKIN_DIVIDE_BY_2("FALSE"),
                .CLKIN_PERIOD(83.333333),
                .CLKIN_PERIOD(83.333333),
                .CLKOUT_PHASE_SHIFT("NONE"),
                .CLKOUT_PHASE_SHIFT("NONE"),
                .CLK_FEEDBACK("1X"),
                .CLK_FEEDBACK("1X"),
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
                .DLL_FREQUENCY_MODE("LOW"),
                .DLL_FREQUENCY_MODE("LOW"),
                .DUTY_CYCLE_CORRECTION("TRUE"),
                .DUTY_CYCLE_CORRECTION("TRUE"),
                .PHASE_SHIFT(0),
                .PHASE_SHIFT(0),
                .STARTUP_WAIT("TRUE")
                .STARTUP_WAIT("TRUE")
        ) u0(   .CLKIN(i_clk_12mhz),
        ) u0(   .CLKIN(i_clk_12mhz),
                .CLK0(ck_zero_0),
                .CLK0(ck_zero_0),
                .CLKFB(ck_zero_0),
                .CLKFB(ck_zero_0),
                .CLKFX(clk_s),
                .CLKFX(clk_s),
                // .CLKFX180(intermediate_clk_n),
                // .CLKFX180(intermediate_clk_n),
                .PSEN(1'b0),
                .PSEN(1'b0),
                .RST(1'b0));
                .RST(1'b0));
 
 
        DCM_SP #(
        DCM_SP #(
                .CLKDV_DIVIDE(2),
                .CLKDV_DIVIDE(2),
                .CLKFX_MULTIPLY(2),
                .CLKFX_MULTIPLY(2),
                .CLKFX_DIVIDE(2),
                .CLKFX_DIVIDE(2),
                .CLKOUT_PHASE_SHIFT("FIXED"),
                .CLKOUT_PHASE_SHIFT("FIXED"),
                .CLK_FEEDBACK("1X"),
                .CLK_FEEDBACK("1X"),
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
                .DESKEW_ADJUST("SYSTEM_SYNCHRONOUS"),
                .DLL_FREQUENCY_MODE("LOW"),
                .DLL_FREQUENCY_MODE("LOW"),
                .DUTY_CYCLE_CORRECTION("TRUE"),
                .DUTY_CYCLE_CORRECTION("TRUE"),
                // At a clock of 92MHz ...
                // At a clock of 92MHz ...
                // Didn't work at -64, -70, -76 is worse than the other two
                // Didn't work at -64, -70, -76 is worse than the other two
                // -56: Write works, 0x96 reads work 
                // -56: Write works, 0x96 reads work 
                // -48: Write fails, 0x0183 or 0x351 is first write that fails
                // -48: Write fails, 0x0183 or 0x351 is first write that fails
                // -40: Write fails, 0x071a,176a,0x576
                // -40: Write fails, 0x071a,176a,0x576
                // -56 was my working choice at 92 MHz
                // -56 was my working choice at 92 MHz
                //      That would be about a 2.4ns delay from clock to 
                //      That would be about a 2.4ns delay from clock to 
                //      data.
                //      data.
                // Suddenly needed to shift to 80 MHz. 
                // Suddenly needed to shift to 80 MHz. 
                //      -56 no longer sort of works
                //      -56 no longer sort of works
                //      -49 writes seem to work, reads ... not so much
                //      -49 writes seem to work, reads ... not so much
                //      -45 writes no longer working ??
                //      -45 writes no longer working ??
                //              Read fails @ 0x891, 0x58e, @0x3d65, @0x0aec,
                //              Read fails @ 0x891, 0x58e, @0x3d65, @0x0aec,
                //                      @0x11b8, @0beb, @0x01014
                //                      @0x11b8, @0beb, @0x01014
                // Trying a different approach: register in i_ram_feedback_clk,
                // Trying a different approach: register in i_ram_feedback_clk,
                //      followed by o_ram_clk, instead of registering on
                //      followed by o_ram_clk, instead of registering on
                //      clk_s second.  Starting build at 1857
                //      clk_s second.  Starting build at 1857
                //      Okay, so that was an error, now they are referenced to
                //      Okay, so that was an error, now they are referenced to
                //      intermediate_clk, and I still need to try
                //      intermediate_clk, and I still need to try
                //      intermediate_clk_n if that doesn't work.
                //      intermediate_clk_n if that doesn't work.
                //      THIS NEEDS A DELAY ADJUSTMENT: WBSDRAMNG adjusted from
                //      THIS NEEDS A DELAY ADJUSTMENT: WBSDRAMNG adjusted from
                //      6 to 5, and rebuild started at 1914. (finished by 1930)
                //      6 to 5, and rebuild started at 1914. (finished by 1930)
                //      This one has read bugs at 0x027, 0x030, 0x039, 0x021
                //      This one has read bugs at 0x027, 0x030, 0x039, 0x021
                //              etc.  So we are worse. 
                //              etc.  So we are worse. 
                //      (We also failed timing--I did nothing to fix that)
                //      (We also failed timing--I did nothing to fix that)
                //
                //
                // tho ... even if this works, it is wrong.  The data lines
                // tho ... even if this works, it is wrong.  The data lines
                // going into wbsdramng need to be clocked on the system clock
                // going into wbsdramng need to be clocked on the system clock
                // on entrance.  Thus, the last always@ block must clock these
                // on entrance.  Thus, the last always@ block must clock these
                // lines on clk_s.  This is fixed, and cannot change.
                // lines on clk_s.  This is fixed, and cannot change.
                // This leaves us with a couple options for clocking the first
                // This leaves us with a couple options for clocking the first
                // always block:
                // always block:
                //
                //
                //      i_ram_feedback_clk, posedge (the right answer ... but
                //      i_ram_feedback_clk, posedge (the right answer ... but
                //              giving me problems)
                //              giving me problems)
                //      clk_s   pos/neg edge
                //      clk_s   pos/neg edge
                //      intermediate_clk        posedge (Build started at 1932)
                //      intermediate_clk        posedge (Build started at 1932)
                //              Result: much worse!!
                //              Result: much worse!!
                //      intermediate_clk_n      posedge (delay of 6 needed, not
                //      intermediate_clk_n      posedge (delay of 6 needed, not
                //              tested as a result.
                //              tested as a result.
                //
                //
                //      
                //      
                .PHASE_SHIFT(-45),
                .PHASE_SHIFT(-45),
                .STARTUP_WAIT("TRUE")
                .STARTUP_WAIT("TRUE")
        ) u1(   .CLKIN(clk_s),
        ) u1(   .CLKIN(clk_s),
                .CLK0(ck_zero_1),
                .CLK0(ck_zero_1),
                .CLKFB(ck_zero_1),
                .CLKFB(ck_zero_1),
                .CLK180(intermediate_clk_n),
                .CLK180(intermediate_clk_n),
                .PSEN(1'b0),
                .PSEN(1'b0),
                .RST(1'b0));
                .RST(1'b0));
        assign  intermediate_clk = ck_zero_1;
        assign  intermediate_clk = ck_zero_1;
 
 
        ODDR2 u2( .Q(o_ram_clk),
        ODDR2 u2( .Q(o_ram_clk),
                .C0(intermediate_clk),
                .C0(intermediate_clk),
                .C1(intermediate_clk_n),
                .C1(intermediate_clk_n),
                .CE(1'b1), .D0(1'b1), .D1(1'b0), .R(1'b0), .S(1'b0));
                .CE(1'b1), .D0(1'b1), .D1(1'b0), .R(1'b0), .S(1'b0));
 
 
        // Generate active-high reset.
        // Generate active-high reset.
        /*
        /*
        reg     r_reset;
        reg     r_reset;
        initial r_reset = 1'b1;
        initial r_reset = 1'b1;
        always @(posedge i_clk_12mhz)
        always @(posedge i_clk_12mhz)
                r_reset <= 1'b0;
                r_reset <= 1'b0;
        */
        */
        assign  reset_s = 1'b0;
        assign  reset_s = 1'b0;
 
 
        jtagser jtagtxrx(clk_s, rx_stb, rx_data, tx_stb, tx_data, tx_busy);
        jtagser jtagtxrx(clk_s, rx_stb, rx_data, tx_stb, tx_data, tx_busy);
 
 
 
 
        wire    [15:0]   ram_data;
        wire    [15:0]   ram_data;
        wire            ram_drive_data;
        wire            ram_drive_data;
        reg     [15:0]   r_ram_data;
        reg     [15:0]   r_ram_data;
 
 
        busmaster #(24,15,14)
        busmaster #(24,15,14)
                wbbus(clk_s, reset_s,
                wbbus(clk_s, reset_s,
                        // External JTAG bus control
                        // External JTAG bus control
                        rx_stb, rx_data, tx_stb, tx_data, tx_busy,
                        rx_stb, rx_data, tx_stb, tx_data, tx_busy,
                        // Board lights and switches ... none
                        // Board lights and switches ... none
                        // SPI/SD-card flash
                        // SPI/SD-card flash
                        o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
                        o_sf_cs_n, o_sd_cs_n, o_spi_sck, o_spi_mosi, i_spi_miso,
                        // SDRAM interface
                        // SDRAM interface
                        // o_ram_clk,   // SDRAM clock = clk_100mhz_s = clk_s
                        // o_ram_clk,   // SDRAM clock = clk_100mhz_s = clk_s
                        o_ram_cs_n,     // Chip select
                        o_ram_cs_n,     // Chip select
                        o_ram_cke,      // Clock enable
                        o_ram_cke,      // Clock enable
                        o_ram_ras_n,    // Row address strobe
                        o_ram_ras_n,    // Row address strobe
                        o_ram_cas_n,    // Column address strobe
                        o_ram_cas_n,    // Column address strobe
                        o_ram_we_n,     // Write enable
                        o_ram_we_n,     // Write enable
                        o_ram_bs,       // Bank select
                        o_ram_bs,       // Bank select
                        o_ram_addr,     // Address lines
                        o_ram_addr,     // Address lines
                        ram_drive_data,
                        ram_drive_data,
                        r_ram_data,     // Data lines (input)
                        r_ram_data,     // Data lines (input)
                        ram_data,       // Data lines (output)
                        ram_data,       // Data lines (output)
                        { o_ram_udqm, o_ram_ldqm },
                        { o_ram_udqm, o_ram_ldqm },
                        // GPIO
                        // GPIO
                        i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart
                        i_gpio, o_gpio, o_pwm, i_rx_uart, o_tx_uart
                );
                );
 
 
        assign io_ram_data = (ram_drive_data) ? ram_data : 16'bzzzz_zzzz_zzzz_zzzz;
        assign io_ram_data = (ram_drive_data) ? ram_data : 16'bzzzz_zzzz_zzzz_zzzz;
 
 
        reg     [15:0]   r_ram_data_ext_clk;
        reg     [15:0]   r_ram_data_ext_clk;
        // always @(posedge intermediate_clk_n)
        // always @(posedge intermediate_clk_n)
        always @(posedge clk_s)
        always @(posedge clk_s)
                r_ram_data_ext_clk <= io_ram_data;
                r_ram_data_ext_clk <= io_ram_data;
        always @(posedge clk_s)
        always @(posedge clk_s)
                r_ram_data <= r_ram_data_ext_clk;
                r_ram_data <= r_ram_data_ext_clk;
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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