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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_int.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 simont
//
2
// version 1.0
3
//
4
 
5
 
6
 
7
//clk  clock (pin)
8
//rst  reset (pin)
9
//wr_addr  address for selecting different registers (input)
10
//data_in  data input (input)
11
//wr   read/write signal (input)
12
//tf0  signal for timer interrupt 0 (input)
13
//tf1  signal for timer interrupt 1 (input)
14
//ie0   signal for external interrupt 0 (input)
15
//ie1   signal for external interrupt 1 (input)
16
//reti  return from interrupt signal (input)
17
//int_src  describes interrupt source (output)
18
//ip  ip register (internal)
19
//ie  ie register (internal)
20
//tcon  tcon register (internal)
21
//id  id register (internal)
22
 
23
 
24
 
25
 
26
`include "oc8051_defines.v"
27
 
28
//synopsys translate_off
29
`include "oc8051_timescale.v"
30
//synopsys translate_on
31
 
32
 
33
 
34 4 markom
module oc0851_int (clk, wr_addr, rd_addr, data_in, bit_in, data_out, bit_out, wr, wr_bit, tf0, tf1, intr, ie0, ie1, rst, reti, int_vec, tr0, tr1, uart, ack);
35 2 simont
input [7:0] wr_addr, data_in, rd_addr;
36
input wr, tf0, tf1, ie0, ie1, clk, rst, reti, wr_bit, bit_in, uart, ack;
37
 
38 4 markom
output tr0, tr1, intr, bit_out;
39 2 simont
output [7:0] int_vec, data_out;
40
 
41
reg [7:0] ip, ie, int_vec, id, data_out;
42
 
43
reg [3:0] tcon_s;
44
reg tcon_tf1, tcon_tf0, tcon_ie1, tcon_ie0, bit_out;
45
wire [7:0] tcon;
46
 
47
//
48
// isrc_cur     current interrupt source
49
// isrc_w       waiting interrupt source
50
reg [2:0] isrc_cur, isrc_w;
51
 
52
//
53
// contains witch level of interrupts is running
54
reg [1:0] int_levl, int_levl_w;
55
 
56
//
57
// int_l0       waiting interrupts on level 0
58
// int_l1       waiting interrupts on level 1
59
wire [4:0] int_l0, int_l1;
60
wire il0, il1;
61
 
62
//reg set_tf0, set_tf1, set_ie0, set_ie1;
63
reg tf0_buff, tf1_buff, ie0_buff, ie1_buff;
64
//reg tf0_ack, tf1_ack, ie0_ack, ie1_ack;
65
 
66
assign tcon = {tcon_tf1, tcon_s[3], tcon_tf0, tcon_s[2], tcon_ie1, tcon_s[1], tcon_ie0, tcon_s[0]};
67
assign tr0 = tcon_s[2];
68
assign tr1 = tcon_s[3];
69 4 markom
assign intr = |int_vec;
70 2 simont
 
71
assign int_l0 = ~ip[4:0] & ie[4:0] & {uart, tcon_tf1, tcon_ie1, tcon_tf0, tcon_ie0};
72
assign int_l1 = ip[4:0] & ie[4:0] & {uart, tcon_tf1, tcon_ie1, tcon_tf0, tcon_ie0};
73
assign il0 = |int_l0;
74
assign il1 = |int_l1;
75
 
76
always @(posedge clk or posedge rst)
77
begin
78
 if (rst) begin
79
   ip <=#1 `OC8051_RST_IP;
80
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_IP)) begin
81
    ip <= #1 data_in;
82
 end else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_IP))
83
    ip[wr_addr[2:0]] <= #1 bit_in;
84
end
85
 
86
always @(posedge clk or posedge rst)
87
begin
88
 if (rst) begin
89
   ie <=#1 `OC8051_RST_IE;
90
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_IE)) begin
91
    ie <= #1 data_in;
92
 end else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_IE))
93
    ie[wr_addr[2:0]] <= #1 bit_in;
94
end
95
 
96
//
97
// tcon_s
98
//
99
always @(posedge clk or posedge rst)
100
begin
101
 if (rst) begin
102
//   tcon_s <=#1 {`OC8051_RST_TCON[6], `OC8051_RST_TCON[4], `OC8051_RST_TCON[2], `OC8051_RST_TCON[0]};
103
   tcon_s <=#1 4'b0000;
104
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TCON)) begin
105
   tcon_s <= #1 {data_in[6], data_in[4], data_in[2], data_in[0]};
106
 end else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_TCON)) begin
107
   case (wr_addr[2:0])
108
     3'b000: tcon_s[0] <= #1 bit_in;
109
     3'b010: tcon_s[1] <= #1 bit_in;
