You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 Mikolaj Wielgus
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * https://www.gnu.org/licenses/gpl-3.0.html
  20. * or you may search the http://www.gnu.org website for the version 3 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef SIM_MODEL_SOURCE_H
  25. #define SIM_MODEL_SOURCE_H
  26. #include <sim/sim_model.h>
  27. #include <sim/sim_model_serializer.h>
  28. #include <sim/spice_generator.h>
  29. namespace SIM_MODEL_SOURCE_GRAMMAR
  30. {
  31. using namespace SIM_MODEL_SERIALIZER_GRAMMAR;
  32. struct pwlSep : plus<space> {};
  33. struct pwlValues : seq<opt<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>,
  34. star<pwlSep,
  35. number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>> {};
  36. struct pwlValuesGrammar : must<opt<sep>,
  37. pwlValues,
  38. opt<sep>,
  39. tao::pegtl::eof> {};
  40. }
  41. class SPICE_GENERATOR_SOURCE : public SPICE_GENERATOR
  42. {
  43. public:
  44. using SPICE_GENERATOR::SPICE_GENERATOR;
  45. std::string ModelLine( const SPICE_ITEM& aItem ) const override;
  46. std::string ItemLine( const SPICE_ITEM& aItem ) const override;
  47. std::string TunerCommand( const SPICE_ITEM& aItem, double aValue ) const override;
  48. private:
  49. std::string getParamValueString( const std::string& aParamName,
  50. const std::string& aDefaultValue ) const;
  51. };
  52. class SIM_MODEL_SOURCE_SERIALIZER : public SIM_MODEL_SERIALIZER
  53. {
  54. public:
  55. using SIM_MODEL_SERIALIZER::SIM_MODEL_SERIALIZER;
  56. };
  57. class SIM_MODEL_SOURCE : public SIM_MODEL
  58. {
  59. public:
  60. SIM_MODEL_SOURCE( TYPE aType );
  61. bool HasAutofill() const override { return true; }
  62. bool HasPrimaryValue() const override { return GetType() == TYPE::V || GetType() == TYPE::I; }
  63. std::vector<std::string> GetPinNames() const override;
  64. const PARAM* GetTunerParam() const override;
  65. protected:
  66. void doSetParamValue( int aParamIndex, const std::string& aValue ) override;
  67. private:
  68. static const std::vector<PARAM::INFO>& makeParamInfos( TYPE aType );
  69. static std::vector<PARAM::INFO> makeDcParamInfos( const std::string& aPrefix,
  70. const std::string& aUnit );
  71. static std::vector<PARAM::INFO> makeSinParamInfos( const std::string& aPrefix,
  72. const std::string& aUnit );
  73. static std::vector<PARAM::INFO> makePulseParamInfos( const std::string& aPrefix,
  74. const std::string& aUnit );
  75. static std::vector<PARAM::INFO> makeExpParamInfos( const std::string& aPrefix,
  76. const std::string& aUnit );
  77. static std::vector<PARAM::INFO> makeAMParamInfos( const std::string& aPrefix,
  78. const std::string& aUnit );
  79. static std::vector<PARAM::INFO> makeSFFMParamInfos( const std::string& aPrefix,
  80. const std::string& aUnit );
  81. static std::vector<SIM_MODEL::PARAM::INFO> makeVcParamInfos( const std::string& aGainUnit );
  82. static std::vector<SIM_MODEL::PARAM::INFO> makeCcParamInfos( const std::string& aGainUnit );
  83. static std::vector<PARAM::INFO> makePwlParamInfos( const std::string& aPrefix,
  84. const std::string& aQuantity,
  85. const std::string& aUnit );
  86. static std::vector<PARAM::INFO> makeWhiteNoiseParamInfos( const std::string& aPrefix,
  87. const std::string& aUnit );
  88. static std::vector<PARAM::INFO> makePinkNoiseParamInfos( const std::string& aPrefix,
  89. const std::string& aUnit );
  90. static std::vector<PARAM::INFO> makeBurstNoiseParamInfos( const std::string& aPrefix,
  91. const std::string& aUnit );
  92. static std::vector<PARAM::INFO> makeRandomUniformParamInfos( const std::string& aPrefix,
  93. const std::string& aUnit );
  94. static std::vector<PARAM::INFO> makeRandomNormalParamInfos( const std::string& aPrefix,
  95. const std::string& aUnit );
  96. static std::vector<PARAM::INFO> makeRandomExpParamInfos( const std::string& aPrefix,
  97. const std::string& aUnit );
  98. static std::vector<PARAM::INFO> makeRandomPoissonParamInfos( const std::string& aPrefix,
  99. const std::string& aUnit );
  100. static void appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, const std::string& aUnit );
  101. static void appendSpParamInfos( std::vector<PARAM::INFO>& aParamInfos, const std::string& aUnit );
  102. };
  103. #endif // SIM_MODEL_SOURCE_H