1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00

Refactoring common library

- Updating interfaces to 2005 style
- Adding license pointers to all files
This commit is contained in:
Andreas Olofsson 2016-04-11 12:01:59 -04:00
parent 5b8328826e
commit 2688bc5aa4
53 changed files with 990 additions and 1534 deletions

View File

@ -1,3 +1,10 @@
//#############################################################################
//# Function: BCD Seven Segment Decoderh #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_7seg_decode ( input [3:0] bcd, //0-9
output a, //a segment (1=0ff)
output b, //b segment
@ -8,7 +15,7 @@ module oh_7seg_decode ( input [3:0] bcd, //0-9
output g //g segment
);
reg a,b,c,d,e,f,g;
reg a,b,c,d,e,f,g;
always @ (*)
case(bcd[3:0])

View File

@ -1,20 +1,17 @@
module oh_abs (/*AUTOARG*/
// Outputs
out, overflow,
// Inputs
in
);
parameter DW = 4;
//inputs
input [DW-1:0] in; //input operand
//outputs
output [DW-1:0] out; //out = abs(in) (signed two's complement)
output overflow; //high for max negative #
//#############################################################################
//# Function: Calculates absolute value of input #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_abs #(parameter DW = 2) // data width
(
input [DW-1:0] in, //input operand
output [DW-1:0] out, //out = abs(in) (signed two's complement)
output overflow //high for max negative #
);
assign out[DW-1:0] = in[DW-1] ? ~in[DW-1:0] + 1'b1 :
in[DW-1:0];

View File

@ -1,36 +1,24 @@
module oh_add (/*AUTOARG*/
// Outputs
sum, cout, zero, neg, overflow,
// Inputs
a, b, opt_sub, cin
);
//#############################################################################
//# Function: Two's compliment adder/subtractor #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//###############################################################
//# Parameters
//###############################################################
parameter DW = 64;
//###############################################################
//# Interface
//###############################################################
//inputs
input [DW-1:0] a; //first operand
input [DW-1:0] b; //second operand
input opt_sub; //subtraction option
input cin; //carry in
//outputs
output [DW-1:0] sum; //sum
output cout; //cary out
output zero; //zero flag
output neg; //negative flag
output overflow; //overflow indication
//###############################################################
//# BODY
//###############################################################
module oh_add #(parameter DW = 1 // data width
)
(
input [DW-1:0] a, //first operand
input [DW-1:0] b, //second operand
input opt_sub, //subtraction option
input cin, //carry in
output [DW-1:0] sum, //sum output
output cout, //carry output
output zero, //zero flag
output neg, //negative flag
output overflow //overflow flag
);
wire [DW-1:0] b_sub;
assign b_sub[DW-1:0] = {(DW){opt_sub}} ^ b[DW-1:0];
@ -39,5 +27,4 @@ module oh_add (/*AUTOARG*/
b_sub[DW-1:0] +
opt_sub +
cin;
endmodule // oh_add

View File

@ -1,24 +1,17 @@
/* Simple combinatorial priority arbiter
* bit[0] has highest priority
*
*/
//#############################################################################
//# Function: Statically configured arbiter #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_arbiter(/*AUTOARG*/
// Outputs
grants,
// Inputs
requests
);
parameter N = 99;
parameter TYPE = "FIXED"; //arbiter type
//"FIXED"
//"ROUNDROBIN"
//"FAIR"
input [N-1:0] requests; //request vector
output [N-1:0] grants; //grant (one hot)
module oh_arbiter #( parameter N = 1,
parameter TYPE = "FIXED" // or ROUNDROBIN, FAIR
)
(
input [N-1:0] requests, //request vector
output [N-1:0] grants //grant (one hot)
);
wire [N-1:0] waitmask;
genvar j;

View File

@ -1,21 +1,17 @@
module oh_bin2gray (/*AUTOARG*/
// Outputs
gray,
// Inputs
bin
);
//#############################################################################
//# Function: Binary to gray encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//###############################################################
//# Interface
//###############################################################
input [DW-1:0] bin; //binary encoded input
output [DW-1:0] gray; //gray encoded output
parameter DW = 64; //width of converter
//###############################################################
//# BODY
//###############################################################
module oh_bin2gray #(parameter DW = 32 // width of data inputs
)
(
input [DW-1:0] bin, //binary encoded input
output [DW-1:0] gray //gray encoded output
);
reg [DW-1:0] gray;
integer i;
@ -25,6 +21,5 @@ module oh_bin2gray (/*AUTOARG*/
for (i=0; i<(DW-1); i=i+1)
gray[i] = bin[i] ^ bin[i+1];
end
endmodule // oh_bin2gray

View File

@ -0,0 +1,28 @@
//#############################################################################
//# Function: Binary to one hot encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_bin2onehot #(parameter DW = 32) // width of data inputs
(
input [NB-1:0] in, // unsigned binary input
output [DW-1:0] out // one hot output vector
);
localparam NB = $clog2(DW); // encoded bit width
integer i;
reg [DW-1:0] out;
always @*
for(i=0;i<DW;i=i+1)
out[i]=(in[NB-1:0]==i);
endmodule // oh_bin2onehot

View File

@ -1,26 +0,0 @@
module oh_binary_decode (/*AUTOARG*/
// Outputs
out,
// Inputs
in
);
parameter N = 32; // one hot bit width
localparam NB = $clog2(N); // encoded bit width
input [NB-1:0] in;
output [N-1:0] out;
integer i;
reg [N-1:0] out;
always @*
for(i=0;i<N;i=i+1)
out[i]=(in[NB-1:0]==i);
endmodule // oh_binary_decode

View File

@ -1,14 +1,17 @@
module oh_bitreverse (/*AUTOARG*/
// Outputs
out,
// Inputs
in
);
//#############################################################################
//# Function: Binary to one hot encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW = 64; // width operation
input [DW-1:0] in; // data input
output [DW-1:0] out; // bit reversed output
module oh_bitreverse #(parameter DW = 32 // width of data inputs
)
(
input [DW-1:0] in, // data input
output [DW-1:0] out // bit reversed output
);
reg [DW-1:0] out;
integer i;

View File

