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

Subversion Repositories mkjpeg

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

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

powered by: WebSVN 2.1.0

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