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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_codec_sdp.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2013 Stefano Tonello                          --
6
--                                                             --
7
-- This source file may be used and distributed without        --
8
-- restriction provided that this copyright statement is not   --
9
-- removed from the file and that any derivative work contains --
10
-- the original copyright notice and the associated disclaimer.--
11
--                                                             --
12
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY         --
13
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   --
15
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      --
16
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         --
17
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    --
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   --
19
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        --
20
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  --
21
-- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  --
22
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  --
23
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         --
24
-- POSSIBILITY OF SUCH DAMAGE.                                 --
25
--                                                             --
26
-----------------------------------------------------------------
27
 
28
---------------------------------------------------------------
29
-- G.729a codec (Single Data Port)
30
---------------------------------------------------------------
31
 
32
---------------------------------------------------------------
33
-- Notes:
34
-- SDP version uses a single data port (DI_i/DO_o) to transfer
35
-- coder input/output data, decoder input/output data and
36
-- ASIP state data, and it therefore more suitable for systems
37
-- with a single main bus, possibly connected to an external
38
-- DRAM memory.
39
---------------------------------------------------------------
40
 
41
library IEEE;
42
use IEEE.std_logic_1164.all;
43
use IEEE.numeric_std.all;
44
use STD.textio.all;
45
 
46
library work;
47
use work.G729A_ASIP_PKG.all;
48
use WORK.G729A_ASIP_BASIC_PKG.all;
49
use WORK.G729A_ASIP_ARITH_PKG.all;
50
use WORK.G729A_ASIP_OP_PKG.all;
51
use WORK.G729A_ASIP_CFG_PKG.all;
52
use work.G729A_CODEC_INTF_PKG.all;
53
 
54
entity G729A_CODEC_SDP is
55
  generic(
56
    -- synthesis translate_off
57
    ST_FILE : string;
58
    WB_FILE : string;
59
    -- synthesis translate_on
60
    REGISTER_INPUTS : std_logic := '0';
61
    REGISTER_OUTPUTS : std_logic := '0';
62
    USE_ROM_MIF : std_logic := '0';
63
    SIMULATION_ONLY : std_logic := '1'
64
  );
65
  port(
66
    CLK_i : in std_logic; -- clock
67
    RST_i : in std_logic; -- reset
68
    STRT_i : in std_logic; -- start
69
    OPS_i : in std_logic_vector(3-1 downto 0);
70
    RE_i : in std_logic; -- state read-enable
71
    WE_i : in std_logic; -- state write-enable
72
    DI_i : in std_logic_vector(SDLEN-1 downto 0); -- data-in
73
 
74
    BSY_o : out std_logic; -- busy
75
    DMAE_o : out std_logic; -- DMA enable
76
    STS_o : out std_logic_vector(3-1 downto 0); -- status
77
    DV_o : out std_logic; -- data-out valid
78
    DO_o : out std_logic_vector(SDLEN-1 downto 0) -- data-out
79
  );
80
end G729A_CODEC_SDP;
81
 
82
architecture ARC of G729A_CODEC_SDP is
83
 
84
  -- I/O transfer sub-programs starting address
85
  constant DATA_IN : natural := 7645;
86
  constant COD_DATA_OUT : natural := 8663;
87
  constant DEC_DATA_IN : natural := 8695;
88
  constant DEC_DATA_OUT : natural := 8679;
89
  constant STATE_IN : natural := 8719;
90
  constant STATE_OUT : natural := 8743;
91
 
92
  component G729A_ASIP_TOP_2W is
93
    generic(
94
      -- synthesis translate_off
95
      ST_FILE : string := "NONE";
96
      WB_FILE : string := "NONE";
97
      -- synthesis translate_on
98
      USE_ROM_MIF : std_logic := '0';
99
      SIMULATION_ONLY : std_logic := '1'
100
    );
