| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- `timescale 1ns/1ps
- module analog_ip (
- inout BAUD_RATE,
- inout TEST_SINGLE,
- inout UART1_RX,
- inout UART1_TX,
- inout so_io1,
- input csn_out_data,
- input csn_out_en,
- output tri0 rxd1_ip_in,
- input sck_out_data,
- input sck_out_en,
- output tri0 so_io1_in,
- input so_io1_out_data,
- input so_io1_out_en,
- input txd1_ip_out_data,
- input txd1_ip_out_en,
- input sys_clock,
- input bus_clock,
- input resetn,
- input stop,
- input [1:0] mem_ahb_htrans,
- input mem_ahb_hready,
- input mem_ahb_hwrite,
- input [31:0] mem_ahb_haddr,
- input [2:0] mem_ahb_hsize,
- input [2:0] mem_ahb_hburst,
- input [31:0] mem_ahb_hwdata,
- output tri1 mem_ahb_hreadyout,
- output tri0 mem_ahb_hresp,
- output tri0 [31:0] mem_ahb_hrdata,
- output tri0 slave_ahb_hsel,
- output tri1 slave_ahb_hready,
- input slave_ahb_hreadyout,
- output tri0 [1:0] slave_ahb_htrans,
- output tri0 [2:0] slave_ahb_hsize,
- output tri0 [2:0] slave_ahb_hburst,
- output tri0 slave_ahb_hwrite,
- output tri0 [31:0] slave_ahb_haddr,
- output tri0 [31:0] slave_ahb_hwdata,
- input slave_ahb_hresp,
- input [31:0] slave_ahb_hrdata,
- output tri0 [3:0] ext_dma_DMACBREQ,
- output tri0 [3:0] ext_dma_DMACLBREQ,
- output tri0 [3:0] ext_dma_DMACSREQ,
- output tri0 [3:0] ext_dma_DMACLSREQ,
- input [3:0] ext_dma_DMACCLR,
- input [3:0] ext_dma_DMACTC,
- output tri0 [3:0] local_int
- );
- assign UART1_TX = txd1_ip_out_en ? txd1_ip_out_data : 1'bz;
- assign rxd1_ip_in = UART1_RX;
- assign slave_ahb_hsel = 1'b0;
- assign slave_ahb_hready = 1'b1;
- assign slave_ahb_htrans = 2'b00;
- assign slave_ahb_hsize = 3'b000;
- assign slave_ahb_hburst = 3'b000;
- assign slave_ahb_hwrite = 1'b0;
- assign slave_ahb_haddr = 32'b0;
- assign slave_ahb_hwdata = 32'b0;
- assign ext_dma_DMACBREQ = 4'b0000; // 禁用DMA
- assign ext_dma_DMACLBREQ = 4'b0000;
- assign ext_dma_DMACSREQ = 4'b0000;
- assign ext_dma_DMACLSREQ = 4'b0000;
- assign local_int = 4'b0000; // 禁用中断
- // ==============================================
- // 核心RAM参数定义
- // ==============================================
- parameter RAM_SIZE = 2048; // 总容量:1024*16bit = 2048字节
- parameter RAM_DEPTH = 1024; // 数据深度:1024个
- parameter RAM_WIDTH = 16; // 数据位宽:16bit
- parameter ADDR_BITS = 16;
- parameter DATA_BITS = 32;
- parameter PER_BITS = 12;
- parameter PER_CNT = 4; // APB外设:ADC0(0)、DAC0(1),这里设置4是为了兼容3000地址的DAC0
- // 前四个地址用作说明 未实际使用对应变量
- // parameter ADC0_ADDR = 'h0000; // ADC0地址
- // parameter CFG_REG_ADDR = 'h1000; // 配置参数模块偏移地址
- // parameter TRIG_CTRL_ADDR= 'h2000; // 触发模块偏移地址
- // parameter DAC0_ADDR = 'h3000; // DAC0地址
- parameter RAM_BASE_ADDR = 'h6000; // 双口RAM APB地址 实际应用
- // ==============================================
- // AHB2APB 桥
- // ==============================================
- wire apb_psel;
- wire apb_penable;
- wire apb_pwrite;
- wire [ADDR_BITS-1:0] apb_paddr;
- wire [DATA_BITS-1:0] apb_pwdata;
- wire [3:0] apb_pstrb;
- wire [2:0] apb_pprot;
- wire apb_pready = 1'b1;
- wire apb_pslverr = 1'b0;
- reg [DATA_BITS-1:0] apb_prdata;
- wire apb_clock = bus_clock;
- ahb2apb #(ADDR_BITS, DATA_BITS) ahb2apb_inst(
- .reset (!resetn ),
- .ahb_clock (sys_clock ),
- .ahb_hmastlock(1'b0 ),
- .ahb_htrans (mem_ahb_htrans ),
- .ahb_hsel (1'b1 ),
- .ahb_hready (mem_ahb_hready ),
- .ahb_hwrite (mem_ahb_hwrite ),
- .ahb_haddr (mem_ahb_haddr[ADDR_BITS-1:0]),
- .ahb_hsize (mem_ahb_hsize ),
- .ahb_hburst (mem_ahb_hburst ),
- .ahb_hprot (4'b0011 ),
- .ahb_hwdata (mem_ahb_hwdata ),
- .ahb_hrdata (mem_ahb_hrdata ),
- .ahb_hreadyout(mem_ahb_hreadyout ),
- .ahb_hresp (mem_ahb_hresp ),
- .apb_clock (apb_clock ),
- .apb_psel (apb_psel ),
- .apb_penable (apb_penable ),
- .apb_pwrite (apb_pwrite ),
- .apb_paddr (apb_paddr ),
- .apb_pwdata (apb_pwdata ),
- .apb_pstrb (apb_pstrb ),
- .apb_pprot (apb_pprot ),
- .apb_pready (apb_pready ),
- .apb_pslverr (apb_pslverr ),
- .apb_prdata (apb_prdata )
- );
- // ==============================================
- // APB 外设选择
- // ==============================================
- wire [PER_CNT-1:0] select = 1 << (apb_paddr[ADDR_BITS-1:PER_BITS]);
- wire per_psel[PER_CNT];
- wire per_penable[PER_CNT];
- wire per_pwrite[PER_CNT];
- wire [PER_BITS-1:0] per_paddr[PER_CNT];
- wire [DATA_BITS-1:0] per_pwdata[PER_CNT];
- wire [DATA_BITS-1:0] per_prdata[PER_CNT];
- genvar i;
- generate
- for (i = 0; i < PER_CNT; i = i + 1) begin : gen_per
- assign per_psel[i] = apb_psel & select[i];
- assign per_penable[i] = apb_penable & select[i];
- assign per_pwrite[i] = apb_pwrite;
- assign per_paddr[i] = apb_paddr[PER_BITS-1:0];
- assign per_pwdata[i] = apb_pwdata;
- end
- endgenerate
- // ==============================================
- // 实例化 cfg_reg
- // ==============================================
- wire cfg_adc_en;
- wire [7:0] cfg_adc_clk_div;
- wire [3:0] cfg_adc_chnl_sel;
- wire [11:0] cfg_trig_threshold;
- wire [15:0] cfg_trig_pulse_width;
- wire [1:0] cfg_trig_edge;
- wire [1:0] cfg_trig_mode;
- wire [4:0] cfg_trig_time_slot;
- wire [15:0] cfg_trig_auto_timeout;
- wire cfg_adc_run;
- wire cfg_adc_restart;
- // 新增:DAC 配置信号
- wire cfg_dac_en;
- wire cfg_dac_run;
- wire [1:0] cfg_wave_type;
- wire [9:0] cfg_max_vol;
- wire [9:0] cfg_min_vol;
- wire [31:0] cfg_frequency;
- wire [7:0] cfg_duty_cycle;
- cfg_reg cfg_reg_inst(
- .pclk (apb_clock),
- .presetn (resetn),
- .paddr (per_paddr[1]),
- .pwrite (per_pwrite[1]),
- .pwdata (per_pwdata[1]),
- .prdata (per_prdata[1]),
- .psel (per_psel[1]),
- .penable (per_penable[1]),
- .adc_en (cfg_adc_en),
- .adc_clk_div (cfg_adc_clk_div),
- .adc_chnl_sel (cfg_adc_chnl_sel),
- .trig_threshold (cfg_trig_threshold),
- .trig_pulse_width (cfg_trig_pulse_width),
- .trig_edge (cfg_trig_edge),
- .trig_mode (cfg_trig_mode),
- .trig_time_slot (cfg_trig_time_slot),
- .trig_auto_timeout (cfg_trig_auto_timeout),
- .adc_run (cfg_adc_run),
- .adc_restart (cfg_adc_restart),
- // ********************** 新增:DAC 输出 **********************
- .dac_en (cfg_dac_en),
- .dac_run (cfg_dac_run),
- .wave_type (cfg_wave_type),
- .max_vol (cfg_max_vol),
- .min_vol (cfg_min_vol),
- .frequency (cfg_frequency),
- .duty_cycle (cfg_duty_cycle)
- );
- // ==============================================
- // 实例化 ADC0
- // ==============================================
- wire adc0_eoc;
- wire [11:0] adc0_data;
- apb_adc #(
- .SCLK_BIT(16)
- ) apb_adc0_inst(
- // APB接口
- .stop (stop ),
- .dma_req (), // 不使用DMA
- .dma_clr (1'b0), // DMA清零置0
- .apb_clock (apb_clock ),
- .apb_resetn (resetn ),
|