Skip to content

Commit a72fa8b

Browse files
committed
cn0577: Use dmac api
Signed-off-by: Stanca Pop <stanca.pop@analog.com>
1 parent d7b9d72 commit a72fa8b

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

testbenches/project/cn0577/tests/test_program.sv

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import pwm_gen_api_pkg::*;
4646
import axi_vip_pkg::*;
4747
import axi4stream_vip_pkg::*;
4848
import cn0577_environment_pkg::*;
49+
import adc_api_pkg::*;
50+
import common_api_pkg::*;
4951

5052
import `PKGIFY(test_harness, mng_axi_vip)::*;
5153
import `PKGIFY(test_harness, ddr_axi_vip)::*;
@@ -81,7 +83,9 @@ localparam bit DEBUG = 1;
8183
// dco delay compared to the reference clk
8284
localparam DCO_DELAY = 12;
8385

86+
dmac_api cn0577_dmac_api;
8487
pwm_gen_api cn0577_pwm_gen_api;
88+
adc_api ltc2387_adc_api;
8589

8690
// dma interface
8791
wire adc_valid;
@@ -102,18 +106,27 @@ initial begin
102106
`TH.`SYS_RST.inst.IF,
103107
`TH.`MNG_AXI.inst.IF,
104108
`TH.`DDR_AXI.inst.IF);
109+
cn0577_dmac_api = new(
110+
"CN0577 DMAC API",
111+
base_env.mng.sequencer,
112+
AXI_LTC2387_DMA_BA);
105113

106114
cn0577_pwm_gen_api = new(
107115
"CN0577 AXI PWM GEN API",
108116
base_env.mng.sequencer,
109117
`AXI_PWM_GEN_BA);
110118

119+
ltc2387_adc_api = new(
120+
"LTC2387 ADC Common API",
121+
base_env.mng.sequencer,
122+
AXI_LTC2387_BA);
123+
111124
setLoggerVerbosity(ADI_VERBOSITY_LOW);
112125

113126
base_env.start();
114127
base_env.sys_reset();
115128

116-
sanity_test();
129+
sanity_tests();
117130

118131
#100ns;
119132

@@ -248,13 +261,14 @@ initial begin
248261
end
249262

250263
//---------------------------------------------------------------------------
251-
// Sanity test reg interface
264+
// Sanity tests
252265
//---------------------------------------------------------------------------
253266

254-
task sanity_test();
255-
axi_write (`AXI_LTC2387_BA + GetAddrs(COMMON_REG_SCRATCH), `SET_COMMON_REG_SCRATCH_SCRATCH(32'hDEADBEEF));
256-
axi_read_v (`AXI_LTC2387_BA + GetAddrs(COMMON_REG_SCRATCH), `SET_COMMON_REG_SCRATCH_SCRATCH(32'hDEADBEEF));
257-
`INFO(("Sanity Test Done"), ADI_VERBOSITY_LOW);
267+
task sanity_tests();
268+
ltc2387_adc_api.sanity_test();
269+
cn0577_dmac_api.sanity_test();
270+
cn0577_pwm_gen_api.sanity_test();
271+
`INFO(("Sanity Tests Done"), ADI_VERBOSITY_LOW);
258272
endtask
259273

260274
//---------------------------------------------------------------------------
@@ -301,13 +315,18 @@ task data_acquisition_test();
301315
`INFO(("AXI_PWM_GEN started"), ADI_VERBOSITY_LOW);
302316

303317
// Configure DMA
304-
base_env.mng.sequencer.RegWrite32(`AXI_LTC2387_DMA_BA + GetAddrs(DMAC_CONTROL), `SET_DMAC_CONTROL_ENABLE(1)); // Enable DMA
305-
base_env.mng.sequencer.RegWrite32(`AXI_LTC2387_DMA_BA + GetAddrs(DMAC_FLAGS),
306-
`SET_DMAC_FLAGS_TLAST(1) |
307-
`SET_DMAC_FLAGS_PARTIAL_REPORTING_EN(1)
308-
); // Use TLAST
309-
base_env.mng.sequencer.RegWrite32(`AXI_LTC2387_DMA_BA + GetAddrs(DMAC_X_LENGTH), `SET_DMAC_X_LENGTH_X_LENGTH((NUM_OF_TRANSFERS*4)-1)); // X_LENGHTH = 1024-1
310-
base_env.mng.sequencer.RegWrite32(`AXI_LTC2387_DMA_BA + GetAddrs(DMAC_DEST_ADDRESS), `SET_DMAC_DEST_ADDRESS_DEST_ADDRESS(`DDR_BA)); // DEST_ADDRESS
318+
cn0577_dmac_api.set_irq_mask(
319+
.transfer_completed(1'b0),
320+
.transfer_queued(1'b1));
321+
cn0577_dmac_api.enable_dma();
322+
cn0577_dmac_api.set_flags(
323+
.cyclic(1'b0),
324+
.tlast(1'b1),
325+
.partial_reporting_en(1'b1));
326+
cn0577_dmac_api.set_lengths(
327+
.xfer_length_x((NUM_OF_TRANSFERS*4)-1),
328+
.xfer_length_y(32'h0));
329+
cn0577_dmac_api.set_dest_addr(`DDR_BA);
311330

312331
// Configure AXI_LTC2387
313332
axi_write (`AXI_LTC2387_BA + GetAddrs(ADC_COMMON_REG_RSTN), `SET_ADC_COMMON_REG_RSTN_RSTN(0));
@@ -319,7 +338,7 @@ task data_acquisition_test();
319338

320339
transfer_status = 1;
321340

322-
base_env.mng.sequencer.RegWrite32(`AXI_LTC2387_DMA_BA + GetAddrs(DMAC_TRANSFER_SUBMIT), `SET_DMAC_TRANSFER_SUBMIT_TRANSFER_SUBMIT(1)); // Submit transfer DMA
341+
cn0577_dmac_api.transfer_start();
323342

324343
wait(transfer_cnt == 2 * NUM_OF_TRANSFERS );
325344

@@ -328,6 +347,13 @@ task data_acquisition_test();
328347
@(posedge ref_clk);
329348
transfer_status = 0;
330349

350+
@(posedge system_tb.test_harness.axi_ltc2387_dma.irq);
351+
352+
//Clear interrupt
353+
cn0577_dmac_api.clear_irq_pending(
354+
.transfer_completed(1'b1),
355+
.transfer_queued(1'b0));
356+
331357
// Stop pwm gen
332358
cn0577_pwm_gen_api.reset();
333359
`INFO(("AXI_PWM_GEN stopped"), ADI_VERBOSITY_LOW);`INFO(("AXI_PWM_GEN stopped"), ADI_VERBOSITY_LOW);

0 commit comments

Comments
 (0)