移植过来

This commit is contained in:
sunbeam 2025-02-03 20:43:43 +08:00
commit aa4759ecc7
575 changed files with 280936 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
Debug
Debug_FLASH

2
CAN_Bootloader/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/dist
/.build

8
CAN_Bootloader/.idea/CAN_Bootloader.iml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

588
CAN_Bootloader/.idea/editor.xml generated Normal file
View File

@ -0,0 +1,588 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Windows_0020Form_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Windows Form Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Windows_0020Form_0020Designer_0020generated_0020code/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Component_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Component Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Component_0020Designer_0020generated_0020code/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Designer_0020generated_0020code/@EntryIndexedValue" value="Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Designer_0020generated_0020code/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Web_0020Form_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Web Form Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Web_0020Form_0020Designer_0020generated_0020code/@EntryIndexRemoved" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexRemoved" />
</component>
</project>

8
CAN_Bootloader/.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/CAN_Bootloader.iml" filepath="$PROJECT_DIR$/.idea/CAN_Bootloader.iml" />
</modules>
</component>
</project>

54
CAN_Bootloader/.idea/workspace.xml generated Normal file
View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorMiscSettings">
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
</component>
<component name="ChangeListManager">
<list default="true" id="6b4e0663-4a4a-4571-8c57-c6d192949937" name="更改" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 6
}]]></component>
<component name="ProjectId" id="2sQu2UhJzJYEIDdo49xNLKQCN3t" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.RadMigrateCodeStyle": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"RunOnceActivity.readMode.enableVisualFormatting": "true",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="默认任务">
<changelist id="6b4e0663-4a4a-4571-8c57-c6d192949937" name="更改" comment="" />
<created>1738399915338</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1738399915338</updated>
<workItem from="1738399916765" duration="563000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

BIN
CAN_Bootloader/DM_RP_SA.dll Normal file

Binary file not shown.

BIN
CAN_Bootloader/USB2XXX.dll Normal file

Binary file not shown.

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<project ver="10" name="RP-77B_CAN_Bootloader" libEmbed="true" icon="..." ui="win" output="RP-77B_CAN_Bootloader.exe" CompanyName="单位名称" FileDescription="CAN_Bootloader" LegalCopyright="Copyright (C) 作者 2022" ProductName="CAN_Bootloader" InternalName="CAN_Bootloader" FileVersion="0.0.0.10" ProductVersion="0.0.0.10" publishDir="/dist/" dstrip="false" local="false" ignored="false">
<file name="main.aardio" path="main.aardio" comment="main.aardio"/>
<folder name="资源文件" path="res" embed="true" local="false" ignored="false"/>
<folder name="窗体文件" path="dlg" comment="目录" embed="true" local="false" ignored="false">
<file name="诊断子窗口.aardio" path="dlg\诊断子窗口.aardio" comment="dlg\诊断子窗口.aardio"/>
</folder>
<folder name="user" path="user" embed="true" comment="目录" local="false" ignored="false">
<file name="CanThread.aardio" path="user\CanThread.aardio" comment="user\CanThread.aardio"/>
<file name="Diag10code.aardio" path="user\Diag10code.aardio" comment="user\Diag10code.aardio"/>
<file name="Diag11code.aardio" path="user\Diag11code.aardio" comment="user\Diag11code.aardio"/>
<file name="Diag22code.aardio" path="user\Diag22code.aardio" comment="user\Diag22code.aardio"/>
<file name="Diag27code.aardio" path="user\Diag27code.aardio" comment="user\Diag27code.aardio"/>
<file name="Diag28code.aardio" path="user\Diag28code.aardio" comment="user\Diag28code.aardio"/>
<file name="Diag2Ecode.aardio" path="user\Diag2Ecode.aardio" comment="user\Diag2Ecode.aardio"/>
<file name="Diag31code.aardio" path="user\Diag31code.aardio" comment="user\Diag31code.aardio"/>
<file name="Diag34code.aardio" path="user\Diag34code.aardio" comment="user\Diag34code.aardio"/>
<file name="Diag36code.aardio" path="user\Diag36code.aardio" comment="user\Diag36code.aardio"/>
<file name="Diag37code.aardio" path="user\Diag37code.aardio" comment="user\Diag37code.aardio"/>
<file name="Diag7Fcode.aardio" path="user\Diag7Fcode.aardio" comment="user\Diag7Fcode.aardio"/>
<file name="Diag85code.aardio" path="user\Diag85code.aardio" comment="user\Diag85code.aardio"/>
<file name="DiagBootcode.aardio" path="user\DiagBootcode.aardio" comment="user\DiagBootcode.aardio"/>
<file name="GeelySecurety.aardio" path="user\GeelySecurety.aardio" comment="user\GeelySecurety.aardio"/>
<file name="S19Decode.aardio" path="user\S19Decode.aardio" comment="user\S19Decode.aardio"/>
</folder>
</project>

View File

@ -0,0 +1,87 @@
import win.ui;
/*DSG{{*/
var winform = win.form(text="诊断读取";right=679;bottom=499;border="thin";max=false;mode="popup")
winform.add(
btnDID_F010={cls="button";text="F010";left=178;top=162;right=305;bottom=193;z=11};
btnDID_F010w={cls="button";text="写F010";left=336;top=296;right=463;bottom=327;z=16};
btnDID_F101={cls="button";text="F101";left=178;top=203;right=305;bottom=234;z=10};
btnDID_F101w={cls="button";text="写F101";left=338;top=335;right=458;bottom=366;z=15};
btnDID_F159={cls="button";text="F159";left=36;top=162;right=163;bottom=193;z=5};
btnDID_F15A={cls="button";text="F15A";left=36;top=203;right=163;bottom=234;z=6};
btnDID_F180={cls="button";text="F180";left=178;top=40;right=305;bottom=71;z=7};
btnDID_F187={cls="button";text="零部件编号";left=36;top=40;right=163;bottom=71;z=2};
btnDID_F18A={cls="button";text="供应商名称";left=36;top=80;right=163;bottom=111;z=3};
btnDID_F18C={cls="button";text="F18C";left=178;top=80;right=305;bottom=111;z=8};
btnDID_F190={cls="button";text="F190 VIN";left=178;top=121;right=305;bottom=152;z=9};
btnDID_F197={cls="button";text="ECU 系统名称";left=36;top=121;right=163;bottom=152;z=4};
btn_1003={cls="button";text="扩展会话";left=22;top=296;right=126;bottom=323;z=14};
btn_2701={cls="button";text="解锁";left=158;top=296;right=262;bottom=323;z=13};
groupbox={cls="groupbox";text="DID";left=16;top=12;right=328;bottom=260;edge=1;z=1};
groupbox2={cls="groupbox";text="DTC";left=343;top=12;right=655;bottom=260;edge=1;z=12}
)
/*}}*/
winform.btnDID_F180.oncommand = function(id,event){
DiagReadDID(0xF180);
}
winform.btnDID_F18A.oncommand = function(id,event){
DiagReadDID(0xF18A);
}
winform.btnDID_F197.oncommand = function(id,event){
DiagReadDID(0xF197);
}
winform.btnDID_F159.oncommand = function(id,event){
DiagReadDID(0xF159);
}
winform.btnDID_F15A.oncommand = function(id,event){
DiagReadDID(0xF15A);
}
winform.btnDID_F18C.oncommand = function(id,event){
DiagReadDID(0xF18C);
}
winform.btnDID_F190.oncommand = function(id,event){
DiagReadDID(0xF190);
}
winform.btnDID_F010.oncommand = function(id,event){
DiagReadDID(0xF010);
}
winform.btnDID_F101.oncommand = function(id,event){
DiagReadDID(0xF101);
}
winform.onClose = function(hwnd,message,wParam,lParam){
winform.show(false);
return 0;
}
winform.btn_2701.oncommand = function(id,event){
::PostThreadMessage(thrdId,114,0x01,0)//自定义消息
}
winform.btn_1003.oncommand = function(id,event){
::PostThreadMessage(thrdId,111,0x00,0x03)//自定义消息
}
winform.btnDID_F187.oncommand = function(id,event){
DiagReadDID(0xF187);
}
winform.btnDID_F010w.oncommand = function(id,event){
::PostThreadMessage(thrdId,115,0xF010,0x00)//自定义消息
}
winform.btnDID_F101w.oncommand = function(id,event){
::PostThreadMessage(thrdId,115,0xF101,0x00)//自定义消息
}
winform.show();
win.loopMessage();
return winform;

View File

@ -0,0 +1,20 @@
//config 配置文件
import fsys.config;
config = fsys.config("/config/");
//config = fsys.config( io.appData("/软件作者/应用程序名/") );
//不需要序列化的配置名字前请添加下划线
namespace config {
__appName = "应用程序名";
__appVersion = "1.0.0.01";
__appDescription = "这是一个测试程序";
__website = "http://www.aardio.com/";
}
/**intellisense(config)
__appName = 应用程序名
__appVersion = 应用程序内部版本号
__appDescription = 程序说明
__website = 官方网站
? = 配置文件名,\n读写配置并序列化为一个表对象,\n表的成员值可以是支持序列化的普通变量,支持table对象\n配置文件在首次使用时自动加载,退出程序时自动保存\n!fsys_table.
end intellisense**/

View File

@ -0,0 +1,490 @@
/*
*使用说明:
*1.创建CAN设备对象 CANHw = usb2canfd.USB2CANHW();
*2.加载DLL CANHw.LoadDll();
*3.扫描设备 hwnum = CANHw.FlashHw();
*4.获取可用设备 allhw = CANHw.GetAvailableHW();
*5.打开设备(初始化) CANHw.OpenDevice(设备序号,通道)
*6.通过SendMsg和GetMsg发送和获取报文
*/
namespace usb2canfd{
//参考 http://www.toomoss.com/help/index.htm
//初始化CAN的数据类型定义
class CANFD_INIT_CONFIG{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
BYTE Mode; //0-正常模式1-自发自收模式
BYTE ISOCRCEnable;//0-禁止ISO CRC,1-使能ISO CRC
BYTE RetrySend;//0-禁止重发1-无限制重发
BYTE ResEnable;//0-不接入内部120欧终端电阻1-接入内部120欧终端电阻
//波特率参数可以用TCANLINPro软件里面的波特率计算工具计算
//仲裁段波特率参数,波特率=40M/NBT_BRP*(1+NBT_SEG1+NBT_SEG2)
BYTE NBT_BRP;
BYTE NBT_SEG1;
BYTE NBT_SEG2;
BYTE NBT_SJW;
//数据段波特率参数,波特率=40M/DBT_BRP*(1+DBT_SEG1+DBT_SEG2)
BYTE DBT_BRP;
BYTE DBT_SEG1;
BYTE DBT_SEG2;
BYTE DBT_SJW;
BYTE __Res0[8];
}
//初始化CAN的数据类型定义
class CAN_INIT_CONFIG{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
//CAN波特率 = 100MHz/(CAN_BRP)/(CAN_SJW+CAN_BS1+CAN_BS2)
INT CAN_BRP; //取值范围1~1024
BYTE CAN_SJW; //取值范围1~4
BYTE CAN_BS1; //取值范围1~16
BYTE CAN_BS2; //取值范围1~8
BYTE CAN_Mode; //CAN工作模式0-正常模式1-环回模式2-静默模式3-静默环回模式bit7为1则接入适配器内部终端电阻否则不接入
BYTE CAN_ABOM; //自动离线管理0-禁止1-使能
BYTE CAN_NART; //报文重发管理0-使能报文重传1-禁止报文重传
BYTE CAN_RFLM; //FIFO锁定管理0-新报文覆盖旧报文1-丢弃新报文
BYTE CAN_TXFP; //发送优先级管理0-标识符决定1-发送请求顺序决定
}
class CAN_FILTER_CONFIG{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
BYTE Enable; //使能该过滤器1-使能0-禁止
BYTE FilterIndex; //过滤器索引号取值范围为0到13
BYTE FilterMode; //过滤器模式0-屏蔽位模式1-标识符列表模式
BYTE ExtFrame; //过滤的帧类型标志为1 代表要过滤的为扩展帧为0 代表要过滤的为标准帧。
INT ID_Std_Ext; //验收码ID
INT ID_IDE; //验收码IDE
INT ID_RTR; //验收码RTR
INT MASK_Std_Ext; //屏蔽码ID该项只有在过滤器模式为屏蔽位模式时有用
INT MASK_IDE; //屏蔽码IDE该项只有在过滤器模式为屏蔽位模式时有用
INT MASK_RTR; //屏蔽码RTR该项只有在过滤器模式为屏蔽位模式时有用
}
//CANfd信息帧的数据类型定义
class CANFD_MSG{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
INT ID; //报文ID。 //| (1<<31);//扩展帧
BYTE DLC; //数据字节长度,可设置为-0,1,2,3,4,5,6,7,8,12,16,20,24,32,48,64
BYTE Flags; //bit[0]-BRS,bit[1]-ESI,bit[2]-FDF,bit[6..5]-Channel,bit[7]-RXD
BYTE __Res0; //保留
BYTE __Res1; //保留
INT TimeStamp; //帧接收或者发送时的时间戳单位为10us
BYTE Data[64]; //报文的数据。
}
//CAN信息帧的数据类型定义
class CAN_MSG{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
INT ID; //报文ID。
INT TimeStamp; //接收到信息帧时的时间标识从CAN 控制器初始化开始计时。
BYTE RemoteFlag; //是否是远程帧
BYTE ExternFlag; //是否是扩展帧
BYTE DataLen; //数据长度(<=8)即Data 的长度。
BYTE Data[8]; //报文的数据。
BYTE __Res;
}
class CAN_UDS_ADDR{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
INT ReqID; //请求报文ID。
INT ResID; //应答报文ID。
BYTE Flag; //bit[0]-帧类型(0-标准帧1-扩展帧),
//bit[1]-FDF(0-普通CAN帧1-CANFD帧),
//bit[2]-BRS(0-CANFD帧不加速1-CANFD帧加速)
BYTE AddrFormats; //0-normal, 1-extended ,2-mixed
BYTE AddrExt; //当AddrFormats不为normal时该数据放到CAN数据域第1字节
BYTE MaxDLC; //每帧最大数据字节数一般设置为8
}
class DEVICE_INFO{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
BYTE FirmwareName[32]; //固件名称字符串
BYTE BuildDate[32]; //固件编译时间字符串
INT HardwareVersion; //硬件版本号
INT FirmwareVersion; //固件版本号
INT SerialNumber[3]; //适配器序列号
INT Functions; //适配器当前具备的功能
}
//调用函数
class USB2CANHW{
ctor( /*输入构造函数所需要的参数*/ ){
};
type=me;
/*对象的所有成员必须用分号分隔*/
//初始化全局变量
DllHandle = null;
//加载DLL
LoadDll = function(){
try{
DllHandle = ..raw.loadDll("\USB2XXX.dll")
}
catch(err)
{
import win;
DllHandle = null;
win.msgboxTimeout("加载USB2LIN的DLL失败请检查USB2XXX.dll和libusb-1.0.dll文件","错误",3000,);
}
if(DllHandle == null)return 1;
return 0;
}
//刷新硬件
FlashHw = function(){
if(DllHandle = null){
//DLL为空返回
AvailableHW = {}
return 0;
}
var arr_temp = {int value[] = { length = 10/*可以使用变量*/ } }//类似动态数组
HwNum = DllHandle.USB_ScanDevice(arr_temp)
AvailableHW = {}
for(i=1;HwNum;1){
var devtemp = {};
devtemp.devnum = i;
devtemp.channel = 1;
devtemp.hLINHW = arr_temp.value[i];
devtemp.name = "dev-" + i + ":" + tostring(arr_temp.value[i],16);
..table.push(AvailableHW,devtemp);
}
return HwNum; //返回有效硬件数
}
//获取设备信息
GetDevInfo = function(index){
if(index > HwNum)
{ //如果序号大于最大硬件数
return 0;
}
DllHandle.USB_OpenDevice(AvailableHW[index].hLINHW);
var DeviceInfo = ..usb2canfd.DEVICE_INFO();
var funcstr = ..raw.buffer(100);
var ret = DllHandle.DEV_GetDeviceInfo(AvailableHW[index].hLINHW,DeviceInfo,funcstr);
return ret,DeviceInfo,funcstr;
}
//获取设备信息
GetNowInfo = function(){
if(Hwconnected == null){
return 0;
}
//DllHandle.USB_OpenDevice(Hwconnected);
var DeviceInfo = ..usb2canfd.DEVICE_INFO();
var funcstr = ..raw.buffer(100);
var ret = DllHandle.DEV_GetDeviceInfo(Hwconnected,DeviceInfo,funcstr);
return ret,DeviceInfo,funcstr;
}
//获取有效硬件
GetAvailableHW = function(){
return AvailableHW;
}
SetFilter = function(index){
CANFilter = ..usb2canfd.CAN_FILTER_CONFIG();
CANFilter.FilterIndex = 0;
CANFilter.Enable = 1;
CANFilter.ExtFrame = 0; //需要过滤接收的帧为标准帧
CANFilter.FilterMode = 1;//标识符列表模式
CANFilter.ID_IDE = 0; //接收到的数据帧IDE必须为1也就是必须为扩展帧数据
CANFilter.ID_RTR = 0; //接收到的帧类型必须为数据帧
CANFilter.ID_Std_Ext = 0x620;//接收到的帧ID必须等于CANFilter.ID_Std_Ext设置的值
var ret = DllHandle.CAN_Filter_Init(AvailableHW[index].hLINHW,0,CANFilter);
CANFilter.FilterIndex = 1;
CANFilter.ID_Std_Ext = 0x610;
var ret = DllHandle.CAN_Filter_Init(AvailableHW[index].hLINHW,0,CANFilter);
for(i=2;13;1){
CANFilter.FilterIndex = i;
CANFilter.Enable = 0;
DllHandle.CAN_Filter_Init(AvailableHW[index].hLINHW,0,CANFilter);
}
}
//打开设备,包括初始化通道
OpenDevice = function(index,channel,canfd){
if(index > HwNum)
{ //如果序号大于最大硬件数
return 0;
}
import console;
var ret = DllHandle.USB_OpenDevice(AvailableHW[index].hLINHW)
//canfd = true;
if(canfd == true){
var canconfig = ..usb2canfd.CANFD_INIT_CONFIG();
canconfig.Mode = 0; //0-正常模式1-自发自收模式
canconfig.ISOCRCEnable = 0;//0-禁止ISO CRC,1-使能ISO CRC
canconfig.RetrySend = 1;//0-禁止重发1-无限制重发
canconfig.ResEnable = 1;//0-不接入内部120欧终端电阻1-接入内部120欧终端电阻
//波特率参数可以用TCANLINPro软件里面的波特率计算工具计算
//仲裁段波特率参数,波特率=40M/NBT_BRP*(1+NBT_SEG1+NBT_SEG2)
canconfig.NBT_BRP = 1; //参数来自官方上位机默认500K
canconfig.NBT_SEG1 = 59;
canconfig.NBT_SEG2 = 20;
canconfig.NBT_SJW = 2;
//数据段波特率参数,波特率=40M/DBT_BRP*(1+DBT_SEG1+DBT_SEG2)
canconfig.DBT_BRP = 2; //参数来自官方上位机默认500K
canconfig.DBT_SEG1 = 29;
canconfig.DBT_SEG2 = 10;
canconfig.DBT_SJW = 2;
ret = DllHandle.CANFD_Init(AvailableHW[index].hLINHW,channel,canconfig);
}
else {
var canconfig = ..usb2canfd.CAN_INIT_CONFIG();
canconfig.CAN_Mode = 0x80;//0-正常模式 1-环回模式 0x80终端电阻
canconfig.CAN_ABOM = 0;//禁止自动离线
canconfig.CAN_NART = 0;//禁止报文重传
canconfig.CAN_RFLM = 0;//FIFO满之后覆盖旧报文
canconfig.CAN_TXFP = 1;//发送请求决定发送顺序
//配置波特率,波特率 = 42M/(BRP*(SJW+BS1+BS2))
canconfig.CAN_BRP = 4;
canconfig.CAN_BS1 = 15;
canconfig.CAN_BS2 = 5;
canconfig.CAN_SJW = 2;
ret = DllHandle.CAN_Init(AvailableHW[index].hLINHW,channel,canconfig);
//console.log("init ret = " + ret);
this.SetFilter(index);
}
canfd_connected = canfd;
if(ret == 0){//调用成功
Hwconnected = AvailableHW[index].hLINHW;
Chconntected = channel;
}
else {
//Hwconnected = null
Chconntected = null;
}
return ret;
}
//关闭设备
CloseDevice = function(){
if(Hwconnected == null){
return;
}
try{
DllHandle.USB_CloseDevice(Hwconnected);
Hwconnected = null;
}
}
//是否连接
isConnected = function(){
if(Hwconnected == null){
return false;
}
else {
return true;
}
}
//发送报文
SendMsg = function(id,data){
if(Hwconnected == null){//未连接
return 0;
}
if(#data == 0 || #data>8){//长度不对
return 0;
}
//console.log("发送报文")
var ret = 0;
if(canfd_connected == true){
var msg = ..usb2canfd.CANFD_MSG();
msg.Flags = 0;
if(id <= 0x7ff){
msg.ID = id; //| (1<<31);//扩展帧
}
else {
msg.ID = id | (1<<31);//扩展帧
}
msg.DLC = #data;
msg.Data = data;
//console.dumpJson(msg);
//console.log("Hwconnected = " + Hwconnected);
//console.log("Chconntected = " + Chconntected);
ret = DllHandle.CANFD_SendMsg(Hwconnected,Chconntected,msg,1);
}
else {
var msg = ..usb2canfd.CAN_MSG();
//msg.Flags = 0;
if(id <= 0x7ff){
msg.ID = id; //| (1<<31);//扩展帧
}
else {
msg.ID = id | (1<<31);//扩展帧
}
msg.ExternFlag = 0;
msg.RemoteFlag = 0;
msg.DataLen = #data;
msg.Data = data;
//console.log("发送报文")
ret = DllHandle.CAN_SendMsg(Hwconnected,Chconntected,msg,1);
//console.log("ret = " + ret);
}
return ret;
}
//从设备缓冲区获取报文
GetMsg = function(){
var ret = 0;
var retdata = {};
if(canfd_connected == true){
//CANFD
do{
var msgbuf = ..usb2canfd.CANFD_MSG();
ret = DllHandle.CANFD_GetMsg(Hwconnected,CANIndex,msgbuf,1);
if(ret == 1){
var data = {};
for(i=1;msgbuf.DLC;1){
data[i] = msgbuf.Data[i];
}
var msg = {"id"=msgbuf.ID;"data"=data;};//
..table.push(retdata,msg);
}
}while(ret > 0)
}
else {
//CAN
do{
//raw.convertArray(raw.sizeof(..usb2canfd.CAN_MSG())
var msgbuf = {};
for(i=1;10;1){
//msgbuf.push(new ..usb2canfd.CAN_MS())
var temp = ..usb2canfd.CAN_MSG()
..table.push(msgbuf,temp);
}
//var msgbuf = ..raw.toarray(10,"struct",..usb2canfd.CAN_MS);
ret = DllHandle.CAN_GetMsgWithSize(Hwconnected,CANIndex,msgbuf[1],1);
if(ret == 1){
var data = {};
for(i=1;msgbuf[1].DataLen;1){
data[i] = msgbuf[1].Data[i];
}
var msg = {"id"=msgbuf[1].ID;"data"=data;};//
..table.push(retdata,msg);
}
}while(ret > 0)
}
return retdata;
}
GetDiag = function(data){
if(#data<2){
return 0,1;
}
var UDSAddr = ..usb2canfd.CAN_UDS_ADDR()
UDSAddr.Flag = 1;//使用扩展帧
UDSAddr.AddrFormats = 0;
UDSAddr.ReqID = 0x18dadff1;
UDSAddr.ResID = 0x18daf1df;
UDSAddr.MaxDLC = 8;
var req_data = ..raw.buffer(#data);
for(i=1;#data;1){
req_data[i] = data[i];
}
ret = DllHandle.CAN_UDS_Request(Hwconnected,CANIndex,UDSAddr,req_data,#data);
var res_data = ..raw.buffer(4096);
//sleep(10);
var ret = DllHandle.CAN_UDS_Response(Hwconnected,CANIndex,UDSAddr,res_data,1000);
return ret,2,res_data;
}
SetPower = function(state){
var ret = DllHandle.LIN_EX_CtrlPowerOut(Hwconnected,state);
return ret;
}
GetPower = function(){
var buf = ..raw.buffer(10);
var ret = DllHandle.LIN_EX_GetVbatValue(Hwconnected,buf);
return ret,buf;
}
}
}
/**intellisense()
usb2canfd = 图莫斯CANFD驱动
usb2canfd.USB2CANHW = USB2CAN库
usb2canfd.USB2CANHW() = 创建设备对象\n!usb2canfdUSB2CANHW.
!usb2canfdUSB2CANHW.LoadDll() = 加载DLL
!usb2canfdUSB2CANHW.FlashHw() = 刷新硬件
!usb2canfdUSB2CANHW.GetDevInfo() = 获取设备信息
!usb2canfdUSB2CANHW.GetAvailableHW() = 获取有效设备需要先FlashHw()刷新
!usb2canfdUSB2CANHW.OpenDevice() = 打开设备
!usb2canfdUSB2CANHW.CloseDevice() = 关闭设备
!usb2canfdUSB2CANHW.isConnected() = 是否已连接
!usb2canfdUSB2CANHW.SendMsg() = 发送报文
!usb2canfdUSB2CANHW.GetMsg() = 接收报文
end intellisense**/

Binary file not shown.

266
CAN_Bootloader/main.aardio Normal file
View File

@ -0,0 +1,266 @@
import win.ui;
/*DSG{{*/
mainForm = win.form(text="CAN_Bootloader";right=599;bottom=465;border="dialog frame";max=false)
mainForm.add(
btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4};
btnFlash={cls="button";text="开始刷写";left=36;top=329;right=135;bottom=357;z=9};
btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2};
btnOpen={cls="button";text="打开文件";left=36;top=296;right=135;bottom=324;z=8};
btnOpenFlashdrv={cls="button";text="打开FlashDriver";left=148;top=296;right=247;bottom=324;z=24};
btnReadF180={cls="button";text="读取boot版本";left=36;top=429;right=135;bottom=457;z=19};
btnReadF186={cls="button";text="读取当前会话";left=36;top=363;right=135;bottom=391;z=13};
btnReadF187={cls="button";text="读取型号";left=148;top=429;right=247;bottom=457;z=20};
btnReadF191={cls="button";text="读取编译日期";left=148;top=362;right=247;bottom=390;z=25};
btnReadHw={cls="button";text="读取硬件版本号";left=148;top=395;right=247;bottom=423;z=12};
btnReadSw={cls="button";text="读取软件版本号";left=36;top=396;right=135;bottom=424;z=10};
btnTest={cls="button";text="停止";left=148;top=330;right=247;bottom=358;z=11};
cbbChannel={cls="combobox";left=58;top=64;right=191;bottom=90;edge=1;items={};mode="dropdown";z=3};
cbbDev={cls="combobox";left=58;top=27;right=191;bottom=53;edge=1;items={};mode="dropdown";z=1};
checkbox={cls="checkbox";text="CANFD设备";left=151;top=101;right=248;bottom=120;checked=1;z=21};
edFile={cls="richedit";left=8;top=131;right=288;bottom=187;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=14};
edFile2={cls="richedit";left=8;top=202;right=288;bottom=258;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=22};
edit={cls="edit";left=294;top=19;right=596;bottom=401;autovscroll=false;edge=1;multiline=1;vscroll=1;z=5};
progress={cls="progress";left=296;top=436;right=596;bottom=464;edge=1;max=100;min=0;z=15};
radiobutton={cls="radiobutton";text="左侧";left=45;top=268;right=121;bottom=288;checked=1;group=1;z=26};
radiobutton2={cls="radiobutton";text="右侧";left=163;top=268;right=242;bottom=287;z=27};
static={cls="static";text="设备";left=1;top=28;right=61;bottom=52;align="center";center=1;transparent=1;z=6};
static2={cls="static";text="通道";left=1;top=66;right=61;bottom=90;align="center";center=1;transparent=1;z=7};
static3={cls="static";text="刷写进度";left=296;top=409;right=349;bottom=429;transparent=1;z=16};
static4={cls="static";text="烧录APP";left=13;top=108;right=85;bottom=132;center=1;transparent=1;z=17};
static5={cls="static";text="V0.2_20241219";left=451;top=1;right=595;bottom=17;align="right";center=1;transparent=1;z=18};
static6={cls="static";text="FlashDriver";left=13;top=184;right=101;bottom=207;transparent=1;z=23}
)
/*}}*/
import win;
import usb2canfd;
import win.timer;
var boot_count = 0;//boot时间计数器
var bootstate = false;//boot状态标志
var starttime = time.now();
timer_bootcount = win.timer(mainForm,100);
timer_bootcount.onTimer = function(){//boot时间定时器100ms间隔
boot_count++;
}
Display = function(str){//显示日志
var nowtime = time();
nowtime.format="%H:%M:%S";
mainForm.edit.print(tostring(nowtime) + " " + str);
}
//遍历目录
import console;
/*
import fsys.fileInfo;
info = fsys.fileInfo("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll");
console.log(info.writeTime);
execute("pause")
raw.loadDll("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll");
*/
CANHw = usb2canfd.USB2CANHW();//尝试加载CAN dll
var ret = CANHw.LoadDll();
if(ret == 0){
Display("DLL加载成功");
}
else {
//Display("DLL加载失败");
return ;
}
//初始化界面
mainForm.cbbChannel.add("通道1");
mainForm.cbbChannel.add("通道2");
mainForm.cbbChannel.selIndex = 1
//刷新按键
mainForm.btnFresh.oncommand = function(id,event){
mainForm.cbbDev.clear();//清空下拉框,防止反复刷新叠加
var hwnum = CANHw.FlashHw();//获取硬件数量
if(hwnum == 0){
mainForm.cbbDev.text = "未找到硬件"
}
else {
var allhw = CANHw.GetAvailableHW();
for(i=1;#allhw;1){
mainForm.cbbDev.add(allhw[i].name);
}
}
mainForm.cbbDev.selIndex = 1
::PostThreadMessage(thrdId,100,0,0)//自定义消息
}
mainForm.btnConnect.oncommand = function(id,event){
var canfd_check = mainForm.checkbox.checked?0x80:0x00;
::PostThreadMessage(thrdId,101,mainForm.cbbDev.selIndex,(mainForm.cbbChannel.selIndex - 1)|canfd_check)//自定义消息
/*
var ret = CANHw.OpenDevice(mainForm.cbbDev.selIndex,mainForm.cbbChannel.selIndex - 1);//通道为0和1
if(ret == 0){
Display("连接成功");
}
else {
Display("连接失败");
}
*/
}
//CAN通讯线程
import thread.command;
var listener = thread.command();
var flag_connected=0;
listener.$Display = function(str){
Display(str);
}
listener.$ShowPath = function(str){
mainForm.edFile.text = str;
}
listener.$ShowFlashDrvPath = function(str){
mainForm.edFile2.text = str;
}
listener.$SetProgress = function(pos){
if(pos >= 0 && pos <= 100){
mainForm.progress.pos = pos;
}
}
listener.$Connected = function(){
mainForm.btnConnect.disabled = true;
mainForm.btnFresh.disabled = true;
mainForm.cbbDev.disabled = true;
mainForm.cbbChannel.disabled = true;
flag_connected = 1;
}
listener.$SendEnd = function(isSuccess){
//timer_bootcount.disable();
var usetime = time.now().diffsecond(starttime);
bootstate = false;
if(isSuccess == true){
Display("刷写成功,用时 " + usetime + " S")
}
}
//线程函数
var CanThread = function(){
//线程函数内部要添加自已的import语句
import win;
import console;
//console.log("线程开始运行")
loadcodex("\user\CanThread.aardio");//加载线程程序
//在子线程启动消息循环
win.loopMessage(FuncLoopMsg)
}
DiagReadDID = function(did){
::PostThreadMessage(thrdId,110,did,0)//自定义消息
}
var Diag10Req = function(num){
::PostThreadMessage(thrdId,111,num,0)//自定义消息
}
var DiagBootReq = function(){
::PostThreadMessage(thrdId,102,0,0)//自定义消息
}
var DiagStopReq = function(){
::PostThreadMessage(thrdId,103,0,0)//自定义消息
}
mainForm.btnReadSw.oncommand = function(id,event){
DiagReadDID(0xF195);
}
mainForm.btnReadHw.oncommand = function(id,event){
DiagReadDID(0xF193);
}
mainForm.btnReadF186.oncommand = function(id,event){
DiagReadDID(0xF186);
}
mainForm.btnTest.oncommand = function(id,event){
DiagStopReq();
}
mainForm.btnFlash.oncommand = function(id,event){
if(io.exist(mainForm.edFile.text) == null){
Display("请打开烧写文件");
return;
}
if(io.exist(mainForm.edFile2.text) == null){
Display("请打开flashdriver文件");
return;
}
if(flag_connected == 0){
Display("请连接设备");
return;
}
if(bootstate == true){
return ;
}
bootstate = true;
mainForm.edit.text = "";
Display("开始刷写流程");
starttime = time.now();
//timer_bootcount.enable();
boot_count = 0;
DiagBootReq();
}
mainForm.btnOpen.oncommand = function(id,event){
::PostThreadMessage(thrdId,104,2,0)//自定义消息-打开文件
}
//程序关闭
mainForm.onClose = function(hwnd,message,wParam,lParam){
if(thrdId != null){
::PostThreadMessage(thrdId,105,0,0)//自定义消息
thread.waitClose(thrdHandle);
}
//PLinHw.isConnected()///待完善
//console.print("线程已关闭")
//console.pause()
}
mainForm.btnReadF180.oncommand = function(id,event){
DiagReadDID(0xF180);
}
mainForm.btnReadF187.oncommand = function(id,event){
DiagReadDID(0xF187);
}
mainForm.btnOpenFlashdrv.oncommand = function(id,event){
::PostThreadMessage(thrdId,104,1,0)//自定义消息-打开flashdriver
}
thrdHandle,thrdId = thread.create( CanThread )
mainForm.onClose = function(hwnd,message,wParam,lParam){
raw.closehandle(thrdHandle);
//frmChild.close();
}
mainForm.btnReadF191.oncommand = function(id,event){
DiagReadDID(0xF191);
}
mainForm.radiobutton.oncommand = function(id,event){
::PostThreadMessage(thrdId,121,0x731,0x7b1)//自定义消息-修改ID
}
mainForm.radiobutton2.oncommand = function(id,event){
::PostThreadMessage(thrdId,121,0x732,0x7b2)//自定义消息-修改ID
}
mainForm.show();
::PostThreadMessage(thrdId,121,0x731,0x7b1)//自定义消息-修改ID
return win.loopMessage();

