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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_psw.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 program status word                                    ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   program status word                                        ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   nothing                                                    ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// ver: 1
45
//
46
 
47
 
48
// synopsys translate_off
49
`include "oc8051_timescale.v"
50
// synopsys translate_on
51
 
52
`include "oc8051_defines.v"
53
 
54
 
55 4 markom
module oc8051_psw (clk, rst, wr_addr, rd_addr, data_in, wr, wr_bit, data_out, data_out_r, bit_out, p, cy_in, ac_in, ov_in, set);
56 2 simont
//
57
// clk          (in)  clock
58
// rst          (in)  reset
59
// addr         (in)  write address [oc8051_ram_wr_sel.out]
60
// data_in      (in)  data input [oc8051_alu.des1]
61
// wr           (in)  write [oc8051_decoder.wr -r]
62
// wr_bit       (in)  write bit addresable [oc8051_decoder.bit_addr -r]
63
// data_out     (out) data output [oc8051_ram_sel.psw]
64 4 markom
// data_out_r   (out) data output [oc8051_ram_sel.psw]
65 2 simont
// p            (in)  parity [oc8051_acc.p]
66
// cy_in        (in)  input bit data [oc8051_alu.desCy]
67
// ac_in        (in)  auxiliary carry input [oc8051_alu.desAc]
68
// ov_in        (in)  overflov input [oc8051_alu.desOv]
69
// set          (in)  set psw (write to caryy, carry and overflov or carry, owerflov and ac) [oc8051_decoder.psw_set -r]
70
//
71
 
72
 
73
input clk, rst, wr, p, cy_in, ac_in, ov_in, wr_bit;
74
input [1:0] set;
75
input [2:0] rd_addr;
76
input [7:0] wr_addr, data_in;
77
 
78
output bit_out;
79
output [7:0] data_out;
80 4 markom
output [7:0] data_out_r;
81 2 simont
 
82
reg bit_out;
83
reg [7:0] data;
84 4 markom
reg wr_psw_r;
85 2 simont
wire wr_psw;
86
 
87 4 markom
assign wr_psw = (wr & (wr_addr==`OC8051_SFR_PSW) && !wr_bit);
88
 
89
always @(posedge clk or posedge rst)
90
  if (rst) wr_psw_r <= #1 1'b0;
91
  else wr_psw_r <= #1 wr_psw;
92
 
93 2 simont
assign data_out = wr_psw ? {data_in[7:1],p}:{data[7:1], p};
94 4 markom
assign data_out_r = wr_psw_r ? {data_in[7:1],p}:{data[7:1], p};
95 2 simont
 
96
 
97
//
98
//case writing to psw
99
always @(posedge clk or posedge rst)
100
begin
101
  if (rst)
102
    data <= #1 `OC8051_RST_PSW;
103
 
104
//
105
// write to psw (byte addressable)
106
  else if (wr & (wr_bit==1'b0) & (wr_addr==`OC8051_SFR_PSW))
107
    data <= #1 data_in;
108
//
109
// write to psw (bit addressable)
110
  else if (wr & wr_bit & (wr_addr[7:3]==`OC8051_SFR_B_PSW))
111
    data[wr_addr[2:0]] <= #1 cy_in;
112
  else begin
113
    case (set)
114
      `OC8051_PS_CY: begin
115
//
116
//write carry
117
        data[7] <= #1 cy_in;
118
      end
119
      `OC8051_PS_OV: begin
120
//
121
//write carry and overflov
122
        data[7] <= #1 cy_in;
123
        data[2] <= #1 ov_in;
124
      end
125
      `OC8051_PS_AC:begin
126
//
127
//write carry, overflov and ac
128
        data[7] <= #1 cy_in;
129
        data[6] <= #1 ac_in;
130
        data[2] <= #1 ov_in;
131
      end
132
    endcase
133
  end
134
end
135
 
136 4 markom
always @(posedge clk or posedge rst)
137 2 simont
begin
138 5 markom
  if (rst) bit_out <= #1 1'b0;
139 4 markom
  else bit_out <= #1 data_out[rd_addr];
140 2 simont
end
141
 
142
endmodule

powered by: WebSVN 2.1.0

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