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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [spi/] [spi_if.v] - Blame information for rev 37

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OMS 8051 cores SPI Interface Module                         ////
4
////                                                              ////
5
////  This file is part of the OMS 8051 cores project             ////
6
////  http://www.opencores.org/cores/oms8051/                     ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  OMS 8051 definitions.                                       ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
////  Revision : Nov 26, 2016                                      //// 
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
 
46
module spi_if
47
          (
48
           clk,
49
           reset_n,
50
 
51
           // towards ctrl i/f
52
           sck_pe,
53
           sck_int,
54
           cs_int_n,
55
           byte_in,
56
           load_byte,
57
           byte_out,
58
           shift_out,
59
           shift_in,
60
 
61
           cfg_tgt_sel,
62
 
63
           sck,
64
           so,
65
           si,
66
           cs_n
67
           );
68
 
69
  input clk,reset_n;
70
  input sck_pe;
71
  input sck_int,cs_int_n;
72
 
73
  input       load_byte;
74
  input [1:0] cfg_tgt_sel;
75
 
76
  input [7:0] byte_out;
77
  input       shift_out,shift_in;
78
 
79
  output [7:0] byte_in;
80
  output       sck,so;
81
  output [3:0] cs_n;
82
  input        si;
83
 
84
 
85
  reg [7:0]    so_reg;
86
  reg [7:0]    si_reg;
87
  wire [7:0]   byte_out;
88
  wire         sck;
89
  reg          so;
90
  wire [3:0]   cs_n;
91
 
92
 
93
  //Output Shift Register
94
 
95
  always @(posedge clk or negedge reset_n) begin
96
     if(!reset_n) begin
97
        so_reg <= 8'h00;
98
        so <= 1'b0;
99
     end
100
     else begin
101
        if(load_byte) begin
102
           so_reg <= byte_out;
103
           if(shift_out) begin
104
              // Handling backto back case : 
105
              // Last Transfer bit + New Trasfer Load
106
              so <= so_reg[7];
107
           end
108
        end // if (load_byte)
109
        else begin
110
           if(shift_out) begin
111
              so <= so_reg[7];
112
              so_reg <= {so_reg[6:0],1'b0};
113
           end // if (shift_out)
114
        end // else: !if(load_byte)
115
     end // else: !if(!reset_n)
116
  end // always @ (posedge clk or negedge reset_n)
117
 
118
 
119
// Input shift register
120
  always @(posedge clk or negedge reset_n) begin
121
     if(!reset_n) begin
122
        si_reg <= 8'h0;
123
     end
124
     else begin
125
        if(sck_pe & shift_in) begin
126
           si_reg[7:0] <= {si_reg[6:0],si};
127
        end // if (sck_pe & shift_in)
128
     end // else: !if(!reset_n)
129
  end // always @ (posedge clk or negedge reset_n)
130
 
131
 
132
  assign byte_in[7:0] = si_reg[7:0];
133
  assign cs_n[0] = (cfg_tgt_sel[1:0] == 2'b00) ? cs_int_n : 1'b1;
134
  assign cs_n[1] = (cfg_tgt_sel[1:0] == 2'b01) ? cs_int_n : 1'b1;
135
  assign cs_n[2] = (cfg_tgt_sel[1:0] == 2'b10) ? cs_int_n : 1'b1;
136
  assign cs_n[3] = (cfg_tgt_sel[1:0] == 2'b11) ? cs_int_n : 1'b1;
137
  assign sck = sck_int;
138
 
139
endmodule

powered by: WebSVN 2.1.0

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