101
    port(
102
      CLK_i : in std_logic; -- clock
103
      RST_i : in std_logic; -- reset
104
      STRT_i : in std_logic; -- start
105
      SADR_i : in std_logic_vector(ALEN-1 downto 0);
106
      SRST_i : in std_logic; -- soft_reset
107
      DIWE_i : in std_logic; -- data-in write-enable
108
      DI_i : in std_logic_vector(SDLEN-1 downto 0); -- data-in
109
      DORE_i : in std_logic; -- data-out read-enable
110
      CHK_ENB_i : in std_logic; -- check-enable
111
      XDMAE_i : in std_logic; -- DMA enable
112
      XWE_i : in std_logic; -- DMA write-enable
113
      XADR_i : in std_logic_vector(ALEN-1 downto 0);
114
      XDI_i : in std_logic_vector(SDLEN-1 downto 0); -- DMA data-in
115
 
116
      BSY_o : out std_logic; -- busy
117
      DIV_o : out std_logic; --
118
      DOV_o : out std_logic; --
119
      DO_o : out std_logic_vector(SDLEN-1 downto 0); -- data-out
120
      XDO_o : out std_logic_vector(SDLEN-1 downto 0) -- DMA data-out
121
    );
122
  end component;
123
 
124
  component G729A_ASIP_SPC is
125
    generic(
126
      SIMULATION_ONLY : std_logic := '1'
127
    );
128
    port(
129
      CLK_i : in std_logic;
130
      RST_i : in std_logic;
131
      STRT_i : in std_logic;
132
      OPS_i : in std_logic_vector(3-1 downto 0);
133
      A_BSY_i : in std_logic;
134
      D_BSY_i : in std_logic;
135
 
136
      SADR_o : out unsigned(ALEN-1 downto 0);
137
      A_STRT_o : out std_logic;
138
      A_DMAE_o : out std_logic;
139
      A_ADR_o : out unsigned(ALEN-1 downto 0);
140
      D_STRT_o : out std_logic;
141
      D_WE_o : out std_logic;
142
      ASEL_o : out std_logic_vector(3-1 downto 0);
143
      BLEN_o : out natural range 0 to 2048-1;
144
      BSY_o : out std_logic;
145
      STS_o : out std_logic_vector(3-1 downto 0);
146
      CHKE_o : out std_logic
147
    );
148
  end component;
149
 
150
  signal STRT_q : std_logic;
151
  signal OPS_q : std_logic_vector(3-1 downto 0);
152
  signal RE_q : std_logic;
153
  signal WE_q : std_logic;
154
  signal DI_q : std_logic_vector(SDLEN-1 downto 0);
155
  signal DO_q : std_logic_vector(SDLEN-1 downto 0);
156
  signal DV_q,DV_Q2 : std_logic;
157
 
158
  signal SRST : std_logic := '0';
159
  signal STRT : std_logic;
160
  signal SADR : unsigned(ALEN-1 downto 0);
161
  signal IO_DDATI : std_logic_vector(SDLEN-1 downto 0);
162
  signal ASIP_BSY : std_logic;
163
  signal IO_DIWE : std_logic;
164
  signal IO_DORE : std_logic;
165
  signal DADR_L,DADR_S : unsigned(ALEN-1 downto 0);
166
  signal IO_DDATO : std_logic_vector(SDLEN-1 downto 0);
167
  signal ASIP_DIV,ASIP_DOV : std_logic;
168
 
169
  signal SPC_D_WE : std_logic;
170
  signal SPC_CHKE : std_logic;
171
  signal SPC_BSY : std_logic;
172
  signal SPC_A_DMAE : std_logic;
173
  signal SPC_D_STRT : std_logic;
174
  signal SPC_A_STRT : std_logic;
175
  signal SPC_A_ADR : unsigned(ALEN-1 downto 0);
176
  signal SPC_BLEN : natural range 0 to 2048-1;
177
  signal SPC_SADR : unsigned(ALEN-1 downto 0);
178
  signal SPC_ASEL : std_logic_vector(3-1 downto 0);
179
 
180
  signal DMA_ENB : std_logic;
181
  signal DMA_BSY : std_logic;
