Line 38... |
Line 38... |
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
//
|
//
|
//
|
//
|
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
module rtcclock(i_clk,
|
module rtclight(i_clk,
|
// Wishbone interface
|
// Wishbone interface
|
i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
|
// o_wb_ack, o_wb_stb, o_wb_data, // no reads here
|
// o_wb_ack, o_wb_stb, o_wb_data, // no reads here
|
// // Button inputs
|
// // Button inputs
|
// i_btn,
|
// i_btn,
|
Line 50... |
Line 50... |
o_data, // multiplexed based upon i_wb_addr
|
o_data, // multiplexed based upon i_wb_addr
|
// Output controls
|
// Output controls
|
o_interrupt,
|
o_interrupt,
|
// A once-per-day strobe on the last clock of the day
|
// A once-per-day strobe on the last clock of the day
|
o_ppd);
|
o_ppd);
|
|
parameter DEFAULT_SPEED = 32'd2814750;
|
input i_clk;
|
input i_clk;
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
input i_wb_cyc, i_wb_stb, i_wb_we;
|
input [2:0] i_wb_addr;
|
input [2:0] i_wb_addr;
|
input [31:0] i_wb_data;
|
input [31:0] i_wb_data;
|
// input i_btn;
|
// input i_btn;
|
output reg [31:0] o_data;
|
output reg [31:0] o_data;
|
output wire o_interrupt, o_ppd;
|
output wire o_interrupt, o_ppd;
|
|
|
reg [31:0] clock, stopwatch, ckspeed;
|
reg [21:0] clock;
|
|
reg [31:0] stopwatch, ckspeed;
|
reg [25:0] timer;
|
reg [25:0] timer;
|
|
|
wire ck_sel, tm_sel, sw_sel, sp_sel, al_sel;
|
wire ck_sel, tm_sel, sw_sel, sp_sel, al_sel;
|
assign ck_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b000));
|
assign ck_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b000));
|
assign tm_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b001));
|
assign tm_sel = ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_addr[2:0]==3'b001));
|
Line 76... |
Line 78... |
{ ck_carry, ck_counter } <= ck_counter + { 8'h00, ckspeed };
|
{ ck_carry, ck_counter } <= ck_counter + { 8'h00, ckspeed };
|
|
|
wire ck_pps;
|
wire ck_pps;
|
reg ck_prepps, ck_ppm, ck_pph, ck_ppd;
|
reg ck_prepps, ck_ppm, ck_pph, ck_ppd;
|
reg [7:0] ck_sub;
|
reg [7:0] ck_sub;
|
initial clock = 32'h00000000;
|
initial clock = 22'h00000;
|
assign ck_pps = (ck_carry)&&(ck_prepps);
|
assign ck_pps = (ck_carry)&&(ck_prepps);
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin
|
begin
|
if (ck_carry)
|
if (ck_carry)
|
ck_sub <= ck_sub + 8'h1;
|
ck_sub <= ck_sub + 8'h1;
|
Line 141... |
Line 143... |
clock[15:8] <= i_wb_data[15:8];
|
clock[15:8] <= i_wb_data[15:8];
|
ck_pph <= (i_wb_data[15:8] == 8'h59);
|
ck_pph <= (i_wb_data[15:8] == 8'h59);
|
end
|
end
|
if (6'h3f != i_wb_data[21:16])
|
if (6'h3f != i_wb_data[21:16])
|
clock[21:16] <= i_wb_data[21:16];
|
clock[21:16] <= i_wb_data[21:16];
|
clock[31:22] <= i_wb_data[31:22];
|
|
if (8'h00 == i_wb_data[7:0])
|
if (8'h00 == i_wb_data[7:0])
|
ck_sub <= 8'h00;
|
ck_sub <= 8'h00;
|
end
|
end
|
end
|
end
|
|
|
Line 378... |
Line 379... |
// real time clock RTL file can handle tracking the clock in any
|
// real time clock RTL file can handle tracking the clock in any
|
// device. Further, because this is only the lower 32 bits of a
|
// device. Further, because this is only the lower 32 bits of a
|
// 48 bit counter per seconds, the clock jitter is kept below
|
// 48 bit counter per seconds, the clock jitter is kept below
|
// 1 part in 65 thousand.
|
// 1 part in 65 thousand.
|
//
|
//
|
initial ckspeed = 32'd2814750; // 2af31e = 2^48 / 100e6 MHz
|
initial ckspeed = DEFAULT_SPEED; // 2af31e = 2^48 / 100e6 MHz
|
// In the case of verilator, comment the above and uncomment the line
|
// In the case of verilator, comment the above and uncomment the line
|
// below. The clock constant below is "close" to simulation time,
|
// below. The clock constant below is "close" to simulation time,
|
// meaning that my verilator simulation is running about 300x slower
|
// meaning that my verilator simulation is running about 300x slower
|
// than board time.
|
// than board time.
|
// initial ckspeed = 32'd786432000;
|
// initial ckspeed = 32'd786432000;
|
Line 397... |
Line 398... |
// connecting this module to a year/month/date date/calendar module.
|
// connecting this module to a year/month/date date/calendar module.
|
assign o_ppd = (ck_ppd)&&(ck_pps);
|
assign o_ppd = (ck_ppd)&&(ck_pps);
|
|
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(i_wb_addr[2:0])
|
case(i_wb_addr[2:0])
|
3'b000: o_data <= { clock[31:22], ck_last_clock };
|
3'b000: o_data <= { 10'h0, ck_last_clock };
|
3'b001: o_data <= { 6'h00, timer };
|
3'b001: o_data <= { 6'h00, timer };
|
3'b010: o_data <= stopwatch;
|
3'b010: o_data <= stopwatch;
|
3'b011: o_data <= { 6'h00, al_tripped, al_enabled, 2'b00, alarm_time };
|
3'b011: o_data <= { 6'h00, al_tripped, al_enabled, 2'b00, alarm_time };
|
3'b100: o_data <= ckspeed;
|
3'b100: o_data <= ckspeed;
|
default: o_data <= 32'h000;
|
default: o_data <= 32'h000;
|