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

Subversion Repositories warp

[/] [warp/] [rtl/] [tmu_scantrace.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 lekernel
/*
2
 * Milkymist VJ SoC
3
 * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
4
 *
5
 * This program is free and excepted software; you can use it, redistribute it
6
 * and/or modify it under the terms of the Exception General Public License as
7
 * published by the Exception License Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
 * FOR A PARTICULAR PURPOSE. See the Exception General Public License for more
13
 * details.
14
 *
15
 * You should have received a copy of the Exception General Public License along
16
 * with this project; if not, write to the Exception License Foundation.
17
 */
18
 
19
module tmu_scantrace(
20
        input sys_clk,
21
        input sys_rst,
22
 
23
        output busy,
24
 
25
        input pipe_stb_i,
26
        output pipe_ack_o,
27
        input [10:0] Y,
28
        input [10:0] S_X,
29
        input [10:0] S_U,
30
        input [10:0] S_V,
31
        input [10:0] E_X,
32
        input du_positive,
33
        input [10:0] du_q,
34
        input [10:0] du_r,
35
        input dv_positive,
36
        input [10:0] dv_q,
37
        input [10:0] dv_r,
38
        input [10:0] divisor,
39
 
40
        output pipe_stb_o,
41
        input pipe_ack_i,
42
        output reg [10:0] P_X,
43
        output reg [10:0] P_Y,
44
        output reg [10:0] P_U,
45
        output reg [10:0] P_V
46
);
47
 
48
reg load;
49
 
50
/* Register some inputs */
51
reg [10:0] E_X_r;
52
reg du_positive_r;
53
reg [10:0] du_q_r;
54
reg [10:0] du_r_r;
55
reg dv_positive_r;
56
reg [10:0] dv_q_r;
57
reg [10:0] dv_r_r;
58
reg [10:0] divisor_r;
59
 
60
always @(posedge sys_clk) begin
61
        if(load) begin
62
                P_Y <= Y;
63
                E_X_r <= E_X;
64
                du_positive_r <= du_positive;
65
                du_q_r <= du_q;
66
                du_r_r <= du_r;
67
                dv_positive_r <= dv_positive;
68
                dv_q_r <= dv_q;
69
                dv_r_r <= dv_r;
70
                divisor_r <= divisor;
71
        end
72
end
73
 
74
/* Current point datapath */
75
reg addD;
76
reg [11:0] errU;
77
reg correctU;
78
reg [11:0] errV;
79
reg correctV;
80
always @(posedge sys_clk) begin
81
        if(load) begin
82
                P_U = S_U;
83
                errU = 12'd0;
84
                P_V = S_V;
85
                errV = 12'd0;
86
        end else begin
87
                if(addD) begin
88
                        errU = errU + du_r_r;
89
                        correctU = (errU[10:0] > {1'b0, divisor_r[10:1]}) & ~errU[11];
90
                        if(du_positive_r) begin
91
                                P_U = P_U + du_q_r;
92
                                if(correctU)
93
                                        P_U = P_U + 11'd1;
94
                        end else begin
95
                                P_U = P_U - du_q_r;
96
                                if(correctU)
97
                                        P_U = P_U - 11'd1;
98
                        end
99
                        if(correctU)
100
                                errU = errU - {1'b0, divisor_r};
101
 
102
                        errV = errV + dv_r_r;
103
                        correctV = (errV[10:0] > {1'b0, divisor_r[10:1]}) & ~errV[11];
104
                        if(dv_positive_r) begin
105
                                P_V = P_V + dv_q_r;
106
                                if(correctV)
107
                                        P_V = P_V + 11'd1;
108
                        end else begin
109
                                P_V = P_V - dv_q_r;
110
                                if(correctV)
111
                                        P_V = P_V - 11'd1;
112
                        end
113
                        if(correctV)
114
                                errV = errV - {1'b0, divisor_r};
115
                end
116
        end
117
end
118
 
119
/* X datapath */
120
reg incX;
121
always @(posedge sys_clk) begin
122
        if(load)
123
                P_X <= S_X;
124
        else if(incX)
125
                P_X <= P_X + 11'd1;
126
end
127
 
128
wire reachedE = (P_X == E_X_r);
129
 
130
/* FSM-based controller */
131
 
132
reg state;
133
reg next_state;
134
 
135
parameter IDLE  = 1'b0;
136
parameter BUSY  = 1'b1;
137
 
138
always @(posedge sys_clk) begin
139
        if(sys_rst)
140
                state <= IDLE;
141
        else
142
                state <= next_state;
143
end
144
 
145
assign busy = state;
146
assign pipe_ack_o = ~state;
147
assign pipe_stb_o = state;
148
 
149
always @(*) begin
150
        next_state = state;
151
        load = 1'b0;
152
        addD = 1'b0;
153
        incX = 1'b0;
154
 
155
        case(state)
156
                IDLE: begin
157
                        if(pipe_stb_i) begin
158
                                load = 1'b1;
159
                                next_state = BUSY;
160
                        end
161
                end
162
                BUSY: begin
163
                        if(pipe_ack_i) begin
164
                                if(reachedE)
165
                                        next_state = IDLE;
166
                                else begin
167
                                        incX = 1'b1;
168
                                        addD = 1'b1;
169
                                end
170
                        end
171
                end
172
        endcase
173
end
174
 
175
endmodule

powered by: WebSVN 2.1.0

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