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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_sp.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
////                                                              ////
3
////  8051 stack pointer                                          ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   8051 special function register: stack pointer.             ////
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
// synopsys translate_off
48
`include "oc8051_timescale.v"
49
// synopsys translate_on
50
 
51
`include "oc8051_defines.v"
52
 
53
 
54
 
55 4 markom
module oc8051_sp (clk, rst, ram_rd_sel, ram_wr_sel, wr_addr, wr, wr_bit, data_in, data_out, data_out_r);
56 2 simont
//
57
// clk          (in)  clock
58
// rst          (in)  reset
59
// ram_rd_sel   (in)  ram read select, used tu calculate next value [oc8051_decoder.ram_rd_sel]
60
// ram_wr_sel   (in)  ram write select, used tu calculate next value [oc8051_decoder.ram_wr_sel -r]
61
// wr           (in)  write [oc8051_decoder.wr -r]
62
// wr_bit       (in)  write bit addresable [oc8051_decoder.bit_addr -r]
63
// data_in      (in)  data input [oc8051_alu.des1]
64
// wr_addr      (in)  write address (if is addres of sp and white high must be written to sp)  [oc8051_ram_wr_sel.out]
65 4 markom
// data_out     (out) data output
66
// data_out_r   (out) data output
67 2 simont
//
68
 
69
 
70
input clk, rst, wr, wr_bit;
71
input [1:0] ram_rd_sel;
72
input [2:0] ram_wr_sel;
73
input [7:0] data_in, wr_addr;
74
output [7:0] data_out;
75 4 markom
output [7:0] data_out_r;
76 2 simont
 
77
reg [7:0] data_out;
78 4 markom
reg [7:0] data_out_r;
79 2 simont
reg [7:0] temp;
80
reg pop, write;
81
wire [7:0] temp1;
82
 
83
assign temp1 = write ? data_in : temp;
84
 
85
always @(wr_addr or wr or wr_bit)
86
begin
87
  if ((wr_addr==`OC8051_SFR_SP) & (wr) & !(wr_bit))
88
    write = 1'b1;
89
  else
90
    write = 1'b0;
91
end
92
 
93
always @(posedge clk or posedge rst)
94
begin
95
  if (rst)
96
    temp <= #1 `OC8051_RST_SP;
97
  else
98
    temp <= #1 data_out;
99
end
100
 
101
always @(temp1 or ram_wr_sel or pop or write)
102
begin
103
//
104
// push
105
  if (ram_wr_sel==`OC8051_RWS_SP) data_out = temp1+8'h01;
106 4 markom
  else if (write) data_out = temp1;
107
  else data_out = temp1 - {7'b0, pop};
108 2 simont
 
109
end
110
 
111
always @(posedge clk or posedge rst)
112 4 markom
  if (rst) data_out_r <= #1 8'h0;
113
  else data_out_r <= #1 data_out;
114
 
115
always @(posedge clk or posedge rst)
116 2 simont
begin
117
  if (rst)
118
    pop <= #1 1'b0;
119
  else if (ram_rd_sel==`OC8051_RRS_SP) pop <= #1 1'b1;
120
  else pop <= #1 1'b0;
121
end
122
 
123 4 markom
endmodule

powered by: WebSVN 2.1.0

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