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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [mdct/] [DCT1D.vhd] - Blame information for rev 67

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

Line No. Rev Author Line
1 67 mikel262
--------------------------------------------------------------------------------
2
--                                                                            --
3
--                          V H D L    F I L E                                --
4
--                          COPYRIGHT (C) 2006                                --
5
--                                                                            --
6
--------------------------------------------------------------------------------
7
--
8
-- Title       : DCT1D
9
-- Design      : MDCT Core
10
-- Author      : Michal Krepa
11
--
12
--------------------------------------------------------------------------------
13
--
14
-- File        : DCT1D.VHD
15
-- Created     : Sat Mar 5 7:37 2006
16
--
17
--------------------------------------------------------------------------------
18
--
19
--  Description : 1D Discrete Cosine Transform (1st stage)
20
--
21
--------------------------------------------------------------------------------
22
 
23
 
24
library IEEE;
25
  use IEEE.STD_LOGIC_1164.all;
26
  use IEEE.NUMERIC_STD.all;
27
 
28
library WORK;
29
  use WORK.MDCT_PKG.all;
30
 
31
--------------------------------------------------------------------------------
32
-- ENTITY
33
--------------------------------------------------------------------------------
34
entity DCT1D is
35
        port(
36
                  clk          : in STD_LOGIC;
37
                  rst          : in std_logic;
38
      dcti         : in std_logic_vector(IP_W-1 downto 0);
39
      idv          : in STD_LOGIC;
40
      romedatao    : in T_ROM1DATAO;
41
      romodatao    : in T_ROM1DATAO;
42
 
43
      odv          : out STD_LOGIC;
44
      dcto         : out std_logic_vector(OP_W-1 downto 0);
45
      romeaddro    : out T_ROM1ADDRO;
46
      romoaddro    : out T_ROM1ADDRO;
47
      ramwaddro    : out STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
48
      ramdatai     : out STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
49
      ramwe        : out STD_LOGIC;
50
      wmemsel      : out STD_LOGIC
51
                );
52
end DCT1D;
53
 
54
--------------------------------------------------------------------------------
55
-- ARCHITECTURE
56
--------------------------------------------------------------------------------
57
architecture RTL of DCT1D is
58
 
59
  type INPUT_DATA is array (N-1 downto 0) of SIGNED(IP_W downto 0);
60
 
61
  signal databuf_reg     : INPUT_DATA;
62
  signal latchbuf_reg    : INPUT_DATA;
63
  signal col_reg         : UNSIGNED(RAMADRR_W/2-1 downto 0);
64
  signal row_reg         : UNSIGNED(RAMADRR_W/2-1 downto 0);
65
  signal rowr_reg        : UNSIGNED(RAMADRR_W/2-1 downto 0);
66
  signal inpcnt_reg      : UNSIGNED(RAMADRR_W/2-1 downto 0);
67
  signal ramwe_s         : STD_LOGIC;
68
  signal wmemsel_reg     : STD_LOGIC;
69
  signal stage2_reg      : STD_LOGIC;
70
  signal stage2_cnt_reg  : UNSIGNED(RAMADRR_W-1 downto 0);
71
  signal col_2_reg       : UNSIGNED(RAMADRR_W/2-1 downto 0);
72
  signal ramwaddro_s     : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
73
 
74
  signal even_not_odd    : std_logic;
75
  signal even_not_odd_d1 : std_logic;
76
  signal even_not_odd_d2 : std_logic;
77
  signal even_not_odd_d3 : std_logic;
78
  signal ramwe_d1        : STD_LOGIC;
79
  signal ramwe_d2        : STD_LOGIC;
80
  signal ramwe_d3        : STD_LOGIC;
81
  signal ramwe_d4        : STD_LOGIC;
82
  signal ramwaddro_d1    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
83
  signal ramwaddro_d2    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
84
  signal ramwaddro_d3    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
85
  signal ramwaddro_d4    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
86
  signal ramwaddro_d5    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
87
  signal ramwaddro_d6    : STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
88
  signal wmemsel_d1      : STD_LOGIC;
89
  signal wmemsel_d2      : STD_LOGIC;
90
  signal wmemsel_d3      : STD_LOGIC;
91
  signal wmemsel_d4      : STD_LOGIC;
92
  signal wmemsel_d5      : STD_LOGIC;
93
  signal wmemsel_d6      : STD_LOGIC;
94
  signal romedatao_d1    : T_ROM1DATAO;
