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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc/] [src/] [dsk/] [ataio.v] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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