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

Subversion Repositories tv80

[/] [tv80/] [branches/] [hpa1/] [env/] [env_io.v] - Blame information for rev 86

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 13 ghutchis
 
9
  parameter str_buf_sz = 256;
10 2 ghutchis
 
11
  input clk;
12
  input iorq_n;
13
  input rd_n;
14
  input wr_n;
15
  input [7:0] addr;
16
  input [7:0] DO;
17
  inout [7:0] DI;
18
 
19
  reg [7:0]    io_data;
20
 
21 13 ghutchis
  reg [7:0]    str_buf [0:str_buf_sz-1];
22 2 ghutchis
  reg          io_cs;
23
  integer      buf_ptr, i;
24
 
25
  reg [7:0]    timeout_ctl;
26
  reg [15:0]   cur_timeout;
27
  reg [15:0]   max_timeout;
28
 
29
  reg [7:0]    int_countdown;
30
 
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
 
43
  always @(posedge clk)
44
    begin
45
      if (!iorq_n & !wr_n)
46
        case (addr)
47
          8'h80 :
48
            begin
49
              case (DO)
50
                1 : tb_top.test_pass;
51
 
52
                2 : tb_top.test_fail;
53
 
54
                3 : tb_top.dumpon;
55
 
56
                4 : tb_top.dumpoff;
57
 
58
                default :
59
                  begin
60
                    $display ("%t: ERROR   : Unknown I/O command %x", $time, DO);
61
                  end
62
              endcase // case(DO)
63
            end // case: :...
64
 
65
          8'h81 :
66
            begin
67
              str_buf[buf_ptr] = DO;
68
              buf_ptr = buf_ptr + 1;
69
 
70 13 ghutchis
              if (buf_ptr == str_buf_sz)
71
                begin
72
                  $display ("%t: WARNING : String buffer reached maximum size without detecting EOL", $time);
73
                  $write ("%t: WARNING : Contents: ", $time);
74
                  for (i=0; i<buf_ptr; i=i+1)
75
                    $write ("%s", str_buf[i]);
76
                  $write ("\n");
77
                  buf_ptr = 0;
78
                end
79
 
80 2 ghutchis
              //$display ("%t: DEBUG   : Detected write of character %x", $time, DO);
81
              if (DO == 8'h0A)
82
                begin
83
                  $write ("%t: PROGRAM : ", $time);
84
 
85
                  for (i=0; i<buf_ptr; i=i+1)
86
                    $write ("%s", str_buf[i]);
87
 
88
                  buf_ptr = 0;
89
                end
90
            end // case: 8'h81
91
 
92
          8'h82 :
93
            begin
94
              timeout_ctl = DO;
95
            end
96
 
97
          8'h83 : max_timeout[7:0] = DO;
98
          8'h84 : max_timeout[15:8] = DO;
99
 
100
          8'h90 : int_countdown = DO;
101
        endcase // case(addr)
102
    end // always @ (posedge clk)
103
 
104
  always @(posedge clk)
105
    begin
106
      if (timeout_ctl[1])
107
        cur_timeout = 0;
108
      else if (timeout_ctl[0])
109
        cur_timeout = cur_timeout + 1;
110
 
111
      if (cur_timeout >= max_timeout)
112
        begin
113
          $display ("%t: ERROR   : Reached timeout %d cycles", $time, max_timeout);
114
          tb_top.test_fail;
115
        end
116
    end // always @ (posedge clk)
117
 
118
  always @(posedge clk)
119
    begin
120
      if (int_countdown == 1)
121
        begin
122
          tb_top.int_n  <= #1 1'b0;
123
          int_countdown = 0;
124
        end
125
      else if (int_countdown > 1)
126
        int_countdown = int_countdown - 1;
127
    end
128
 
129
endmodule // env_io

powered by: WebSVN 2.1.0

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