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

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.24/] [fpga/] [src/] [dsk/] [ataio.v] - Blame information for rev 211

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 121 hellwig
//
2
// ataio.v -- parallel ATA I/O
3
//
4
 
5
 
6 27 hellwig
module ata_io (clk, reset,
7
               bus_en, bus_wr, bus_addr, bus_din, bus_dout, bus_wait,
8
               ata_d, ata_a, ata_cs0_n, ata_cs1_n,
9
               ata_dior_n, ata_diow_n, ata_iordy);
10
    input clk;
11
    input reset;
12
    //
13
    input bus_en;
14
    input bus_wr;
15
    input [3:0] bus_addr;
16
    input [15:0] bus_din;
17
    output reg [15:0] bus_dout;
18
    output bus_wait;
19
    //
20
    inout [15:0] ata_d;
21
    output reg [2:0] ata_a;
22
    output reg ata_cs0_n;
23
    output reg ata_cs1_n;
24
    output reg ata_dior_n;
25
    output reg ata_diow_n;
26
    input ata_iordy;
27
 
28
  reg [2:0] state;
29
  reg [4:0] delay_counter;
30
  reg ata_d_drive;
31
 
32
  assign ata_d = ata_d_drive ? bus_din : 16'bzzzzzzzzzzzzzzzz;
33
  assign bus_wait = bus_en & (state != 3'd5);
34
 
35
  always @(posedge clk) begin
36
    if (reset == 1'b1) begin
37
      state <= 3'd0;
38
      delay_counter <= 5'd31;
39
      ata_d_drive <= 1'b0;
40
      ata_a <= 3'b000;
41
      ata_cs0_n <= 1'b1;
42
      ata_cs1_n <= 1'b1;
43
      ata_dior_n <= 1'b1;
44
      ata_diow_n <= 1'b1;
45
      bus_dout <= 16'd0;
46
    end else begin
47
      if (delay_counter == 5'd0) begin
48
        case (state)
49
 
50
          // ready - wait for request from the bus
51
          3'd0: begin
52
            if (bus_en & ata_iordy) begin
53
              // assert address and -> state 1, wait 3+1
54
              // address mapping
55
              //   0xxx : control block registers
56
              //   1xxx : command block registers
57
              ata_a[2:0] <= bus_addr[2:0];
58
              ata_cs0_n <= ~bus_addr[3];
59
              ata_cs1_n <= bus_addr[3];
60
              state <= 3'd1;
61
              delay_counter <= 5'd3;
62
            end
63
          end
64
 
65
          // assert data-out and RW strobes, then -> state 2, wait 14+1
66
          3'd1: begin
67
            ata_d_drive <= bus_wr;
68
            ata_dior_n <= bus_wr;
69
            ata_diow_n <= ~bus_wr;
70
            state <= 3'd2;
71
            delay_counter <= 5'd14;
72
          end
73
 
74
          // de-assert RW strobes and sample data-in,
75
          // then -> state 3, wait 1+1
76
          3'd2: begin
77
            bus_dout <= ata_d;
78
            ata_dior_n <= 1'b1;
79
            ata_diow_n <= 1'b1;
80
            state <= 3'd3;
81
            delay_counter <= 5'd1;
82
          end
83
 
84
          // de-assert data and address, then -> state 4, wait 7+1
85
          // (such that 600 ns min cycle time is satisfied)
86
          3'd3: begin
87
            ata_d_drive <= 1'b0;
88
            ata_cs0_n <= 1'b1;
89
            ata_cs1_n <= 1'b1;
90
            state <= 3'd4;
91
            delay_counter <= 5'd7;
92
          end
93
 
94
          // auxiliary state, for necessity see comment in state 5
95
          3'd4: begin
96
            state <= 3'd5;
97
            delay_counter <= 5'd0;
98
          end
99
 
100
          // finish - used to release bus wait
101
          // WARNING: This state must not be entered with a delay!
102
          // Otherwise bus wait will be released too early and
103
          // subsequent bus cycles will not work properly.
104
          3'd5: begin
105
            state <= 3'd0;
106
            delay_counter <= 5'd0;
107
          end
108
 
109
        endcase
110
      end else begin
111
        delay_counter <= delay_counter - 1;
112
      end
113
    end
114
  end
115
 
116
endmodule

powered by: WebSVN 2.1.0

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