182
  signal DMA_WE : std_logic;
183
  signal DMA_ADR : std_logic_vector(ALEN-1 downto 0);
184
  signal DMA_ADR_q,DMA_ADR_q2 : unsigned(ALEN-1 downto 0);
185
  signal DMA_DI,DMA_DI_q : std_logic_vector(SDLEN-1 downto 0);
186
  signal DMA_DO,DMA_DO_q : std_logic_vector(SDLEN-1 downto 0);
187
  signal DMA_CNT_q : unsigned(ALEN-1 downto 0);
188
  signal DMA_DEC : std_logic;
189
 
190
  signal ERROR_q : std_logic := '0';
191
  signal CHK : integer;
192
  signal VALID_OPS : std_logic;
193
 
194
begin
195
 
196
  ---------------------------------------------------
197
  -- I/O Interface signals (unused)
198
  ---------------------------------------------------
199
 
200
  IO_DIWE <= '0';
201
  IO_DDATI <= (others => '0');
202
  IO_DORE <= '0';
203
 
204
  ---------------------------------------------------
205
  -- Input signal registers
206
  ---------------------------------------------------
207
 
208
  -- Warning: registering RE_i adds an extra delay
209
  -- cycles between RE_i assertion and data output.
210
 
211
  G0_T : if (REGISTER_INPUTS = '1') generate
212
 
213
  process(CLK_i)
214
  begin
