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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [env/] [env_io.v] - Blame information for rev 37

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

Line No. Rev Author Line
1 2 ghutchis
 
2
module env_io (/*AUTOARG*/
3
  // Outputs
4
  DI,
5
  // Inputs
6
  clk, iorq_n, rd_n, wr_n, addr, DO
7
  );
8
 
9
  input clk;
10
  input iorq_n;
11
  input rd_n;
12
  input wr_n;
13
  input [7:0] addr;
14
  input [7:0] DO;
15
  inout [7:0] DI;
16
 
17
  reg [7:0]    io_data;
18
 
19
  reg [7:0]    str_buf [0:255];
20
  reg          io_cs;
21
  integer      buf_ptr, i;
22
 
23
  reg [7:0]    timeout_ctl;
24
  reg [15:0]   cur_timeout;
25
  reg [15:0]   max_timeout;
26
 
27
  reg [7:0]    int_countdown;
28 37 ghutchis
  reg [7:0]    checksum;
29
  reg [7:0]    ior_value;  // increment-on-read value
30 2 ghutchis
 
31
  assign       DI = (!iorq_n & !rd_n & io_cs) ? io_data : {8{1'bz}};
32
 
33
  initial
34
    begin
35
      io_cs = 0;
36
      buf_ptr = 0;
37
      cur_timeout = 0;
38
      max_timeout = 10000;
39
      timeout_ctl = 1;
40
      int_countdown = 0;
41
    end
42 37 ghutchis
 
43
  always @*
44
    begin
45
      if (!iorq_n & !rd_n)
46
        begin
47
          io_cs = (addr[7:5] == 3'b100);
48
 
49
          case (addr)
50
            8'h83 : io_data = max_timeout[7:0];
51
            8'h84 : io_data = max_timeout[15:8];
52
 
53
            8'h90 : io_data = int_countdown;
54
            8'h91 : io_data = checksum;
55
            8'h93 : io_data = ior_value;
56
            default : io_data = 8'hzz;
57
          endcase // case(addr)
58
        end // if (!iorq_n & !rd_n)
59
    end // always @ *
60
 
61 2 ghutchis
  always @(posedge clk)
62
    begin
63
      if (!iorq_n & !wr_n)
64
        case (addr)
65
          8'h80 :
66
            begin
67
              case (DO)
68
                1 : tb_top.test_pass;
69
 
70
                2 : tb_top.test_fail;
71
 
72
                3 : tb_top.dumpon;
73
 
74
                4 : tb_top.dumpoff;
75
 
76
                default :
77
                  begin
78
                    $display ("%t: ERROR   : Unknown I/O command %x", $time, DO);
79
                  end
80
              endcase // case(DO)
81
            end // case: :...
82
 
83
          8'h81 :
84
            begin
85
              str_buf[buf_ptr] = DO;
86
              buf_ptr = buf_ptr + 1;
87
 
88
              //$display ("%t: DEBUG   : Detected write of character %x", $time, DO);
89
              if (DO == 8'h0A)
90
                begin
91
                  $write ("%t: PROGRAM : ", $time);
92
 
93
                  for (i=0; i<buf_ptr; i=i+1)
94
                    $write ("%s", str_buf[i]);
95
 
96
                  buf_ptr = 0;
97
                end
98
            end // case: 8'h81
99
 
100
          8'h82 :
101
            begin
102
              timeout_ctl = DO;
103
            end
104
 
105
          8'h83 : max_timeout[7:0] = DO;
106
          8'h84 : max_timeout[15:8] = DO;
107
 
108
          8'h90 : int_countdown = DO;
109 37 ghutchis
          8'h91 : checksum = DO;
110
          8'h92 : checksum = checksum + DO;
111
          8'h93 : ior_value = DO;
112 2 ghutchis
        endcase // case(addr)
113
    end // always @ (posedge clk)
114
 
115
  always @(posedge clk)
116
    begin
117
      if (timeout_ctl[1])
118
        cur_timeout = 0;
119
      else if (timeout_ctl[0])
120
        cur_timeout = cur_timeout + 1;
121
 
122
      if (cur_timeout >= max_timeout)
123
        begin
124
          $display ("%t: ERROR   : Reached timeout %d cycles", $time, max_timeout);
125
          tb_top.test_fail;
126
        end
127
    end // always @ (posedge clk)
128
 
129
  always @(posedge clk)
130
    begin
131
      if (int_countdown == 1)
132
        begin
133
          tb_top.int_n  <= #1 1'b0;
134
          int_countdown = 0;
135
        end
136
      else if (int_countdown > 1)
137 31 ghutchis
        begin
138
          int_countdown = int_countdown - 1;
139
          tb_top.int_n  <= #1 1'b1;
140
        end
141 2 ghutchis
    end
142
 
143
endmodule // env_io

powered by: WebSVN 2.1.0

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