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

Subversion Repositories tv80

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

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

powered by: WebSVN 2.1.0

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