215
    if(CLK_i = '1' and CLK_i'event) then
216
      if(RST_i = '1') then
217
        STRT_q <= '0';
218
        RE_q <= '0';
219
        WE_q <= '0';
220
      else
221
        STRT_q <= STRT_i;
222
        RE_q <= RE_i;
223
        WE_q <= WE_i;
224
      end if;
225
      OPS_q <= OPS_i;
226
      DI_q <= DI_i;
227
    end if;
228
  end process;
229
 
230
  end generate;
231
 
232
  G0_F : if (REGISTER_INPUTS = '0') generate
233
 
234
    STRT_q <= STRT_i;
235
    RE_q <= RE_i;
236
    WE_q <= WE_i;
237
    OPS_q <= OPS_i;
238
    DI_q <= DI_i;
239
 
240
  end generate;
241
 
242
  ---------------------------------------------------
243
  -- Output signal registers
244
  ---------------------------------------------------
245
 
246
  -- Note: only data-out signal DO_o needs to be
247
  -- explicitly registred, other output signals are
248
  -- already driven by registers.
249
 
250
  -- Warning: registering DO_o adds an extra delay
251
  -- cycles between RE_i assertion and data output.
252
 
253
  G1_T : if (REGISTER_OUTPUTS = '1') generate
254
 
255
  process(CLK_i)
256
  begin
257
    if(CLK_i = '1' and CLK_i'event) then
258
      DO_q <= DMA_DO;
259
    end if;
260
  end process;
261
 
262
  end generate;
263
 
264
  G1_F : if (REGISTER_OUTPUTS = '0') generate
265
 
266
    DO_q <= DMA_DO;
267
 
268
  end generate;
269
 
270
  ---------------------------------------------------
271
  -- Data(-out) valid flag
272
  ---------------------------------------------------
273
 
274
  -- this flag get asserted when valid data are available
275
  -- on DO_o in response to an assertion of RE_i.
276
 
277
  process(CLK_i)
278
  begin
279
    if(CLK_i = '1' and CLK_i'event) then
280
      if(RST_i = '1') then
281
        DV_q <= '0';
282
      else
283
        DV_q <= (DMA_ENB and not(SPC_D_WE) and RE_q);
284
      end if;
285
    end if;
286
  end process;
287
 
288
  G2_T : if (REGISTER_OUTPUTS = '1') generate
289
 
290
  process(CLK_i)
291
  begin
292
    if(CLK_i = '1' and CLK_i'event) then
293
      if(RST_i = '1') then
294
        DV_q2 <= '0';
295
      else
296
        DV_q2 <= DV_q;
297
      end if;
298
    end if;
299
  end process;
300
 
301
  end generate;
302
 
303
  ---------------------------------------------------
304
  -- DMA logic
305
  ---------------------------------------------------
306
 
307
  DMA_ENB <= SPC_A_DMAE;
308
 
309
  DMA_WE <= (SPC_D_WE and WE_q);
310
 
311
  DMA_DI <= DI_q;
312
 
313
  process(CLK_i)
314
  begin
315
    if(CLK_i = '1' and CLK_i'event) then
316
      if(RST_i = '1') then
317
        DMA_CNT_q <= to_unsigned(0,ALEN);
318
      elsif(RST_i = '1' or SPC_D_STRT = '1') then
319
        DMA_CNT_q <= to_unsigned(SPC_BLEN - 1,ALEN);
320
      elsif(DMA_CNT_q > 0 and DMA_DEC = '1') then
321
        DMA_CNT_q <= DMA_CNT_q - 1;
322
      end if;
323
    end if;
324
  end process;
325
 
326
  DMA_DEC <= (SPC_D_WE and WE_q) or (not(SPC_D_WE) and RE_q);
327
 
328
  DMA_BSY <= '1' when DMA_CNT_q > 0 else '0';
329
 
330
  process(CLK_i)
331
  begin
332
    if(CLK_i = '1' and CLK_i'event) then
333
      if(RST_i = '1') then
334
        DMA_ADR_q <= to_unsigned(0,ALEN);
335
      elsif(RST_i = '1' or SPC_D_STRT = '1') then
336
        DMA_ADR_q <= SPC_A_ADR;
337
      elsif(DMA_CNT_q > 0 and DMA_DEC = '1') then
338
        DMA_ADR_q <= DMA_ADR_q + 1;
339
      end if;
340
    end if;
341
  end process;
342
 
343
  DMA_ADR <= to_std_logic_vector(DMA_ADR_q);
344
 
345
  ---------------------------------------------------
346
  -- ASIP Core Top module
347
  ---------------------------------------------------
348
 
349
  U_ASIP : G729A_ASIP_TOP_2W
350
    generic map(
351
      -- synthesis translate_off
352
      ST_FILE => ST_FILE,
353
      WB_FILE => WB_FILE,
354
      -- synthesis translate_on
355
      USE_ROM_MIF => USE_ROM_MIF,
356
      SIMULATION_ONLY => SIMULATION_ONLY
357
    )
358
    port map(
359
      CLK_i => CLK_i,
360
      RST_i => RST_i,
361
      STRT_i => SPC_A_STRT,
362
      SADR_i => to_std_logic_vector(SPC_SADR),
363
      SRST_i => SRST, -- inactive!
364
      DIWE_i => IO_DIWE,
365
      DI_i => IO_DDATI,
366
      DORE_i => IO_DORE,
367
      CHK_ENB_i => SPC_CHKE,
368
      XDMAE_i => DMA_ENB,
369
      XWE_i => DMA_WE,
370
      XADR_i => DMA_ADR,
371
      XDI_i => DMA_DI,
372
 
373
      BSY_o => ASIP_BSY,
374
      DIV_o => open, --ASIP_DIV, -- not used
375
      DOV_o => open, --ASIP_DOV, -- not used
376
      DO_o => open, --IO_DDATO,
377
      XDO_o => DMA_DO
378
    );
379
 
380
  ---------------------------------------------------
381
  -- ASIP Sub-program Controller
382
  ---------------------------------------------------
383
 
384
  U_SPC : G729A_ASIP_SPC
385
    generic map(
386
      SIMULATION_ONLY => SIMULATION_ONLY
387
    )
388
    port map(
389
      CLK_i => CLK_i,
390
      RST_i => RST_i,
391
      STRT_i => STRT_q,
392
      OPS_i => OPS_q,
393
      A_BSY_i => ASIP_BSY,
394
      D_BSY_i => DMA_BSY,
395
 
396
      SADR_o => SPC_SADR,
397
      A_STRT_o => SPC_A_STRT, -- ASIP start
398
      A_DMAE_o => SPC_A_DMAE, -- ASIP DMA enable
399
      A_ADR_o => SPC_A_ADR, -- ASIP DMA adr.
400
      D_STRT_o => SPC_D_STRT, -- DMA start
401
      D_WE_o => SPC_D_WE, -- DMA write-enable
402
      ASEL_o => open, --SPC_ASEL, -- unused
403
      BLEN_o => SPC_BLEN, -- DMA burst len.
404
      BSY_o => SPC_BSY,
405
      STS_o => STS_o,
406
      CHKE_o => SPC_CHKE
407
    );
408
 
409
  ---------------------------------------------------
410
  -- Outputs
411
  ---------------------------------------------------
412
 
413
  DMAE_o <= DMA_ENB;
414
  BSY_o <= SPC_BSY;
415
 
416
  G3_T : if (REGISTER_OUTPUTS = '1') generate
417
  DV_o <= DV_q2;
418
  end generate;
419
 
420
  G3_F : if (REGISTER_OUTPUTS = '0') generate
421
  DV_o <= DV_q;
422
  end generate;
423
 
424
  DO_o <= DO_q;
425
 
426
  ---------------------------------------------------
427
  -- Checkers
428
  ---------------------------------------------------
429
 
430
  -- synthesis translate_off
431
 
432
  -- Check that STRT_i signal is either '0' or '1' on clock
433
  -- rising edge (ignore reset).
434
 
435
  assert not(not(STRT_i = '0' or STRT_i = '1') and RST_i = '0'
436
    and CLK_i = '1' and CLK_i'event)
437
  report "STRT_i is not '0' or '1' on clock rising edge!"
438
  severity ERROR;
439
 
440
  -- Check that OPS_i has a valid value when STRT_i is asserted
441
  -- on a clock rising edge (ignore reset).
442
 
443
  VALID_OPS <= '1' when (
444
    OPS_i = INIT or
445
    OPS_i = SAVS or
446
    OPS_i = RSTS or
447
    OPS_i = RUNF or
448
    OPS_i = RUNC or
449
    OPS_i = RUND
450
  ) else '0';
451
 
452
  assert not(VALID_OPS = '0' and STRT_i = '1' and RST_i = '0' and
453
    CLK_i = '1' and CLK_i'event)
454
  report "invalid OPS_i value when STRT_i asserted!"
455
  severity ERROR;
456
 
457
  -- Check that RE_i is asserted only in DMA mode (ignore reset).
458
 
459
  assert not(DMA_ENB = '0' and RE_i = '1' and RST_i = '0' and
460
    CLK_i = '1' and CLK_i'event)
461
  report "RE_i asserted not in DMA mode!"
462
  severity ERROR;
463
 
464
  -- Check that RE_i is asserted only in DMA read mode (ignore reset).
465
 
466
  assert not(DMA_ENB = '1' and SPC_D_WE = '1' and RE_i = '1' and RST_i = '0' and
467
    CLK_i = '1' and CLK_i'event)
468
  report "RE_i asserted in DMA write mode!"
469
  severity ERROR;
470
 
471
  -- Check that WE_i is asserted only in DMA mode (ignore reset).
472
 
473
  assert not(DMA_ENB = '0' and WE_i = '1' and RST_i = '0' and
474
    CLK_i = '1' and CLK_i'event)
475
  report "WE_i asserted not in DMA mode!"
476
  severity ERROR;
477
 
478
  -- Check that WE_i is asserted only in DMA write mode (ignore reset).
479
 
480
  assert not(DMA_ENB = '1' and SPC_D_WE = '0' and WE_i = '1' and RST_i = '0' and
481
    CLK_i = '1' and CLK_i'event)
482
  report "WE_i asserted in DMA read mode!"
483
  severity ERROR;
484
 
485
  -- synthesis translate_on
486
 
487
end ARC;

powered by: WebSVN 2.1.0

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