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

Subversion Repositories mkjpeg

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

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

powered by: WebSVN 2.1.0

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