Added simulation models for Efinix and Anlogic
authorMiodrag Milanovic <mmicko@gmail.com>
Sun, 15 Sep 2019 07:37:16 +0000 (09:37 +0200)
committerMiodrag Milanovic <mmicko@gmail.com>
Sun, 15 Sep 2019 07:37:16 +0000 (09:37 +0200)
techlibs/anlogic/cells_sim.v
techlibs/efinix/cells_sim.v

index 058e766050e3b671558b3e12a2e819d22f92297c..652de3b26eaf5982dc063e6075c3bfa523597870 100644 (file)
@@ -1,5 +1,5 @@
 module AL_MAP_SEQ (
-       output q,
+       output reg q,
        input ce,
        input clk,
        input sr,
@@ -9,6 +9,70 @@ module AL_MAP_SEQ (
        parameter REGSET = "RESET"; //RESET/SET
        parameter SRMUX = "SR"; //SR/INV
        parameter SRMODE = "SYNC"; //SYNC/ASYNC
+
+       wire clk_ce;
+       assign clk_ce = ce ? clk : 1'b0;
+
+       wire srmux;
+       generate
+               case (SRMUX)
+                       "SR": assign srmux = sr;
+                       "INV": assign srmux = ~sr;
+                       default: assign srmux = sr;
+               endcase
+       endgenerate     
+
+       wire regset;
+       generate
+               case (REGSET)
+                       "RESET": assign regset = 1'b0;
+                       "SET": assign regset = 1'b1;
+                       default: assign regset = 1'b0;
+               endcase
+       endgenerate
+
+       initial q = regset;
+
+       generate
+               if (DFFMODE == "FF") 
+               begin
+                       if (SRMODE == "ASYNC") 
+                       begin
+                               always @(posedge clk_ce, posedge srmux)
+                                       if (srmux)
+                                               q <= regset;
+                                       else 
+                                               q <= d; 
+                       end 
+                       else
+                       begin
+                               always @(posedge clk_ce)
+                                       if (srmux)
+                                               q <= regset;
+                                       else 
+                                               q <= d; 
+                       end
+               end
+               else
+               begin
+                       if (SRMODE == "ASYNC") 
+                       begin
+                               always @(clk_ce, srmux)
+                                       if (srmux)
+                                               q <= regset;
+                                       else 
+                                               q <= d; 
+                       end 
+                       else
+                       begin
+                               always @(clk_ce)
+                                       if (srmux)
+                                               q <= regset;
+                                       else 
+                                               q <= d; 
+                       end
+               end
+    endgenerate
 endmodule
 
 module AL_MAP_LUT1 (
@@ -100,4 +164,18 @@ module AL_MAP_ADDER (
   output [1:0] o
 );
        parameter ALUTYPE = "ADD";
+
+       generate
+               case (ALUTYPE)
+                       "ADD":           assign o = a + b + c;
+                       "SUB":           assign o = a - b - c;
+                       "A_LE_B":    assign o = a - b - c;
+
+                       "ADD_CARRY":    assign o = {  a, 1'b0 };
+                       "SUB_CARRY":    assign o = { ~a, 1'b0 };
+                       "A_LE_B_CARRY": assign o = {  a, 1'b0 };
+                       default: assign o = a + b + c;
+               endcase
+       endgenerate     
+
 endmodule
index 8c8f6afaa3e91c77cc5c32f14c1c1888a2452682..a41ff1a35e648139f4ac19d73b10453612d0781b 100644 (file)
@@ -6,6 +6,7 @@ module EFX_LUT4(
    input I3
 );
    parameter LUTMASK  = 16'h0000;
+       assign O = LUTMASK >> {I3, I2, I1, I0};   
 endmodule
 
 module EFX_ADD(
@@ -17,10 +18,18 @@ module EFX_ADD(
 );
    parameter I0_POLARITY   = 1;
    parameter I1_POLARITY   = 1;
+
+   wire i0;
+   wire i1;
+
+   assign i0 = I0_POLARITY ? I0 : ~I0;
+   assign i1 = I1_POLARITY ? I1 : ~I1;
+
+   assign {CO, O} = i0 + i1 + CI;
 endmodule
 
 module EFX_FF(
-   output Q,
+   output reg Q,
    input D,
    input CE,
    input CLK,
@@ -33,6 +42,51 @@ module EFX_FF(
    parameter SR_VALUE = 0;
    parameter SR_SYNC_PRIORITY = 0;
    parameter D_POLARITY = 1;
+
+   wire clk;
+   wire ce;
+   wire sr;
+   wire d;
+   wire prio;
+   wire sync;
+   wire async;
+
+   assign clk = CLK_POLARITY ? CLK : ~CLK;
+   assign ce = CE_POLARITY ? CE : ~CE;
+   assign sr = SR_POLARITY ? SR : ~SR;
+   assign d = D_POLARITY ? D : ~D;
+  
+   generate
+       if (SR_SYNC == 1) 
+      begin
+         if (SR_SYNC_PRIORITY == 1) 
+         begin
+            always @(posedge clk)
+               if (sr)
+                  Q <= SR_VALUE;
+               else if (ce)
+                  Q <= d;
+         end
+         else
+         begin
+            always @(posedge clk)
+               if (ce)
+                  if (sr)
+                     Q <= SR_VALUE;
+                  else
+                     Q <= d;            
+         end
+      end
+      else
+      begin
+         always @(posedge clk or posedge sr)
+            if (sr)
+               Q <= SR_VALUE;
+            else if (ce)
+               Q <= d;
+         
+      end
+   endgenerate
 endmodule
 
 module EFX_GBUFCE(
@@ -41,6 +95,12 @@ module EFX_GBUFCE(
    output O
 );
    parameter CE_POLARITY = 1'b1;
+
+   wire ce;
+   assign ce = CE_POLARITY ? CE : ~CE;
+   
+   assign O = I & ce;
+   
 endmodule
 
 module EFX_RAM_5K(
@@ -104,4 +164,4 @@ module EFX_RAM_5K(
                            (WRITE_WIDTH == 10) ? 9 :  // 512x10
                            (WRITE_WIDTH == 5)  ? 10 : -1; // 1024x5
    
-endmodule
\ No newline at end of file
+endmodule