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

Subversion Repositories spigpio

[/] [spigpio/] [trunk/] [rtl/] [verilog/] [spigpio.v] - Diff between revs 4 and 5

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 5
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
//// SPI GPIO IP Core                                             ////
//// SPI GPIO IP Core                                             ////
////                                                              ////
////                                                              ////
//// This file is part of the spigpio project                     ////
//// This file is part of the spigpio project                     ////
//// http://www.opencores.org/project,spislave                    ////
//// http://www.opencores.org/project,spislave                    ////
////                                                              ////
////                                                              ////
//// Description                                                  ////
//// Description                                                  ////
//// Implementation of spislave IP core according to              ////
//// Implementation of spislave IP core according to              ////
//// spigpio IP core specification document.                      ////
//// spigpio IP core specification document.                      ////
////                                                              ////
////                                                              ////
//// To Do:                                                       ////
//// To Do:                                                       ////
////   -                                                          ////
////   -                                                          ////
////                                                              ////
////                                                              ////
//// Author(s):                                                   ////
//// Author(s):                                                   ////
////      - Sivakumar.B , email: siva@zilogic.com                 ////
////      - Sivakumar.B , email: siva@zilogic.com                 ////
////                      email: siva12@opencores.org             ////
////                      email: siva12@opencores.org             ////
////        Engineer  Zilogic systems,chennai. www.zilogic.com    ////
////        Engineer  Zilogic systems,chennai. www.zilogic.com    ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
//// Copyright (C) 2009 Zilogic Systems and OPENCORES.ORG         ////
//// Copyright (C) 2009 Zilogic Systems 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                     ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////       RTL program for SPI SLAVE -- shift 8 bit register       ////  
////       RTL program for SPI GPIO --                            ////  
 
 
`define         P0_OP           7'b0000000 //0x00
`define         P0_OP           7'b0000000 //0x00
`define         P1_OP           7'b0000001 //0x01
`define         P1_OP           7'b0000001 //0x01
`define         P2_OP           7'b0000010 //0x02
`define         P2_OP           7'b0000010 //0x02
`define         P3_OP           7'b0000011 //0x03
`define         P3_OP           7'b0000011 //0x03
`define         P4_OP           7'b0000100 //0x04
`define         P4_OP           7'b0000100 //0x04
`define         P5_OP           7'b0000101 //0x05
`define         P5_OP           7'b0000101 //0x05
`define         P6_OP           7'b0000110 //0x06
`define         P6_OP           7'b0000110 //0x06
`define         P7_OP           7'b0000111 //0x07
`define         P7_OP           7'b0000111 //0x07
`define         P8_OP           7'b0001000 //0x08
`define         P8_OP           7'b0001000 //0x08
`define         P9_OP           7'b0001001 //0x09
`define         P9_OP           7'b0001001 //0x09
 
 
`define         P0_P9_OP        7'b0001010 //0x0A
`define         P0_P9_OP        7'b0001010 //0x0A
`define         P0_P3_OP        7'b0001011 //0x0B
`define         P0_P3_OP        7'b0001011 //0x0B
`define         P4_P7_OP        7'b0001100 //0x0C
`define         P4_P7_OP        7'b0001100 //0x0C
`define         P8_P9_OP        7'b0001101 //0x0D
`define         P8_P9_OP        7'b0001101 //0x0D
 
 
`define         PO_P7_IP        7'b0001110 //0x0E       
`define         PO_P7_IP        7'b0001110 //0x0E       
`define         P8_P9_IP        7'b0001111 //0x0F
`define         P8_P9_IP        7'b0001111 //0x0F
 
 
`define         RAM             7'b0010011 //0x13
`define         RAM             7'b0010011 //0x13
 
 
module spigpio(clk, cs, sr_in, gpioin, gpioout, sr_out);
module spigpio(clk, cs, sr_in, gpioin, gpioout, sr_out);
 
 
        input clk, cs;
        input clk, cs;
        input sr_in;
        input sr_in;
        input [9:0] gpioin;
        input [9:0] gpioin;
 
 
        output sr_out;
        output sr_out;
        output [9:0] gpioout;
        output [9:0] gpioout;
 
 
        reg [9:0] gpioout;
        reg [9:0] gpioout;
        reg sr_out;
        reg sr_out;
 
 
        reg [7:0] ram;
        reg [7:0] ram;
        wire [6:0] addr;
        wire [6:0] addr;
        wire [7:0] data;
        wire [7:0] data;
        wire rw;
        wire rw;
        reg [15:0] sr;
        reg [15:0] sr;
 
 
        assign rw = sr[15];
        assign rw = sr[15];
        assign addr = sr[14:8];
        assign addr = sr[14:8];
        assign data = sr[7:0];
        assign data = sr[7:0];
 
 
        always@(posedge clk or posedge cs)
        always@(posedge clk or posedge cs)
        begin
        begin
                if (cs == 1'b0)
                if (cs == 1'b0)
                begin
                begin
                        sr_out <= sr[15];
                        sr_out <= sr[15];
                        sr[15:1] <= sr[14:0];
                        sr[15:1] <= sr[14:0];
                        sr[0] <= sr_in;
                        sr[0] <= sr_in;
                end
                end
 
 
                if (cs == 1'b1)
                if (cs == 1'b1)
                begin
                begin
 
 
                        if (rw == 1'b0)
                        if (rw == 1'b0)
                        begin
                        begin
 
 
                                case (addr)
                                case (addr)
                                `P0_OP    : gpioout[0] <= data[0];
                                `P0_OP    : gpioout[0] <= data[0];
                                `P1_OP    : gpioout[1] <= data[0];
                                `P1_OP    : gpioout[1] <= data[0];
                                `P2_OP    : gpioout[2] <= data[0];
                                `P2_OP    : gpioout[2] <= data[0];
                                `P3_OP    : gpioout[3] <= data[0];
                                `P3_OP    : gpioout[3] <= data[0];
                                `P4_OP    : gpioout[4] <= data[0];
                                `P4_OP    : gpioout[4] <= data[0];
                                `P5_OP    : gpioout[5] <= data[0];
                                `P5_OP    : gpioout[5] <= data[0];
                                `P6_OP    : gpioout[6] <= data[0];
                                `P6_OP    : gpioout[6] <= data[0];
                                `P7_OP    : gpioout[7] <= data[0];
                                `P7_OP    : gpioout[7] <= data[0];
                                `P8_OP    : gpioout[8] <= data[0];
                                `P8_OP    : gpioout[8] <= data[0];
                                `P9_OP    : gpioout[9] <= data[0];
                                `P9_OP    : gpioout[9] <= data[0];
 
 
                                `P0_P9_OP : gpioout[9:0] <= {data[0], data[0], data[0], data[0], data[0],
                                `P0_P9_OP : gpioout[9:0] <= {data[0], data[0], data[0], data[0], data[0],
                                                             data[0], data[0], data[0], data[0], data[0]};
                                                             data[0], data[0], data[0], data[0], data[0]};
                                `P0_P3_OP : gpioout[3:0] <= {data[0], data[0], data[0], data[0]};
                                `P0_P3_OP : gpioout[3:0] <= {data[0], data[0], data[0], data[0]};
                                `P4_P7_OP : gpioout[7:4] <= {data[0], data[0], data[0], data[0]};
                                `P4_P7_OP : gpioout[7:4] <= {data[0], data[0], data[0], data[0]};
                                `P8_P9_OP : gpioout[9:8] <= {data[0], data[0]};
                                `P8_P9_OP : gpioout[9:8] <= {data[0], data[0]};
                                `RAM      : ram[7:0] <= data[7:0];
                                `RAM      : ram[7:0] <= data[7:0];
                                endcase
                                endcase
                        end
                        end
 
 
                        if (rw == 1'b1)             // READ THE PORT LEVEL
                        if (rw == 1'b1)             // READ THE PORT LEVEL
                        begin
                        begin
 
 
                                case (addr)
                                case (addr)
                                `P0_OP    : sr[7:0] <= {7'b0, gpioout[0]};
                                `P0_OP    : sr[7:0] <= {7'b0, gpioout[0]};
                                `P1_OP    : sr[7:0] <= {7'b0, gpioout[1]};
                                `P1_OP    : sr[7:0] <= {7'b0, gpioout[1]};
                                `P2_OP    : sr[7:0] <= {7'b0, gpioout[2]};
                                `P2_OP    : sr[7:0] <= {7'b0, gpioout[2]};
                                `P3_OP    : sr[7:0] <= {7'b0, gpioout[3]};
                                `P3_OP    : sr[7:0] <= {7'b0, gpioout[3]};
                                `P4_OP    : sr[7:0] <= {7'b0, gpioout[4]};
                                `P4_OP    : sr[7:0] <= {7'b0, gpioout[4]};
                                `P5_OP    : sr[7:0] <= {7'b0, gpioout[5]};
                                `P5_OP    : sr[7:0] <= {7'b0, gpioout[5]};
                                `P6_OP    : sr[7:0] <= {7'b0, gpioout[6]};
                                `P6_OP    : sr[7:0] <= {7'b0, gpioout[6]};
                                `P7_OP    : sr[7:0] <= {7'b0, gpioout[7]};
                                `P7_OP    : sr[7:0] <= {7'b0, gpioout[7]};
                                `P8_OP    : sr[7:0] <= {7'b0, gpioout[8]};
                                `P8_OP    : sr[7:0] <= {7'b0, gpioout[8]};
                                `P9_OP    : sr[7:0] <= {7'b0, gpioout[9]};
                                `P9_OP    : sr[7:0] <= {7'b0, gpioout[9]};
                                `P0_P9_OP : sr[7:0] <= {7'b0, gpioout[0]};
                                `P0_P9_OP : sr[7:0] <= {7'b0, gpioout[0]};
                                `P0_P3_OP : sr[7:0] <= {7'b0, gpioout[0]};
                                `P0_P3_OP : sr[7:0] <= {7'b0, gpioout[0]};
                                `P4_P7_OP : sr[7:0] <= {7'b0, gpioout[4]};
                                `P4_P7_OP : sr[7:0] <= {7'b0, gpioout[4]};
                                `P8_P9_OP : sr[7:0] <= {7'b0, gpioout[8]};
                                `P8_P9_OP : sr[7:0] <= {7'b0, gpioout[8]};
                                `PO_P7_IP : sr[7:0] <= gpioin[7:0];
                                `PO_P7_IP : sr[7:0] <= gpioin[7:0];
                                `P8_P9_IP : sr[7:0] <= gpioin[9:8];
                                `P8_P9_IP : sr[7:0] <= gpioin[9:8];
                                `RAM      : sr[7:0] <= ram[7:0];
                                `RAM      : sr[7:0] <= ram[7:0];
                                endcase
                                endcase
                        end
                        end
                end
                end
        end
        end
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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