BIN
CAN_Bootloader/res/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -0,0 +1,328 @@
import usb2canfd;
import thread.command;
import win.timer;
//初始化CAN句柄对象
CANHw = usb2canfd.USB2CANHW();
CANHw.LoadDll();
DiagReqID = 0x732;//0x18dadff1;
DiagRespID = 0x7B2;//0x18daf1df;
DiagGloableID = 0x7DF;//0x18DB33F1;
stopflag = 0;
write2Etest = function(did){
select(did) {
case 0xF010 {
var data = {1,2,3,4, 0,0,0,0, 0,0,0,0, 0,0,0,0,};
FuncReq2E(did,data);
}
case 0xF101 {
var data = {1,2,3,4, 0,0,0,0, };
FuncReq2E(did,data);
}
}
}
//注册一个消息钩子函数
FuncLoopMsg = function(msg){
select(msg.message) {
case 100 {//刷新硬件
FuncFreshHw();
}
case 101 {//连接硬件
//console.log("msg.wParam = " + msg.wParam);
//console.log("msg.lParam = " + msg.lParam);
FuncConnect(msg.wParam,msg.lParam);
}
case 102 {//开始boot
FuncStartBoot();
}
case 103 {//停止boot
FuncStopBoot();
}
case 104 {//打开s19文件
if(msg.wParam == 1){
FuncDisplay("打开FlashDriver");
var ret = FuncOpenS19File(msg.wParam);
if(ret != null){
thread.command.$ShowFlashDrvPath(ret);
var crc32 = FuncGetFlashCRC(1);
FuncDisplay("CRC = " ++ string.format("%X",crc32));
}
}
else {
FuncDisplay("打开烧写文件");
var ret = FuncOpenS19File(msg.wParam);
if(ret != null){
thread.command.$ShowPath(ret);
var crc32 = FuncGetFlashCRC(2);
FuncDisplay("CRC = " ++ string.format("%X",crc32));
}
}
}
case 105 {//停止boot
thread.stop(0);
}
case 110 {//readDID
FuncReadDID(msg.wParam);
}
case 111 {
FuncReq10(msg.wParam,msg.lParam);
}
case 112 {
FuncReq28(msg.wParam);
}
case 113 {
FuncReq85(msg.wParam);
}
case 114 {
FuncReq27(msg.wParam);
}
case 115 {
write2Etest(msg.wParam)
}
case 120 {
win.quitMessage()
}
case 121 {
SetDiagID(msg.wParam,msg.lParam);
}
else {
}
}
}
SetDiagID = function(reqid,respid){
DiagReqID = reqid;//0x18dadff1;
DiagRespID = respid;//0x18daf1df;
var idstr = string.format("req=0x%x,resp=0x%x",DiagReqID,DiagRespID);
FuncDisplay(idstr);
}
var delay_const = 100000;
DelayTest = function(){
import time.performance;
var tk = time.performance.tick();
for(i=1;1000000;1)
{
}
var tk2 = time.performance.tick();
tk2 = tk2 - tk;
delay_const = math.ceil(1000000*(1/tk2));
FuncDisplay(delay_const);
//console.log(delay_const);
}
FuncFreshHw = function(){
var hwnum = CANHw.FlashHw();
if(hwnum == 0){
//mainForm.cbbDev.text = "未找到硬件"
}
else {
FuncDisplay("找到硬件")
}
}
FuncConnect = function(dev,chn){
var canfd = (chn&0x80)==0x80?true:false;
var ret = CANHw.OpenDevice(dev,chn&0x7f,canfd);
if(ret == 0){
FuncDisplay("连接成功");
thread.command.$Connected();
}
else {
FuncDisplay("连接失败");
}
}
FuncDisplay = function(str){
thread.command.$Display(str);//"线程" +
}
loadcodex("\user\Diag10code.aardio");
loadcodex("\user\Diag11code.aardio");
loadcodex("\user\Diag22code.aardio");
loadcodex("\user\Diag27code.aardio");
loadcodex("\user\Diag2Ecode.aardio");
loadcodex("\user\Diag28code.aardio");
loadcodex("\user\Diag31code.aardio");
loadcodex("\user\Diag34code.aardio");
loadcodex("\user\Diag36code.aardio");
loadcodex("\user\Diag37code.aardio");
loadcodex("\user\Diag7Fcode.aardio");
loadcodex("\user\Diag85code.aardio");
loadcodex("\user\DiagBootcode.aardio");
loadcodex("\user\S19Decode.aardio");
RespState = 0;
FuncDiagPro = function(diagmsg){
select(diagmsg.sid) {
case 0x50 {
FuncDiag10Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x62 {
FuncDiag22Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x67 {
FuncDiag27Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x74 {
FuncDiag34Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x71 {
FuncDiag31Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x76 {
FuncDiag36Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x68 {
FuncDiag28Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0xC5 {
FuncDiag85Pro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x7F {
FuncDiag7FPro(table.slice(diagmsg.data,1,diagmsg.len))
}
case 0x6E {
FuncDiag2EPro(table.slice(diagmsg.data,1,diagmsg.len))
}
else {
}
}
RespState = diagmsg.sid;
}
FuncStartBoot = function(){
FuncInitBootState();
boottimer.enable();
FuncDisplay("开始刷写");
stopflag = 0;
}
var delay = function(w){
var delay_time = w*delay_const;
for(i=1;delay_time;1)
{
}
}
var PackNext = 0x21;
var Packdata = {};
var PackID = 0;
var FuncSendPackage = function(){
while(#Packdata > 0)
{
//sleep(1);
delay(1);
var data = {PackNext,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC};
var max = #Packdata > 7 ? 7 : #Packdata;
for(i=1;max;1){
data[i+1] = table.remove(Packdata);
}
//sleep(0.3);
CANHw.SendMsg(PackID,data);
PackNext += 1;
if(PackNext > 0x2f){
PackNext = 0x20;
}
}
}
FuncPushPackage = function(ID,data){
PackNext = 0x21;
Packdata = data;
PackID = ID;
}
boottimer = win.timer(,10);
boottimer.onTimer = function(){
if(CANHw.isConnected() == false){
boottimer.disable();
return;
}
FuncBootSeq();
}
timer1 = win.timer(,1);
diagresp = {}
timer1.onTimer = function(){
if(CANHw.isConnected() == false){
return;
}
ret = CANHw.GetMsg();
for(i=1;#ret;1){
//console.log("id = " + tostring(ret[i].id))
if(ret[i].id & 0x7FFFFFFF == DiagRespID){
if(ret[i].data[1] == 0x10){//首帧
var data = {0x30,0x00,0x14,0x00,0,0,0,0};
CANHw.SendMsg(DiagReqID,data);
diagresp["sid"] = ret[i].data[3];
diagresp["len"] = ret[i].data[2]-1;
diagresp["data"] = {};
diagresp["next"] = 0x21;
table.append(diagresp["data"],table.slice(ret[i].data,4));
}
elseif(ret[i].data[1] <= 0x07){//单帧
//console.dumpJson()
diagresp["sid"] = ret[i].data[2];
diagresp["len"] = ret[i].data[1]-1;
diagresp["data"] = table.slice(ret[i].data,3);
FuncDiagPro(diagresp);
}
elseif(ret[i].data[1] >= 0x21 && ret[i].data[1] <= 0x2f){
if(ret[i].data[1] == diagresp["next"]){//多帧
diagresp["next"] += 1;
if(diagresp["next"] >= 0x2F){
diagresp["next"] = 0x20;
}
table.append(diagresp["data"],table.slice(ret[i].data,2));
if(#diagresp["data"] >= diagresp["len"]){
FuncDiagPro(diagresp);
}
}
}
elseif(ret[i].data[1] == 0x30){//
FuncSendPackage();
}
}
else {
//console.varDump(ret[i].id);
//显示报文
}
}
}
timer1.enable();
FuncDisplay("正在运行");
DelayTest();

View File

@ -0,0 +1,33 @@
//发送
FuncReq10 = function(Addr,num){
if(num >= 1 && num <= 3){
var data = {0x02,0x10,num,0,0,0,0,0};
if(Addr == true){
CANHw.SendMsg(DiagGloableID,data);
}
else {
CANHw.SendMsg(DiagReqID,data);
}
}
}
//接收
FuncDiag10Pro = function(data){
//console.dumpJson(data);
select(data[1]) {
case 1 {
FuncDisplay("进入默认会话成功")
}
case 2 {
FuncDisplay("进入编程会话成功")
}
case 3 {
FuncDisplay("进入扩展会话成功")
}
else {
}
}
}

View File

@ -0,0 +1,9 @@
//发送
FuncReq11 = function(num){
var txdata = {0x2,0x11,num,0x00,0x00,0x00,0x00,0x00};
CANHw.SendMsg(DiagReqID,txdata);
}
//接收
FuncDiag11Pro = function(data){
FuncDisplay("复位成功")
}

View File

@ -0,0 +1,75 @@
var diag22state = 0;
//发送
FuncReadDID = function(did){
if(CANHw.isConnected() == false){
return;
}
var data = {0x03,0x22,did>>8,did&0xff,0,0,0,0};
var ret = CANHw.SendMsg(DiagReqID,data);
diag22state = 1;
//console.log("did = " + tostring(did,16));
//console.log("ret = " + ret);
//FuncDisplay("did = " + tostring(did,16));
}
g22data = {};
//接收
FuncDiag22Pro = function(data){
//console.log("诊断22服务")
if(#data < 3){
return;
}
var did = (data[1]<<8) + data[2];
select(did) {
case 0xF180 {
FuncDisplay("BOOT版本号");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
}
case 0xF186 {
FuncDisplay("当前会话: " + data[3]);
}
case 0xF193 {
FuncDisplay("硬件版本号");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
g22data["F193"] = string.str(string.pack(table.slice(data,3)));
}
case 0xF195 {
FuncDisplay("软件版本号");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
g22data["F195"] = string.str(string.pack(table.slice(data,3)));
}
case 0xF191 {
FuncDisplay("编译时间");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
}
case 0xF187 {
FuncDisplay("ECU系统名称");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
g22data["F187"] = string.str(string.pack(table.slice(data,3)));
}
case 0xF198 {
FuncDisplay("repair_shopcode");
FuncDisplay(string.str(string.pack(table.slice(data,3))));
}
case 0xF199 {
FuncDisplay("installation_date");
FuncDisplay(string.format("%x%X%x%x",data[3],data[4],data[5],data[6]));
}
case 0xF18A {
FuncDisplay("系统供应商公司名称代码");
FuncDisplay(string.pack(table.slice(data,3)));
}
case 0xF197 {
FuncDisplay("ECU 系统名称");
FuncDisplay(string.pack(table.slice(data,3)));
}
else {
FuncDisplay("未知DID - " + tostring(did,16));
}
}
}

View File

@ -0,0 +1,78 @@
var SecuretySeed = {0,0,0,0,};
var SecuretyKey = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
var lockstate = 0;
//发送
FuncReq27 = function(num,key){
if(num >= 1 && num <= 0x1C){
if(key == null){
var data = {0x02,0x27,num,0,0,0,0,0};
CANHw.SendMsg(DiagReqID,data);
}
else {
if(#key > 4){
var data = {0x10,0X12,0x27,num,key[1],key[2],key[3],key[4]};
CANHw.SendMsg(DiagReqID,data);
FuncPushPackage(DiagReqID,table.slice(key,5));
}
else {
var data = {0x06,0x27,num,key[1],key[2],key[3],key[4],0x00};
CANHw.SendMsg(DiagReqID,data);
}
}
}
else {
FuncDisplay("27长度错误");
}
}
//loadcodex("\user\securety.aardio");
loadcodex("\user\GeelySecurety.aardio");
//接收
FuncDiag27Pro = function(data){
//console.dumpJson(data);
select(data[1]) {
case 1,3,5,7,9,11,0x11 {
var str = "收到种子";
for(i=1;4;1){
SecuretySeed[i] = data[i+1];
str += " " + tostring(SecuretySeed[i],16);
lockstate = 1;
}
FuncDisplay(str)
SecuretyKey = securetyKeyCalc(SecuretySeed,data[1]);
if(#SecuretyKey >= 4){
FuncReq27(data[1]+1,SecuretyKey);
var str = "计算密钥-";
for(i=1;4;1){
str += " " + tostring(SecuretyKey[i],16);
}
FuncDisplay(str);
}
else {
FuncDisplay("计算失败");
}
}
case 2,4,6,8,10,12,0x12 {
FuncDisplay("解锁成功");
lockstate = 2;
}
else {
FuncDisplay("27服务未知子服务");
}
}
}
FuncDiag27GetState = function(){
if(lockstate == 2){
return 0;
}
else {
return 1;
}
}

View File

@ -0,0 +1,27 @@
//发送
FuncReq28 = function(num1,num2){
var txdata = {0x03,0x28,num1,num2,0,0,0,0};
var ret = CANHw.SendMsg(DiagGloableID,txdata);
}
//接收
FuncDiag28Pro = function(data){
//console.dumpJson(data);
select(data[1]) {
case 0 {
FuncDisplay("使能接收发送")
}
case 1 {
FuncDisplay("使能接收,禁止发送")
}
case 2 {
FuncDisplay("禁止接收,使能发送")
}
case 3 {
FuncDisplay("禁止接收发送")
}
else {
}
}
}

View File

@ -0,0 +1,43 @@
var diag22state = 0;
//发送
FuncDIDWriteStr = function(did,str){
var data = {}
for(i=1;string.len(str);1){
data[i] = string.unpack(str,i);
}
FuncReq2E(did,data)
return data;
}
//FuncDIDWriteStr(0xf198,"0123456789abcdef1234");
FuncReq2E = function(did,data){
if(CANHw.isConnected() == false){
return;
}
if(#data > 4){
//多帧
var txdata = {0x10,3+#data,0x2E,did>>8,did&0xff,data[1],data[2],data[3]};
CANHw.SendMsg(DiagReqID,txdata);
//等待发送
FuncPushPackage(DiagReqID,table.slice(data,3));
}
else {
var txdata = {3+#data,0x2E,did>>8,did&0xff,0,0,0,0};
for(i=1;#data;1){
txdata[4+i] = data[i];
}
CANHw.SendMsg(DiagReqID,txdata);
}
}
//接收
FuncDiag2EPro = function(data){
var did = (data[1]<<8) + data[2];
FuncDisplay("写入" + tostring(did,16) + "成功");
}

View File

@ -0,0 +1,82 @@
FuncReq31EraseFlash = function(addr,len){
FuncDisplay("开始擦除数据")
var data = {0xfd,0x01,0x44,addr>>24,addr>>16,addr>>8,addr,len>>24,len>>16,len>>8,len};
FuncReq31(data);
}
FuncReq31CheckLogicBlock = function(crc){//(addr,len)
//var data = {0x02,0x02,0x44,addr>>24,addr>>16,addr>>8,addr,len>>24,len>>16,len>>8,len};
var data = {0x02,0x02,crc>>24,crc>>16,crc>>8,crc};
FuncReq31(data);
}
FuncReq31CheckPD = function(){//Programming Dependencies
var data = {0xFF,0x01};
FuncReq31(data);
}
FuncReq31CheckFlash = function(){
var data = {0x02,0x02};
FuncReq31(data);
}
FuncReq3103 = function(id){
//停止例程
var txdata = {0x04,0x31,0x03,id>>8,id&0xff,0x00,0x00,0x00};
CANHw.SendMsg(DiagReqID,txdata);
}
FuncReq3101FD02 = function(){
var txdata = {0x04,0x31,0x01,0xfd,0x02,0x00,0x00,0x00};
CANHw.SendMsg(DiagReqID,txdata);
}
FuncReq3101FD03 = function(){
var txdata = {0x04,0x31,0x01,0xfd,0x03,0x00,0x00,0x00};
CANHw.SendMsg(DiagReqID,txdata);
}
//发送
FuncReq31 = function(data){
if(#data > 5){//多帧
var txdata = {0x10,2+#data,0x31,0x01,data[1],data[2],data[3],data[4]};
CANHw.SendMsg(DiagReqID,txdata);
FuncPushPackage(DiagReqID,table.slice(data,5));
}
else {
var txdata = {2+#data,0x31,0x01,0, 0,0,0,0};
for(i=1;#data;1){
txdata[3+i] = data[i];
}
CANHw.SendMsg(DiagReqID,txdata);
}
}
//接收
FuncDiag31Pro = function(data){
//console.dumpJson(data);
if(#data < 3){
//FuncDisplay("31长度错误");
return;
}
var rid = (data[2]<<8) + data[3];
select(rid) {
case 0xFD01 {
FuncDisplay("擦除成功")
}
case 0xFD02 {
FuncDisplay("flash driver校验成功")
}
case 0x0202 {
FuncDisplay("校验成功")
}
case 0xFF01 {
FuncDisplay("检查标志成功")
}
case 0xF518 {
FuncDisplay("数字签名错误")
}
else {
}
}
}

View File

@ -0,0 +1,29 @@
//发送
FuncReq34 = function(addr,len){
var data = {0x44,addr>>24,addr>>16,addr>>8,addr,len>>24,len>>16,len>>8,len};
var txdata = {0x10,2+#data,0x34,0x00,data[1],data[2],data[3],data[4]};
CANHw.SendMsg(DiagReqID,txdata);
FuncPushPackage(DiagReqID,table.slice(data,5));
}
var maxlen = 0;
//接收
FuncDiag34Pro = function(data){
//console.dumpJson(data);
FuncDisplay("请求下载成功")
maxlen = (data[2]<<8) + data[3];
FuncDisplay("最大长度:" + maxlen);
}
FuncGetSengLen = function(){
if(maxlen>2){
return maxlen-2;
}
else {
return 0;
}
}

View File

@ -0,0 +1,66 @@
//
var blocknum=1;
var flag_sendend = false;
var flag_sending = false;
var alldata = {};
FuncStartSendBlock = function(data){
blocknum = 0x01;
flag_sendend = false;
flag_sending = true;
alldata = data;
}
FuncStopSendBlock = function(data){
blocknum = 0x01;
flag_sendend = false;
flag_sending = false;
}
FuncGetSendStatus = function(){
return flag_sendend;
}
FuncSendNextBlock = function(){
var len = FuncGetSengLen();
//sleep(500);
if(#alldata>len){
FuncReq36(blocknum,table.slice(alldata,1,len));
alldata = table.slice(alldata,len+1,)
}
else {
FuncReq36(blocknum,alldata);
alldata = {};
flag_sendend = true;
}
blocknum += 1;
}
//发送
FuncReq36 = function(num,data){
len = #data+2;
if(len > 7){
var txdata = {0x10+(len>>8),len&0xff,0x36,num&0xff,data[1],data[2],data[3],data[4]};
CANHw.SendMsg(DiagReqID,txdata);
FuncPushPackage(DiagReqID,table.slice(data,5));
}
else {
var txdata = {len,0x36,num&0xff,0, 0,0,0,0};
for(i=1;#data;1){
txdata[i+3] = data[i];
}
CANHw.SendMsg(DiagReqID,txdata);
}
}
//接收
FuncDiag36Pro = function(data){
//console.dumpJson(data);
/*
if(data[1] == blocknum){
blocknum += 1;
if(flag_sending == true){
FuncSendNextBlock();
}
}
*/
}

View File

@ -0,0 +1,9 @@
//发送
FuncReq37 = function(){
var txdata = {0x1,0x37,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA};
CANHw.SendMsg(DiagReqID,txdata);
}
//接收
FuncDiag37Pro = function(data){
}

View File

@ -0,0 +1,46 @@
var errSID=0,errNRC=0;
FuncGetNrc = function(){
return errSID,errNRC;
}
FuncClrNrc = function(){
//return errSID,errNRC;
errSID = 0;
errNRC = 0;
}
var TableToStr = function(data){
if(data == null){
return " ";
}
if(#data == 0){
return " ";
}
var str = "data:"
for(i=1;#data;1){
str += " "
str += tostring(data[i],16);
}
return str;
}
//接收
FuncDiag7FPro = function(data){
//console.dumpJson(data);
errSID = data[1];
errNRC = data[2];
select(errNRC) {
case 0x78 {
if(errSID != 0x36){
FuncDisplay("服务正忙")
}
}
else {
FuncDisplay("SID:" + tostring(errSID,16))
FuncDisplay("错误 - NRC:" + tostring(errNRC,16))
FuncDisplay(TableToStr(data));
}
}
}

View File

@ -0,0 +1,27 @@
//发送
FuncReq85 = function(num){
if(num >= 1 && num <= 3){
var data = {0x02,0x85,num,0,0,0,0,0};
CANHw.SendMsg(DiagGloableID,data);
}
}
//接收
FuncDiag85Pro = function(data){
//console.dumpJson(data);
select(data[1]) {
case 0x01 {
FuncDisplay("DTC开启")
}
case 0x02 {
FuncDisplay("DTC禁能")
}
case 3 {
FuncDisplay("DTC - 01")
}
else {
FuncDisplay("DTC - TDB")
}
}
}

View File

@ -0,0 +1,521 @@
var bootstate = 0;
var bootcount = 0;
var sendstate = 0;
FuncWait = function(sid){
if(RespState == (sid + 0x40)){//正响应
//bootcount = 0;
return 0;
}
errsid,errnrc = FuncGetNrc();
FuncClrNrc();
if(errsid == sid){
if(errnrc == 0x78){//等待
bootcount = 0;
return 0xff;
}
else {
FuncDisplay("刷写错误 步骤" + bootstate);
boottimer.disable();
thread.command.$SendEnd(false);
return 1; //负响应
}
}
if(stopflag == 1){
FuncDisplay("停止");
boottimer.disable();
thread.command.$SendEnd(false);
return 2;//停止命令
}
bootcount += 1;
/*
if(bootcount > 20 && sid == 0x36){
bootcount = 0;
return 0;
}
*/
if(bootcount >= 400){
FuncDisplay("步骤" + bootstate + "超时 " + tostring(sid,16));
thread.command.$SendEnd(false);
boottimer.disable();
return 3;//超时
}
}
FuncStopBoot = function(){
stopflag = 1;
}
FuncClearState = function(){
RespState = 0;
bootcount = 0;
sendstate = 1;
}
FuncInitBootState = function(){
bootstate = 0;
RespState = 0;
bootcount = 0;
sendstate = 0;
}
BCD_Conv = function(num){
if(num > 99){
return 0;
}
var ret = 0;
ret += math.floor(num/10) * 16;
ret += num%10;
return ret;
}
var sendblockstate = 0;
var alldata = {};
var blocknum = 1;
var alldata_blocknum = 0;
var block_sended = 0;
var sendFlashDriverState = 0;
var FuncSendBlockApp_sendflag = 0;
var nowid=0;
FuncSendBlockInit = function(id){
var len = 0;
alldata = FuncGetAllData(id);
blocknum = 1;
if(alldata == null){
FuncDisplay("错误:空数据");
alldata_blocknum = 0;
sendblockstate = 0xff;
return 1;
}
for(i=1;#alldata;1){
len += math.ceil(#alldata[i]["data"] / FuncGetSengLen())
}
alldata_blocknum = len;
block_sended = 0;
sendblockstate = 0;
FuncSendBlockApp_sendflag = 0;
nowid = id;
//console.log("发送数据初始化")
return 0;
}
nextstate = function(val){
if(val == 0){
bootstate += 1;
sendstate = 0;
block_sended += 1;
}
}
FuncSendBlockApp = function(){
select(sendblockstate) {
case 0{
if(FuncSendBlockApp_sendflag == 0){
FuncReq34(alldata[blocknum]["address"],#alldata[blocknum]["data"]);
FuncSendBlockApp_sendflag = 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x34) == 0){
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
}
}
case 1 {
FuncStartSendBlock(alldata[blocknum]["data"]);//初始化
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
case 2 {
if(FuncSendBlockApp_sendflag == 0){
FuncSendNextBlock();
FuncSendBlockApp_sendflag = 1;
block_sended += 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x36) == 0){
FuncSendBlockApp_sendflag = 0;
if(FuncGetSendStatus() == true){//所有块发送完成
sendblockstate += 1;
if(nowid == 1){
sendblockstate += 1;
}
}
}
}
}
case 3 {
if(FuncSendBlockApp_sendflag == 0){
FuncReq37();
FuncSendBlockApp_sendflag = 1;
RespState = 0;
bootcount = 0;
}
else {
if(FuncWait(0x37) == 0){
FuncSendBlockApp_sendflag = 0;
sendblockstate += 1;
}
}
}
else {
if(blocknum < #alldata){
blocknum += 1;
sendblockstate = 0;
}
else {
//所有数据发送完成
return 0;
}
}
}
return 1;
}
FuncSendBlockFlashDriver = function(){
select(sendFlashDriverState) {
case 0 {
}
case 1 {
}
case 2 {
}
case 3 {
}
else {
}
}
}
var delaycount = 0;
//boot总流程
var boottime = 0;
FuncBootSeq = function(){
boottime++;
select(bootstate) {
case 0 {
boottime = 1;
if(sendstate == 0){
//FuncSendBlockInit(0);
g22data = {};
FuncReadDID(0xF187);
FuncClearState();
}
else {
var ret = FuncWait(0x22);
if(g22data["F187"]!= null){
if(g22data["F187"] == "RP-77B"){
nextstate(0);
}
else {
FuncDisplay("型号错误");
FuncStopBoot();
thread.command.$SendEnd(false);
boottimer.disable();
}
}
}
}
case 1 {
if(sendstate == 0){
FuncReadDID(0xF195);//读取软件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
nextstate(ret);
}
}
case 2 {
if(sendstate == 0){
FuncReadDID(0xF193);//读取硬件版本
FuncClearState();
}
else {
var ret = FuncWait(0x22);
if(g22data["F193"]!= null){
if(g22data["F193"] == "HW01"){
nextstate(0);
}
else {
FuncDisplay("硬件错误");
FuncStopBoot();
thread.command.$SendEnd(false);
boottimer.disable();
}
}
}
}
case 3 {
if(sendstate == 0){
FuncReq10(true,0x03);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 4 {
if(sendstate == 0){
FuncReq85(0x02);//关闭DTC
FuncClearState();
}
else {
var ret = FuncWait(0x85);
nextstate(ret);
}
}
case 5 {
if(sendstate == 0){
FuncReq28(0x01,0x01);//禁止发送
FuncClearState();
}
else {
var ret = FuncWait(0x28);
nextstate(0);
}
}
case 6 {
if(sendstate == 0){
FuncReq10(false,0x02);//进入编程会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 7 {
if(sendstate == 0){//等待复位完成
delaycount = 0;
FuncClearState();
}
else {
delaycount += 1;
if(delaycount > 20){
nextstate(0);//延时1S
}
}
}
case 8 {
if(sendstate == 0){
FuncReq27(0x09);//解密
FuncClearState();
}
else {
var ret = FuncWait(0x27);
nextstate(ret);
}
}
case 9 {
if(sendstate == 0){
//FuncReq27(02);//发送key
FuncClearState();
FuncDisplay("等待解锁");
}
else {
//var ret = FuncWait(0x27);
var ret = FuncDiag27GetState();
nextstate(ret);
}
}
case 10 {
if(sendstate == 0){
FuncReq31EraseFlash(0x20005BF0,0x800);
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 11 {
if(sendstate == 0){//写入installation_date
FuncReq3103(0xFD01);
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 12 {
if(sendstate == 0){//发送数据
FuncSendBlockInit(1);
FuncDisplay("开始发送FlashDrv数据");
FuncClearState();
}
else {
var ret = FuncSendBlockApp();
nextstate(ret);
}
}
case 13 {
if(sendstate == 0){//CheckLogicBlock
//var crc = FuncGetFlashCRC(0);
//FuncReq31CheckLogicBlock(crc);
FuncReq3101FD02();
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 14 {
if(sendstate == 0){//
FuncReq3103(0xFD02);
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 15 {
if(sendstate == 0){//CheckLogicBlock
FuncReq31EraseFlash(0x00010000,0x28000);
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 16 {
if(sendstate == 0){//发送数据
FuncSendBlockInit(2);
FuncDisplay("开始发送App数据");
FuncClearState();
}
else {
var ret = FuncSendBlockApp();
nextstate(ret);
}
}
case 17 {
if(sendstate == 0){//CheckLogicBlock
FuncReq3101FD03();
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 18 {
if(sendstate == 0){////Programming Dependencies
FuncReq3103(0xFD03);
FuncClearState();
}
else {
var ret = FuncWait(0x31);
nextstate(ret);
}
}
case 19 {
if(sendstate == 0){//等待复位完成
delaycount = 0;
FuncClearState();
}
else {
delaycount += 1;
if(delaycount > 10){
nextstate(0);//延时0.1S
}
}
}
case 20 {
if(sendstate == 0){//复位
FuncClearState();
FuncReq11(0x01);
}
else {
var ret = FuncWait(0x11);
nextstate(ret);
}
}
case 21 {
if(sendstate == 0){//等待复位完成
delaycount = 0;
FuncClearState();
}
else {
delaycount += 1;
if(delaycount > 20){
nextstate(0);//延时1S
}
}
}
case 22 {
if(sendstate == 0){
FuncReq10(true,0x03);//进入扩展会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
case 23 {
if(sendstate == 0){
FuncReq28(0x00,0x01);//开启发送
FuncClearState();
}
else {
var ret = FuncWait(0x28);
nextstate(ret);
}
}
case 24 {
if(sendstate == 0){
FuncReq85(0x01);//开启DTC
FuncClearState();
}
else {
var ret = FuncWait(0x85);
nextstate(ret);
}
}
case 25 {
if(sendstate == 0){
FuncReq10(true,0x01);//进入默认会话
FuncClearState();
}
else {
var ret = FuncWait(0x10);
nextstate(ret);
}
}
else {
thread.command.$SendEnd(true);
//FuncDisplay("刷写完成,用时 " + boottime/100 + " S")
boottimer.disable();
}
}
if(alldata_blocknum != 0){
thread.command.$SetProgress(block_sended/alldata_blocknum * 100);
}
}

View File

@ -0,0 +1,99 @@
xorArray = {0xAA,0x50,0x43,0x52}
securetyKeyCalc = function(pucSeed,ucSecurityLevel){
//SeedSec_t cal,key,seed;
var seed = {0,0,0,0};
var key = {0,0,0,0};
var cal = {0,0,0,0};
seed[1]=pucSeed[4];
seed[2]=pucSeed[3];
seed[3]=pucSeed[2];
seed[4]=pucSeed[1];
select(ucSecurityLevel) {
case 0x01 {
var dll = raw.loadDll("/DM_RP_SA.dll",,"cdecl" );
if(dll != null){
FuncDisplay("加载密钥dll成功");
var retlen = raw.buffer(4,0);
var seedraw = raw.buffer(4,0);
var iVariant = raw.buffer(20,0);
var keyraw = raw.buffer(4,0);
seedraw[1] = pucSeed[1];
seedraw[2] = pucSeed[2];
seedraw[3] = pucSeed[3];
seedraw[4] = pucSeed[4];
var ret = 0;
ret = dll.GenerateKeyEx(seedraw,4,0x01,iVariant,keyraw,4,retlen);
FuncDisplay("ret = " ++ ret );
key[1] = keyraw[1];
key[2] = keyraw[2];
key[3] = keyraw[3];
key[4] = keyraw[4];
return key;
}
else {
FuncDisplay("加载密钥dll失败");
}
}
case 0x09 {
var dll = raw.loadDll("/DM_RP_SA.dll",,"cdecl" );
if(dll != null){
FuncDisplay("加载密钥dll成功");
var retlen = raw.buffer(4,0);
var seedraw = raw.buffer(4,0);
var iVariant = raw.buffer(20,0);
var keyraw = raw.buffer(4,0);
seedraw[1] = pucSeed[1];
seedraw[2] = pucSeed[2];
seedraw[3] = pucSeed[3];
seedraw[4] = pucSeed[4];
var ret = 0;
ret = dll.GenerateKeyEx(seedraw,4,0x09,iVariant,keyraw,4,retlen);
FuncDisplay("ret = " ++ ret );
key[1] = keyraw[1];
key[2] = keyraw[2];
key[3] = keyraw[3];
key[4] = keyraw[4];
return key;
}
else {
FuncDisplay("加载密钥dll失败");
}
}
case 0x11 {
/*
cal.byte[0] = seed.byte[0]^xorArray[0];
cal.byte[1] = seed.byte[1]^xorArray[1];
cal.byte[2] = seed.byte[2]^xorArray[2];
cal.byte[3] = seed.byte[3]^xorArray[3];
key.byte[3] = ((cal.byte[1]&0x03)<<6)|(( cal.byte[0]&0xFC)>>2);
key.byte[2] = ((cal.byte[0]&0x03)<<6)|(cal.byte[3]&0x3F);
key.byte[1] = (cal.byte[3]&0xFC)|((cal.byte[2]&0xC0)>>6);
key.byte[0] = (cal.byte[2]&0xFC)|(cal.byte[1]&0x03);
*/
cal[1] = seed[1]^xorArray[1];
cal[2] = seed[2]^xorArray[2];
cal[3] = seed[3]^xorArray[3];
cal[4] = seed[4]^xorArray[4];
key[4] = ((cal[2]&0x03)<<6)|(( cal[1]&0xFC)>>2);
key[3] = ((cal[1]&0x03)<<6)|(cal[4]&0x3F);
key[2] = (cal[4]&0xFC)|((cal[3]&0xC0)>>6);
key[1] = (cal[3]&0xFC)|(cal[2]&0x03);
}
else {
}
}
var pucKey = {0,0,0,0};
pucKey[1]=key[4];
pucKey[2]=key[3];
pucKey[3]=key[2];
pucKey[4]=key[1];
return pucKey;
}

View File

@ -0,0 +1,199 @@
var Crc32Tble =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
var fileinfo = "";
var FlashData = {};
var AllData = {}
FuncGetAllData = function(id){
if(id > #AllData){
return null;
}
return AllData[id];
}
FuncGetFileInfo = function(){
return fileinfo;
}
FuncCRC32Calc = function(Data){
var usCRC = 0xFFFFFFFF;
for(i=1;#Data;1){
var temp = (usCRC ^ Data[i]) & 0xFF;
usCRC = ((usCRC >> 8)&0xffffff) ^ Crc32Tble[temp+1];
}
usCRC ^= 0xFFFFFFFF;
return usCRC;
}
FuncGetFlashCRC = function(id){
var Data = AllData[id];
var crc = FuncCRC32Calc(Data[1].data);
return crc;
}
var s19crc = {};
FuncOpenS19File = function(id,path){
import fsys.dlg;
if(path == null){
path = fsys.dlg.open('S19文件|*.sx;*.s19;*.srec|所有文件|*.*||',,,winform);
}
if(io.exist( path )){
//winform.editPath.text = path;
var readbuf = string.load(path);
readbuf = string.split(readbuf,'\r\n');
//console.dumpJson(readbuf);
var block = null;
FlashData = {};
for(i=1;#readbuf;1){
if(#readbuf[i] == 0){
continue;
}
var str = readbuf[i];
var data = "";
var addr = 0;
var len = 0;
select(string.slice(str,1,2)) {
case "S0"{
//S0为文件信息
var fileinfobuf = string.slice(str,9,-3);//取出文件信息
fileinfo = "file info:"+string.unhex(fileinfobuf,"")//解码
fileinfo = string.replace(fileinfo,"\z"," ");//替换空字符
FuncDisplay(fileinfo)//显示
continue;
}
case "S1"{
len = tonumber(string.slice(str,3,4),16)
addr = tonumber(string.slice(str,5,8),16)
data = string.slice(str,9,-3)
}
case "S2"{
len = tonumber(string.slice(str,3,4),16)
addr = tonumber(string.slice(str,5,10),16)
data = string.slice(str,11,-3)
}
case "S3"{
len = tonumber(string.slice(str,3,4),16)
addr = tonumber(string.slice(str,5,12),16)
data = string.slice(str,13,-3)
}
else {
continue;
}
}
if(block == null){
//空表,第一次进入
block = {};
block["address"] = addr;
block["data"] = {};
}
else {
//非空表
if(addr == (block["address"]+#block["data"])){
//连续,无动作
}
else {
//不同块,新建块
FlashData[#FlashData+1]={"address" = block["address"];"data" = block["data"];}
block["address"] = addr;
block["data"] = {};
}
}
data = string.unhex(data,"")
for(i=1;#data;1){
var bytedata = string.unpack(data,i)
table.push(block["data"],bytedata)
}
}
s19crc = null;
FuncDisplay(string.format("addr=%x ,len = %x",block.address,#block.data))//显示
if(block.address == 0x10000){
var last_data_addr = 0;
last_data_addr = #block.data;
var temp = last_data_addr%2048;
if(temp != 0){
last_data_addr += 2048-temp;
}
for(i=#block.data+1;last_data_addr;1){
block.data[i] = 0xff;
}
s19crc = {};
s19crc["address"] = 0x37800;
s19crc["data"] = {};
for(i=1;0x800;1){
s19crc.data[i] = 0xff;
}
last_data_addr+=0x10000;
s19crc.data[0x7FC] = last_data_addr>>24;
s19crc.data[0x7FB] = last_data_addr>>16;
s19crc.data[0x7FA] = last_data_addr>>8;
s19crc.data[0x7F9] = last_data_addr&0XFF;
var crc32temp = FuncCRC32Calc(block.data);
s19crc.data[0x800] = crc32temp>>24;
s19crc.data[0x7FF] = crc32temp>>16;
s19crc.data[0x7FE] = crc32temp>>8;
s19crc.data[0x7FD] = crc32temp&0XFF;
}
if(block != null){
table.push(FlashData,block)
}
if(s19crc != null){
table.push(FlashData,s19crc)
}
AllData[id] = FlashData;
}
//blocknum = 1;
return path;
}

25
cva_asw_m0118/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,25 @@
{
"MicroPython.executeButton": [
{
"text": "▶",
"tooltip": "运行",
"alignment": "left",
"command": "extension.executeFile",
"priority": 3.5
}
],
"MicroPython.syncButton": [
{
"text": "$(sync)",
"tooltip": "同步",
"alignment": "left",
"command": "extension.execute",
"priority": 4
}
],
"files.associations": {
"canuser.h": "c",
"apptask.h": "c",
"mcu.h": "c"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,65 @@
S32520005BF000000000395E00204D5E00204D600020F1B489B00120694608710999096807914E
S32520005C10002106916A461279520002231A400692069A079B1A606A46D070099A1268059193
S32520005C306B46DB781B01102423400593059B13606B469870099B1B6804916C46A478640124
S32520005C5020252C400494049C1C606C466070099C246803916D466D78AD01402635400395A9
S32520005C70039D25606D462870099D2D6802916E463678F60008273E400296029E2E60099E3E
S32520005C90366808910100C9B289000427394031600AB0F0BC7047F0B501000025280001222A
S32520005CB013000C681E00F6B2F60180273E4026600B681B68DB091340DBB2002BF8D00B689F
S32520005CD01B685B091340DBB2002B0CD10B681B681B091340DBB2002B05D10B681B681A4074
S32520005CF0D2B2002A01D007221000C0B2F0BDF2B584B00400002528006946887028006946ED
S32520005D104870206801260068C10A30000840C0B200280ED16846007C01280AD16068006864
S32520005D30010D30000840C0B2012802D130006946487020680068C10930000840C0B20028D6
S32520005D5001D109206DE02000FFF752FF0D2069460870290022680195FF2002900B00DBB278
S32520005D70D3181F7F029B9F43BC466B461F78029B3B4067463B430193019B0F00FFB2D71978
S32520005D903B776B461B7C002B01D0370000E02F0031006A461170216803910195029003984F
S32520005DB0694609784018007F029988433900C9B2029A0A4002430192019803996A4612785F
S32520005DD0891808772000FFF766FF6946097C002909D021680968CA0A31001140C9B20029C8
S32520005DF001D1052108006946097C002909D1216809680A0B31001140C9B2002901D1052109
S32520005E1008000100C9B200290BD169464978002907D021683200D2B2520380239B011A4026
S32520005E300A60C0B205B0F0BD10B50400824804602000FFF7DDFE0020E06110BDF3B595B0EB
S32520005E5000273800694608707B48046815988005800D002803D0012069460870E7E0380056
S32520005E703D001698854200D3E1E0206801260068C10930000840C0B2002803D10920694607
S32520005E900870D4E02000FFF7B3FE05216846017338006A469071206814900997FF2013901A
S32520005EB0149A6B469B79D218137F139A93439C466A46137B139A1A4063461A430992099BCE
S32520005ED09C46149B6A4692799A1863461377159A6B46DA7232006B465A7122681292089734
S32520005EF01190129A6B465B79D218137F119A93439C466A46D37A119A1A4063461A43089219
S32520005F10089B9C46129B6A4652799A1863461377159AAB02D218120A6B469A7202226B46C5
S32520005F301A712268109207970F90109A6B461B79D218137F0F9A93439C466A46937A0F9A05
S32520005F501A4063461A430792079B9C46109B6A4612799A1863461377159AAB02D218120C5F
S32520005F706B465A7203226B46DA7022680E9206970D900E9A6B46DB78D218137F0D9A934345
S32520005F909C466A46537A0D9A1A4063461A430692069B9C460E9B6A46D2789A1863461377C2
S32520005FB0159AAB02D218120E6B461A7204226B469A7022680C9205970B900C9A6B469B785E
S32520005FD0D218137F0B9A93439C466A46137A0B9A1A4063461A430592059B9C460C9B6A4600
S32520005FF092789A18634613776A46D6716A465170266804970A90684640783018007F0A9981
S3252000601088436946C9790A9A0A4002430492049869464978711808772000FFF73CFE6946B2
S32520006030087068460078002801D16D1C19E76846007817B0F0BD0000F05B0020F7B598B010
S325200060500025280069464874874800680190072018990140002901D0012501E11A99084074
S32520006070002801D00325FBE028006946087002950B950198006801270068C10A380008408C
S32520006090C0B2012802D138006946087068460078002803D000210198FFF729FE18988005D0
S325200060B0800D0B900B98A021490544182E001A98864205D21998805D2070641C761CF6E7E8
S325200060D0019800680068C10938000840C0B2002801D10925BCE00198FFF78AFD06206946B6
S325200060F008742800694688720198006816900A95FF20159016996A46927A8918097F159AD0
S3252000611091436A46137C159A1A400A430A920A9A16996B469B7AC9180A7718996A46D17324
S3252000613069464F720199096814910995139014996A46527A8918097F139A91436A46D27BF8
S32520006150139B13400B4309930999149A6B465B7AD21811771899090A6A46917302216A468B
S3252000617011720199096812910895119012996A46127A8918097F119A91436A46927B119B82
S3252000619013400B4308930899129A6B461B7AD21811771899090C6A46517303216A46D17039
S325200061B001990968109107950F9010996A46D2788918097F0F9A91436A46527B0F9B1340FF
S325200061D00B4307930799109A6B46DB78D21811771899090E6A46117304216A469170019975
S325200061F009680E9106950D900E996A4692788918097F0D9A91436A46127B0D9B13400B4396
S32520006210069306990E9A6B469B78D21811771A99C908491E6A46D17205216A465170019923
S325200062300F6805950C90684640783818007F0C9988436946C97A0C9A0A400243059205987B
S3252000625069464978791808770198FFF724FD050068460078002803D001210198FFF747FDBD
S325200062702800C0B21BB0F0BDF05B0020FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F
S32520006290FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE8
S325200062B0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC8
S325200062D0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA8
S325200062F0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF88
S32520006310FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF67
S32520006330FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF47
S32520006350FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF27
S32520006370FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF07
S32520006390FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE7
S325200063B0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7
S325200063D0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF10CACC19E4
S70500000001F9

View File

@ -0,0 +1,146 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _CRC_H_
#define _CRC_H_
/*! \brief Contains public interface to various functions related
* to the CRC algorithms
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*! \brief The CRC table
*/
static const uint16_t c_crcTable[] =
{
0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241,
0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440,
0XCC01, 0X0CC0, 0X0D80, 0XCD41, 0X0F00, 0XCFC1, 0XCE81, 0X0E40,
0X0A00, 0XCAC1, 0XCB81, 0X0B40, 0XC901, 0X09C0, 0X0880, 0XC841,
0XD801, 0X18C0, 0X1980, 0XD941, 0X1B00, 0XDBC1, 0XDA81, 0X1A40,
0X1E00, 0XDEC1, 0XDF81, 0X1F40, 0XDD01, 0X1DC0, 0X1C80, 0XDC41,
0X1400, 0XD4C1, 0XD581, 0X1540, 0XD701, 0X17C0, 0X1680, 0XD641,
0XD201, 0X12C0, 0X1380, 0XD341, 0X1100, 0XD1C1, 0XD081, 0X1040,
0XF001, 0X30C0, 0X3180, 0XF141, 0X3300, 0XF3C1, 0XF281, 0X3240,
0X3600, 0XF6C1, 0XF781, 0X3740, 0XF501, 0X35C0, 0X3480, 0XF441,
0X3C00, 0XFCC1, 0XFD81, 0X3D40, 0XFF01, 0X3FC0, 0X3E80, 0XFE41,
0XFA01, 0X3AC0, 0X3B80, 0XFB41, 0X3900, 0XF9C1, 0XF881, 0X3840,
0X2800, 0XE8C1, 0XE981, 0X2940, 0XEB01, 0X2BC0, 0X2A80, 0XEA41,
0XEE01, 0X2EC0, 0X2F80, 0XEF41, 0X2D00, 0XEDC1, 0XEC81, 0X2C40,
0XE401, 0X24C0, 0X2580, 0XE541, 0X2700, 0XE7C1, 0XE681, 0X2640,
0X2200, 0XE2C1, 0XE381, 0X2340, 0XE101, 0X21C0, 0X2080, 0XE041,
0XA001, 0X60C0, 0X6180, 0XA141, 0X6300, 0XA3C1, 0XA281, 0X6240,
0X6600, 0XA6C1, 0XA781, 0X6740, 0XA501, 0X65C0, 0X6480, 0XA441,
0X6C00, 0XACC1, 0XAD81, 0X6D40, 0XAF01, 0X6FC0, 0X6E80, 0XAE41,
0XAA01, 0X6AC0, 0X6B80, 0XAB41, 0X6900, 0XA9C1, 0XA881, 0X6840,
0X7800, 0XB8C1, 0XB981, 0X7940, 0XBB01, 0X7BC0, 0X7A80, 0XBA41,
0XBE01, 0X7EC0, 0X7F80, 0XBF41, 0X7D00, 0XBDC1, 0XBC81, 0X7C40,
0XB401, 0X74C0, 0X7580, 0XB541, 0X7700, 0XB7C1, 0XB681, 0X7640,
0X7200, 0XB2C1, 0XB381, 0X7340, 0XB101, 0X71C0, 0X7080, 0XB041,
0X5000, 0X90C1, 0X9181, 0X5140, 0X9301, 0X53C0, 0X5280, 0X9241,
0X9601, 0X56C0, 0X5780, 0X9741, 0X5500, 0X95C1, 0X9481, 0X5440,
0X9C01, 0X5CC0, 0X5D80, 0X9D41, 0X5F00, 0X9FC1, 0X9E81, 0X5E40,
0X5A00, 0X9AC1, 0X9B81, 0X5B40, 0X9901, 0X59C0, 0X5880, 0X9841,
0X8801, 0X48C0, 0X4980, 0X8941, 0X4B00, 0X8BC1, 0X8A81, 0X4A40,
0X4E00, 0X8EC1, 0X8F81, 0X4F40, 0X8D01, 0X4DC0, 0X4C80, 0X8C41,
0X4400, 0X84C1, 0X8581, 0X4540, 0X8701, 0X47C0, 0X4680, 0X8641,
0X8201, 0X42C0, 0X4380, 0X8341, 0X4100, 0X81C1, 0X8081, 0X4040
};
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Calculates the CRC16 result
*
* This function implements the CRC16 calculation
*
* \param[in] pData : the input byte array
* \param[in] length : the length of input array
* \return the CRC16 result
*/
static inline uint16_t Crc_CalcCrc16(const uint8_t *pData, uint32_t length)
{
uint8_t tmp;
uint16_t crcWord = 0xFFFF;
while(length--)
{
tmp = *pData++ ^ crcWord;
crcWord >>= 8;
crcWord ^= c_crcTable[tmp];
}
return crcWord;
}
/*! \brief Calculates the CRC8 result
*
* This function implements the CRC8 calculation
*
* \param[in] pData : the input byte array
* \param[in] length : the length of input array
* \param[in] polynomial : the polynomial used for the calculation
* \return the CRC8 result
*/
static inline uint8_t Crc_CalcCrc8(const uint8_t *pData, uint32_t length, uint8_t polynomial)
{
uint8_t bitIndex = 0;
uint8_t byteIndex = 0;
uint8_t crc = 0xFF;
for(byteIndex = 0; byteIndex < length; ++byteIndex)
{
crc ^= pData[byteIndex];
for(bitIndex = 0; bitIndex < 8; ++bitIndex)
{
if((crc & 0x80) != 0)
{
crc = (crc << 1) ^ polynomial;
}
else
{
crc = (crc << 1);
}
}
}
return ~crc;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _CRC_H_ */

View File

@ -0,0 +1,333 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _LIST_H_
#define _LIST_H_
/*! \brief Contains public interface to various functions related
* to a wrapped linked-list
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of LIST object
*/
typedef struct _ListNode_
{
int32_t nextIndex; /*!< next index value */
void *pElement; /*!< the pointer to the element */
} ListNode;
/*! \brief Declaration of LIST object
*/
typedef struct _ListType_
{
ListNode *nodeArray; /*!< the pointer to the nodes, which must be an 1-D array */
uint32_t containerSize; /*!< the size of the container */
uint32_t length; /*!< the length of list */
ListNode head; /*!< the head node */
} ListType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the LIST object.
*
* This function initialize the LIST instance
*
* \param[in] obj : pointer to List instance
* \param[in] pNodes : pointer to node
* \param[in] pContainer : pointer to container
* \param[in] elemSize : element size in byte
* \param[in] containerSize : the size of the container
*/
static inline void List_Init(ListType *obj, ListNode *pNodes, void *pContainer, uint32_t elemSize, uint32_t containerSize)
{
obj->nodeArray = pNodes;
obj->containerSize = containerSize;
uint32_t i = 0;
for(i = 0; i < obj->containerSize; ++i)
{
obj->nodeArray[i].pElement = (void *)((unsigned char *)pContainer + i * elemSize);
obj->nodeArray[i].nextIndex = -1; /* Next index is -1 representing not occupied */
}
obj->head.nextIndex = obj->containerSize; /* next index = containerSize Mark the list */
obj->head.pElement = NULL;
obj->length = 0;
}
/*! \brief Get the length of the list
*
* This function get the length of the list
*
* \param[in] obj : pointer to List instance
* \return The length
*/
static inline uint32_t List_Length(const ListType *obj)
{
return obj->length;
}
/*! \brief Insert the element at the given index
*
* This function insert the element at the given index.
*
* \note If the given index is larger than the last element index+1,
* or the vector is full, the function will do nothing
*
* \param[in] obj : pointer to List instance
* \param[in] pElem : the pointer to the element
* \param[in] elemSize : the element size
* \param[in] index : the index to insert
* \return the result of the operation
* - true : success
* - false : fail
*/
static inline bool List_Insert(ListType *obj, const void *pElem, uint32_t elemSize, uint32_t index)
{
/* If full, we cannot insert more elements */
if(obj->length == obj->containerSize)
{
return false;
}
/* If no enough elements*/
if(index > obj->length)
{
return false;
}
/* Find first node not occupied*/
uint32_t actualIndex = 0;
bool actualIndexFound = false;
uint32_t i = 0;
for(i = 0; i < obj->containerSize; ++i)
{
if(obj->nodeArray[i].nextIndex == -1)
{
actualIndexFound = true;
actualIndex = i;
break;
}
}
if(actualIndexFound == false)
{
return false; /* Must found */
}
/* Assign the value */
unsigned char *src = (unsigned char *)pElem;
unsigned char *dest = (unsigned char *)(obj->nodeArray[actualIndex].pElement);
uint32_t byte;
for(byte = 0; byte < elemSize; byte++)
{
*dest++ = *src++;
}
/* Find the previous node */
if(index == 0)
{
/* Insert at the first node */
obj->nodeArray[actualIndex].nextIndex = obj->head.nextIndex; /* Replace the first valid data node */
obj->head.nextIndex = actualIndex; /* Mark the new first node */
}
else
{
uint32_t prevIndex = obj->head.nextIndex;
for(i = 0; i < index - 1; ++i)
{
prevIndex = obj->nodeArray[prevIndex].nextIndex;
}
obj->nodeArray[actualIndex].nextIndex = obj->nodeArray[prevIndex].nextIndex;
obj->nodeArray[prevIndex].nextIndex = actualIndex;
}
/* Increase the length */
obj->length++;
return true;
}
/*! \brief Get the element at the given index
*
* This function gets the element at the given index
*
* \note index must be in the range of 0-size
*
* \param[in] obj : pointer to List instance
* \param[out] pElem : pointer to the element to get
* \param[in] elemSize : size of element
* \param[in] index : index of the element to get
* \return result of the operation
* - true : success
* - false : failed
*/
static inline bool List_GetElement(const ListType *obj, void *pElem, uint32_t elemSize, uint32_t index)
{
if(index >= obj->length)
{
return false;
}
uint32_t i = 0;
uint32_t actualIndex = obj->head.nextIndex;
for(i = 0; i < index; ++i)
{
actualIndex = obj->nodeArray[actualIndex].nextIndex;
}
unsigned char *dest = (unsigned char *)pElem;
unsigned char *src = (unsigned char *)(obj->nodeArray[actualIndex].pElement);
for(i = 0; i < elemSize; i++)
{
*dest++ = *src++;
}
return true;
}
/*! \brief Get the element at the given index
*
* This function gets the element at the given index
*
* \note index must be in the range of 0-size-1
*
* \param[in] obj : pointer to List instance
* \param[in] elemSize : the element size
* \param[in] index : the index to get
* \return the pointer to the element
*/
static inline const void *List_At(const ListType *obj, uint32_t elemSize, uint32_t index)
{
if(index >= obj->length)
{
return ((void *)0);
}
uint32_t i = 0;
uint32_t actualIndex = obj->head.nextIndex;
for(i = 0; i < index; ++i)
{
actualIndex = obj->nodeArray[actualIndex].nextIndex;
}
return obj->nodeArray[actualIndex].pElement;
}
/*! \brief Clear the whole vector
*
* This function clears the whole vector
*
* \param[in] obj : pointer to List instance
*/
static inline void List_Clear(ListType *obj)
{
uint32_t i = 0;
for(i = 0; i < obj->containerSize; ++i)
{
obj->nodeArray[i].nextIndex = -1; /* Next index is -1 representing not occupied */
}
obj->head.nextIndex = obj->containerSize;
obj->head.pElement = NULL;
obj->length = 0;
}
/*! \brief Remove the element at the given index
*
* This function removes the element at the given index
*
* \param[in] obj : pointer to List instance
*/
static inline bool List_Remove(ListType *obj, uint32_t elemSize, uint32_t index)
{
/* If empty, we cannot remove any elements */
if(obj->length == 0)
{
return false;
}
/* If no enough elements */
if(index >= obj->length)
{
return false;
}
/* Find the previous node */
if(index == 0)
{
/* Remove the first node */
uint32_t currentIndex = obj->head.nextIndex;
obj->head.nextIndex = obj->nodeArray[obj->head.nextIndex].nextIndex;
obj->nodeArray[currentIndex].nextIndex = -1; /* Mark unoccupied */
}
else
{
uint32_t prevIndex = obj->head.nextIndex;
uint32_t i = 0;
for(i = 0; i < index - 1; ++i)
{
prevIndex = obj->nodeArray[prevIndex].nextIndex;
}
uint32_t currentIndex = obj->nodeArray[prevIndex].nextIndex;
obj->nodeArray[prevIndex].nextIndex = obj->nodeArray[currentIndex].nextIndex;
obj->nodeArray[currentIndex].nextIndex = -1; /* Mark unoccupied */
}
/* Decrease the length */
obj->length--;
return true;
}
/*! \brief Whether the list is full
*
* This function returns whether the list is full.
*
* \param[in] obj : pointer to List instance
*/
static inline bool List_IsFull(const ListType *obj)
{
return obj->length == obj->containerSize;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _LIST_H_ */

View File

@ -0,0 +1,194 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _RINGBUFFER_H_
#define _RINGBUFFER_H_
/*! \brief Contains public interface to various functions related
* to the ring buffer template
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief RingBuffer prototype definition
*/
typedef struct _RingBufferType_
{
void *pBuffer; /*!< The actual buffer holder */
int32_t readIndex; /*!< The current index for the read */
int32_t writeIndex; /*!< The current index for the write */
int32_t usedNum; /*!< The number of used elements */
int32_t totalNum; /*!< The number of total elements */
} RingBufferType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initializes the ringbuffer instance
*
* This function initializes a ringbuffer instance
*
* \param[in] obj : pointer to RingBuffer instance
* \param[in] pBuffer : the actual buffer holder
* \param[in] size : the size of actual buffer holder
*/
static inline void RingBuffer_Init(RingBufferType *obj, void *pBuffer, uint32_t size)
{
obj->pBuffer = pBuffer;
obj->readIndex = 0;
obj->writeIndex = 0;
obj->usedNum = 0;
obj->totalNum = size;
}
/*! \brief Puts an element to the ringbuffer.
*
* This function puts an element to the ringbuffer.
*
* \param[in] obj : pointer to RingBuffer instance
* \param[in] pElem : pointer to the element to push into the buffer
* \param[in] size : the size of the element in bytes
* \return the result of the put operation
* true : success
* false : failed because the buffer is full
*/
static inline bool RingBuffer_Put(RingBufferType *obj, const void *pElem, uint32_t size)
{
uint32_t i = 0;
unsigned char *src;
unsigned char *dest;
/* Check if the buffer is full */
if(obj->usedNum >= obj->totalNum)
{
return false;
}
/* Copy the element */
src = (unsigned char *)pElem;
dest = (unsigned char *)obj->pBuffer + (obj->writeIndex * size);
for(i = 0; i < size; i++)
{
*dest++ = *src++;
}
/* Move the index */
obj->writeIndex++;
if(obj->writeIndex >= obj->totalNum)
{
obj->writeIndex = 0;
}
obj->usedNum++;
return true;
}
/*! \brief Gets an element from the ringbuffer.
*
* This function gets an element from the ringbuffer.
*
* \param[in] obj : pointer to RingBuffer instance
* \param[in] pElem : pointer to the element to get from the buffer
* \param[in] size : the size of the element in bytes
* \return the result of the put operation
* true : success
* false : failed because the buffer is empty
*/
static inline bool RingBuffer_Get(RingBufferType *obj, void *pElem, uint32_t size)
{
uint32_t i = 0;
unsigned char *src;
unsigned char *dest;
/* Check if the buffer is empty */
if(obj->usedNum <= 0)
{
return false;
}
/* Copy the element */
dest = (unsigned char *)pElem;
src = (unsigned char *)obj->pBuffer + (obj->readIndex * size);
for(i = 0; i < size; i++)
{
*dest++ = *src++;
}
/* Move the index */
obj->readIndex++;
if(obj->readIndex >= obj->totalNum)
{
obj->readIndex = 0;
}
obj->usedNum--;
return true;
}
/*! \brief See if the ringbuffer is full.
*
* This function gets if the ringbuffer is full
*
* \param[in] obj : pointer to RingBuffer instance
* \return whether the buffer is full
* true : the buffer is full
* false : the buffer is not full
*/
static inline bool RingBuffer_IsFull(const RingBufferType *obj)
{
return (obj->usedNum >= obj->totalNum);
}
/*! \brief See if the ringbuffer is empty.
*
* This function gets if the ringbuffer is empty
*
* \param[in] obj : pointer to RingBuffer instance
* \return whether the buffer is empty
* true : the buffer is empty
* false : the buffer is not empty
*/
static inline bool RingBuffer_IsEmpty(const RingBufferType *obj)
{
return (obj->usedNum <= 0);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _RINGBUFFER_H_ */

View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _TABLE_H_
#define _TABLE_H_
/*! \brief Contains public interface to various functions related
* to the table template
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of table prototype
* The container should be an array in the form of buffer[rowNum][columnNum]
*/
typedef struct _TableType_
{
void *pContainer; /*!< The pointer to the container, which must be a 2-D array */
uint16_t rowNum; /*!< Total row number of the container */
uint16_t columnNum; /*!< Total column number of the container */
} TableType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the TABLE object.
*
* This function initializes a 2-D table instance
*
* \note The container should be the 2-D array
*
* \param[in] obj : pointer to Table instance
* \param[in] pContainer : the container (2-D array) for this table
* \param[in] rowNum : the total row count of the table
* \param[in] columnNum : the total column count of the table
*/
static inline void Table_Init(TableType *obj, void *pContainer, uint16_t rowNum, uint16_t columnNum)
{
obj->pContainer = pContainer;
obj->rowNum = rowNum;
obj->columnNum = columnNum;
}
/*! \brief Get a certain element determined by row and column from the table
*
* This function gets a certain element determined by row and column from the table
*
* \param[in] obj : pointer to Table instance
* \param[out] pElem : pointer to the element
* \param[in] elemSize : the size of element in byte
* \param[in] row : the row of the output element
* \param[in] column : the column of the output element
* \return the result of the get operation
* - true : succees
* - false : fail to get the element
*/
static inline bool Table_GetElement(const TableType *obj, void *pElem, uint16_t elemSize, uint16_t row, uint16_t column)
{
if(row > obj->rowNum - 1 || column > obj->columnNum - 1)
{
return false;
}
int i = 0;
unsigned char *src;
unsigned char *dest;
dest = (unsigned char *)pElem;
src = (unsigned char *)(obj->pContainer) + elemSize * (row * obj->columnNum + column);
for(i = 0; i < elemSize; i++)
{
*dest++ = *src++;
}
return true;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _TABLE_H_ */

View File

@ -0,0 +1,122 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _TABLE3D_H_
#define _TABLE3D_H_
/*! \brief Contains public interface to various functions related
* to the 3-D table template
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of 3-D table prototype
* \note The container should be an array in the form of buffer[depthNum][rowNum][columnNum]
*/
typedef struct _Table3DType_
{
void *pContainer; /*!< The pointer to the container, which must be a 3-D array */
uint16_t rowNum; /*!< Total row number of the container */
uint16_t columnNum; /*!< Total column number of the container */
uint16_t depthNum; /*!< Total depth number of the container */
} Table3DType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the TABLE 3D object.
*
* This function initializes a 3-D table instance
*
* \note The container should be the 3-D array
*
* \param[in] obj : pointer to 3-D Table instance
* \param[in] pContainer : the container (3-D array) for this table
* \param[in] rowNum : the total row count of the table
* \param[in] columnNum : the total column count of the table
* \param[in] depthNum : the total depth count of the table
*/
static inline void Table3D_Init(Table3DType *obj, void *pContainer, uint16_t rowNum, uint16_t columnNum, uint16_t depthNum)
{
obj->pContainer = pContainer;
obj->rowNum = rowNum;
obj->columnNum = columnNum;
obj->depthNum = depthNum;
}
/*! \brief Get a certain element determined by row, column, depth from the table
*
* This function gets a certain element determined by row, column, depth from the table
*
* \param[in] obj : pointer to 3-D Table instance
* \param[out] pElem : pointer to the element
* \param[in] elemSize : the size of element in byte
* \param[in] row : the row of the output element
* \param[in] column : the column of the output element
* \param[in] depth : the depth of the output element
* \return the result of the get operation
* - true : succees
* - false : fail to get the element
*/
static inline bool Table3D_GetElement(const Table3DType *obj, void *pElem, uint16_t elemSize, uint16_t row, uint16_t column, uint16_t depth)
{
if(row > obj->rowNum - 1 || column > obj->columnNum - 1 || depth > obj->depthNum - 1)
{
return false;
}
int i = 0;
unsigned char *src;
unsigned char *dest;
dest = (unsigned char *)pElem;
src = (unsigned char *)(obj->pContainer) + elemSize * (depth * obj->rowNum * obj->columnNum + row * obj->columnNum + column);
for(i = 0; i < elemSize; i++)
{
*dest++ = *src++;
}
return true;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _TABLE3D_H_ */

View File

@ -0,0 +1,301 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _VECTOR_H_
#define _VECTOR_H_
/*! \brief Contains public interface to various functions related
* to a wrapped fix-size array
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of Vector prototype
*/
typedef struct _VectorType_
{
void *pContainer; /*!< The pointer to the container, which must be an 1-D array */
uint32_t containerSize; /*!< The size of the container */
uint32_t length; /*!< The current occupied length */
} VectorType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initializes the Vector instance.
*
* This function initializes the Vector instance
*
* \param[in] obj : pointer to Vector instance
* \param[in] pContainer : the container (1-D array) for this table
* \param[in] size : the size of the container array
*/
static inline void Vector_Init(VectorType *obj, void *pContainer, uint32_t size)
{
obj->pContainer = pContainer;
obj->containerSize = size;
obj->length = 0;
}
/*! \brief Gets the current length of the vector
*
* This function gets the current length of the vector
*
* \param[in] obj : pointer to Vector instance
* \return the current length of the vector
*/
static inline uint32_t Vector_Length(const VectorType *obj)
{
return obj->length;
}
/*! \brief Inserts an element at the given index
*
* This function inserts an element at the given index
*
* \note If the given index is larger than the last element index+1,
* or the vector is full, the function will do nothing
*
* \param[in] obj : pointer to Vector instance
* \param[in] pElem : pointer to the element
* \param[in] elemSize : the size of element in byte
* \param[in] index : index where the element is inserted
* \return the result of the insert operation
* - true : success
* - false : failed
*/
static inline bool Vector_Insert(VectorType *obj, const void *pElem, uint32_t elemSize, uint32_t index)
{
/* If full, we cannot insert more elements */
if(obj->length == obj->containerSize)
{
return false;
}
/* If no enough elements */
if(index > obj->length)
{
return false;
}
unsigned char *src;
unsigned char *dest;
/* Move items by one position in memory */
if(obj->length > 0)
{
uint32_t i = 0;
for(i = obj->length; i > index; --i)
{
src = (unsigned char *)(obj->pContainer) + elemSize * (i - 1);
dest = (unsigned char *)(obj->pContainer) + elemSize * i;
uint32_t byte;
for(byte = 0; byte < elemSize; byte++)
{
*dest++ = *src++;
}
}
}
/* Assign the value */
src = (unsigned char *)pElem;
dest = (unsigned char *)(obj->pContainer) + elemSize * index;
uint32_t byte;
for(byte = 0; byte < elemSize; byte++)
{
*dest++ = *src++;
}
/* Increase the length */
obj->length++;
return true;
}
/*! \brief Gets the element at the given index
*
* This function gets the element at the given index
*
* \note index must be in the range of 0-size
*
* \param[in] obj : pointer to Vector instance
* \param[in] pElem : pointer to the element
* \param[in] elemSize : the size of element in byte
* \param[in] index : index of the element to get
* \return the result of the get operation
* - true : success
* - false : failed
*/
static inline bool Vector_GetElement(const VectorType *obj, void *pElem, uint32_t elemSize, uint32_t index)
{
if(index >= obj->length)
{
return false;
}
int i = 0;
unsigned char *src;
unsigned char *dest;
dest = (unsigned char *)pElem;
src = (unsigned char *)(obj->pContainer) + elemSize * index;
for(i = 0; i < elemSize; i++)
{
*dest++ = *src++;
}
return true;
}
/*! \brief Get the pointer to the element at the given index
*
* This function gets the pointer to the element at the given index
*
* \note index must be in the range of 0-size
*
* \param[in] obj : pointer to Vector instance
* \param[in] elemSize : the size of element in byte
* \param[in] index : index of the element to get
* \return pointer to the element
*/
static inline const void *Vector_At(const VectorType *obj, uint32_t elemSize, uint32_t index)
{
if(index >= obj->length)
{
return ((void *)0);
}
return (void *)((unsigned char *)(obj->pContainer) + elemSize * index);
}
/*! \brief Clears the whole vector
*
* This function clears the whole vector
*
* \param[in] obj : pointer to Vector instance
*/
static inline void Vector_Clear(VectorType *obj)
{
obj->length = 0;
}
/*! \brief Remove the element at the given index
*
* This function removes the element at the at the given index
*
* \param[in] obj : pointer to Vector instance
* \param[in] elemSize : the size of element in byte
* \param[in] index : index of the element to remove
* \return the result of the remove operation
* - true : success
* - false : failed
*/
static inline bool Vector_Remove(VectorType *obj, uint32_t elemSize, uint32_t index)
{
/* If empty, we cannot remove any elements */
if(obj->length == 0)
{
return false;
}
/* If no enough elements */
if(index >= obj->length)
{
return false;
}
unsigned char *src;
unsigned char *dest;
/* Move items by one position in memory */
if(obj->length - 1 > index)
{
uint32_t i = 0;
for(i = index; i < obj->length; ++i)
{
src = (unsigned char *)(obj->pContainer) + elemSize * (i + 1);
dest = (unsigned char *)(obj->pContainer) + elemSize * i;
uint32_t byte;
for(byte = 0; byte < elemSize; byte++)
{
*dest++ = *src++;
}
}
}
/* Decrease the length */
obj->length--;
return true;
}
/*! \brief Whether the vector is full
*
* This function gets whether the vector is full
*
* \param[in] obj : pointer to Vector instance
* \return whether the vector is full
* - true : full
* - false : not full
*/
static inline bool Vector_IsFull(const VectorType *obj)
{
return obj->length == obj->containerSize;
}
/*! \brief Whether the vector is empty
*
* This function gets whether the vector is empty
*
* \param[in] obj : pointer to Vector instance
* \return whether the vector is empty
* - true : empty
* - false : not empty
*/
static inline bool Vector_IsEmpty(const VectorType *obj)
{
return obj->length == 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _VECTOR_H_ */

View File

@ -0,0 +1,157 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _GRADIENT_H_
#define _GRADIENT_H_
/*! \brief Contains public interface to various functions related
* to the 1st order linear curve with GRADIENT
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of Gradient Class
*
*/
typedef struct _GradientType_
{
_iq target; /*!< Input: target input */
_iq upStep; /*!< Parameter: up step of ramp */
_iq downStep; /*!< Parameter: down step of ramp */
_iq output; /*!< Output: output value */
} GradientType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the Gradient instance
*
* This function initializes the Gradient instance
*
* \param[in] obj : pointer to Gradient instance
* \param[in] upStep : step when going up
* \param[in] downStep : step when going down
*/
static inline void Gradient_Init(GradientType *obj, _iq upStep, _iq downStep)
{
obj->target = 0;
obj->output = 0;
obj->upStep = upStep;
obj->downStep = downStep;
}
/*! \brief Calculates the output
*
* This function calculates the output
*
* \param[in] obj : pointer to Gradient instance
*/
static inline void Gradient_Calc(GradientType *obj)
{
_iq upStep = _IQabs(obj->upStep); /* step must be a positive value */
_iq downStep = _IQabs(obj->downStep); /* step must be a positive value */
if(obj->target > obj->output)
{
if((obj->target - obj->output) > upStep)
{
obj->output += upStep;
}
else
{
obj->output = obj->target; /* less than one step needed, just jump to the target */
}
}
else if(obj->target < obj->output)
{
if((obj->output - obj->target) > downStep)
{
obj->output -= downStep;
}
else
{
obj->output = obj->target; /* less than one step needed, just jump to the target */
}
}
}
/*! \brief Calculate the output using the external reference
*
* This function calculates the output using the external reference,
* instead of the internal output
*
* \param[in] obj : pointer to Gradient instance
* \param[in] pOutput : pointer to external output
*/
static inline void Gradient_CalcExternal(GradientType *obj, _iq *pOutput)
{
_iq upStep = _IQabs(obj->upStep); /* step must be a positive value */
_iq downStep = _IQabs(obj->downStep); /* step must be a positive value */
if(obj->target > (*pOutput))
{
if((obj->target - (*pOutput)) > upStep)
{
(*pOutput) += upStep;
}
else
{
(*pOutput) = obj->target; /* less than one step needed, just jump to the target */
}
}
else if(obj->target < (*pOutput))
{
if(((*pOutput) - obj->target) > downStep)
{
(*pOutput) -= downStep;
}
else
{
(*pOutput) = obj->target; /* less than one step needed, just jump to the target */
}
}
obj->output = *pOutput; /* We don't use the obj->output normally in this function, just be safe */
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _GRADIENT_H_ */

View File

@ -0,0 +1,107 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _RAMP_H_
#define _RAMP_H_
/*! \brief Contains public interface to various functions related
* to the ramp object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of Ramp Class
*/
typedef struct _RampType_
{
_iq target; /*!< Input: target input */
_iq step; /*!< Parameter: step of ramp */
_iq output; /*!< Output: output value */
} RampType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the Ramp instance
*
* This function initializes the Ramp instance
*
* \param[in] obj : pointer to Ramp instance
* \param[in] Step : step of going up and down
*/
static inline void Ramp_Init(RampType *obj, _iq step)
{
obj->target = 0;
obj->output = 0;
obj->step = step;
}
/*! \brief Calculates the output
*
* This function calculates the output
*
* \param[in] obj : pointer to Ramp instance
*/
static inline void Ramp_Calc(RampType *obj)
{
_iq step = _IQabs(obj->step); /* step must be a positive value */
if(_IQabs(obj->target - obj->output) > step)
{
if(obj->target > obj->output)
{
obj->output += step;
}
else
{
obj->output -= step;
}
}
else
{
/* less than one step needed, just jump to the target */
obj->output = obj->target;
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _RAMP_H_ */

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _AVERAGE_H_
#define _AVERAGE_H_
/*! \brief Contains public interface to various functions related
* to the Averaging with sliding window (AVERAGE) filter object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct _AverageType_
{
bool isInitial; /*!< Internal variable: Flag to indicate initial state */
_iq *pBuffer; /*!< Internal variable: The pointer to the buffer */
uint16_t winSize; /*!< Internal variable: window length */
uint16_t index; /*!< Internal variable: index of the value ready to pop */
_iq sum; /*!< Internal variable: the sum of all the values in buffer */
_iq output; /*!< Output: The output value */
} AverageType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the AVERAGE object
*
* This function initializes the average instance.
*
* \param[in] obj : pointer to Average instance
* \param[in] buffer : filter buffer
* \param[in] bufferSize : size of buffer
*/
static inline void Average_Init(AverageType *obj, _iq buffer[], uint16_t bufferSize)
{
obj->pBuffer = &buffer[0];
obj->winSize = bufferSize;
for(obj->index = 0; obj->index < obj->winSize; obj->index++)
{
obj->pBuffer[obj->index] = 0;
}
obj->index = 0;
obj->isInitial = true;
obj->sum = 0;
obj->output = 0;
}
/*! \brief Push input to the filter
*
* This function pushes input to the filter.
*
* \param[in] obj : pointer to Average instance
* \param[in] input : input value to be filter
*/
static inline void Average_PushInput(AverageType *obj, _iq input)
{
if(obj->isInitial)
{
obj->output = input;
obj->isInitial = false;
}
else
{
obj->sum = obj->sum - obj->pBuffer[obj->index] + input;
obj->pBuffer[obj->index] = input;
obj->index++;
if(obj->index > obj->winSize - 1)
{
obj->index = 0;
}
obj->output = obj->sum / obj->winSize;
}
}
/*! \brief Get the output value
*
* This function gets the filter result.
*
* \param[in] obj : pointer to Average instance
* \return the filter result in IQ format
*/
static inline _iq Average_GetOutput(const AverageType *obj)
{
return obj->output;
}
/*! \brief Reset the filter
*
* This function resets the filter to the initial state.
*
* \param[in] obj : pointer to Average instance
*/
static inline void Average_Reset(AverageType *obj)
{
for(obj->index = 0; obj->index < obj->winSize; obj->index++)
{
obj->pBuffer[obj->index] = 0;
}
obj->index = 0;
obj->isInitial = true;
obj->output = 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _AVERAGE_H_ */

View File

@ -0,0 +1,246 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _BP_SO_H_
#define _BP_SO_H_
/*! \brief Contains public interface to various functions related
* to the 2nd-Order band-pass (BpSo) filter object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the BpSo object
*
* The transfer function is as follows:
*
* 1 - Z^-2
* H(z) = (1-b)-------------------------------------
* 1 - 2*b*cosWn*z^-1 + (2*b - 1)*z^-2
*
* 1
* b = ---------------
* 1+tan(deltaW/2)
*
*
* a1= -2*b*cosWn
*
* a2= 2*b - 1
*
* a3= 1 - b
*/
typedef struct _BpSoType_
{
_iq coeff1; /*!< Parameter: The coefficient of Y(k-1) */
_iq coeff2; /*!< Parameter: The coefficient of Y(k-2) */
_iq coeff3; /*!< Parameter: The coefficient of X(k)-X(k-2) */
bool isInitial; /*!< Internal variable: Has the filter got the first input */
_iq prevOutput; /*!< Internal variable: The previous output cached */
_iq prevPrevOutput; /*!< Internal variable: The previous previous output cached */
_iq prevInput; /*!< Internal variable: The previous input cached */
_iq prevPrevInput; /*!< Internal variable: The previous previous input cached */
_iq output; /*!< Output: The output value */
} BpSoType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initializes the BpSo instance
*
* This function initializes the BpSo instance using the unit of rad/s
*
* \param[in] obj : pointer to BpSo instance
* \param[in] Wc_rps : the center frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaW : 3-dB bandwidth in rad/s
*/
static inline void BpSo_Init(BpSoType *obj, float Wc_rps, float runFreq_kHz, float deltaW)
{
float b = 1 / (tan((deltaW / runFreq_kHz * 0.001) * 0.5) + 1);
float a1 = -2 * b * cos(Wc_rps / runFreq_kHz * 0.001);
float a2 = 2 * b - 1;
float a3 = 1 - b;
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(a3);
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Initializes the BpSo instance, 2nd interface
*
* This function is an overload initialization that
* initialize the BpSo instance using the unit of Hz
*
* \param[in] obj : pointer to BpSo instance
* \param[in] fc_Hz : the center frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaF : 3 dB bandwidth in Hz
*/
static inline void BpSo_Init2(BpSoType *obj, float fc_Hz, float runFreq_kHz, float deltaF)
{
float b = 1 / (tan((MATH_2PI * deltaF / runFreq_kHz * 0.001) * 0.5) + 1);
float a1 = -2 * b * cos(MATH_2PI * fc_Hz / runFreq_kHz * 0.001);
float a2 = 2 * b - 1;
float a3 = 1 - b;
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(a3);
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Push input to the filter
*
* This function is used to push data into the filter
*
* \param[in] obj : pointer to BpSo instance
* \param[in] input : the input data in IQ format
*/
static inline void BpSo_PushInput(BpSoType *obj, _iq input)
{
if(obj->isInitial)
{
obj->output = input;
obj->prevOutput = input;
obj->prevPrevOutput = input;
obj->prevInput = input;
obj->prevPrevInput = input;
obj->isInitial = false;
}
else
{
obj->output = -_IQmpy(obj->prevOutput, obj->coeff1) - _IQmpy(obj->prevPrevOutput, obj->coeff2)
+ _IQmpy(input - obj->prevPrevInput, obj->coeff3);
obj->prevPrevInput = obj->prevInput;
obj->prevInput = input;
obj->prevPrevOutput = obj->prevOutput;
obj->prevOutput = obj->output;
}
}
/*! \brief Gets the output value
*
* This function gets the output of the filter
*
* \param[in] obj : pointer to BpSo instance
* \return the result of the filter in IQ format
*/
static inline _iq BpSo_GetOutput(const BpSoType *obj)
{
return obj->output;
}
/*! \brief Resets the filter
*
* This function resets the filter to initial state
*
* \param[in] obj : pointer to BpSo instance
*/
static inline void BpSo_Reset(BpSoType *obj)
{
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Update the parameters of the filter
*
* This function updates the parameters of the filter using the unit of rad/s
*
* \param[in] obj : pointer to BpSo instance
* \param[in] Wc_rps : the center frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaW : 3-dB bandwidth in rad/s
*/
static inline void BpSo_UpdateParams(BpSoType *obj, float Wc_rps, float runFreq_kHz, float deltaW)
{
float b = 1 / (tan((deltaW / runFreq_kHz * 0.001) * 0.5) + 1);
float a1 = -2 * b * cos(Wc_rps / runFreq_kHz * 0.001);
float a2 = 2 * b - 1;
float a3 = 1 - b;
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(a3);
}
/*! \brief Update the parameters of the filter
*
* This function updates the parameters of the filter using the unit of Hz
*
* \param[in] obj : pointer to BpSo instance
* \param[in] fc_Hz : the center frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaF : 3 dB bandwidth in Hz
*/
static inline void BpSo_UpdateParams2(BpSoType *obj, float fc_Hz, float runFreq_kHz, float deltaF)
{
float b = 1 / (tan((MATH_2PI * deltaF / runFreq_kHz * 0.001) * 0.5) + 1);
float a1 = -2 * b * cos(MATH_2PI * fc_Hz / runFreq_kHz * 0.001);
float a2 = 2 * b - 1;
float a3 = 1 - b;
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(a3);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _BP_SO_H_ */

View File

@ -0,0 +1,245 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _BS_SO_H_
#define _BS_SO_H_
/*! \brief Contains public interface to various functions related
* to the Band-stop (NOTCH) filter object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the BS_SO object
* \note The transfer function is as follows:
*
* 1-2*cosWn*z^-1 + z^-2
* H(z) = b-----------------------------------
* 1 - 2*b*cosWn*z^-1 + (2*b -1)*z^-2
*
* 1
* b = ---------------
* 1+tan(deltaW/2)
*
* a1= -2*b*cosWn
*
* a2= 2*b - 1
*
*/
typedef struct _BsSoType_
{
_iq coeff1; /*!< Parameter: The coefficient of Y(k-1) */
_iq coeff2; /*!< Parameter: The coefficient of Y(k-2) */
_iq coeff3; /*!< Parameter: The coefficient of X(k) */
_iq coeff4; /*!< Parameter: The coefficient of X(k-1) */
_iq coeff5; /*!< Parameter: The coefficient of X(k-2) */
bool isInitial; /*!< Internal variable: Has the filter got the first input */
_iq prevOutput; /*!< Internal variable: The previous output cached */
_iq prevPrevOutput; /*!< Internal variable: The previous previous output cached */
_iq prevInput; /*!< Internal variable: The previous input cached */
_iq prevPrevInput; /*!< Internal variable: The previous previous input cached */
_iq output; /*!< Output: The output value */
} BsSoType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Theoretically initialize the BS_SO object with detailed parameters
*
* This function initializes the BsSo instance using the unit of rad/s
*
* \param[in] obj : pointer to BsSo instance
* \param[in] Wc_rps : the center frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaW : 3-dB bandwidth in rad/s
*/
static inline void BsSo_Init(BsSoType *obj, float Wc_rps, float runFreq_kHz, float deltaW)
{
float b = 1 / (tan((deltaW / runFreq_kHz * 0.001) / 2) + 1);
float a2 = 2 * b - 1;
float a1 = -2 * b * cos(Wc_rps / runFreq_kHz * 0.001);
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(b);
obj->coeff4 = obj->coeff1;
obj->coeff5 = obj->coeff3;
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Theoretically initialize the BS_SO object with detailed parameters, 2nd interface
*
* This function is an overload initialization that
* initialize the BsSo instance using the unit of Hz
*
* \param[in] obj : pointer to BsSo instance
* \param[in] fc_Hz : the center frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaF : 3 dB bandwidth in Hz
*/
static inline void BsSo_Init2(BsSoType *obj, float fc_Hz, float runFreq_kHz, float deltaF)
{
float b = 1 / (tan((MATH_2PI * deltaF / runFreq_kHz * 0.001) / 2) + 1);
float a2 = 2 * b - 1;
float a1 = -2 * b * cos(MATH_2PI * fc_Hz / runFreq_kHz * 0.001);
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(b);
obj->coeff4 = obj->coeff1;
obj->coeff5 = obj->coeff3;
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Push input to the filter
*
* This function is used to push data into the filter
*
* \param[in] obj : pointer to BsSo instance
* \param[in] input : the input data in IQ format
*/
static inline void BsSo_PushInput(BsSoType *obj, _iq input)
{
if(obj->isInitial)
{
obj->output = input;
obj->prevOutput = input;
obj->prevPrevOutput = input;
obj->prevInput = input;
obj->prevPrevInput = input;
obj->isInitial = false;
}
else
{
obj->output = -_IQmpy(obj->prevOutput, obj->coeff1) - _IQmpy(obj->prevPrevOutput, obj->coeff2)
+ _IQmpy(input, obj->coeff3) + _IQmpy(obj->prevInput, obj->coeff4)
+ _IQmpy(obj->prevPrevInput, obj->coeff5);
obj->prevPrevInput = obj->prevInput;
obj->prevInput = input;
obj->prevPrevOutput = obj->prevOutput;
obj->prevOutput = obj->output;
}
}
/*! \brief Gets the output value
*
* This function gets the output of the filter
*
* \param[in] obj : pointer to BsSo instance
* \return the result of the filter in IQ format
*/
static inline _iq BsSo_GetOutput(const BsSoType *obj)
{
return obj->output;
}
/*! \brief Resets the filter
*
* This function resets the filter to initial state
*
* \param[in] obj : pointer to BsSo instance
*/
static inline void BsSo_Reset(BsSoType *obj)
{
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Update the parameters of the filter
*
* This function updates the parameters of the filter with unit rad/s
*
* \param[in] obj : pointer to BsSo instance
* \param[in] Wc_rps : the center frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaW : 3-dB bandwidth in rad/s
*/
static inline void BsSo_UpdateParams(BsSoType *obj, float Wc_rps, float runFreq_kHz, float deltaW)
{
float b = 1 / (tan((deltaW / runFreq_kHz * 0.001) / 2) + 1);
float a2 = 2 * b - 1;
float a1 = -2 * b * cos(Wc_rps / runFreq_kHz * 0.001);
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(b);
obj->coeff4 = obj->coeff1;
obj->coeff5 = obj->coeff3;
}
/*! \brief Update the parameters of the filter
*
* This function update the parameters of the filter with unit Hz
*
* \param[in] obj : pointer to BsSo instance
* \param[in] fc_Hz : the center frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] deltaF : 3 dB bandwidth in Hz
*/
static inline void BsSo_UpdateParams2(BsSoType *obj, float fc_Hz, float runFreq_kHz, float deltaF)
{
float b = 1 / (tan((MATH_2PI * deltaF / runFreq_kHz * 0.001) / 2) + 1);
float a2 = 2 * b - 1;
float a1 = -2 * b * cos(MATH_2PI * fc_Hz / runFreq_kHz * 0.001);
obj->coeff1 = _IQ(a1);
obj->coeff2 = _IQ(a2);
obj->coeff3 = _IQ(b);
obj->coeff4 = obj->coeff1;
obj->coeff5 = obj->coeff3;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _BS_SO_H_ */

View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _DEBOUNCE_H_
#define _DEBOUNCE_H_
/*! \brief Contains public interface to various functions related
* to the debounce (DEBOUNCE) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#include "common/sort/compare.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef enum
{
DEBOUNCE_TYPE_OVER, /*!< Over the threshold is active */
DEBOUNCE_TYPE_UNDER, /*!< Under the threshold is active */
} Debounce_ModeType;
/*! \brief Defines all the parameters used to initialize DEBOUNCE object
*/
typedef struct _Debounce_ParamsType_
{
uint32_t debounceConfirmCntMax; /*!< The max value of the debounce count */
uint32_t debounceRehabCntMax; /*!< The max value of the debounce count */
_iq threshold; /*!< The threshold of the input compare */
Debounce_ModeType compType; /*!< The compare type */
} Debounce_ParamsType;
/*! \brief Defines the DEBOUNCE object
*/
typedef struct _DebounceType_
{
_iq input; /*!< Input: The input value of the debounce */
uint32_t countConfirmMax; /*!< Parameters: The max value of the debounce count */
uint32_t countRehabMax; /*!< Parameters: The max value of the debounce count */
_iq threshold; /*!< Parameters: The threshold of the input compare */
uint32_t count; /*!< Internal variable: The count of the debouncing process */
bool (*comp)(_iq, _iq); /*!< Internal Variable: The compare function pointer */
bool isActive; /*!< Output: Is active after debounce */
} DebounceType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the DEBOUNCE object
*
* This function initialize the debounce instance.
*
* \param[in] obj : pointer to Debounce instance
* \param[in] pParams : The pointer to initial parameters
*/
static inline void Debounce_Init(DebounceType *obj, const Debounce_ParamsType *pParams)
{
obj->countConfirmMax = pParams->debounceConfirmCntMax;
obj->countRehabMax = pParams->debounceRehabCntMax;
obj->threshold = pParams->threshold;
if(pParams->compType == DEBOUNCE_TYPE_UNDER)
{
obj->comp = Compare_SmallerThan;
}
else if(pParams->compType == DEBOUNCE_TYPE_OVER)
{
obj->comp = Compare_GreaterThan;
}
obj->count = 0;
obj->isActive = false;
}
/*! \brief Run the DEBOUNCE process
*
* This function is the calculation of debounce process.
*
* \param[in] obj :pointer to Debounce instance
*/
static inline void Debounce_Run(DebounceType *obj)
{
if(obj->comp(obj->input, obj->threshold))
{
if(obj->isActive)
{
obj->count = 0;
}
else if(++obj->count >= obj->countConfirmMax)
{
obj->isActive = true;
obj->count = 0;
}
}
else
{
if(!obj->isActive)
{
obj->count = 0;
}
else if(++obj->count >= obj->countRehabMax)
{
obj->isActive = false;
obj->count = 0;
}
}
}
/*! \brief Reset the DEBOUNCE object
*
* This function resets the debounce instance to intial state.
*
* \param[in] obj : pointer to Debounce instance
*/
static inline void Debounce_Reset(DebounceType *obj)
{
obj->count = 0;
obj->isActive = false;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _DEBOUNCE_H_ */

View File

@ -0,0 +1,179 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IIR_FO_H_
#define _IIR_FO_H_
/*! \brief Contains public interface to various functions related
* to the 1st-Order IIR (IirFo) low-pass filter object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct _IirFoType_
{
_iq output; /*!< the output value */
bool isInitial; /*!< the flag to indicate whether the instance is initialized */
_iq filterCoeff; /*!< 1st order IIR, y[n] = y[n-1] + coeff*(x[n]-y[n-1]) */
} IirFoType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the IirFo object
*
* This function initializes the 1st-order IIR filter instance
*
* \param[in] obj : pointer to IirFo instance
* \param[in] filterCoeff : the coefficient of the filter
*/
static inline void IirFo_Init(IirFoType *obj, _iq filterCoeff)
{
obj->isInitial = true;
obj->output = 0;
if(filterCoeff > 0 && filterCoeff < _IQ(1.0))
{
obj->filterCoeff = filterCoeff;
}
else
{
obj->filterCoeff = _IQ(1.0); /* Just for protection, normally we don't want this */
}
}
/*! \brief Theoretically initialize the IirFo object with detailed parameters
*
* This function initialize the IirFo object in the theoretical way using the unit rad/s
*
* \note The Wc_rps is the cutoff frequency in the unit of rad/s
*
* \param[in] obj : pointer to IirFo instance
* \param[in] Wc_rps : the cut-off frequency in rad/s
* \param[in] runFreq_kHz : the calculation frequency of the filter
*/
static inline void IirFo_InitTheo(IirFoType *obj, float Wc_rps, float runFreq_kHz)
{
obj->isInitial = true;
obj->output = 0;
_iq filterCoeff = _IQ(Wc_rps / runFreq_kHz * 0.001);
if(filterCoeff > 0 && filterCoeff < _IQ(1.0))
{
obj->filterCoeff = filterCoeff;
}
else
{
obj->filterCoeff = _IQ(1.0); /* Just for protection, normally we don't want this */
}
}
/*! \brief Theoretically initialize the IirFo object with detailed parameters, 2nd interface
*
* This function initialize the IirFo object in the theoretical way using the unit Hz
*
* \note The fc_Hz is the cutoff frequency in the unit of Hz
*
* \param[in] obj : pointer to IirFo instance
* \param[in] fc_Hz : the cut-off frequency in Hz
* \param[in] runFreq_kHz : the calculation frequency of the filter
*/
static inline void IirFo_InitTheo2(IirFoType *obj, float fc_Hz, float runFreq_kHz)
{
obj->isInitial = true;
obj->output = 0;
_iq filterCoeff = _IQ(MATH_2PI * fc_Hz / runFreq_kHz * 0.001);
if(filterCoeff > 0 && filterCoeff < _IQ(1.0))
{
obj->filterCoeff = filterCoeff;
}
else
{
obj->filterCoeff = _IQ(1.0); /* Just for protection, normally we don't want this */
}
}
/*! \brief Push input to the filter
*
* This function push data into the filter
*
* \param[in] obj : pointer to IirFo instance
* \param[in] input : the input data
*/
static inline void IirFo_PushInput(IirFoType *obj, _iq input)
{
if(obj->isInitial)
{
obj->output = input;
obj->isInitial = false;
}
else
{
obj->output = obj->output + _IQmpy(input - obj->output, obj->filterCoeff);
}
}
/*! \brief Get the output value
*
* This function gets the output value.
*
* \param[in] obj : pointer to IirFo instance
* \return the filter result of the filter in IQ format.
*/
static inline _iq IirFo_GetOutput(const IirFoType *obj)
{
return obj->output;
}
/*! \brief Reset the filter
*
* This function reset the filter to the initial state.
*
* \param[in] obj : pointer to IirFo instance
*/
static inline void IirFo_Reset(IirFoType *obj)
{
obj->isInitial = true;
obj->output = 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IIR_FO_H_ */

View File

@ -0,0 +1,271 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IIR_SO_H_
#define _IIR_SO_H_
/*! \brief Contains public interface to various functions related
* to the 1st-Order IIR (IirSo) low-pass filter object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the IirSo object
* \note The transfer function is as follows:
*
* Wc^2
* H(s) = -------------------------
* s^2 + 2*Zeta*Wc*s + Wc^2
*
* The discrete equation uses Tustin method, in which
*
* 2 z - 1
* s = --- * -------
* T z + 1
*
* We add pre-warping to compensate the frequency, in which
*
* 2 T
* W' = --- * tan(W*---)
* T 2
*/
typedef struct _IirSoType_
{
_iq coeff1; /*!< Parameter: The coefficient of Y(k-1) */
_iq coeff2; /*!< Parameter: The coefficient of Y(k-2) */
_iq coeff3; /*!< Parameter: The coefficient of X(k)+2*X(k-1)+X(k-2) */
bool isInitial; /*!< Internal variable: Has the filter got the first input */
_iq prevOutput; /*!< Internal variable: The previous output cached */
_iq prevPrevOutput; /*!< Internal variable: The previous previous output cached */
_iq prevInput; /*!< Internal variable: The previous input cached */
_iq prevPrevInput; /*!< Internal variable: The previous previous input cached */
_iq output;
} IirSoType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the IirSo object
*
* This function initialize the IirSo instance with parameters
*
* \note The Wc_rps is the cutoff frequency in the unit of rad/s
*
* \param[in] obj : pointer to IirSo instance
* \param[in] Wc_rps : the cut-off frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] zeta : the zeta coefficient
*/
static inline void IirSo_Init(IirSoType *obj, float Wc_rps, float runFreq_kHz, float zeta)
{
/* Prewarping */
float twoph = 2000 * runFreq_kHz;
float hptwo = 0.0005 / runFreq_kHz;
Wc_rps = twoph * tan(Wc_rps * hptwo);
_iq tmp = _IQ(Wc_rps / runFreq_kHz * 0.001);
_iq c1 = _IQmpy(tmp, tmp);
_iq c2 = _IQ(zeta * Wc_rps / runFreq_kHz * 0.001);
_iq k = _IQ(1) + c2 + _IQdiv4(c1);
obj->coeff1 = _IQdiv(_IQ(2) - _IQdiv2(c1), k);
obj->coeff2 = _IQdiv(-_IQdiv4(c1) - _IQ(1) + c2, k);
obj->coeff3 = _IQdiv(_IQdiv4(c1), k);
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Theoretically initialize the IirSo object with detailed parameters, 2nd interface
*
* This function theoretically initialize the IirSo object with detailed parameters
* This is an overload function.
*
* \note The fc_Hz is the cutoff frequency in the unit of Hz
*
* \param[in] obj : pointer to IirSo instance
* \param[in] fc_Hz : the cut-off frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] zeta : the zeta coefficient
*/
static inline void IirSo_Init2(IirSoType *obj, float fc_Hz, float runFreq_kHz, float zeta)
{
/* Prewarping */
float twoph = 2000 * runFreq_kHz;
float hptwo = 0.0005 / runFreq_kHz;
float Wc_rps = twoph * tan(MATH_2PI * fc_Hz * hptwo);
_iq tmp = _IQ(Wc_rps / runFreq_kHz * 0.001);
_iq c1 = _IQmpy(tmp, tmp);
_iq c2 = _IQ(zeta * Wc_rps / runFreq_kHz * 0.001);
_iq k = _IQ(1) + c2 + _IQdiv4(c1);
obj->coeff1 = _IQdiv(_IQ(2) - _IQdiv2(c1), k);
obj->coeff2 = _IQdiv(-_IQdiv4(c1) - _IQ(1) + c2, k);
obj->coeff3 = _IQdiv(_IQdiv4(c1), k);
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Push input to the filter
*
* This function push data into the filter
*
* \param[in] obj : pointer to IirSo instance
* \param[in] input : input data in IQ format
*/
static inline void IirSo_PushInput(IirSoType *obj, _iq input)
{
if(obj->isInitial)
{
obj->output = input;
obj->prevOutput = input;
obj->prevPrevOutput = input;
obj->prevInput = input;
obj->prevPrevInput = input;
obj->isInitial = false;
}
else
{
obj->output = _IQmpy(obj->prevOutput, obj->coeff1) + _IQmpy(obj->prevPrevOutput, obj->coeff2)
+ _IQmpy(input + _IQmpy2(obj->prevInput) + obj->prevPrevInput, obj->coeff3);
obj->prevPrevInput = obj->prevInput;
obj->prevInput = input;
obj->prevPrevOutput = obj->prevOutput;
obj->prevOutput = obj->output;
}
}
/*! \brief Get the output value
*
* This function gets the filter result
*
* \param[in] obj : pointer to IirSo instance
* \return the filter result
*/
static inline _iq IirSo_GetOutput(const IirSoType *obj)
{
return obj->output;
}
/*! \brief Reset the filter
*
* This function resets the filter to the initial state
*
* \param[in] obj : pointer to IirSo instance
*/
static inline void IirSo_Reset(IirSoType *obj)
{
obj->isInitial = true;
obj->output = 0;
obj->prevOutput = 0;
obj->prevPrevOutput = 0;
obj->prevInput = 0;
obj->prevPrevInput = 0;
}
/*! \brief Update the parameters of the filter
*
* This function updates the parameter of the filter in the runtime.
*
* \param[in] obj : pointer to IirSo instance
* \param[in] Wc_rps : the cut-off frequency in rad/s
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] zeta : the zeta coefficient
*/
static inline void IirSo_UpdateParams(IirSoType *obj, float Wc_rps, float runFreq_kHz, float zeta)
{
/* Prewarping */
float twoph = 2000 * runFreq_kHz;
float hptwo = 0.0005 / runFreq_kHz;
Wc_rps = twoph * tan(Wc_rps * hptwo);
_iq tmp = _IQ(Wc_rps / runFreq_kHz * 0.001);
_iq c1 = _IQmpy(tmp, tmp);
_iq c2 = _IQ(zeta * Wc_rps / runFreq_kHz * 0.001);
_iq k = _IQ(1) + c2 + _IQdiv4(c1);
obj->coeff1 = _IQdiv(_IQ(2) - _IQdiv2(c1), k);
obj->coeff2 = _IQdiv(-_IQdiv4(c1) - _IQ(1) + c2, k);
obj->coeff3 = _IQdiv(_IQdiv4(c1), k);
}
/*! \brief Update the parameters of the filter
*
* This function updates the parameter of the filter in the runtime.
* This is an overload function.
*
* \param[in] obj : pointer to IirSo instance
* \param[in] fc_Hz : the cut-off frequency in Hz
* \param[in] runFreq_kHz : the frequency pushing the data in
* \param[in] zeta : the zeta coefficient
*/
static inline void IirSo_UpdateParams2(IirSoType *obj, float fc_Hz, float runFreq_kHz, float zeta)
{
/* Prewarping */
float twoph = 2000 * runFreq_kHz;
float hptwo = 0.0005 / runFreq_kHz;
float Wc_rps = twoph * tan(MATH_2PI * fc_Hz * hptwo);
_iq tmp = _IQ(Wc_rps / runFreq_kHz * 0.001);
_iq c1 = _IQmpy(tmp, tmp);
_iq c2 = _IQ(zeta * Wc_rps / runFreq_kHz * 0.001);
_iq k = _IQ(1) + c2 + _IQdiv4(c1);
obj->coeff1 = _IQdiv(_IQ(2) - _IQdiv2(c1), k);
obj->coeff2 = _IQdiv(-_IQdiv4(c1) - _IQ(1) + c2, k);
obj->coeff3 = _IQdiv(_IQdiv4(c1), k);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IIR_SO_H_ */

View File

@ -0,0 +1,197 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _INTERP1D_H_
#define _INTERP1D_H_
/*! \brief Contains public interface to various functions related
* to the 1-D Linear Interpolation
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct _Interp1d_PointType_
{
_iq x; /*!< x. */
_iq y; /*!< y. */
} Interp1d_PointType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief This is an linear interpolate calculation function using 2 x and the scale as input
* The result x should satisfy: scale = (x-x1) / (x2-x1)
*
* \param[in] x1 : x value of point 1
* \param[in] x2 : x value of point 2
* \param[in] scale : the scale = (x-x1) / (x2-x1)
* \return the value x in the scale equation
*/
static inline _iq Interp1d(_iq x1, _iq x2, _iq scale)
{
return (_IQmpy(scale, x2 - x1) + x1);
}
/*! \brief This is an linear interpolate calculation function using 2 points as input
* Calculate y for the given x, based on two points - (x1, y1) and (x2, y2)
*
* \note If x1 is equal to x2, which is not actually allowed, it will return
* (y1+y2)/2 instead. User should prevent this situation.
*
* \param[in] x1 : x value of point 1
* \param[in] y1 : y value of point 1
* \param[in] x2 : x value of point 2
* \param[in] y2 : y value of point 2
* \param[in] x : x value of the target point
* \return the y value of the target point
*/
static inline _iq Interp1dPoints(_iq x1, _iq y1, _iq x2, _iq y2, _iq x)
{
return (x2 != x1) ? (_IQmpy(_IQdiv(y2 - y1, x2 - x1), x - x1) + y1) : _IQdiv2(y2 + y1);
}
/*! \brief This is an linear interpolate calculation function using the whole table as input
*
* \note The values in x[] must be from smallest to biggest
*
* \param[in] u0 : x value of the target point
* \param[in] x[] : the x value array
* \param[in] y[] : the y value array
* \param[in] maxIndex : max index of the array
* \return the y value of the target point
*/
static inline _iq Interp1dTable(_iq u0, const _iq x[], const _iq y[], uint32_t maxIndex)
{
_iq frac;
uint32_t right;
uint32_t left;
uint32_t bpIdx;
if(u0 <= x[0U])
{
left = 0U;
frac = (x[1U] == x[0U]) ? _IQ(0.5) : _IQdiv(u0 - x[0U], x[1U] - x[0U]);
}
else if(u0 < x[maxIndex])
{
/* Binary Search */
bpIdx = maxIndex >> 1U;
left = 0U;
right = maxIndex;
while(right - left > 1U)
{
if(u0 < x[bpIdx])
{
right = bpIdx;
}
else
{
left = bpIdx;
}
bpIdx = (right + left) >> 1U;
}
frac = (x[left + 1U] != x[left]) ? _IQdiv(u0 - x[left], x[left + 1U] - x[left]) : _IQ(0.5);
}
else
{
left = maxIndex - 1U;
frac = (x[maxIndex] != x[maxIndex - 1U]) ? _IQdiv(u0 - x[maxIndex - 1U], x[maxIndex] - x[maxIndex - 1U]) : _IQ(0.5);
}
return (_IQmpy(_IQ(1.0) - frac, y[left]) + _IQmpy(y[left + 1U], frac));
}
/*! \brief This is an linear interpolate calculation function using the whole table as input
*
* \note The values in pPt[].x must be from smallest to biggest
*
* \param[in] u0 : x value of the target point
* \param[in] pPt : the pointer to the points array
* \param[in] maxIndex : max index of the array
* \return the y value of the target point
*/
static inline _iq Interp1dPtArray(_iq u0, const Interp1d_PointType *pPt, uint32_t maxIndex)
{
_iq frac;
uint32_t right;
uint32_t left;
uint32_t bpIdx;
if(u0 <= pPt[0U].x)
{
left = 0U;
frac = (pPt[1U].x == pPt[0U].x) ? _IQ(0.5) : _IQdiv(u0 - pPt[0U].x, pPt[1U].x - pPt[0U].x);
}
else if(u0 < pPt[maxIndex].x)
{
/* Binary Search */
bpIdx = maxIndex >> 1U;
left = 0U;
right = maxIndex;
while(right - left > 1U)
{
if(u0 < pPt[bpIdx].x)
{
right = bpIdx;
}
else
{
left = bpIdx;
}
bpIdx = (right + left) >> 1U;
}
frac = (pPt[left + 1U].x != pPt[left].x) ? _IQdiv(u0 - pPt[left].x, pPt[left + 1U].x - pPt[left].x) : _IQ(0.5);
}
else
{
left = maxIndex - 1U;
frac = (pPt[maxIndex].x != pPt[maxIndex - 1U].x) ? _IQdiv(u0 - pPt[maxIndex - 1U].x, pPt[maxIndex].x - pPt[maxIndex - 1U].x) : _IQ(0.5);
}
return (_IQmpy(_IQ(1.0) - frac, pPt[left].y) + _IQmpy(pPt[left + 1U].y, frac));
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _INTERP1D_H_ */

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _INTERP2D_H_
#define _INTERP2D_H_
/*! \brief Contains public interface to various functions related
* to the 2-D linear interpolation
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#include "interp1d.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief This is an 2-D linear interpolate calculation function using the row and column scale as input
*
* \param[in] x00 : the x value of (0, 0) point
* \param[in] x01 : the x value of (0, 1) point
* \param[in] x10 : the x value of (1, 0) point
* \param[in] x11 : the x value of (1, 1) point
* \param[in] rowScale : the scale of row
* \param[in] columnScale : the scale of column
* \return the x value of the target point
*/
static inline _iq Interp2d(_iq x00, _iq x01, _iq x10, _iq x11, _iq rowScale, _iq columnScale)
{
return Interp1d(Interp1d(x00, x10, rowScale),
Interp1d(x01, x11, rowScale),
columnScale);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _INTERP2D_H_ */

View File

@ -0,0 +1,189 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IQMATH_H_
#define _IQMATH_H_
//! \brief This is the default floating point implementation of IQ math library.
//! Almost all the platforms can use it, but some may come across
//! the performance issue. So use it carefully unless you know what
//! you are doing.
//!
//###########################################################################
#ifndef _USING_CUSTOM_IQMATH_
//###########################################################################
// The default floating point IQ math
//===========================================================================
/*******************************************************************************
* the includes
******************************************************************************/
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
#define MATH_PI (3.1415926535897932384626433832795f)
#define MATH_2PI (6.283185307179586476925286766559f)
#define MATH_ONE_OVER_THREE (0.3333333333f)
#define MATH_ONE_OVER_SQRT_THREE (0.5773502692f)
#define MATH_SQRT_THREE_OVER_TWO (0.8660254038f)
#define IQMATH_ONE_OVER_THREE (0.3333333333f)
#define IQMATH_ONE_OVER_SQRT_THREE (0.5773502692f)
#define IQMATH_SQRT_THREE_OVER_TWO (0.8660254038f)
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef float _iq;
/*******************************************************************************
* the function prototypes
******************************************************************************/
#define _IQmpy2(A) ((A)*2.0f)
#define _IQmpy4(A) ((A)*4.0f)
#define _IQmpy8(A) ((A)*8.0f)
#define _IQmpy16(A) ((A)*16.0f)
#define _IQmpy32(A) ((A)*32.0f)
#define _IQmpy64(A) ((A)*64.0f)
#define _IQdiv2(A) ((A)*0.5f)
#define _IQdiv4(A) ((A)*0.25f)
#define _IQdiv8(A) ((A)*0.125f)
#define _IQdiv16(A) ((A)*0.0625f)
#define _IQdiv32(A) ((A)*0.03125f)
#define _IQdiv64(A) ((A)*0.015625f)
#define _IQ(A) (A)
#define _IQtoF(A) (A)
//! \note In case for some compiler version, __fmax and __fmin are not defined
//! Add a simple implementation here
#ifndef __fmax
#define __fmax(A, B) (A>B ? A : B)
#endif
#ifndef __fmin
#define __fmin(A, B) (A<B ? A : B)
#endif
#define _IQsat(A, Pos, Neg) (__fmax(((__fmin((A),(Pos)))),(Neg)))
#define _IQtoQ15(A) (int) ((A) * 32768.0f)
#define _IQtoQ14(A) (int) ((A) * 16384.0f)
#define _IQtoQ13(A) (int) ((A) * 8192.0f)
#define _IQtoQ12(A) (int) ((A) * 4096.0f)
#define _IQtoQ11(A) (int) ((A) * 2048.0f)
#define _IQtoQ10(A) (int) ((A) * 1024.0f)
#define _IQtoQ9(A) (int) ((A) * 512.0f)
#define _IQtoQ8(A) (int) ((A) * 256.0f)
#define _IQtoQ7(A) (int) ((A) * 128.0f)
#define _IQtoQ6(A) (int) ((A) * 64.0f)
#define _IQtoQ5(A) (int) ((A) * 32.0f)
#define _IQtoQ4(A) (int) ((A) * 16.0f)
#define _IQtoQ3(A) (int) ((A) * 8.0f)
#define _IQtoQ2(A) (int) ((A) * 4.0f)
#define _IQtoQ1(A) (int) ((A) * 2.0f)
#define _Q15toIQ(A) (((float) (A)) * 0.000030518f)
#define _Q14toIQ(A) (((float) (A)) * 0.000061035f)
#define _Q13toIQ(A) (((float) (A)) * 0.000122070f)
#define _Q12toIQ(A) (((float) (A)) * 0.000244141f)
#define _Q11toIQ(A) (((float) (A)) * 0.000488281f)
#define _Q10toIQ(A) (((float) (A)) * 0.000976563f)
#define _Q9toIQ(A) (((float) (A)) * 0.001953125f)
#define _Q8toIQ(A) (((float) (A)) * 0.003906250f)
#define _Q7toIQ(A) (((float) (A)) * 0.007812500f)
#define _Q6toIQ(A) (((float) (A)) * 0.015625000f)
#define _Q5toIQ(A) (((float) (A)) * 0.031250000f)
#define _Q4toIQ(A) (((float) (A)) * 0.062500000f)
#define _Q3toIQ(A) (((float) (A)) * 0.125000000f)
#define _Q2toIQ(A) (((float) (A)) * 0.250000000f)
#define _Q1toIQ(A) (((float) (A)) * 0.500000000f)
#define _IQmpy(A,B) ((A) * (B))
#define _IQrmpy(A,B) ((A) * (B))
#define _IQrsmpy(A,B) ((A) * (B))
#define _IQdiv(A,B) ((float)(A) / (float)(B))
#define _IQsin(A) sinf(A)
#define _IQsinPU(A) sinf((A)*6.283185307f)
#define _IQasin(A) asinf(A)
#define _IQcos(A) cosf(A)
#define _IQcosPU(A) cosf((A)*6.283185307f)
#define _IQacos(A) acosf(A)
#define _IQatan(A) atanf(A)
#define _IQatan2(A,B) atan2f(A,B)
#define _IQatan2PU(A,B) ((atan2f(A,B)*(1.0f/6.283185307f)) >= 0.0f ? (atan2f(A,B)*(1.0f/6.283185307f)) : (1.0f + (atan2f(A,B)*(1.0f/6.283185307f))))
#define _IQsqrt(A) sqrtf(A)
#define _IQisqrt(A) (1.0f/sqrtf(A))
#define _IQexp(A) expf(A)
#define _IQint(A) ((long) (A))
#define _IQfrac(A) ((A) - (float)((long) (A)))
#define _IQmag(A,B) sqrtf((A)*(A) + (B)*(B))
#define _IQabs(A) fabsf(A)
#define _IQlog(A) logf(A)
#ifdef __cplusplus
}
#endif /* extern "C" */
//###########################################################################
#else
//###########################################################################
// The custom IQ math
//===========================================================================
//! \note It's the user's duty to undefine the macros that are different with ones
//! defined above in the "iqmathcustom.h", which must be put in this folder.
//! \note When building some kind of library and we cannot access the BSW, just create
//! and fake the MCU folder.
//!
#include "iqmathcustom.h"
#endif
#endif /* _IQMATH_H_ */

View File

@ -0,0 +1,237 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _MATRIX_H_
#define _MATRIX_H_
/*! \brief Contains public interface to various functions related
* to the matrix object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the initial parameters for matrix object
*/
typedef struct _MatrixType_
{
_iq *pContainer; /*!< Pointer to the matrix table container */
uint16_t rowNum; /*!< Total row number of the container */
uint16_t columnNum; /*!< Total column number of the container */
} MatrixType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the MATRIX object.
*
* This function initialize the MATRIX object.
*
* \note The container should be the 2-D array
*
* \param[in] obj : pointer to MATRIX instance
* \param[in] pContainer : pointer to the container
* \param[in] rowNum : the row number of the 2-D array
* \param[in] columnNum : the column number of the 2-D array
*/
static inline void Matrix_Init(MatrixType *obj, _iq *pContainer, uint16_t rowNum, uint16_t columnNum)
{
obj->pContainer = pContainer;
obj->rowNum = rowNum;
obj->columnNum = columnNum;
}
/*! \brief Set the value to the MATRIX element.
*
* This function sets the value to the specific position.
*
* \note The row and column start with 0
* The first element is row 0 and column 0
*
* \param[in] obj : pointer to MATRIX instance
* \param[in] value : the value to be set
* \param[in] row : the row index to set value
* \param[in] column : the column index to set value
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool Matrix_SetValue(MatrixType *obj, _iq value, uint16_t row, uint16_t column)
{
if(row >= obj->rowNum || column >= obj->columnNum)
{
return false;
}
(*(obj->pContainer + column + row * obj->columnNum)) = value;
return true;
}
/*! \brief Set the "other" matrix to this MATRIX.
*
* This function set the whole matrix values with another matrix
*
* \param[in] obj : pointer to MATRIX instance
* \param[in] other : the pointer to the other matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool Matrix_SetMatrix(MatrixType *obj, const MatrixType *other)
{
if(obj->rowNum != other->rowNum || obj->columnNum != other->columnNum)
{
return false;
}
uint16_t i;
uint16_t j;
for(i = 0; i < obj->rowNum; i++)
{
for(j = 0; j < obj->columnNum; j++)
{
(*(obj->pContainer + j + i * obj->columnNum)) = (*(other->pContainer + j + i * obj->columnNum));
}
}
return true;
}
/*! \brief Get the value of the MATRIX element.
*
* This function gets the value of the specific position
*
* \note The row and column start with 0
* The first element is row 0 and column 0
*
* \param[in] obj : pointer to MATRIX instance
* \param[out] pValue : pointer to the output value
* \param[in] row : the row index
* \param[in] column : the column index
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool Matrix_GetValue(MatrixType *obj, _iq *pValue, uint16_t row, uint16_t column)
{
if(row >= obj->rowNum || column >= obj->columnNum)
{
return false;
}
*pValue = (*(obj->pContainer + column + row * obj->columnNum));
return true;
}
/*! \brief multiply 2 matrix
*
* This function multiply 2 matrix
*
* \note The formula is S = LR, return false if mismatch, else return true.
*
* \param[in] pL : pointer to the left matrix
* \param[in] pR : pointer to the right matrix
* \param[out] pS : pointer to the product matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool Matrix_Multiply(const MatrixType *pL, const MatrixType *pR, MatrixType *pS)
{
uint16_t i;
uint16_t j;
if((pL->columnNum != pR->rowNum) || (pR->columnNum > 1))
{
return false;
}
for(i = 0; i < pL->rowNum; i++)
{
*(pS->pContainer + i) = 0;
for(j = 0; j < pR->rowNum; j++)
{
(*(pS->pContainer + i)) += _IQmpy((*(pL->pContainer + j + i * pR->rowNum)), (*(pR->pContainer + j)));
}
}
return true;
}
/*! \brief Add 2 matrix
*
* This function add 2 matrix.
*
* \note The formula is S = L+R, return false if mismatch, else return true.
*
* \param[in] pL : pointer to the left matrix
* \param[in] pR : pointer to the right matrix
* \param[out] pS : pointer to the sum matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool Matrix_Add(MatrixType *pL, MatrixType *pR, MatrixType *pS)
{
uint16_t i;
uint16_t j;
if((pL->columnNum != pR->columnNum) && (pL->rowNum != pR->rowNum))
{
return false;
}
for(i = 0; i < pL->rowNum; i++)
{
for(j = 0; j < pL->columnNum; j++)
{
(*(pS->pContainer + j + i * pL->columnNum))
= (*(pL->pContainer + j + i * pL->columnNum)) + (*(pR->pContainer + j + i * pL->columnNum));
}
}
return true;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _MATRIX_H_ */

View File

@ -0,0 +1,236 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _MATRIX_F32_H_
#define _MATRIX_F32_H_
/*! \brief Contains public interface to various functions related
* to the matrix object using float32_t.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the initial parameters for matrix object
*/
typedef struct _MatrixF32Type_
{
float *pContainer; /*!< Pointer to the matrix table container */
uint16_t rowNum; /*!< Total row number of the container */
uint16_t columnNum; /*!< Total column number of the container */
} MatrixF32Type;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the MATRIX_F32 object.
*
* This function initialize the MATRIX_F32 object.
*
* \note The container should be the 2-D array
*
* \param[in] obj : pointer to Matrix_f32 instance
* \param[in] pContainer : pointer to the container
* \param[in] rowNum : the row number of the 2-D array
* \param[in] columnNum : the column number of the 2-D array
*/
static inline void MatrixF32_Init(MatrixF32Type *obj, float *pContainer, uint16_t rowNum, uint16_t columnNum)
{
obj->pContainer = pContainer;
obj->rowNum = rowNum;
obj->columnNum = columnNum;
}
/*! \brief Set the value to the MATRIX_F32 element.
*
* This function sets the value to the specific position.
*
* \note The row and column start with 0
* The first element is row 0 and column 0
*
* \param[in] obj : pointer to Matrix_f32 instance
* \param[in] value : the value to be set
* \param[in] row : the row index to set value
* \param[in] column : the column index to set value
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool MatrixF32_SetValue(MatrixF32Type *obj, float value, uint16_t row, uint16_t column)
{
if(row >= obj->rowNum || column >= obj->columnNum)
{
return false;
}
(*(obj->pContainer + column + row * obj->columnNum)) = value;
return true;
}
/*! \brief Set the "other" matrix to this MATRIX.
*
* This function set the whole matrix values with another matrix
*
* \param[in] obj : pointer to Matrix_f32 instance
* \param[in] other : the pointer to the other matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool MatrixF32_SetMatrix(MatrixF32Type *obj, const MatrixF32Type *other)
{
if(obj->rowNum != other->rowNum || obj->columnNum != other->columnNum)
{
return false;
}
uint16_t i;
uint16_t j;
for(i = 0; i < obj->rowNum; i++)
{
for(j = 0; j < obj->columnNum; j++)
{
(*(obj->pContainer + j + i * obj->columnNum)) = (*(other->pContainer + j + i * obj->columnNum));
}
}
return true;
}
/*! \brief Get the value of the MATRIX_F32 element.
*
* This function gets the value of the specific position
*
* \note The row and column start with 0
* The first element is row 0 and column 0
*
* \param[in] obj : pointer to Matrix_f32 instance
* \param[out] pValue : pointer to the output value
* \param[in] row : the row index
* \param[in] column : the column index
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool MatrixF32_GetValue(const MatrixF32Type *obj, float *pValue, uint16_t row, uint16_t column)
{
if(row >= obj->rowNum || column >= obj->columnNum)
{
return false;
}
*pValue = (*(obj->pContainer + column + row * obj->columnNum));
return true;
}
/*! \brief multiply 2 matrix
*
* This function multiply 2 matrix
*
* \note The formula is S = LR, return false if mismatch, else return true.
*
* \param[in] pL : pointer to the left matrix
* \param[in] pR : pointer to the right matrix
* \param[out] pS : pointer to the product matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool MatrixF32_Multiply(const MatrixF32Type *pL, const MatrixF32Type *pR, MatrixF32Type *pS)
{
uint16_t i;
uint16_t j;
if((pL->columnNum != pR->rowNum) || (pR->columnNum > 1))
{
return false;
}
for(i = 0; i < pL->rowNum; i++)
{
*(pS->pContainer + i) = 0;
for(j = 0; j < pR->rowNum; j++)
{
(*(pS->pContainer + i)) += ((*(pL->pContainer + j + i * pR->rowNum)) * (*(pR->pContainer + j)));
}
}
return true;
}
/*! \brief Add 2 matrix
*
* This function add 2 matrix.
*
* \note The formula is S = L+R, return false if mismatch, else return true.
*
* \param[in] pL : pointer to the left matrix
* \param[in] pR : pointer to the right matrix
* \param[out] pS : pointer to the sum matrix
* \return the result of the operation
* - true : success
* - false : failed
*/
static inline bool MatrixF32_Add(const MatrixF32Type *pL, const MatrixF32Type *pR, MatrixF32Type *pS)
{
uint16_t i;
uint16_t j;
if((pL->columnNum != pR->columnNum) && (pL->rowNum != pR->rowNum))
{
return false;
}
for(i = 0; i < pL->rowNum; i++)
{
for(j = 0; j < pL->columnNum; j++)
{
(*(pS->pContainer + j + i * pL->columnNum))
= (*(pL->pContainer + j + i * pL->columnNum)) + (*(pR->pContainer + j + i * pL->columnNum));
}
}
return true;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _MATRIX_F32_H_ */

View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IPI_H_
#define _IPI_H_
/*! \brief Contains public interface to various functions related
* to the Incremental PI (IPI) object.
* \note The form of this PID is parallel.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct _IpiType_
{
_iq ref; /*!< Input: Reference input */
_iq fdb; /*!< Input: Feedback input */
_iq Kp; /*!< Parameter: Proportional gain */
_iq Ki; /*!< Parameter: Integral gain */
_iq lastError; /*!< Internal Variable: last error */
_iq delta; /*!< Output: The output of increment value */
} IpiType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the IPI object
*
* This function intialize the IPI object
*
* \param[in] obj : pointer to IPI instance
* \param[in] Kp : Kp value in IQ format
* \param[in] Ki : Ki value in IQ format
*/
static inline void Ipi_Init(IpiType *obj, _iq Kp, _iq Ki)
{
obj->ref = 0;
obj->fdb = 0;
obj->delta = 0;
obj->Kp = Kp;
obj->Ki = Ki;
obj->lastError = 0;
}
/*! \brief Run the IPI control
*
* This function run the IPI calculation
*
* \param[in] obj : pointer to IPI instance
*/
static inline void Ipi_Run(IpiType *obj)
{
/* Compute the error */
_iq error = obj->ref - obj->fdb;
/* Compute the proportional output */
_iq Up = _IQmpy(obj->Kp, error - obj->lastError);
/* Compute the integral output */
_iq Ui = _IQmpy(obj->Ki, error);
/* Remember error for next time */
obj->lastError = error;
/* Assign the output */
obj->delta = Up + Ui;
}
/*! \brief Reset the IPI variables
*
* This function reset the IPI instance to the initial state
*
* \param[in] obj : pointer to IPI instance
*/
static inline void Ipi_Reset(IpiType *obj)
{
obj->lastError = 0;
obj->delta = 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IPI_H_ */

View File

@ -0,0 +1,165 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PID_H_
#define _PID_H_
/*! \brief Contains public interface to various functions related
* to the PID object.
* \note The form of this PID is parallel.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of PID object
*/
typedef struct _PidType_
{
_iq ref; /*!< Input: Reference input */
_iq fdb; /*!< Input: Feedback input */
_iq Kp; /*!< Parameter: Proportional gain */
_iq Ki; /*!< Parameter: Integral gain */
_iq Kd; /*!< Parameter: Derivative gain */
_iq outMax; /*!< Parameter: Maximum output */
_iq outMin; /*!< Parameter: Minimum output */
_iq Ui; /*!< Internal Variable: Integral output */
_iq lastError; /*!< Internal Variable: last error */
_iq output; /*!< Output: PID output */
} PidType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the PID object
*
* This function initializes the PID instance
*
* \param[in] obj : pointer to Pid instance
* \param[in] Kp : the Kp value in IQ format
* \param[in] Ki : the Ki value in IQ format
* \param[in] Kd : the Kd value in IQ format
* \param[in] min : the min value allowed in output
* \param[in] max : the max value allowed in output
*/
static inline void Pid_Init(PidType *obj, _iq Kp, _iq Ki, _iq Kd, _iq min, _iq max)
{
obj->Kp = Kp;
obj->Ki = Ki;
obj->Kd = Kd;
obj->outMin = min;
obj->outMax = max;
obj->ref = 0;
obj->fdb = 0;
obj->Ui = 0;
obj->lastError = 0;
obj->output = 0;
}
/*! \brief Run the PID control
*
* This fucntion runs the PID control
*
* \note The form of this PID is parallel
*
* \param[in] obj : pointer to Pid instance
*/
static inline void Pid_Run(PidType *obj)
{
/* Compute the error */
_iq error = obj->ref - obj->fdb;
/* Compute the proportional output */
_iq Up = _IQmpy(obj->Kp, error);
/* Compute the integral output */
obj->Ui = obj->Ui + _IQmpy(obj->Ki, error);
/* Saturate Ui */
if(obj->Ui > obj->outMax)
{
obj->Ui = obj->outMax;
}
if(obj->Ui < obj->outMin)
{
obj->Ui = obj->outMin;
}
/* Compute the derivative output */
_iq Ud = _IQmpy(obj->Kd, (error - obj->lastError));
obj->lastError = error;
/* Compute the pre-saturated output */
_iq tmpOutput = Up + obj->Ui + Ud;
/* Saturate the output */
if(tmpOutput > obj->outMax)
{
obj->output = obj->outMax;
}
else if(tmpOutput < obj->outMin)
{
obj->output = obj->outMin;
}
else
{
obj->output = tmpOutput;
}
}
/*! \brief Reset the PID variables
*
* This function reset the PID to initial state
*
* \note The form of this PID is parallel
*
* \param[in] obj : pointer to Pid instance
*/
static inline void Pid_Reset(PidType *obj)
{
obj->lastError = 0;
obj->output = 0;
obj->Ui = 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PID_H_ */

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _SMC_H_
#define _SMC_H_
/*! \brief Contains public interface to various functions related
* to the Sliding Mode Control (SMC) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize SMC object
* \note We use 2 coefficients to determine the current output:
*
* accumulator(k) = coeff1 * accumulator(k-1) + coeff2 * Z(k)
*
* If coeff1 + coeff2 = 1, this will act like a normal LPF
* whose gain will be 1. But sometimes we need this algorithm's
* gain NOT equal to 1. So 2 coefficients are put here for the
* user to set freely.
*/
typedef struct _Smc_ParamsType_
{
float Kslide; /*!< The gain of the sliding mode */
float maxError; /*!< The max error of input */
float coeff1; /*!< The coefficient of last output */
float coeff2; /*!< The coefficient of bang-bang control value */
} Smc_ParamsType;
/*! \brief Declaration of SMC object
*/
typedef struct _SmcType_
{
_iq error; /*!< Input: Reference input */
_iq Kslide; /*!< Parameter: The gain of the sliding mode */
_iq maxError; /*!< Parameter: The max error of input */
_iq gain; /*!< Parameter: The max error of input */
_iq coeff1; /*!< Parameter: The coefficient of last output */
_iq coeff2; /*!< Parameter: The coefficient of bang-bang control value */
_iq accum; /*!< Internal variable: The accumulator of bang-bang control value */
_iq output; /*!< Output: The output of the sliding-mode control */
} SmcType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the SMC object
*
* This function initialize the SMC instance
*
* \param[in] obj : pointer to Smc instance
* \param[in] pParams :
*/
static inline void Smc_Init(SmcType *obj, const Smc_ParamsType *pParams)
{
/* Initialize all parameters */
obj->Kslide = _IQ(pParams->Kslide);
obj->maxError = _IQ(pParams->maxError);
obj->gain = _IQdiv(obj->Kslide, obj->maxError);
obj->coeff1 = _IQ(pParams->coeff1);
obj->coeff2 = _IQ(pParams->coeff2);
/* Initialize all internal variables */
obj->accum = 0;
/* Reset the outputs */
obj->output = 0;
}
/*! \brief Run the SMC control
*
* This function run the SMC algorithm.
*
* \param[in] obj : pointer to Smc instance
*/
static inline void Smc_Run(SmcType *obj)
{
/* Bang-bang control with linear treatment around zero */
_iq Z;
if(_IQabs(obj->error) < obj->maxError)
{
Z = _IQmpy(obj->gain, obj->error);
}
else if(obj->error > 0)
{
Z = obj->Kslide;
}
else
{
Z = -obj->Kslide;
}
/* Filter the bang-bang control value */
obj->accum = _IQmpy(obj->accum, obj->coeff1) + _IQmpy(Z, obj->coeff2);
/* Put together the final output */
obj->output = obj->accum + Z;
}
/*! \brief Reset the SMC variables
*
* This function reset the SMC instance to the initial state.
*
* \param[in] obj : pointer to Smc instance
*/
static inline void Smc_Reset(SmcType *obj)
{
obj->accum = 0;
obj->output = 0;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _SMC_H_ */

View File

@ -0,0 +1,128 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _COMPARE_H_
#define _COMPARE_H_
/*! \brief Contains public interface to various functions related
* to the compare object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
#define FLOAT_EQUAL_DEADBAND (0.0001)
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The greater than (>) comparison
*
* This function do the greater comparison between 2 IQ value
*
* \param[in] A : value A in IQ format
* \param[in] B : value B in IQ format
*/
static inline bool Compare_GreaterThan(_iq A, _iq B)
{
return A > B;
}
/*! \brief The smaller than (<) comparison
*
* This function do the smaller comparison between 2 IQ value
*
* \param[in] A : value A in IQ format
* \param[in] B : value B in IQ format
*/
static inline bool Compare_SmallerThan(_iq A, _iq B)
{
return A < B;
}
/*! \brief The greater than or equal (>=) comparison
*
* This function do the greater than or equal (>=) comparison between 2 IQ value
*
* \param[in] A : value A in IQ format
* \param[in] B : value B in IQ format
*/
static inline bool Compare_GreaterOrEqual(_iq A, _iq B)
{
return A >= B;
}
/*! \brief The smaller than or equal (<=) comparison
*
* This function do the smaller than or equal (<=) comparison between 2 IQ value
*
* \param[in] A : value A in IQ format
* \param[in] B : value B in IQ format
*/
static inline bool Compare_SmallerOrEqual(_iq A, _iq B)
{
return A <= B;
}
/*! \brief The equal (==) comparison
*
* This function do the equal (==) comparison between 2 IQ value
*
* \note If the IQ is floating value, it's not the exact equal because of the precision
* of floating value.
*
* \param[in] A : value A in IQ format
* \param[in] B : value B in IQ format
*/
static inline bool Compare_Equal(_iq A, _iq B)
{
if((long)_IQ(0.1))
{ /* Fix-point IQ math */
return (A == B);
}
else
{
return (_IQabs(A - B) < _IQ(FLOAT_EQUAL_DEADBAND));
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _COMPARE_H_ */

View File

@ -0,0 +1,139 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _SORT_H_
#define _SORT_H_
/*! \brief Contains public interface to various functions related
* to the sort algorithms
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Return the max value in an array
*
* This function returns the max value in an array
*
* \param[in] array[] : the array to search
* \param[in] len : the length of the array
*/
static inline _iq MaxInArray(const _iq array[], uint16_t len)
{
_iq retval = array[0];
uint16_t i = 0;
for(i = 0; i < len; i++)
{
if(array[i] > retval)
{
retval = array[i];
}
}
return retval;
}
/*! \brief Return the minimum value in an array
*
* This function returns the minimun value in an array
*
* \param[in] array[] : the array to search
* \param[in] len : the length of the array
*/
static inline _iq MinInArray(const _iq array[], uint16_t len)
{
_iq retval = array[0];
uint16_t i = 0;
for(i = 0; i < len; i++)
{
if(array[i] < retval)
{
retval = array[i];
}
}
return retval;
}
/*! \brief Return the max absolute value in an array
*
* This function returns the max absolute value in an array
*
* \param[in] array[] : the array to search
* \param[in] len : the length of the array
*/
static inline _iq MaxAbsInArray(const _iq array[], uint16_t len)
{
_iq retval = _IQabs(array[0]);
uint16_t i = 0;
for(i = 0; i < len; i++)
{
if(_IQabs(array[i]) > retval)
{
retval = _IQabs(array[i]);
}
}
return retval;
}
/*! \brief Return the minimum absolute value in an array
*
* This function returns the minimum absolute value in an array
*
* \param[in] array[] : the array to search
* \param[in] len : the length of the array
*/
static inline _iq MinAbsInArray(const _iq array[], uint16_t len)
{
_iq retval = _IQabs(array[0]);
uint16_t i = 0;
for(i = 0; i < len; i++)
{
if(_IQabs(array[i]) < retval)
{
retval = _IQabs(array[i]);
}
}
return retval;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _SORT_H_ */

View File

@ -0,0 +1,147 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _STIMER_H_
#define _STIMER_H_
/*! \brief Contains public interface to various functions related
* to the Software Timer (STIMER) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Declaration of STIMER object
*/
typedef struct _StimerType_
{
uint32_t counter; /*!< The counter register */
uint32_t period; /*!< The period, time out will occur when count reach period */
bool enable; /*!< Whether the timer is started */
bool overflow; /*!< Whether the timer is overflow */
} StimerType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The constructor of the timer object
*
* This function initialize the Stimer object
*
* \param[in] obj : pointer to Stimer instance
*/
static inline void Stimer_Init(StimerType *obj)
{
obj->counter = 0;
obj->period = 0;
obj->enable = false;
obj->overflow = false;
}
/*! \brief Start the timer for the period, this is one shot
*
* This function start the timer. This is one-shot.
*
* \note The real time is based on the time base running Ticker()
* \note Call this function if already started will restart the timer
*
* \param[in] obj : pointer to Stimer instance
* \param[in] period : the period value
*/
static inline void Stimer_Start(StimerType *obj, uint32_t period)
{
obj->counter = 0;
obj->period = period;
obj->enable = true;
obj->overflow = false;
}
/*! \brief The time base of the timer object
*
* This function provide the real time base of the stimer instance.
*
* \param[in] obj : pointer to Stimer instance
*/
static inline void Stimer_Tick(StimerType *obj)
{
if(obj->enable && obj->overflow == false)
{
if(obj->counter < obj->period)
{
obj->counter++;
if(obj->counter == obj->period)
{
obj->overflow = true;
}
}
}
}
/*! \brief Whether timeout
*
* This function returns whether it's timeout
*
* \param[in] obj : pointer to Stimer instance
* \return Whether it's timeout
* - true : the timer is time-out
* - false : the timer is not time-out
*/
static inline bool Stimer_Timeout(const StimerType *obj)
{
return obj->overflow;
}
/*! \brief Whether it's started
*
* This function returns whether the Timer instance is started
*
* \param[in] obj : pointer to Stimer instance
* \return Whether it's started
* - true : the timer is started
* - false : the timer is not started
*/
static inline bool Stimer_IsActive(StimerType *obj)
{
return obj->enable;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _STIMER_H_ */

View File

@ -0,0 +1,189 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _TRIGGER_H_
#define _TRIGGER_H_
/*! \brief Contains public interface to various functions related
* to the Trigger object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#include "common/sort/compare.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief The definition of Compare mode
*/
typedef enum
{
TRIGGER_COMPTYPE_OVER,
TRIGGER_COMPTYPE_UNDER,
} Trigger_CompModeType;
/*! \brief The definition of parameters of Trigger class
*/
typedef struct _Trigger_ParamsType_
{
Trigger_CompModeType compType;
_iq threshold;
_iq recoverValue;
uint16_t trigCntMax;
uint16_t recoverCntMax;
bool isRecoverable;
} Trigger_ParamsType;
/*! \brief The definition of Trigger prototype
*/
typedef struct _TriggerType_
{
_iq input; /*!< Input: The input for scan */
_iq threshold; /*!< Parameter: The threshold for compare */
_iq recoverValue; /*!< Parameter: The recover value that will reverse trigger */
uint16_t trigCntMax; /*!< Parameter: The max counts for the compare */
uint16_t recoverCntMax; /*!< Parameter: The max counts for the recover */
bool isRecoverable; /*!< Parameter: Whether the trigger can be recovered */
uint16_t trigCnt; /*!< Internal Variable: The count for the compare */
uint16_t recoverCnt; /*!< Internal Variable: The count for the recover */
bool (*comp)(_iq, _iq); /*!< Internal Variable: The compare function pointer */
bool (*recover)(_iq, _iq); /*!< Internal Variable: The recover function pointer */
bool compSatisfied; /*!< Output: Whether compare satisfied without debounce */
bool isTriggered; /*!< Output: Whether it's triggered based on compare and debounce */
} TriggerType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The initialization of Trigger
*
* This function initializes the trigger instance
*
* \param[in] obj : pointer to Trigger instance
* \param[in] pParams : pointer to the parameters
*/
static inline void Trigger_Init(TriggerType *obj, const Trigger_ParamsType *pParams)
{
obj->trigCntMax = pParams->trigCntMax;
obj->recoverCntMax = pParams->recoverCntMax;
obj->threshold = pParams->threshold;
obj->recoverValue = pParams->recoverValue;
obj->isRecoverable = pParams->isRecoverable;
if(pParams->compType == TRIGGER_COMPTYPE_OVER)
{
obj->comp = Compare_GreaterThan;
obj->recover = Compare_SmallerThan;
}
else if(pParams->compType == TRIGGER_COMPTYPE_UNDER)
{
obj->comp = Compare_SmallerThan;
obj->recover = Compare_GreaterThan;
}
obj->trigCnt = 0;
obj->recoverCnt = 0;
obj->compSatisfied = false;
obj->isTriggered = false;
}
/*! \brief Run the trigger algorithm
*
* This function runs the trigger algorithm
*
* \param[in] obj : pointer to Trigger instance
*/
static inline void Trigger_Run(TriggerType *obj)
{
if(obj->comp(obj->input, obj->threshold))
{
obj->compSatisfied = true;
obj->recoverCnt = 0;
if(obj->trigCnt < obj->trigCntMax)
{
obj->trigCnt++;
}
if(obj->trigCnt >= obj->trigCntMax)
{
obj->isTriggered = true;
}
}
else
{
obj->compSatisfied = false;
obj->trigCnt = 0;
if(obj->isRecoverable)
{
if(obj->recover(obj->input, obj->recoverValue))
{
if(obj->recoverCnt < obj->recoverCntMax)
{
obj->recoverCnt++;
}
if(obj->recoverCnt >= obj->recoverCntMax)
{
obj->isTriggered = false;
}
}
else
{
obj->recoverCnt = 0;
}
}
}
}
/*! \brief Reset the trigger instance
*
* This function reset the trigger to the initial state
*
* \param[in] obj : pointer to Trigger instance
*/
static inline void Trigger_Reset(TriggerType *obj)
{
obj->trigCnt = 0;
obj->recoverCnt = 0;
obj->compSatisfied = false;
obj->isTriggered = false;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _TRIGGER_H_ */

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IMEFE_H_
#define _IMEFE_H_
/*! \brief Contains public interface to various functions related
* to the Induction Motor Enhance Flux Estimator (IMEFE) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/filter/iir_fo.h"
#include "common/pid/pid.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize IMEFE object
*/
typedef struct _Imefe_ParamsType_
{
float Rs_ohm; /*!< Stator resistance (ohm) */
float Rr_ohm; /*!< Rotor resistance (ohm) */
float Ls_H; /*!< Stator inductance (H) */
float Lr_H; /*!< Rotor inductance (H) */
float Lm_H; /*!< Magnetizing inductance (H) */
float IBase_A; /*!< Base phase current (amp) */
float VBase_V; /*!< Base phase voltage (volt) */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float phaseCalcFreq_kHz; /*!< Frequency to run phase calculation */
float responseSpeed_rps; /*!< The response speed in rad/s */
float spdCalcFreq_kHz; /*!< Frequency to run phase calculation */
float spdFilterPole_rps; /*!< Pole value of speed filter calculation */
float gain; /*!< Controller Gain (0.0 to 0.9999) */
float linearError; /*!< Controller Max allowed linear error (0.0 to 0.9999) */
} Imefe_ParamsType;
/*! \brief Defines the IMEFE object
*/
typedef struct _ImefeType_
{
_iq Ialpha; /*!< Input: The stationary d-axis stator current */
_iq Ibeta; /*!< Input: The stationary q-axis stator current */
_iq Valpha; /*!< Input: The stationary d-axis stator voltage */
_iq Vbeta; /*!< Input: The stationary q-axis stator voltage */
_iq emfAs; /*!< Internal Variable: The stationary d-axis emf */
_iq emfBs; /*!< Internal Variable: The stationary q-axis emf */
_iq psiAs; /*!< Internal Variable: The stationary d-axis psi */
_iq psiBs; /*!< Internal Variable: The stationary q-axis psi */
_iq psiAr; /*!< Internal Variable: The stationary d-axis psi */
_iq psiBr; /*!< Internal Variable: The stationary q-axis psi */
_iq gain1; /*!< Parameter: Motor dependent control gain */
_iq sigma1; /*!< Parameter: Motor dependent control gain */
_iq gain2; /*!< Parameter: Motor dependent control gain */
_iq sigma2; /*!< Parameter: Motor dependent control gain */
_iq Rs; /*!< Parameter: Motor dependent control gain */
_iq model; /*!< Parameter: Motor dependent control gain */
_iq gain3; /*!< Parameter: Motor dependent control gain */
_iq gain4; /*!< Parameter: Motor dependent control gain */
_iq gain5; /*!< Parameter: Motor dependent control gain */
_iq factor; /*!< Parameter: Motor dependent control gain */
_iq maxErr; /*!< Parameter: Motor dependent control max Error */
IirFoType lpfFlx; /*!< Internal Variable: The filter for electric flux calculation */
IirFoType lpfSpd; /*!< Internal Variable: The filter for electric speed calculation */
PidType pidVAs; /*!< Internal Variable: The Stationary d-axis stator voltage PID */
PidType pidVBs; /*!< Internal Variable: The Stationary q-axis stator voltage PID */
PidType pidPLL; /*!< Internal Variable: The PLL PID */
_iq rawSpeed_pu; /*!< Internal variable: The raw speed before filter in P.U. */
_iq rawWslip_pu; /*!< Internal variable: The raw slip speed before filter in P.U. */
_iq angle_pu; /*!< Output: The electric angle */
_iq speed_pu; /*!< Output: The filtered electric speed updated every electric period */
} ImefeType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the IMEFE object
*
* This function initalizes IMEFE by setting configuration parameters
*
* \param[in] obj : pointer to IMEFE instance
* \param[in] pParams : pointer to IMEFE configuration parameters
*/
extern int32_t Imefe_Init(ImefeType *obj, const Imefe_ParamsType *pParams);
/*! \brief Run the Angle Compensation
*
* This function runs IMEFE function, calculates Angle compensation value
*
* \param[in] obj : pointer to IMEFE instance
*/
extern int32_t Imefe_Run(ImefeType *obj);
/*! \brief Calculate the speed
* \note Might run slower than current control frequency
*
*
* \param[in] obj : pointer to IMEFE instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Imefe_CalcSpeed(ImefeType *obj);
/*! \brief Reset the IMEFE object
*
* This function resets the IMEFE relevant calculation parameters
*
* \param[in] obj : pointer to IMEFE instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Imefe_Reset(ImefeType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IMEFE_H_ */

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "angle_comp.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void AngleComp_Init(AngleCompType *obj, const AngleComp_ParamsType *pParams)
{
obj->runFreq_kHz = pParams->runFreq_kHz;
obj->compFactor = _IQ(pParams->fBase_Hz * 0.001 / pParams->runFreq_kHz * pParams->delayCompFactor);
}

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _ANGLE_COMP_H_
#define _ANGLE_COMP_H_
/*! \brief Contains public interface to various functions related
* to the Angle Compensation (ANGLE_COMP) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize ANGLE_COMP object
*/
typedef struct _AngleComp_ParamsType_
{
float runFreq_kHz; /*!< the frequency of running current loop in kHz */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float delayCompFactor; /*!< The factor used to compensate the delay caused by PWM generation. */
} AngleComp_ParamsType;
/*! \brief Defines the ANGLE_COMP object
*/
typedef struct _AngleCompType_
{
_iq speed_pu; /*!< Input: the electrical speed in P.U. */
_iq angleUncomp_pu; /*!< Input: the angle before compensation in P.U. */
_iq compFactor; /*!< Internal variable: The factor used to calculate delta angle */
float runFreq_kHz; /*!< Internal variable: The frequency of running current loop in kHz */
_iq angleComp_pu; /*!< Output: the angle after compensation in P.U. */
} AngleCompType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the ANGLE_COMP object
*
* This function initalizes ANGLE_COMP by setting configuration parameters
*
* \param[in] obj : pointer to Angle_Comp instance
* \param[in] pParams : pointer to Angle_Comp configuration parameters
*/
extern void AngleComp_Init(AngleCompType *obj, const AngleComp_ParamsType *pParams);
/*! \brief Run the Angle Compensation
*
* This function runs Angle_Comp function, calculates Angle compensation value
*
* \param[in] obj : pointer to Angle_Comp instance
*/
static inline void AngleComp_Run(AngleCompType *obj)
{
_iq angleTmp_pu = obj->angleUncomp_pu + _IQmpy(obj->compFactor, obj->speed_pu);
angleTmp_pu = _IQfrac(angleTmp_pu); /* get the fraction part */
if(angleTmp_pu < 0)
{
angleTmp_pu += _IQ(1.0);
}
obj->angleComp_pu = angleTmp_pu;
}
/*! \brief Update the Angle Compensation configuration parameters
*
* This function updates the Angle_Comp function configuration parameters
*
* \param[in] obj : pointer to Angle_Comp instance
* \param[in] runFreq_kHz : the frequency of running current loop
*/
static inline void AngleComp_UpdateParams(AngleCompType *obj, float runFreq_kHz)
{
obj->compFactor = _IQmpy(obj->compFactor, _IQ(obj->runFreq_kHz / runFreq_kHz));
obj->runFreq_kHz = runFreq_kHz;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _ANGLE_COMP_H_ */

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "zero_offset.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void ZeroOffset_Init(ZeroOffsetType *obj, const ZeroOffset_ParamsType *pParams)
{
obj->scale = _IQ(pParams->delay_us * pParams->fBase_Hz / 1000000);
obj->offset = -_IQmpy(obj->scale, _IQ(pParams->calibBaseOnSpd_Hz / pParams->fBase_Hz));
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _ZERO_OFFSET_H_
#define _ZERO_OFFSET_H_
/*! \brief Contains public interface to various functions related
* to the Zero angle Offset (ZERO_OFFSET) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize ZERO_OFFSET object
*/
typedef struct _ZeroOffset_ParamsType_
{
float calibBaseOnSpd_Hz; /*!< calibrate zero position base on speed in Hz */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float delay_us; /*!< The delay time for the current in */
} ZeroOffset_ParamsType;
/*! \brief Defines the ANGLE_COMP object
*/
typedef struct _ZeroOffsetType_
{
_iq speed_pu; /*!< Input: the electrical speed in P.U. */
_iq angleUncomp_pu; /*!< Input: the angle before compensation in P.U. */
_iq scale; /*!< Parameter: The scale for scale*speed+offset */
_iq offset; /*!< Parameter: The offset for scale*speed+offset */
_iq angleComp_pu; /*!< Output: the angle after compensation in P.U. */
} ZeroOffsetType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the ZERO_OFFSET object
*
* This function initalizes Zero_Offset by setting configuration parameters
*
* \param[in] obj : pointer to Zero_Offset instance
* \param[in] pParams : pointer to Zero_Offset configuration parameters
*/
extern void ZeroOffset_Init(ZeroOffsetType *obj, const ZeroOffset_ParamsType *pParams);
/*! \brief Run the ZERO_OFFSET Compensation
*
* This function runs Zero_Offset function, calculates zero offset value
*
* \param[in] obj : pointer to Zero_Offset instance
*/
static inline void ZeroOffset_Run(ZeroOffsetType *obj)
{
_iq angleTmp_pu = obj->angleUncomp_pu + _IQmpy(obj->scale, obj->speed_pu) + obj->offset;
angleTmp_pu = _IQfrac(angleTmp_pu); /* get the fraction part */
if(angleTmp_pu < 0)
{
angleTmp_pu += _IQ(1.0);
}
obj->angleComp_pu = angleTmp_pu;
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _ZERO_OFFSET_H_ */

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _CLARKE_H_
#define _CLARKE_H_
/*! \brief Contains public interface to various functions related
* to the clarke modules
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Clarke prototype definition
*/
typedef struct _ClarkeType_
{
_iq As; /*!< phase A component */
_iq Bs; /*!< phase B component */
_iq Cs; /*!< phase C component */
_iq alpha; /*!< the alpha component */
_iq beta; /*!< the beta component */
} ClarkeType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Runs the clarke function
*
* This function runs clarke function, calculates clarke transforms value
*
* \param[in] obj : pointer to Clarke instance
*/
static inline void Clarke_Run(ClarkeType *obj)
{
obj->alpha = _IQmpy(_IQmpy2(obj->As) - (obj->Bs + obj->Cs), IQMATH_ONE_OVER_THREE);
obj->beta = _IQmpy((obj->Bs - obj->Cs), IQMATH_ONE_OVER_SQRT_THREE);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _CLARKE_H_ */

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "clff.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Clff_Init(ClffType *obj, const Clff_ParamsType *pParams)
{
/* Based value */
obj->RsBase_ohm = pParams->VBase_V / pParams->IBase_A;
obj->LBase_mH = pParams->VBase_V / pParams->IBase_A / (2 * MATH_PI * pParams->fBase_Hz) * 1000.0;
obj->PsiBase_Wb = pParams->VBase_V / (2 * MATH_PI * pParams->fBase_Hz);
/*init value */
_iq Vdc_pu = _IQ(pParams->ratedVdc_V / pParams->VBase_V);
obj->Kd = _IQdiv(_IQ(pParams->Ld_mH / obj->LBase_mH), Vdc_pu);
obj->Kq = _IQdiv(_IQ(pParams->Lq_mH / obj->LBase_mH), Vdc_pu);
obj->Kf = _IQdiv(_IQ(pParams->flux_Wb / obj->PsiBase_Wb), Vdc_pu);
obj->Kr = _IQdiv(_IQ(pParams->Rs_Ohm / obj->RsBase_ohm), Vdc_pu);
obj->minVdc_pu = _IQ(pParams->minVdc_V / pParams->VBase_V);
obj->maxVdc_pu = _IQ(pParams->maxVdc_V / pParams->VBase_V);
obj->Vd = 0;
obj->Vq = 0;
}

View File

@ -0,0 +1,152 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _CLFF_H_
#define _CLFF_H_
/*! \brief Contains public interface to various functions related
* to the Current Loop Feed-Forward (CLFF) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the initial parameters for CLFF object
*/
typedef struct _Clff_ParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float flux_Wb; /*!< The flux of rotor */
float ratedVdc_V; /*!< Rated dc bus voltage */
float IBase_A; /*!< Base value of current used for P.U. */
float VBase_V; /*!< Base value of voltage used for P.U. */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float minVdc_V; /*!< Minimum DC voltage allowed */
float maxVdc_V; /*!< Maximum DC voltage allowed */
} Clff_ParamsType;
/*! \brief Defines the dynamic parameters used to update CLFF object
*/
typedef struct _Clff_DynamicParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float flux_Wb; /*!< The flux of rotor */
_iq Vdc_pu; /*!< bus voltage in P.U. */
} Clff_DynamicParamsType;
/*! \brief Defines the CLFF object
*/
typedef struct _ClffType_
{
_iq Id_pu; /*!< Input: Id current in P.U. */
_iq Iq_pu; /*!< Input: Iq current in P.U. */
_iq eleFreq_pu; /*!< Input: electrical frequency in P.U. */
_iq Kf; /*!< Parameter: coefficient determined by Back EMF */
_iq Kd; /*!< Parameter: coefficient determined by Ld */
_iq Kq; /*!< Parameter: coefficient determined by Lq */
_iq Kr; /*!< Parameter: coefficient determined by Rs */
float RsBase_ohm; /*!< Parameter: Base value of resistance used for P.U. */
float LBase_mH; /*!< Parameter: Base value of Ls used for P.U. */
float PsiBase_Wb; /*!< Parameter: Base value of flux used for P.U. */
_iq minVdc_pu; /*!< Parameter: Minimum DC voltage allowed in P.U. */
_iq maxVdc_pu; /*!< Parameter: Maximum DC voltage allowed in P.U. */
_iq Vd; /*!< Output: theoretical Vd */
_iq Vq; /*!< Output: theoretical Vq */
} ClffType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the CLFF object
*
* This function initalizes CLFF by setting configuration parameters
*
* \param[in] obj : pointer to Clff instance
* \param[in] pParams : pointer to CLFF configuration parameters
*/
extern void Clff_Init(ClffType *obj, const Clff_ParamsType *pParams);
/*! \brief Calculate the theoretical Vd, Vq
*
* This function runs Clff function, calculates the theoretical Vd, Vq value
*
* \param[in] obj : pointer to Clff instance
*/
static inline void Clff_Calc(ClffType *obj)
{
obj->Vd = _IQmpy(obj->Kr, obj->Id_pu)
- _IQmpy(_IQmpy(obj->Kq, obj->Iq_pu), obj->eleFreq_pu);
obj->Vq = _IQmpy(obj->Kr, obj->Iq_pu)
+ _IQmpy(_IQmpy(obj->Kd, obj->Id_pu) + obj->Kf, obj->eleFreq_pu);
}
/*! \brief Update the parameters
*
* This function updates the Clff function configuration parameters dynamically
*
* \param[in] obj : pointer to Clff instance
* \param[in] pParams : pointer to Clff dynamic configuration parameters instance
*/
static inline void Clff_UpdateParams(ClffType *obj, const Clff_DynamicParamsType *pParams)
{
if(pParams->Vdc_pu >= obj->minVdc_pu && pParams->Vdc_pu <= obj->maxVdc_pu)
{
obj->Kd = _IQdiv(_IQ(pParams->Ld_mH / obj->LBase_mH), pParams->Vdc_pu);
obj->Kq = _IQdiv(_IQ(pParams->Lq_mH / obj->LBase_mH), pParams->Vdc_pu);
obj->Kf = _IQdiv(_IQ(pParams->flux_Wb / obj->PsiBase_Wb), pParams->Vdc_pu);
obj->Kr = _IQdiv(_IQ(pParams->Rs_Ohm / obj->RsBase_ohm), pParams->Vdc_pu);
}
else
{
obj->Kd = 0;
obj->Kq = 0;
obj->Kf = 0;
obj->Kr = 0;
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _CLFF_H_ */

View File

@ -0,0 +1,146 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _ESTIDC_H_
#define _ESTIDC_H_
/*! \brief Contains public interface to various functions related
* to the DC current Estimation (ESTIDC) object.
*
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the phase enumeration
*/
typedef enum
{
ESTIDC_PHASE_A = 0,
ESTIDC_PHASE_B,
ESTIDC_PHASE_C,
ESTIDC_PHASE_U,
ESTIDC_PHASE_V,
ESTIDC_PHASE_W,
ESTIDC_PHASE_Num
} Estidc_PhaseType;
/*! \brief Defines all the parameters used to initialize ESTIDC object
*/
typedef struct _Estidc_ParamsType_
{
_iq Tdb; /*!< Percentage of dead-band */
uint8_t phaseNumber; /*!< Number of phase */
} Estidc_ParamsType;
/*! \brief data of each phase
*/
typedef struct _Estidc_PhaseDataType
{
_iq I; /*!< Current of ever phase */
_iq T; /*!< 100%-(duty of ever phase ) */
_iq prevI; /*!< The last Current of ever phase */
_iq prevT; /*!< The last 100%-(duty of ever phase) */
_iq prevPrevT; /*!< The previous last 100%-(duty of ever phase) */
} Estidc_PhaseDataType;
/*! \brief Defines the ESTIDC object
*/
typedef struct _EstidcType_
{
_iq Ia; /*!< Input: current of phase A */
_iq Ib; /*!< Input: current of phase B */
_iq Ic; /*!< Input: current of phase C */
_iq Iu; /*!< Input: current of phase U */
_iq Iv; /*!< Input: current of phase V */
_iq Iw; /*!< Input: current of phase W */
_iq Ta; /*!< Input: 100%-(duty) of phase A */
_iq Tb; /*!< Input: 100%-(duty) of phase B */
_iq Tc; /*!< Input: 100%-(duty) of phase C */
_iq Tu; /*!< Input: 100%-(duty) of phase U */
_iq Tv; /*!< Input: 100%-(duty) of phase V */
_iq Tw; /*!< Input: 100%-(duty) of phase W */
_iq Tdb; /*!< Parameter: Percentage of dead-band */
uint16_t phaseNumber; /*!< Parameter: Number of phase */
Estidc_PhaseDataType data[ESTIDC_PHASE_Num]; /*!< Internal Variable: data of each phase */
_iq estIdc; /*!< Output: The estimated DC current */
} EstidcType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the ESTIDC object
*
* This function initalizes Estidc by setting configuration parameters
*
* \param[in] obj : pointer to Estidc instance
* \param[in] pParams : pointer to Estidc configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Estidc_Init(EstidcType *obj, const Estidc_ParamsType *pParams);
/*! \brief Run the estimation
*
* This function runs Estidc function, calculates idc estimation value
*
* \param[in] obj : pointer to Estidc instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Estidc_Run(EstidcType *obj);
/*! \brief Update the parameters of ESTIDC object
*
* This function updates the Estidc function configuration parameters
*
* \param[in] obj : pointer to Estidc instance
* \param[in] Tdb : the percentage of dead-band
*/
extern void Estidc_UpdateParams(EstidcType *obj, _iq Tdb);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _ESTIDC_H_ */

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "esttrq_tf.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void EstTrqTf_Init(EstTrqTfType *obj, const EstTrqTf_ParamsType *pParams)
{
obj->torqueFactor_I = _IQ(1.5 * pParams->polePairs * pParams->IBase_A / pParams->torqueBase_Nm);
obj->torqueFactor_F = _IQ((pParams->Ld_mH - pParams->Lq_mH) * 0.001 * pParams->IBase_A);
obj->flux_Wb = pParams->flux_Wb;
obj->IBaseFactor = 0.001 * pParams->IBase_A;
}
void EstTrqTf_Calc(EstTrqTfType *obj)
{
obj->torque_pu = _IQmpy(_IQmpy(obj->filteredIqFdb_pu,
_IQmpy(obj->filteredIdFdb_pu, obj->torqueFactor_F) + obj->flux_Wb),
obj->torqueFactor_I);
}
void EstTrqTf_UpdateParams(EstTrqTfType *obj, float Ld_mH, float Lq_mH, float flux_Wb)
{
obj->torqueFactor_F = _IQ((Ld_mH - Lq_mH) * obj->IBaseFactor);
obj->flux_Wb = flux_Wb;
}

View File

@ -0,0 +1,110 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _ESTTRQ_TF_H_
#define _ESTTRQ_TF_H_
/*! \brief Contains public interface to various functions related
* to the Torque Estimation using Torque Formula method.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize ESTTRQ_TF object
*/
typedef struct _EstTrqTf_ParamsType_
{
float IBase_A; /*!< Base value of current used for P.U. */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float torqueBase_Nm; /*!< Base value of torque used for P.U. */
uint32_t polePairs; /*!< Pole pairs of the motor */
float Ld_mH; /*!< d-axis inductance in mH */
float Lq_mH; /*!< q-axis inductance in mH */
float flux_Wb; /*!< The flux of PM in Webers */
} EstTrqTf_ParamsType;
/*! \brief Defines the ESTTRQ_TF object
*/
typedef struct _EstTrqTfType_
{
_iq filteredIdFdb_pu; /*!< Input: The Id feedback in P.U. */
_iq filteredIqFdb_pu; /*!< Input: The Iq feedback in P.U. */
_iq flux_Wb; /*!< Parameter: The flux of PM in Webers */
_iq torqueFactor_I; /*!< Parameter: Current factor to calculate torque */
_iq torqueFactor_F; /*!< Parameter: Flux factor to calculate torque */
float IBaseFactor; /*!< Parameter: Base current factor to calculate torque */
_iq torque_pu; /*!< Output: The estimated torque */
} EstTrqTfType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the ESTTRQ_TF object
*
* This function initalizes Esttrq_Tf by setting configuration parameters
*
* \param[in] obj : pointer to Esttrq_Tf instance
* \param[in] pParams : pointer to parameters
*/
extern void EstTrqTf_Init(EstTrqTfType *obj, const EstTrqTf_ParamsType *pParams);
/*! \brief Run the Torque estimation
*
* This function runs Esttrq_Tf function, calculates torque estimation value
*
* \param[in] obj : pointer to Esttrq_Tf instance
*/
extern void EstTrqTf_Calc(EstTrqTfType *obj);
/*! \brief Update the parameters of ESTTRQ_TF object
*
* This function updates the Esttrq_Tf function configuration parameters
*
* \param[in] obj : pointer to Esttrq_Tf instance
* \param[in] Ld_mH : d-axis inductance in mH
* \param[in] Lq_mH : q-axis inductance in mH
* \param[in] flux_Wb : the flux of PM in Webers
*/
extern void EstTrqTf_UpdateParams(EstTrqTfType *obj, float Ld_mH, float Lq_mH, float flux_Wb);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _ESTTRQ_TF_H_ */

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "fag.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Fag_Init(FagType *obj, float fBase_Hz, float runFreq_kHz)
{
obj->factor = _IQ(fBase_Hz / (runFreq_kHz * 1000.0));
obj->angle_pu = 0;
obj->frequency_pu = 0;
}

View File

@ -0,0 +1,116 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FAG_H_
#define _FAG_H_
/*! \brief Contains public interface to various functions related
* to the fag modules
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Fag prototype definition
*/
typedef struct _FagType_
{
_iq frequency_pu; /*!< Input: The electric frequency */
_iq factor; /*!< Internal Variable: The factor used to calculate the angle */
_iq angle_pu; /*!< Output: The angle generated */
} FagType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the FAG object
*
* This function initalizes Fag by setting configuration parameters
*
* \param[in] obj : pointer to Fag instance
* \param[in] fBase_Hz : the default maximum current base frequency
* \param[in] runFreq_kHz : the frequency of running current loop
*/
extern void Fag_Init(FagType *obj, float fBase_Hz, float runFreq_kHz);
/*! \brief Gets FAG calculation value
*
* This function gets Fag function calculation value
*
* \param[in] obj : pointer to Fag instance
*/
static inline _iq Fag_GetAngle(FagType *obj)
{
return (obj->angle_pu);
}
/*! \brief Sets the frequency of false angle
*
* This function Sets the frequency of false angle
*
* \param[in] obj : pointer to Fag instance
* \param[in] frequency : the desired frequency of false angle
*/
static inline void Fag_SetFrequency(FagType *obj, _iq frequency)
{
obj->frequency_pu = frequency;
}
/*! \brief Runs the FAG
*
* This function runs Fag function, calculates dynamic changing false angle value
*
* \param[in] obj : pointer to Fag instance
*/
static inline void Fag_Run(FagType *obj)
{
obj->angle_pu += _IQmpy(obj->frequency_pu, obj->factor);
obj->angle_pu = _IQfrac(obj->angle_pu); /* Get the fraction part */
if(obj->angle_pu < 0)
{
obj->angle_pu += _IQ(1.0);
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FAG_H_ */

View File

@ -0,0 +1,223 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FAST_H_
#define _FAST_H_
/*! \brief Contains public interface to various functions related
* to the Flux, Angle, Speed, Torque estimation (FAST) modules
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/pid/pid.h"
#include "common/filter/iir_fo.h"
#include "md_lib/clarke/clarke.h"
#include "md_lib/park/park.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Fast prototype definition
*/
typedef struct _Fast_ParamsType_
{
uint32_t polePairs; /*!< Pole pairs of the motor */
float runFreq_kHz; /*!< Frequency to run the process */
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< d-axis inductance in mH */
float Lq_mH; /*!< q-axis inductance in mH */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float VBase_V; /*!< Base value of voltage used for P.U. */
float IBase_A; /*!< Base value of current used for P.U. */
float torqueBase_Nm; /*!< Base value of torque used for P.U. */
float spdFilterPole_rps; /*!< Pole value of speed filter calculation */
float dirFilterPole_rps; /*!< Pole value of speed direction filter calculation */
float fluxFilterPole_rps; /*!< Pole value of flux filter calculation */
float ratedVdc_V; /*!< The rated phase-to-ground voltage */
float fstCalcFreq_kHz; /*!< The calculation frequency of flux, speed and torque */
float minElecFreq_Hz; /*!< The min speed supported in Hz */
float fluxBase_Wb; /*!< Base value of current used for P.U. */
float defaultFlux_Wb; /*!< The default value of flux in Wb */
float gain; /*!< Controller Gain (0.0 to 0.9999) */
float linearError; /*!< Controller Max allowed linear error (0.0 to 0.9999) */
float dampingFactor; /*!< Damping factor of controller */
} Fast_ParamsType;
/*! \brief Defines the dynamic parameters used to update Fast object
*/
typedef struct _Fast_DynamicParamsType_
{
float runFreq_kHz; /*!< Frequency to run the process */
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< d-axis inductance in mH */
float Lq_mH; /*!< q-axis inductance in mH */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float VBase_V; /*!< Base value of voltage used for P.U. */
float IBase_A; /*!< Base value of current used for P.U. */
} Fast_DynamicParamsType;
/*! \brief Defines the Fast type
*/
typedef struct _FastType_
{
_iq Ia_pu; /*!< Input: The Stationary current of phase A */
_iq Ib_pu; /*!< Input: The Stationary current of phase B */
_iq Ic_pu; /*!< Input: The Stationary current of phase C */
_iq Va_pu; /*!< Input: The Stationary voltage of phase A */
_iq Vb_pu; /*!< Input: The Stationary voltage of phase B */
_iq Vc_pu; /*!< Input: The Stationary voltage of phase C */
_iq Fdsmo; /*!< Parameter: Motor dependent control gain */
_iq Fqsmo; /*!< Parameter: Motor dependent control gain */
_iq Gdsmo; /*!< Parameter: Motor dependent control gain */
_iq Gqsmo; /*!< Parameter: Motor dependent control gain */
_iq Kdsmo; /*!< Parameter: Motor dependent control gain */
_iq Kqsmo; /*!< Parameter: Motor dependent control gain */
_iq Kslide; /*!< Parameter: Sliding control gain */
_iq maxError; /*!< Parameter: Maximum current error for linear SMC */
_iq angleFactor; /*!< Parameter: Factor to calculate angle from speed */
_iq fluxFactor; /*!< Parameter: Factor to calculate flux */
_iq torqueFactor_I; /*!< Parameter: Current factor to calculate torque */
_iq torqueFactor_F; /*!< Parameter: Flux factor to calculate torque */
_iq minSpd_pu; /*!< Parameter: Min electric speed in P.U. */
_iq defaultFlux_pu; /*!< Parameter: The default value of flux in P.U. */
_iq Vd; /*!< Internal Variable: The d-axis voltage */
_iq Vq; /*!< Internal Variable: The q-axis voltage */
_iq Zd; /*!< Internal Variable: Stationary d-axis sliding control */
_iq Zq; /*!< Internal Variable: Stationary q-axis sliding control */
_iq Eq; /*!< Internal Variable: Stationary q-axis back EMF */
ClarkeType clarkeI; /*!< Internal Variable: The clarke transform for current */
ClarkeType clarkeV; /*!< Internal Variable: The clarke transform for current */
ParkType parkI; /*!< Internal Variable: The park transform for current */
ParkType parkV; /*!< Internal Variable: The park transform for current */
PidType pidPLL; /*!< Internal Variable: The PLL PID */
_iq Id; /*!< Internal Variable: The d-axis current */
_iq Iq; /*!< Internal Variable: The q-axis current */
_iq IdEst; /*!< Internal Variable: Estimated d-axis current */
_iq IqEst; /*!< Internal Variable: Estimated q-axis current */
_iq IdError; /*!< Internal Variable: The d-axis current error */
_iq IqError; /*!< Internal Variable: The q-axis current error */
IirFoType filterSpd; /*!< Internal Variable: The filter for electric speed calculation */
IirFoType filterDir; /*!< Internal Variable: The filter for speed direction detection */
IirFoType filterFlux; /*!< Internal Variable: The filter for flux calculation */
int16_t spdDir; /*!< Internal Variable: The actual speed direction; 1:forward, -1:backward */
_iq rawSpeed_pu; /*!< Internal variable: The raw speed before filter in P.U. */
_iq currentAngle_pu; /*!< Internal variable: The angle for this control loop */
_iq nextAngle_pu; /*!< Internal variable: The angle for next control loop */
_iq angle_pu; /*!< Output: The electric angle */
_iq speed_pu; /*!< Output: The filtered electric speed updated every electric period */
_iq flux_pu; /*!< Output: The flux of PM in P.U. */
_iq torque_pu; /*!< Output: The electrical torque in P.U. */
} FastType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the FAST object
*
* This function initalizes Fast by setting configuration parameters
*
* \param[in] obj : pointer to Fast instance
* \param[in] pParams : pointer to Fast configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_Init(FastType *obj, const Fast_ParamsType *pParams);
/*! \brief Run the FAST
*
* This function runs Fast function, calculates Fast relevant value
*
* \param[in] obj : pointer to Fast instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_Run(FastType *obj);
/*! \brief Calculates current motor speed
*
* This function calculates current motor speed based on Fast estimation parameters
*
* \param[in] obj : pointer to Fast instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_CalcSpeed(FastType *obj);
/*! \brief Calculates current motor parameters
*
* This function calculates current motor flux and torque
* based on Fast estimation parameters
*
* \param[in] obj : pointer to Fast instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_CalcFluxAndTorque(FastType *obj);
/*! \brief Updates configuration parameters
*
* This function updates configuration parameters dynamically
*
* \param[in] obj : pointer to Fast instance
* \param[in] pParams : pointer to Fast configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_UpdateParams(FastType *obj, const Fast_DynamicParamsType *pParams);
/*! \brief Reset the Fast object
*
* This function resets the Fast relevant calculation parameters
*
* \param[in] obj : pointer to Fast instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Fast_Reset(FastType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FAST_H_ */

View File

@ -0,0 +1,240 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _EFOC_H_
#define _EFOC_H_
/*! \brief Contains public interface to various functions related
* to the Enhanced Field-Oriented Control (EFOC) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "md_lib/clarke/clarke.h"
#include "md_lib/park/park.h"
#include "md_lib/ipark/ipark.h"
#include "md_lib/svgen/svgen.h"
#include "md_lib/fullwave/fullwave.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the control type of the EFOC
*/
typedef enum
{
EFOC_CTRLTYPE_VVVF = 0,
EFOC_CTRLTYPE_CURRENTLOOP,
EFOC_CTRLTYPE_FULLWAVE,
EFOC_CTRLTYPE_OFFLINE,
} EFoc_CtrlModeType;
/*! \brief Defines all the parameters used to initialize EFOC object
*/
typedef struct _EFoc_ParamsType_
{
float VsMax_pu; /*!< Max allowed Vs */
float VdMaxScale; /*!< Max allowed Vd scale factor based on Vs. */
float minVdc_V; /*!< Minimum DC voltage allowed */
float maxVdc_V; /*!< Maximum DC voltage allowed */
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float flux_Wb; /*!< The flux of rotor */
float runFreq_kHz; /*!< Frequency to run FOC */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float VBase_V; /*!< Base value of voltage used for P.U. */
float ratedVdc_V; /*!< Rated dc bus voltage */
float IBase_A; /*!< Base value of current used for P.U. */
EFoc_CtrlModeType ctrlType; /*!< Control type of FOC */
float switchTime_ms; /*!< The switch time between FOC and full wave */
float fullwaveBWScale; /*!< Current control run frequency / Bandwidth in full wave mode */
float lambda; /*!< Control parameter for the decouple network */
float alpha; /*!< Control parameter for the Ls */
float beta; /*!< Control parameter for the Rs */
} EFoc_ParamsType;
/*! \brief Defines the dynamic parameters used to update EFOC object
*/
typedef struct _EFoc_DynamicParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float flux_Wb; /*!< The flux of rotor */
float runFreq_kHz; /*!< Frequency to run FOC */
_iq Vdc_pu; /*!< DC bus voltage */
float lambda; /*!< Control parameter for the decouple network */
float alpha; /*!< Control parameter for the Ls */
float beta; /*!< Control parameter for the Rs */
} EFoc_DynamicParamsType;
/*! \brief Defines the EFOC object
*/
typedef struct _EFocType_
{
_iq Ia_pu; /*!< Input: The phase-A current */
_iq Ib_pu; /*!< Input: The phase-B current */
_iq Ic_pu; /*!< Input: The phase-C current */
_iq parkSinTh; /*!< Input: The sin value for PARK transform */
_iq parkCosTh; /*!< Input: The cos value for PARK transform */
_iq iparkSinTh; /*!< Input: The sin value for IPARK transform */
_iq iparkCosTh; /*!< Input: The cos value for IPARK transform */
_iq Vref; /*!< Input: Only used in VVVF mode */
_iq IdRef; /*!< Input: The Id reference */
_iq IqRef; /*!< Input: The Iq reference */
_iq speed_pu; /*!< Input: Feedback speed in P.U. */
_iq compVd; /*!< Input: The compensation value of Vd, normally is 0 */
_iq compVq; /*!< Input: The compensation value of Vq, normally is 0 */
_iq VsMax; /*!< Parameters: Max value of Vs */
_iq VdMax; /*!< Parameters: Max value of Vd */
EFoc_CtrlModeType ctrlType; /*!< Parameters: Control type of FOC */
_iq minVdc_pu; /*!< Parameter: Minimum DC voltage allowed in P.U. */
_iq maxVdc_pu; /*!< Parameter: Maximum DC voltage allowed in P.U.*/
_iq Kr; /*!< Internal variable: coefficient determined by Rs */
_iq Kd_Vd; /*!< Internal variable: coefficient determined by Ld in Vd equation */
_iq Kq_Vd; /*!< Internal variable: coefficient determined by Lq in Vd equation */
_iq Kq_Vq; /*!< Internal variable: coefficient determined by Lq in Vq equation */
_iq Kd_Vq; /*!< Internal variable: coefficient determined by Ld in Vq equation */
_iq Kf; /*!< Internal variable: coefficient determined by flux in Vq equation */
float factorR; /*!< Internal variable: factor of IBase/VBase */
float factorL; /*!< Internal variable: factor of fBase*IBase/VBase */
float factorBemf; /*!< Internal variable: factor of fBase/VBase */
ClarkeType clarkeI; /*!< Internal variable: Clarke transform of current */
ParkType park; /*!< Internal variable: Part transform */
IparkType ipark; /*!< Internal variable: iPark transform */
SvgenType svgen; /*!< Internal variable: SVPWM generator */
FullWaveType fullwave; /*!< Internal variable: Full wave control */
_iq Vd; /*!< Internal variable: Vd */
_iq Vq; /*!< Internal variable: Vq */
_iq lastErrorId; /*!< Internal variable: Last error of Id */
_iq lastErrorIq; /*!< Internal variable: Last error of Iq */
_iq VdAccum; /*!< Internal variable: The accumulator of Vd */
_iq VqAccum; /*!< Internal variable: The accumulator of Vq */
_iq Vs; /*!< Output: Clarke transform of current */
} EFocType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the EFOC object
*
* This function initalizes EFoc by setting configuration parameters
*
* \param[in] obj : pointer to EFoc instance
* \param[in] pParams : pointer to EFoc configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t EFoc_Init(EFocType *obj, const EFoc_ParamsType *pParams);
/*! \brief Set the current feedback value
*
* This function sets current feedback value
*
* \param[in] obj : pointer to EFoc instance
* \param[in] Ia_pu : The phase-A current in P.U.
* \param[in] Ib_pu : The phase-B current in P.U.
* \param[in] Ic_pu : The phase-C current in P.U.
*/
static inline void EFoc_SetCurrentFdb(EFocType *obj, _iq Ia_pu, _iq Ib_pu, _iq Ic_pu)
{
obj->Ia_pu = Ia_pu;
obj->Ib_pu = Ib_pu;
obj->Ic_pu = Ic_pu;
}
/*! \brief The main process function of EFoc
*
* This function runs EFoc function, perform motor control functions
*
* \param[in] obj : pointer to EFoc instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t EFoc_Run(EFocType *obj);
/*! \brief Get the PWM compare value of EFoc
*
* This function gets three phase duty
*
* \param[in] obj : pointer to EFoc instance
* \param[out] Ta : the phase-A duty
* \param[out] Tb : the phase-B duty
* \param[out] Tc : the phase-C duty
*/
extern void EFoc_GetPwmCompareValue(EFocType *obj, _iq *Ta, _iq *Tb, _iq *Tc);
/*! \brief Reset the EFoc object
*
* This function resets the EFoc relevant calculation parameters
*
* \param[in] obj : pointer to EFoc instance
*/
extern void EFoc_Reset(EFocType *obj);
/*! \brief Update the parameters of EFoc
*
* This function updates the EFoc function configuration parameters
*
* \param[in] obj : pointer to EFoc instance
* \param[in] pParams : pointer to control configuration paramter
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t EFoc_UpdateParams(EFocType *obj, const EFoc_DynamicParamsType *pParams);
/*! \brief Change the control type of EFoc
*
* This function updates the EFoc function configuration parameters
*
* \param[in] obj : pointer to EFoc instance
* \param[in] ctrlType : the control type of the EFOC
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t EFoc_ChangeCtrlType(EFocType *obj, EFoc_CtrlModeType ctrlType);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _EFOC_H_ */

View File

@ -0,0 +1,241 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "foc.h"
/*******************************************************************************
* the defines
******************************************************************************/
#define FULL_WAVE_VS (_IQ(0.66666)) /* The Vs used in full wave mode */
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Foc_Init(FocType *obj, const Foc_ParamsType *pParams)
{
obj->ctrlType = pParams->ctrlType;
obj->minVdc_pu = _IQ(pParams->minVdc_V / pParams->VBase_V);
obj->maxVdc_pu = _IQ(pParams->maxVdc_V / pParams->VBase_V);
obj->factorKpKi = 2 * MATH_PI * pParams->IBase_A / pParams->VBase_V / pParams->bandWidthScale;
/* Calculate PID parameters */
_iq Ki_parallel = _IQ(2 * MATH_PI * pParams->Rs_Ohm / pParams->bandWidthScale
* pParams->IBase_A / pParams->ratedVdc_V);
_iq Kp_parallel = _IQ(2 * MATH_PI * pParams->Ld_mH * pParams->runFreq_kHz / pParams->bandWidthScale
* pParams->IBase_A / pParams->ratedVdc_V);
obj->VsMax = _IQ(pParams->VsMax_pu);
obj->VdMax = _IQ(pParams->VsMax_pu * pParams->VdMaxScale);
/* Apply to current PID, note that the pidIq limits will be set dynamically, so just set 0 when init */
Pid_Init(&obj->pidId, Kp_parallel, Ki_parallel, 0, -obj->VdMax, obj->VdMax);
Ki_parallel = _IQ(2 * MATH_PI * pParams->Rs_Ohm / pParams->bandWidthScale
* pParams->IBase_A / pParams->ratedVdc_V);
Kp_parallel = _IQ(2 * MATH_PI * pParams->Lq_mH * pParams->runFreq_kHz / pParams->bandWidthScale
* pParams->IBase_A / pParams->ratedVdc_V);
Pid_Init(&obj->pidIq, Kp_parallel, Ki_parallel, 0, 0, 0);
/* Full wave control */
FullWave_ParamsType fullwaveParams;
fullwaveParams.Rs_Ohm = pParams->Rs_Ohm;
fullwaveParams.Ld_mH = pParams->Ld_mH;
fullwaveParams.runFreq_kHz = pParams->runFreq_kHz;
fullwaveParams.ratedVdc_V = pParams->ratedVdc_V;
fullwaveParams.IBase_A = pParams->IBase_A;
fullwaveParams.VsMax = pParams->VsMax_pu;
fullwaveParams.VdMaxScale = pParams->VdMaxScale;
fullwaveParams.VsRampStep = FULL_WAVE_VS / (pParams->switchTime_ms * pParams->runFreq_kHz);
fullwaveParams.bandWidthScale = pParams->fullwaveBWScale;
FullWave_Init(&obj->fullwave, &fullwaveParams);
obj->svgen.mode = SVGEN_MODE_NORMAL;
obj->IdRef = 0;
obj->IqRef = 0;
obj->Vref = 0;
obj->Vdff = 0;
obj->Vqff = 0;
}
void Foc_Run(FocType *obj)
{
if(obj->ctrlType == FOC_CTRLTYPE_VVVF)
{
/* No current control */
obj->ipark.Ds = obj->Vref;
obj->ipark.Qs = 0;
}
else
{
/* Clarke transform */
obj->clarkeI.As = obj->Ia_pu;
obj->clarkeI.Bs = obj->Ib_pu;
obj->clarkeI.Cs = obj->Ic_pu;
Clarke_Run(&obj->clarkeI);
/* Park transform */
obj->park.alpha = obj->clarkeI.alpha;
obj->park.beta = obj->clarkeI.beta;
obj->park.sinTh = obj->parkSinTh;
obj->park.cosTh = obj->parkCosTh;
Park_Run(&obj->park);
if(obj->ctrlType == FOC_CTRLTYPE_CURRENTLOOP)
{
/* Id PID */
obj->pidId.ref = obj->IdRef;
obj->pidId.fdb = obj->park.Ds;
Pid_Run(&obj->pidId);
obj->Vd = _IQsat(obj->pidId.output + obj->Vdff, obj->VdMax, -obj->VdMax);
/* Vq limit calculation */
_iq VsMaxSqr = _IQmpy(obj->VsMax, obj->VsMax);
_iq VdSqr = _IQmpy(obj->Vd, obj->Vd);
_iq VqMaxSqr = VdSqr < VsMaxSqr ? VsMaxSqr - VdSqr : 0;
_iq VqMax = _IQsqrt(VqMaxSqr);
/* Iq PID */
obj->pidIq.outMax = VqMax;
obj->pidIq.outMin = -VqMax;
obj->pidIq.ref = obj->IqRef;
obj->pidIq.fdb = obj->park.Qs;
Pid_Run(&obj->pidIq);
obj->Vq = _IQsat(obj->pidIq.output + obj->Vqff, VqMax, -VqMax);
/* IPARK */
obj->ipark.Ds = obj->Vd;
obj->ipark.Qs = obj->Vq;
}
else if(obj->ctrlType == FOC_CTRLTYPE_FULLWAVE)
{
/* Full-wave control */
obj->fullwave.IqRef_pu = obj->IqRef;
obj->fullwave.Iq_pu = obj->park.Qs;
obj->fullwave.speed_pu = obj->speed_pu;
obj->fullwave.Vdff = obj->Vdff;
FullWave_Run(&obj->fullwave);
/* IPARK */
obj->ipark.Ds = obj->fullwave.Vd;
obj->ipark.Qs = obj->fullwave.Vq;
}
}
obj->ipark.sinTh = obj->iparkSinTh;
obj->ipark.cosTh = obj->iparkCosTh;
IPark_Run(&obj->ipark);
/* Calculate Vs */
obj->Vs = _IQmag(obj->ipark.Ds, obj->ipark.Qs);
/* SVGEN */
obj->svgen.Ualpha = obj->ipark.alpha;
obj->svgen.Ubeta = obj->ipark.beta;
Svgen_Run(&obj->svgen);
}
void Foc_GetPwmCompareValue(FocType *obj, _iq *Ta, _iq *Tb, _iq *Tc)
{
*Ta = obj->svgen.Ta;
*Tb = obj->svgen.Tb;
*Tc = obj->svgen.Tc;
}
void Foc_Reset(FocType *obj)
{
obj->IqRef = 0; /* Clear IqRef first just to be safe */
obj->IdRef = 0;
obj->pidId.Ui = 0;
obj->pidId.output = 0;
obj->pidIq.Ui = 0;
obj->pidIq.output = 0;
obj->Vd = 0;
obj->Vq = 0;
obj->ipark.Ds = 0;
obj->ipark.Qs = 0;
obj->Vdff = 0;
obj->Vqff = 0;
}
void Foc_UpdateParams(FocType *obj, const Foc_DynamicParamsType *pParams)
{
if(pParams->Vdc_pu >= obj->minVdc_pu && pParams->Vdc_pu <= obj->maxVdc_pu)
{
if(obj->ctrlType != FOC_CTRLTYPE_FULLWAVE)
{
obj->pidId.Kp = _IQdiv(_IQ(obj->factorKpKi * pParams->Ld_mH * pParams->runFreq_kHz), pParams->Vdc_pu);
obj->pidId.Ki = _IQdiv(_IQ(obj->factorKpKi * pParams->Rs_Ohm), pParams->Vdc_pu);
obj->pidIq.Kp = _IQdiv(_IQ(obj->factorKpKi * pParams->Lq_mH * pParams->runFreq_kHz), pParams->Vdc_pu);
obj->pidIq.Ki = obj->pidId.Ki;
}
else
{
FullWave_DynamicParamsType fullwaveDynamicParams;
fullwaveDynamicParams.Rs_Ohm = pParams->Rs_Ohm;
fullwaveDynamicParams.Ld_mH = pParams->Ld_mH;
fullwaveDynamicParams.runFreq_kHz = pParams->runFreq_kHz;
fullwaveDynamicParams.Vdc_pu = pParams->Vdc_pu;
FullWave_UpdateParams(&obj->fullwave, &fullwaveDynamicParams);
}
}
}
void Foc_ChangeCtrlType(FocType *obj, Foc_CtrlModeType ctrlType)
{
if(obj->ctrlType != FOC_CTRLTYPE_FULLWAVE
&& ctrlType == FOC_CTRLTYPE_FULLWAVE)
{ /* Switch to full wave control */
/* Remember the current Vd, Vq */
obj->fullwave.Vd = obj->ipark.Ds;
obj->fullwave.Vq = obj->ipark.Qs;
obj->fullwave.pidIq.output = -obj->fullwave.Vd;
obj->fullwave.pidIq.Ui = obj->fullwave.pidIq.output;
/* Change the target Vs */
FullWave_SetVsMax(&obj->fullwave, FULL_WAVE_VS);
obj->svgen.mode = SVGEN_MODE_SQUAREWAVE;
}
else if(obj->ctrlType == FOC_CTRLTYPE_FULLWAVE
&& ctrlType == FOC_CTRLTYPE_CURRENTLOOP)
{ /* Switch back to current loop */
/* Remember the current Vd, Vq */
obj->pidId.output = obj->ipark.Ds;
obj->pidId.Ui = obj->pidId.output;
obj->pidIq.output = obj->ipark.Qs;
obj->pidIq.Ui = obj->pidIq.output;
/* Change the target Vs */
FullWave_SetVsMax(&obj->fullwave, obj->VsMax);
obj->svgen.mode = SVGEN_MODE_NORMAL;
}
obj->ctrlType = ctrlType;
}

View File

@ -0,0 +1,212 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FOC_H_
#define _FOC_H_
/*! \brief Contains public interface to various functions related
* to the Field-Oriented Control (FOC) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/pid/pid.h"
#include "md_lib/clarke/clarke.h"
#include "md_lib/park/park.h"
#include "md_lib/ipark/ipark.h"
#include "md_lib/svgen/svgen.h"
#include "md_lib/fullwave/fullwave.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the control type of the FOC
*/
typedef enum
{
FOC_CTRLTYPE_VVVF = 0,
FOC_CTRLTYPE_CURRENTLOOP,
FOC_CTRLTYPE_FULLWAVE,
FOC_CTRLTYPE_OFFLINE,
} Foc_CtrlModeType;
/*! \brief Defines all the parameters used to initialize FOC object
*/
typedef struct _Foc_ParamsType_
{
float VsMax_pu; /*!< Max allowed Vs */
float VdMaxScale; /*!< Max allowed Vd scale factor based on Vs. */
float minVdc_V; /*!< Minimum DC voltage allowed */
float maxVdc_V; /*!< Maximum DC voltage allowed */
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float runFreq_kHz; /*!< Frequency to run FOC */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float ratedVdc_V; /*!< Rated dc bus voltage */
float VBase_V; /*!< Base value of voltage used for P.U. */
float IBase_A; /*!< Base value of current used for P.U. */
Foc_CtrlModeType ctrlType; /*!< Control type of FOC */
float switchTime_ms; /*!< The switch time between FOC and full wave */
float bandWidthScale; /*!< Current control run frequency / Bandwidth */
float fullwaveBWScale; /*!< Current control run frequency / Bandwidth in full wave mode */
} Foc_ParamsType;
/*! \brief Defines the dynamic parameters used to update FOC object
*/
typedef struct _Foc_DynamicParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float Lq_mH; /*!< Normal Q-axis inductance in mH */
float runFreq_kHz; /*!< Frequency to run FOC */
_iq Vdc_pu; /*!< DC bus voltage */
} Foc_DynamicParamsType;
/*! \brief Defines the FOC object
*/
typedef struct _FocType_
{
_iq Ia_pu; /*!< Input: The phase-A current */
_iq Ib_pu; /*!< Input: The phase-B current */
_iq Ic_pu; /*!< Input: The phase-C current */
_iq parkSinTh; /*!< Input: The sin value for PARK transform */
_iq parkCosTh; /*!< Input: The cos value for PARK transform */
_iq iparkSinTh; /*!< Input: The sin value for IPARK transform */
_iq iparkCosTh; /*!< Input: The cos value for IPARK transform */
_iq Vref; /*!< Input: Only used in VVVF mode */
_iq IdRef; /*!< Input: The Id reference */
_iq IqRef; /*!< Input: The Iq reference */
_iq speed_pu; /*!< Input: Feedback speed in P.U. */
_iq Vdff; /*!< Input: Feed-forward Vd */
_iq Vqff; /*!< Input: Feed-forward Vq */
_iq VsMax; /*!< Parameter: Max value of Vs */
_iq VdMax; /*!< Parameter: Max value of Vd */
Foc_CtrlModeType ctrlType; /*!< Parameter: Control type of FOC */
float factorKpKi; /*!< Parameter: The factor to calculate Kp Ki in runtime */
_iq minVdc_pu; /*!< Parameter: Minimum DC voltage allowed in P.U. */
_iq maxVdc_pu; /*!< Parameter: Maximum DC voltage allowed in P.U. */
PidType pidId; /*!< Internal variable: The PID control of Id current */
PidType pidIq; /*!< Internal variable: The PID control of Iq current */
ClarkeType clarkeI; /*!< Internal variable: Clarke transform of current */
ParkType park; /*!< Internal variable: Part transform */
IparkType ipark; /*!< Internal variable: iPark transform */
SvgenType svgen; /*!< Internal variable: SVPWM generator */
FullWaveType fullwave; /*!< Internal variable: Full wave control */
_iq Vd; /*!< Internal variable: Vd */
_iq Vq; /*!< Internal variable: Vq */
_iq Vs; /*!< Output: Clarke transform of current */
} FocType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the FOC object
*
* This function initalizes Foc by setting configuration parameters
*
* \param[in] obj : pointer to Foc instance
* \param[in] pParams : pointer to Foc configuration parameters
*/
extern void Foc_Init(FocType *obj, const Foc_ParamsType *pParams);
/*! \brief Set the current feedback value
*
* This function runs Foc function, perform motor control functions
*
* \param[in] obj : pointer to Foc instance
* \param[in] Ia_pu : The phase-A current in P.U.
* \param[in] Ib_pu : The phase-B current in P.U.
* \param[in] Ic_pu : The phase-C current in P.U.
*/
static inline void Foc_SetCurrentFdb(FocType *obj, _iq Ia_pu, _iq Ib_pu, _iq Ic_pu)
{
obj->Ia_pu = Ia_pu;
obj->Ib_pu = Ib_pu;
obj->Ic_pu = Ic_pu;
}
/*! \brief The main process function of Foc
*
* This function runs Foc function, perform motor control functions
*
* \param[in] obj : pointer to Foc instance
*/
extern void Foc_Run(FocType *obj);
/*! \brief Get the PWM compare value of Foc
*
* This function gets three phase duty
*
* \param[in] obj : pointer to Foc instance
* \param[out] Ta : the phase-A duty
* \param[out] Tb : the phase-B duty
* \param[out] Tc : the phase-C duty
*/
extern void Foc_GetPwmCompareValue(FocType *obj, _iq *Ta, _iq *Tb, _iq *Tc);
/*! \brief Reset the Foc object
*
* This function resets the Foc relevant calculation parameters
*
* \param[in] obj : pointer to Foc instance
*/
extern void Foc_Reset(FocType *obj);
/*! \brief Update the parameters of Foc
*
* This function updates the Foc function configuration parameters
*
* \param[in] obj : pointer to Foc instance
* \param[in] pParams : pointer to control configuration paramter
*/
extern void Foc_UpdateParams(FocType *obj, const Foc_DynamicParamsType *pParams);
/*! \brief Change the control type of Foc
*
* This function updates the Foc function configuration parameters
*
* \param[in] obj : pointer to Foc instance
* \param[in] ctrlType : the control type of the FOC
*/
extern void Foc_ChangeCtrlType(FocType *obj, Foc_CtrlModeType ctrlType);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FOC_H_ */

View File

@ -0,0 +1,150 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FULLWAVE_H_
#define _FULLWAVE_H_
/*! \brief Contains public interface to various functions related
* to the full-wave control (FULLWAVE) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#include "common/pid/pid.h"
#include "common/curve/ramp.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize FULLWAVE object
*/
typedef struct _FullWave_ParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float runFreq_kHz; /*!< Frequency to run FOC */
float ratedVdc_V; /*!< Rated dc bus voltage */
float IBase_A; /*!< Base value of current used for P.U. */
float VBase_V; /*!< Base value of voltage used for P.U. */
float VsMax; /*!< Max allowed Vs */
float VdMaxScale; /*!< Max allowed Vd scale factor based on Vs. */
float VsRampStep; /*!< The step of changing the Vs */
float bandWidthScale; /*!< Current control run frequency / Bandwidth */
float minVdc_V; /*!< Minimum DC voltage allowed */
float maxVdc_V; /*!< Minimum DC voltage allowed */
} FullWave_ParamsType;
/*! \brief Defines the dynamic parameters used to update FULLWAVE object
*/
typedef struct _FullWave_DynamicParamsType_
{
float Rs_Ohm; /*!< Stationary resistance in Ohm */
float Ld_mH; /*!< Normal D-axis inductance in mH */
float runFreq_kHz; /*!< Frequency to run FOC */
_iq Vdc_pu; /*!< DC bus voltage */
} FullWave_DynamicParamsType;
/*! \brief Defines the FULLWAVE object
*/
typedef struct _FullWaveType_
{
_iq IqRef_pu; /*!< Input: Command Iq current in P.U. */
_iq Iq_pu; /*!< Input: Feedback Iq current in P.U. */
_iq speed_pu; /*!< Input: Feedback speed in P.U. */
_iq Vdff; /*!< Input: Feed-forward Vd */
float factorKpKi; /*!< Parameter: The factor to calculate Kp and Ki */
_iq minVdc_pu; /*!< Parameter: Minimum DC voltage allowed in P.U. */
_iq maxVdc_pu; /*!< Parameter: Maximum DC voltage allowed in P.U. */
PidType pidIq; /*!< Internal variable: The PID to tune Iq */
RampType rampVs; /*!< Internal variable: The ramp of changing the Vs */
_iq VdMaxScale; /*!< Internal variable: Max allowed Vd scale factor based on Vs. */
_iq VsMax; /*!< Internal variable: The Max ABS value of Vs */
_iq Vd; /*!< Output: Vd */
_iq Vq; /*!< Output: Vq */
} FullWaveType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the FullWave object
*
* This function initalizes FullWave by setting configuration parameters
*
* \param[in] obj : pointer to FullWave instance
* \param[in] pParams : pointer to FullWave configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t FullWave_Init(FullWaveType *obj, const FullWave_ParamsType *pParams);
/*! \brief Run the full wave control
*
* This function runs full wave control function, perform motor control functions
*
* \param[in] obj : pointer to FullWave instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t FullWave_Run(FullWaveType *obj);
/*! \brief Set the Vs max
*
* This function sets Vs max value
*
* \param[in] obj : pointer to FullWave instance
* \param[in] VsMax : Vs max value
*/
extern void FullWave_SetVsMax(FullWaveType *obj, _iq VsMax);
/*! \brief Update the parameters
*
* This function updates the FullWave function configuration parameters
*
* \param[in] obj : pointer to FullWave instance
* \param[in] pParams : pointer to control configuration paramter
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t FullWave_UpdateParams(FullWaveType *obj, const FullWave_DynamicParamsType *pParams);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FULLWAVE_H_ */

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "fw.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*! \brief Defines the Field Weakening (FW) increment delta correction
*/
#define FW_INC_DELTA (0.00002)
/*! \brief Defines the Field Weakening (FW) decrement delta correction
*/
#define FW_DEC_DELTA (0.00002)
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Fw_Init(FwType *obj, _iq maxNegIdRef)
{
obj->outMax = 0;
obj->outMin = maxNegIdRef;
obj->deltaInc = _IQ(FW_INC_DELTA);
obj->deltaDec = _IQ(FW_DEC_DELTA);
obj->output = 0;
}
void Fw_Run(FwType *obj)
{
if(obj->refValue > obj->fbackValue)
{
obj->output += obj->deltaInc;
}
else if(obj->refValue < obj->fbackValue)
{
obj->output -= obj->deltaDec;
}
obj->output = _IQsat(obj->output, obj->outMax, obj->outMin); /* Saturate the output */
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _FW_H_
#define _FW_H_
/*! \brief Contains public interface to various functions related
* to the Field Weakening (FW) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
typedef struct _FwType_
{
_iq refValue; /*!< Input: The reference value */
_iq fbackValue; /*!< Input: The feedback value */
_iq outMax; /*!< Parameter: Maximum output */
_iq outMin; /*!< Parameter: Minimum output */
_iq deltaInc; /*!< Parameter: The field weakening delta increment of Id reference */
_iq deltaDec; /*!< Parameter: The field weakening delta decrement of Id reference */
_iq output; /*!< Output: The output of field weakening */
} FwType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the Fw object
*
* This function initalizes Fw by setting configuration parameters
*
* \param[in] obj : pointer to Fw instance
* \param[in] maxNegIdRef : max -id reference value
*/
extern void Fw_Init(FwType *obj, _iq maxNegIdRef);
/*! \brief Run the field weakening control
*
* This function runs Fw function, perform motor control functions
*
* \param[in] obj : pointer to Fw instance
*/
extern void Fw_Run(FwType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _FW_H_ */

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IPARK_H_
#define _IPARK_H_
/*! \brief Contains the public interface to the
* Park transform module routines
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the IPARK object
*
*/
typedef struct _IparkType_
{
_iq sinTh; /*!< Input: sin value of rotating angle (pu) */
_iq cosTh; /*!< Input: cos value of rotating angle (pu) */
_iq Ds; /*!< Input: rotating d-axis stator variable */
_iq Qs; /*!< Input: rotating q-axis stator variable */
_iq alpha; /*!< Output: stationary alpha-axis stator variable */
_iq beta; /*!< Output: stationary beta-axis stator variable */
} IparkType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Process the IPARK algorithm
*
* This function runs IPARK function to calculate stationary axis variable
*
* \param[in] obj : pointer to Ipark instance
*/
static inline void IPark_Run(IparkType *obj)
{
obj->alpha = _IQmpy(obj->Ds, obj->cosTh) - _IQmpy(obj->Qs, obj->sinTh);
obj->beta = _IQmpy(obj->Qs, obj->cosTh) + _IQmpy(obj->Ds, obj->sinTh);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IPARK_H_ */

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _HFI_H_
#define _HFI_H_
/*! \brief Contains public interface to various functions related
* to the Initial Position Detection (IPD) using
* High Frequency Injection method (HFI) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/filter/bp_so.h"
#include "common/filter/iir_fo.h"
#include "common/pid/pid.h"
#include "md_lib/fag/fag.h"
#include "md_lib/park/park.h"
#include "md_lib/clarke/clarke.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize HFI object
*/
typedef struct _Hfi_ParamsType_
{
float runFreq_kHz; /*!< Frequency to run the process */
float injectFreq_kHz; /*!< The injected frequency in kHz */
float injectVd_pVdc; /*!< The injected frequency per Vdc */
float lpfPole_rps; /*!< Pole value of low pass filter in rad/s */
float pllPole_rps; /*!< Pole value of PLL in rad/s */
float Ld_mH; /*!< d-axis inductance in mH */
float Lq_mH; /*!< q-axis inductance in mH */
float ratedVdc_V; /*!< Rated DC bus voltage in Volts */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float compFactor; /*!< The factor to compensate the high-frequency voltage and current */
} Hfi_ParamsType;
/*! \brief Defines the HFI object
*/
typedef struct _HfiType_
{
_iq Ia_pu; /*!< Input: The phase-A current */
_iq Ib_pu; /*!< Input: The phase-B current */
_iq Ic_pu; /*!< Input: The phase-C current */
_iq VdAmplitude; /*!< Internal Variable: The amplitude of high-frequency Vd */
_iq compAngle_pu; /*!< Internal Variable: The compensation angle */
_iq angleFactor; /*!< Internal Variable: Factor to calculate angle from speed */
_iq nextAngle_pu; /*!< Internal variable: The angle for next control loop */
ClarkeType clarkeI; /*!< Internal Variable: The Clarke transform for current */
IirFoType lpf; /*!< Internal Variable: The low pass filter for the Iq */
BpSoType IalphaBpf; /*!< Internal Variable: The band-pass filter for the alpha-axis current */
BpSoType IbetaBpf; /*!< Internal Variable: The band-pass filter for the beta-axis current */
FagType fag; /*!< Internal Variable: The high-frequency angle generator */
ParkType park; /*!< Internal Variable: The PARK transform of the injected high-frequency current */
PidType pidPLL; /*!< Internal Variable: The PLL PID */
_iq Vd_hf; /*!< Output: The high-frequency Vd */
_iq estAngle; /*!< Output: The delta angle between the true angle and the one passed in from inputs */
} HfiType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the HFI object
*
* This function initalizes Hfi by setting configuration parameters
*
* \param[in] obj : pointer to Hfi instance
* \param[in] pParams : pointer to Hfi configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Hfi_Init(HfiType *obj, const Hfi_ParamsType *pParams);
/*! \brief Run the HFI process
*
* This function runs Hfi function to control motor
*
* \param[in] obj : pointer to Hfi instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Hfi_Run(HfiType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _HFI_H_ */

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/interp/interp2d.h"
#include "ipm_pte.h"
#include "ipm.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Ipm_Init(IpmType *obj, const Ipm_ParamsType *pParams)
{
obj->type = pParams->type;
obj->maxRows = pParams->maxRows;
obj->maxColumns = pParams->maxColumns;
obj->defaultRs_Ohm = pParams->defaultRs_Ohm;
obj->defaultLd_mH = pParams->defaultLd_mH;
obj->defaultLq_mH = pParams->defaultLq_mH;
obj->defaultPsi_Wb = pParams->defaultPsi_Wb;
obj->Rs_Ohm = obj->defaultRs_Ohm;
if(obj->type == IPM_OUTPUTTYPE_FIXED)
{
obj->Ld_mH = obj->defaultLd_mH;
obj->Lq_mH = obj->defaultLq_mH;
obj->Psi_Wb = obj->defaultPsi_Wb;
}
else if(obj->type == IPM_OUTPUTTYPE_DYNAMIC)
{
Table_Init(&obj->paramTable, pParams->pContainer, obj->maxRows, obj->maxColumns);
/* Calculate row and column interval, the table must have at least 4 elements */
IpmPteType elem00;
IpmPteType elem01;
IpmPteType elem10;
Table_GetElement(&obj->paramTable, (void *)&elem00, sizeof(IpmPteType), 0, 0);
Table_GetElement(&obj->paramTable, (void *)&elem01, sizeof(IpmPteType), 0, 1);
Table_GetElement(&obj->paramTable, (void *)&elem10, sizeof(IpmPteType), 1, 0);
/*! \note The interval between rows and columns must the same for the whole table */
obj->rowInterval = _IQabs(elem10.absId_pu - elem00.absId_pu);
obj->columnInterval = _IQabs(elem01.absIq_pu - elem00.absIq_pu);
obj->oneOverRowIntvl = _IQdiv(_IQ(1.0), obj->rowInterval);
obj->oneOverColumnIntvl = _IQdiv(_IQ(1.0), obj->columnInterval);
}
}
void Ipm_Calc(IpmType *obj)
{
if(obj->type == IPM_OUTPUTTYPE_DYNAMIC)
{
/* The row and column index value should all be ABS */
obj->absId_pu = _IQabs(obj->Id_pu);
obj->absIq_pu = _IQabs(obj->Iq_pu);
/* Find row */
/*! \note The interval between rows must the same for the whole table */
uint16_t row = (uint16_t)(obj->absId_pu / obj->rowInterval);
row = (row > obj->maxRows - 2 ? obj->maxRows - 2 : row);
/* Find column */
/*! \note The interval between columns must the same for the whole table */
uint16_t column = (uint16_t)(obj->absIq_pu / obj->columnInterval);
column = (column > obj->maxColumns - 2 ? obj->maxColumns - 2 : column);
/* Find 4 elements */
IpmPteType topLeft;
IpmPteType topRight;
IpmPteType bottomLeft;
IpmPteType bottomRight;
Table_GetElement(&obj->paramTable, (void *)&topLeft, sizeof(IpmPteType), row, column);
Table_GetElement(&obj->paramTable, (void *)&topRight, sizeof(IpmPteType), row, column + 1);
Table_GetElement(&obj->paramTable, (void *)&bottomLeft, sizeof(IpmPteType), row + 1, column);
Table_GetElement(&obj->paramTable, (void *)&bottomRight, sizeof(IpmPteType), row + 1, column + 1);
_iq rowScale = _IQmpy(obj->absId_pu - topLeft.absId_pu, obj->oneOverRowIntvl);
rowScale = (rowScale > _IQ(1.0) ? _IQ(1.0) : (rowScale < 0 ? 0 : rowScale));
_iq columnScale = _IQmpy(obj->absIq_pu - topLeft.absIq_pu, obj->oneOverColumnIntvl);
columnScale = (columnScale > _IQ(1.0) ? _IQ(1.0) : (columnScale < 0 ? 0 : columnScale));
/* Calculate Ld */
obj->Ld_mH = Interp2d(topLeft.Ld_mH, topRight.Ld_mH, bottomLeft.Ld_mH, bottomRight.Ld_mH, rowScale, columnScale);
/* Calculate Lq */
obj->Lq_mH = Interp2d(topLeft.Lq_mH, topRight.Lq_mH, bottomLeft.Lq_mH, bottomRight.Lq_mH, rowScale, columnScale);
/* Calculate Psi */
obj->Psi_Wb = Interp2d(topLeft.Psi_wb, topRight.Psi_wb, bottomLeft.Psi_wb, bottomRight.Psi_wb, rowScale, columnScale);
}
}

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IPM_H_
#define _IPM_H_
/*! \brief Contains public interface to various functions related
* to the Interior Permanent Magnet Motor (IPM)
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/container/table.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the motor object
*/
typedef enum
{
IPM_OUTPUTTYPE_FIXED,
IPM_OUTPUTTYPE_DYNAMIC,
} Ipm_ParamsModeType;
/*! \brief Defines the initial parameters for IPM object
*/
typedef struct _Ipm_ParamsType_
{
Ipm_ParamsModeType type; /*!< How the use motor parameters */
void *pContainer; /*!< Pointer to the table container */
uint16_t maxRows; /*!< Max row number of motor parameter 2-D table */
uint16_t maxColumns; /*!< Max column number of motor parameter 2-D table */
_iq defaultRs_Ohm; /*!< The default value of Rs */
_iq defaultLd_mH; /*!< The default value of Ld */
_iq defaultLq_mH; /*!< The default value of Lq */
_iq defaultPsi_Wb; /*!< The default value of Psi */
} Ipm_ParamsType;
/*! \brief Defines the motor object
*/
typedef struct _IpmType_
{
_iq temp_pu; /*!< Input: Motor temperature */
_iq Id_pu; /*!< Input: D-axis current */
_iq Iq_pu; /*!< Input: Q-axis current */
Ipm_ParamsModeType type; /*!< Parameter: How to use motor parameters */
uint16_t maxRows; /*!< Parameter: Max row number of motor parameter matrix */
uint16_t maxColumns; /*!< Parameter: Max column number of motor parameter matrix */
_iq defaultRs_Ohm; /*!< Parameter: The default value of Rs */
_iq defaultLd_mH; /*!< Parameter: The default value of Ld */
_iq defaultLq_mH; /*!< Parameter: The default value of Lq */
_iq defaultPsi_Wb; /*!< Parameter: The default value of Psi */
TableType paramTable; /*!< Internal variable: The motor parameter table */
_iq rowInterval; /*!< Internal variable: The interval between rows of motor parameter matrix */
_iq columnInterval; /*!< Internal variable: The interval between columns of motor parameter matrix */
_iq oneOverRowIntvl; /*!< Internal variable: Reciprocal of interval between rows of motor parameter matrix */
_iq oneOverColumnIntvl; /*!< Internal variable: Reciprocal of interval between columns of motor parameter matrix */
_iq absId_pu; /*!< Internal variable: ABS value of D-axis current */
_iq absIq_pu; /*!< Internal variable: ABS value of Q-axis current */
_iq Rs_Ohm; /*!< Output: The stator resistance in P.U. */
_iq Ld_mH; /*!< Output: The direct stator inductance in P.U. */
_iq Lq_mH; /*!< Output: The quadrature stator inductance in P.U. */
_iq Psi_Wb; /*!< Output: The permanent magnet flux in P.U. */
} IpmType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the IPM object
*
* This function initalizes Ipm by setting configuration parameters
*
* \param[in] obj : pointer to Ipm instance
* \param[in] pParams : pointer to Ipm configuration parameters
*/
extern void Ipm_Init(IpmType *obj, const Ipm_ParamsType *pParams);
/*! \brief Calculates and Gets the Ipm parameters
*
* This function calculates and gets the Ipm parameters from table data
*
* \param[in] obj : pointer to Ipm instance
*/
extern void Ipm_Calc(IpmType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IPM_H_ */

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _IPM_PTE_H_
#define _IPM_PTE_H_
/*! \brief Contains public interface to various functions related
* to the Interior Permanent Magnet Motor (IPM)
* Parameters Table Element (PTE)
*/
/*******************************************************************************
* the includes
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the IPM parameters table element
* \note To make it simple we use the ABS value for the row and column,
* but actually the Id normally is negative, and Iq is irrelevant of
* the sign.
* \note The size must align to 4 bytes
*/
typedef struct _IpmPteType_
{
_iq absId_pu; /*!< Donate the row variable - ABS Id value in P.U. */
_iq absIq_pu; /*!< Donate the column variable - ABS Iq value in P.U. */
_iq Ld_mH; /*!< Donate the D-axis inductance in mH */
_iq Lq_mH; /*!< Donate the D-axis inductance in mH */
_iq Psi_wb; /*!< Donate the permanent magnet flux in Wb */
} IpmPteType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _IPM_PTE_H_ */

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PARK_H_
#define _PARK_H_
/*! \brief Contains the public interface to the
* Park transform module routines
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the PARK object
*/
typedef struct _ParkType_
{
_iq alpha; /*!< Input: stationary d-axis stator variable */
_iq beta; /*!< Input: stationary q-axis stator variable */
_iq sinTh; /*!< Input: sin value of rotating angle (pu) */
_iq cosTh; /*!< Input: cos value of rotating angle (pu) */
_iq Ds; /*!< Output: rotating d-axis stator variable */
_iq Qs; /*!< Output: rotating q-axis stator variable */
} ParkType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The main process function of Park
*
* This function runs Park function to calculate rotating axis variable
*
* \param[in] obj : pointer to Park instance
*/
static inline void Park_Run(ParkType *obj)
{
obj->Ds = _IQmpy(obj->alpha, obj->cosTh) + _IQmpy(obj->beta, obj->sinTh);
obj->Qs = _IQmpy(obj->beta, obj->cosTh) - _IQmpy(obj->alpha, obj->sinTh);
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PARK_H_ */

View File

@ -0,0 +1,106 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PCUD_H_
#define _PCUD_H_
/*! \brief Contains public interface to various functions related
* to the phase current unbalance detection (PCUD) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize PCUD object
*/
typedef struct _Pcud_ParamsType_
{
float unbalanceTh; /*!< the threshold of unbalance, normally will be 1.2 (120%) */
float minDetectI_A; /*!< the minimum detect current in A */
float minDetectFreq_Hz; /*!< the minimum detect frequency in Hz */
float IBase_A; /*!< the current base value in A */
float fBase_Hz; /*!< the base value of frequency used for P.U. */
} Pcud_ParamsType;
/*! \brief Defines the PCUD object
*/
typedef struct _PcudType_
{
_iq Ia_rms; /*!< Input: phase A current */
_iq Ib_rms; /*!< Input: phase B current */
_iq Ic_rms; /*!< Input: phase C current */
_iq speed_pu; /*!< Input: speed feedback in P.U. */
_iq unbalanceTh; /*!< Parameter: The threshold of unbalance */
_iq minDetectI_pu; /*!< Parameter: The minimum detect current in P.U. */
_iq minDetectFreq_pu; /*!< Parameter: The minimum detect frequency in P.U. */
bool isUnbalance; /*!< Output: Whether is unbalanced */
} PcudType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the PCUD object
*
* This function initalizes Pcud by setting configuration parameters
*
* \param[in] obj : pointer to Pcud instance
* \param[in] pParams : pointer to Pcud configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pcud_Init(PcudType *obj, const Pcud_ParamsType *pParams);
/*! \brief Run the PCUD process
*
* This function runs the phase current unbalance detection
*
* \param[in] obj : pointer to Pcud instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pcud_Run(PcudType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PCUD_H_ */

View File

@ -0,0 +1,126 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PHLACK_H_
#define _PHLACK_H_
/*! \brief Contains public interface to various functions related
* to the Phase-lacking (PHLACK) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize PHLACK object
*/
typedef struct _Phlack_ParamsType_
{
float runFreq_kHz; /*!< the frequency of running current loop in kHz */
float Vref; /*!< the reference voltage used to detect the current */
float detectFreq_Hz; /*!< the reference frequency used to detect the current */
float detectTime_ms; /*!< the time used to detect the phase lacking */
float currentTh_A; /*!< the current threshold used to determine the phase lacking */
float IBase_A; /*!< the base value of phase current in A */
float fBase_Hz; /*!< the frequency base value in Hz */
float VBase_V; /*!< the base value of voltage in V */
} Phlack_ParamsType;
typedef enum
{
PHLACK_STATUS_FINISH = 0,
PHLACK_STATUS_RUNNING,
} Phlack_StatusType;
/*! \brief Defines the PHLACK object
*/
typedef struct _PhlackType_
{
bool startCmd; /*!< Input: True to command to start, will set false when finished */
_iq Ia_pu; /*!< Input: The current of phase A */
_iq Ib_pu; /*!< Input: the current of phase B */
_iq Ic_pu; /*!< Input: the current of phase C */
_iq detectFreq_pu; /*!< Parameter: The reference frequency used to detect the current */
_iq detectVolt_pu; /*!< Parameter: The reference voltage used to detect the current */
_iq currentTh_pu; /*!< Parameter: The current threshold used to determine the phase lacking */
uint32_t scanCountMax; /*!< Parameter: The max value of count used for timing */
uint32_t scanCount; /*!< Internal variable: The count value used for scan timing */
Phlack_StatusType status; /*!< Internal variable: The status of the current process */
bool flagA; /*!< Internal variable: The phase lacking flag of phase A */
bool flagB; /*!< Internal variable: The phase lacking flag of phase B */
bool flagC; /*!< Internal variable: The phase lacking flag of phase C */
_iq Vref_pu; /*!< Output: The reference voltage in P.U. */
_iq freqRef_pu; /*!< Output: The reference frequency in P.U. */
bool lackingPhaseA; /*!< Output: The final flag output of lacking phase A */
bool lackingPhaseB; /*!< Output: The final flag output of lacking phase B */
bool lackingPhaseC; /*!< Output: The final flag output of lacking phase C */
} PhlackType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the PHLACK object
*
* This function initalizes Phlack by setting configuration parameters
*
* \param[in] obj : pointer to Phlack instance
* \param[in] pParams : pointer to Phlack configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Phlack_Init(PhlackType *obj, const Phlack_ParamsType *pParams);
/*! \brief Run the PHLACK process
*
* This function runs the phase-lacking detection
*
* \param[in] obj : pointer to Phlack instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Phlack_Run(PhlackType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PHLACK_H_ */

View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PVCR_H_
#define _PVCR_H_
/*! \brief Contains public interface to various functions related
* Phase Voltage and Current Reconstruction (PVCR) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize PVCR object
*/
typedef struct _Pvcr_ParamsType_
{
float Tdb; /*!< The percent taking account of dead-band time and rise/fall time */
} Pvcr_ParamsType;
/*! \brief Defines the PVCR object
*/
typedef struct _PvcrType_
{
_iq sensedIa; /*!< Input: The sampled current of phase A */
_iq sensedIb; /*!< Input: The sampled current of phase B */
_iq sensedIc; /*!< Input: The sampled current of phase C */
_iq Ta; /*!< Input: 100%-(duty of phase A) */
_iq Tb; /*!< Input: 100%-(duty of phase B) */
_iq Tc; /*!< Input: 100%-(duty of phase C) */
_iq Vdc; /*!< Input: Voltage of DC */
_iq Tdb; /*!< Parameter: The percent taking account of dead-band time and rise/fall time */
_iq offsetV; /*!< Internal variable: The offset voltage of 3 phases, note that all 3 phases's offset are the same */
_iq prevTa; /*!< Internal variable: The previous Ta */
_iq prevTb; /*!< Internal variable: The previous Tb */
_iq prevTc; /*!< Internal variable: The previous Tc */
_iq prevPrevTa; /*!< Internal variable: The previous of previous Ta */
_iq prevPrevTb; /*!< Internal variable: The previous of previous Tb */
_iq prevPrevTc; /*!< Internal variable: The previous of previous Tc; */
_iq prevIa; /*!< Internal variable: The previous Ia */
_iq prevIb; /*!< Internal variable: The previous Ib */
_iq prevIc; /*!< Internal variable: The previous Ic */
_iq Va; /*!< Output: The estimated phase A voltage at the middle of last PWM period */
_iq Vb; /*!< Output: The estimated phase B voltage at the middle of last PWM period */
_iq Vc; /*!< Output: The estimated phase C voltage at the middle of last PWM period */
_iq Ia; /*!< Output: The estimated phase A current at the middle of last PWM period */
_iq Ib; /*!< Output: The estimated phase A current at the middle of last PWM period */
_iq Ic; /*!< Output: The estimated phase A current at the middle of last PWM period */
} PvcrType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the PVCR object
*
* This function initalizes Pvcr by setting configuration parameters
*
* \param[in] obj : pointer to Pvcr instance
* \param[in] pParams : pointer to Pvcr configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pvcr_Init(PvcrType *obj, const Pvcr_ParamsType *pParams);
/*! \brief Run the PVCR process
* \note The input must use the FOC control result from this loop
*
* This function runs the phase Voltage and current reconstruction function
*
* \param[in] obj : pointer to Pvcr instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pvcr_Run(PvcrType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PVCR_H_ */

View File

@ -0,0 +1,130 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _PWMDBC_H_
#define _PWMDBC_H_
/*! \brief Contains public interface to various functions related
* to the PWM Dead-band Compensation (PWMDBC) object.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines all the parameters used to initialize PWMDBC object
*/
typedef struct _Pwmdbc_ParamsType_
{
float Tdb; /*!< The percent taking account of dead-band time and rise/fall time */
float zeroCurrentTh_A; /*!< The threshold for zero current, in A */
float IBase_A; /*!< Base value of current used for P.U. */
float gain; /*!< Gain value for the compensation */
} Pwmdbc_ParamsType;
/*! \brief Defines the dynamic parameters used to update PWMDBC object
*/
typedef struct _Pwmdbc_DynamicParamsType_
{
float Tdb; /*!< The percent taking account of dead-band time and rise/fall time */
float zeroCurrentTh_A; /*!< The threshold for zero current, in A */
float gain; /*!< Gain value for the compensation */
} Pwmdbc_DynamicParamsType;
/*! \brief Defines the PWMDBC object
*/
typedef struct _PwmdbcType_
{
_iq TaUncomp; /*!< Input: (duty of phase A) - 50% before compensation */
_iq TbUncomp; /*!< Input: (duty of phase B) - 50% before compensation */
_iq TcUncomp; /*!< Input: (duty of phase C) - 50% before compensation */
_iq Ia_pu; /*!< Input: The sampled current of phase A */
_iq Ib_pu; /*!< Input: The sampled current of phase B */
_iq Ic_pu; /*!< Input: The sampled current of phase C */
_iq Tdb; /*!< Parameter: The percent taking account of dead-band time and rise/fall time */
_iq scale; /*!< Parameter: The scale of dead-band percent */
_iq zeroCurrentTh_pu; /*!< Parameter: The threshold for zero current, in P.U. */
float IBase_A; /*!< Parameter: Base value of current used for P.U. */
_iq TaComp; /*!< Input: (duty of phase A) - 50% after compensation */
_iq TbComp; /*!< Input: (duty of phase B) - 50% after compensation */
_iq TcComp; /*!< Input: (duty of phase C) - 50% after compensation */
} PwmdbcType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the PWMDBC object
*
* This function initalizes Pwmdbc by setting configuration parameters
*
* \param[in] obj : pointer to Pwmdbc instance
* \param[in] pParams : pointer to Pwmdbc configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pwmdbc_Init(PwmdbcType *obj, const Pwmdbc_ParamsType *pParams);
/*! \brief Run the PWMDBC process
*
* This function runs the pwm dead-band compensation function
*
* \param[in] obj : pointer to Pwmdbc instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pwmdbc_Run(PwmdbcType *obj);
/*! \brief Update the parameters of PWMDBC
*
* This function updates the Pwmdbc function configuration parameters
*
* \param[in] obj : pointer to Pwmdbc instance
* \param[in] pParams : pointer to control configuration paramter
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Pwmdbc_UpdateParams(PwmdbcType *obj, const Pwmdbc_DynamicParamsType *pParams);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _PWMDBC_H_ */

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _HALL_H_
#define _HALL_H_
/*! \brief Contains the public interface to the hall abstract class.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#include "common/filter/iir_fo.h"
#include "../fag/fag.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the hall parameters
*/
typedef struct _Hall_ParamsType_
{
float phaseCalcFreq_kHz; /*!< Frequency to run phase calculation */
float spdCalcFreq_kHz; /*!< Frequency to run speed calculation */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float spdFilterPole_rps; /*!< Pole value of speed filter calculation */
float stamptimerFreq_Hz; /*!< Base clock source frequency */
uint8_t* pForwardHalSqe; /*!< Hall value order */
float timeOutFreq_Hz; /*!< Timeout detection frequency */
} Hall_ParamsType;
/*! \brief Defines the hall object
*/
typedef struct _HallType_
{
uint8_t halValue; /*!< Input: Current hall value */
uint32_t timerCntDiff; /*!< Input: Time of change hall value */
uint32_t dirRef; /*!< Input: Desired direction at startup */
_iq hallAngleBuf_pu[7]; /*!< Parameter: Hall Angle value used for P.U */
uint16_t cntInCycle; /*!< Parameter: Mechanical commutation threshold value */
uint32_t timerOutCnt; /*!< Parameter: Time out count threshold value */
float spdCalCoef; /*!< Parameter: Coefficient of speed calculation*/
float spdCalFastCoef; /*!< Parameter: Coefficient of fast speed calculation*/
_iq halCalibAngle_pu; /*!< Internal variable: Current hall value angle used for P.U */
uint32_t timerCntDiffCycle; /*!< Internal variable: The time count after one turn of the electric angle */
uint8_t halValuePre; /*!< Internal variable: previous hall value */
bool reStartFlag; /*!< Internal variable: Start flag */
int16_t reStartCnt; /*!< Internal variable: Start flag */
uint16_t commutationCnt; /*!< Internal variable: Commutation count */
FagType hallEstObj; /*!< Internal variable: Angle estimation object */
FagType startAngleObj; /*!< Internal variable: Start Angle calculate object */
uint32_t timerCnt; /*!< Internal variable: Running time counter */
uint32_t reStartTimerCnt; /*!< Internal variable: Running time counter */
_iq rawSpeed_pu; /*!< Internal variable: The raw speed before filter in P.U. */
_iq rawSpeedFast_pu; /*!< Internal variable: The raw fast speed in P.U. */
IirFoType filterSpd; /*!< Internal Variable: The filter for electric speed calculation */
_iq angle_pu; /*!< Output: The electrical angle in P.U. */
uint8_t speedDir; /*!< Output: The electrical angle in P.U. */
_iq speed_pu; /*!< Output: The speed in P.U. */
} HallType;
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize hall
*
* This function Initialize hall object by setting configuration parameters
*
* \param[in] obj : pointer to hall instance
* \param[in] pParams : pointer to hall configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Hall_Init(HallType *obj, const Hall_ParamsType *pParams);
/*! \brief Calculate the angle for PARK and IPARK module
*
* \note Must run in the same frequency with current control loop
*
* \param[in] obj : pointer to hall instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Hall_EstAngle(HallType *obj);
/*! \brief Calculate the speed
*
* \note Might run slower than current control frequency
*
* \param[in] obj : pointer to Hall instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Hall_CalcSpeed(HallType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _HALL_H_ */

View File

@ -0,0 +1,149 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _RESOLVER_H_
#define _RESOLVER_H_
/*! \brief Contains the public interface to the resolver
* abstract class. This would also cover the usage of
* MagnetoResistance position sensor
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "common/iqmath/iqmath.h"
#include "common/pid/pid.h"
#include "common/filter/iir_fo.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the Resolver parameters
* \note The pole pair scale should not > 128
*/
typedef struct _Resolver_ParamsType_
{
float polePairScale; /*!< Pole pair of the motor / Pole pair of the resolver */
uint16_t reverseDir; /*!< Set this value other than 0 will reverse the positive direction, default to use 0 */
float phaseCalcFreq_kHz; /*!< Frequency to run phase calculation */
float spdCalcFreq_kHz; /*!< Frequency to run phase calculation */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float responseSpeed_rps; /*!< The response speed in rad/s */
float spdFilterPole_rps; /*!< Pole value of speed filter calculation */
} Resolver_ParamsType;
/*! \brief Defines the dynamic parameters used to update RESOLVER object
*/
typedef struct _Resolver_DynamicParamsType_
{
float phaseCalcFreq_kHz; /*!< Frequency to run phase calculation */
float spdCalcFreq_kHz; /*!< Frequency to run phase calculation */
} Resolver_DynamicParamsType;
/*! \brief Defines the Resolver object
*/
typedef struct _ResolverType_
{
_iq sin_pu; /*!< Input: The sin value in P.U. */
_iq cos_pu; /*!< Input: The cos value in P.U. */
_iq error; /*!< Parameter: error to calculate angle from speed */
_iq angleFactor; /*!< Parameter: Factor to calculate angle from speed */
_iq polePairScale; /*!< Parameter: Pole pair of the motor / Pole pair of the resolver */
uint16_t reverseDir; /*!< Parameter: Set this value other than 0 will reverse the positive direction, default to use 0 */
float phaseCalcFreq_kHz; /*!< Parameter: Frequency to run phase calculation */
float spdCalcFreq_kHz; /*!< Parameter: Frequency to run phase calculation */
uint16_t polePairScaleFactor; /*!< Internal variable: The factor for pole pair scale */
bool firstCalcStatus; /*!< Internal variable: The PLL PID first calculate status */
PidType pidPLL; /*!< Internal variable: The PLL PID */
IirFoType filterSpd; /*!< Internal Variable: The filter for electric speed calculation */
_iq rawSpeed_pu; /*!< Internal variable: The raw speed before filter in P.U. */
_iq currentAngle_pu; /*!< Internal variable: The angle represented by input */
_iq nextAngle_pu; /*!< Internal variable: The angle represented by input */
_iq angle_pu; /*!< Output: The electrical angle in P.U. */
_iq speed_pu; /*!< Output: The speed in P.U. */
} ResolverType;
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize resolver
*
* This function initalizes resolver by setting configuration parameters
*
* \param[in] obj : pointer to Resolver instance
* \param[in] pParams : pointer to Resolver configuration parameters
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Resolver_Init(ResolverType *obj, const Resolver_ParamsType *pParams);
/*! \brief Run the resolver the calculate the phase
* for PARK and IPARK module
* \note Must run in the same frequency with current control loop
*
* \param[in] obj : pointer to Resolver instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Resolver_CalcPhase(ResolverType *obj);
/*! \brief Calculate the speed
* \note Might run slower than current control frequency
*
*
* \param[in] obj : pointer to Resolver instance
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Resolver_CalcSpeed(ResolverType *obj);
/*! \brief Update the parameters of Resolver
*
* This function updates the Resolver function configuration parameters
*
* \param[in] obj : pointer to Resolver instance
* \param[in] pParams : pointer to control configuration paramter
* \return the MCUs authorized evaluation
* - -1 : Functions not available
* - 0 : Functions available
*/
extern int32_t Resolver_UpdateParams(ResolverType *obj, const Resolver_DynamicParamsType *pParams);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _RESOLVER_H_ */

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "afwsc.h"
/*******************************************************************************
* the defines
******************************************************************************/
#define DAMPING_FACTOR (4)
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void Afwsc_Init(AfwscType *obj, Afwsc_ParamsType *pParams)
{
obj->speedRef = 0;
/* Calculate PID parameters */
_iq Ki_series = _IQ(pParams->spdFilterPole_rps / (DAMPING_FACTOR * DAMPING_FACTOR) * pParams->runFreq_kHz / 1000);
float K = 1.5 * pParams->polePairs * pParams->rotorFlux_Wb / pParams->inertia_kgm2;
_iq Kp_series = _IQ(pParams->spdFilterPole_rps / (K * DAMPING_FACTOR)
* 2 * MATH_PI * pParams->fBase_Hz / pParams->polePairs / pParams->IBase_A);
_iq Kp_parallel = Kp_series;
_iq Ki_parallel = _IQmpy(Ki_series, Kp_series);
Pid_Init(&obj->pidSpd, Kp_parallel, Ki_parallel, 0, _IQ(0), _IQ(pParams->maxCurrent_A / pParams->IBase_A));
Ramp_Init(&obj->spdRamp, _IQ(0.000005));
Fw_Init(&obj->fwObj, _IQ(pParams->minId_A / pParams->IBase_A));
}
void Afwsc_Run(AfwscType *obj)
{
/* Field weakening */
obj->fwObj.refValue = obj->VsRef;
obj->fwObj.fbackValue = obj->Vs;
Fw_Run(&obj->fwObj);
obj->IdRef = obj->fwObj.output;
/* Ramp for the reference */
obj->spdRamp.target = obj->speedRef;
Ramp_Calc(&obj->spdRamp);
/* PID for speed */
obj->pidSpd.ref = obj->spdRamp.output;
obj->pidSpd.fdb = obj->speed;
Pid_Run(&obj->pidSpd);
/* PID output is iq */
obj->IqRef = obj->pidSpd.output;
}
void Afwsc_Reset(AfwscType *obj)
{
obj->fwObj.output = 0;
obj->pidSpd.Ui = 0;
;
obj->IdRef = 0;
obj->IqRef = 0;
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _AFWSC_H_
#define _AFWSC_H_
/*! \brief Contains public interface to various functions related
* to the Auto Field-Weakening Speed Control of (AFWSC) object
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include <stdint.h>
#include "common/iqmath/iqmath.h"
#include "common/pid/pid.h"
#include "common/curve/ramp.h"
#include "md_lib/fw/fw.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the initial parameters for AFWSC_IPM object
*/
typedef struct _Afwsc_ParamsType_
{
uint16_t polePairs; /*!< Pole pairs of the motor */
float runFreq_kHz; /*!< Frequency to run */
float fBase_Hz; /*!< Base value of frequency used for P.U. */
float IBase_A; /*!< Base value of current used for P.U. */
float inertia_kgm2; /*!< The inertia of the rotoring system */
float rotorFlux_Wb; /*!< The rotor flux, equal to BEMF in v*s/rad */
float spdFilterPole_rps; /*!< Pole value of speed filter calculation */
float minId_A; /*!< Max value of Id to prevent demagnetization for PM motors */
float maxCurrent_A; /*!< Max value of speed PID output */
} Afwsc_ParamsType;
/*! \brief Defines the AFWSC_IPM object
*/
typedef struct _AfwscType_
{
_iq speedRef; /*!< Input: The speed reference value of speed loop control */
_iq speed; /*!< Input: The speed feedback */
_iq VsRef; /*!< Input: The reference value of Vs */
_iq Vs; /*!< Input: The feedback value of Vs */
PidType pidSpd; /*!< Internal Variable: The PID for speed loop */
RampType spdRamp; /*!< Internal Variable: The ramp for speed reference value */
FwType fwObj; /*!< Internal Variable: The field-weakening object */
_iq IdRef; /*!< Output: The Id reference value */
_iq IqRef; /*!< Output: The Iq reference value */
} AfwscType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief Initialize the Afwsc object
*
* This function initalizes Afwsc by setting configuration parameters
*
* \param[in] obj : pointer to Afwsc instance
* \param[in] pParams : pointer to Afwsc configuration parameters
*/
extern void Afwsc_Init(AfwscType *obj, Afwsc_ParamsType *pParams);
/*! \brief The main process function of Afwsc
*
* This function runs Afwsc function, perform motor control functions
*
* \param[in] obj : pointer to Svgen instance
*/
extern void Afwsc_Run(AfwscType *obj);
/*! \brief Reset the Afwsc object
*
* This function resets the Afwsc relevant calculation parameters
*
* \param[in] obj : pointer to Afwsc instance
*/
extern void Afwsc_Reset(AfwscType *obj);
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _AFWSC_H_ */

View File

@ -0,0 +1,134 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _GDGEN_H_
#define _GDGEN_H_
/*! \brief Contains the public interface to the
* GDPWM generator routines
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the control mode of the GDGEN
*/
typedef enum
{
GDGEN_MODE_NORMAL = 0, /*!< Normal mode of sine and trapezoid */
GDGEN_MODE_SQUAREWAVE, /*!< Square wave mode */
} Gdgen_ModeType;
/*! \brief Defines the Space Vector Generator object
*/
typedef struct _GdgenType_
{
_iq Ualpha; /*!< Input: reference alpha-axis phase voltage */
_iq Ubeta; /*!< Input: reference beta-axis phase voltage */
Gdgen_ModeType mode; /*!< Parameter: the working mode */
_iq Ta; /*!< Output: reference phase-a switching function */
_iq Tb; /*!< Output: reference phase-b switching function */
_iq Tc; /*!< Output: reference phase-c switching function */
} GdgenType;
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The main process function of Gdgen
*
* This function runs Gdgen function, perform motor control functions
*
* \param[in] obj : pointer to Gdgen instance
*/
static inline void Gdgen_Run(GdgenType *obj)
{
_iq Vmax, Vcom;
_iq Vref1, Vref2, Vref3;
_iq Va_tmp = -_IQdiv2(obj->Ualpha);
_iq Vb_tmp = _IQmpy(IQMATH_SQRT_THREE_OVER_TWO, obj->Ubeta);
Vref1 = obj->Ualpha; /*alpha */
Vref2 = Va_tmp + Vb_tmp; /*-0.5*alpha + sqrt(3)/2 * beta; */
Vref3 = Va_tmp - Vb_tmp; /*-0.5*alpha - sqrt(3)/2 * beta; */
Vmax = 0;
/* find Vmax, Vcom */
Vmax = (_IQabs(Vref1) > _IQabs(Vref2)) ? Vref1 : Vref2;
if(_IQabs(Vref3) > _IQabs(Vmax))
{
Vmax = Vref3;
}
Vcom = (Vmax > 0) ? (Vmax - _IQ(0.5)) : (Vmax + _IQ(0.5));
/* Subtract common-mode term to achieve GD modulation */
obj->Ta = (Vref1 - Vcom);
obj->Tb = (Vref2 - Vcom);
obj->Tc = (Vref3 - Vcom);
/* If in SquareWave mode, the outputs is not continuous */
if(obj->mode == GDGEN_MODE_SQUAREWAVE)
{
if(obj->Ta > 0)
{
obj->Ta = _IQ(0.5);
}
if(obj->Ta < 0)
{
obj->Ta = -_IQ(0.5);
}
if(obj->Tb > 0)
{
obj->Tb = _IQ(0.5);
}
if(obj->Tb < 0)
{
obj->Tb = -_IQ(0.5);
}
if(obj->Tc > 0)
{
obj->Tc = _IQ(0.5);
}
if(obj->Tc < 0)
{
obj->Tc = -_IQ(0.5);
}
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _GDGEN_H_ */

View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
#ifndef _SVGEN_H_
#define _SVGEN_H_
/*! \brief Contains the public interface to the
* SVPWM generator routines
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "common/iqmath/iqmath.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*! \brief Defines the control mode of the SVGEN
*/
typedef enum
{
SVGEN_MODE_NORMAL = 0, /*!< Normal mode of sine and trapezoid */
SVGEN_MODE_SQUAREWAVE, /*!< Square wave mode */
} Svgen_ModeType;
/*! \brief Defines the Space Vector Generator object
*/
typedef struct _SvgenType_
{
_iq Ualpha; /*!< Input: reference alpha-axis phase voltage */
_iq Ubeta; /*!< Input: reference beta-axis phase voltage */
Svgen_ModeType mode; /*!< Parameter: the working mode */
_iq Ta; /*!< Output: reference phase-a switching function */
_iq Tb; /*!< Output: reference phase-b switching function */
_iq Tc; /*!< Output: reference phase-c switching function */
} SvgenType;
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the function prototypes
******************************************************************************/
/*! \brief The main process function of Svgen
*
* This function runs Svgen function, perform motor control functions
*
* \param[in] obj : pointer to Svgen instance
*/
static inline void Svgen_Run(SvgenType *obj)
{
_iq Vmax, Vmin, Vcom;
_iq Vref1, Vref2, Vref3;
_iq Va_tmp = -_IQdiv2(obj->Ualpha);
_iq Vb_tmp = _IQmpy(IQMATH_SQRT_THREE_OVER_TWO, obj->Ubeta);
Vref1 = obj->Ualpha; /* alpha */
Vref2 = Va_tmp + Vb_tmp; /* -0.5*alpha + sqrt(3)/2 * beta; */
Vref3 = Va_tmp - Vb_tmp; /* -0.5*alpha - sqrt(3)/2 * beta; */
Vmax = 0;
Vmin = 0;
/* find order Vmin,Vmid,Vmax */
if(Vref1 > Vref2)
{
Vmax = Vref1;
Vmin = Vref2;
}
else
{
Vmax = Vref2;
Vmin = Vref1;
}
if(Vref3 > Vmax)
{
Vmax = Vref3;
}
else if(Vref3 < Vmin)
{
Vmin = Vref3;
}
Vcom = _IQmpy(Vmax + Vmin, _IQ(0.5));
/* Subtract common-mode term to achieve SV modulation */
obj->Ta = (Vref1 - Vcom);
obj->Tb = (Vref2 - Vcom);
obj->Tc = (Vref3 - Vcom);
/* If in SquareWave mode, the outputs is not continuous */
if(obj->mode == SVGEN_MODE_SQUAREWAVE)
{
if(obj->Ta > 0)
{
obj->Ta = _IQ(0.5);
}
if(obj->Ta < 0)
{
obj->Ta = -_IQ(0.5);
}
if(obj->Tb > 0)
{
obj->Tb = _IQ(0.5);
}
if(obj->Tb < 0)
{
obj->Tb = -_IQ(0.5);
}
if(obj->Tc > 0)
{
obj->Tc = _IQ(0.5);
}
if(obj->Tc < 0)
{
obj->Tc = -_IQ(0.5);
}
}
}
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif /* _SVGEN_H_ */

View File

@ -0,0 +1,164 @@
/*
* Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
* All rights reserved.
*
* Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
* exclusively with CVA's microcontroller products. This file can be freely
* distributed within development tools that are supporting such microcontroller
* products.
*
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*/
/*******************************************************************************
* the includes
******************************************************************************/
#include "dbc_comm.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
void DbcComm_Init(DbcCommType *obj, const DbcComm_ParamsType *pParams)
{
uint8_t node = 0;
for(node = 0; node < DBCCOMM_NODE_NUM; ++node)
{
obj->enableNodeTx[node] = false;
obj->enableNodeRx[node] = false;
}
obj->sendCanMsg = pParams->sendCanMsg;
uint16_t i = 0;
/* Process send message */
for(i = 0; i < obj->txMsgNum; ++i)
{
obj->txMsgArray[i].periodCntMax = (uint32_t)(pParams->runFreq_kHz * obj->txMsgArray[i].pInfo->period_ms);
obj->txMsgArray[i].periodCnt = i; /* Stagger the start timing */
}
/* Process received message */
for(i = 0; i < obj->rxMsgNum; ++i)
{
obj->rxMsgArray[i].timeoutCntMax = (uint32_t)(pParams->runFreq_kHz * obj->rxMsgArray[i].pInfo->timeout_ms);
obj->rxMsgArray[i].timeoutCnt = 0;
obj->rxMsgArray[i].isTimeout = false;
}
}
void DbcComm_Run(DbcCommType *obj)
{
uint16_t i = 0;
/* Process send message */
for(i = 0; i < obj->txMsgNum; ++i)
{
DbcComm_CanNodeType node = obj->txMsgArray[i].pInfo->node;
if(obj->enableNodeTx[node])
{
if(obj->txMsgArray[i].periodCntMax > 0)
{
obj->txMsgArray[i].periodCnt++;
if(obj->txMsgArray[i].periodCnt >= obj->txMsgArray[i].periodCntMax)
{
obj->txMsgArray[i].periodCnt = 0;
/* Pack message and send it */
DbcComm_CanMsgType msg = CAN_MSG_DEFAULT;
obj->txMsgArray[i].pInfo->packMsg(obj, &msg);
obj->sendCanMsg(node, &msg);
}
}
}
}
/* Process received message */
for(i = 0; i < obj->rxMsgNum; ++i)
{
DbcComm_CanNodeType node = obj->rxMsgArray[i].pInfo->node;
if(obj->enableNodeRx[node])
{
if(obj->rxMsgArray[i].timeoutCntMax > 0 && false == obj->rxMsgArray[i].isTimeout)
{
obj->rxMsgArray[i].timeoutCnt++;
if(obj->rxMsgArray[i].timeoutCnt >= obj->rxMsgArray[i].timeoutCntMax)
{
obj->rxMsgArray[i].timeoutCnt = 0;
obj->rxMsgArray[i].isTimeout = true;
}
}
}
}
}
void DbcComm_ReceiveCanMsg(DbcCommType *obj, DbcComm_CanNodeType node, const DbcComm_CanMsgType *pMsg)
{
uint16_t i = 0;
for(i = 0; i < obj->rxMsgNum; ++i)
{
if(pMsg->id == obj->rxMsgArray[i].pInfo->id && node == obj->rxMsgArray[i].pInfo->node)
{
obj->rxMsgArray[i].timeoutCnt = 0;
obj->rxMsgArray[i].isTimeout = false;
obj->rxMsgArray[i].pInfo->unpackMsg(obj, pMsg);
break;
}
}
}
void DbcComm_EnableRx(DbcCommType *obj, DbcComm_CanNodeType node, bool enable)
{
if(obj->enableNodeRx[node] != enable)
{
/* Change the enable status */
uint16_t i = 0;
for(i = 0; i < obj->rxMsgNum; ++i)
{
if(obj->rxMsgArray[i].pInfo->node == node)
{
if(obj->rxMsgArray[i].timeoutCntMax > 0)
{
obj->rxMsgArray[i].timeoutCnt = 0;
obj->rxMsgArray[i].isTimeout = false;
}
}
}
obj->enableNodeRx[node] = enable;
}
}
void DbcComm_EnableTx(DbcCommType *obj, DbcComm_CanNodeType node, bool enable)
{
if(obj->enableNodeTx[node] != enable)
{
/* Change the enable status */
uint16_t i = 0;
for(i = 0; i < obj->txMsgNum; ++i)
{
if(obj->txMsgArray[i].pInfo->node == node)
{
if(obj->txMsgArray[i].periodCntMax > 0)
{
obj->txMsgArray[i].periodCnt = obj->txMsgArray[i].periodCntMax;
}
}
}
obj->enableNodeTx[node] = enable;
}
}

Some files were not shown because too many files have changed in this diff Show More