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

Subversion Repositories two_dimensional_fast_hartley_transform

[/] [two_dimensional_fast_hartley_transform/] [trunk/] [mtx_trps_8x8_dpsram.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 irezki
/**********************************************************************
2
 * File  : mtx_trps_8x8_dpsram.v
3
 * Author: Ivan Rezki
4
 * email : irezki@gmail.com
5
 * Topic : RTL Core
6
 *                2-Dimensional Fast Hartley Transform
7
 *
8
 *
9
 * Matrix Transpose 8x8
10
 * DPSRAM-based Double Buffer
11
 * Buffer size is 64*2 words, each word is 16 bits
12
 *
13
 * Matrix Transpose -> 64 clk delay
14
 *                      - Double Buffer Solution:
15
 *
16
 * RIGHT TO USE: This code example, or any portion thereof, may be
17
 * used and distributed without restriction, provided that this entire
18
 * comment block is included with the example.
19
 *
20
 * DISCLAIMER: THIS CODE EXAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY
21
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
22
 * TO WARRANTIES OF MERCHANTABILITY, FITNESS OR CORRECTNESS. IN NO
23
 * EVENT SHALL THE AUTHOR OR AUTHORS BE LIABLE FOR ANY DAMAGES,
24
 * INCLUDING INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE
25
 * USE OF THIS CODE.
26
 **********************************************************************/
27 2 irezki
 
28
module mtx_trps_8x8_dpsram (
29
        rstn,
30
        sclk,
31
 
32
        // Input
33
        inp_valid,
34
        inp_data,
35
 
36
        // Output
37
        mem_data,
38
        mem_valid
39
);
40
parameter N = 8;
41
 
42
input                   rstn;
43
input                   sclk;
44
 
45
input                   inp_valid;
46
input   [N-1:0]  inp_data;
47
 
48
output  [N-1:0]  mem_data;
49
output                  mem_valid;
50
 
51
reg [6:0]        cnt128d_wr;                             // Write Mode Counter
52
wire            indicator;                              // 64 words written - Indication(pos. or neg. edge)
53
reg                     indicator_1d;                   // Indication 1 clock delay
54
wire            indicator_pos_edge;             // positive edge
55
wire            indicator_neg_edge;             // negative edge
56
reg     [6:0]    cnt128d_rd;                             // Read Counter
57
wire            cnt128d_rd_valid_start; // Counter start increment
58
wire            cnt128d_rd_valid_stop;  // Counter stop increment
59
reg                     cnt128d_rd_valid;               // valid time for cnt128d_rd counter
60
reg                     mem_valid;                              // 1 clock delay after reading
61
 
62
// DPSRAM Memory Signal Description
63
wire [15:0] wr_DATA;
64
wire [ 6:0] wr_ADDR;
65
wire            wr_CSN;
66
wire            wr_WEN;
67
 
68
wire [ 6:0] rd_ADDR;
69
wire            rd_CSN;
70
 
71 4 irezki
`ifdef USE_FPGA_SPSRAM
72
        wire [15:0] rd_DATA;
73
        dpsram_128x16 u_dpsram(
74
                .addra  (wr_ADDR),
75
                .addrb  (rd_ADDR),
76
                .clka   (sclk),
77
                .clkb   (sclk),
78
                .dina   (wr_DATA),
79
                .dinb   ({16{1'b0}}),
80
                .douta  (/* OPEN */),
81
                .doutb  (rd_DATA),
82
                .ena    (wr_CSN),
83
                .enb    (rd_CSN),
84
                .wea    (wr_WEN),
85
                .web    (1'b1)
86
        );
87
`endif
88 2 irezki
 
89 4 irezki
`ifdef USE_ASIC_SPSRAM
90
        reg [15:0] rd_DATA = 16'd0;
91
        reg     [15:0] sram[0:127];
92
        always @(posedge sclk)
93
                if (~wr_WEN && ~wr_CSN) sram[wr_ADDR] <= wr_DATA;       // Write
94
        always @(posedge sclk)
95
                if (  1'b1  && ~rd_CSN) rd_DATA <= sram[rd_ADDR];       // Read
96
`endif
97
 
98 2 irezki
always @(posedge sclk or negedge rstn)
99
if              (!rstn)         cnt128d_wr <= #1 0;
100
else if (inp_valid)     cnt128d_wr <= #1 cnt128d_wr + 1;
101
 
102
assign wr_DATA = {{16-N{1'b0}},inp_data};
103
assign wr_ADDR = cnt128d_wr;
104
assign wr_CSN  = ~inp_valid;
105
assign wr_WEN  = ~inp_valid;
106
 
107
// Start Reading After fisrt 64 words had been written
108
assign indicator = cnt128d_wr[6];
109
always @(posedge sclk or negedge rstn)
110
if      (!rstn) indicator_1d <= #1 1'b0;
111
else            indicator_1d <= #1 indicator;
112
 
113
assign indicator_pos_edge =  indicator & ~indicator_1d;
114
assign indicator_neg_edge = ~indicator &  indicator_1d;
115
 
116
assign cnt128d_rd_valid_start = indicator_pos_edge | indicator_neg_edge;
117
assign cnt128d_rd_valid_stop  = (cnt128d_rd[5:0] == 63) ? 1'b1 : 1'b0;
118
 
119
always @(posedge sclk or negedge rstn)
120
if              (!rstn)                                 cnt128d_rd_valid <= #1 1'b0;
121
else if (cnt128d_rd_valid_start)cnt128d_rd_valid <= #1 1'b1;
122
else if (cnt128d_rd_valid_stop) cnt128d_rd_valid <= #1 1'b0;
123
 
124
// Read Mode Counter
125
always @(posedge sclk or negedge rstn)
126
if              (!rstn)                         cnt128d_rd <= #1 1'b0;
127
else if (cnt128d_rd_valid)      cnt128d_rd <= #1 cnt128d_rd + 1;
128
 
129
assign rd_ADDR = {cnt128d_rd[6],cnt128d_rd[2:0],cnt128d_rd[5:3]};
130
assign rd_CSN  = ~cnt128d_rd_valid;
131
 
132
// Output
133
always @(posedge sclk or negedge rstn)
134
if      (!rstn) mem_valid <= #1 1'b0;
135
else            mem_valid <= #1 cnt128d_rd_valid;
136
 
137
assign #1 mem_data = rd_DATA[N-1:0];
138
 
139
// synopsys translate_off
140
// <<<------------- DUMP Section
141 4 irezki
/*
142 2 irezki
// 2D FHT OUTPUT DUMP DATA
143
parameter MEM_TRPS_DPSRAM_FILE = "./result/mem_trps_dpsram.txt";
144
integer mem_trps_dpsram_dump;
145
initial mem_trps_dpsram_dump = $fopen(MEM_TRPS_DPSRAM_FILE);
146
 
147
always @(posedge sclk)
148
if (mem_valid) $fdisplay(mem_trps_dpsram_dump,"%h",mem_data);
149 4 irezki
*/
150 2 irezki
// synopsys translate_on
151
endmodule

powered by: WebSVN 2.1.0

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