110
     3'b100: tcon_s[2] <= #1 bit_in;
111
     3'b110: tcon_s[3] <= #1 bit_in;
112
   endcase
113
 end
114
end
115
 
116
//
117
// tf1 (tmod.7)
118
//
119
always @(posedge clk or posedge rst)
120
begin
121
 if (rst) begin
122
//   tcon_tf1 <=#1 `OC8051_RST_TCON[7];
123
   tcon_tf1 <=#1 1'b0;
124
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TCON)) begin
125
   tcon_tf1 <= #1 data_in[7];
126
 end else if ((wr) & (wr_bit) & (wr_addr=={`OC8051_SFR_B_TCON, 3'b111})) begin
127
   tcon_tf1 <= #1 bit_in;
128
 end else if (!(tf1_buff) & (tf1)) begin
129
   tcon_tf1 <= #1 1'b1;
130
 end else if (ack & (isrc_cur==`OC8051_ISRC_TF1)) begin
131
   tcon_tf1 <= #1 1'b0;
132
 end
133
end
134
 
135
//
136
// tf0 (tmod.5)
137
//
138
always @(posedge clk or posedge rst)
139
begin
140
 if (rst) begin
141
//   tcon_tf0 <=#1 `OC8051_RST_TCON[5];
142
   tcon_tf0 <=#1 1'b0;
143
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TCON)) begin
144
   tcon_tf0 <= #1 data_in[5];
145
 end else if ((wr) & (wr_bit) & (wr_addr=={`OC8051_SFR_B_TCON, 3'b101})) begin
146
   tcon_tf0 <= #1 bit_in;
147
 end else if (!(tf0_buff) & (tf0)) begin
148
   tcon_tf0 <= #1 1'b1;
149
 end else if (ack & (isrc_cur==`OC8051_ISRC_TF0)) begin
150
   tcon_tf0 <= #1 1'b0;
151
 end
152
end
153
 
154
 
155
//
156
// ie0 (tmod.1)
157
//
158
always @(posedge clk or posedge rst)
159
begin
160
 if (rst) begin
161
//   tcon_ie0 <=#1 `OC8051_RST_TCON[1];
162
   tcon_ie0 <=#1 1'b0;
163
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TCON)) begin
164
   tcon_ie0 <= #1 data_in[1];
165
 end else if ((wr) & (wr_bit) & (wr_addr=={`OC8051_SFR_B_TCON, 3'b001})) begin
166
   tcon_ie0 <= #1 bit_in;
167
 end else if (((tcon_s[0]) & (ie0_buff) & !(ie0)) | (!(tcon_s[0]) & !(ie0))) begin
168
   tcon_ie0 <= #1 1'b1;
169
 end else if (ack & (isrc_cur==`OC8051_ISRC_IE0) & (tcon_s[0])) begin
170
   tcon_ie0 <= #1 1'b0;
171
 end else if (!(tcon_s[0]) & (ie0)) begin
172
   tcon_ie0 <= #1 1'b0;
173
 end
174
end
175
 
176
 
177
//
178
// ie1 (tmod.3)
179
//
180
always @(posedge clk or posedge rst)
181
begin
182
 if (rst) begin
183
//   tcon_ie1 <=#1 `OC8051_RST_TCON[3];
184
   tcon_ie1 <=#1 1'b0;
185
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TCON)) begin
186
   tcon_ie1 <= #1 data_in[3];
