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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [JFIFGen/] [JFIFGen.vhd] - Blame information for rev 25

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

Line No. Rev Author Line
1 25 mikel262
-------------------------------------------------------------------------------
2
-- File Name :  JFIFGen.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : JFIFGen
7
--
8
-- Content   : JFIF Header Generator
9
--
10
-- Description :
11
--
12
-- Spec.     : 
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090309: (MK): Initial Creation.
19
-------------------------------------------------------------------------------
20
 
21
-------------------------------------------------------------------------------
22
-------------------------------------------------------------------------------
23
----------------------------------- LIBRARY/PACKAGE ---------------------------
24
-------------------------------------------------------------------------------
25
-------------------------------------------------------------------------------
26
 
27
-------------------------------------------------------------------------------
28
-- generic packages/libraries:
29
-------------------------------------------------------------------------------
30
library ieee;
31
  use ieee.std_logic_1164.all;
32
  use ieee.numeric_std.all;
33
 
34
library work;
35
  use work.JPEG_PKG.all;
36
 
37
-------------------------------------------------------------------------------
38
-- user packages/libraries:
39
-------------------------------------------------------------------------------
40
 
41
-------------------------------------------------------------------------------
42
-------------------------------------------------------------------------------
43
----------------------------------- ENTITY ------------------------------------
44
-------------------------------------------------------------------------------
45
-------------------------------------------------------------------------------
46
entity JFIFGen is
47
  port
48
  (
49
        CLK                : in  std_logic;
50
        RST                : in  std_logic;
51
        -- CTRL
52
        start              : in  std_logic;
53
        ready              : out std_logic;
54
        eoi                : in  std_logic;
55
 
56
        -- ByteStuffer
57
        num_enc_bytes      : in  std_logic_vector(23 downto 0);
58
 
59
        -- HOST IF
60
        qwren              : in  std_logic;
61
        qwaddr             : in  std_logic_vector(5 downto 0);
62
        qwdata             : in  std_logic_vector(7 downto 0);
63
        image_size_reg     : in  std_logic_vector(31 downto 0);
64
        image_size_reg_wr  : in  std_logic;
65
 
66
        -- OUT RAM
67
        ram_byte           : out std_logic_vector(7 downto 0);
68
        ram_wren           : out std_logic;
69
        ram_wraddr         : out std_logic_vector(23 downto 0)
70
    );
71
end entity JFIFGen;
72
 
73
-------------------------------------------------------------------------------
74
-------------------------------------------------------------------------------
75
----------------------------------- ARCHITECTURE ------------------------------
76
-------------------------------------------------------------------------------
77
-------------------------------------------------------------------------------
78
architecture RTL of JFIFGen is
79
 
80
  constant C_SIZE_Y_H  : integer := 25;
81
  constant C_SIZE_Y_L  : integer := 26;
82
  constant C_SIZE_X_H  : integer := 27;
83
  constant C_SIZE_X_L  : integer := 28;
84
 
85
  constant C_EOI       : std_logic_vector(15 downto 0) := X"FFD9";
86
 
87
 
88
  signal hr_data      : std_logic_vector(7 downto 0);
89
  signal hr_waddr     : std_logic_vector(8 downto 0);
90
  signal hr_raddr     : std_logic_vector(8 downto 0);
91
  signal hr_we        : std_logic;
92
  signal hr_q         : std_logic_vector(7 downto 0);
93
  signal size_wr_cnt  : unsigned(2 downto 0);
94
  signal size_wr      : std_logic;
95
  signal rd_cnt       : unsigned(8 downto 0);
96
  signal rd_en        : std_logic;
97
  signal rd_en_d1     : std_logic;
98
  signal rd_cnt_d1    : unsigned(8 downto 0);
99
  signal rd_cnt_d2    : unsigned(8 downto 0);
100
  signal eoi_cnt      : unsigned(1 downto 0);
101
  signal eoi_wr       : std_logic;
102
  signal eoi_wr_d1    : std_logic;
103
 
104
-------------------------------------------------------------------------------
105
-- Architecture: begin
106
-------------------------------------------------------------------------------
107
begin
108
 
109
  -------------------------------------------------------------------
110
  -- Header RAM
111
  -------------------------------------------------------------------
112
  U_Header_RAM : entity work.RAMZ
113
  generic map
114
  (
115
      RAMADDR_W     => 9,
116
      RAMDATA_W     => 8
117
  )
118
  port map
119
  (
120
        d           => hr_data,
121
        waddr       => hr_waddr,
122
        raddr       => hr_raddr,
123
        we          => hr_we,
124
        clk         => CLK,
125
 
126
        q           => hr_q
127
  );
128
 
129
  hr_raddr <= std_logic_vector(rd_cnt);
130
 
131
  -------------------------------------------------------------------
132
  -- Host programming
133
  -------------------------------------------------------------------
134
  p_host_wr : process(CLK, RST)
135
  begin
136
    if RST = '1' then
