X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=techlibs%2Fgreenpak4%2Fcells_sim_digital.v;h=43d35d08f33c4c3c66ee49e585c756139de0bdf4;hb=ff785cdb46d6b1ddc19d5acc21b4d1236b3adf3f;hp=250f1da6a0677b82d8146003900e58040bb5cf8e;hpb=3618ca22181715cd24f6dca5911019d406f562e7;p=yosys.git diff --git a/techlibs/greenpak4/cells_sim_digital.v b/techlibs/greenpak4/cells_sim_digital.v index 250f1da6a..43d35d08f 100644 --- a/techlibs/greenpak4/cells_sim_digital.v +++ b/techlibs/greenpak4/cells_sim_digital.v @@ -57,40 +57,52 @@ module GP_COUNT14(input CLK, input wire RST, output reg OUT); case(RESET_MODE) "RISING": begin - always @(posedge CLK or posedge RST) begin - count <= count - 1'd1; - if(count == 0) - count <= COUNT_TO; - + always @(posedge CLK, posedge RST) begin if(RST) - count <= 0; + count <= 0; + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end end end "FALLING": begin - always @(posedge CLK or negedge RST) begin - count <= count - 1'd1; - if(count == 0) - count <= COUNT_TO; - + always @(posedge CLK, negedge RST) begin if(!RST) - count <= 0; + count <= 0; + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end end end "BOTH": begin initial begin - $display("Both-edge reset mode for GP_COUNT8 not implemented"); + $display("Both-edge reset mode for GP_COUNT14 not implemented"); $finish; end end "LEVEL": begin + always @(posedge CLK, posedge RST) begin + if(RST) + count <= 0; + + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end + end end default: begin initial begin - $display("Invalid RESET_MODE on GP_COUNT8"); + $display("Invalid RESET_MODE on GP_COUNT14"); $finish; end end @@ -116,6 +128,8 @@ module GP_COUNT14_ADV(input CLK, input RST, output reg OUT, end end + reg[13:0] count = COUNT_TO; + //Combinatorially output underflow flag whenever we wrap low always @(*) begin if(UP) @@ -131,21 +145,7 @@ module GP_COUNT14_ADV(input CLK, input RST, output reg OUT, case(RESET_MODE) "RISING": begin - always @(posedge CLK or posedge RST) begin - - //Main counter - if(KEEP) begin - end - else if(UP) - count <= count + 1'd1; - else - count <= count - 1'd1; - - //Wrapping - if(count == 0 && !UP) - count <= COUNT_TO; - if(count == 14'h3fff && UP) - count <= COUNT_TO; + always @(posedge CLK, posedge RST) begin //Resets if(RST) begin @@ -155,34 +155,48 @@ module GP_COUNT14_ADV(input CLK, input RST, output reg OUT, count <= COUNT_TO; end - end - end - - "FALLING": begin - always @(posedge CLK or negedge RST) begin - - //Main counter - if(KEEP) begin + else if(KEEP) begin end - else if(UP) + else if(UP) begin count <= count + 1'd1; - else + if(count == 14'h3fff) + count <= COUNT_TO; + end + else begin count <= count - 1'd1; - //Wrapping - if(count == 0 && !UP) - count <= COUNT_TO; - if(count == 14'h3fff && UP) - count <= COUNT_TO; + if(count == 0) + count <= COUNT_TO; + end + + end + end + + "FALLING": begin + always @(posedge CLK, negedge RST) begin //Resets - if(RST) begin + if(!RST) begin if(RESET_VALUE == "ZERO") count <= 0; else count <= COUNT_TO; end + else if(KEEP) begin + end + else if(UP) begin + count <= count + 1'd1; + if(count == 14'h3fff) + count <= COUNT_TO; + end + else begin + count <= count - 1'd1; + + if(count == 0) + count <= COUNT_TO; + end + end end @@ -194,6 +208,35 @@ module GP_COUNT14_ADV(input CLK, input RST, output reg OUT, end "LEVEL": begin + always @(posedge CLK, posedge RST) begin + + //Resets + if(RST) begin + if(RESET_VALUE == "ZERO") + count <= 0; + else + count <= COUNT_TO; + end + + else begin + + if(KEEP) begin + end + else if(UP) begin + count <= count + 1'd1; + if(count == 14'h3fff) + count <= COUNT_TO; + end + else begin + count <= count - 1'd1; + + if(count == 0) + count <= COUNT_TO; + end + + end + + end end default: begin @@ -217,6 +260,8 @@ module GP_COUNT8_ADV(input CLK, input RST, output reg OUT, parameter COUNT_TO = 8'h1; parameter CLKIN_DIVIDE = 1; + reg[7:0] count = COUNT_TO; + initial begin if(CLKIN_DIVIDE != 1) begin $display("ERROR: CLKIN_DIVIDE values other than 1 not implemented"); @@ -239,21 +284,7 @@ module GP_COUNT8_ADV(input CLK, input RST, output reg OUT, case(RESET_MODE) "RISING": begin - always @(posedge CLK or posedge RST) begin - - //Main counter - if(KEEP) begin - end - else if(UP) - count <= count + 1'd1; - else - count <= count - 1'd1; - - //Wrapping - if(count == 0 && !UP) - count <= COUNT_TO; - if(count == 8'hff && UP) - count <= COUNT_TO; + always @(posedge CLK, posedge RST) begin //Resets if(RST) begin @@ -263,34 +294,50 @@ module GP_COUNT8_ADV(input CLK, input RST, output reg OUT, count <= COUNT_TO; end - end - end - - "FALLING": begin - always @(posedge CLK or negedge RST) begin - //Main counter - if(KEEP) begin + else if(KEEP) begin end - else if(UP) + else if(UP) begin count <= count + 1'd1; - else + if(count == 8'hff) + count <= COUNT_TO; + end + else begin count <= count - 1'd1; - //Wrapping - if(count == 0 && !UP) - count <= COUNT_TO; - if(count == 8'hff && UP) - count <= COUNT_TO; + if(count == 0) + count <= COUNT_TO; + end + + end + end + + "FALLING": begin + always @(posedge CLK, negedge RST) begin //Resets - if(RST) begin + if(!RST) begin if(RESET_VALUE == "ZERO") count <= 0; else count <= COUNT_TO; end + //Main counter + else if(KEEP) begin + end + else if(UP) begin + count <= count + 1'd1; + if(count == 8'hff) + count <= COUNT_TO; + end + else begin + count <= count - 1'd1; + + if(count == 0) + count <= COUNT_TO; + end + end end @@ -302,6 +349,34 @@ module GP_COUNT8_ADV(input CLK, input RST, output reg OUT, end "LEVEL": begin + always @(posedge CLK, posedge RST) begin + + //Resets + if(RST) begin + if(RESET_VALUE == "ZERO") + count <= 0; + else + count <= COUNT_TO; + end + + else begin + + if(KEEP) begin + end + else if(UP) begin + count <= count + 1'd1; + if(count == 8'hff) + count <= COUNT_TO; + end + else begin + count <= count - 1'd1; + + if(count == 0) + count <= COUNT_TO; + end + end + + end end default: begin @@ -339,7 +414,7 @@ module GP_COUNT8( //Combinatorially output underflow flag whenever we wrap low always @(*) begin OUT <= (count == 8'h0); - OUT <= count; + POUT <= count; end //POR or SYSRST reset value is COUNT_TO. Datasheet is unclear but conversations w/ Silego confirm. @@ -348,24 +423,26 @@ module GP_COUNT8( case(RESET_MODE) "RISING": begin - always @(posedge CLK or posedge RST) begin - count <= count - 1'd1; - if(count == 0) - count <= COUNT_TO; - + always @(posedge CLK, posedge RST) begin if(RST) count <= 0; + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end end end "FALLING": begin - always @(posedge CLK or negedge RST) begin - count <= count - 1'd1; - if(count == 0) - count <= COUNT_TO; - + always @(posedge CLK, negedge RST) begin if(!RST) count <= 0; + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end end end @@ -377,6 +454,16 @@ module GP_COUNT8( end "LEVEL": begin + always @(posedge CLK, posedge RST) begin + if(RST) + count <= 0; + + else begin + count <= count - 1'd1; + if(count == 0) + count <= COUNT_TO; + end + end end default: begin @@ -655,20 +742,24 @@ module GP_PGEN(input wire nRST, input wire CLK, output reg OUT); parameter PATTERN_DATA = 16'h0; parameter PATTERN_LEN = 5'd16; + localparam COUNT_MAX = PATTERN_LEN - 1'h1; + reg[3:0] count = 0; - always @(posedge CLK) begin + always @(posedge CLK, negedge nRST) begin + if(!nRST) - OUT <= PATTERN_DATA[0]; + count <= 0; else begin - count <= count + 1; - OUT <= PATTERN_DATA[count]; - - if( (count + 1) == PATTERN_LEN) - count <= 0; + count <= count - 1'h1; + if(count == 0) + count <= COUNT_MAX; end end + always @(*) + OUT = PATTERN_DATA[count]; + endmodule module GP_SHREG(input nRST, input CLK, input IN, output OUTA, output OUTB);