Subversion Repositories ngs

Rev

Rev 99 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 99 Rev 100
Line 5... Line 5...
5
`timescale 1ns/100ps
5
`timescale 1ns/100ps
6
 
6
 
7
module sd
7
module sd
8
(
8
(
9
        input  wire clk,
9
        input  wire clk,
10
        input  wire di,
10
        input  wire sdi,
11
        output wire do
11
        output wire sdo
12
);
12
);
13
 
13
 
14
        reg [7:0] byteout;
14
        reg [7:0] byteout;
15
        reg [7:0] bytein;
15
        reg [7:0] bytein;
16
 
16
 
Line 18... Line 18...
18
        int bitcntin;
18
        int bitcntin;
19
 
19
 
20
        int state;
20
        int state;
21
        int count;
21
        int count;
22
 
22
 
-
 
23
        reg [7:0] tmp;
-
 
24
 
23
        localparam _FF   = 'd0;
25
        localparam _FF   = 'd0;
24
        localparam _FE   = 'd1;
26
        localparam _FE   = 'd1;
25
        localparam _DATA = 'd2;
27
        localparam _DATA = 'd2;
26
        localparam _CRC  = 'd3;
28
        localparam _CRC  = 'd3;
27
 
29
 
28
 
30
 
29
        initial byteout = 8'hFF;
31
        initial byteout = 8'hFF;
30
        initial bitcntout = 7;
32
        initial bitcntout = 8;
31
        initial bitcntin = 7;
33
        initial bitcntin = 7;
32
        initial state = _FF;
34
        initial state = _FF;
33
        initial count = 5;
35
        initial count = 5;
34
 
36
 
35
 
37
 
36
 
38
 
37
        assign do = byteout[7];
39
        assign sdo = byteout[7];
38
 
40
 
39
 
41
 
40
        always @(negedge clk)
42
        always @(negedge clk)
41
        begin
43
        begin
42
                byteout <= byteout<<1;
44
                byteout <= {byteout[6:0],1'b1};
43
                bitcntout = bitcntout - 1;
45
                bitcntout = bitcntout - 1;
44
 
46
 
45
                if( bitcntout<0 )
47
                if( bitcntout<0 )
46
                begin
48
                begin
47
                        bitcntout = 7;
49
                        bitcntout = 7;
Line 49... Line 51...
49
                        case( state )
51
                        case( state )
50
 
52
 
51
                        _FF:begin
53
                        _FF:begin
52
                                count = count - 1;
54
                                count = count - 1;
53
                                if( count<=0 )
55
                                if( count <= 0 )
54
                                        state = _FE;
56
                                        state <= _FE;
55
                                byteout <= 8'hFF;
57
                                byteout <= 8'hFF;
56
                        end
58
                        end
57
 
59
 
58
                        _FE:begin
60
                        _FE:begin
59
                                state = _DATA;
61
                                state <= _DATA;
60
                                byteout <= 8'hFE;
62
                                byteout <= 8'hFE;
61
                                count = 512;
63
                                count = 512;
62
                        end
64
                        end
63
 
65
 
64
                        _DATA:begin
66
                        _DATA:begin
-
 
67
                                count = count - 1;
-
 
68
                                if( count <= 0 )
-
 
69
                                begin
-
 
70
                                        state <= _CRC;
-
 
71
                                        count <= 2;
65
                                count
72
                                end
-
 
73
                               
-
 
74
                                tmp = $random>>24;
-
 
75
                                byteout <= tmp;
-
 
76
                                tb.sdmp3_chk.push_back(tmp);
66
                        end
77
                        end
67
 
78
 
68
                        _CRC:begin
79
                        _CRC:begin
-
 
80
                                count = count - 1;
-
 
81
                                if( count <= 0 )
-
 
82
                                begin
-
 
83
                                        state <= _FF;
-
 
84
                                        count <= 1+($random&63);
-
 
85
                                end
-
 
86
 
-
 
87
                                byteout <= $random>>24;
69
                        end
88
                        end
70
 
89
 
71
 
90
 
72
                        endcase
91
                        endcase
73
                end
92
                end
Line 75... Line 94...
75
 
94
 
76
       
95
       
77
 
96
 
78
        always @(posedge clk)
97
        always @(posedge clk)
79
        begin
98
        begin
80
                bytein = {bytein[7:1], di};
99
                bytein = {bytein[6:0], sdi};
81
 
100
 
82
                bitcntin = bitcntin - 1;
101
                bitcntin = bitcntin - 1;
83
 
102
 
84
                if( bitcntin<0 )
103
                if( bitcntin<0 )
85
                begin
104
                begin
86
                        bitcnt = 7;
105
                        bitcntin = 7;
87
 
106
 
88
                        if( bytein!==8'hFF )
107
                        if( bytein!==8'hFF )
89
                        begin
108
                        begin
90
                                $display("sd: received not FF!");
109
                                $display("sd: received not FF!");
91
                                $stop;
110
                                $stop;