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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [sc_env/] [tv_responder.cpp] - Blame information for rev 111

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 92 ghutchis
#include "tv_responder.h"
2
 
3 111 ghutchis
uint64_t get_time_stamp () {
4
        sc_time t;
5
 
6
        t = sc_time_stamp();
7
        return t.value();
8
}
9
 
10 92 ghutchis
void tv_responder::event ()
11
{
12
        // init
13 94 ghutchis
        //reset_n = 0;
14
        /*
15 92 ghutchis
        wait_n = 1;
16
        int_n = 1;
17
        nmi_n = 1;
18
        busrq_n = 1;
19
        di_resp = 0;
20 94 ghutchis
        */
21 111 ghutchis
        uint8_t oldval;
22 92 ghutchis
 
23 94 ghutchis
        if (reset_time > 0) {
24
                reset_n = 0;
25
            wait_n = 1;
26
                int_n = 1;
27
                nmi_n = 1;
28
                busrq_n = 1;
29
                di_resp = 0;
30
                reset_time--;
31
                if (reset_time == 0)
32
                        printf ("Initialization complete.\n");
33
                return;
34
        } else {
35
                if (reset_time == 0) {
36
                        reset_n = 1;
37
                        reset_time--;
38
                }
39
        }
40
 
41
 
42
    if (!iorq_n & !rd_n)
43
        {
44
          switch (addr) {
45
            case (0x82) : di_resp = timeout_ctl; break;
46
                        case(0x83) : di_resp = max_timeout & 0xff; break;
47
                        case(0x84) : di_resp = max_timeout >> 8; break;
48
 
49
                case(0x90) : di_resp = int_countdown; break;
50 111 ghutchis
            case(CKSUM_VALUE) :
51
                di_resp = checksum;
52
                                //printf ("%2.6f: Read checksum value of %02x\n", sc_time_stamp().to_seconds(), checksum);
53
                break;
54 94 ghutchis
            case(0x93) : di_resp = ior_value; break;
55
            case(0x94) : di_resp = rand();  break;
56
            case(0x95) : di_resp = nmi_countdown; break;
57
            case(0xA0) : di_resp = nmi_trigger; break;
58
            default : di_resp = 0;
59
          }
60
        } // if (!iorq_n & !rd_n)
61
 
62
//  wire wr_stb;
63
//  reg last_iowrite;
64
 
65
//  assign wr_stb = (!iorq_n & !wr_n);
66
 
67
//  always @(posedge clk)
68
//   begin
69
      //last_iowrite <= #1 wr_stb;
70
    //if (!iorq_n && !wr_n)
71
    //  printf ("DEBUG:  I/O Write detected addr=%02x\n", 0xff & (int) addr.read());
72
 
73
    if (!iorq_n && !wr_n && !last_iowrite) {
74
        int l_dout, l_addr;
75
 
76
        l_addr = addr.read();
77
        l_dout = dout.read();
78
 
79
        last_iowrite = true;
80
                switch ( l_addr & 0xff) {
81 111 ghutchis
                        case(SIM_CTL_PORT) :
82 94 ghutchis
                        // dump control deprecated
83
                        if (l_dout == 1) {
84 111 ghutchis
                                printf ("%2.6f: --- TEST PASSED ---\n", sc_time_stamp().to_seconds());
85 94 ghutchis
                                sc_stop();
86
                        } else if (l_dout == 2) {
87 111 ghutchis
                                printf ("%2.6f: !!! TEST FAILED !!!\n", sc_time_stamp().to_seconds());
88 94 ghutchis
                                sc_stop();
89
                        }
90
                        break;
91
 
92 111 ghutchis
                        case(MSG_PORT) :
93 94 ghutchis
 
94
                        if (l_dout == 0x0A) {
95 111 ghutchis
                                        printf ("%2.6f: PROGRAM : ", sc_time_stamp().to_seconds());
96 94 ghutchis
 
97
                                        for (int i=0; i<buf_ptr; i=i+1)
98 111 ghutchis
                                                printf ("%c", str_buf[i]);
99 94 ghutchis
 
100 111 ghutchis
                                        printf ("\n");
101 94 ghutchis
                                        buf_ptr = 0;
102
                                } else {
103
                                str_buf[buf_ptr] = (char) (l_dout & 0xff);
104
                                buf_ptr = buf_ptr + 1;
105
                        }
106
                    break;
107
 
108 111 ghutchis
                        case(TIMEOUT_PORT) :
109 94 ghutchis
                        timeout_ctl = l_dout;
110
                                break;
111
 
112 111 ghutchis
                        case(MAX_TIMEOUT_LOW) :
113 94 ghutchis
                                max_timeout = l_dout | (max_timeout & 0xFF00);
114
                                break;
115
 
116 111 ghutchis
                        case(MAX_TIMEOUT_HIGH) :
117
                                max_timeout = (l_dout << 8) | (max_timeout & 0x00FF);
118
                                printf ("%2.6f: ENVIRON : Timeout reset to %d (dout=%d)\n", sc_time_stamp().to_seconds(), max_timeout, l_dout);
119 94 ghutchis
                                break;
120
 
121
                        case(0x90) : int_countdown = dout; break;
122 111 ghutchis
                        case(CKSUM_VALUE) : checksum = dout; break;
123
                        case(CKSUM_ACCUM) :
124
                                oldval = checksum;
125
                                checksum = checksum + dout;
126
                                //printf ("%2.6f: ENVIRON : cksum %02x=%02x + %02x\n", sc_time_stamp().to_seconds(), checksum, oldval, l_dout);
127
                                break;
128 94 ghutchis
                        case(0x93) : ior_value = dout; break;
129
                        case(0x95) : nmi_countdown = dout; break;
130
                        case(0xA0) : nmi_trigger = dout; break;
131
                }
132
    } else if (iorq_n)
133
        last_iowrite = false;
134
 
135 111 ghutchis
        if (timeout_ctl & 0x2) {
136 94 ghutchis
                cur_timeout = 0;
137 111 ghutchis
                timeout_ctl = timeout_ctl & 1;
138
        } else if (timeout_ctl & 0x1)
139 94 ghutchis
                cur_timeout = cur_timeout + 1;
140
 
141
    if (cur_timeout >= max_timeout) {
142 111 ghutchis
          printf ("%2.6f: ERROR   : Reached timeout %d cycles\n", sc_time_stamp().to_seconds(), max_timeout);
143 94 ghutchis
          //tb_top.test_fail;
144
          sc_stop();
145
    }
146
 
147
        if (int_countdown == 0) {
148
                int_n = 1;
149
        } else if (int_countdown == 1)
150
                int_n  = 0;
151
    else if (int_countdown > 1) {
152
          int_countdown = int_countdown - 1;
153
          int_n  = 1;
154
    }
155
 
156
    // when nmi countdown reaches 1, an NMI will be issued.
157
    // to clear the interrupt, write nmi_countdown to 0.
158
    if ((nmi_countdown == 0) && (nmi_trigger == 0))
159
                nmi_n = 1;
160
    else if (nmi_countdown == 1)
161
                nmi_n = 0;
162
    else if (nmi_countdown > 1) {
163
                nmi_countdown = nmi_countdown - 1;
164
                nmi_n = 1;
165
    }
166
 
167
    // when IR equals the target instruction, an NMI will be
168
    // issued.  To clear the interrupt, write nmi_trigger to
169
    // zero.
170
    /*  can't do this in systemc
171
    if (nmi_trigger != 0) {
172
          if (nmi_trigger === tb_top.tv80s_inst.i_tv80_core.IR[7:0])
173
            begin
174
              tb_top.nmi_n <= #80 0;
175
              tb_top.nmi_n <= #160 1;
176
            end
177
    } else if (nmi_countdown == 0)
178
        nmi_n = 1;
179
     */
180 92 ghutchis
}

powered by: WebSVN 2.1.0

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