95
  signal romodatao_d1    : T_ROM1DATAO;
96
  signal romedatao_d2    : T_ROM1DATAO;
97
  signal romodatao_d2    : T_ROM1DATAO;
98
  signal romedatao_d3    : T_ROM1DATAO;
99
  signal romodatao_d3    : T_ROM1DATAO;
100
  signal dcto_1          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
101
  signal dcto_2          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
102
  signal dcto_3          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
103
  signal dcto_4          : STD_LOGIC_VECTOR(DA_W-1 downto 0);
104
 
105
  signal fpr_out         : STD_LOGIC_VECTOR(DA_W-12-1 downto 0);
106
 
107
  component FinitePrecRndNrst is
108
  generic
109
  (
110
    C_IN_SZ   : natural := 37;
111
    C_OUT_SZ  : natural := 16;
112
    C_FRAC_SZ : natural := 15
113
  );
114
  port (
115
    CLK     : in std_logic;
116
    RST     : in std_logic;
117
    datain  : in STD_LOGIC_VECTOR(C_IN_SZ-1 downto 0);
118
    dataval : in std_logic;
119
    dataout : out STD_LOGIC_VECTOR(C_OUT_SZ-1 downto 0);
120
 
121
    clip_inc : out std_logic;
122
    dval_out : out std_logic
123
  );
124
end component;
125
 
126
begin
127
 
128
  ramwaddro <= ramwaddro_d6;
129
  --ramwe     <= ramwe_d4;
130
  --ramdatai  <= dcto_4(DA_W-1 downto 12);
131
  wmemsel   <= wmemsel_d4;
132
 
133
  odv <= ramwe_d4;
134
  dcto <= STD_LOGIC_VECTOR(RESIZE(SIGNED(fpr_out),12));
135
 
136
  ramdatai <= fpr_out;
137
 
138
  U_FinitePrecRndNrst : FinitePrecRndNrst
139
  generic map(
140
    C_IN_SZ  => DA_W,
141
    C_OUT_SZ => DA_W-12,
142
    C_FRAC_SZ => 12
143
  )
144
  port map(
145
    CLK         => clk,
146
    RST         => rst,
147
 
148
    datain      => dcto_4,
149
    dataval     => ramwe_d4,
150
    dataout     => fpr_out,
151
 
152
    clip_inc    => open,
153
    dval_out    => ramwe
154
  );
155
 
156
  process(clk,rst)
157
  begin
158
    if rst = '1' then
159
      inpcnt_reg      <= (others => '0');
160
      latchbuf_reg    <= (others => (others => '0'));
161
      databuf_reg     <= (others => (others => '0'));
162
      stage2_reg      <= '0';
163
      stage2_cnt_reg  <= (others => '1');
164
      ramwe_s         <= '0';
165
      ramwaddro_s     <= (others => '0');
166
      col_reg         <= (others => '0');
167
      row_reg         <= (others => '0');
168
      wmemsel_reg     <= '0';
169
      col_2_reg       <= (others => '0');
170
    elsif clk = '1' and clk'event then
171
      stage2_reg     <= '0';
172
      ramwe_s        <= '0';
173
 
174
      --------------------------------
175
      -- 1st stage
176
      --------------------------------
177
      if idv = '1' then
178
 
179
        inpcnt_reg    <= inpcnt_reg + 1;
180
 
181
        -- right shift input data
182
        latchbuf_reg(N-2 downto 0) <= latchbuf_reg(N-1 downto 1);
183
        latchbuf_reg(N-1)          <= SIGNED('0' & dcti) - LEVEL_SHIFT;
184
 
185
        if inpcnt_reg = N-1 then
186
          -- after this sum databuf_reg is in range of -256 to 254 (min to max) 
187
          databuf_reg(0)  <= latchbuf_reg(1)+(SIGNED('0' & dcti) - LEVEL_SHIFT);
188
          databuf_reg(1)  <= latchbuf_reg(2)+latchbuf_reg(7);
189
          databuf_reg(2)  <= latchbuf_reg(3)+latchbuf_reg(6);
190
          databuf_reg(3)  <= latchbuf_reg(4)+latchbuf_reg(5);
191
          databuf_reg(4)  <= latchbuf_reg(1)-(SIGNED('0' & dcti) - LEVEL_SHIFT);
192
          databuf_reg(5)  <= latchbuf_reg(2)-latchbuf_reg(7);
193
          databuf_reg(6)  <= latchbuf_reg(3)-latchbuf_reg(6);
