Files
BSI-901-fpga-software/c64_pro.srcs/sources_1/rtl/pl_top.v
T
2024-10-28 13:14:49 +08:00

438 lines
14 KiB
Verilog

`timescale 1 ns / 1 ps
module pl_top#
(
parameter VERSION = 32'h10000001 ,
parameter CLK_FREQ = 100 ,
parameter CLK_PERIOD = 10 ,
//----------------------------------------- RHS2116
parameter RSH2116_QTY = 4 ,
parameter RHS2116_SPI_CLK_DIV = 4 ,
parameter RSH2116_SPI_PERIOD = 1500 ,
//----------------------------------------- ADS1299
parameter ADS1299_QTY = 8 ,
parameter ADS1299_CH = 8 ,
parameter ADS1299_SPI_CLK_DIV = 4 ,
parameter ADS1299_SPI_QTY = 4 ,
parameter ADS1299_SPI_SLAVE_QTY = 2 ,
parameter ADS1299_SPI_PERIOD = 2000
)
(
input clk ,
input rst_n ,
//--------------------------------------------- PS:
input [12:0] bram_stim_addr ,
input bram_stim_clk ,
input [31:0] bram_stim_din ,
output [31:0] bram_stim_dout ,
input bram_stim_en ,
input bram_stim_rst ,
input [ 3:0] bram_stim_we ,
input [12:0] bram_eeg_addr ,
input bram_eeg_clk ,
input [31:0] bram_eeg_din ,
output [31:0] bram_eeg_dout ,
input bram_eeg_en ,
input bram_eeg_rst ,
input [ 3:0] bram_eeg_we ,
input [12:0] bram_emg_addr ,
input bram_emg_clk ,
input [31:0] bram_emg_din ,
output [31:0] bram_emg_dout ,
input bram_emg_en ,
input bram_emg_rst ,
input [ 3:0] bram_emg_we ,
input [12:0] bram_accel_addr ,
input bram_accel_clk ,
input [31:0] bram_accel_din ,
output [31:0] bram_accel_dout ,
input bram_accel_en ,
input bram_accel_rst ,
input [ 3:0] bram_accel_we ,
input [12:0] bram_msg_addr ,
input bram_msg_clk ,
input [31:0] bram_msg_din ,
output [31:0] bram_msg_dout ,
input bram_msg_en ,
input bram_msg_rst ,
input [ 3:0] bram_msg_we ,
//--------------------------------------------- interrupt
output stim_int ,
output eeg_int ,
output emg_int ,
output accel_int ,
input [31:0] m_axis_stim_tdata ,
input m_axis_stim_tlast ,
output m_axis_stim_tready ,
input m_axis_stim_tvalid ,
input m_axis_record_tfull ,
output [ 7:0] m_axis_record_tdata ,
output [ 0:0] m_axis_record_tkeep ,
output m_axis_record_tlast ,
input m_axis_record_tready ,
output m_axis_record_tvalid ,
//--------------------------------------------- RSH2116
output [RSH2116_QTY-1:0] rsh2116_enable ,
output [RSH2116_QTY-1:0] rsh2116_spi_cs ,
output [RSH2116_QTY-1:0] rsh2116_spi_sclk ,
output [RSH2116_QTY-1:0] rsh2116_spi_mosi ,
input [RSH2116_QTY-1:0] rsh2116_spi_miso ,
//--------------------------------------------- ADS1299 for EEG
output [ADS1299_QTY-1:0] eeg_ads1299_spi_cs ,
output [ 4-1:0] eeg_ads1299_spi_sclk ,
output [ 4-1:0] eeg_ads1299_spi_mosi ,
input [ 4-1:0] eeg_ads1299_spi_miso ,
input [ 4-1:0] eeg_ads1299_drdy_n ,
output eeg_ads1299_start ,
//--------------------------------------------- ADS1299 for EMG
output emg_ads1299_spi_cs ,
output emg_ads1299_spi_sclk ,
output emg_ads1299_spi_mosi ,
input emg_ads1299_spi_miso ,
input emg_ads1299_drdy_n ,
output emg_ads1299_start ,
output emg_ads1299_reset_n ,
output emg_ads1299_pwdn_n ,
//------------------------------------------ device: MEMS
output accel_spi_cs ,
output accel_spi_sclk ,
output accel_spi_mosi ,
input accel_spi_miso ,
input accel_int0 ,
input accel_int1 ,
//--------------------------------------------- ADG1414
output adg1414_spi_sync ,
output adg1414_spi_sclk ,
output adg1414_spi_mosi ,
input adg1414_spi_miso ,
//--------------------------------------------- Trigger
input trigger_reset ,
input [32-1:0] trigger_in ,
output [32-1:0] trigger_out ,
//--------------------------------------------- For developer
output [ 4-1:0] debug_sig
);
//*****************************************************************************
// Parameter definition
//*****************************************************************************
//*****************************************************************************
// Internal register and wire declarations
//*****************************************************************************
wire [32-1:0] trigger_in_int ;
wire [32-1:0] trigger_in_ext ;
wire [32-1:0] axis_trigger_tdata ;
wire axis_trigger_tvalid ;
wire axis_trigger_tready ;
wire [32-1:0] axis_eeg16_tdata ;
wire axis_eeg16_tlast ;
wire axis_eeg16_tready ;
wire axis_eeg16_tvalid ;
wire [32-1:0] axis_eeg24_tdata ;
wire axis_eeg24_tlast ;
wire axis_eeg24_tready ;
wire axis_eeg24_tvalid ;
wire [32-1:0] axis_emg_tdata ;
wire axis_emg_tlast ;
wire axis_emg_tready ;
wire axis_emg_tvalid ;
wire [48-1:0] accel_data ;
wire sw_enable ;
wire sw_data_sel ;
wire [64-1:0] sw_data_0 ;
wire [64-1:0] sw_data_1 ;
wire [64-1:0] sw_state ;
wire [ 4-1:0] debug_sig_2116 ;
wire [ 4-1:0] debug_sig_eeg ;
wire [ 4-1:0] debug_sig_msg ;
//*****************************************************************************
// Instantiation
//*****************************************************************************
trigger_top#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_trigger_top
(
.clk ( clk ),
.rst_n ( rst_n ),
.trigger_reset ( trigger_reset ),
.trigger_in_int ( trigger_in_int ),
.trigger_in_ext ( trigger_in_ext ),
.m_trigger_tdata ( axis_trigger_tdata ),
.m_trigger_tvalid ( axis_trigger_tvalid ),
.m_trigger_tready ( axis_trigger_tready ),
.error_overflow ( )
);
rhs2116_top#
(
.CLK_PERIOD ( CLK_PERIOD ),
.VERSION ( VERSION ),
.SPI_CLK_DIV ( RHS2116_SPI_CLK_DIV ),
.CHIPSET_QTY ( RSH2116_QTY ),
.SPI_TRANS_PERIOD ( RSH2116_SPI_PERIOD )
)
u_rhs2116_top
(
.clk ( clk ),
.rst_n ( rst_n ),
.bram_addr ( bram_stim_addr ),
.bram_clk ( bram_stim_clk ),
.bram_din ( bram_stim_din ),
.bram_dout ( bram_stim_dout ),
.bram_en ( bram_stim_en ),
.bram_rst ( bram_stim_rst ),
.bram_we ( bram_stim_we ),
.interrupt ( stim_int ),
.stim_event_code ( trigger_in_int ),
//------------------------------------------ FIFO: stim input and record output
.axi_str_txd_tdata ( m_axis_stim_tdata ),
.axi_str_txd_tlast ( m_axis_stim_tlast ),
.axi_str_txd_tready ( m_axis_stim_tready ),
.axi_str_txd_tvalid ( m_axis_stim_tvalid ),
.axi_str_rxd_tdata ( axis_eeg16_tdata ),
.axi_str_rxd_tlast ( axis_eeg16_tlast ),
.axi_str_rxd_tready ( axis_eeg16_tready ),
.axi_str_rxd_tvalid ( axis_eeg16_tvalid ),
//------------------------------------------ channel stim state
.sw_enable ( sw_enable ),
.sw_data_sel ( sw_data_sel ),
.sw_data_0 ( sw_data_0 ),
.sw_data_1 ( sw_data_1 ),
.sw_state ( sw_state ),
//------------------------------------------ device
.stim_en ( rsh2116_enable ),
.cs ( rsh2116_spi_cs ),
.sclk ( rsh2116_spi_sclk ),
.mosi ( rsh2116_spi_mosi ),
.miso ( rsh2116_spi_miso ),
.debug_sig ( debug_sig_2116 )
);
eeg_top#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_eeg_top
(
.clk ( clk ),
.rst_n ( rst_n ),
.bram_addr ( bram_eeg_addr ),
.bram_clk ( bram_eeg_clk ),
.bram_din ( bram_eeg_din ),
.bram_dout ( bram_eeg_dout ),
.bram_en ( bram_eeg_en ),
.bram_rst ( bram_eeg_rst ),
.bram_we ( bram_eeg_we ),
.interrupt ( eeg_int ),
//------------------------------------------ FIFO: eeg output
.axis_record_tdata ( axis_eeg24_tdata ),
.axis_record_tlast ( axis_eeg24_tlast ),
.axis_record_tready ( axis_eeg24_tready ),
.axis_record_tvalid ( axis_eeg24_tvalid ),
//------------------------------------------ device spi
.cs ( eeg_ads1299_spi_cs ),
.sclk ( eeg_ads1299_spi_sclk ),
.mosi ( eeg_ads1299_spi_mosi ),
.miso ( eeg_ads1299_spi_miso ),
.drdy ( eeg_ads1299_drdy_n ),
.start ( eeg_ads1299_start ),
//------------------------------------------ debug signal
.debug_sig ( debug_sig_eeg )
);
emg_top#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_emg_top
(
.clk ( clk ),
.rst_n ( rst_n ),
.bram_addr ( bram_emg_addr ),
.bram_clk ( bram_emg_clk ),
.bram_din ( bram_emg_din ),
.bram_dout ( bram_emg_dout ),
.bram_en ( bram_emg_en ),
.bram_rst ( bram_emg_rst ),
.bram_we ( bram_emg_we ),
.interrupt ( emg_int ),
//------------------------------------------ FIFO: emg output
.axis_txd_tdata ( axis_emg_tdata ),
.axis_txd_tlast ( axis_emg_tlast ),
.axis_txd_tready ( axis_emg_tready ),
.axis_txd_tvalid ( axis_emg_tvalid ),
//------------------------------------------ device interface
.cs ( emg_ads1299_spi_cs ),
.sclk ( emg_ads1299_spi_sclk ),
.mosi ( emg_ads1299_spi_mosi ),
.miso ( emg_ads1299_spi_miso ),
.drdy ( emg_ads1299_drdy_n ),
.start ( emg_ads1299_start ),
.reset_n ( emg_ads1299_reset_n ),
.pwdn_n ( emg_ads1299_pwdn_n )
);
accel_top#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_accel_top
(
.clk ( clk ),
.rst_n ( rst_n ),
.bram_addr ( bram_accel_addr ),
.bram_clk ( bram_accel_clk ),
.bram_din ( bram_accel_din ),
.bram_dout ( bram_accel_dout ),
.bram_en ( bram_accel_en ),
.bram_rst ( bram_accel_rst ),
.bram_we ( bram_accel_we ),
.interrupt ( accel_int ),
.accel_data ( accel_data ),
.accel_spi_cs ( accel_spi_cs ),
.accel_spi_sclk ( accel_spi_sclk ),
.accel_spi_mosi ( accel_spi_mosi ),
.accel_spi_miso ( accel_spi_miso ),
.accel_int0 ( accel_int0 ),
.accel_int1 ( accel_int1 )
);
channel_switch#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_channel_switch
(
.clk ( clk ),
.rst_n ( rst_n ),
.enable ( sw_enable ),
.data_sel ( sw_data_sel ),
.data_0 ( sw_data_0 ),
.data_1 ( sw_data_1 ),
.state ( sw_state ),
.sync ( adg1414_spi_sync ),
.sclk ( adg1414_spi_sclk ),
.sdin ( adg1414_spi_mosi ),
.sdo ( adg1414_spi_miso )
);
upload_top#
(
.CLK_PERIOD ( CLK_PERIOD )
)
u_upload_top
(
.clk ( clk ),
.rst_n ( rst_n ),
//------------------------------------------ config
.bram_addr ( bram_msg_addr ),
.bram_clk ( bram_msg_clk ),
.bram_din ( bram_msg_din ),
.bram_dout ( bram_msg_dout ),
.bram_en ( bram_msg_en ),
.bram_rst ( bram_msg_rst ),
.bram_we ( bram_msg_we ),
//------------------------------------------ recive
.s_axis_trigger_tdata ( axis_trigger_tdata ),
.s_axis_trigger_tvalid ( axis_trigger_tvalid ),
.s_axis_trigger_tready ( axis_trigger_tready ),
.s_axis_eeg16_tdata ( axis_eeg16_tdata ),
.s_axis_eeg16_tlast ( axis_eeg16_tlast ),
.s_axis_eeg16_tready ( axis_eeg16_tready ),
.s_axis_eeg16_tvalid ( axis_eeg16_tvalid ),
.s_axis_eeg24_tdata ( axis_eeg24_tdata ),
.s_axis_eeg24_tlast ( axis_eeg24_tlast ),
.s_axis_eeg24_tready ( axis_eeg24_tready ),
.s_axis_eeg24_tvalid ( axis_eeg24_tvalid ),
.s_axis_emg_tdata ( axis_emg_tdata ),
.s_axis_emg_tlast ( axis_emg_tlast ),
.s_axis_emg_tready ( axis_emg_tready ),
.s_axis_emg_tvalid ( axis_emg_tvalid ),
.accel_data ( accel_data ),
//------------------------------------------ upload
.m_axis_record_tfull ( m_axis_record_tfull ),
.m_axis_record_tdata ( m_axis_record_tdata ),
.m_axis_record_tkeep ( m_axis_record_tkeep ),
.m_axis_record_tlast ( m_axis_record_tlast ),
.m_axis_record_tready ( m_axis_record_tready ),
.m_axis_record_tvalid ( m_axis_record_tvalid ),
//------------------------------------------ debug signal
.debug_sig ( debug_sig_msg )
);
//*****************************************************************************
// Wire assignment
//*****************************************************************************
assign trigger_in_ext = trigger_in;
assign trigger_out = trigger_in_int;
assign debug_sig = debug_sig_2116;
// assign debug_sig[0] = axis_eeg24_tvalid;
// assign debug_sig[1] = axis_eeg24_tlast;
// assign debug_sig[2] = axis_eeg24_tready;
// assign debug_sig[3] = 1'b0;
endmodule