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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [spi/] [spi_if.v] - Blame information for rev 7

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

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

powered by: WebSVN 2.1.0

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