194
          databuf_reg(7)  <= latchbuf_reg(4)-latchbuf_reg(5);
195
          stage2_reg      <= '1';
196
        end if;
197
      end if;
198
      --------------------------------
199
 
200
      --------------------------------
201
      -- 2nd stage
202
      --------------------------------
203
      if stage2_cnt_reg < N then
204
 
205
        stage2_cnt_reg <= stage2_cnt_reg + 1;
206
 
207
        -- write RAM
208
        ramwe_s   <= '1';
209
        -- reverse col/row order for transposition purpose
210
        ramwaddro_s <= STD_LOGIC_VECTOR(col_2_reg & row_reg);
211
        -- increment column counter
212
        col_reg   <= col_reg + 1;
213
        col_2_reg <= col_2_reg + 1;
214
 
215
        -- finished processing one input row
216
        if col_reg = 0 then
217
          row_reg         <= row_reg + 1;
218
          -- switch to 2nd memory
219
          if row_reg = N - 1 then
220
            wmemsel_reg <= not wmemsel_reg;
221
            col_reg         <= (others => '0');
222
          end if;
223
        end if;
224
 
225
      end if;
226
 
227
      if stage2_reg = '1' then
228
        stage2_cnt_reg <= (others => '0');
229
        col_reg        <= (0=>'1',others => '0');
230
        col_2_reg      <= (others => '0');
231
      end if;
232
      ----------------------------------   
233
 
234
 
235
    end if;
236
  end process;
237
 
238
  -- output data pipeline
239
  p_data_out_pipe : process(CLK, RST)
240
  begin
241
    if RST = '1' then
242
      even_not_odd    <= '0';
243
      even_not_odd_d1 <= '0';
244
      even_not_odd_d2 <= '0';
245
      even_not_odd_d3 <= '0';
246
      ramwe_d1        <= '0';
247
      ramwe_d2        <= '0';
248
      ramwe_d3        <= '0';
249
      ramwe_d4        <= '0';
250
      ramwaddro_d1    <= (others => '0');
251
      ramwaddro_d2    <= (others => '0');
252
      ramwaddro_d3    <= (others => '0');
253
      ramwaddro_d4    <= (others => '0');
254
      wmemsel_d1      <= '0';
255
      wmemsel_d2      <= '0';
256
      wmemsel_d3      <= '0';
257
      wmemsel_d4      <= '0';
258
      dcto_1          <= (others => '0');
259
      dcto_2          <= (others => '0');
260
      dcto_3          <= (others => '0');
261
      dcto_4          <= (others => '0');
262
    elsif CLK'event and CLK = '1' then
263
      even_not_odd    <= stage2_cnt_reg(0);
264
      even_not_odd_d1 <= even_not_odd;
265
      even_not_odd_d2 <= even_not_odd_d1;
266
      even_not_odd_d3 <= even_not_odd_d2;
267
      ramwe_d1        <= ramwe_s;
268
      ramwe_d2        <= ramwe_d1;
269
      ramwe_d3        <= ramwe_d2;
270
      ramwe_d4        <= ramwe_d3;
271
      ramwaddro_d1    <= ramwaddro_s;
272
      ramwaddro_d2    <= ramwaddro_d1;
273
      ramwaddro_d3    <= ramwaddro_d2;
274
      ramwaddro_d4    <= ramwaddro_d3;
275
      ramwaddro_d5    <= ramwaddro_d4;
276
      ramwaddro_d6    <= ramwaddro_d5;
277
      wmemsel_d1      <= wmemsel_reg;
278
      wmemsel_d2      <= wmemsel_d1;
279
      wmemsel_d3      <= wmemsel_d2;
280
      wmemsel_d4      <= wmemsel_d3;
281
      wmemsel_d5      <= wmemsel_d4;
282
      wmemsel_d6      <= wmemsel_d5;
283
 
284
      if even_not_odd = '0' then
285
        dcto_1 <= STD_LOGIC_VECTOR(RESIZE
286
          (RESIZE(SIGNED(romedatao(0)),DA_W) +
287
          (RESIZE(SIGNED(romedatao(1)),DA_W-1) & '0') +
288
          (RESIZE(SIGNED(romedatao(2)),DA_W-2) & "00"),
289
          DA_W));
290
      else
