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

Subversion Repositories mkjpeg

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

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

powered by: WebSVN 2.1.0

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