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

Subversion Repositories spimaster

[/] [spimaster/] [trunk/] [model/] [sdModel.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
`include "timescale.v"
2
 
3
module sdModel(
4
  spiClk,
5
  spiDataIn,
6
  spiDataOut,
7
  spiCS_n
8
);
9
input spiClk;
10
input spiDataIn;
11
output spiDataOut;
12
reg spiDataOut;
13
input spiCS_n;
14
 
15
//local wires and regs
16
reg [7:0] rxByte;
17
reg [7:0] respByte;
18
reg [1:0] smSt;
19
reg [7:0] cnt;
20
 
21
`define START 2'b00
22
`define WAIT_FF 2'b01
23
`define WAIT_FF_FIN 2'b10
24
 
25
initial
26
begin
27
  smSt = `START;
28
end
29
 
30
 
31
// ------------------------------ txRxByte --------------------------
32
task txRxByte;
33
input [7:0] txData;
34
output [7:0] rxData;
35
 
36
integer i;
37
begin
38
  spiDataOut <= txData[7];
39
  //@(negedge spiCS_n);
40
  for (i=0;i<=7;i=i+1) begin
41
    @(posedge spiClk);
42
    rxData[0] <= spiDataIn;
43
    rxData = rxData << 1;
44
    @(negedge spiClk);
45
    spiDataOut <= txData[6];
46
    txData = txData << 1;
47
  end
48
end
49
endtask
50
 
51
 
52
//response state machine
53
always begin
54
    case (smSt)
55
      `START: begin
56
        txRxByte(8'hff, rxByte);
57
        if (rxByte == 8'hff) begin
58
          smSt <= `WAIT_FF;
59
          cnt <= 8'h00;
60
        end
61
      end
62
      `WAIT_FF: begin
63
        txRxByte(8'hff, rxByte);
64
        if (rxByte == 8'hff) begin
65
          cnt <= cnt + 1'b1;
66
          if (cnt == 8'h04) begin
67
            txRxByte(respByte, rxByte);
68
            smSt <= `WAIT_FF_FIN;
69
          end
70
        end
71
        else begin
72
          smSt <= `START;
73
          cnt <= 8'h00;
74
        end
75
      end
76
      `WAIT_FF_FIN: begin
77
        txRxByte(8'hff, rxByte);
78
        if (rxByte == 8'h04) begin
79
          cnt <= cnt + 1'b1;
80
          if (cnt == 8'hff) begin
81
            txRxByte(respByte, rxByte);
82
            smSt <= `START;
83
          end
84
        end
85
        else
86
          smSt <= `START;
87
      end
88
    endcase
89
end
90
 
91
// setRespByte
92
task setRespByte;
93
  input [7:0] dataByte;
94
  begin
95
    respByte = dataByte;
96
  end
97
endtask
98
 
99
endmodule

powered by: WebSVN 2.1.0

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