291
        dcto_1 <= STD_LOGIC_VECTOR(RESIZE
292
          (RESIZE(SIGNED(romodatao(0)),DA_W) +
293
          (RESIZE(SIGNED(romodatao(1)),DA_W-1) & '0') +
294
          (RESIZE(SIGNED(romodatao(2)),DA_W-2) & "00"),
295
          DA_W));
296
      end if;
297
 
298
      if even_not_odd_d1 = '0' then
299
        dcto_2 <= STD_LOGIC_VECTOR(RESIZE
300
          (signed(dcto_1) +
301
          (RESIZE(SIGNED(romedatao_d1(3)),DA_W-3) & "000") +
302
          (RESIZE(SIGNED(romedatao_d1(4)),DA_W-4) & "0000"),
303
          DA_W));
304
      else
305
        dcto_2 <= STD_LOGIC_VECTOR(RESIZE
306
          (signed(dcto_1) +
307
          (RESIZE(SIGNED(romodatao_d1(3)),DA_W-3) & "000") +
308
          (RESIZE(SIGNED(romodatao_d1(4)),DA_W-4) & "0000"),
309
          DA_W));
310
      end if;
311
 
312
      if even_not_odd_d2 = '0' then
313
        dcto_3 <= STD_LOGIC_VECTOR(RESIZE
314
          (signed(dcto_2) +
315
          (RESIZE(SIGNED(romedatao_d2(5)),DA_W-5) & "00000") +
316
          (RESIZE(SIGNED(romedatao_d2(6)),DA_W-6) & "000000"),
317
          DA_W));
318
      else
319
        dcto_3 <= STD_LOGIC_VECTOR(RESIZE
320
          (signed(dcto_2) +
321
          (RESIZE(SIGNED(romodatao_d2(5)),DA_W-5) & "00000") +
322
          (RESIZE(SIGNED(romodatao_d2(6)),DA_W-6) & "000000"),
323
          DA_W));
324
      end if;
325
 
326
      if even_not_odd_d3 = '0' then
327
        dcto_4 <= STD_LOGIC_VECTOR(RESIZE
328
          (signed(dcto_3) +
329
          (RESIZE(SIGNED(romedatao_d3(7)),DA_W-7) & "0000000") -
330
          (RESIZE(SIGNED(romedatao_d3(8)),DA_W-8) & "00000000"),
331
          DA_W));
332
      else
333
        dcto_4 <= STD_LOGIC_VECTOR(RESIZE
334
          (signed(dcto_3) +
335
          (RESIZE(SIGNED(romodatao_d3(7)),DA_W-7) & "0000000") -
336
          (RESIZE(SIGNED(romodatao_d3(8)),DA_W-8) & "00000000"),
337
          DA_W));
338
      end if;
339
    end if;
340
  end process;
341
 
342
  -- read precomputed MAC results from LUT
343
  p_romaddr : process(CLK, RST)
344
  begin
345
    if RST = '1' then
346
      romeaddro   <= (others => (others => '0'));
347
      romoaddro   <= (others => (others => '0'));
348
    elsif CLK'event and CLK = '1' then
349
      for i in 0 to 8 loop
350
        -- even
351
        romeaddro(i) <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
352
                 databuf_reg(0)(i) &
353
                 databuf_reg(1)(i) &
354
                 databuf_reg(2)(i) &
355
                 databuf_reg(3)(i);
356
        -- odd
357
        romoaddro(i) <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
358
                 databuf_reg(4)(i) &
359
                 databuf_reg(5)(i) &
360
                 databuf_reg(6)(i) &
361
                 databuf_reg(7)(i);
362
      end loop;
363
    end if;
364
  end process;
365
 
366
  p_romdatao_d1 : process(CLK, RST)
367
  begin
368
    if RST = '1' then
369
      romedatao_d1    <= (others => (others => '0'));
370
      romodatao_d1    <= (others => (others => '0'));
371
      romedatao_d2    <= (others => (others => '0'));
372
      romodatao_d2    <= (others => (others => '0'));
373
      romedatao_d3    <= (others => (others => '0'));
374
      romodatao_d3    <= (others => (others => '0'));
375
    elsif CLK'event and CLK = '1' then
376
      romedatao_d1   <= romedatao;
377
      romodatao_d1   <= romodatao;
378
      romedatao_d2   <= romedatao_d1;
379
      romodatao_d2   <= romodatao_d1;
380
      romedatao_d3   <= romedatao_d2;
381
      romodatao_d3   <= romodatao_d2;
382
    end if;
383
  end process;
384
 
385
end RTL;
386
--------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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