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

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [design/] [control/] [CtrlSM.vhd] - Blame information for rev 51

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

Line No. Rev Author Line
1 25 mikel262
-------------------------------------------------------------------------------
2
-- File Name :  CtrlSM.vhd
3
--
4
-- Project   : JPEG_ENC
5
--
6
-- Module    : CtrlSM
7
--
8
-- Content   : CtrlSM
9
--
10
-- Description : CtrlSM core
11
--
12
-- Spec.     : 
13
--
14
-- Author    : Michal Krepa
15
--
16
-------------------------------------------------------------------------------
17
-- History :
18
-- 20090301: (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
-------------------------------------------------------------------------------
35
-- user packages/libraries:
36
-------------------------------------------------------------------------------
37
library work;
38
  use work.JPEG_PKG.all;
39
-------------------------------------------------------------------------------
40
-------------------------------------------------------------------------------
41
----------------------------------- ENTITY ------------------------------------
42
-------------------------------------------------------------------------------
43
-------------------------------------------------------------------------------
44
entity CtrlSM is
45
  port
46
  (
47
        CLK                : in  std_logic;
48
        RST                : in  std_logic;
49 42 mikel262
 
50
        -- output IF
51
        outif_almost_full  : in  std_logic;
52 25 mikel262
 
53
        -- HOST IF
54
        sof                : in  std_logic;
55
        img_size_x         : in  std_logic_vector(15 downto 0);
56
        img_size_y         : in  std_logic_vector(15 downto 0);
57
        jpeg_ready         : out std_logic;
58
        jpeg_busy          : out std_logic;
59
        cmp_max            : in  std_logic_vector(1 downto 0);
60
 
61
        -- FDCT
62
        fdct_start         : out std_logic;
63
        fdct_ready         : in  std_logic;
64
        fdct_sm_settings   : out T_SM_SETTINGS;
65
 
66
        -- ZIGZAG
67
        zig_start          : out std_logic;
68
        zig_ready          : in  std_logic;
69
        zig_sm_settings    : out T_SM_SETTINGS;
70
 
71 34 mikel262
        -- Quantizer
72
        qua_start          : out std_logic;
73
        qua_ready          : in  std_logic;
74
        qua_sm_settings    : out T_SM_SETTINGS;
75
 
76 25 mikel262
        -- RLE
77
        rle_start          : out std_logic;
78
        rle_ready          : in  std_logic;
79
        rle_sm_settings    : out T_SM_SETTINGS;
80
 
81
        -- Huffman
82
        huf_start          : out std_logic;
83
        huf_ready          : in  std_logic;
84
        huf_sm_settings    : out T_SM_SETTINGS;
85
 
86
        -- ByteStuffdr
87
        bs_start           : out std_logic;
88
        bs_ready           : in  std_logic;
89
        bs_sm_settings     : out T_SM_SETTINGS;
90
 
91
        -- JFIF GEN
92
        jfif_start         : out std_logic;
93
        jfif_ready         : in  std_logic;
94
        jfif_eoi           : out std_logic;
95
 
96
        -- OUT MUX
97
        out_mux_ctrl       : out std_logic
98 46 mikel262
   );
99 25 mikel262
end entity CtrlSM;
100
 
101
-------------------------------------------------------------------------------
102
-------------------------------------------------------------------------------
103
----------------------------------- ARCHITECTURE ------------------------------
104
-------------------------------------------------------------------------------
105
-------------------------------------------------------------------------------
106
architecture RTL of CtrlSM is
107
 
108 44 mikel262
 
109 34 mikel262
  constant NUM_STAGES   : integer := 6;
110
 
111 25 mikel262
  type T_STATE is (IDLES, JFIF, HORIZ, COMP, VERT, EOI);
112 34 mikel262
  type ARR_FSM is array(NUM_STAGES downto 1) of std_logic_vector(1 downto 0);
113 25 mikel262
 
114 34 mikel262
  type T_ARR_SM_SETTINGS is array(NUM_STAGES+1 downto 1) of T_SM_SETTINGS;
115 25 mikel262
  signal Reg             : T_ARR_SM_SETTINGS;
116
  signal main_state      : T_STATE;
117 34 mikel262
  signal start           : std_logic_vector(NUM_STAGES+1 downto 1);
118
  signal idle            : std_logic_vector(NUM_STAGES+1 downto 1);
119
  signal start_PB        : std_logic_vector(NUM_STAGES downto 1);
120
  signal ready_PB        : std_logic_vector(NUM_STAGES downto 1);
121 25 mikel262
  signal fsm             : ARR_FSM;
122
  signal start1_d        : std_logic;
123
  signal RSM             : T_SM_SETTINGS;
124
  signal out_mux_ctrl_s  : std_logic;
125
  signal out_mux_ctrl_s2 : std_logic;
126
 
127
-------------------------------------------------------------------------------
128
-- Architecture: begin
129
-------------------------------------------------------------------------------
130
begin
131
 
132
  fdct_sm_settings <= Reg(1);
133
  zig_sm_settings  <= Reg(2);
134 34 mikel262
  qua_sm_settings  <= Reg(3);
135
  rle_sm_settings  <= Reg(4);
136
  huf_sm_settings  <= Reg(5);
137
  bs_sm_settings   <= Reg(6);
138 25 mikel262
 
139
  fdct_start    <= start_PB(1);
140
  ready_PB(1)   <= fdct_ready;
141
 
142
  zig_start     <= start_PB(2);
143
  ready_PB(2)   <= zig_ready;
144
 
145 34 mikel262
  qua_start     <= start_PB(3);
146
  ready_PB(3)   <= qua_ready;
147 25 mikel262
 
148 34 mikel262
  rle_start     <= start_PB(4);
149
  ready_PB(4)   <= rle_ready;
150 25 mikel262
 
151 34 mikel262
  huf_start     <= start_PB(5);
152
  ready_PB(5)   <= huf_ready;
153 25 mikel262
 
154 34 mikel262
  bs_start      <= start_PB(6);
155
  ready_PB(6)   <= bs_ready;
156
 
157 25 mikel262
  -----------------------------------------------------------------------------
158 34 mikel262
  -- CTRLSM 1..NUM_STAGES
159 25 mikel262
  -----------------------------------------------------------------------------
160 34 mikel262
  G_S_CTRL_SM : for i in 1 to NUM_STAGES generate
161 25 mikel262
 
162 34 mikel262
    -- CTRLSM 1..NUM_STAGES
163 25 mikel262
    U_S_CTRL_SM : entity work.SingleSM
164
    port map
165
    (
166
        CLK          => CLK,
167
        RST          => RST,
168
        -- from/to SM(m)   
169
        start_i      => start(i),
170
        idle_o       => idle(i),
171
        -- from/to SM(m+1) 
172
        idle_i       => idle(i+1),
173
        start_o      => start(i+1),
174
        -- from/to processing block
175
        pb_rdy_i     => ready_PB(i),
176
        pb_start_o   => start_PB(i),
177
        -- state out
178
        fsm_o        => fsm(i)
179
    );
180
  end generate G_S_CTRL_SM;
181
 
182 42 mikel262
  idle(NUM_STAGES+1) <= not outif_almost_full;
183 25 mikel262
 
184
  -------------------------------------------------------------------
185 34 mikel262
  -- Regs
186 25 mikel262
  -------------------------------------------------------------------
187 34 mikel262
  G_REG_SM : for i in 1 to NUM_STAGES generate
188 25 mikel262
    p_reg1 : process(CLK, RST)
189
    begin
190
      if RST = '1' then
191
        Reg(i) <= C_SM_SETTINGS;
192
      elsif CLK'event and CLK = '1' then
193
        if start(i) = '1' then
194
          if i = 1 then
195
            Reg(i).x_cnt   <= RSM.x_cnt;
196
            Reg(i).y_cnt   <= RSM.y_cnt;
197
            Reg(i).cmp_idx <= RSM.cmp_idx;
198
          else
199
            Reg(i) <= Reg(i-1);
200
          end if;
201
        end if;
202
      end if;
203
    end process;
204
  end generate G_REG_SM;
205
 
206
  -------------------------------------------------------------------
207
  -- Main_SM
208
  -------------------------------------------------------------------
209
  p_main_sm : process(CLK, RST)
210
  begin
211
    if RST = '1' then
212
      main_state        <= IDLES;
213
      start(1)          <= '0';
214
      start1_d          <= '0';
215
      jpeg_ready        <= '0';
216
      RSM.x_cnt         <= (others => '0');
217
      RSM.y_cnt         <= (others => '0');
218
      jpeg_busy         <= '0';
219
      RSM.cmp_idx       <= (others => '0');
220
      out_mux_ctrl_s    <= '0';
221
      out_mux_ctrl_s2   <= '0';
222
      jfif_eoi          <= '0';
223
      out_mux_ctrl      <= '0';
224
      jfif_start        <= '0';
225
    elsif CLK'event and CLK = '1' then
226
      start(1)          <= '0';
227
      start1_d          <= start(1);
228
      jpeg_ready        <= '0';
229
      jfif_start        <= '0';
230
      out_mux_ctrl_s2   <= out_mux_ctrl_s;
231
      out_mux_ctrl      <= out_mux_ctrl_s2;
232
 
233
      case main_state is
234
        -------------------------------
235
        -- IDLE
236
        -------------------------------
237
        when IDLES =>
238
          if sof = '1' then
239
            RSM.x_cnt    <= (others => '0');
240
            RSM.y_cnt    <= (others => '0');
241
            jfif_start   <= '1';
242
            out_mux_ctrl_s <= '0';
243
            jfif_eoi     <= '0';
244
            main_state <= JFIF;
245
          end if;
246
 
247
        -------------------------------
248
        -- JFIF
249
        -------------------------------
250
        when JFIF =>
251
          if jfif_ready = '1' then
252
            out_mux_ctrl_s <= '1';
253
            main_state   <= HORIZ;
254
          end if;
255
 
256
        -------------------------------
257
        -- HORIZ
258
        -------------------------------
259
        when HORIZ =>
260
          if RSM.x_cnt < unsigned(img_size_x) then
261
            main_state <= COMP;
262
          else
263
            RSM.x_cnt      <= (others => '0');
264
            main_state <= VERT;
265
          end if;
266
 
267
        -------------------------------
268
        -- COMP
269
        -------------------------------
270
        when COMP =>
271
          if idle(1) = '1' and start(1) = '0' then
272
            if RSM.cmp_idx < unsigned(cmp_max) then
273
              start(1)   <= '1';
274
            else
275
              RSM.cmp_idx    <= (others => '0');
276
              RSM.x_cnt      <= RSM.x_cnt + 8;
277
              main_state <= HORIZ;
278
            end if;
279
          end if;
280
 
281
        -------------------------------
282
        -- VERT
283
        -------------------------------
284
        when VERT =>
285
          if RSM.y_cnt < unsigned(img_size_y)-8 then
286
            RSM.x_cnt <= (others => '0');
287
            RSM.y_cnt <= RSM.y_cnt + 8;
288
            main_state <= HORIZ;
289
          else
290 34 mikel262
            if idle(NUM_STAGES downto 1) = (NUM_STAGES-1 downto 0 => '1') then
291
              main_state     <= EOI;
292
              jfif_eoi       <= '1';
293 25 mikel262
              out_mux_ctrl_s <= '0';
294 34 mikel262
              jfif_start     <= '1';
295 25 mikel262
            end if;
296
          end if;
297
 
298
        -------------------------------
299
        -- VERT
300
        -------------------------------
301
        when EOI =>
302
          if jfif_ready = '1' then
303
            jpeg_ready   <= '1';
304
            main_state   <= IDLES;
305
          end if;
306
 
307
        -------------------------------
308
        -- others
309
        -------------------------------
310
        when others =>
311
          main_state <= IDLES;
312
 
313
      end case;
314
 
315
      if start1_d = '1' then
316
        RSM.cmp_idx    <= RSM.cmp_idx + 1;
317
      end if;
318
 
319
      if main_state = IDLES then
320
        jpeg_busy <= '0';
321
      else
322
        jpeg_busy <= '1';
323
      end if;
324
 
325
    end if;
326
  end process;
327
 
328
 
329
 
330
end architecture RTL;
331
-------------------------------------------------------------------------------
332
-- Architecture: end
333
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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