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

Subversion Repositories mkjpeg

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

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

powered by: WebSVN 2.1.0

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