137
      size_wr_cnt <= (others => '0');
138
      size_wr     <= '0';
139
      hr_we       <= '0';
140
      hr_data     <= (others => '0');
141
      hr_waddr    <= (others => '0');
142
    elsif CLK'event and CLK = '1' then
143
      hr_we <= '0';
144
 
145
      if image_size_reg_wr = '1' then
146
        size_wr_cnt <= (others => '0');
147
        size_wr     <= '1';
148
      end if;
149
 
150
      -- write image size
151
      if size_wr = '1' then
152
        if size_wr_cnt = 4 then
153
          size_wr_cnt <= (others => '0');
154
          size_wr     <= '0';
155
        else
156
          size_wr_cnt <= size_wr_cnt + 1;
157
          hr_we <= '1';
158
          case size_wr_cnt is
159
            -- height H byte
160
            when "000" =>
161
              hr_data  <= image_size_reg(15 downto 8);
162
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_Y_H,hr_waddr'length));
163
            -- height L byte
164
            when "001" =>
165
              hr_data <= image_size_reg(7 downto 0);
166
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_Y_L,hr_waddr'length));
167
            -- width H byte
168
            when "010" =>
169
              hr_data <= image_size_reg(31 downto 24);
170
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_X_H,hr_waddr'length));
171
            -- width L byte
172
            when "011" =>
173
              hr_data <= image_size_reg(23 downto 16);
174
              hr_waddr <= std_logic_vector(to_unsigned(C_SIZE_X_L,hr_waddr'length));
175
            when others =>
176
              null;
177
          end case;
178
        end if;
179
      -- write Quantization table
180
      elsif qwren = '1' then
181
        hr_waddr <= std_logic_vector( resize(unsigned(qwaddr),hr_waddr'length) +
182
                    to_unsigned(44,hr_waddr'length));
183
        hr_we   <= '1';
184
        hr_data <= qwdata;
185
      end if;
186
 
187
    end if;
188
  end process;
189
 
190
  -------------------------------------------------------------------
191
  -- CTRL
192
  -------------------------------------------------------------------
193
  p_ctrl : process(CLK, RST)
194
  begin
195
    if RST = '1' then
196
      ready      <= '0';
197
      rd_en      <= '0';
198
      rd_cnt     <= (others => '0');
199
      rd_cnt_d1  <= (others => '0');
200
      rd_cnt_d2  <= (others => '0');
201
      rd_cnt_d1  <= (others => '0');
202
      rd_en_d1   <= '0';
203
      eoi_wr_d1  <= '0';
204
      eoi_wr     <= '0';
205
      eoi_cnt    <= (others => '0');
206
      ram_wren   <= '0';
207
      ram_byte   <= (others => '0');
208
      ram_wraddr <= (others => '0');
209
    elsif CLK'event and CLK = '1' then
210
      ready     <= '0';
211
      rd_cnt_d1 <= rd_cnt;
212
      rd_cnt_d2 <= rd_cnt_d1;
213
      rd_en_d1  <= rd_en;
214
      eoi_wr_d1 <= eoi_wr;
215
 
216
      -- defaults: encoded data write
217
      ram_wren   <= rd_en_d1;
218
      ram_wraddr <= std_logic_vector(resize(rd_cnt_d1,ram_wraddr'length));
219
      ram_byte   <= hr_q;
220
 
221
      -- start JFIF
222
      if start = '1' and eoi = '0' then
223
        rd_cnt <= (others => '0');
224
        rd_en  <= '1';
225
      elsif start = '1' and eoi = '1' then
226
        eoi_wr  <= '1';
227
        eoi_cnt <= (others => '0');
228
      end if;
229
 
230
      -- read JFIF Header
231
      if rd_en = '1' then
232
        if rd_cnt = C_HDR_SIZE-1 then
233
          rd_en  <= '0';
234
          ready  <= '1';
235
        else
236
          rd_cnt <= rd_cnt + 1;
237
        end if;
238
      end if;
239
 
240
      -- EOI MARKER write
241
      if eoi_wr = '1' then
242
        if eoi_cnt = 2 then
243
          eoi_cnt  <= (others => '0');
244
          eoi_wr   <= '0';
245
          ready    <= '1';
246
        else
247
          eoi_cnt  <= eoi_cnt + 1;
248
          ram_wren <= '1';
249
          if eoi_cnt = 0 then
250
            ram_byte   <= C_EOI(15 downto 8);
251
            ram_wraddr <= num_enc_bytes;
252
          elsif eoi_cnt = 1 then
253
            ram_byte   <= C_EOI(7 downto 0);
254
            ram_wraddr <= std_logic_vector(unsigned(num_enc_bytes) +
255
                                           to_unsigned(1,ram_wraddr'length));
256
          end if;
257
        end if;
258
      end if;
259
    end if;
260
  end process;
261
 
262
end architecture RTL;
263
-------------------------------------------------------------------------------
264
-- Architecture: end
265
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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