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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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