//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
////
|
////
|
////
|
////
|
//// TOP I2C BLOCK to I2C Core
|
//// TOP I2C BLOCK to I2C Core
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This file is part of the APB to I2C project
|
//// This file is part of the APB to I2C project
|
////
|
////
|
//// http://www.opencores.org/cores/apbi2c/
|
//// http://www.opencores.org/cores/apbi2c/
|
////
|
////
|
////
|
////
|
////
|
////
|
//// Description
|
//// Description
|
////
|
////
|
//// Implementation of APB IP core according to
|
//// Implementation of APB IP core according to
|
////
|
////
|
//// apbi2c_spec IP core specification document.
|
//// apbi2c_spec IP core specification document.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// To Do: Things are right here but always all block can suffer changes
|
//// To Do: Things are right here but always all block can suffer changes
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
////
|
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
|
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
|
//// Ronal Dario Celaya
|
//// Ronal Dario Celaya
|
////
|
////
|
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
////
|
////
|
////
|
////
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This source file may be used and distributed without
|
//// This source file may be used and distributed without
|
////
|
////
|
//// restriction provided that this copyright statement is not
|
//// restriction provided that this copyright statement is not
|
////
|
////
|
//// removed from the file and that any derivative work contains
|
//// removed from the file and that any derivative work contains
|
//// the original copyright notice and the associated disclaimer.
|
//// the original copyright notice and the associated disclaimer.
|
////
|
////
|
////
|
////
|
//// This source file is free software; you can redistribute it
|
//// This source file is free software; you can redistribute it
|
////
|
////
|
//// and/or modify it under the terms of the GNU Lesser General
|
//// and/or modify it under the terms of the GNU Lesser General
|
////
|
////
|
//// Public License as published by the Free Software Foundation;
|
//// Public License as published by the Free Software Foundation;
|
//// either version 2.1 of the License, or (at your option) any
|
//// either version 2.1 of the License, or (at your option) any
|
////
|
////
|
//// later version.
|
//// later version.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// This source is distributed in the hope that it will be
|
//// This source is distributed in the hope that it will be
|
////
|
////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied
|
////
|
////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
////
|
////
|
//// PURPOSE. See the GNU Lesser General Public License for more
|
//// PURPOSE. See the GNU Lesser General Public License for more
|
//// details.
|
//// details.
|
////
|
////
|
////
|
////
|
////
|
////
|
//// You should have received a copy of the GNU Lesser General
|
//// You should have received a copy of the GNU Lesser General
|
////
|
////
|
//// Public License along with this source; if not, download it
|
//// Public License along with this source; if not, download it
|
////
|
////
|
//// from http://www.opencores.org/lgpl.shtml
|
//// from http://www.opencores.org/lgpl.shtml
|
////
|
////
|
////
|
////
|
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
|
|
`timescale 1ns/1ps //timescale
|
`timescale 1ns/1ps //timescale
|
|
|
module i2c(
|
module i2c(
|
//APB PORTS
|
//APB PORTS
|
input PCLK,
|
input PCLK,
|
input PRESETn,
|
input PRESETn,
|
input [31:0] PADDR,
|
input [31:0] PADDR,
|
input [31:0] PWDATA,
|
input [31:0] PWDATA,
|
input PWRITE,
|
input PWRITE,
|
input PSELx,
|
input PSELx,
|
input PENABLE,
|
input PENABLE,
|
output PREADY,
|
output PREADY,
|
output PSLVERR,
|
output PSLVERR,
|
output INT_RX,
|
output INT_RX,
|
output INT_TX,
|
output INT_TX,
|
output [31:0] PRDATA,
|
output [31:0] PRDATA,
|
//I2C OUTPUT
|
//I2C OUTPUT
|
|
output SDA_ENABLE,
|
|
output SCL_ENABLE,
|
inout SDA,
|
inout SDA,
|
inout SCL
|
inout SCL
|
|
|
);
|
);
|
|
|
wire RESET_N;
|
wire RESET_N;
|
|
|
//THIS IS USED TO RESET FIFO
|
//THIS IS USED TO RESET FIFO
|
assign RESET_N = (PRESETn == 0)?1'b1:1'b0;
|
assign RESET_N = (PRESETn == 0)?1'b1:1'b0;
|
|
|
//WIRES USED TO CONECT BLOCK WITH EACH OTHER
|
//WIRES USED TO CONECT BLOCK WITH EACH OTHER
|
wire TX_RD_EN;
|
wire TX_RD_EN;
|
wire TX_F_EMPTY;
|
wire TX_F_EMPTY;
|
wire TX_F_FULL;
|
wire TX_F_FULL;
|
wire [31:0] TX_DATA_IN;
|
wire [31:0] TX_DATA_IN;
|
wire [31:0] TX_DATA_OUT;
|
wire [31:0] TX_DATA_OUT;
|
wire TX_WRITE_ENA;
|
wire TX_WRITE_ENA;
|
|
|
wire RX_RD_EN;
|
wire RX_RD_EN;
|
wire RX_F_EMPTY;
|
wire RX_F_EMPTY;
|
wire RX_F_FULL;
|
wire RX_F_FULL;
|
wire [31:0] RX_DATA_IN;
|
wire [31:0] RX_DATA_IN;
|
wire [31:0] RX_DATA_OUT;
|
wire [31:0] RX_DATA_OUT;
|
wire RX_WRITE_ENA;
|
wire RX_WRITE_ENA;
|
|
|
|
|
wire [13:0] REGISTER_CONFIG;
|
wire [13:0] REGISTER_CONFIG;
|
|
wire [13:0] TIMEOUT_CONFIG;
|
|
|
|
|
wire error;
|
wire error;
|
|
|
|
|
wire tx_empty;
|
wire tx_empty;
|
wire rx_empty;
|
wire rx_empty;
|
|
|
//wire w_pwrite;
|
//wire w_pwrite;
|
wire w_full;
|
wire w_full;
|
//wire w_full_tx;
|
//wire w_full_tx;
|
|
|
//assign w_pwrite = (PWRITE == 1'b0)?1'b1:1'b0;
|
//assign w_pwrite = (PWRITE == 1'b0)?1'b1:1'b0;
|
|
|
|
|
|
|
//CONECTIONS WITH FIFO TX
|
//CONECTIONS WITH FIFO TX
|
fifo DUT_FIFO_TX (
|
fifo DUT_FIFO_TX (
|
.clock(PCLK),
|
.clock(PCLK),
|
.reset(RESET_N),
|
.reset(RESET_N),
|
.wr_en(TX_WRITE_ENA),
|
.wr_en(TX_WRITE_ENA),
|
.rd_en(TX_RD_EN),
|
.rd_en(TX_RD_EN),
|
.data_in(TX_DATA_IN),
|
.data_in(TX_DATA_IN),
|
.f_full(w_full),
|
.f_full(w_full),
|
.f_empty(TX_F_EMPTY),
|
.f_empty(TX_F_EMPTY),
|
.data_out(TX_DATA_OUT)
|
.data_out(TX_DATA_OUT)
|
);
|
);
|
|
|
|
|
//and(w_full_tx,w_pwrite,w_full);
|
//and(w_full_tx,w_pwrite,w_full);
|
|
|
assign TX_F_FULL = w_full;
|
assign TX_F_FULL = w_full;
|
|
|
//CONECTIONS WITH FIFO RX
|
//CONECTIONS WITH FIFO RX
|
fifo DUT_FIFO_RX (
|
fifo DUT_FIFO_RX (
|
.clock(PCLK),
|
.clock(PCLK),
|
.reset(RESET_N),
|
.reset(RESET_N),
|
.wr_en(RX_WRITE_ENA),
|
.wr_en(RX_WRITE_ENA),
|
.rd_en(RX_RD_EN),
|
.rd_en(RX_RD_EN),
|
.data_in(RX_DATA_IN),
|
.data_in(RX_DATA_IN),
|
.f_full(RX_F_FULL),
|
.f_full(RX_F_FULL),
|
.f_empty(RX_F_EMPTY),
|
.f_empty(RX_F_EMPTY),
|
.data_out(RX_DATA_OUT)
|
.data_out(RX_DATA_OUT)
|
);
|
);
|
|
|
//CONECTIONS WITH APB AND ALL BLOCKS WHERE IS TWO FIFOS AND I2C CORE
|
//CONECTIONS WITH APB AND ALL BLOCKS WHERE IS TWO FIFOS AND I2C CORE
|
apb DUT_APB (
|
apb DUT_APB (
|
|
|
.PCLK(PCLK),
|
.PCLK(PCLK),
|
.PRESETn(PRESETn),
|
.PRESETn(PRESETn),
|
.PADDR(PADDR),
|
.PADDR(PADDR),
|
.PRDATA(PRDATA),
|
.PRDATA(PRDATA),
|
.PWDATA(PWDATA),
|
.PWDATA(PWDATA),
|
.PWRITE(PWRITE),
|
.PWRITE(PWRITE),
|
.PSELx(PSELx),
|
.PSELx(PSELx),
|
.PENABLE(PENABLE),
|
.PENABLE(PENABLE),
|
.PREADY(PREADY),
|
.PREADY(PREADY),
|
.PSLVERR(PSLVERR),
|
.PSLVERR(PSLVERR),
|
.READ_DATA_ON_RX(RX_DATA_OUT),
|
.READ_DATA_ON_RX(RX_DATA_OUT),
|
.INTERNAL_I2C_REGISTER_CONFIG(REGISTER_CONFIG),
|
.INTERNAL_I2C_REGISTER_CONFIG(REGISTER_CONFIG),
|
|
.INTERNAL_I2C_REGISTER_TIMEOUT(TIMEOUT_CONFIG),
|
.INT_RX(INT_RX),
|
.INT_RX(INT_RX),
|
.WR_ENA(TX_WRITE_ENA),
|
.WR_ENA(TX_WRITE_ENA),
|
.WRITE_DATA_ON_TX(TX_DATA_IN),
|
.WRITE_DATA_ON_TX(TX_DATA_IN),
|
.RD_ENA(RX_RD_EN),
|
.RD_ENA(RX_RD_EN),
|
.INT_TX(INT_TX),
|
.INT_TX(INT_TX),
|
.TX_EMPTY(tx_empty),
|
.TX_EMPTY(tx_empty),
|
.RX_EMPTY(rx_empty),
|
.RX_EMPTY(rx_empty),
|
.ERROR(error)
|
.ERROR(error)
|
|
|
);
|
);
|
|
|
//I2C CORE BLOCK WITH ALL ANOTHER BLOCKS
|
//I2C CORE BLOCK WITH ALL ANOTHER BLOCKS
|
module_i2c DUT_I2C_INTERNAL (
|
module_i2c DUT_I2C_INTERNAL_RX_TX (
|
.PCLK(PCLK),
|
.PCLK(PCLK),
|
.PRESETn(PRESETn),
|
.PRESETn(PRESETn),
|
.fifo_tx_rd_en(TX_RD_EN),
|
|
.fifo_tx_f_full(TX_F_FULL),
|
|
.fifo_tx_f_empty(TX_F_EMPTY),
|
|
.fifo_tx_data_out(TX_DATA_OUT),
|
|
.fifo_rx_wr_en(RX_WRITE_ENA),
|
.fifo_rx_wr_en(RX_WRITE_ENA),
|
.fifo_rx_f_empty(RX_F_EMPTY),
|
.fifo_rx_f_empty(RX_F_EMPTY),
|
.fifo_rx_data_in(RX_DATA_IN),
|
.fifo_rx_data_in(RX_DATA_IN),
|
.fifo_rx_f_full(RX_F_FULL),
|
.fifo_rx_f_full(RX_F_FULL),
|
|
.fifo_tx_f_full(TX_F_FULL),
|
|
.fifo_tx_f_empty(TX_F_EMPTY),
|
|
.fifo_tx_rd_en(TX_RD_EN),
|
|
.fifo_tx_data_out(TX_DATA_OUT),
|
.DATA_CONFIG_REG(REGISTER_CONFIG),
|
.DATA_CONFIG_REG(REGISTER_CONFIG),
|
.TX_EMPTY(tx_empty),
|
.TIMEOUT_TX(TIMEOUT_CONFIG),
|
.RX_EMPTY(rx_empty),
|
.RX_EMPTY(rx_empty),
|
|
.TX_EMPTY(tx_empty),
|
.ERROR(error),
|
.ERROR(error),
|
|
.ENABLE_SDA(SDA_ENABLE),
|
|
.ENABLE_SCL(SCL_ENABLE),
|
.SDA(SDA),
|
.SDA(SDA),
|
.SCL(SCL)
|
.SCL(SCL)
|
);
|
);
|
|
|
endmodule
|
endmodule
|
|
|