@ -3,72 +3,78 @@
// Secondary clock must be multiple of first clock #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_clockdiv(/*AUTOARG*/
// Outputs
clkout0, clkrise0, clkfall0, clkout1, clkrise1, clkfall1,
// Inputs
clk, nreset, clken, clkdiv, clkphase0, clkphase1
);
//parameters
parameter DW = 8; // divider counter width
//inputs
input clk; // main clock
input nreset; // async active low reset
input clken; // clock enable enable
input [7:0] clkdiv; // [7:0]=period (0==off, 1=div/2, 2=div/3, etc)
input [15:0] clkphase0; // [7:0]=rising,[15:8]=falling
input [15:0] clkphase1; // [7:0]=rising,[15:8]=falling
//primary clock
output clkout0; // primary output clock
output clkrise0; // rising edge match
output clkfall0; // falling edge match
//secondary clock
output clkout1; // secondary output clock
output clkrise1; // rising edge match
output clkfall1; // falling edge match
//################################
//# BODY
//################################
module oh_clockdiv
(
//inputs
input clk, // main clock
input nreset, // async active low reset (from oh_rsync)
input clkchange, // indicates a parameter change
input clken, // clock enable
input [7:0] clkdiv, // [7:0]=period (0==bypass, 1=div/2, 2=div/3, etc)
input [15:0] clkphase0, // [7:0]=rising,[15:8]=falling
input [15:0] clkphase1, // [7:0]=rising,[15:8]=falling
//outputs
output clkout0, // primary output clock
output clkrise0, // rising edge match
output clkfall0, // falling edge match
output clkout1, // secondary output clock
output clkrise1, // rising edge match
output clkfall1, // falling edge match
output clkstable // clock is guaranteed to be stable
);
//regs
reg [DW-1:0] counter; // free running counter
reg clkout0_reg;
reg clkout1_reg;
reg clkout1_shift;
reg [7:0] counter;
reg clkout0_reg;
reg clkout1_reg;
reg clkout1_shift;
reg [2:0] period;
//###########################################
//# CHANGE DETECT (count 8 periods)
//###########################################
always @ (posedge clk or negedge nreset)
if(!nreset)
period[2:0] <= 'b0;
else if (clkchange)
period[2:0] <='b0;
else if(period_match & ~clkstable)
period[2:0] <= period[2:0] +1'b1;
assign clkstable = (period[2:0]==3'b111);
//###########################################
//# CYCLE COUNTER
//###########################################
always @ (posedge clk or negedge nreset)
if (~nreset)
counter[DW-1:0] <= 'b0;
if (!nreset)
counter[7:0] <= 'b0;
else if(clken)
if(period_match)
counter[DW-1:0] <= 'b0;
counter[7:0] <= 'b0;
else
counter[DW-1:0] <= counter[DW-1:0] + 1'b1;
assign period_match = (counter[DW-1:0]==clkdiv[7:0]);
counter[7:0] <= counter[7:0] + 1'b1;
assign period_match = (counter[7:0]==clkdiv[7:0]);
//###########################################
//# RISING/FALLING EDGE SELECTORS
//###########################################
assign clkrise0 = (counter[DW-1:0]==clkphase0[7:0]);
assign clkfall0 = (counter[DW-1:0]==clkphase0[15:8]);
assign clkrise1 = (counter[DW-1:0]==clkphase1[7:0]);
assign clkfall1 = (counter[DW-1:0]==clkphase1[15:8]);
assign clkrise0 = (counter[7:0]==clkphase0[7:0]);
assign clkfall0 = (counter[7:0]==clkphase0[15:8]);
assign clkrise1 = (counter[7:0]==clkphase1[7:0]);
assign clkfall1 = (counter[7:0]==clkphase1[15:8]);
//###########################################
//# CLKOUT0
//###########################################
always @ (posedge clk or negedge nreset)
if(!nreset)
clkout0_reg <= 1'b0;
@ -78,6 +84,7 @@ module oh_clockdiv(/*AUTOARG*/
clkout0_reg <= 1'b0;
//bypass divider on "divide by 1"
//TODO: Fix clock glitch!
assign clkout0 = (clkdiv[7:0]==8'd0) ? clk : // bypass
clkout0_reg; // all others
@ -96,37 +103,13 @@ module oh_clockdiv(/*AUTOARG*/
always @ (negedge clk)
clkout1_shift <= clkout1_reg;
//TODO: Fix clock glitch!
assign clkout1 = (clkdiv[7:0]==8'd0) ? clk : //bypass
(clkdiv[7:0]==8'd1) ? clkout1_shift : //div2
clkout1_reg; //all others
endmodule // oh_clockdiv
///////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software") //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT //
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,21 +1,18 @@
module oh_clockgate(/*AUTOARG*/
// Outputs
eclk,
// Inputs
nrst, clk, en, se
);
//#############################################################################
//# Function: Low power clock gate circuit #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
input nrst; // active low reset (synced to clk)
input clk; // clock input
input se; // scan enable
input [DW-1:0] en; // enable (from positive edge FF)
output [DW-1:0] eclk;// enabled clock
`ifdef CFG_ASIC
`else
module oh_clockgate #(parameter DW = 1) // width of data
(
input nrst, // active low sync reset (synced to input clk)
input clk, // clock input
input se, // scan enable
input [DW-1:0] en, // enable (from positive edge FF)
output [DW-1:0] eclk// enabled clock output
);
wire [DW-1:0] en_sh;
wire [DW-1:0] en_sl;
@ -26,15 +23,14 @@ module oh_clockgate(/*AUTOARG*/
{(DW){~nrst}};
//making signal stable
oh_lat0 #(.DW(1)) lat0 (.out_sh (en_sh[DW-1:0]),
.in_sl (en_sl[DW-1:0]),
.clk (clk)
oh_lat0 #(.DW(1)) lat0 (.out (en_sh[DW-1:0]),
.in (en_sl[DW-1:0]),
.clk (clk)
);
assign eclk[DW-1:0] = {(DW){clk}} & en_sh[DW-1:0];
`endif
endmodule // clock_gater
endmodule // oh_clockgate

View File

@ -1,53 +1,30 @@
module oh_counter (/*AUTOARG*/
// Outputs
count, carry, zero,
// Inputs
clk, in, en, load, load_data
);
//###############################################################
//# Interface
//###############################################################
//#############################################################################
//# Function: Binary to gray encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW = 64;
parameter TYPE = "INCREMENT"; //INCREMENT, DECREMENT, GRAY, LFSR
module oh_counter #(parameter DW = 32, // width of data inputs
parameter TYPE = "INCREMENT" // also DECREMENT, GRAY, LFSR
)
(
input clk, // clk input
input in, // input to count
input en, // enable counter
input load, // load counter
input [DW-1:0] load_data,// load data
output [DW-1:0] count, // current count value
output carry, // carry out from counter
output zero // counter is zero
);
//clock interface
input clk; // clk input
//counter control
input in; // input to count
input en; // enable counter
input load; // load counter
input [DW-1:0] load_data;// load data
//outputs
output [DW-1:0] count; // current count value
output carry; // carry out from counter
output zero; // counter is zero
//###############################################################
//# Interface
//###############################################################
// local variables
reg [DW-1:0] count;
reg carry;
wire [DW-1:0] count_in;
wire carry_in;
always @(posedge clk)
if(load)
begin
carry <= 1'b0;
count[DW-1:0] <= load_data[DW-1:0];
end
else if (en)
begin
carry <= carry_in;
count[DW-1:0] <= count_in[DW-1:0];
end
assign zero = ~(count[DW-1:0]);
// configure counter based on type
generate
if(TYPE=="INCREMENT")
@ -69,8 +46,23 @@ module oh_counter (/*AUTOARG*/
$display ("NOT IMPLEMENTED");
end
endgenerate
// counter
always @(posedge clk)
if(load)
begin
carry <= 1'b0;
count[DW-1:0] <= load_data[DW-1:0];
end
else if (en)
begin
carry <= carry_in;
count[DW-1:0] <= count_in[DW-1:0];
end
// counter expired
assign zero = ~(count[DW-1:0]);
endmodule // oh_counter

View File

@ -1,28 +1,20 @@
module oh_crc (/*AUTOARG*/
// Outputs
crc_state, crc_next,
// Inputs
data_in
);
//#############################################################################
//# Function: CRC combinatorial encoder wrapper #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//###############################################################
//# Interface
//###############################################################
// parameters
parameter TYPE = "ETH"; // type: "ETH", "OTHER"
parameter DW = 8; // width of data
parameter CW = 32; // width of polynomial
// signals
input [DW-1:0] data_in;
output [CW-1:0] crc_state;
output [CW-1:0] crc_next;
//###############################################################
//# BODY
//###############################################################
module oh_crc #( parameter TYPE = "ETH", // type: "ETH", "OTHER"
parameter DW = 8) // width of data
(
input [DW-1:0] data_in, // input data
input [CW-1:0] crc_state, // input crc state
output [CW-1:0] crc_next // next crc state
);
localparam CW = 32; // width of polynomial
generate
if(TYPE=="ETH")
begin
@ -45,3 +37,4 @@ module oh_crc (/*AUTOARG*/
endgenerate
endmodule // oh_crc

View File

@ -2,11 +2,11 @@
//# Function: Carry Save Adder (3:2) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in this repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_csa32 #( parameter DW = 1 // data width
)
module oh_csa32 #(parameter DW = 1 // data width
)
( input [DW-1:0] in0, //input
input [DW-1:0] in1,//input
input [DW-1:0] in2,//input

View File

@ -2,11 +2,10 @@
//# Function: Carry Save Adder (4:2) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in this repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_csa42 #( parameter DW = 1 // data width
)
module oh_csa42 #( parameter DW = 1) // data width
( input [DW-1:0] in0, //input
input [DW-1:0] in1,//input
input [DW-1:0] in2,//input

View File

@ -3,10 +3,10 @@
//# Function: Carry Save Adder (6:2) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in this repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_csa62 #( parameter DW = 1 // data width
module oh_csa62 #(parameter DW = 1 // data width
)
( input [DW-1:0] in0, //input
input [DW-1:0] in1,//input

View File

@ -2,11 +2,10 @@
//# Function: Carry Save Adder (9:2) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in this repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_csa92 #( parameter DW = 1 // data width
)
module oh_csa92 #( parameter DW = 1) // data width
( input [DW-1:0] in0, //input
input [DW-1:0] in1,//input

View File

@ -1,18 +1,21 @@
module oh_datagate (/*AUTOARG*/
// Outputs
dout,
// Inputs
clk, en, din
);
//#############################################################################
//# Function: Low power data gate #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW = 32;
parameter PS = 3;
module oh_datagate #(parameter DW = 32, // width of data inputs
parameter PS = 3 // min quiet time before shutdown
)
(
input clk, // clock
input en, // data valid
input [DW-1:0] din, // data input
output [DW-1:0] dout // data output
);
input clk;
input en;
input [DW-1:0] din;
output [DW-1:0] dout;
reg [PS-1:0] enable_pipe;
wire enable;
@ -22,6 +25,5 @@ module oh_datagate (/*AUTOARG*/
assign enable = {enable_pipe[PS-1:0],en};
assign dout[DW-1:0] = {(DW){enable}} & din[DW-1:0];
endmodule // oh_datagate

View File

@ -1,40 +1,35 @@
//#########################################################################
//# Function: A digital debounce circuit
//# Usage: Set the BOUNCE and CLKPERIOD values during instantional to suite
//# your switch and clkperiod.
//#
//########################################################################
module oh_debouncer (/*AUTOARG*/
// Outputs
clean_out,
// Inputs
clk, nreset, noisy_in
);
//#############################################################################
//# Function: A digital debouncer circuit #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
// parameters (in milliseconds)
parameter BOUNCE = 100; // bounce time of switch (s)
parameter CLKPERIOD = 0.00001; // period (10ns=0.0001ms))
parameter CW = $clog2(BOUNCE/CLKPERIOD);// counter width needed
module oh_debouncer #( parameter BOUNCE = 100, // bounce time (s)
parameter CLKPERIOD = 0.00001 // period (10ns=0.0001ms)
)
(
input clk, // clock to synchronize to
input nreset, // syncronous active high reset
input noisy_in, // noisy input signal to filter
output clean_out // clean signal to logic
);
// signal interface
input clk; // clock to synchronize to
input nreset; // syncronous active high reset
input noisy_in; // noisy input signal to filter
output clean_out; // clean signal to logic
//temp variables
wire noisy_synced;
//################################
//# wires/regs/ params
//################################
localparam integer CW = $clog2(BOUNCE/CLKPERIOD);// counter width needed
//regs
reg noisy_reg;
reg clean_out;
wire nreset_synced;
// synchronize reset
// synchronize incoming signal
oh_dsync dsync (.dout (noisy_synced),
.clk (clk),
.din (noisy_in));
// synchronize input to clk (always!)
// synchronize reset to clk
oh_rsync rsync (.nrst_out (nreset_synced),
.clk (clk),
.nrst_in (nreset));
@ -45,7 +40,7 @@ module oh_debouncer (/*AUTOARG*/
assign change_detected = noisy_reg ^ noisy_synced;
// synchronous counter
// synchronous counter "filter"
oh_counter #(.DW(CW))
oh_counter (// Outputs
.count (),
@ -64,5 +59,6 @@ module oh_debouncer (/*AUTOARG*/
if(carry)
clean_out <= noisy_reg;
endmodule
endmodule // oh_debouncer

View File

@ -1,45 +1,34 @@
/* A control signal synchronizer with "PS" number of stages
*/
//#############################################################################
//# Function: Clock synchronizer #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_dsync (/*AUTOARG*/
// Outputs
dout,
// Inputs
clk, din
);
parameter PS = 2; //number of sync pipeline stages
parameter DW = 1; //number of bits to synchronize
module oh_dsync #(parameter DW = 1, // width of data
parameter PS = 3 // mnumber of sync stages
)
(
input clk, // clock
input [DW-1:0] din, // input data
output [DW-1:0] dout // synchronized data
);
input clk;
input [DW-1:0] din;
output [DW-1:0] dout;
`ifdef TARGET_SIM
reg [DW-1:0] sync_pipe[PS-1:0];
`else
(* ASYNC_REG = "TRUE" *) (* DONT_TOUCH = "TRUE" *) reg [DW-1:0] sync_pipe[PS-1:0];
`endif
reg [DW-1:0] sync_pipe[PS-1:0];
genvar i;
generate
for(i=0;i<PS;i=i+1)
if(i==0)
begin
always @ (posedge clk)
sync_pipe[0][DW-1:0] <= din[DW-1:0];
end
always @ (posedge clk)
sync_pipe[0][DW-1:0] <= din[DW-1:0];
else
begin
always @ (posedge clk )
sync_pipe[i][DW-1:0] <= sync_pipe[i-1][DW-1:0];
end // else: !if(i==0)
endgenerate
assign dout[DW-1:0] = sync_pipe[PS-1][DW-1:0];
endmodule // oh_dsync

View File

@ -2,32 +2,19 @@
//# Function: Converts an edge to a single cycle pulse #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_edge2pulse(/*AUTOARG*/
// Outputs
out,
// Inputs
clk, nreset, in
);
module oh_edge2pulse #( parameter DW = 1) // width of data inputs
(
input clk, // clock
input nreset, // async active low reset
input [DW-1:0] in, // edge input
output [DW-1:0] out // one cycle pulse
);
reg [DW-1:0] in_reg;
//########################################
//# INTERFACE
//########################################
parameter DW = 1; // width of data inputs
input clk; // clock
input nreset; // async active low reset
input [DW-1:0] in; // edge input
output [DW-1:0] out; // one cycle pulse
//########################################
//# BODY
//########################################
reg [DW-1:0] in_reg;
always @ (posedge clk or negedge nreset)
if(!nreset)
in_reg[DW-1:0] <= 'b0 ;
@ -37,28 +24,3 @@ module oh_edge2pulse(/*AUTOARG*/
assign out[DW-1:0] = in_reg[DW-1:0] ^ in[DW-1:0] ;
endmodule // oh_edge2pulse
//////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software")//
// to deal in the Software without restriction, including without limitation//
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT//
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,9 +1,11 @@
/* Detects the common aligned positive edge for a
* slow/fast clocks. The circuit uses the negedge of the fast clock
* to sample the slow clock. Output is positive edge sampled.
*
* NOTE: Assumes clocks are aligned and synchronous!
*
//#############################################################################
//# Function: Aligns positive edge of slow clock to fast clock #
//# !!!Assumes clocks are aligned and synchronous!!! #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
/*
* ___________ ___________
* __/ \___________/ \ SLOWCLK
* __ __ __ __ __ __
@ -16,10 +18,7 @@
* ____ ______
* \________________/ \________ FIRSTEDGE
*
*
*
*/
module oh_edgealign (/*AUTOARG*/
// Outputs
firstedge,
@ -44,10 +43,6 @@ module oh_edgealign (/*AUTOARG*/
firstedge <= ~clk45 & clk90;
end
//TODO: parametrized based on 1/N ratios?
//TODO: can we do this without using clock as data input?
endmodule // oh_edgealign

View File

@ -1,31 +1,18 @@
//#############################################################################
//# Function: Converts a falling edge to a single cycle pulse #
//# Function: Converts a falling edge to a single cycle pulse #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_fall2pulse(/*AUTOARG*/
// Outputs
out,
// Inputs
clk, nreset, in
);
//########################################
//# INTERFACE
//########################################
parameter DW = 1; // width of data inputs
input clk; // clock
input nreset; // async active low reset
input [DW-1:0] in; // edge input
output [DW-1:0] out; // one cycle pulse
//########################################
//# BODY
//########################################
module oh_fall2pulse #(parameter DW = 1) //data width
(
input clk, // clock
input nreset, // async active low reset
input [DW-1:0] in, // edge input
output [DW-1:0] out // one cycle pulse
);
reg [DW-1:0] in_reg;
always @ (posedge clk or negedge nreset)
@ -36,29 +23,5 @@ module oh_fall2pulse(/*AUTOARG*/
assign out[DW-1:0] = ~in[DW-1:0] & in_reg[DW-1:0] ;
endmodule // oh_edge2pulse
endmodule // oh_fall2pulse
//////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software")//
// to deal in the Software without restriction, including without limitation//
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT//
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,108 +1,73 @@
`include "mio_constants.vh"
module oh_fifo_async (/*AUTOARG*/
// Outputs
dout, full, prog_full, empty, rd_count,
// Inputs
nreset, wr_clk, wr_en, din, rd_clk, rd_en
);
//#############################################################################
//# Function: Parametrized asynchronous clock FIFO #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//#####################################################################
//# INTERFACE
//#####################################################################
parameter DW = 104; // FIFO width
parameter DEPTH = 32; // FIFO depth (entries)
parameter TARGET = "GENERIC"; // GENERIC,XILINX,ALTERA,GENERIC,ASIC
parameter WAIT = 0; // assert random prog_full wait
parameter PROG_FULL = DEPTH/2; // program full threshold
parameter AW = $clog2(DEPTH);// binary read count width
module oh_fifo_async # (parameter DW = 104, //FIFO width
parameter DEPTH = 32, //FIFO depth (entries)
parameter TARGET = "GENERIC",//XILINX,ALTERA,GENERIC,ASIC
parameter PROG_FULL = (DEPTH/2),// program full threshold
parameter AW = $clog2(DEPTH) // binary read count width
)
(
input nreset, // async reset
input wr_clk, // write clock
input wr_en, // write fifo
input [DW-1:0] din, // data to write
input rd_clk, // read clock
input rd_en, // read fifo
output [DW-1:0] dout, // output data (next cycle)
output full, // fifo is full
output prog_full, // fifo reaches full threshold
output empty, // fifo is empty
output [AW-1:0] rd_count // # of valid entries in fifo
);
//clk/reset
input nreset; // async reset
//write port
input wr_clk; // write clock
input wr_en; // write fifo
input [DW-1:0] din; // data to write
//read port
input rd_clk; // read clock
input rd_en; // read fifo
output [DW-1:0] dout; // output data (next cycle)
//status
output full; // fifo is full
output prog_full; // fifo reaches full threshold
output empty; // fifo is empty
output [AW-1:0] rd_count; // valid entries in fifo
//#####################################################################
//# BODY
//#####################################################################
//local wires
wire fifo_prog_full;
wire wait_random;
wire [AW-1:0] wr_count; // valid entries in fifo
assign prog_full = fifo_prog_full | wait_random;
generate
if(TARGET=="GENERIC") begin : basic
oh_fifo_generic
#(.DEPTH(DEPTH),
.DW(DW))
fifo_generic (
// Outputs
.full (full),
.prog_full (fifo_prog_full),
.dout (dout[DW-1:0]),
.empty (empty),
.rd_count (rd_count[AW-1:0]),
.wr_count (wr_count[AW-1:0]),
// Inputs
.nreset (nreset),
.wr_clk (wr_clk),
.rd_clk (rd_clk),
.wr_en (wr_en),
.din (din[DW-1:0]),
.rd_en (rd_en));
end
else if (TARGET=="XILINX") begin : xilinx
if((DW==104) & (DEPTH==32))
begin
fifo_async_104x32 fifo (
// Outputs
.full (full),
.prog_full (fifo_prog_full),
.dout (dout[DW-1:0]),
.empty (empty),
.rd_data_count (rd_count[AW-1:0]),
// Inputs
.rst (~nreset),
.wr_clk (wr_clk),
.rd_clk (rd_clk),
.wr_en (wr_en),
.din (din[DW-1:0]),
.rd_en (rd_en));
end // if ((DW==104) & (DEPTH==32))
end // block: xilinx
endgenerate
//Random wait generator (for testing)
generate
if(WAIT>0)
begin
reg [7:0] wait_counter;
always @ (posedge wr_clk or negedge nreset)
if(~nreset)
wait_counter[7:0] <= 'b0;
else
wait_counter[7:0] <= wait_counter+1'b1;
assign wait_random = (|wait_counter[4:0]);//(|wait_counter[3:0]);//1'b0;
end
else
begin
assign wait_random = 1'b0;
end // else: !if(WAIT)
if(TARGET=="GENERIC") begin : basic
oh_fifo_generic #(.DEPTH(DEPTH),
.DW(DW))
fifo_generic (
// Outputs
.full (full),
.prog_full (prog_full),
.dout (dout[DW-1:0]),
.empty (empty),
.rd_count (rd_count[AW-1:0]),
.wr_count (wr_count[AW-1:0]),
// Inputs
.nreset (nreset),
.wr_clk (wr_clk),
.rd_clk (rd_clk),
.wr_en (wr_en),
.din (din[DW-1:0]),
.rd_en (rd_en));
end
else if (TARGET=="XILINX") begin : xilinx
if((DW==104) & (DEPTH==32))
begin
fifo_async_104x32
fifo (
// Outputs
.full (full),
.prog_full (prog_full),
.dout (dout[DW-1:0]),
.empty (empty),
.rd_data_count (rd_count[AW-1:0]),
// Inputs
.rst (~nreset),
.wr_clk (wr_clk),
.rd_clk (rd_clk),
.wr_en (wr_en),
.din (din[DW-1:0]),
.rd_en (rd_en));
end // if ((DW==104) & (DEPTH==32))
end // block: xilinx
endgenerate
endmodule // oh_fifo_async

View File

@ -1,57 +1,36 @@
//########################################################################
//# FIFO based clock Domain Crosser
//########################################################################
module oh_fifo_cdc (/*AUTOARG*/
// Outputs
wait_out, access_out, packet_out, prog_full, full, empty,
// Inputs
nreset, clk_in, access_in, packet_in, clk_out, wait_in
);
//#############################################################################
//# Function: Clock domain crossing FIFO #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//#####################################################################
//# INTERFACE
//#####################################################################
parameter DW = 104; // FIFO width
parameter DEPTH = 32; // FIFO depth (entries)
parameter TARGET = "GENERIC"; // GENERIC,XILINX,ALTERA,GENERIC,ASIC
parameter WAIT = 0; // assert random prog_full wait
module oh_fifo_cdc # (parameter DW = 104, //FIFO width
parameter DEPTH = 32, //FIFO depth (entries)
parameter TARGET = "GENERIC" //XILINX,ALTERA,GENERIC,ASIC
)
(
input nreset, // shared domain async active low reset
input clk_in, // write clock
input access_in, // write access
input [DW-1:0] packet_in, // write packet
output wait_out, // write pushback
input clk_out, //read clock
output access_out, //read access
output [DW-1:0] packet_out, //read packet
input wait_in, // read pushback
output prog_full, // fifo is half full
output full, // fifo is full
output empty // fifo is empty
);
//shared async reset
input nreset;
//input packet
input clk_in;
input access_in;
input [DW-1:0] packet_in;
output wait_out;
//output packet
input clk_out;
output access_out;
output [DW-1:0] packet_out;
input wait_in;
//status
output prog_full;
output full;
output empty;
// local variables
reg access_out;
//#####################################################################
//# BODY
//#####################################################################
//Local wires
wire wr_en;
wire rd_en;
wire empty;
wire full;
wire prog_full;
reg access_out;
//We use the prog_full clean out any buffers in pipe
//Assumption: The "full" state should never be reached!
// FIFO control logic
assign wr_en = access_in;
assign rd_en = ~empty & ~wait_in;
assign wait_out = prog_full;
assign wait_out = prog_full; //wait_out should stall access_in signal
//Holds access high while waiting
always @ (posedge clk_out or negedge nreset)
@ -63,8 +42,7 @@ module oh_fifo_cdc (/*AUTOARG*/
//Read response fifo (from master)
oh_fifo_async #(.TARGET(TARGET),
.DW(DW),
.DEPTH(DEPTH),
.WAIT(WAIT))
.DEPTH(DEPTH))
fifo (.prog_full (prog_full),
.full (full),
.rd_count (),
@ -75,7 +53,7 @@ module oh_fifo_cdc (/*AUTOARG*/
.rd_clk (clk_out),
.wr_en (wr_en),
.din (packet_in[DW-1:0]),
.rd_en (rd_en)
);
.rd_en (rd_en));
endmodule // fifo_cdc
endmodule // oh_fifo_cdc

View File

@ -1,52 +1,32 @@
//#####################################################################
//# Asynchronous FIFO based on article by Clifford Cummings,
//# "Simulation and Synthesis Techniques for Asynchronous FIFO Design"
//# (SNUG2002)
//#
//# Modifications: Using binary comparisons for simplicity. This may cost
//# a few more gates, but the the clarity is worth it.
//#####################################################################
module oh_fifo_generic
(/*AUTOARG*/
// Outputs
dout, empty, full, prog_full, rd_count, wr_count,
// Inputs
nreset, wr_clk, wr_en, din, rd_clk, rd_en
);
//#############################################################################
//# Function: Generic Async FIFO #
//# Based on article by Clifford Cummings, #
// "Simulation and Synthesis Techniques for Asynchronous FIFO Design" #
//# (SNUG2002) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//#####################################################################
//# INTERFACE
//#####################################################################
// parameters
parameter DW = 104; // FIFO width
parameter DEPTH = 16; // FIFO depth (entries)
parameter PROG_FULL = DEPTH/2; // FIFO full threshold
parameter AW = $clog2(DEPTH); // FIFO address width (for model)
// common reset
input nreset; // asynch active low reset
// fifo write
input wr_clk; // write clock
input wr_en; // write enable
input [DW-1:0] din; // write data
// fifo read
input rd_clk; // read clock
input rd_en; // read enable
output [DW-1:0] dout; // read data
// status
output empty; // fifo is empty
output full; // fifo is full
output prog_full; // fifo is "half empty"
output [AW-1:0] rd_count; // NOT IMPLEMENTED
output [AW-1:0] wr_count; // NOT IMPLEMENTED
//#####################################################################
//# BODY
//#####################################################################
module oh_fifo_generic #(parameter DW = 104, //FIFO width
parameter DEPTH = 32, //FIFO depth (entries)
parameter PROG_FULL = (DEPTH/2),//program full threshold
parameter AW = $clog2(DEPTH) // binary read count width
)
(
input nreset, // asynch active low reset
input wr_clk, // write clock
input wr_en, // write enable
input [DW-1:0] din, // write data
input rd_clk, // read clock
input rd_en, // read enable
output [DW-1:0] dout, // read data
output empty, // fifo is empty
output full, // fifo is full
output prog_full, // fifo is "half empty"
output [AW-1:0] rd_count, // NOT IMPLEMENTED
output [AW-1:0] wr_count // NOT IMPLEMENTED
);
//regs
reg [AW:0] wr_addr; // extra bit for wraparound comparison
@ -63,7 +43,7 @@ module oh_fifo_generic
//# Full/empty indicators
//###########################
// uses on extra bit for compare to track wraparound pointers
// uses one extra bit for compare to track wraparound pointers
// careful clock synchronization done using gray codes
// could get rid of gray2bin for rd_addr_sync...
@ -128,7 +108,6 @@ module oh_fifo_generic
rd_g2b (.bin (rd_addr_sync[AW:0]),
.gray (rd_addr_gray_sync[AW:0]));
//###########################
//#dual ported memory
//###########################

View File

@ -1,40 +1,28 @@
module oh_fifo_sync (/*AUTOARG*/
// Outputs
dout, full, prog_full, empty, rd_count,
// Inputs
clk, nreset, din, wr_en, rd_en
);
//#####################################################################
//# INTERFACE
//#####################################################################
parameter DEPTH = 4;
parameter DW = 104;
parameter PROG_FULL = DEPTH/2;
parameter AW = $clog2(DEPTH);
//#############################################################################
//# Function: Synchronous FIFO #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//clk/reset
input clk; // clock
input nreset; // active high async reset
//write port
input [DW-1:0] din; // data to write
input wr_en; // write fifo
//read port
input rd_en; // read fifo
output [DW-1:0] dout; // output data (next cycle)
//Status
output full; // fifo full
output prog_full; // fifo is almost full
output empty; // fifo is empty
output [AW-1:0] rd_count; // valid entries in fifo
//#####################################################################
//# BODY
//#####################################################################
module oh_fifo_sync #(parameter DW = 104, //FIFO width
parameter DEPTH = 32, //FIFO depth
parameter PROG_FULL = (DEPTH/2),//prog_full threshold
parameter AW = $clog2(DEPTH) //rd_count width
)
(
input clk, // clock
input nreset, // active high async reset
input [DW-1:0] din, // data to write
input wr_en, // write fifo
input rd_en, // read fifo
output [DW-1:0] dout, // output data (next cycle)
output full, // fifo full
output prog_full, // fifo is almost full
output empty, // fifo is empty
output [AW-1:0] rd_count // valid entries in fifo
);
reg [AW-1:0] wr_addr;
reg [AW-1:0] rd_addr;
reg [AW-1:0] rd_count;
@ -72,8 +60,7 @@ module oh_fifo_sync (/*AUTOARG*/
oh_memory_dp
#(.DW(DW),
.AW(AW))
mem (
// read port
mem (// read port
.rd_dout (dout[DW-1:0]),
.rd_clk (clk),
.rd_en (fifo_read),
@ -83,11 +70,6 @@ module oh_fifo_sync (/*AUTOARG*/
.wr_en (fifo_write),
.wr_wem ({(DW){1'b1}}),
.wr_addr (wr_addr[AW-1:0]),
.wr_din (din[DW-1:0])
);
.wr_din (din[DW-1:0]));
endmodule // fifo_sync
// Local Variables:
// verilog-library-directories:(".")
// End:
endmodule // oh_fifo_sync

View File

@ -1,23 +1,17 @@
module oh_gray2bin (/*AUTOARG*/
// Outputs
bin,
// Inputs
gray
);
//#############################################################################
//# Function: Gray to binary encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//###############################################################
//# Interface
//###############################################################
input [DW-1:0] gray; //gray encoded input
output [DW-1:0] bin; //binary encoded output
parameter DW = 64; //width of converter
module oh_gray2bin #(parameter DW = 32) // width of data inputs
(
input [DW-1:0] gray,//gray encoded input
output [DW-1:0] bin //binary encoded output
);
//###############################################################
//# BODY
//###############################################################
reg [DW-1:0] bin;
reg [DW-1:0] bin;
integer i,j;
always @*

View File

@ -1,30 +1,19 @@
//##################################################################
//# ***DUAL DATA RATE INPUT***
//#
//# * Equivalent to "SAME_EDGE_PIPELINED" for xilinx
//# * din sampled on rising edge of clk
//# * din sampled on falling edge of clk
//# * q1 holds rising edge data
//# * q2 holds falling edge data
//#
//##################################################################
//#############################################################################
//# Function: Dual data rate input buffer #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_iddr (/*AUTOARG*/
// Outputs
q1, q2,
// Inputs
clk, ce, din
);
//parameters
parameter DW = 32; // width of interface
//interface
input clk; // clock
input ce; // clock enable, set to high to clock in data
input [DW-1:0] din; // data input
output [DW-1:0] q1; // iddr rising edge sampled data
output [DW-1:0] q2; // iddr falling edge sampled data
module oh_iddr #(parameter DW = 1 // width of data inputs
)
(
input clk, // clock
input ce, // clock enable, set to high to clock in data
input [DW-1:0] din, // data input sampled on both edges of clock
output [DW-1:0] q1, // iddr rising edge sampled data
output [DW-1:0] q2 // iddr falling edge sampled data
);
//regs("sl"=stable low, "sh"=stable high)
reg [DW-1:0] q1_sl;

View File

@ -1,50 +1,53 @@
//#############################################################################
//# Function: Dual Port Memory #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
/*###########################################################################
# Function: Dual port memory wrapper (one read/ one write port)
# To run without hardware platform dependancy, `define:
# "TARGET_CLEAN"
############################################################################
*/
module oh_memory_dp(/*AUTOARG*/
// Outputs
rd_dout,
// Inputs
wr_clk, wr_en, wr_wem, wr_addr, wr_din, rd_clk, rd_en, rd_addr
);
parameter AW = 14; //address width
parameter DW = 32; //memory width
localparam MD = 1<<AW;//memory depth
//write-port
input wr_clk; //write clock
input wr_en; //write enable
input [DW-1:0] wr_wem; //per bit write enable
input [AW-1:0] wr_addr;//write address
input [DW-1:0] wr_din; //write data
//read-port
input rd_clk; //read clock
input rd_en; //read enable
input [AW-1:0] rd_addr;//read address
output[DW-1:0] rd_dout;//read output data
module oh_memory_dp # (parameter DW = 104, //memory width
parameter DEPTH = 32, //memory depth
parameter PROJ = "", //project name
parameter MCW = 8 //repair/config vector width
)
(//write interface
input wr_clk, //write clock
input wr_en, //write enable
input [DW-1:0] wr_wem, //per bit write enable
input [AW-1:0] wr_addr,//write address
input [DW-1:0] wr_din, //write data
//read interface
input rd_clk, //read clock
input rd_en, //read enable
input [AW-1:0] rd_addr,//read address
output [DW-1:0] rd_dout,//read output data
//asic stuff
input vss, // common ground
input vdd, // periphery power rail
input vddm, // sram array power rail
input shutdown, // shutdown signal from always on domain
input [MCW-1:0] memconfig, // generic memory config
input [MCW-1:0] memrepair // repair vector
);
reg [DW-1:0] ram [MD-1:0];
localparam AW = $clog2(DEPTH); // address bus width
reg [DW-1:0] ram [DEPTH-1:0];
reg [DW-1:0] rd_dout;
integer i;
//read port
//registered read port
always @ (posedge rd_clk)
if(rd_en)
rd_dout[DW-1:0] <= ram[rd_addr[AW-1:0]];
//write port
//write port with vector enable
always @(posedge wr_clk)
for (i=0;i<DW;i=i+1)
if (wr_en & wr_wem[i])
ram[wr_addr[AW-1:0]][i] <= wr_din[i];
endmodule // memory_dp
endmodule // oh_memory_dp

View File

@ -1,42 +1,40 @@
module oh_memory_sp(/*AUTOARG*/
// Outputs
dout,
// Inputs
clk, en, we, wem, addr, din, vss, vdd, vddm, shutdown, memconfig,
memrepair, bist_en, bist_we, bist_wem, bist_addr, bist_din
);
//#############################################################################
//# Function: Sinle Port Memory #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_memory_sp # (parameter DW = 104, //memory width
parameter DEPTH = 32, //memory depth
parameter PROJ = "", //project name
parameter MCW = 8 //repair/config vector width
)
(// memory interface
input clk, // clock
input en, // memory access
input we, // write enable global signal
input [DW-1:0] wem, // write enable vector
input [AW-1:0] addr, // address
input [DW-1:0] din, // data input
output [DW-1:0] dout, // data output
// Power/repair (ASIC)
input vss, // common ground
input vdd, // periphery power rail
input vddm, // sram array power rail
input shutdown, // shutdown signal from always on domain
input [MCW-1:0] memconfig, // generic memory config
input [MCW-1:0] memrepair, // repair vector
// BIST interface (ASICs)
input bist_en, // bist enable
input bist_we, // write enable global signal
input [DW-1:0] bist_wem, // write enable vector
input [AW-1:0] bist_addr, // address
input [DW-1:0] bist_din // data input
);
// parameters
parameter DW = 32; // memory width
parameter DEPTH = 14; // memory depth
parameter MCW = 8; // repair/config vector width
parameter PROJ = ""; // project name (used for IP selection)
localparam AW = $clog2(DEPTH); // address bus width
// standard memory interface
input clk; // clock
input en; // memory access
input we; // write enable global signal
input [DW-1:0] wem; // write enable vector
input [AW-1:0] addr; // address
input [DW-1:0] din; // data input
output [DW-1:0] dout; // data output
// Power/repair interface (ASICs only)
input vss; // common ground
input vdd; // periphery power rail
input vddm; // array power rail
input shutdown; // shutdown signal from always on domain
input [MCW-1:0] memconfig; // generic memory config
input [MCW-1:0] memrepair; // repair vector
// BIST interface (ASICs only)
input bist_en; // bist enable
input bist_we; // write enable global signal
input [DW-1:0] bist_wem; // write enable vector
input [AW-1:0] bist_addr; // address
input [DW-1:0] bist_din; // data input
`ifdef CFG_ASIC
//Actual IP hidden behind wrapper to protect the innocent
@ -69,7 +67,7 @@ module oh_memory_sp(/*AUTOARG*/
`else
//Assume FPGA tool knows what it's doing (single clock...)
//Note: shutdown not modeleled properly, should invalidate all entries
//Note: shutdown not modeled properly, should invalidate all entries
//Retention should depend on vdd as well
reg [DW-1:0] ram [DEPTH-1:0];

View File

@ -1,30 +1,21 @@
//#########################################################################
//# GENERIC "ONE HOT" N:1 MUX
//# See also oh_mux2.v, oh_mux3.v, etc
//#########################################################################
module oh_mux (/*AUTOARG*/
// Outputs
out,
// Inputs
sel, in
);
//#####################################################################
//# INTERFACE
//#####################################################################
parameter DW = 1; // width of data inputs
parameter N = 1; // number of inputs
//#############################################################################
//# Function: "ONE HOT" N:1 MUX #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
input [N-1:0] sel; // select vector
input [N*DW-1:0] in; // concatenated input {..,in1[DW-1:0],in0[DW-1:0]
output [DW-1:0] out; // output
module oh_mux #( parameter DW = 1, // width of data inputs
parameter N = 1 // number of inputs
)
(
input [N-1:0] sel, // select vector
input [N*DW-1:0] in, // concatenated input {..,in1[DW-1:0],in0[DW-1:0]
output [DW-1:0] out // output
);
//#####################################################################
//# BODY
//#####################################################################
reg [DW-1:0] out;
//parametrized mux
integer i;
always @*
begin
@ -36,3 +27,4 @@ module oh_mux (/*AUTOARG*/
endmodule // oh_mux

View File

@ -1,45 +1,39 @@
module oh_mux12(/*AUTOARG*/
// Outputs
out,
// Inputs
in11, in10, in9, in8, in7, in6, in5, in4, in3, in2, in1, in0,
sel11, sel10, sel9, sel8, sel7, sel6, sel5, sel4, sel3, sel2, sel1,
sel0
);
//#############################################################################
//# Function: 12:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in11;
input [DW-1:0] in10;
input [DW-1:0] in9;
input [DW-1:0] in8;
input [DW-1:0] in7;
input [DW-1:0] in6;
input [DW-1:0] in5;
input [DW-1:0] in4;
input [DW-1:0] in3;
input [DW-1:0] in2;
input [DW-1:0] in1;
input [DW-1:0] in0;
//select inputs
input sel11;
input sel10;
input sel9;
input sel8;
input sel7;
input sel6;
input sel5;
input sel4;
input sel3;
input sel2;
input sel1;
input sel0;
output [DW-1:0] out;
module oh_mux12 #(parameter DW = 1 ) // width of mux
(
input sel11,
input sel10,
input sel9,
input sel8,
input sel7,
input sel6,
input sel5,
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in11,
input [DW-1:0] in10,
input [DW-1:0] in9,
input [DW-1:0] in8,
input [DW-1:0] in7,
input [DW-1:0] in6,
input [DW-1:0] in5,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |
{(DW){sel2}} & in2[DW-1:0] |
@ -52,7 +46,6 @@ module oh_mux12(/*AUTOARG*/
{(DW){sel9}} & in9[DW-1:0] |
{(DW){sel10}} & in10[DW-1:0] |
{(DW){sel11}} & in11[DW-1:0]);
endmodule // oh_mux12

View File

@ -1,21 +1,18 @@
module oh_mux2(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, sel0, sel1
);
//#############################################################################
//# Function: 2:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
//select inputs
input sel0;
input sel1;
output [DW-1:0] out;
module oh_mux2 #(parameter DW = 1 ) // width of mux
(
input sel1,
input sel0,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0]);

View File

@ -1,24 +1,20 @@
module oh_mux3(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, sel0, sel1, sel2
);
//#############################################################################
//# Function: 3:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
//select inputs
input sel0;
input sel1;
input sel2;
output [DW-1:0] out;
module oh_mux3 #(parameter DW = 1 ) // width of mux
(
input sel2,
input sel1,
input sel0,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |

View File

@ -1,48 +1,38 @@
module oh_mux4(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, sel0, sel1, sel2, sel3
);
//#############################################################################
//# Function: 4:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
module oh_mux4 #(parameter DW = 1 ) // width of mux
(
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
output [DW-1:0] out;
wire error;
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |
{(DW){sel2}} & in2[DW-1:0] |
{(DW){sel3}} & in3[DW-1:0]);
`ifdef TARGET_SIM
wire error;
assign error = (sel0 | sel1 | sel2 | sel3) &
~(sel0 ^ sel1 ^ sel2 ^ sel3);
always @ (posedge error)
begin
#1
if(error)
#1 if(error)
$display ("ERROR at in oh_mux4 %m at ",$time);
end
`endif
`endif
endmodule // oh_mux4

View File

@ -1,34 +1,29 @@
module oh_mux5(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, in4, sel0, sel1, sel2, sel3, sel4
);
//#############################################################################
//# Function: 5:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
input [DW-1:0] in4;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
input sel4;
output [DW-1:0] out;
module oh_mux5 #(parameter DW = 1 ) // width of mux
(
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |
{(DW){sel2}} & in2[DW-1:0] |
{(DW){sel3}} & in3[DW-1:0] |
{(DW){sel4}} & in4[DW-1:0]);
endmodule // mux5

View File

@ -1,32 +1,27 @@
module oh_mux6(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, in4, in5, sel0, sel1, sel2, sel3, sel4, sel5
);
//#############################################################################
//# Function: 6:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
input [DW-1:0] in4;
input [DW-1:0] in5;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
input sel4;
input sel5;
output [DW-1:0] out;
module oh_mux6 #(parameter DW = 1 ) // width of mux
(
input sel5,
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in5,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |
{(DW){sel2}} & in2[DW-1:0] |

View File

@ -1,35 +1,28 @@
module oh_mux7(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, in4, in5, in6, sel0, sel1, sel2, sel3, sel4,
sel5, sel6
);
//#############################################################################
//# Function: 7:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
input [DW-1:0] in4;
input [DW-1:0] in5;
input [DW-1:0] in6;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
input sel4;
input sel5;
input sel6;
output [DW-1:0] out;
module oh_mux7 #(parameter DW = 1 ) // width of mux
(
input sel6,
input sel5,
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in6,
input [DW-1:0] in5,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |

View File

@ -1,37 +1,30 @@
module oh_mux8(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, in4, in5, in6, in7, sel0, sel1, sel2, sel3,
sel4, sel5, sel6, sel7
);
//#############################################################################
//# Function: 8:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
input [DW-1:0] in4;
input [DW-1:0] in5;
input [DW-1:0] in6;
input [DW-1:0] in7;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
input sel4;
input sel5;
input sel6;
input sel7;
output [DW-1:0] out;
module oh_mux8 #(parameter DW = 1 ) // width of mux
(
input sel7,
input sel6,
input sel5,
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in7,
input [DW-1:0] in6,
input [DW-1:0] in5,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |

View File

@ -1,38 +1,33 @@
module oh_mux9(/*AUTOARG*/
// Outputs
out,
// Inputs
in0, in1, in2, in3, in4, in5, in6, in7, in8, sel0, sel1, sel2,
sel3, sel4, sel5, sel6, sel7, sel8
);
//#############################################################################
//# Function: 9:1 one hot mux #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter DW=1;
module oh_mux9 #( parameter DW = 1 ) // width of mux
(
input sel8,
input sel7,
input sel6,
input sel5,
input sel4,
input sel3,
input sel2,
input sel1,
input sel0,
input [DW-1:0] in8,
input [DW-1:0] in7,
input [DW-1:0] in6,
input [DW-1:0] in5,
input [DW-1:0] in4,
input [DW-1:0] in3,
input [DW-1:0] in2,
input [DW-1:0] in1,
input [DW-1:0] in0,
output [DW-1:0] out //selected data output
);
//data inputs
input [DW-1:0] in0;
input [DW-1:0] in1;
input [DW-1:0] in2;
input [DW-1:0] in3;
input [DW-1:0] in4;
input [DW-1:0] in5;
input [DW-1:0] in6;
input [DW-1:0] in7;
input [DW-1:0] in8;
//select inputs
input sel0;
input sel1;
input sel2;
input sel3;
input sel4;
input sel5;
input sel6;
input sel7;
input sel8;
output [DW-1:0] out;
assign out[DW-1:0] = ({(DW){sel0}} & in0[DW-1:0] |
{(DW){sel1}} & in1[DW-1:0] |
{(DW){sel2}} & in2[DW-1:0] |
@ -42,7 +37,6 @@ module oh_mux9(/*AUTOARG*/
{(DW){sel6}} & in6[DW-1:0] |
{(DW){sel7}} & in7[DW-1:0] |
{(DW){sel8}} & in8[DW-1:0]);
endmodule // oh_mux9

View File

@ -2,11 +2,10 @@
//# Function: Dual data rate output buffer #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in this repository) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_oddr #(parameter DW = 1 // width of data inputs
)
module oh_oddr #(parameter DW = 1) // width of data inputs
(
input clk, // clock input
input [DW-1:0] din1, // data input1

View File

@ -2,58 +2,36 @@
//# Function: Parallel to Serial Converter #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE in OH! repositpory) #
//#############################################################################
module oh_par2ser (/*AUTOARG*/
// Outputs
dout, access_out, wait_out,
// Inputs
clk, nreset, din, load, shift, datasize, lsbfirst, fill, wait_in
);
module oh_par2ser #(parameter PW = 64, // parallel packet width
parameter SW = 1 // serial packet width
)
(
input clk, // sampling clock
input nreset, // async active low reset
input [PW-1:0] din, // parallel data
output [SW-1:0] dout, // serial output data
output access_out,// output data valid
input load, // load parallel data (priority)
input shift, // shift data
input [7:0] datasize, // size of data to shift
input lsbfirst, // lsb first order
input fill, // fill bit
input wait_in, // wait input
output wait_out // wait output (wait in | serial wait)
);
// parameters
localparam CW = $clog2(PW/SW); // serialization factor (for counter)
//###########################
//# INTERFACE
//###########################
// parameters
parameter PW = 64; // parallel packet width
parameter SW = 1; // serial packet width
localparam CW = $clog2(PW/SW); // serialization factor (for counter)
// reset, clk
input clk; // sampling clock
input nreset; // async active low reset
// data interface
input [PW-1:0] din; // parallel data
output [SW-1:0] dout; // serial output data
output access_out;// output data valid
// control interface
input load; // load parallel data (priority)
input shift; // shift data
input [7:0] datasize; // size of data to shift
input lsbfirst; // lsb first order
input fill; // fill bit
input wait_in; // wait input
output wait_out; // wait output (wait in | serial wait)
//###########################
//# BODY
//###########################
reg [PW-1:0] shiftreg;
reg [CW-1:0] count;
//##########################
//# STATE MACHINE
//##########################
assign start_transfer = load &
~wait_in &
~busy;
// start serialization
assign start_transfer = load & ~wait_in & ~busy;
//transfer counter
always @ (posedge clk or negedge nreset)
if(!nreset)
@ -70,13 +48,9 @@ module oh_par2ser (/*AUTOARG*/
assign access_out = busy;
//wait until valid data is finished
assign wait_out = wait_in |
busy;
//##########################
//# SHIFT REGISTER
//##########################
assign wait_out = wait_in | busy;
// shift register
always @ (posedge clk)
if(start_transfer)
shiftreg[PW-1:0] = din[PW-1:0];
@ -91,29 +65,6 @@ module oh_par2ser (/*AUTOARG*/
endmodule // oh_par2ser
///////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software") //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT //
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,17 +1,19 @@
module oh_parity (/*AUTOARG*/
// Outputs
out,
// Inputs
in
);
//#############################################################################
//# Function: Calculates parity value for #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH repository) #
//#############################################################################
parameter DW = 64; // width of converter
input [DW-1:0] in; // data input
output out; // calculated parity bit
assign parity = ^data[DW-1:0];
module oh_parity #( parameter DW = 2 // data width
)
(
input [DW-1:0] in, // data input
output out // calculated parity bit
);
assign parity = ^in[DW-1:0];
endmodule // oh_parity

View File

@ -1,32 +1,26 @@
module oh_pll (/*AUTOARG*/
// Outputs
clkout, locked,
// Inputs
clkin, nreset, clkfb, pll_en, clkdiv, clkphase, clkmult
);
//#############################################################################
//# Function: Phase Locked Loop #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter N = 16; // number of clock outputs
// inputs
input clkin; // primary clock input
input nreset; // async active low reset
input clkfb; // feedback clock
input pll_en; // enable pll
input [N*8-1:0] clkdiv; // clock divider settings (per clock)
input [N*16-1:0] clkphase; // clock phase setting (rise/fall edge)
input [7:0] clkmult; // feedback clock multiplier
// outputs
output [N-1:0] clkout; // output clocks
output locked; // PLL locked status
module oh_pll #(parameter N = 8) // number of clocks
( input clkin, // primary clock input
input nreset, // async active low reset
input clkfb, // feedback clock
input pll_en, // enable pll
input [N*8-1:0] clkdiv, // clock divider settings (per clock)
input [N*16-1:0] clkphase, // clock phase setting (rise/fall edge)
input [7:0] clkmult, // feedback clock multiplier
output [N-1:0] clkout, // output clocks
output locked // PLL locked status
);
`ifdef TARGET_SIM
//insert PLL simulation model
`endif
endmodule // oh_pll

View File

@ -1,27 +1,22 @@
// FUNCTION: Transfers a pulse on clkin domain to a pulse on clkout domain
// !!!WARNING: "din" pulse width must be greater than clkout width!!!
//#############################################################################
//# Function: Clock domain one cycle pulse transfer #
// !!"din" pulse width must be 2x greater than clkout width!!! #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_pulse2pulse(/*AUTOARG*/
// Outputs
dout,
// Inputs
nrstin, din, clkin, nrstout, clkout
);
//input clock domain
input nrstin; //input domain reset
input din; //input pulse (one clock cycle)
input clkin; //input clock
//output clock domain
input nrstout; //output domain reset
input clkout; //output clock
output dout; //output pulse (one clock cycle)
module oh_pulse2pulse (
input nrstin, //input domain reset
input din, //input pulse (one clock cycle)
input clkin, //input clock
input nrstout, //output domain reset
input clkout, //output clock
output dout //output pulse (one clock cycle)
);
reg toggle_reg;
reg pulse_reg;
wire toggle;
//pulse to toggle
assign toggle = din ? ~toggle_reg : toggle_reg;
@ -31,14 +26,12 @@ module oh_pulse2pulse(/*AUTOARG*/
toggle_reg <= 1'b0;
else
toggle_reg <= toggle;
//metastability synchronizer
oh_dsync #(1) sync(.dout (toggle_sync),
.din (toggle),
.clk (clkout)
);
.clk (clkout));
//toogle to pulse
always @ (posedge clkout)
if(!nrstout)

View File

@ -2,24 +2,17 @@
//# Function: Buffer that propagates "X" if power supply is invalid #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_pwr_buf (/*AUTOARG*/
// Outputs
out,
// Inputs
vdd, vss, in
);
parameter DW=1; // width of macro
input vdd; // supply (set to 1 if valid)
input vss; // ground (set to 0 if valid)
input [DW-1:0] in; // input signal
output [DW-1:0] out; // buffered output signal
module oh_pwr_buf #( parameter DW = 1) // width of data inputs
(
input vdd, // supply (set to 1 if valid)
input vss, // ground (set to 0 if valid)
input [DW-1:0] in, // input signal
output [DW-1:0] out // buffered output signal
);
`ifdef TARGET_SIM
assign out[DW-1:0] = ((vdd===1'b1) && (vss===1'b0)) ? in[DW-1:0]:
{(DW){1'bX}};
@ -30,29 +23,5 @@ module oh_pwr_buf (/*AUTOARG*/
endmodule // oh_buf
endmodule // oh_pwr_buf
///////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software") //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT //
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,13 +1,14 @@
module oh_pwr_gate (/*AUTOARG*/
// Outputs
vddg,
// Inputs
npower, vdd
);
//#############################################################################
//# Function: Power supply header switch #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
input npower; // active low power on
input vdd; // input supply
output vddg; // gated supply
module oh_pwr_gate (input npower, // active low power on
input vdd, // input supply
output vddg // gated output supply
);
`ifdef TARGET_SIM
assign vddg = ((vdd===1'b1) && (npower===1'b0)) ? 1'b1 : 1'bX;

View File

@ -2,24 +2,18 @@
//# Function: Isolation buffer for multi supply domains #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_pwr_isolate (/*AUTOARG*/
// Outputs
out,
// Inputs
vdd, vss, niso, in
);
parameter DW=1; // width of macro
input vdd; // supply (set to 1 if valid)
input vss; // ground (set to 0 if valid)
input niso; // active low isolation signal
input [DW-1:0] in; // input signal
output [DW-1:0] out; // buffered output signal
module oh_pwr_isolate #(parameter DW = 1) // width of data inputs
(
input vdd, // supply (set to 1 if valid)
input vss, // ground (set to 0 if valid)
input niso, // active low isolation signal
input [DW-1:0] in, // input signal
output [DW-1:0] out // buffered output signal
);
`ifdef TARGET_SIM
assign out[DW-1:0] = ((vdd===1'b1) && (vss===1'b0)) ? ({(DW){niso}} & in[DW-1:0]):
{(DW){1'bX}};
@ -28,28 +22,3 @@ module oh_pwr_isolate (/*AUTOARG*/
`endif
endmodule // oh_buf
///////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software") //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT //
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
///////////////////////////////////////////////////////////////////////////////

View File

@ -2,30 +2,17 @@
//# Function: Converts a rising edge to a single cycle pulse #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_rise2pulse(/*AUTOARG*/
// Outputs
out,
// Inputs
clk, nreset, in
);
//########################################
//# INTERFACE
//########################################
parameter DW = 1; // width of data inputs
input clk; // clock
input nreset; // async active low reset
input [DW-1:0] in; // edge input
output [DW-1:0] out; // one cycle pulse
//########################################
//# BODY
//########################################
module oh_rise2pulse #(parameter DW = 1) // data width
( input clk, // clock
input nreset, // async active low reset
input [DW-1:0] in, // edge input
output [DW-1:0] out // one cycle pulse
);
reg [DW-1:0] in_reg;
always @ (posedge clk or negedge nreset)
@ -36,29 +23,5 @@ module oh_rise2pulse(/*AUTOARG*/
assign out[DW-1:0] = in[DW-1:0] & ~in_reg[DW-1:0] ;
endmodule // oh_edge2pulse
endmodule // oh_rise2pulse
//////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software")//
// to deal in the Software without restriction, including without limitation//
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT//
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
//////////////////////////////////////////////////////////////////////////////

View File

@ -2,40 +2,22 @@
//# Purpose: Serial to Parallel Converter #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see below) #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_ser2par (/*AUTOARG*/
// Outputs
dout,
// Inputs
clk, din, lsbfirst, shift
);
//###########################
//# INTERFACE
//###########################
// parameters
parameter PW = 64; // parallel packet width
parameter SW = 1; // serial packet width
module oh_ser2par #(parameter PW = 64, // parallel packet width
parameter SW = 1 // serial packet width
)
(
input clk, // sampling clock
input [SW-1:0] din, // serial data
output [PW-1:0] dout, // parallel data
input lsbfirst, // lsb first order
input shift // shift the shifter
);
localparam CW = $clog2(PW/SW); // serialization factor (for counter)
// reset, clk
input clk; // sampling clock
//data interface
input [SW-1:0] din; // serial data
output [PW-1:0] dout; // parallel data
// control interface
input lsbfirst; // lsb first order
input shift; // shift the shifter
//##############################
//# BODY
//##############################
reg [PW-1:0] dout;
reg [CW-1:0] count;
wire [PW-1:0] shiftdata;
@ -47,29 +29,3 @@ module oh_ser2par (/*AUTOARG*/
dout[PW-1:0] <= {dout[PW-SW-1:0],din[SW-1:0]};
endmodule // oh_ser2par
///////////////////////////////////////////////////////////////////////////////
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016, Adapteva, Inc. //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software") //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included //
// in all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF //
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. //
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY //
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT //
// OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
// //
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,28 +1,19 @@
module oh_shifter (/*AUTOARG*/
// Outputs
out, zero,
// Inputs
a, b
);
//#############################################################################
//# Function: Barrel shifter #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
//###############################################################
//# Parameters
//###############################################################
parameter DW = 64;
parameter TYPE = "LSL"; //shift type
//LSL, LSR, or ASR
//###############################################################
//# Interface
//###############################################################
//inputs
input [DW-1:0] a; //first operand
input [DW-1:0] b; //shift amount
//outputs
output [DW-1:0] out;
output zero; //set if all output bits are zero
//TODO: catch shift out?
module oh_shifter #(parameter DW = 1, // data width
parameter TYPE = "LSL"// LSR, SR, LSL
)
(
input [DW-1:0] in, //first operand
input [DW-1:0] shift,//shift amount
output [DW-1:0] out, // shifted data out
output zero //set if all output bits are zero
);
endmodule // oh_shifter

View File

@ -1,28 +1,26 @@
module oh_standby (/*AUTOARG*/
// Outputs
clk_out,
// Inputs
clk, nreset, wakeup, idle
);
//#############################################################################
//# Purpose: Low power standby state machine #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter PD = 5; //cycles to stay awake after "wakeup"
//Basic Interface
input clk; //clock input
input nreset; //sync reset
input wakeup; //wake up now!
input idle; //core is in idle
output clk_out; //clock output
module oh_standby #( parameter PD = 5) //cycles to stay awake after "wakeup"
(
input clkin, //clock input
input nreset, //sync reset
input wakeup, //wake up now!
input idle, //core is in idle
output clkout //clock output
);
//Wire declarations
reg [PD-1:0] wakeup_pipe;
reg idle_reg;
wire state_change;
wire clk_en;
// detect an idle state change (wake up on any)
always @ (posedge clk )
idle_reg <= idle;
idle_reg <= idle;
assign state_change = (idle ^ idle_reg);
always @ (posedge clk)
@ -36,13 +34,13 @@ module oh_standby (/*AUTOARG*/
~idle; //core not in idle
//clock gater (technology specific)
oh_clockgate clockgate (.eclk(clk_out),
oh_clockgate clockgate (.eclk(clkout),
.clk(clk),
.en(clk_en),
.nrst(nreset),
.se(1'b0)
);
.se(1'b0));
endmodule // standby
endmodule // oh_standby

View File

@ -1,31 +1,22 @@
/*
* This module stretches a pulse by DW+1 clock cycles
* Can be useful for synchronous clock transfers from fast to slow.
* The block has one cycle latency
*
* in
* clk
* out
*
*/
module oh_stretcher (/*AUTOARG*/
// Outputs
out,
// Inputs
clk, in, nrst
);
//#############################################################################
//# Purpose: Stretches a pulse by DW+1 clock cycles #
//# Adds one cycle latency #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
parameter CYCLES = 4;
module oh_stretcher #(parameter CYCLES = 5) // "wakeup" cycles
( input clk, // clock
input in, // input pulse
input nreset, // async active low reset
output out // stretched output pulse
);
input clk;
input in;
input nrst;
output out;
reg [CYCLES-1:0] valid;
always @ (posedge clk)
if(!nrst)
always @ (posedge clk or negedge nreset)
if(!nreset)
valid[CYCLES-1:0] <='b0;
else if(in)
valid[CYCLES-1:0] <={(CYCLES){1'b1}};