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

Subversion Repositories tv80

[/] [tv80/] [branches/] [restruc1/] [env/] [env_io.v] - Blame information for rev 112

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 41 ghutchis
            8'h94 : io_data = {$random};
57 37 ghutchis
            default : io_data = 8'hzz;
58
          endcase // case(addr)
59
        end // if (!iorq_n & !rd_n)
60
    end // always @ *
61
 
62 2 ghutchis
  always @(posedge clk)
63
    begin
64
      if (!iorq_n & !wr_n)
65
        case (addr)
66
          8'h80 :
67
            begin
68
              case (DO)
69
                1 : tb_top.test_pass;
70
 
71
                2 : tb_top.test_fail;
72
 
73
                3 : tb_top.dumpon;
74
 
75
                4 : tb_top.dumpoff;
76
 
77
                default :
78
                  begin
79
                    $display ("%t: ERROR   : Unknown I/O command %x", $time, DO);
80
                  end
81
              endcase // case(DO)
82
            end // case: :...
83
 
84
          8'h81 :
85
            begin
86
              str_buf[buf_ptr] = DO;
87
              buf_ptr = buf_ptr + 1;
88
 
89
              //$display ("%t: DEBUG   : Detected write of character %x", $time, DO);
90
              if (DO == 8'h0A)
91
                begin
92
                  $write ("%t: PROGRAM : ", $time);
93
 
94
                  for (i=0; i<buf_ptr; i=i+1)
95
                    $write ("%s", str_buf[i]);
96
 
97
                  buf_ptr = 0;
98
                end
99
            end // case: 8'h81
100
 
101
          8'h82 :
102
            begin
103
              timeout_ctl = DO;
104
            end
105
 
106
          8'h83 : max_timeout[7:0] = DO;
107
          8'h84 : max_timeout[15:8] = DO;
108
 
109
          8'h90 : int_countdown = DO;
110 37 ghutchis
          8'h91 : checksum = DO;
111
          8'h92 : checksum = checksum + DO;
112
          8'h93 : ior_value = DO;
113 2 ghutchis
        endcase // case(addr)
114
    end // always @ (posedge clk)
115
 
116
  always @(posedge clk)
117
    begin
118
      if (timeout_ctl[1])
119
        cur_timeout = 0;
120
      else if (timeout_ctl[0])
121
        cur_timeout = cur_timeout + 1;
122
 
123
      if (cur_timeout >= max_timeout)
124
        begin
125
          $display ("%t: ERROR   : Reached timeout %d cycles", $time, max_timeout);
126
          tb_top.test_fail;
127
        end
128
    end // always @ (posedge clk)
129
 
130
  always @(posedge clk)
131
    begin
132
      if (int_countdown == 1)
133
        begin
134
          tb_top.int_n  <= #1 1'b0;
135
          int_countdown = 0;
136
        end
137
      else if (int_countdown > 1)
138 31 ghutchis
        begin
139
          int_countdown = int_countdown - 1;
140
          tb_top.int_n  <= #1 1'b1;
141
        end
142 2 ghutchis
    end
143
 
144
endmodule // env_io

powered by: WebSVN 2.1.0

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