Added support for inferring counters with reset to full scale instead of zero
authorAndrew Zonenberg <azonenberg@drawersteak.com>
Wed, 13 Sep 2017 22:57:17 +0000 (15:57 -0700)
committerAndrew Zonenberg <azonenberg@drawersteak.com>
Thu, 14 Sep 2017 17:26:43 +0000 (10:26 -0700)
passes/techmap/extract_counter.cc

index 1e20b1fd8dcbfcba2084ab880c021d2d81a37b1a..27fc558ad5ee7801e89a302b139ef51ee6e52a19 100644 (file)
@@ -95,6 +95,7 @@ struct CounterExtraction
        bool has_ce;                                    //true if we have a clock enable
        RTLIL::SigSpec rst;                             //reset pin
        bool rst_inverted;                              //true if reset is active low
+       bool rst_to_max;                                //true if we reset to max instead of 0
        int count_value;                                //value we count from
        RTLIL::SigSpec ce;                              //clock signal
        RTLIL::SigSpec clk;                             //clock enable, if any
@@ -237,10 +238,16 @@ int counter_tryextract(
        {
                extract.has_reset = true;
 
-               //Verify ARST_VALUE is zero.
-               //Detect polarity inversions on reset.
+               //Check polarity of reset - we may have to add an inverter later on!
                extract.rst_inverted = (count_reg->getParam("\\ARST_POLARITY").as_int() != 1);
-               if(count_reg->getParam("\\ARST_VALUE").as_int() != 0)
+
+               //Verify ARST_VALUE is zero or full scale
+               int rst_value = count_reg->getParam("\\ARST_VALUE").as_int();
+               if(rst_value == 0)
+                       extract.rst_to_max = false;
+               else if(rst_value == extract.count_value)
+                       extract.rst_to_max = true;
+               else
                        return 23;
 
                //Save the reset
@@ -419,7 +426,7 @@ void counter_worker(
                        "No init value found",                                                  //20
                        "Underflow value is not equal to init value",   //21
                        "RESERVED, not implemented",                                    //22, kept for compatibility but not used anymore
-                       "Reset is not to zero",                                                 //23
+                       "Reset is not to zero or COUNT_TO",                             //23
                        "Clock enable configuration is unsupported"             //24
                };