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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [sim/] [iverilog/] [pc_dma/] [tb_pc_dma.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
 
2
module tb_pc_dma();
3
 
4
reg clk;
5
reg rst_n;
6
 
7
reg  [3:0] slave_address        = 4'd0;
8
reg        slave_read           = 1'b0;
9
wire [7:0] slave_readdata;
10
reg        slave_write          = 1'b0;
11
reg  [7:0] slave_writedata      = 8'd0;
12
 
13
reg  [3:0] page_address         = 4'd0;
14
reg        page_read            = 1'b0;
15
wire [7:0] page_readdata;
16
reg        page_write           = 1'b0;
17
reg  [7:0] page_writedata       = 8'd0;
18
 
19
reg  [4:0] master_address       = 5'd0;
20
reg        master_read          = 1'b0;
21
wire [7:0] master_readdata;
22
reg        master_write         = 1'b0;
23
reg  [7:0] master_writedata     = 8'd0;
24
 
25
wire [31:0] avm_address;
26
reg         avm_waitrequest     = 1'b0;
27
wire        avm_read;
28
reg         avm_readdatavalid   = 1'b0;
29
reg  [7:0]  avm_readdata        = 8'd0;
30
wire        avm_write;
31
wire [7:0]  avm_writedata;
32
 
33
reg        dma_floppy_req       = 1'b0;
34
wire       dma_floppy_ack;
35
wire       dma_floppy_terminal;
36
wire [7:0] dma_floppy_readdata;
37
reg  [7:0] dma_floppy_writedata = 8'd0;
38
 
39
reg        dma_soundblaster_req         = 1'b0;
40
wire       dma_soundblaster_ack;
41
wire       dma_soundblaster_terminal;
42
wire [7:0] dma_soundblaster_readdata;
43
reg  [7:0] dma_soundblaster_writedata   = 8'd0;
44
 
45
pc_dma pc_dma_inst(
46
    .clk                        (clk),
47
    .rst_n                      (rst_n),
48
 
49
    //000h - 00Fh for slave DMA
50
    .slave_address              (slave_address),      //input [3:0]
51
    .slave_read                 (slave_read),         //input
52
    .slave_readdata             (slave_readdata),     //output [7:0]
53
    .slave_write                (slave_write),        //input
54
    .slave_writedata            (slave_writedata),    //input [7:0]
55
 
56
    //080h - 08Fh for DMA page    
57
    .page_address               (page_address),       //input [3:0]
58
    .page_read                  (page_read),          //input
59
    .page_readdata              (page_readdata),      //output [7:0]
60
    .page_write                 (page_write),         //input
61
    .page_writedata             (page_writedata),     //input [7:0]
62
 
63
    //0C0h - 0DFh for master DMA
64
    .master_address             (master_address),     //input [4:0]
65
    .master_read                (master_read),        //input
66
    .master_readdata            (master_readdata),    //output [7:0]
67
    .master_write               (master_write),       //input
68
    .master_writedata           (master_writedata),   //input [7:0]
69
 
70
    //master
71
    .avm_address                (avm_address),        //output [31:0]
72
    .avm_waitrequest            (avm_waitrequest),    //input
73
    .avm_read                   (avm_read),           //output
74
    .avm_readdatavalid          (avm_readdatavalid),  //input
75
    .avm_readdata               (avm_readdata),       //input [7:0]
76
    .avm_write                  (avm_write),          //output
77
    .avm_writedata              (avm_writedata),      //output [7:0]
78
 
79
    //floppy 8-bit dma channel
80
    .dma_floppy_req             (dma_floppy_req),         //input
81
    .dma_floppy_ack             (dma_floppy_ack),         //output
82
    .dma_floppy_terminal        (dma_floppy_terminal),    //output
83
    .dma_floppy_readdata        (dma_floppy_readdata),    //output [7:0]
84
    .dma_floppy_writedata       (dma_floppy_writedata),   //input [7:0]
85
 
86
    //soundblaster 8-bit dma channel
87
    .dma_soundblaster_req       (dma_soundblaster_req),       //input
88
    .dma_soundblaster_ack       (dma_soundblaster_ack),       //output
89
    .dma_soundblaster_terminal  (dma_soundblaster_terminal),  //output
90
    .dma_soundblaster_readdata  (dma_soundblaster_readdata),  //output [7:0]
91
    .dma_soundblaster_writedata (dma_soundblaster_writedata)  //input [7:0]
92
);
93
 
94
initial begin
95
    avm_readdatavalid = 1'b0;
96
    avm_readdata = 8'd0;
97
    forever begin
98
        #10
99
        avm_readdatavalid = ~avm_readdatavalid;
100
        avm_readdata = avm_readdata + 8'd1;
101
    end
102
end
103
 
104
initial begin
105
    dma_floppy_req = 1'b0;
106
    #50
107
    dma_floppy_req = 1'b1;
108
    #300
109
    dma_floppy_req = 1'b0;
110
end
111
 
112
initial begin
113
    dma_soundblaster_req = 1'b0;
114
    #50
115
    dma_soundblaster_req = 1'b1;
116
    #400
117
    dma_soundblaster_req = 1'b0;
118
end
119
 
120
initial begin
121
    clk = 1'b0;
122
    forever #5 clk = ~clk;
123
end
124
 
125
`define WRITE_SLA(addr, data)  \
126
    slave_write        = 1'b1; \
127
    slave_address      = addr; \
128
    slave_writedata    = data; \
129
    #10;                       \
130
    slave_write        = 1'b0;
131
 
132
`define WRITE_MAS(addr, data)   \
133
    master_write        = 1'b1; \
134
    master_address      = addr; \
135
    master_writedata    = data; \
136
    #10;                        \
137
    master_write        = 1'b0;
138
 
139
`define WRITE_PAGE(addr, data) \
140
    page_write        = 1'b1;  \
141
    page_address      = addr;  \
142
    page_writedata    = data;  \
143
    #10;                       \
144
    page_write        = 1'b0;
145
 
146
integer finished = 0;
147
 
148
reg [255:0] dumpfile_name;
149
initial begin
150
    if( $value$plusargs("dumpfile=%s", dumpfile_name) == 0 ) begin
151
        dumpfile_name = "default.vcd";
152
    end
153
 
154
    $dumpfile(dumpfile_name);
155
    $dumpvars(0);
156
    $dumpon();
157
 
158
    $display("START");
159
 
160
    rst_n = 1'b0;
161
    #10 rst_n = 1'b1;
162
 
163
/*
164
 
165
  xor ax, ax
166
  out PORT_DMA1_MASTER_CLEAR(0x0D),al
167
  out PORT_DMA2_MASTER_CLEAR(0xDA),al
168
 
169
  ;; then initialize the DMA controllers
170
  mov al, #0xC0
171
  out PORT_DMA2_MODE_REG(0xD6), al ; cascade mode of channel 4 enabled
172
  mov al, #0x00
173
  out PORT_DMA2_MASK_REG(0xD4), al ; unmask channel 4
174
 
175
#define PORT_DMA_ADDR_2        0x0004
176
#define PORT_DMA_CNT_2         0x0005
177
#define PORT_DMA1_MASK_REG     0x000a
178
#define PORT_DMA1_MODE_REG     0x000b
179
#define PORT_DMA1_CLEAR_FF_REG 0x000c
180
#define PORT_DMA1_MASTER_CLEAR 0x000d
181
#define PORT_DMA_PAGE_2        0x0081
182
#define PORT_DMA2_MASTER_CLEAR 0x00da
183
#define PORT_DMA2_MASK_REG     0x00d4
184
#define PORT_DMA2_MODE_REG     0x00d6
185
 
186
  BX_DEBUG_INT13_FL("masking DMA-1 c2\n");
187
  outb(PORT_DMA1_MASK_REG(0x0A), 0x06);
188
 
189
  BX_DEBUG_INT13_FL("clear flip-flop\n");
190
      outb(PORT_DMA1_CLEAR_FF_REG(0x0C), 0x00); // clear flip-flop
191
      outb(PORT_DMA_ADDR_2(0x04), base_address);
192
      outb(PORT_DMA_ADDR_2(0x04), base_address>>8);
193
  BX_DEBUG_INT13_FL("clear flip-flop\n");
194
      outb(PORT_DMA1_CLEAR_FF_REG(0x0C), 0x00); // clear flip-flop
195
      outb(PORT_DMA_CNT_2(0x05), base_count);
196
      outb(PORT_DMA_CNT_2(0x05), base_count>>8);
197
 
198
  // Read Diskette Sectors
199
 
200
  // port 0b: DMA-1 Mode Register
201
    mode_register = 0x46; // single mode, increment, autoinit disable,
202
                          // transfer type=write, channel 2
203
  BX_DEBUG_INT13_FL("setting mode register\n");
204
    outb(PORT_DMA1_MODE_REG(0x0B), mode_register);
205
 
206
  BX_DEBUG_INT13_FL("setting page register\n");
207
    // port 81: DMA-1 Page Register, channel 2
208
   outb(PORT_DMA_PAGE_2(0x81), page);
209
 
210
  BX_DEBUG_INT13_FL("unmask chan 2\n");
211
    outb(PORT_DMA1_MASK_REG(0x0A), 0x02); // unmask channel 2
212
 
213
    BX_DEBUG_INT13_FL("unmasking DMA-1 c2\n");
214
    outb(PORT_DMA1_MASK_REG(0x0A), 0x02);
215
 
216
    //--------------------------------------
217
    // set up floppy controller for transfer
218
    //--------------------------------------
219
    floppy_prepare_controller(drive);
220
 
221
    // send read-normal-data command (9 bytes) to controller
222
    outb(PORT_FD_DATA, 0xe6); // e6: read normal data
223
*/
224
 
225
    /*
226
    `WRITE_SLA(4'hE, 8'd0) //clear slave mask
227
 
228
    `WRITE_MAS(5'h1C, 8'd0) //clear master mask
229
 
230
    `WRITE_SLA(4'hB, 8'b00001010) //mode for floppy
231
 
232
    `WRITE_SLA(4'hB, 8'b00000101) //mode for soundblaster
233
 
234
    `WRITE_SLA(4'h4, 8'h1A) //address
235
    `WRITE_SLA(4'h4, 8'hCD)
236
 
237
    `WRITE_SLA(4'h5, 8'h03) //count
238
    `WRITE_SLA(4'h5, 8'h00)
239
    */
240
 
241
    `WRITE_SLA(4'hD, 8'h00)
242
    `WRITE_MAS(5'h1A, 8'h00)
243
 
244
    `WRITE_MAS(5'h16, 8'hC0)
245
    `WRITE_MAS(5'h14, 8'h00)
246
 
247
    `WRITE_SLA(4'hA, 8'h06)
248
    `WRITE_SLA(4'hC, 8'h00)
249
    `WRITE_SLA(4'h4, 8'hCD)
250
    `WRITE_SLA(4'h4, 8'hAB)
251
 
252
    `WRITE_SLA(4'hC, 8'h00)
253
    `WRITE_SLA(4'h5, 8'h05)
254
    `WRITE_SLA(4'h5, 8'h00)
255
 
256
    `WRITE_SLA(4'hB, 8'h46)
257
    `WRITE_PAGE(4'h1, 8'h78)
258
 
259
    `WRITE_SLA(4'hA, 8'h02)
260
    `WRITE_SLA(4'hA, 8'h02)
261
 
262
    #100
263
 
264
    dma_floppy_req = 1'b1;
265
 
266
    #5000
267
 
268
 
269
    while(finished == 0) begin
270
        if($time > 50000) $finish_and_return(-1);
271
        #10;
272
 
273
        //$dumpflush();
274
    end
275
 
276
    #60;
277
 
278
    $dumpoff();
279
    $finish_and_return(0);
280
end
281
 
282
endmodule

powered by: WebSVN 2.1.0

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