2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Purpose: Low power standby state machine #
|
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
|
|
//#############################################################################
|
2015-12-03 18:04:46 -05:00
|
|
|
|
2016-04-19 22:54:00 -04:00
|
|
|
module oh_standby #( parameter PD = 5, // cycles to stay awake after "wakeup"
|
2016-06-24 21:26:14 -04:00
|
|
|
parameter N = 5) // project name
|
2016-04-11 12:01:59 -04:00
|
|
|
(
|
2016-04-19 16:23:50 -04:00
|
|
|
input clkin, //clock input
|
|
|
|
input nreset,//async active low reset
|
|
|
|
input [N-1:0] wakeup, //wake up event vector
|
|
|
|
input idle, //core is in idle
|
|
|
|
output clkout //clock output
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2016-08-17 15:06:01 +01:00
|
|
|
|
2015-12-03 18:04:46 -05:00
|
|
|
//Wire declarations
|
|
|
|
reg [PD-1:0] wakeup_pipe;
|
|
|
|
reg idle_reg;
|
2016-04-17 09:47:55 -04:00
|
|
|
wire state_change;
|
2016-04-19 16:23:50 -04:00
|
|
|
wire clk_en;
|
|
|
|
wire [N-1:0] wakeup_pulse;
|
|
|
|
wire wakeup_now;
|
|
|
|
|
|
|
|
// Wake up on any external event change
|
|
|
|
oh_edge2pulse #(.DW(N))
|
|
|
|
oh_edge2pulse (.out (wakeup_pulse[N-1:0]),
|
2016-04-19 22:54:00 -04:00
|
|
|
.clk (clkin),
|
2016-04-19 16:23:50 -04:00
|
|
|
.nreset (nreset),
|
|
|
|
.in (wakeup[N-1:0]));
|
2015-12-03 18:04:46 -05:00
|
|
|
|
2016-04-19 16:23:50 -04:00
|
|
|
assign wakeup_now = |(wakeup_pulse[N-1:0]);
|
2015-12-03 18:04:46 -05:00
|
|
|
|
2016-04-19 16:23:50 -04:00
|
|
|
// Stay away for PD cycles
|
2016-04-17 09:47:55 -04:00
|
|
|
always @ (posedge clkin)
|
2016-04-19 16:23:50 -04:00
|
|
|
wakeup_pipe[PD-1:0] <= {wakeup_pipe[PD-2:0], wakeup_now};
|
2015-12-03 18:04:46 -05:00
|
|
|
|
2016-04-19 16:23:50 -04:00
|
|
|
// Clock enable
|
|
|
|
assign clk_en = wakeup_now | //immediate wakeup
|
2015-12-03 18:04:46 -05:00
|
|
|
(|wakeup_pipe[PD-1:0]) | //anything in pipe
|
|
|
|
~idle; //core not in idle
|
|
|
|
|
2016-04-19 16:23:50 -04:00
|
|
|
// Clock gating cell
|
2016-08-17 15:06:01 +01:00
|
|
|
oh_clockgate oh_clockgate (.eclk(clkout),
|
2016-04-19 22:54:00 -04:00
|
|
|
.clk(clkin),
|
|
|
|
.en(clk_en),
|
|
|
|
.te(1'b0));
|
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
endmodule // oh_standby
|
|
|
|
|
2015-12-03 18:04:46 -05:00
|
|
|
|
|
|
|
|