187
 end else if ((wr) & (wr_bit) & (wr_addr=={`OC8051_SFR_B_TCON, 3'b011})) begin
188
   tcon_ie1 <= #1 bit_in;
189
 end else if (((tcon_s[1]) & (ie1_buff) & !(ie1)) | (!(tcon_s[1]) & !(ie1))) begin
190
   tcon_ie1 <= #1 1'b1;
191
 end else if (ack & (isrc_cur==`OC8051_ISRC_IE1) & (tcon_s[1])) begin
192
   tcon_ie1 <= #1 1'b0;
193
 end else if (!(tcon_s[1]) & (ie1)) begin
194
   tcon_ie1 <= #1 1'b0;
195
 end
196
end
197
 
198
 
199
always @(posedge clk or posedge rst)
200
begin
201
 if (rst) begin
202
   int_vec <= #1 8'h00;
203
   isrc_cur <= #1 `OC8051_ISRC_NO;
204
   isrc_w <= #1 `OC8051_ISRC_NO;
205
   int_levl <= #1 `OC8051_ILEV_NO;
206
   int_levl_w <= #1 `OC8051_ILEV_NO;
207
 end else if (reti) begin  // return from interrupt
208
   isrc_cur <= #1 isrc_w;
209
   int_levl <= #1 int_levl_w;
210
 end else if ((ie[7]) & (int_levl!=`OC8051_ILEV_L1) & (il1)) begin  // interrupt on level 1
211
   isrc_w <= #1 isrc_cur;
212
   int_levl <= #1 `OC8051_ILEV_L1;
213
   int_levl_w <= #1 int_levl;
214
   if (int_l1[0]) begin
215
     int_vec <= #1 `OC8051_INT_X0;
216
     isrc_cur <= #1 `OC8051_ISRC_IE0;
217
   end else if (int_l1[1]) begin
218
     int_vec <= #1 `OC8051_INT_T0;
219
     isrc_cur <= #1 `OC8051_ISRC_TF0;
220
   end else if (int_l1[2]) begin
221
     int_vec <= #1 `OC8051_INT_X1;
222
     isrc_cur <= #1 `OC8051_ISRC_IE1;
223
   end else if (int_l1[3]) begin
224
     int_vec <= #1 `OC8051_INT_T1;
225
     isrc_cur <= #1 `OC8051_ISRC_TF1;
226
   end else if (int_l1[4]) begin
227
     int_vec <= #1 `OC8051_INT_UART;
228
     isrc_cur <= #1 `OC8051_ISRC_UART;
229
   end
230
 end else if ((ie[7]) & (int_levl==`OC8051_ILEV_NO) & (il0)) begin  // interrupt on level 0
231
   int_levl <= #1 `OC8051_ILEV_L0;
232
   if (int_l0[0]) begin
233
     int_vec <= #1 `OC8051_INT_X0;
234
     isrc_cur <= #1 `OC8051_ISRC_IE0;
235
   end else if (int_l0[1]) begin
236
     int_vec <= #1 `OC8051_INT_T0;
237
     isrc_cur <= #1 `OC8051_ISRC_TF0;
238
   end else if (int_l0[2]) begin
239
     int_vec <= #1 `OC8051_INT_X1;
240
     isrc_cur <= #1 `OC8051_ISRC_IE1;
241
   end else if (int_l0[3]) begin
242
     int_vec <= #1 `OC8051_INT_T1;
243
     isrc_cur <= #1 `OC8051_ISRC_TF1;
244
   end else if (int_l0[4]) begin
245
     int_vec <= #1 `OC8051_INT_UART;
246
     isrc_cur <= #1 `OC8051_ISRC_UART;
247
   end
248
 end else begin
249
   int_vec <= #1 8'h00;
250
 end
251
end
252
 
253
 
254 4 markom
always @(posedge clk or posedge rst)
255 2 simont
begin
256 4 markom
  if (rst) data_out <= #1 8'h0;
257
  else if (wr & !wr_bit & (wr_addr==rd_addr) & (
258 2 simont
     (wr_addr==`OC8051_SFR_IP) | (wr_addr==`OC8051_SFR_IE) | (wr_addr==`OC8051_SFR_TCON))) begin
259
    data_out <= #1 data_in;
260
  end else begin
261
    case (rd_addr)
262
      `OC8051_SFR_IP: data_out <= #1 ip;
263
      `OC8051_SFR_IE: data_out <= #1 ie;
264
      default: data_out <= #1 tcon;
265
    endcase
266
  end
267
end
268
 
269 4 markom
always @(posedge clk or posedge rst)
270
  if (rst) begin
271
    tf0_buff <= #1 1'b0;
272
    tf1_buff <= #1 1'b0;
273
    ie0_buff <= #1 1'b0;
274
    ie1_buff <= #1 1'b0;
275
  end else begin
276
    tf0_buff <= #1 tf0;
277
    tf1_buff <= #1 tf1;
278
    ie0_buff <= #1 ie0;
279
    ie1_buff <= #1 ie1;
280
  end
281 2 simont
 
282 4 markom
always @(posedge clk or posedge rst)
283 2 simont
begin
284 4 markom
  if (rst) bit_out <= #1 1'b0;
285
  else if (wr & wr_bit & (wr_addr==rd_addr) & ((wr_addr[7:3]==`OC8051_SFR_B_IP) |
286 2 simont
     (wr_addr[7:3]==`OC8051_SFR_B_IE) | (wr_addr[7:3]==`OC8051_SFR_B_TCON))) begin
287
    bit_out <= #1 bit_in;
288
  end else begin
289
    case (rd_addr[7:3])
290
      `OC8051_SFR_B_IP: bit_out <= #1 ip[rd_addr[2:0]];
291
      `OC8051_SFR_B_IE: bit_out <= #1 ie[rd_addr[2:0]];
292
      default: bit_out <= #1 tcon[rd_addr[2:0]];
293
    endcase
294
  end
295
end
296
 
297
 
298
endmodule

powered by: WebSVN 2.1.0

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