fix: Address conventions and resolve MATLAB handler default issue

- Corrected naming conventions across modules for consistency.
- Fixed the issue where the MATLAB code was defaulting to the handler by initializing struct variables to zero.
- Improved CAN TX function for more reliable data transmission.
stable
Rakshita 2025-01-23 16:31:22 +05:30
parent b1fa1129af
commit 071788de56
24 changed files with 910 additions and 879 deletions

View File

@ -380,25 +380,25 @@
<listOptionValue builtIn="false" value="LINKER_COMMAND_FILE=mspm0g3507.lds"/> <listOptionValue builtIn="false" value="LINKER_COMMAND_FILE=mspm0g3507.lds"/>
<listOptionValue builtIn="false" value="RUNTIME_SUPPORT_LIBRARY=libc.a"/> <listOptionValue builtIn="false" value="RUNTIME_SUPPORT_LIBRARY=libc.a"/>
<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/> <listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
<listOptionValue builtIn="false" value="PRODUCTS=MSPM0-SDK:1.20.1.06;sysconfig:1.18.0;"/> <listOptionValue builtIn="false" value="PRODUCTS=MSPM0-SDK:2.3.0.07;sysconfig:1.18.0;"/>
<listOptionValue builtIn="false" value="PRODUCT_MACRO_IMPORTS={&quot;MSPM0-SDK&quot;:[&quot;${COM_TI_MSPM0_SDK_INCLUDE_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARY_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARIES}&quot;,&quot;${COM_TI_MSPM0_SDK_SYMBOLS}&quot;,&quot;${COM_TI_MSPM0_SDK_SYSCONFIG_MANIFEST}&quot;],&quot;sysconfig&quot;:[&quot;${SYSCONFIG_TOOL_INCLUDE_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARY_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARIES}&quot;,&quot;${SYSCONFIG_TOOL_SYMBOLS}&quot;,&quot;${SYSCONFIG_TOOL_SYSCONFIG_MANIFEST}&quot;]}"/> <listOptionValue builtIn="false" value="PRODUCT_MACRO_IMPORTS={&quot;sysconfig&quot;:[&quot;${SYSCONFIG_TOOL_INCLUDE_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARY_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARIES}&quot;,&quot;${SYSCONFIG_TOOL_SYMBOLS}&quot;,&quot;${SYSCONFIG_TOOL_SYSCONFIG_MANIFEST}&quot;],&quot;MSPM0-SDK&quot;:[&quot;${COM_TI_MSPM0_SDK_INCLUDE_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARY_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARIES}&quot;,&quot;${COM_TI_MSPM0_SDK_SYMBOLS}&quot;,&quot;${COM_TI_MSPM0_SDK_SYSCONFIG_MANIFEST}&quot;]}"/>
<listOptionValue builtIn="false" value="OUTPUT_TYPE=executable"/> <listOptionValue builtIn="false" value="OUTPUT_TYPE=executable"/>
</option> </option>
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.416761197" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="GNU_9.2.1:Linaro" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.416761197" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="GNU_9.2.1:Linaro" valueType="string"/>
<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.targetPlatformDebug.149693371" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.targetPlatformDebug"/> <targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.targetPlatformDebug.149693371" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.targetPlatformDebug"/>
<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.builderDebug.1185751452" name="GNU Make.Test__GNU" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.builderDebug"/> <builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.builderDebug.1185751452" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.builderDebug"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.compilerDebug.1024471374" name="GNU Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.compilerDebug"> <tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.compilerDebug.1024471374" name="GNU Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.compilerDebug">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MCPU.85555502" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MCPU" value="cortex-m0plus" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MCPU.85555502" name="Target CPU (-mcpu)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MCPU" value="cortex-m0plus" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MARCH.1352827936" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MARCH" value="armv6-m" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MARCH.1352827936" name="Target architecture (-march)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MARCH" value="armv6-m" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE.1352763914" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE.THUMB" valueType="enumerated"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE.1352763914" name="Code state" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.CODE_STATE.THUMB" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MFLOAT_ABI.2071683333" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MFLOAT_ABI" value="soft" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MFLOAT_ABI.2071683333" name="Use floating point hardware (-mfloat-abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.MFLOAT_ABI" value="soft" valueType="string"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEFINE.926517778" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEFINE" valueType="definedSymbols"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEFINE.926517778" name="Define symbols (-D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEFINE" valueType="definedSymbols">
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_SYMBOLS}"/> <listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_SYMBOLS}"/>
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_SYMBOLS}"/> <listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_SYMBOLS}"/>
<listOptionValue builtIn="false" value="__MSPM0G3507__"/> <listOptionValue builtIn="false" value="__MSPM0G3507__"/>
<listOptionValue builtIn="false" value="DeviceFamily_ID=DeviceFamily_ID_MSPM0G350X"/> <listOptionValue builtIn="false" value="DeviceFamily_ID=DeviceFamily_ID_MSPM0G350X"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH.1406977247" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH.1406977247" name="Include paths (-I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH" valueType="includePath">
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INCLUDE_PATH}"/> <listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INCLUDE_PATH}"/>
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_INCLUDE_PATH}"/> <listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_INCLUDE_PATH}"/>
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Generated Codes}"/> <listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Generated Codes}"/>
@ -420,16 +420,16 @@
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Core/Include}"/> <listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Core/Include}"/>
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Core/Source}"/> <listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Core/Source}"/>
</option> </option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL.764173782" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL.OPT_FOR_DEBUG" valueType="enumerated"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL.764173782" name="Optimization Level" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OPT_LEVEL.OPT_FOR_DEBUG" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.FUNCTION_SECTIONS.343631336" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.FUNCTION_SECTIONS" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.FUNCTION_SECTIONS.343631336" name="Place each function into its own section (-ffunction-sections)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.FUNCTION_SECTIONS" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DATA_SECTIONS.260438983" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DATA_SECTIONS" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DATA_SECTIONS.260438983" name="Place data items into their own section (-fdata-sections)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DATA_SECTIONS" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEBUG.1087585413" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEBUG" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEBUG.1087585413" name="Generate debug information (-g)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DEBUG" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION.1099895322" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION.3" valueType="enumerated"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION.1099895322" name="Generate debug information in DWARF version (-gdwarf-)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.DWARF_VERSION.3" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.STRICT_DWARF.1918790934" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.STRICT_DWARF" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.STRICT_DWARF.1918790934" name="Do not emit DWARF additions beyond selected version (-gstrict-dwarf)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.STRICT_DWARF" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OTHER_FLAGS.1652229166" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OTHER_FLAGS" valueType="stringList"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OTHER_FLAGS.1652229166" name="Miscellaneous flags" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.OTHER_FLAGS" valueType="stringList">
<listOptionValue builtIn="false" value=""/> <listOptionValue builtIn="false" value=""/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.ASM_SPECIFIC_FLAGS.2136097121" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.ASM_SPECIFIC_FLAGS" valueType="stringList"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.ASM_SPECIFIC_FLAGS.2136097121" name="Miscellaneous assembly source specific flags" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.ASM_SPECIFIC_FLAGS" valueType="stringList">
<listOptionValue builtIn="false" value="[asm: -xassembler-with-cpp]"/> <listOptionValue builtIn="false" value="[asm: -xassembler-with-cpp]"/>
</option> </option>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__C_SRCS.1639579902" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__C_SRCS"/> <inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__C_SRCS.1639579902" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__C_SRCS"/>
@ -438,12 +438,12 @@
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__ASM2_SRCS.1432406178" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__ASM2_SRCS"/> <inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__ASM2_SRCS.1432406178" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compiler.inputType__ASM2_SRCS"/>
</tool> </tool>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.linkerDebug.1000144524" name="GNU Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.linkerDebug"> <tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.linkerDebug.1000144524" name="GNU Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exe.linkerDebug">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OUTPUT_FILE.34135815" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OUTPUT_FILE.34135815" name="Output file (-o)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.MAP_FILE.573004638" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.MAP_FILE" value="${ProjName}.map" valueType="string"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.MAP_FILE.573004638" name="Write a map file (-Map)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.MAP_FILE" value="${ProjName}.map" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.NOSTARTFILES.400973291" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.NOSTARTFILES" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.NOSTARTFILES.400973291" name="Do not use the standard system startup files when linking (-nostartfiles)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.NOSTARTFILES" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.STATIC.193004299" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.STATIC" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.STATIC.193004299" name="Do not link with the shared libraries (-static)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.STATIC" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.GC_SECTIONS.418719281" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.GC_SECTIONS" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.GC_SECTIONS.418719281" name="Remove unused sections (--gc-sections)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.GC_SECTIONS" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.LIBRARY.195483867" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.LIBRARY" valueType="libs"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.LIBRARY.195483867" name="Libraries (-l, --library)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.LIBRARY" valueType="libs">
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_LIBRARIES}"/> <listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_LIBRARIES}"/>
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_LIBRARIES}"/> <listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_LIBRARIES}"/>
<listOptionValue builtIn="false" value="gcc"/> <listOptionValue builtIn="false" value="gcc"/>
@ -451,7 +451,7 @@
<listOptionValue builtIn="false" value="m"/> <listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="nosys"/> <listOptionValue builtIn="false" value="nosys"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.SEARCH_PATH.33957587" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.SEARCH_PATH" valueType="libPaths"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.SEARCH_PATH.33957587" name="Library search path (-L, --library-path)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.SEARCH_PATH" valueType="libPaths">
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_LIBRARY_PATH}"/> <listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_LIBRARY_PATH}"/>
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_LIBRARY_PATH}"/> <listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_LIBRARY_PATH}"/>
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source"/> <listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source"/>
@ -459,7 +459,7 @@
<listOptionValue builtIn="false" value="${PROJECT_BUILD_DIR}/syscfg"/> <listOptionValue builtIn="false" value="${PROJECT_BUILD_DIR}/syscfg"/>
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/arm-none-eabi/lib/thumb/v6-m/nofp"/> <listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/arm-none-eabi/lib/thumb/v6-m/nofp"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OTHER_FLAGS.1870280945" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OTHER_FLAGS" valueType="stringList"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OTHER_FLAGS.1870280945" name="Miscellaneous flags" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.linkerID.OTHER_FLAGS" valueType="stringList">
<listOptionValue builtIn="false" value="-march=armv6-m -mthumb"/> <listOptionValue builtIn="false" value="-march=armv6-m -mthumb"/>
</option> </option>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__CMD_SRCS.509703605" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__CMD_SRCS"/> <inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__CMD_SRCS.509703605" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__CMD_SRCS"/>
@ -467,8 +467,8 @@
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__GEN_CMDS.549626369" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__GEN_CMDS"/> <inputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__GEN_CMDS.549626369" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.exeLinker.inputType__GEN_CMDS"/>
</tool> </tool>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.441697188" name="GNU Objcopy Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex"> <tool id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.441697188" name="GNU Objcopy Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.TOOL_ENABLE.416049721" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.TOOL_ENABLE" value="true" valueType="boolean"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.TOOL_ENABLE.416049721" name="Enable tool" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.TOOL_ENABLE" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET.1303449514" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET.IHEX" valueType="enumerated"/> <option id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET.1303449514" name="Create an output file in format &lt;bfdname&gt; (-O, --output-target)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET" value="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.OUTPUT_TARGET.IHEX" valueType="enumerated"/>
<outputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.outputType__BIN.1303094658" name="Binary File" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.outputType__BIN"/> <outputType id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.outputType__BIN.1303094658" name="Binary File" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.hex.outputType__BIN"/>
</tool> </tool>
</toolChain> </toolChain>

View File

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="com.ti.ccstudio.debug.launchType.device.debugging"> <launchConfiguration type="com.ti.ccstudio.debug.launchType.device.debugging">
<mapAttribute key="ccs.memoryview.format">
<mapEntry key="org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser@#$Texas Instruments XDS110 USB Debug Probe_0/CORTEX_M0P@#$0" value="32-Bit Hex - TI Style"/>
</mapAttribute>
<mapAttribute key="ccs.memoryview.pageexpr">
<mapEntry key="org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser@#$Texas Instruments XDS110 USB Debug Probe_0/CORTEX_M0P" value="@@0x20207F40"/>
</mapAttribute>
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.SEGGER J-Link Emulator_0/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ResetOnRestart&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;RestartOnSymbolLoad&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;UseLegacyStopMode&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/> <stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.SEGGER J-Link Emulator_0/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ResetOnRestart&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;RestartOnSymbolLoad&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;UseLegacyStopMode&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/>
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.Texas Instruments XDS110 USB Debug Probe/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/> <stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.Texas Instruments XDS110 USB Debug Probe/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/>
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.Texas Instruments XDS110 USB Debug Probe_0/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/> <stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_DEBUGGER_PROPERTIES.MSPM0G3507.ccxml.Texas Instruments XDS110 USB Debug Probe_0/CORTEX_M0P" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/>

View File

@ -1,5 +1,8 @@
#ifndef IVEC_MCAL_COMMON_H #ifndef IVEC_MCAL_COMMON_H
#define IVEC_MCAL_COMMON_H #define IVEC_MCAL_COMMON_H
#include "..\utils\utils.h"
#include "ti_msp_dl_config.h"
/* /*
* File: ivec_mcal_common.h * File: ivec_mcal_common.h
* Description: Header file for IVEC MCAL common functionalities. * Description: Header file for IVEC MCAL common functionalities.
@ -60,7 +63,10 @@ typedef enum
commonMCAL_DEINIT_FAIL, commonMCAL_DEINIT_FAIL,
commonMCAL_CONFIG_FAIL, commonMCAL_CONFIG_FAIL,
commonMCAL_READ_FAIL, commonMCAL_READ_FAIL,
commonMCAL_WRITE_FAIL commonMCAL_WRITE_FAIL,
commonMCAL_ALREADY_INIT=-20,
commonMCAL_ALREADY_DEINIT,
commonMCAL_NOT_IMPLEMENTED
}IVEC_McalCommonErr_e; }IVEC_McalCommonErr_e;
// Enable/disable logging // Enable/disable logging

View File

@ -25,6 +25,6 @@ int8_t u8MCAL_gpioDeInit(GPIO_Regs *GPIOx, uint32_t GPIO_Pin);
void vMCAL_gpioWrite(void* port, uint32_t pin, uint32_t state); void vMCAL_gpioWrite(void* port, uint32_t pin, uint32_t state);
uint32_t u32MCAL_gpioRead(void* port, uint32_t pin); uint32_t u32MCAL_gpioRead(void* port, uint32_t pin);
void vMCAL_gpioToggle(void *port, uint32_t pin); void vMCAL_gpioToggle(void *port, uint32_t pin);
void vMCAL_set_gpioDirection(uint32_t pincmIndex, bool direction); void vMCAL_SetGpioDirection(uint32_t pincmIndex, bool direction);
#endif /* CORE_INCLUDE_IVEC_MCAL_GPIO_H_ */ #endif /* CORE_INCLUDE_IVEC_MCAL_GPIO_H_ */

View File

@ -1,58 +1,48 @@
#ifndef CORE_INCLUDE_IVEc_MCAL_MCAN_H_ #ifndef CORE_INCLUDE_IVEc_MCAL_MCAN_H_
#define CORE_INCLUDE_IVEc_MCAL_MCAN_H_ #define CORE_INCLUDE_IVEc_MCAL_MCAN_H_
#include <../Core/Include/ivec_mcal_common.h>
#include "..\utils\utils.h" #include "..\utils\utils.h"
#include "ti_msp_dl_config.h" #include "ti_msp_dl_config.h"
#define ivMCAL_MAX_FILTERS 10 #include <../Core/Include/ivec_mcal_mcan.h>
#define mcalMAX_FILTERS_u8 10
/* Enum for CAN ID Types */ typedef enum{
typedef enum { IVEC_MCAL_CAN_BR_125 = 125,
IVEC_MCAL_CAN_ID_STD = 0x00, /* Standard ID */ IVEC_MCAL_CAN_BR_250 = 250,
IVEC_MCAL_CAN_ID_EXT = 0x01, /* Extended ID */ IVEC_MCAL_CAN_BR_500 = 500,
IVEC_MCAL_CAN_ID_ERROR = 0x02 /* Error ID */ IVEC_MCAL_CAN_BR_1000 = 1000
} xMCAL_CanIdType_e; }IVEC_McalCanBr_e;
/* CAN Baud Rate Options */
typedef enum
{
IVEC_CAN_BAUD_500 = 500,
IVEC_CAN_BAUD_250 = 250,
IVEC_CAN_BAUD_150 = 150,
IVEC_CAN_BAUD_1000 = 1000,
IVEC_CAN_BAUD_125 = 125,
}xMCAL_CanBaud_e;
typedef struct typedef struct
{ {
MCAN_Regs *pMCAN; MCAN_Regs *pMCAN;
uint8_t __u8Init; uint8_t __u8Init;
xMCAL_CanBaud_e u16Speed; IVEC_McalCanBr_e u16Speed;
int32_t i32MaskCount; int32_t i32MaskCount;
int32_t i32FilterCount; int32_t i32FilterCount;
uint32_t u32MaskValues[ivMCAL_MAX_FILTERS]; uint32_t u32MaskValues[mcalMAX_FILTERS_u8];
uint32_t u32FilterValues[ivMCAL_MAX_FILTERS]; uint32_t u32FilterValues[mcalMAX_FILTERS_u8];
} xMcalCanHandle; } IVEC_McalCanHandle_s;
/* Function Prototypes for MCAN MCAL Layer */ /* Function Prototypes for MCAN MCAL Layer */
/* Initialize the MCAN module */ /* Initialize the MCAN module */
IVEC_McalStatus_e xMCAL_MCANInit(xMcalCanHandle* pxCanHandle); IVEC_McalCommonErr_e xMCAL_MCANInit(IVEC_McalCanHandle_s* pxCanHandle);
/* Deinitialize the MCAN module */ /* Deinitialize the MCAN module */
IVEC_McalStatus_e xMCAL_MCANDeInit(xMcalCanHandle* pxCanHandle); IVEC_McalCommonErr_e xMCAL_MCANDeInit(IVEC_McalCanHandle_s* pxCanHandle);
/* Transmit data via MCAN */ /* Transmit data via MCAN */
IVEC_McalStatus_e xMCAL_MCANTx(xMcalCanHandle* pxCanHandle, uint32_t u32Id, uint16_t* pu16TxData, uint32_t u32BufNum, uint32_t u32Bytes); IVEC_McalCommonErr_e xMCAL_MCANTx(IVEC_McalCanHandle_s* pxCanHandle, uint32_t u32Id, uint16_t* pu16TxData, uint32_t u32BufNum, uint32_t u32Bytes);
/* Receive data via MCAN */ /* Receive data via MCAN */
IVEC_McalStatus_e xMCAL_MCANRx(xMcalCanHandle* pxCanHandle, uint32_t* pu32Id, uint8_t* pu8RxData, int iDLC); IVEC_McalCommonErr_e xMCAL_MCANRx(IVEC_McalCanHandle_s* pxCanHandle, uint32_t* pu32Id, uint8_t* pu8RxData, int iDLC);
/* Get the error status of the MCAN module */ /* Get the error status of the MCAN module */
IVEC_McalStatus_e xMCAL_MCANGetErrorStatus(xMcalCanHandle* pxCanHandle, char* pcErrorStatus); IVEC_McalCommonErr_e xMCAL_MCANGetErrorStatus(IVEC_McalCanHandle_s* pxCanHandle, char* pcErrorStatus);
/* Get interrupt status of MCAN Interrupt Line 1 */ /* Get interrupt status of MCAN Interrupt Line 1 */
IVEC_McalStatus_e xMCAL_MCANGetInterruptLine1Status(xMcalCanHandle* pxCanHandle, uint32_t* pu32InterruptStatus); IVEC_McalCommonErr_e xMCAL_MCANGetInterruptLine1Status(IVEC_McalCanHandle_s* pxCanHandle, uint32_t* pu32InterruptStatus);
#endif /* CORE_INCLUDE_IVEc_MCAL_MCAN_H_ */ #endif /* CORE_INCLUDE_IVEc_MCAL_MCAN_H_ */

View File

@ -6,98 +6,88 @@
#include <stdint.h> #include <stdint.h>
#include "ivec_mcal_common.h" #include "ivec_mcal_common.h"
typedef enum {
IVEC_MCAL_UART_BAUD_AUTO = 0,
IVEC_MCAL_UART_BAUD_2400 = 2400,
IVEC_MCAL_UART_BAUD_4800 = 4800,
IVEC_MCAL_UART_BAUD_9600 = 9600,
IVEC_MCAL_UART_BAUD_14400 = 14400,
IVEC_MCAL_UART_BAUD_19200 = 19200,
IVEC_MCAL_UART_BAUD_28800 = 28800,
IVEC_MCAL_UART_BAUD_33600 = 33600,
IVEC_MCAL_UART_BAUD_38400 = 38400,
IVEC_MCAL_UART_BAUD_57600 = 57600,
IVEC_MCAL_UART_BAUD_115200 = 115200,
IVEC_MCAL_UART_BAUD_230400 = 230400,
IVEC_MCAL_UART_BAUD_460800 = 460800,
IVEC_MCAL_UART_BAUD_921600 = 921600,
IVEC_MCAL_UART_BAUD_1000000 = 1000000,
IVEC_MCAL_UART_BAUD_1843200 = 1843200,
IVEC_MCAL_UART_BAUD_2000000 = 2000000,
IVEC_MCAL_UART_BAUD_2100000 = 2100000,
IVEC_MCAL_UART_BAUD_3686400 = 3686400,
IVEC_MCAL_UART_BAUD_4000000 = 4000000,
IVEC_MCAL_UART_BAUD_4468750 = 4468750
} IVEC_McalUartBaudRate_e;
typedef enum typedef enum {
{ IVEC_MCAL_UART_DATA_BIT_7 = 7,
eMcalUartBaudAuto = 0, IVEC_MCAL_UART_DATA_BIT_8 = 8
eMcalUartBaud2400 = 2400, } IVEC_McalUartDataBit_e;
eMcalUartBaud4800 = 4800,
eMcalUartBaud9600 = 9600,
eMcalUartBaud14400 = 14400,
eMcalUartBaud19200 = 19200,
eMcalUartBaud28800 = 28800,
eMcalUartBaud33600 = 33600,
eMcalUartBaud38400 = 38400,
eMcalUartBaud57600 = 57600,
eMcalUartBaud115200 = 115200,
eMcalUartBaud230400 = 230400,
eMcalUartBaud460800 = 460800,
eMcalUartBaud921600 = 921600,
eMcalUartBaud1000000 = 1000000,
eMcalUartBaud1843200 = 1843200,
eMcalUartBaud2000000 = 2000000,
eMcalUartBaud2100000 = 2100000,
eMcalUartBaud3686400 = 3686400,
eMcalUartBaud4000000 = 4000000,
eMcalUartBaud4468750 = 4468750
} eMcalUartBaudRate;
typedef enum typedef enum {
{ IVEC_MCAL_UART_STOP_BIT_1 = 1,
eMcalUartDataBit7 = 7, IVEC_MCAL_UART_STOP_BIT_2 = 2
eMcalUartDataBit8 = 8 } IVEC_McalUartStopBit_e;
} eMcalUartDataBit;
typedef enum typedef enum {
{ IVEC_MCAL_UART_PARITY_NONE,
eMcalUartStopBit1 = 1, IVEC_MCAL_UART_PARITY_ODD,
eMcalUartStopBit2 = 2 IVEC_MCAL_UART_PARITY_EVEN
} eMcalUartStopBit; } IVEC_McalUartParityBit_e;
typedef enum typedef enum {
{ IVEC_MCAL_UART_FC_NONE = 0,
eMcalUartParityNone, IVEC_MCAL_UART_FC_HW
eMcalUartParityOdd, } IVEC_McalUartFlowCtrl_e;
eMcalUartParityEven
} eMcalUartParityBit;
typedef enum typedef enum{
{ IVEC_MCAL_UART_PORT_1=0,
eMcalUartFcNone = 0, IVEC_MCAL_UART_PORT_2,
eMcalUartFcHw IVEC_MCAL_UART_PORT_3,
} eMcalUartFlowCtrl; IVEC_MCAL_UART_PORT_MAX
}IVEC_McalUartPort_e;
typedef struct typedef struct
{ {
eMcalUartBaudRate eUartBaudrate; IVEC_McalUartBaudRate_e eUartBaudrate;
eMcalUartDataBit eUartDataBit; IVEC_McalUartDataBit_e eUartDataBit;
eMcalUartStopBit eUartStopBit; IVEC_McalUartStopBit_e eUartStopBit;
eMcalUartParityBit eUartParityBit; IVEC_McalUartParityBit_e eUartParityBit;
eMcalUartFlowCtrl eUartFlowCtrl; IVEC_McalUartFlowCtrl_e eUartFlowCtrl;
} xMcalUartConfig; }IVEC_McalUartConfig_s;
typedef enum typedef enum {
{ IVEC_MCAL_UART_EVENT_RX_ARRIVED = 1, ///< Received new data
eMcalUartPort1 = 0, IVEC_MCAL_UART_EVENT_RX_OVERFLOW = 2, ///< Rx FIFO overflowed
eMcalUartPort2, IVEC_MCAL_UART_EVENT_TX_COMPLETE = 3 ///< All data had been sent
eMcalUartPort3, } IVEC_McalUartEvents_e;
eMcalUartPortMax
} eMcalUartPortNumber;
#define IVEC_MCAL_GNSS_UART eMcalUartPort3
typedef enum
{
eIvecMcalUartEventRxArrived = 1, ///< Received new data
eIvecMcalUartEventRxOverflow = 2, ///< Rx FIFO overflowed
eIvecMcalUartEventTxComplete = 3 ///< All data had been sent
} eIvecMcalUartEvents;
typedef struct typedef struct
{ {
eMcalUartPortNumber eUartPortNumber; IVEC_McalUartPort_e eUartPortNumber;
xMcalUartConfig xUartConfig; IVEC_McalUartConfig_s xUartConfig;
char* pcBuffer; char* pcBuffer;
uint16_t u16Length; uint16_t u16Length;
void (*pvUartRecvCallback)(eMcalUartPortNumber, eIvecMcalUartEvents, char*, uint32_t); void (*pvUartRecvCallback)(IVEC_McalUartPort_e, IVEC_McalUartEvents_e, char*, uint32_t);
} xMcalUartHandle; } IVEC_McalUartHandle_s;
#define IVEC_MCAL_UART_MAX_PORT 3 //#define IVEC_MCAL_UART_PORT_MAX 3
/* Function Prototypes */ /* Function Prototypes */
IVEC_McalCommonErr_e xMCAL_UartInit(xMcalUartHandle* pxUartHandle); IVEC_McalCommonErr_e xMCAL_UartInit(IVEC_McalUartHandle_s* pxUartHandle);
IVEC_McalCommonErr_e xMCAL_UartDeInit(xMcalUartHandle* pxUartHandle); IVEC_McalCommonErr_e xMCAL_UartDeInit(IVEC_McalUartHandle_s* pxUartHandle);
IVEC_McalCommonErr_e xMCAL_UartRead(xMcalUartHandle* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength); IVEC_McalCommonErr_e xMCAL_UartRead(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength);
IVEC_McalCommonErr_e xMCAL_UartWrite(xMcalUartHandle* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength); IVEC_McalCommonErr_e xMCAL_UartWrite(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength);
#endif /* CORE_INCLUDE_IVEC_MCAL_UART_H_ */ #endif /* CORE_INCLUDE_IVEC_MCAL_UART_H_ */

View File

@ -0,0 +1,3 @@
#include <../Core/Include/ivec_mcal_common.h>
#include "string.h"
//#include "ql_api_osi.h"

View File

@ -119,7 +119,7 @@ void vMCAL_gpioToggle(void *port, uint32_t pin)
* *
* @returns None * @returns None
*/ */
void vMCAL_set_gpioDirection(uint32_t pincmIndex, bool direction) void vMCAL_setGpioDirection(uint32_t pincmIndex, bool direction)
{ {
if(direction) if(direction)

View File

@ -9,40 +9,27 @@
*/ */
#include <../Core/Include/ivec_mcal_mcan.h> #include <../Core/Include/ivec_mcal_mcan.h>
#include "string.h" #include "string.h"
/* MCAN Status Flag */
volatile uint8_t u8MCAL_MCAN_StatusFlag = IVEC_MCAL_STATUS_ERROR;
/* MCAN Protocol Status Header */ /* MCAN Protocol Status Header */
volatile DL_MCAN_ProtocolStatus xMCAL_HeaderStat; volatile DL_MCAN_ProtocolStatus g_xHeaderStat;
extern xMCAL_CanBaud_e g_eCanSpeed;
/* MCAN Interrupt Line 1 Status */ /* MCAN Interrupt Line 1 Status */
volatile uint32_t u32MCAL_InterruptLine1Status; volatile uint32_t g_u32InterruptLine1Status;
/* MCAN Error Interrupt Status */ __attribute__((weak)) void vMCU_FDCANRxFifoCallback(uint32_t u32Identifier, uint8_t *pu8data, uint16_t u16DataLength)
volatile char cMCAL_ErrorInterruptStatus[50];
volatile uint32_t can_interrupt = 0;
volatile DL_MCAN_RxBufElement xMCAL_TempRxMsgInFunction;
__attribute__((weak)) void vMCU_FDCANRxFifoCallback(uint32_t Identifier, uint8_t *data, uint16_t DataLength)
{ {
} }
/*=======================================================================================PRIVATE_MEMBERS======================================================================================*/ /*=======================================================================================PRIVATE_MEMBERS======================================================================================*/
static const DL_MCAN_ClockConfig gMCAN0ClockConf = { static const DL_MCAN_ClockConfig __gprv_xClockConf = {
.clockSel = DL_MCAN_FCLK_HFCLK,////DL_MCAN_FCLK_SYSPLLCLK1,DL_MCAN_FCLK_HFCLK, .clockSel = DL_MCAN_FCLK_HFCLK,////DL_MCAN_FCLK_SYSPLLCLK1,DL_MCAN_FCLK_HFCLK,
.divider = DL_MCAN_FCLK_DIV_1, .divider = DL_MCAN_FCLK_DIV_1,
}; };
static DL_MCAN_InitParams gMCAN0InitParams= { static DL_MCAN_InitParams __gprv_xInitParams= {
/* Initialize MCAN Init parameters. */ /* Initialize MCAN Init parameters. */
.fdMode = false, .fdMode = false,
@ -62,7 +49,7 @@ static DL_MCAN_InitParams gMCAN0InitParams= {
.tdcConfig.tdco = 6, .tdcConfig.tdco = 6,
}; };
static DL_MCAN_ConfigParams gMCAN0ConfigParams={ static DL_MCAN_ConfigParams __gprv_xConfigParams={
/* Initialize MCAN Config parameters. */ /* Initialize MCAN Config parameters. */
.monEnable = false, .monEnable = false,
.asmEnable = false, .asmEnable = false,
@ -76,7 +63,7 @@ static DL_MCAN_ConfigParams gMCAN0ConfigParams={
.filterConfig.anfe = 0, .filterConfig.anfe = 0,
.filterConfig.anfs = 0, .filterConfig.anfs = 0,
}; };
static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams = { static DL_MCAN_MsgRAMConfigParams __gprv_xMsgRAMConfigParams = {
/* Standard ID Filter List Start Address. */ /* Standard ID Filter List Start Address. */
.flssa = 0x0, .flssa = 0x0,
@ -87,7 +74,7 @@ static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams = {
/* List Size: Extended ID. */ /* List Size: Extended ID. */
.lse = 10 , .lse = 10 ,
/* Tx Buffers Start Address. */ /* Tx Buffers Start Address. */
.txStartAddr = 40 + 80 , .txStartAddr = 40 + 80+20 ,
/* Number of Dedicated Transmit Buffers. */ /* Number of Dedicated Transmit Buffers. */
.txBufNum = 0 , .txBufNum = 0 ,
.txFIFOSize = 3, .txFIFOSize = 3,
@ -101,14 +88,14 @@ static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams = {
/* Level for Tx Event FIFO watermark interrupt. */ /* Level for Tx Event FIFO watermark interrupt. */
.txEventFIFOWaterMark = 0, .txEventFIFOWaterMark = 0,
/* Rx FIFO0 Start Address. */ /* Rx FIFO0 Start Address. */
.rxFIFO0startAddr = 40 + 80 + 36 , .rxFIFO0startAddr = 40 + 80 + 36+20 +40,
/* Number of Rx FIFO elements. */ /* Number of Rx FIFO elements. */
.rxFIFO0size = 3 , .rxFIFO0size = 3 ,
/* Rx FIFO0 Watermark. */ /* Rx FIFO0 Watermark. */
.rxFIFO0waterMark = 0, .rxFIFO0waterMark = 0,
.rxFIFO0OpMode = 0, .rxFIFO0OpMode = 0,
/* Rx FIFO1 Start Address. */ /* Rx FIFO1 Start Address. */
.rxFIFO1startAddr = 40 + 80 + 36 + 36 , .rxFIFO1startAddr = 40 + 80 + 36 + 36+80 ,
/* Number of Rx FIFO elements. */ /* Number of Rx FIFO elements. */
.rxFIFO1size = 3 , .rxFIFO1size = 3 ,
/* Level for Rx FIFO 1 watermark interrupt. */ /* Level for Rx FIFO 1 watermark interrupt. */
@ -125,7 +112,7 @@ static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams = {
.rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES, .rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
}; };
static DL_MCAN_BitTimingParams gMCAN0BitTimes_500 = { static DL_MCAN_BitTimingParams __gprv_xBitTimes_500 = {
/* Arbitration Baud Rate Pre-scaler. */ /* Arbitration Baud Rate Pre-scaler. */
.nomRatePrescalar = 0, .nomRatePrescalar = 0,
/* Arbitration Time segment before sample point. */ /* Arbitration Time segment before sample point. */
@ -144,7 +131,7 @@ static DL_MCAN_BitTimingParams gMCAN0BitTimes_500 = {
.dataSynchJumpWidth = 0, .dataSynchJumpWidth = 0,
}; };
static const DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = { static const DL_MCAN_BitTimingParams __gprv_xBitTimes_250 = {
/* Arbitration Baud Rate Pre-scaler. */ /* Arbitration Baud Rate Pre-scaler. */
.nomRatePrescalar = 0, .nomRatePrescalar = 0,
/* Arbitration Time segment before sample point. */ /* Arbitration Time segment before sample point. */
@ -162,20 +149,6 @@ static const DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = {
/* Data (Re)Synchronization Jump Width. */ /* Data (Re)Synchronization Jump Width. */
.dataSynchJumpWidth = 0, .dataSynchJumpWidth = 0,
}; };
volatile DL_MCAN_TxBufElement txMsg = {
.id = ((uint32_t)(0x00)) << 18U,
.rtr = 0U,
.xtd = 0U,
.esi = 0U,
.dlc = 8U,
.brs = 0U,
.fdf = 0U,
.efc = 1U,
.mm = 0xAAU,
.data = {0},
};
/*____________________________________________________________________________________________________________________________________________________________________________________________*/ /*____________________________________________________________________________________________________________________________________________________________________________________________*/
@ -200,42 +173,43 @@ volatile DL_MCAN_TxBufElement txMsg = {
*/ */
void __prv_CANInterruptProcess(uint32_t u32InterruptStatus) static void __prv_McalCanInterruptProcess(uint32_t u32InterruptStatus)
{ {
can_interrupt = u32InterruptStatus; volatile uint32_t l_u32CanInterrupt = 0;
l_u32CanInterrupt = u32InterruptStatus;
uint32_t u32IntrStatus = u32InterruptStatus; uint32_t u32IntrStatus = u32InterruptStatus;
if (u32IntrStatus & (DL_MCAN_INTERRUPT_RF1F | DL_MCAN_INTERRUPT_RF0N | DL_MCAN_INTERRUPT_RF0F | DL_MCAN_INTERRUPT_RF1N)) { if (u32IntrStatus & (DL_MCAN_INTERRUPT_RF1F | DL_MCAN_INTERRUPT_RF0N | DL_MCAN_INTERRUPT_RF0F | DL_MCAN_INTERRUPT_RF1N)) {
volatile DL_MCAN_RxFIFOStatus xMCAL_RxFIFOStatus; volatile DL_MCAN_RxFIFOStatus l_xRxFIFOStatus = {0};
if (u32IntrStatus & (DL_MCAN_INTERRUPT_RF0F | DL_MCAN_INTERRUPT_RF0N)) if (u32IntrStatus & (DL_MCAN_INTERRUPT_RF0F | DL_MCAN_INTERRUPT_RF0N))
xMCAL_RxFIFOStatus.num = DL_MCAN_RX_FIFO_NUM_0; l_xRxFIFOStatus.num = DL_MCAN_RX_FIFO_NUM_0;
else else
xMCAL_RxFIFOStatus.num = DL_MCAN_RX_FIFO_NUM_1; l_xRxFIFOStatus.num = DL_MCAN_RX_FIFO_NUM_1;
DL_MCAN_getRxFIFOStatus(CANFD0, &xMCAL_RxFIFOStatus); DL_MCAN_getRxFIFOStatus(CANFD0, &l_xRxFIFOStatus);
while ((xMCAL_RxFIFOStatus.fillLvl) != 0) while ((l_xRxFIFOStatus.fillLvl) != 0)
{ {
volatile DL_MCAN_RxBufElement xMCAL_TempRxMsg; volatile DL_MCAN_RxBufElement l_xTempRxMsg;
DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, xMCAL_RxFIFOStatus.num, &xMCAL_TempRxMsg); DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, l_xRxFIFOStatus.num, &l_xTempRxMsg);
DL_MCAN_writeRxFIFOAck(CANFD0, xMCAL_RxFIFOStatus.num, xMCAL_RxFIFOStatus.getIdx); DL_MCAN_writeRxFIFOAck(CANFD0, l_xRxFIFOStatus.num, l_xRxFIFOStatus.getIdx);
if (!xMCAL_TempRxMsg.xtd) if (!l_xTempRxMsg.xtd)
xMCAL_TempRxMsg.id = (uint32_t)(xMCAL_TempRxMsg.id >> 18); l_xTempRxMsg.id = (uint32_t)(l_xTempRxMsg.id >> 18);
/* Extract data payload */ /* Extract data payload */
uint8_t au8DataArr[8] = {0}; uint8_t au8DataArr[8] = {0};
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
au8DataArr[i] = xMCAL_TempRxMsg.data[i] & 0xFF; au8DataArr[i] = l_xTempRxMsg.data[i] & 0xFF;
} }
vMCAL_CanReceiveFifoCallback(xMCAL_TempRxMsg.id, &au8DataArr[0], xMCAL_TempRxMsg.dlc); vMCAL_CanReceiveFifoCallback(l_xTempRxMsg.id, &au8DataArr[0], l_xTempRxMsg.dlc);
DL_MCAN_getRxFIFOStatus(CANFD0, &xMCAL_RxFIFOStatus); DL_MCAN_getRxFIFOStatus(CANFD0, &l_xRxFIFOStatus);
} }
} }
if(u32IntrStatus & (DL_MCAN_INTR_SRC_MSG_RAM_ACCESS_FAILURE|DL_MCAN_INTR_SRC_TIMEOUT|DL_MCAN_INTR_SRC_ERR_LOG_OVRFLW|DL_MCAN_INTR_SRC_ERR_PASSIVE|DL_MCAN_INTR_SRC_ERR_PASSIVE|DL_MCAN_INTR_SRC_WARNING_STATUS|DL_MCAN_INTR_SRC_BUS_OFF_STATUS|DL_MCAN_INTR_SRC_WATCHDOG|DL_MCAN_INTR_SRC_PROTOCOL_ERR_ARB|DL_MCAN_INTR_SRC_PROTOCOL_ERR_DATA|DL_MCAN_INTR_SRC_RES_ADDR_ACCESS) ) { if(u32IntrStatus & (DL_MCAN_INTR_SRC_MSG_RAM_ACCESS_FAILURE|DL_MCAN_INTR_SRC_TIMEOUT|DL_MCAN_INTR_SRC_ERR_LOG_OVRFLW|DL_MCAN_INTR_SRC_ERR_PASSIVE|DL_MCAN_INTR_SRC_ERR_PASSIVE|DL_MCAN_INTR_SRC_WARNING_STATUS|DL_MCAN_INTR_SRC_BUS_OFF_STATUS|DL_MCAN_INTR_SRC_WATCHDOG|DL_MCAN_INTR_SRC_PROTOCOL_ERR_ARB|DL_MCAN_INTR_SRC_PROTOCOL_ERR_DATA|DL_MCAN_INTR_SRC_RES_ADDR_ACCESS) ) {
can_interrupt = u32InterruptStatus; l_u32CanInterrupt = u32InterruptStatus;
} }
} }
@ -252,33 +226,33 @@ void CANFD0_IRQHandler(void)
case DL_MCAN_IIDX_LINE1: case DL_MCAN_IIDX_LINE1:
{ {
/* Get interrupt status for Line 1 */ /* Get interrupt status for Line 1 */
uint32_t u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0); uint32_t l_u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0);
/* Process the interrupt */ /* Process the interrupt */
__prv_CANInterruptProcess(u32IntrStatus); __prv_McalCanInterruptProcess(l_u32IntrStatus );
/* Clear the interrupt status for Line 1 */ /* Clear the interrupt status for Line 1 */
DL_MCAN_clearIntrStatus(MCAN0_INST, u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_LINE_1); DL_MCAN_clearIntrStatus(MCAN0_INST, l_u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_LINE_1);
break; break;
} }
case DL_MCAN_IIDX_LINE0: case DL_MCAN_IIDX_LINE0:
{ {
/* Get interrupt status for Line 0 */ /* Get interrupt status for Line 0 */
uint32_t u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0); uint32_t l_u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0);
/* Process the interrupt */ /* Process the interrupt */
__prv_CANInterruptProcess(u32IntrStatus); __prv_McalCanInterruptProcess(l_u32IntrStatus );
/* Clear the interrupt status for Line 0 */ /* Clear the interrupt status for Line 0 */
DL_MCAN_clearIntrStatus(MCAN0_INST, u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_LINE_0); DL_MCAN_clearIntrStatus(MCAN0_INST, l_u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_LINE_0);
break; break;
} }
default: default:
{ {
/* Get interrupt status for external timestamp */ /* Get interrupt status for external timestamp */
uint32_t u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0); uint32_t l_u32IntrStatus = DL_MCAN_getIntrStatus(CANFD0);
/* Clear the interrupt status for external timestamp */ /* Clear the interrupt status for external timestamp */
DL_MCAN_clearIntrStatus(MCAN0_INST, u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_EXT_TS); DL_MCAN_clearIntrStatus(MCAN0_INST, l_u32IntrStatus, DL_MCAN_INTR_SRC_MCAN_EXT_TS);
break; break;
} }
} }
@ -313,21 +287,35 @@ void CANFD0_IRQHandler(void)
* 7. Clears and enables interrupts in the NVIC for the CAN module. * 7. Clears and enables interrupts in the NVIC for the CAN module.
*/ */
IVEC_McalStatus_e xMCAL_MCANInit(xMcalCanHandle* pxCanHandle) IVEC_McalCommonErr_e xMCAL_MCANInit(IVEC_McalCanHandle_s* pxCanHandle)
{ {
assert(pxCanHandle->pMCAN == CANFD0);
assert(pxCanHandle->u16Speed == IVEC_CAN_BAUD_500 || pxCanHandle->u16Speed == IVEC_CAN_BAUD_250);
// g_xEcuCanHandle.__xCanHandle.u16Speed = eMcalUartBaud115200; if((pxCanHandle->pMCAN != CANFD0) && (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_500 || pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_250))
{
return commonMCAL_INVALID_PARAM;
}
if(pxCanHandle->__u8Init == 1)
{
return commonMCAL_INVALID_PARAM;
}
DL_MCAN_RevisionId revid_MCAN0; /* Enable power to the MCAN module */
DL_MCAN_enablePower(pxCanHandle->pMCAN);
delay_cycles(POWER_STARTUP_DELAY);
/* Configure GPIO for CAN TX and RX */
DL_GPIO_initPeripheralOutputFunction(GPIO_MCAN0_IOMUX_CAN_TX, GPIO_MCAN0_IOMUX_CAN_TX_FUNC);
DL_GPIO_initPeripheralInputFunction(GPIO_MCAN0_IOMUX_CAN_RX, GPIO_MCAN0_IOMUX_CAN_RX_FUNC);
DL_MCAN_RevisionId xRevid;
DL_MCAN_enableModuleClock(pxCanHandle->pMCAN); DL_MCAN_enableModuleClock(pxCanHandle->pMCAN);
DL_MCAN_setClockConfig(pxCanHandle->pMCAN, (DL_MCAN_ClockConfig *) &gMCAN0ClockConf); DL_MCAN_setClockConfig(pxCanHandle->pMCAN, (DL_MCAN_ClockConfig *) &__gprv_xClockConf);
/* Get MCANSS Revision ID. */ /* Get MCANSS Revision ID. */
DL_MCAN_getRevisionId(pxCanHandle->pMCAN, &revid_MCAN0); DL_MCAN_getRevisionId(pxCanHandle->pMCAN, &xRevid);
/* Wait for Memory initialization to be completed. */ /* Wait for Memory initialization to be completed. */
while (false == DL_MCAN_isMemInitDone(pxCanHandle->pMCAN)); while (false == DL_MCAN_isMemInitDone(pxCanHandle->pMCAN));
@ -340,39 +328,39 @@ IVEC_McalStatus_e xMCAL_MCANInit(xMcalCanHandle* pxCanHandle)
while (DL_MCAN_OPERATION_MODE_SW_INIT != DL_MCAN_getOpMode(pxCanHandle->pMCAN)); while (DL_MCAN_OPERATION_MODE_SW_INIT != DL_MCAN_getOpMode(pxCanHandle->pMCAN));
/* Initialize MCAN module. */ /* Initialize MCAN module. */
DL_MCAN_init(pxCanHandle->pMCAN, (DL_MCAN_InitParams*)&gMCAN0InitParams); DL_MCAN_init(pxCanHandle->pMCAN, (DL_MCAN_InitParams*)&__gprv_xInitParams);
gMCAN0ConfigParams.filterConfig.anfe = 0; __gprv_xConfigParams.filterConfig.anfe = 0;
gMCAN0ConfigParams.filterConfig.anfs = 0; __gprv_xConfigParams.filterConfig.anfs = 0;
for (int u32Index = 0; u32Index <= pxCanHandle->i32MaskCount; u32Index++) { for (int u32Index = 0; u32Index <= pxCanHandle->i32MaskCount; u32Index++) {
if ((pxCanHandle->u32FilterValues[u32Index] > 0x7FF) || (pxCanHandle->u32MaskValues[u32Index] > 0x7FF)) { if ((pxCanHandle->u32FilterValues[u32Index] > 0x7FF) || (pxCanHandle->u32MaskValues[u32Index] > 0x7FF)) {
gMCAN0ConfigParams.filterConfig.anfe = 3; __gprv_xConfigParams.filterConfig.anfe = 3;
} }
else else
{ {
gMCAN0ConfigParams.filterConfig.anfs = 3; __gprv_xConfigParams.filterConfig.anfs = 3;
} }
} }
/* Configure MCAN module. */ /* Configure MCAN module. */
DL_MCAN_config(pxCanHandle->pMCAN, (DL_MCAN_ConfigParams*)&gMCAN0ConfigParams); DL_MCAN_config(pxCanHandle->pMCAN, (DL_MCAN_ConfigParams*)&__gprv_xConfigParams);
/* Configure Bit timings. */ /* Configure Bit timings. */
if (pxCanHandle->u16Speed == IVEC_CAN_BAUD_500) if (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_500)
{ {
DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&gMCAN0BitTimes_500); DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&__gprv_xBitTimes_500);
} }
else if (pxCanHandle->u16Speed == IVEC_CAN_BAUD_250) else if (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_250)
{ {
DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&gMCAN0BitTimes_250); DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&__gprv_xBitTimes_250);
} }
else else
{ {
DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&gMCAN0BitTimes_500); DL_MCAN_setBitTime(pxCanHandle->pMCAN, (DL_MCAN_BitTimingParams*)&__gprv_xBitTimes_250);
} }
/* Configure Message RAM Sections */ /* Configure Message RAM Sections */
DL_MCAN_msgRAMConfig(pxCanHandle->pMCAN, (DL_MCAN_MsgRAMConfigParams*)&gMCAN0MsgRAMConfigParams); DL_MCAN_msgRAMConfig(pxCanHandle->pMCAN, (DL_MCAN_MsgRAMConfigParams*)&__gprv_xMsgRAMConfigParams);
uint8_t l_u8ExtendedFilterCount = 0; uint8_t l_u8ExtendedFilterCount = 0;
uint8_t l_u8StandardFilterCount = 0; uint8_t l_u8StandardFilterCount = 0;
@ -438,7 +426,7 @@ IVEC_McalStatus_e xMCAL_MCANInit(xMcalCanHandle* pxCanHandle)
NVIC_EnableIRQ(CANFD0_INT_IRQn); NVIC_EnableIRQ(CANFD0_INT_IRQn);
pxCanHandle->__u8Init = 1; pxCanHandle->__u8Init = 1;
return IVEC_MCAL_STATUS_SUCCESS; return commonMCAL_SUCCESS;
} }
@ -448,11 +436,17 @@ IVEC_McalStatus_e xMCAL_MCANInit(xMcalCanHandle* pxCanHandle)
* @retval IVEC MCAL status * @retval IVEC MCAL status
*/ */
IVEC_McalStatus_e xMCAL_MCANDeInit(xMcalCanHandle* pxCanHandle) IVEC_McalCommonErr_e xMCAL_MCANDeInit(IVEC_McalCanHandle_s* pxCanHandle)
{ {
/* Assert that the MCAN module pointer is valid */ /* Assert that the MCAN module pointer is valid */
assert(pxCanHandle->pMCAN == CANFD0); if((pxCanHandle->pMCAN != CANFD0) && (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_500 || pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_250))
assert(pxCanHandle->__u8Init != 0); /* Ensure the module was initialized before deinitializing. */ {
return commonMCAL_INVALID_PARAM;
}
if(pxCanHandle->__u8Init == 0) /* Ensure the module was initialized before deinitializing. */
{
return commonMCAL_INVALID_PARAM;
}
/* Reset the CAN module to initialization mode */ /* Reset the CAN module to initialization mode */
DL_MCAN_setOpMode(pxCanHandle->pMCAN, DL_MCAN_OPERATION_MODE_SW_INIT); DL_MCAN_setOpMode(pxCanHandle->pMCAN, DL_MCAN_OPERATION_MODE_SW_INIT);
@ -476,6 +470,7 @@ IVEC_McalStatus_e xMCAL_MCANDeInit(xMcalCanHandle* pxCanHandle)
DL_MCAN_INTERRUPT_TC | \ DL_MCAN_INTERRUPT_TC | \
DL_MCAN_INTERRUPT_TOO), false); DL_MCAN_INTERRUPT_TOO), false);
/* Disable interrupt lines */ /* Disable interrupt lines */
DL_MCAN_enableIntrLine(pxCanHandle->pMCAN, DL_MCAN_INTR_LINE_NUM_0, false); DL_MCAN_enableIntrLine(pxCanHandle->pMCAN, DL_MCAN_INTR_LINE_NUM_0, false);
DL_MCAN_enableIntrLine(pxCanHandle->pMCAN, DL_MCAN_INTR_LINE_NUM_1, false); DL_MCAN_enableIntrLine(pxCanHandle->pMCAN, DL_MCAN_INTR_LINE_NUM_1, false);
@ -504,7 +499,7 @@ IVEC_McalStatus_e xMCAL_MCANDeInit(xMcalCanHandle* pxCanHandle)
/* Wait for power down to complete */ /* Wait for power down to complete */
delay_cycles(16); delay_cycles(16);
return IVEC_MCAL_STATUS_SUCCESS; return commonMCAL_SUCCESS;
} }
/** /**
@ -533,19 +528,30 @@ IVEC_McalStatus_e xMCAL_MCANDeInit(xMcalCanHandle* pxCanHandle)
* 7. Disables the CAN module's clock and power, waiting for the power down process to complete. * 7. Disables the CAN module's clock and power, waiting for the power down process to complete.
*/ */
IVEC_McalStatus_e xMCAL_MCANTx(xMcalCanHandle* pxCanHandle, uint32_t u32Id, IVEC_McalCommonErr_e xMCAL_MCANTx(IVEC_McalCanHandle_s* pxCanHandle, uint32_t u32Id,
uint16_t* pu16TxData, uint32_t u32BufNum, uint16_t* pu16TxData, uint32_t u32BufNum,
uint32_t u32Bytes) uint32_t u32Bytes)
{ {
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
assert(pxCanHandle->pMCAN == CANFD0); if((pxCanHandle->pMCAN != CANFD0) && (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_500 || pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_250))
assert(pxCanHandle->u16Speed == IVEC_CAN_BAUD_500 || pxCanHandle->u16Speed == IVEC_CAN_BAUD_250); {
return IVEC_MCAL_STATUS_UNSUPPORTED;
}
/* Ensure that the MCAN is initialized */ /* Ensure that the MCAN is initialized */
assert(pxCanHandle->__u8Init != 0); if(pxCanHandle->__u8Init == 0)
{
return IVEC_MCAL_STATUS_FALSE;
}
/* Validate the byte size */ /* Validate the byte size */
assert(u32Bytes <= 8); if (u32Bytes > 8)
{
return IVEC_MCAL_STATUS_FALSE;
}
DL_MCAN_TxBufElement txMsg = {0};
/* Set the message type (standard or extended ID) */ /* Set the message type (standard or extended ID) */
if (u32Id > 0x7FF) if (u32Id > 0x7FF)
@ -560,23 +566,23 @@ IVEC_McalStatus_e xMCAL_MCANTx(xMcalCanHandle* pxCanHandle, uint32_t u32Id,
} }
/* Copy the data bytes to the message */ /* Copy the data bytes to the message */
for (int i = 0; i < u32Bytes; i++) for (uint32_t u32Index = 0; u32Index < u32Bytes; u32Index++)
{ {
txMsg.data[i] = pu16TxData[i]; txMsg.data[u32Index] = pu16TxData[u32Index];
} }
txMsg.dlc = u32Bytes; /* Set the Data Length Code (DLC) */ txMsg.dlc = u32Bytes; /* Set the Data Length Code (DLC) */
__asm("nop"); /* No operation for synchronization */ __asm("nop"); /* No operation for synchronization */
volatile DL_MCAN_TxFIFOStatus sMcalTxFifoStatus_x = { 0 }; // Structure variable prefixed with 's' for structure type and 'x' for typedef suffix volatile DL_MCAN_TxFIFOStatus l_xTxFifoStatus = { 0 }; // Structure variable prefixed with 's' for structure type and 'x' for typedef suffix
DL_MCAN_getTxFIFOQueStatus(pxCanHandle->pMCAN, &sMcalTxFifoStatus_x); // Get the FIFO status DL_MCAN_getTxFIFOQueStatus(pxCanHandle->pMCAN, &l_xTxFifoStatus); // Get the FIFO status
// __disable_irq();
if (sMcalTxFifoStatus_x.freeLvl) // Check if there is space in the FIFO if (l_xTxFifoStatus.freeLvl) // Check if there is space in the FIFO
{ {
DL_MCAN_writeMsgRam(pxCanHandle->pMCAN, DL_MCAN_MEM_TYPE_FIFO, u32BufNum, &txMsg); // Function and variable name updated DL_MCAN_writeMsgRam(pxCanHandle->pMCAN, DL_MCAN_MEM_TYPE_FIFO, u32BufNum, &txMsg); // Function and variable name updated
if (DL_MCAN_TXBufAddReq(pxCanHandle->pMCAN, sMcalTxFifoStatus_x.putIdx) == IVEC_MCAL_STATUS_ERROR) // Function return type 'x' if (DL_MCAN_TXBufAddReq(pxCanHandle->pMCAN, l_xTxFifoStatus.putIdx) == IVEC_MCAL_STATUS_ERROR) // Function return type 'x'
{ {
return IVEC_MCAL_STATUS_ERROR; return IVEC_MCAL_STATUS_ERROR;
} }
@ -587,6 +593,27 @@ IVEC_McalStatus_e xMCAL_MCANTx(xMcalCanHandle* pxCanHandle, uint32_t u32Id,
return IVEC_MCAL_STATUS_BUSY; return IVEC_MCAL_STATUS_BUSY;
} }
DL_MCAN_getTxFIFOQueStatus(pxCanHandle->pMCAN, &l_xTxFifoStatus);
volatile uint32_t l_i32TransmitTimeout = i32MCAL_getTicks();
volatile uint8_t l_u8StatusFlag = IVEC_MCAL_STATUS_BUSY;
while (1)
{
if (l_u8StatusFlag == IVEC_MCAL_STATUS_SUCCESS)
{
return l_u8StatusFlag;
}
else if ((i32MCAL_getTicks() - l_i32TransmitTimeout) > 2)
{
return IVEC_MCAL_STATUS_TIMEOUT;
}
l_u8StatusFlag = (DL_MCAN_getTxBufTransmissionStatus(pxCanHandle->pMCAN) == 0x01) ? \
IVEC_MCAL_STATUS_SUCCESS : IVEC_MCAL_STATUS_ERROR;
}
// __enable_irq();
return IVEC_MCAL_STATUS_SUCCESS; return IVEC_MCAL_STATUS_SUCCESS;
} }
@ -605,15 +632,19 @@ IVEC_McalStatus_e xMCAL_MCANTx(xMcalCanHandle* pxCanHandle, uint32_t u32Id,
* @return IVEC_MCAL_STATUS_SUCCESS on successful reception. * @return IVEC_MCAL_STATUS_SUCCESS on successful reception.
*/ */
IVEC_McalStatus_e xMCAL_MCANRx(xMcalCanHandle* pxCanHandle, uint32_t *pu32ID, uint8_t *pu8RxData, int iDLC) IVEC_McalCommonErr_e xMCAL_MCANRx(IVEC_McalCanHandle_s* pxCanHandle, uint32_t *pu32ID, uint8_t *pu8RxData, int iDLC)
{ {
/* Assert that the CAN module is CANFD0 and that the MCAL initialization flag is set */ /* Assert that the CAN module is CANFD0 and that the MCAL initialization flag is set */
assert(pxCanHandle->pMCAN == CANFD0); if((pxCanHandle->pMCAN != CANFD0) && (pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_500 || pxCanHandle->u16Speed == IVEC_MCAL_CAN_BR_250))
assert(pxCanHandle->u16Speed == IVEC_CAN_BAUD_500 || pxCanHandle->u16Speed == IVEC_CAN_BAUD_250); {
assert(pxCanHandle->__u8Init != 0); return commonMCAL_INVALID_PARAM;
}
if(pxCanHandle->__u8Init == 0)
{
return commonMCAL_INVALID_PARAM;
}
return commonMCAL_FAIL;
return IVEC_MCAL_STATUS_ERROR;
} }
@ -630,24 +661,24 @@ IVEC_McalStatus_e xMCAL_MCANRx(xMcalCanHandle* pxCanHandle, uint32_t *pu32ID, ui
*/ */
IVEC_McalStatus_e xMCAL_MCANGetErrorStatus(xMcalCanHandle* pxCanHandle, char *pcErrorStatus) IVEC_McalCommonErr_e xMCAL_MCANGetErrorStatus(IVEC_McalCanHandle_s* pxCanHandle, char *pcErrorStatus)
{ {
/* Assert that the MCAN initialization flag is set */ /* Assert that the MCAN initialization flag is set */
assert(pxCanHandle->__u8Init != 0);; if(pxCanHandle->__u8Init == 0)
{
/* Copy the error interrupt status to the provided buffer */ return commonMCAL_INVALID_PARAM;
strcpy(pcErrorStatus, cMCAL_ErrorInterruptStatus); }
/* Retrieve the current protocol status of the MCAN module */ /* Retrieve the current protocol status of the MCAN module */
DL_MCAN_getProtocolStatus(CANFD0, &xMCAL_HeaderStat); DL_MCAN_getProtocolStatus(pxCanHandle->pMCAN, &g_xHeaderStat);
/* Declare and initialize the error counter status structure */ /* Declare and initialize the error counter status structure */
volatile DL_MCAN_ErrCntStatus lErrCounter = {0}; volatile DL_MCAN_ErrCntStatus l_xCounter = {0};
DL_MCAN_getErrCounters(CANFD0, &lErrCounter); DL_MCAN_getErrCounters(CANFD0, &l_xCounter);
/* Return the status based on various error conditions */ /* Return the status based on various error conditions */
return ( return (
(xMCAL_HeaderStat.busOffStatus)) ? IVEC_MCAL_STATUS_ERROR : IVEC_MCAL_STATUS_SUCCESS; (g_xHeaderStat.busOffStatus)) ? commonMCAL_FAIL : commonMCAL_SUCCESS;
} }
@ -662,13 +693,16 @@ IVEC_McalStatus_e xMCAL_MCANGetErrorStatus(xMcalCanHandle* pxCanHandle, char *pc
* @return IVEC_MCAL_STATUS_SUCCESS if successful. * @return IVEC_MCAL_STATUS_SUCCESS if successful.
*/ */
IVEC_McalStatus_e xMCAL_MCANGetInterruptLine1Status(xMcalCanHandle* pxCanHandle, uint32_t *pu32InterruptStatus) IVEC_McalCommonErr_e xMCAL_MCANGetInterruptLine1Status(IVEC_McalCanHandle_s* pxCanHandle, uint32_t *pu32InterruptStatus)
{ {
// Ensure CAN module is initialized (optional assertion, can be uncommented as needed) // Ensure CAN module is initialized (optional assertion, can be uncommented as needed)
assert(pxCanHandle->__u8Init != 0);; if(pxCanHandle->__u8Init == 0)
{
return commonMCAL_INVALID_PARAM;
}
*pu32InterruptStatus = u32MCAL_InterruptLine1Status; *pu32InterruptStatus = g_u32InterruptLine1Status;
return IVEC_MCAL_STATUS_SUCCESS; return commonMCAL_SUCCESS;
} }

View File

@ -10,13 +10,13 @@
#define LOG_STRING "ivec-mcal-uart" #define LOG_STRING "ivec-mcal-uart"
/* Global UART Handles Array */ /* Global UART Handles Array */
xMcalUartHandle* gpxMcalUartHandles[IVEC_MCAL_UART_MAX_PORT] = { 0 }; static IVEC_McalUartHandle_s* __gprv_pIVEC_McalUartHandle_ss[IVEC_MCAL_UART_PORT_MAX] = { 0 };
/* Static Variables */ /* Static Variables */
static uint32_t prv_u32DataCount = 0; /* Data count for tracking received bytes */ static uint32_t __gprv_u32DataCount = 0; /* Data count for tracking received bytes */
/* Static Function Prototypes */ /* Static Function Prototypes */
static eMcalUartPortNumber _prvMCAL_GetUartPort(UART_Regs* pxUartInstance); static IVEC_McalUartPort_e __prv_McalGetUartPort(UART_Regs* pxUartInstance);
/** /**
* @brief UART read callback function. * @brief UART read callback function.
@ -35,7 +35,7 @@ static eMcalUartPortNumber _prvMCAL_GetUartPort(UART_Regs* pxUartInstance);
* - If `bStatus` is true: * - If `bStatus` is true:
* 1. Increments the `prv_u32DataCount` variable to track received data events. * 1. Increments the `prv_u32DataCount` variable to track received data events.
* 2. Logs the data count using the `IVEC_MCAL_LOG` macro. * 2. Logs the data count using the `IVEC_MCAL_LOG` macro.
* 3. Iterates through `gpxMcalUartHandles` to find a valid UART handle. * 3. Iterates through `gpIVEC_McalUartHandle_ss` to find a valid UART handle.
* 4. If a valid user-defined receive callback (`pvUartRecvCallback`) is found, * 4. If a valid user-defined receive callback (`pvUartRecvCallback`) is found,
* it is invoked with the received data. * it is invoked with the received data.
* - If `bStatus` is false, the function performs no additional operations. * - If `bStatus` is false, the function performs no additional operations.
@ -45,17 +45,17 @@ void vMCAL_UartReadCallback(UART_Regs* pxUartInstance, uint8_t* pu8Buffer, bool
{ {
if (bStatus) if (bStatus)
{ {
prv_u32DataCount++; __gprv_u32DataCount++;
IVEC_MCAL_LOG(LOG_STRING, "UART Receive Callback: %d", prv_u32DataCount); IVEC_MCAL_LOG(LOG_STRING, "UART Receive Callback: %d", prv_u32DataCount);
for (uint32_t i = 0; i < IVEC_MCAL_UART_MAX_PORT; i++) for (uint32_t i = 0; i < IVEC_MCAL_UART_PORT_MAX; i++)
{ {
if (gpxMcalUartHandles[i] != NULL) if (__gprv_pIVEC_McalUartHandle_ss[i] != NULL)
{ {
if (gpxMcalUartHandles[i]->pvUartRecvCallback != NULL) if (__gprv_pIVEC_McalUartHandle_ss[i]->pvUartRecvCallback != NULL)
{ {
gpxMcalUartHandles[i]->pvUartRecvCallback(_prvMCAL_GetUartPort(pxUartInstance),eIvecMcalUartEventRxArrived,(char*)pu8Buffer,1); __gprv_pIVEC_McalUartHandle_ss[i]->pvUartRecvCallback(__prv_McalGetUartPort(pxUartInstance),IVEC_MCAL_UART_EVENT_RX_ARRIVED,(char*)pu8Buffer,1);
} }
break; break;
} }
@ -148,18 +148,18 @@ void UART2_IRQHandler()
* @return Pointer to the UART instance, or `eMcalUartPortMax` for invalid input. * @return Pointer to the UART instance, or `eMcalUartPortMax` for invalid input.
*/ */
static UART_Regs* _prvMCAL_GetUartInstance(eMcalUartPortNumber eUartPortNumber) static UART_Regs* __prv_McalGetUartInstance(IVEC_McalUartPort_e eUartPortNumber)
{ {
switch (eUartPortNumber) switch (eUartPortNumber)
{ {
case eMcalUartPort1: case IVEC_MCAL_UART_PORT_1:
return UART0; return UART0;
case eMcalUartPort2: case IVEC_MCAL_UART_PORT_2:
return UART1; return UART1;
case eMcalUartPort3: case IVEC_MCAL_UART_PORT_3:
return UART2; return UART2;
default: default:
return eMcalUartPortMax; // Invalid UART port return NULL; // Invalid UART port
} }
} }
@ -173,22 +173,21 @@ static UART_Regs* _prvMCAL_GetUartInstance(eMcalUartPortNumber eUartPortNumber)
* @return Corresponding `eMcalUartPortNumber` or `eMcalUartPortMax` if invalid. * @return Corresponding `eMcalUartPortNumber` or `eMcalUartPortMax` if invalid.
*/ */
static eMcalUartPortNumber _prvMCAL_GetUartPort(UART_Regs* pxUartInstance) static IVEC_McalUartPort_e __prv_McalGetUartPort(UART_Regs* pxUartInstance)
{ {
switch ((uint32_t)pxUartInstance) switch ((uint32_t)pxUartInstance)
{ {
case (uint32_t)UART0: case (uint32_t)UART0:
return eMcalUartPort1; return IVEC_MCAL_UART_PORT_1;
case (uint32_t)UART1: case (uint32_t)UART1:
return eMcalUartPort2; return IVEC_MCAL_UART_PORT_2;
case (uint32_t)UART2: case (uint32_t)UART2:
return eMcalUartPort3; return IVEC_MCAL_UART_PORT_3;
default: default:
return eMcalUartPortMax; // Invalid UART port return IVEC_MCAL_UART_PORT_MAX; // Invalid UART port
} }
} }
/**
/** /**
* @brief Deinitializes a UART instance. * @brief Deinitializes a UART instance.
* *
@ -200,22 +199,22 @@ static eMcalUartPortNumber _prvMCAL_GetUartPort(UART_Regs* pxUartInstance)
* `IVEC_CORE_STATUS_ERROR` if the UART instance is invalid. * `IVEC_CORE_STATUS_ERROR` if the UART instance is invalid.
*/ */
static IVEC_CoreStatus_e _prvMCAL_UartDeInitInstance(xMcalUartHandle* pxUartHandle) static IVEC_McalCommonErr_e _prvMCAL_UartDeInitInstance(IVEC_McalUartHandle_s* pxUartHandle)
{ {
// Get the UART instance based on the port number in the handle // Get the UART instance based on the port number in the handle
UART_Regs* pxUARTInstance = _prvMCAL_GetUartInstance(pxUartHandle->eUartPortNumber); UART_Regs* pxUartInstance = __prv_McalGetUartInstance(pxUartHandle->eUartPortNumber);
// Check if the UART instance is valid // Check if the UART instance is valid
if (pxUARTInstance == NULL) if (pxUartInstance == NULL)
{ {
return IVEC_CORE_STATUS_ERROR; return commonMCAL_INVALID_PARAM;
} }
// Disable UART instance // Disable UART instance
DL_UART_Main_disable(pxUARTInstance); DL_UART_Main_disable(pxUartInstance );
// Disable interrupts for the UART instance // Disable interrupts for the UART instance
DL_UART_Main_disableInterrupt(pxUARTInstance, DL_UART_Main_disableInterrupt(pxUartInstance ,
DL_UART_MAIN_INTERRUPT_BREAK_ERROR | DL_UART_MAIN_INTERRUPT_BREAK_ERROR |
DL_UART_MAIN_INTERRUPT_FRAMING_ERROR | DL_UART_MAIN_INTERRUPT_FRAMING_ERROR |
DL_UART_MAIN_INTERRUPT_NOISE_ERROR | DL_UART_MAIN_INTERRUPT_NOISE_ERROR |
@ -225,19 +224,19 @@ static IVEC_CoreStatus_e _prvMCAL_UartDeInitInstance(xMcalUartHandle* pxUartHand
DL_UART_MAIN_INTERRUPT_RX_TIMEOUT_ERROR); DL_UART_MAIN_INTERRUPT_RX_TIMEOUT_ERROR);
// Clear and disable NVIC interrupt requests based on UART instance // Clear and disable NVIC interrupt requests based on UART instance
if (pxUARTInstance == UART0) if (pxUartInstance == UART0)
{ {
NVIC_DisableIRQ(UART0_INT_IRQn); NVIC_DisableIRQ(UART0_INT_IRQn);
NVIC_ClearPendingIRQ(UART0_INT_IRQn); NVIC_ClearPendingIRQ(UART0_INT_IRQn);
// Reset the UART0 init flag if needed (b_UART0_init_flag = 0) // Reset the UART0 init flag if needed (b_UART0_init_flag = 0)
} }
else if (pxUARTInstance == UART1) else if (pxUartInstance == UART1)
{ {
NVIC_DisableIRQ(UART1_INT_IRQn); NVIC_DisableIRQ(UART1_INT_IRQn);
NVIC_ClearPendingIRQ(UART1_INT_IRQn); NVIC_ClearPendingIRQ(UART1_INT_IRQn);
// Reset the UART1 init flag if needed (b_UART1_init_flag = 0) // Reset the UART1 init flag if needed (b_UART1_init_flag = 0)
} }
else if (pxUARTInstance == UART2) else if (pxUartInstance == UART2)
{ {
NVIC_DisableIRQ(UART2_INT_IRQn); NVIC_DisableIRQ(UART2_INT_IRQn);
NVIC_ClearPendingIRQ(UART2_INT_IRQn); NVIC_ClearPendingIRQ(UART2_INT_IRQn);
@ -245,9 +244,9 @@ static IVEC_CoreStatus_e _prvMCAL_UartDeInitInstance(xMcalUartHandle* pxUartHand
} }
// Optionally, reset the UART clock configuration if needed // Optionally, reset the UART clock configuration if needed
DL_UART_Main_setClockConfig(pxUARTInstance, NULL); DL_UART_Main_setClockConfig(pxUartInstance, NULL);
return IVEC_CORE_STATUS_SUCCESS; return commonMCAL_SUCCESS;
} }
/** /**
@ -263,14 +262,14 @@ static IVEC_CoreStatus_e _prvMCAL_UartDeInitInstance(xMcalUartHandle* pxUartHand
* `commonMCAL_DEINIT_FAIL` if deinitialization fails. * `commonMCAL_DEINIT_FAIL` if deinitialization fails.
*/ */
IVEC_McalCommonErr_e xMCAL_UartDeInit(xMcalUartHandle* pxUartHandle) IVEC_McalCommonErr_e xMCAL_UartDeInit(IVEC_McalUartHandle_s* pxUartHandle)
{ {
if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_PORT_MAX)
{ {
return commonMCAL_INIT_FAIL; return commonMCAL_INIT_FAIL;
} }
IVEC_CoreStatus_e xRetStatus; IVEC_McalCommonErr_e xRetStatus;
IVEC_MCAL_FUNC_ENTRY(LOG_STRING); IVEC_MCAL_FUNC_ENTRY(LOG_STRING);
IVEC_McalCommonErr_e eFuncStatus = commonMCAL_SUCCESS; IVEC_McalCommonErr_e eFuncStatus = commonMCAL_SUCCESS;
@ -286,7 +285,7 @@ IVEC_McalCommonErr_e xMCAL_UartDeInit(xMcalUartHandle* pxUartHandle)
IVEC_MCAL_LOG(LOG_STRING, "Deinitializing UART status: %d", xRetStatus); IVEC_MCAL_LOG(LOG_STRING, "Deinitializing UART status: %d", xRetStatus);
// Check the return status // Check the return status
if (xRetStatus != IVEC_CORE_STATUS_SUCCESS) if (xRetStatus != commonMCAL_SUCCESS)
{ {
eFuncStatus = commonMCAL_DEINIT_FAIL; eFuncStatus = commonMCAL_DEINIT_FAIL;
goto exit; goto exit;
@ -313,10 +312,10 @@ exit:
* `commonMCAL_FAIL` if no data was received or an error occurred. * `commonMCAL_FAIL` if no data was received or an error occurred.
*/ */
static IVEC_McalCommonErr_e prvIvecMcalUart_ReadByte(xMcalUartHandle* pxUartHandle, uint8_t* pucData) static IVEC_McalCommonErr_e __prv_McalUartReadByte(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pucData)
{ {
/* Get the UART instance based on the port number in the handle */ /* Get the UART instance based on the port number in the handle */
UART_Regs* pUartInstance = _prvMCAL_GetUartInstance(pxUartHandle->eUartPortNumber); UART_Regs* pUartInstance = __prv_McalGetUartInstance(pxUartHandle->eUartPortNumber);
/* Check if the UART instance is valid */ /* Check if the UART instance is valid */
if (pUartInstance == NULL) if (pUartInstance == NULL)
@ -325,11 +324,11 @@ static IVEC_McalCommonErr_e prvIvecMcalUart_ReadByte(xMcalUartHandle* pxUartHan
} }
bool bDataReceived = false; bool bDataReceived = false;
uint32_t u32StartTick = i32MCAL_GetTicks(); uint32_t u32StartTick = i32MCAL_getTicks();
/* Wait until data is received or timeout occurs */ /* Wait until data is received or timeout occurs */
while (!DL_UART_isTXFIFOEmpty(pUartInstance) && while (!DL_UART_isTXFIFOEmpty(pUartInstance) &&
((i32MCAL_GetTicks() - u32StartTick) < 50)) ((i32MCAL_getTicks() - u32StartTick) < 50))
{ {
*pucData = DL_UART_Main_receiveData(pUartInstance); *pucData = DL_UART_Main_receiveData(pUartInstance);
bDataReceived = true; bDataReceived = true;
@ -358,9 +357,9 @@ static IVEC_McalCommonErr_e prvIvecMcalUart_ReadByte(xMcalUartHandle* pxUartHan
* `commonMCAL_INVALID_PARAM` if input parameters are incorrect, * `commonMCAL_INVALID_PARAM` if input parameters are incorrect,
* `commonMCAL_FAIL` if the read operation fails. * `commonMCAL_FAIL` if the read operation fails.
*/ */
IVEC_McalCommonErr_e xIvecMcalUart_Read(xMcalUartHandle* pxUartHandle, uint8_t* pucData, uint32_t u32DataLength) IVEC_McalCommonErr_e xMCAL_UartRead(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pucData, uint32_t u32DataLength)
{ {
if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_PORT_MAX)
{ {
return commonMCAL_INIT_FAIL; return commonMCAL_INIT_FAIL;
} }
@ -377,7 +376,7 @@ IVEC_McalCommonErr_e xIvecMcalUart_Read(xMcalUartHandle* pxUartHandle, uint8_t*
} }
/* Attempt to read a single byte from UART */ /* Attempt to read a single byte from UART */
i32RetVal = prvIvecMcalUart_ReadByte(pxUartHandle, pucData); i32RetVal = __prv_McalUartReadByte(pxUartHandle, pucData);
/* Log the read operation status */ /* Log the read operation status */
IVEC_MCAL_LOG(LOG_STRING, "UART read status: %d", i32RetVal); IVEC_MCAL_LOG(LOG_STRING, "UART read status: %d", i32RetVal);
@ -411,19 +410,19 @@ exit:
* @return `IVEC_CORE_STATUS_SUCCESS` if data is transmitted successfully, * @return `IVEC_CORE_STATUS_SUCCESS` if data is transmitted successfully,
* `IVEC_CORE_STATUS_ERROR` if an error occurs. * `IVEC_CORE_STATUS_ERROR` if an error occurs.
*/ */
static IVEC_CoreStatus_e _prvMCAL_UartTransmit(xMcalUartHandle* pxUartHandle, uint8_t* pu8TxData, uint32_t u32Size) static IVEC_McalCommonErr_e __prv_McalUartTransmit(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pu8TxData, uint32_t u32Size)
{ {
/* Retrieve UART instance based on the port number */ /* Retrieve UART instance based on the port number */
UART_Regs* pxUartInstance = _prvMCAL_GetUartInstance(pxUartHandle->eUartPortNumber); UART_Regs* pxUartInstance = __prv_McalGetUartInstance(pxUartHandle->eUartPortNumber);
/* Validate the UART instance and data size */ /* Validate the UART instance and data size */
if (pxUartInstance == NULL || u32Size == 0) if (pxUartInstance == NULL || u32Size == 0)
{ {
return IVEC_CORE_STATUS_ERROR; return commonMCAL_INVALID_PARAM;
} }
/* Track transmission timeout */ /* Track transmission timeout */
uint32_t u32TickStart = i32MCAL_GetTicks(); uint32_t u32TickStart = i32MCAL_getTicks();
for (uint32_t u32Index = 0; u32Index < u32Size; u32Index++) for (uint32_t u32Index = 0; u32Index < u32Size; u32Index++)
{ {
/* Transmit data byte */ /* Transmit data byte */
@ -431,11 +430,12 @@ static IVEC_CoreStatus_e _prvMCAL_UartTransmit(xMcalUartHandle* pxUartHandle, ui
/* Wait for TX FIFO to become available, with timeout */ /* Wait for TX FIFO to become available, with timeout */
while (DL_UART_isTXFIFOFull(pxUartInstance) && while (DL_UART_isTXFIFOFull(pxUartInstance) &&
((i32MCAL_GetTicks() - u32TickStart) < 100)); ((i32MCAL_getTicks() - u32TickStart) < 100));
} }
return IVEC_CORE_STATUS_SUCCESS; return commonMCAL_SUCCESS;
} }
/** /**
* @brief Writes data to the UART port. * @brief Writes data to the UART port.
* *
@ -450,9 +450,9 @@ static IVEC_CoreStatus_e _prvMCAL_UartTransmit(xMcalUartHandle* pxUartHandle, ui
* `commonMCAL_INVALID_PARAM` if input parameters are invalid, * `commonMCAL_INVALID_PARAM` if input parameters are invalid,
* `commonMCAL_WRITE_FAIL` if the write operation fails. * `commonMCAL_WRITE_FAIL` if the write operation fails.
*/ */
IVEC_McalCommonErr_e xMCAL_UartWrite(xMcalUartHandle* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength) IVEC_McalCommonErr_e xMCAL_UartWrite(IVEC_McalUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint32_t u32DataLength)
{ {
if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_PORT_MAX)
{ {
return commonMCAL_INIT_FAIL; return commonMCAL_INIT_FAIL;
} }
@ -471,7 +471,7 @@ IVEC_McalCommonErr_e xMCAL_UartWrite(xMcalUartHandle* pxUartHandle, uint8_t* pu8
} }
/* Call static transmit function */ /* Call static transmit function */
i32Ret = _prvMCAL_UartTransmit(pxUartHandle, pu8Data, u32DataLength); i32Ret = __prv_McalUartTransmit(pxUartHandle, pu8Data, u32DataLength);
/* Log transmit status */ /* Log transmit status */
IVEC_MCAL_LOG(LOG_STRING, "UART write status: %d", i32Ret); IVEC_MCAL_LOG(LOG_STRING, "UART write status: %d", i32Ret);
@ -513,16 +513,16 @@ exit:
*/ */
static IVEC_CoreStatus_e prvMCAL_UARTInitInstance(xMcalUartHandle* pxUartHandle, eMcalUartBaudRate xBaud) static IVEC_McalCommonErr_e __prv_McalUartInitInstance(IVEC_McalUartHandle_s* pxUartHandle, IVEC_McalUartBaudRate_e xBaud)
{ {
if (pxUartHandle->eUartPortNumber == eMcalUartPort2) if (pxUartHandle->eUartPortNumber == IVEC_MCAL_UART_PORT_2)
{ {
DL_UART_Main_reset(UART1); DL_UART_Main_reset(UART1);
DL_UART_Main_enablePower(UART1); DL_UART_Main_enablePower(UART1);
DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX); DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX);
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX); DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX);
} }
else if (pxUartHandle->eUartPortNumber == eMcalUartPort3) else if (pxUartHandle->eUartPortNumber == IVEC_MCAL_UART_PORT_3)
{ {
DL_UART_Main_reset(UART2); DL_UART_Main_reset(UART2);
DL_UART_Main_enablePower(UART2); DL_UART_Main_enablePower(UART2);
@ -530,7 +530,7 @@ static IVEC_CoreStatus_e prvMCAL_UARTInitInstance(xMcalUartHandle* pxUartHandle,
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX); DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX);
} }
UART_Regs* pxUartInstance = _prvMCAL_GetUartInstance(pxUartHandle->eUartPortNumber); UART_Regs* pxUartInstance = __prv_McalGetUartInstance(pxUartHandle->eUartPortNumber);
if (pxUartInstance == NULL) if (pxUartInstance == NULL)
{ {
@ -541,36 +541,36 @@ static IVEC_CoreStatus_e prvMCAL_UARTInitInstance(xMcalUartHandle* pxUartHandle,
xUartConfig.direction = DL_UART_MAIN_DIRECTION_TX_RX; xUartConfig.direction = DL_UART_MAIN_DIRECTION_TX_RX;
xUartConfig.mode = DL_UART_MAIN_MODE_NORMAL; xUartConfig.mode = DL_UART_MAIN_MODE_NORMAL;
uint8_t ucDataLength = pxUartHandle->xUartConfig.eUartDataBit; uint8_t u8DataLength = pxUartHandle->xUartConfig.eUartDataBit;
if (ucDataLength == eMcalUartDataBit7) if (u8DataLength == IVEC_MCAL_UART_DATA_BIT_7)
{ {
xUartConfig.wordLength = DL_UART_WORD_LENGTH_7_BITS; xUartConfig.wordLength = DL_UART_WORD_LENGTH_7_BITS;
} }
else if (ucDataLength == eMcalUartDataBit8) else if (u8DataLength == IVEC_MCAL_UART_DATA_BIT_8)
{ {
xUartConfig.wordLength = DL_UART_WORD_LENGTH_8_BITS; xUartConfig.wordLength = DL_UART_WORD_LENGTH_8_BITS;
} }
uint8_t ucStopBit = pxUartHandle->xUartConfig.eUartStopBit; uint8_t u8StopBit = pxUartHandle->xUartConfig.eUartStopBit;
if (ucStopBit == eMcalUartStopBit1) if (u8StopBit == IVEC_MCAL_UART_STOP_BIT_1)
{ {
xUartConfig.stopBits = DL_UART_STOP_BITS_ONE; xUartConfig.stopBits = DL_UART_STOP_BITS_ONE;
} }
else if (ucStopBit == eMcalUartStopBit2) else if (u8StopBit == IVEC_MCAL_UART_STOP_BIT_2)
{ {
xUartConfig.stopBits = DL_UART_STOP_BITS_TWO; xUartConfig.stopBits = DL_UART_STOP_BITS_TWO;
} }
uint8_t ucParityBit = pxUartHandle->xUartConfig.eUartParityBit; uint8_t u8ParityBit = pxUartHandle->xUartConfig.eUartParityBit;
if (ucParityBit == eMcalUartParityNone) if (u8ParityBit == IVEC_MCAL_UART_PARITY_NONE)
{ {
xUartConfig.parity = DL_UART_PARITY_NONE; xUartConfig.parity = DL_UART_PARITY_NONE;
} }
else if (ucParityBit == eMcalUartParityOdd) else if (u8ParityBit == IVEC_MCAL_UART_PARITY_ODD)
{ {
xUartConfig.parity = DL_UART_PARITY_ODD; xUartConfig.parity = DL_UART_PARITY_ODD;
} }
else if (ucParityBit == eMcalUartParityEven) else if (u8ParityBit == IVEC_MCAL_UART_PARITY_EVEN)
{ {
xUartConfig.parity = DL_UART_PARITY_EVEN; xUartConfig.parity = DL_UART_PARITY_EVEN;
} }
@ -587,59 +587,59 @@ static IVEC_CoreStatus_e prvMCAL_UARTInitInstance(xMcalUartHandle* pxUartHandle,
DL_UART_Main_setOversampling(pxUartInstance, DL_UART_OVERSAMPLING_RATE_16X); DL_UART_Main_setOversampling(pxUartInstance, DL_UART_OVERSAMPLING_RATE_16X);
if (xBaud == eMcalUartBaud115200) if (xBaud == IVEC_MCAL_UART_BAUD_115200)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 19, 34); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 19, 34);
} }
else if (xBaud == eMcalUartBaud9600) else if (xBaud == IVEC_MCAL_UART_BAUD_9600)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 234, 24); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 234, 24);
} }
else if (xBaud == eMcalUartBaud2400) else if (xBaud == IVEC_MCAL_UART_BAUD_2400)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 937, 32); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 937, 32);
} }
else if (xBaud == eMcalUartBaud4800) else if (xBaud == IVEC_MCAL_UART_BAUD_4800)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 468, 48); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 468, 48);
} }
else if (xBaud == eMcalUartBaud14400) else if (xBaud == IVEC_MCAL_UART_BAUD_14400)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 156, 16); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 156, 16);
} }
else if (xBaud == eMcalUartBaud19200) else if (xBaud == IVEC_MCAL_UART_BAUD_19200)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 117, 12); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 117, 12);
} }
else if (xBaud == eMcalUartBaud28800) else if (xBaud == IVEC_MCAL_UART_BAUD_28800)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 78, 8); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 78, 8);
} }
else if (xBaud == eMcalUartBaud33600) else if (xBaud == IVEC_MCAL_UART_BAUD_33600)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 66, 62); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 66, 62);
} }
else if (xBaud == eMcalUartBaud38400) else if (xBaud == IVEC_MCAL_UART_BAUD_38400)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 58, 38); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 58, 38);
} }
else if (xBaud == eMcalUartBaud57600) else if (xBaud == IVEC_MCAL_UART_BAUD_57600)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 39, 4); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 39, 4);
} }
else if (xBaud == eMcalUartBaud230400) else if (xBaud == IVEC_MCAL_UART_BAUD_230400)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 9, 49); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 9, 49);
} }
else if (xBaud == eMcalUartBaud460800) else if (xBaud == IVEC_MCAL_UART_BAUD_460800)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 4, 57); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 4, 57);
} }
else if (xBaud == eMcalUartBaud921600) else if (xBaud == IVEC_MCAL_UART_BAUD_921600)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 2, 28); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 2, 28);
} }
else if (xBaud == eMcalUartBaud1000000) else if (xBaud == IVEC_MCAL_UART_BAUD_1000000)
{ {
DL_UART_Main_setBaudRateDivisor(pxUartInstance, 2, 16); DL_UART_Main_setBaudRateDivisor(pxUartInstance, 2, 16);
} }
@ -742,23 +742,23 @@ static void __prvMCAL_UartNotifyRecvCb(uint32 ind_type, ql_uart_port_number_e po
/** /**
* @brief Registers a UART handle for a specified UART port. * @brief Registers a UART handle for a specified UART port.
* *
* This function stores the given UART handle in the UART handles (`gpxMcalUartHandles`) * This function stores the given UART handle in the UART handles (`gpIVEC_McalUartHandle_ss`)
* at the index corresponding to the specified UART port number. It ensures that the handle can be accessed * at the index corresponding to the specified UART port number. It ensures that the handle can be accessed
* later for operations like configuring or handling UART events. * later for operations like configuring or handling UART events.
* *
* @param [in] pxUartHandle Pointer to the UART handle to be registered. The handle should contain * @param [in] pxUartHandle Pointer to the UART handle to be registered. The handle should contain
* valid configuration and state information for the corresponding UART port. * valid configuration and state information for the corresponding UART port.
*/ */
static void prvMCAL_UartRegisterHandle(xMcalUartHandle* pxUartHandle) static void prvMCAL_UartRegisterHandle(IVEC_McalUartHandle_s* pxUartHandle)
{ {
gpxMcalUartHandles[pxUartHandle->eUartPortNumber] = pxUartHandle; __gprv_pIVEC_McalUartHandle_ss[pxUartHandle->eUartPortNumber] = pxUartHandle;
} }
/** /**
* @brief Initializes the UART peripheral based on the provided configuration. * @brief Initializes the UART peripheral based on the provided configuration.
* *
* This function initializes the UART instance by registering the handle, * This function initializes the UART instance by registering the handle,
* configuring the UART instance with the settings specified in the * configuring the UART instance with the settings specified in the
* `xMcalUartHandle`, and setting the UART's baud rate. If the provided handle * `IVEC_McalUartHandle_s`, and setting the UART's baud rate. If the provided handle
* is invalid or if initialization fails, an appropriate error code is returned. * is invalid or if initialization fails, an appropriate error code is returned.
* *
* @param [in] pxUartHandle Pointer to the UART handle, containing the port number and configuration * @param [in] pxUartHandle Pointer to the UART handle, containing the port number and configuration
@ -769,12 +769,12 @@ static void prvMCAL_UartRegisterHandle(xMcalUartHandle* pxUartHandle)
* - `commonMCAL_INVALID_PARAM` if the provided handle is invalid (NULL or incorrect port number). * - `commonMCAL_INVALID_PARAM` if the provided handle is invalid (NULL or incorrect port number).
* - `commonMCAL_INIT_FAIL` if initialization of the UART instance fails. * - `commonMCAL_INIT_FAIL` if initialization of the UART instance fails.
*/ */
IVEC_McalCommonErr_e xMCAL_UartInit(xMcalUartHandle* pxUartHandle) IVEC_McalCommonErr_e xMCAL_UartInit(IVEC_McalUartHandle_s* pxUartHandle)
{ {
IVEC_MCAL_FUNC_ENTRY(LOG_STRING); IVEC_MCAL_FUNC_ENTRY(LOG_STRING);
IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS; IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS;
if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_MCAL_UART_PORT_MAX)
{ {
return commonMCAL_INVALID_PARAM; return commonMCAL_INVALID_PARAM;
goto exit; goto exit;
@ -782,7 +782,7 @@ IVEC_McalCommonErr_e xMCAL_UartInit(xMcalUartHandle* pxUartHandle)
prvMCAL_UartRegisterHandle(pxUartHandle); prvMCAL_UartRegisterHandle(pxUartHandle);
int l_i32Ret = prvMCAL_UARTInitInstance(pxUartHandle, pxUartHandle->xUartConfig.eUartBaudrate); int l_i32Ret = __prv_McalUartInitInstance(pxUartHandle, pxUartHandle->xUartConfig.eUartBaudrate);
if (l_i32Ret != IVEC_CORE_STATUS_SUCCESS) if (l_i32Ret != IVEC_CORE_STATUS_SUCCESS)
{ {
l_xFuncStatus = commonMCAL_INIT_FAIL; l_xFuncStatus = commonMCAL_INIT_FAIL;

View File

@ -3,9 +3,9 @@
* *
* Code generated for Simulink model 'socTouchDisplay'. * Code generated for Simulink model 'socTouchDisplay'.
* *
* Model version : 1.128 * Model version : 1.140
* Simulink Coder version : 23.2 (R2023b) 01-Aug-2023 * Simulink Coder version : 23.2 (R2023b) 01-Aug-2023
* C/C++ source code generated on : Fri Dec 27 18:51:07 2024 * C/C++ source code generated on : Mon Jan 20 13:31:03 2025
* *
* Target selection: ert.tlc * Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64) * Embedded hardware selection: Intel->x86-64 (Windows64)
@ -45,13 +45,14 @@ typedef struct {
void* SFunction_canFrameBUS; /* '<S3>/S-Function' */ void* SFunction_canFrameBUS; /* '<S3>/S-Function' */
uint32_T durationCounter_1; /* '<Root>/Chart1' */ uint32_T durationCounter_1; /* '<Root>/Chart1' */
uint32_T temporalCounter_i1; /* '<Root>/Chart' */ uint32_T temporalCounter_i1; /* '<Root>/Chart' */
uint32_T durationCounter_1_g; /* '<Root>/Chart' */ uint32_T durationCounter_1_l; /* '<Root>/Chart' */
uint32_T durationCounter_2; /* '<Root>/Chart' */ uint32_T durationCounter_2; /* '<Root>/Chart' */
uint32_T durationCounter_3; /* '<Root>/Chart' */ uint32_T durationCounter_1_a; /* '<Root>/Chart' */
uint8_T is_active_c1_socTouchDisplay;/* '<Root>/Chart1' */ uint8_T is_active_c1_socTouchDisplay;/* '<Root>/Chart1' */
uint8_T is_c1_socTouchDisplay; /* '<Root>/Chart1' */ uint8_T is_c1_socTouchDisplay; /* '<Root>/Chart1' */
uint8_T is_active_c3_socTouchDisplay;/* '<Root>/Chart' */ uint8_T is_active_c3_socTouchDisplay;/* '<Root>/Chart' */
uint8_T is_c3_socTouchDisplay; /* '<Root>/Chart' */ uint8_T is_c3_socTouchDisplay; /* '<Root>/Chart' */
uint8_T is_chargingMode; /* '<Root>/Chart' */
} DW_socTouchDisplay_T; } DW_socTouchDisplay_T;
/* External inputs (root inport signals with default storage) */ /* External inputs (root inport signals with default storage) */

View File

@ -3,9 +3,9 @@
* *
* Code generated for Simulink model 'socTouchDisplay'. * Code generated for Simulink model 'socTouchDisplay'.
* *
* Model version : 1.128 * Model version : 1.133
* Simulink Coder version : 23.2 (R2023b) 01-Aug-2023 * Simulink Coder version : 23.2 (R2023b) 01-Aug-2023
* C/C++ source code generated on : Fri Dec 27 18:51:07 2024 * C/C++ source code generated on : Sat Jan 18 20:05:13 2025
* *
* Target selection: ert.tlc * Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64) * Embedded hardware selection: Intel->x86-64 (Windows64)

View File

@ -3,9 +3,9 @@
* *
* Code generated for Simulink model 'socTouchDisplay'. * Code generated for Simulink model 'socTouchDisplay'.
* *
* Model version : 1.128 * Model version : 1.133
* Simulink Coder version : 23.2 (R2023b) 01-Aug-2023 * Simulink Coder version : 23.2 (R2023b) 01-Aug-2023
* C/C++ source code generated on : Fri Dec 27 18:51:07 2024 * C/C++ source code generated on : Sat Jan 18 20:05:13 2025
* *
* Target selection: ert.tlc * Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64) * Embedded hardware selection: Intel->x86-64 (Windows64)

View File

@ -3,9 +3,9 @@
* *
* Code generated for Simulink model 'socTouchDisplay'. * Code generated for Simulink model 'socTouchDisplay'.
* *
* Model version : 1.128 * Model version : 1.140
* Simulink Coder version : 23.2 (R2023b) 01-Aug-2023 * Simulink Coder version : 23.2 (R2023b) 01-Aug-2023
* C/C++ source code generated on : Fri Dec 27 18:51:07 2024 * C/C++ source code generated on : Mon Jan 20 13:31:03 2025
* *
* Target selection: ert.tlc * Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64) * Embedded hardware selection: Intel->x86-64 (Windows64)
@ -20,7 +20,10 @@
/* Named constants for Chart: '<Root>/Chart' */ /* Named constants for Chart: '<Root>/Chart' */
#define socTouchDis_IN_touchNotDetected ((uint8_T)4U) #define socTouchDis_IN_touchNotDetected ((uint8_T)4U)
#define socTouchDisp_IN_chargingDisplay ((uint8_T)1U) #define socTouchDisp_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define socTouchDisplay_IN_HideSoc ((uint8_T)1U)
#define socTouchDisplay_IN_chargingMode ((uint8_T)1U)
#define socTouchDisplay_IN_dispalySoc ((uint8_T)2U)
#define socTouchDisplay_IN_displayError ((uint8_T)2U) #define socTouchDisplay_IN_displayError ((uint8_T)2U)
#define socTouchDisplay_IN_displaySoc ((uint8_T)3U) #define socTouchDisplay_IN_displaySoc ((uint8_T)3U)
@ -29,7 +32,7 @@
#define socTouchDisplay_IN_init ((uint8_T)2U) #define socTouchDisplay_IN_init ((uint8_T)2U)
/* Block signals (default storage) */ /* Block signals (default storage) */
B_socTouchDisplay_T socTouchDisplay_B; B_socTouchDisplay_T socTouchDisplay_B = {0};
/* Block states (default storage) */ /* Block states (default storage) */
DW_socTouchDisplay_T socTouchDisplay_DW; DW_socTouchDisplay_T socTouchDisplay_DW;
@ -52,6 +55,7 @@ void socTouchDisplay_step(void)
uint32_T tmp; uint32_T tmp;
uint8_T rtb_Cast; uint8_T rtb_Cast;
boolean_T Memory_PreviousInput; boolean_T Memory_PreviousInput;
boolean_T rtb_AND;
boolean_T rtb_Equal; boolean_T rtb_Equal;
boolean_T rtb_Memory; boolean_T rtb_Memory;
@ -76,21 +80,25 @@ void socTouchDisplay_step(void)
*/ */
rtb_Equal = (socTouchDisplay_B.SFunction.ID == socTouchDisplay_U.ip_u32canId); rtb_Equal = (socTouchDisplay_B.SFunction.ID == socTouchDisplay_U.ip_u32canId);
/* Outputs for Enabled SubSystem: '<S3>/Enabled Subsystem' incorporates:
* EnablePort: '<S5>/Enable'
*/
/* Logic: '<S3>/AND' incorporates: /* Logic: '<S3>/AND' incorporates:
* Constant: '<S3>/Constant' * Constant: '<S3>/Constant'
* RelationalOperator: '<S3>/Equal1' * RelationalOperator: '<S3>/Equal1'
*/ */
if (rtb_Equal && (socTouchDisplay_B.SFunction.Data[0] == 2)) { rtb_AND = (rtb_Equal && (socTouchDisplay_B.SFunction.Data[0] == 2));
/* Memory: '<S3>/Memory' */
rtb_Memory = Memory_PreviousInput;
/* Outputs for Enabled SubSystem: '<S3>/Enabled Subsystem' incorporates:
* EnablePort: '<S5>/Enable'
*/
if (rtb_AND) {
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
/* SignalConversion generated from: '<S5>/In1' */ /* SignalConversion generated from: '<S5>/In1' */
socTouchDisplay_B.In1[i] = socTouchDisplay_B.SFunction.Data[i]; socTouchDisplay_B.In1[i] = socTouchDisplay_B.SFunction.Data[i];
} }
} }
/* End of Logic: '<S3>/AND' */
/* End of Outputs for SubSystem: '<S3>/Enabled Subsystem' */ /* End of Outputs for SubSystem: '<S3>/Enabled Subsystem' */
/* DataTypeConversion: '<S3>/Cast' */ /* DataTypeConversion: '<S3>/Cast' */
@ -113,13 +121,10 @@ void socTouchDisplay_step(void)
/* End of Logic: '<S3>/AND1' */ /* End of Logic: '<S3>/AND1' */
/* End of Outputs for SubSystem: '<S3>/Enabled Subsystem1' */ /* End of Outputs for SubSystem: '<S3>/Enabled Subsystem1' */
/* Memory: '<S3>/Memory' */
rtb_Memory = Memory_PreviousInput;
/* Update for Memory: '<S3>/Memory' incorporates: /* Update for Memory: '<S3>/Memory' incorporates:
* Logic: '<S3>/OR' * Logic: '<S3>/OR'
*/ */
Memory_PreviousInput = (rtb_Equal || Memory_PreviousInput); Memory_PreviousInput = (rtb_AND || Memory_PreviousInput);
} }
/* End of Outputs for SubSystem: '<Root>/canMsgDecode' */ /* End of Outputs for SubSystem: '<Root>/canMsgDecode' */
@ -169,9 +174,8 @@ void socTouchDisplay_step(void)
if (socTouchDisplay_DW.is_active_c3_socTouchDisplay == 0U) { if (socTouchDisplay_DW.is_active_c3_socTouchDisplay == 0U) {
socTouchDisplay_DW.is_active_c3_socTouchDisplay = 1U; socTouchDisplay_DW.is_active_c3_socTouchDisplay = 1U;
socTouchDisplay_DW.durationCounter_3 = 0U;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDis_IN_touchNotDetected; socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDis_IN_touchNotDetected;
/* Outport: '<Root>/op_bDisplayStatus' */ /* Outport: '<Root>/op_bDisplayStatus' */
@ -181,13 +185,16 @@ void socTouchDisplay_step(void)
socTouchDisplay_Y.op_bErrorStatus = false; socTouchDisplay_Y.op_bErrorStatus = false;
} else { } else {
switch (socTouchDisplay_DW.is_c3_socTouchDisplay) { switch (socTouchDisplay_DW.is_c3_socTouchDisplay) {
case socTouchDisp_IN_chargingDisplay: case socTouchDisplay_IN_chargingMode:
/* Outport: '<Root>/op_bDisplayStatus' */ if (socTouchDisplay_B.Compare) {
socTouchDisplay_Y.op_bDisplayStatus = true; socTouchDisplay_DW.durationCounter_1_a = 0U;
if (socTouchDisplay_DW.temporalCounter_i1 >= 20U) { }
socTouchDisplay_DW.durationCounter_3 = 0U;
if ((socTouchDisplay_DW.durationCounter_1_a > 20U) ||
(!Memory_PreviousInput)) {
socTouchDisplay_DW.is_chargingMode = socTouchDisp_IN_NO_ACTIVE_CHILD;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_DW.is_c3_socTouchDisplay =
socTouchDis_IN_touchNotDetected; socTouchDis_IN_touchNotDetected;
@ -196,6 +203,28 @@ void socTouchDisplay_step(void)
/* Outport: '<Root>/op_bErrorStatus' */ /* Outport: '<Root>/op_bErrorStatus' */
socTouchDisplay_Y.op_bErrorStatus = false; socTouchDisplay_Y.op_bErrorStatus = false;
} else if (socTouchDisplay_DW.is_chargingMode ==
socTouchDisplay_IN_HideSoc) {
/* Outport: '<Root>/op_bDisplayStatus' */
socTouchDisplay_Y.op_bDisplayStatus = false;
if (socTouchDisplay_DW.temporalCounter_i1 >= 20U) {
socTouchDisplay_DW.temporalCounter_i1 = 0U;
socTouchDisplay_DW.is_chargingMode = socTouchDisplay_IN_dispalySoc;
/* Outport: '<Root>/op_bDisplayStatus' */
socTouchDisplay_Y.op_bDisplayStatus = true;
}
} else {
/* Outport: '<Root>/op_bDisplayStatus' */
/* case IN_dispalySoc: */
socTouchDisplay_Y.op_bDisplayStatus = true;
if (socTouchDisplay_DW.temporalCounter_i1 >= 20U) {
socTouchDisplay_DW.temporalCounter_i1 = 0U;
socTouchDisplay_DW.is_chargingMode = socTouchDisplay_IN_HideSoc;
/* Outport: '<Root>/op_bDisplayStatus' */
socTouchDisplay_Y.op_bDisplayStatus = false;
}
} }
break; break;
@ -204,9 +233,8 @@ void socTouchDisplay_step(void)
socTouchDisplay_Y.op_bErrorStatus = true; socTouchDisplay_Y.op_bErrorStatus = true;
if ((uint32_T)((int32_T)socTouchDisplay_DW.temporalCounter_i1 * 100) >= if ((uint32_T)((int32_T)socTouchDisplay_DW.temporalCounter_i1 * 100) >=
(uint32_T)ceil(socTouchDisplay_U.ip_u32DisplayDuration_msec)) { (uint32_T)ceil(socTouchDisplay_U.ip_u32DisplayDuration_msec)) {
socTouchDisplay_DW.durationCounter_3 = 0U;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_DW.is_c3_socTouchDisplay =
socTouchDis_IN_touchNotDetected; socTouchDis_IN_touchNotDetected;
@ -223,9 +251,8 @@ void socTouchDisplay_step(void)
socTouchDisplay_Y.op_bDisplayStatus = true; socTouchDisplay_Y.op_bDisplayStatus = true;
if ((uint32_T)((int32_T)socTouchDisplay_DW.temporalCounter_i1 * 100) >= if ((uint32_T)((int32_T)socTouchDisplay_DW.temporalCounter_i1 * 100) >=
(uint32_T)ceil(socTouchDisplay_U.ip_u32DisplayDuration_msec)) { (uint32_T)ceil(socTouchDisplay_U.ip_u32DisplayDuration_msec)) {
socTouchDisplay_DW.durationCounter_3 = 0U;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_DW.is_c3_socTouchDisplay =
socTouchDis_IN_touchNotDetected; socTouchDis_IN_touchNotDetected;
@ -244,45 +271,43 @@ void socTouchDisplay_step(void)
/* Outport: '<Root>/op_bErrorStatus' */ /* Outport: '<Root>/op_bErrorStatus' */
socTouchDisplay_Y.op_bErrorStatus = false; socTouchDisplay_Y.op_bErrorStatus = false;
rtb_Memory = !(socTouchDisplay_U.in_bTouchDetected == 1.0); if (socTouchDisplay_B.Compare && Memory_PreviousInput) {
if (rtb_Memory) { socTouchDisplay_DW.durationCounter_1_a = 0U;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.is_c3_socTouchDisplay =
} socTouchDisplay_IN_chargingMode;
tmp = (uint32_T)ceil(socTouchDisplay_U.ip_u32TouchDuration_msec);
if (((uint32_T)((int32_T)socTouchDisplay_DW.durationCounter_2 * 100) > tmp)
&& Memory_PreviousInput) {
socTouchDisplay_DW.temporalCounter_i1 = 0U; socTouchDisplay_DW.temporalCounter_i1 = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_IN_displaySoc; socTouchDisplay_DW.is_chargingMode = socTouchDisplay_IN_dispalySoc;
/* Outport: '<Root>/op_bDisplayStatus' */ /* Outport: '<Root>/op_bDisplayStatus' */
socTouchDisplay_Y.op_bDisplayStatus = true; socTouchDisplay_Y.op_bDisplayStatus = true;
} else { } else {
rtb_Memory = !(socTouchDisplay_U.in_bTouchDetected == 1.0);
if (rtb_Memory) { if (rtb_Memory) {
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
} }
if (((uint32_T)((int32_T)socTouchDisplay_DW.durationCounter_1_g * 100) > tmp = (uint32_T)ceil(socTouchDisplay_U.ip_u32TouchDuration_msec);
tmp) && (!Memory_PreviousInput)) { if (((uint32_T)((int32_T)socTouchDisplay_DW.durationCounter_2 * 100) >
tmp) && Memory_PreviousInput) {
socTouchDisplay_DW.temporalCounter_i1 = 0U; socTouchDisplay_DW.temporalCounter_i1 = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_DW.is_c3_socTouchDisplay =
socTouchDisplay_IN_displayError; socTouchDisplay_IN_displaySoc;
/* Outport: '<Root>/op_bErrorStatus' */ /* Outport: '<Root>/op_bDisplayStatus' */
socTouchDisplay_Y.op_bErrorStatus = true; socTouchDisplay_Y.op_bDisplayStatus = true;
} else { } else {
if (!socTouchDisplay_B.Compare) { if (rtb_Memory) {
socTouchDisplay_DW.durationCounter_3 = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
} }
if ((socTouchDisplay_DW.durationCounter_3 > 20U) && if (((uint32_T)((int32_T)socTouchDisplay_DW.durationCounter_1_l * 100)
Memory_PreviousInput) { > tmp) && (!Memory_PreviousInput)) {
socTouchDisplay_DW.temporalCounter_i1 = 0U; socTouchDisplay_DW.temporalCounter_i1 = 0U;
socTouchDisplay_DW.is_c3_socTouchDisplay = socTouchDisplay_DW.is_c3_socTouchDisplay =
socTouchDisp_IN_chargingDisplay; socTouchDisplay_IN_displayError;
/* Outport: '<Root>/op_bDisplayStatus' */ /* Outport: '<Root>/op_bErrorStatus' */
socTouchDisplay_Y.op_bDisplayStatus = true; socTouchDisplay_Y.op_bErrorStatus = true;
} }
} }
} }
@ -291,17 +316,17 @@ void socTouchDisplay_step(void)
} }
if (socTouchDisplay_U.in_bTouchDetected == 1.0) { if (socTouchDisplay_U.in_bTouchDetected == 1.0) {
socTouchDisplay_DW.durationCounter_1_g++; socTouchDisplay_DW.durationCounter_1_l++;
socTouchDisplay_DW.durationCounter_2++; socTouchDisplay_DW.durationCounter_2++;
} else { } else {
socTouchDisplay_DW.durationCounter_1_g = 0U; socTouchDisplay_DW.durationCounter_1_l = 0U;
socTouchDisplay_DW.durationCounter_2 = 0U; socTouchDisplay_DW.durationCounter_2 = 0U;
} }
if (socTouchDisplay_B.Compare) { if (!socTouchDisplay_B.Compare) {
socTouchDisplay_DW.durationCounter_3++; socTouchDisplay_DW.durationCounter_1_a++;
} else { } else {
socTouchDisplay_DW.durationCounter_3 = 0U; socTouchDisplay_DW.durationCounter_1_a = 0U;
} }
/* End of Chart: '<Root>/Chart' */ /* End of Chart: '<Root>/Chart' */

View File

@ -9,16 +9,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define ivECU_MAX_FILTERS ivMCAL_MAX_FILTERS #define ecuMAX_FILTERS_u8 mcalMAX_FILTERS_u8
// Macro Definitions // Macro Definitions
#define IVEC_ECU_CAN_QUEUE(name, buff) \ #define IVEC_ECU_CAN_QUEUE(name, buff) \
volatile IVEC_ECU_CANQueue_s name = { \ volatile IVEC_ECU_CANQueue_s name = { \
.front = 0, \ .u16Front = 0, \
.rear = 0, \ .u16Rear = 0, \
.size = (sizeof(buff) / sizeof(buff[0])), \ .u16Size = (sizeof(buff) / sizeof(buff[0])), \
.element_size = sizeof(buff[0]), \ .u8ElementSize = sizeof(buff[0]), \
.buffer = buff, \ .pxBuffer = buff, \
} }
#define IVEC_ECU_CAN_FLUSH(name) do { \ #define IVEC_ECU_CAN_FLUSH(name) do { \
@ -28,34 +28,34 @@
} while (0) } while (0)
#define IVEC_ECU_CAN_ENQUEUE(queue, data) do { \ #define IVEC_ECU_CAN_ENQUEUE(queue, data) do { \
memcpy(&queue.buffer[queue.front++], &data, sizeof(data)); \ memcpy(&queue.pxBuffer[queue.u16Front++], &data, sizeof(data)); \
queue.front %= queue.size; \ queue.u16Front %= queue.u16Size; \
} while (0) } while (0)
#define IVEC_ECU_CAN_DEQUEUE(queue, data) do { \ #define IVEC_ECU_CAN_DEQUEUE(queue, data) do { \
memcpy(&data, &queue.buffer[queue.rear++], sizeof(data)); \ memcpy(&data, &queue.pxBuffer[queue.u16Rear++], sizeof(data)); \
queue.rear %= queue.size; \ queue.u16Rear %= queue.u16Size; \
} while (0) } while (0)
#define IVEC_ECU_CAN_IS_FULL(queue) ((queue.front - queue.rear) == (queue.size - 1) || \ #define IVEC_ECU_CAN_IS_FULL(queue) ((queue.u16Front - queue.u16Rear) == (queue.u16Size - 1) || \
(queue.front - queue.rear) == -1) (queue.u16Front - queue.u16Rear) == -1)
#define IVEC_ECU_CAN_IS_EMPTY(queue) (queue.front == queue.rear) #define IVEC_ECU_CAN_IS_EMPTY(queue) (queue.u16Front == queue.u16Rear)
/* Private Variable */ /* Private Variable */
typedef struct { typedef struct {
uint32_t ulId; uint32_t u32UlId;
uint8_t ucData[8]; uint8_t u8Data[8];
uint8_t ucLength; uint8_t u8Length;
uint8_t resv[3]; uint8_t u8Resv[3];
} IVEC_ECU_CANBuff_s; } IVEC_ECU_CANBuff_s;
typedef struct { typedef struct {
uint16_t front; uint16_t u16Front;
uint16_t rear; uint16_t u16Rear;
uint16_t size; uint16_t u16Size;
uint8_t element_size; uint8_t u8ElementSize;
IVEC_ECU_CANBuff_s *buffer; IVEC_ECU_CANBuff_s *pxBuffer;
} IVEC_ECU_CANQueue_s; } IVEC_ECU_CANQueue_s;
typedef enum typedef enum
@ -66,29 +66,28 @@ typedef enum
IVEC_ECU_CAN_SPEED_250 = 250, IVEC_ECU_CAN_SPEED_250 = 250,
IVEC_ECU_CAN_SPEED_500 = 500, IVEC_ECU_CAN_SPEED_500 = 500,
IVEC_ECU_CAN_SPEED_1000 = 1000, IVEC_ECU_CAN_SPEED_1000 = 1000,
}IVEC_EcuCANSpeed_s; }IVEC_EcuCANSpeed_e;
typedef struct typedef struct
{ {
xMcalCanHandle __xCanHandle; IVEC_McalCanHandle_s __xCanHandle;
MCAN_Regs *pMCAN; MCAN_Regs *pMCAN;
uint8_t __u8Init; uint8_t __u8Init;
IVEC_EcuCANSpeed_s u16Speed; IVEC_EcuCANSpeed_e u16Speed;
int32_t i32MaskCount; int32_t i32MaskCount;
int32_t i32FilterCount; int32_t i32FilterCount;
uint8_t __u8MaxFilter; uint32_t u32MaskValues[ecuMAX_FILTERS_u8];
uint32_t u32MaskValues[ivECU_MAX_FILTERS]; uint32_t u32FilterValues[ecuMAX_FILTERS_u8];
uint32_t u32FilterValues[ivECU_MAX_FILTERS];
}IVEC_EcuCANHandle_s; }IVEC_EcuCANHandle_s;
// Function Prototypes // Function Prototypes
void vMCU_FDCANRxFifoCallback(uint32_t ulIdentifier, uint8_t *pucData, uint16_t usDataLength); void vMCU_FDCANRxFifoCallback(uint32_t u32Identifier, uint8_t *pu8data, uint16_t u16DataLength);
uint8_t u8MCAL_StoreMsgFromISRToQueue(uint32_t ulId, uint8_t *pucData, uint8_t ucLen); uint8_t u8MCAL_StoreMsgFromISRToQueue(uint32_t u32UlId, uint8_t* pu8Data, uint8_t u8Len);
IVEC_EcuCommonErr_e xECU_CANInit(IVEC_EcuCANHandle_s *xCANhandle); IVEC_EcuCommonErr_e xECU_CANInit(IVEC_EcuCANHandle_s *xCANhandle);
IVEC_EcuCommonErr_e xECU_CANDeInit(IVEC_EcuCANHandle_s *xCANhandle); IVEC_EcuCommonErr_e xECU_CANDeInit(IVEC_EcuCANHandle_s *xCANhandle);
IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(IVEC_EcuCANHandle_s *xCANhandle,uint8_t *pucBuf, uint32_t ulId, int iRetCode, uint32_t ulBufNum); IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(IVEC_EcuCANHandle_s *xCanHandle, uint8_t* pu8Buf, uint32_t u32Id, int i32RetCode, uint32_t u32BufNum);
IVEC_EcuCommonErr_e xECU_CANGetData(IVEC_EcuCANHandle_s *xCANhandle, IVEC_ECU_CANBuff_s *pxBuff); IVEC_EcuCommonErr_e xECU_CANGetData(IVEC_EcuCANHandle_s *xCanHandle, IVEC_ECU_CANBuff_s *pxBuff);
IVEC_EcuCommonErr_e xECU_CANReInit(IVEC_EcuCANHandle_s *xCANhandle); IVEC_EcuCommonErr_e xECU_CANReInit(IVEC_EcuCANHandle_s *xCANhandle);
IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCANhandle); IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCANhandle);

View File

@ -3,10 +3,10 @@
#include "../Core/Include/ivec_mcal_uart.h" #include "../Core/Include/ivec_mcal_uart.h"
/* Static CAN buffer for storing CAN message data */ /* Static CAN buffer for storing CAN message data */
static IVEC_ECU_CANBuff_s g_xCanBuffer[1024] = {0}; /* All the CAN ID, length, and data are stored in this array */ static IVEC_ECU_CANBuff_s __gprv_xCanBuffer[1024] = {0}; /* All the CAN ID, length, and data are stored in this array */
/* Queue for CAN messages */ /* Queue for CAN messages */
IVEC_ECU_CAN_QUEUE(g_xCanQueue_x, g_xCanBuffer); IVEC_ECU_CAN_QUEUE(g_xCanQueue, __gprv_xCanBuffer);
/** /**
* @brief Callback function for receiving CAN messages and storing them in a queue. * @brief Callback function for receiving CAN messages and storing them in a queue.
@ -23,7 +23,7 @@ IVEC_ECU_CAN_QUEUE(g_xCanQueue_x, g_xCanBuffer);
void vMCAL_CanReceiveFifoCallback(uint32_t u32Identifier, uint8_t* pu8Data, uint16_t u16DataLength) void vMCAL_CanReceiveFifoCallback(uint32_t u32Identifier, uint8_t* pu8Data, uint16_t u16DataLength)
{ {
/* Check if the CAN queue is full */ /* Check if the CAN queue is full */
if (!IVEC_ECU_CAN_IS_FULL(g_xCanQueue_x)) { if (!IVEC_ECU_CAN_IS_FULL(g_xCanQueue)) {
/* Store the received message in the queue from the interrupt */ /* Store the received message in the queue from the interrupt */
u8MCAL_StoreMsgFromISRToQueue(u32Identifier, pu8Data, u16DataLength); u8MCAL_StoreMsgFromISRToQueue(u32Identifier, pu8Data, u16DataLength);
} }
@ -41,56 +41,56 @@ void vMCAL_CanReceiveFifoCallback(uint32_t u32Identifier, uint8_t* pu8Data, uint
*/ */
uint8_t u8MCAL_StoreMsgFromISRToQueue(uint32_t ulId, uint8_t* pucData, uint8_t ucLen) uint8_t u8MCAL_StoreMsgFromISRToQueue(uint32_t u32UlId, uint8_t* pu8Data, uint8_t u8Len)
{ {
IVEC_ECU_CANBuff_s xBuff = {0}; IVEC_ECU_CANBuff_s xBuff = {0};
xBuff.ulId = ulId; xBuff.u32UlId = u32UlId;
xBuff.ucLength = ucLen; xBuff.u8Length = u8Len;
memcpy(xBuff.ucData, pucData, ucLen); memcpy(xBuff.u8Data, pu8Data, u8Len);
IVEC_ECU_CAN_ENQUEUE(g_xCanQueue_x, xBuff); // Ensure `ENQUEUE` is defined properly. IVEC_ECU_CAN_ENQUEUE(g_xCanQueue, xBuff); // Ensure `ENQUEUE` is defined properly.
return 0; return 0;
} }
/** /**
* @brief Writes data over CAN. * @brief Writes data over CAN.
* *
* This function writes a data buffer to the CAN bus using the provided CAN * This function s a data buffer to the CAN bus using the provided CAN
* handle and ID. It processes the buffer, applies a transformation (XOR with 0x0000), * handle and ID. It processes the buffer, applies a transformation (XOR with 0x0000),
* and attempts to send the data using `xMCAL_MCANTx`. * and attempts to send the data using `xMCAL_MCANTx`.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @param[in] pucBuf Pointer to the buffer containing data to be sent. * @param[in] pu8Buf Pointer to the buffer containing data to be sent.
* @param[in] u32Id CAN ID for the message. * @param[in] u32Id CAN ID for the message.
* @param[in] iRetCode Number of bytes to be written. * @param[in] i32RetCode Number of bytes to be written.
* @param[in] u32BufNum Buffer number to be used for transmission. * @param[in] u32BufNum Buffer number to be used for transmission.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_WRITE_FAIL`). * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_WRITE_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(IVEC_EcuCANHandle_s *xCANhandle, uint8_t* pucBuf, uint32_t u32Id, int iRetCode, uint32_t u32BufNum) IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(IVEC_EcuCANHandle_s *xCanHandle, uint8_t* pu8Buf, uint32_t u32Id, int i32RetCode, uint32_t u32BufNum)
{ {
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_WRITE_FAIL; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_WRITE_FAIL;
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
if (xCANhandle->__xCanHandle.__u8Init == 0) if (xCanHandle->__xCanHandle.__u8Init == 0)
{ {
l_xFuncStatus = commonMCAL_FAIL; l_eFuncStatus = commonMCAL_FAIL;
return l_xFuncStatus; return l_eFuncStatus;
} }
uint8_t u8RetCode; uint8_t u8RetCode;
uint16_t au16TxData[8] = {0}; // Define a buffer for the CAN payload data. uint16_t au16TxData[8] = {0}; // Define a buffer for the CAN payload data.
for (int i = 0; i < iRetCode; i++) { for (int u32Index = 0; u32Index < i32RetCode; u32Index++) {
au16TxData[i] = (uint16_t)(pucBuf[i] ^ 0x0000); au16TxData[u32Index] = (uint16_t)(pu8Buf[u32Index] ^ 0x0000);
} }
int iBytes = iRetCode; int i32Bytes = i32RetCode;
u8RetCode = xMCAL_MCANTx(&xCANhandle->__xCanHandle, u32Id, au16TxData, u32BufNum, iBytes); u8RetCode = xMCAL_MCANTx(&xCanHandle->__xCanHandle, u32Id, au16TxData, u32BufNum, i32Bytes);
if (u8RetCode == IVEC_MCAL_STATUS_SUCCESS) { if (u8RetCode == IVEC_MCAL_STATUS_SUCCESS) {
l_xFuncStatus = commonECU_SUCCESS; l_eFuncStatus = commonECU_SUCCESS;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
@ -99,30 +99,30 @@ IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(IVEC_EcuCANHandle_s *xCANhandle, uint8
* This function checks if the CAN queue is not empty and, if so, retrieves * This function checks if the CAN queue is not empty and, if so, retrieves
* the next CAN message from the queue and copies it into the provided buffer. * the next CAN message from the queue and copies it into the provided buffer.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @param[out] pxBuff Pointer to the buffer to store the retrieved CAN message. * @param[out] pxBuff Pointer to the buffer to store the retrieved CAN message.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_FAIL`). * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_CANGetData(IVEC_EcuCANHandle_s *xCANhandle, IVEC_ECU_CANBuff_s *pxBuff) IVEC_EcuCommonErr_e xECU_CANGetData(IVEC_EcuCANHandle_s *xCanHandle, IVEC_ECU_CANBuff_s *pxBuff)
{ {
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_FAIL; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_FAIL;
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
if (xCANhandle->__xCanHandle.__u8Init == 0) if (xCanHandle->__xCanHandle.__u8Init == 0)
{ {
l_xFuncStatus = commonMCAL_FAIL; l_eFuncStatus = commonMCAL_FAIL;
return l_xFuncStatus; return l_eFuncStatus;
} }
if (!IVEC_ECU_CAN_IS_EMPTY(g_xCanQueue_x)) { if (!IVEC_ECU_CAN_IS_EMPTY(g_xCanQueue)) {
IVEC_ECU_CANBuff_s xBuff = { 0x00 }; IVEC_ECU_CANBuff_s xBuff = { 0x00 };
IVEC_ECU_CAN_DEQUEUE(g_xCanQueue_x, xBuff); IVEC_ECU_CAN_DEQUEUE(g_xCanQueue, xBuff);
memcpy(pxBuff, &xBuff, sizeof(IVEC_ECU_CANBuff_s)); memcpy(pxBuff, &xBuff, sizeof(IVEC_ECU_CANBuff_s));
l_xFuncStatus = commonECU_SUCCESS; l_eFuncStatus = commonECU_SUCCESS;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
* @brief Reinitializes the CAN module. * @brief Reinitializes the CAN module.
@ -131,50 +131,44 @@ IVEC_EcuCommonErr_e xECU_CANGetData(IVEC_EcuCANHandle_s *xCANhandle, IVEC_ECU_CA
* ensuring the correct configuration of power, GPIO, and CAN settings. It handles * ensuring the correct configuration of power, GPIO, and CAN settings. It handles
* errors in the initialization and deinitialization process. * errors in the initialization and deinitialization process.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonECU_ALREADY_DEINIT`, * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonECU_ALREADY_DEINIT`,
* `commonECU_DEINIT_FAIL`, or `commonECU_INIT_FAIL`). * `commonECU_DEINIT_FAIL`, or `commonECU_INIT_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_CANReInit(IVEC_EcuCANHandle_s *xCANhandle) IVEC_EcuCommonErr_e xECU_CANReInit(IVEC_EcuCANHandle_s *xCanHandle)
{ {
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
assert(xCANhandle->pMCAN == CANFD0); if((xCanHandle->pMCAN != CANFD0) && (xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_500))
assert(xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_500);
if (xCANhandle->__xCanHandle.__u8Init == 0)
{ {
l_xFuncStatus = commonECU_ALREADY_DEINIT; return commonECU_INVALID_PARAM;
return l_xFuncStatus; }
if (xCanHandle->__xCanHandle.__u8Init == 0)
{
l_eFuncStatus = commonECU_ALREADY_DEINIT;
return l_eFuncStatus;
} }
IVEC_McalStatus_e l_xMCALStatus; IVEC_McalCommonErr_e l_eMCALStatus;
/* Deinitialize the MCAN module */ /* Deinitialize the MCAN module */
l_xMCALStatus = xMCAL_MCANDeInit(&xCANhandle->__xCanHandle); l_eMCALStatus = xECU_CANDeInit(&xCanHandle->__xCanHandle);
if (l_xMCALStatus != IVEC_MCAL_STATUS_SUCCESS) { if (l_eMCALStatus != commonMCAL_SUCCESS) {
l_xFuncStatus = commonECU_DEINIT_FAIL; l_eFuncStatus = commonECU_DEINIT_FAIL;
return l_xFuncStatus; return l_eFuncStatus;
} }
/* Enable power to the MCAN module */
DL_MCAN_enablePower(xCANhandle->pMCAN);
delay_cycles(POWER_STARTUP_DELAY);
/* Configure GPIO for CAN TX and RX */
DL_GPIO_initPeripheralOutputFunction(GPIO_MCAN0_IOMUX_CAN_TX, GPIO_MCAN0_IOMUX_CAN_TX_FUNC);
DL_GPIO_initPeripheralInputFunction(GPIO_MCAN0_IOMUX_CAN_RX, GPIO_MCAN0_IOMUX_CAN_RX_FUNC);
/* Reinitialize the MCAN module */ /* Reinitialize the MCAN module */
l_xMCALStatus = xMCAL_MCANInit(&xCANhandle->__xCanHandle); l_eMCALStatus = xECU_CANInit(xCanHandle);
/* Check if reinitialization was successful */ /* Check if reinitialization was successful */
if (l_xMCALStatus != IVEC_MCAL_STATUS_SUCCESS) { if (l_eMCALStatus != commonMCAL_SUCCESS) {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
@ -184,37 +178,47 @@ IVEC_EcuCommonErr_e xECU_CANReInit(IVEC_EcuCANHandle_s *xCANhandle)
* It ensures the correct speed configuration and performs the necessary hardware * It ensures the correct speed configuration and performs the necessary hardware
* initializations. * initializations.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_INIT_FAIL`). * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS` or `commonECU_INIT_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_CANInit(IVEC_EcuCANHandle_s *xCANhandle) IVEC_EcuCommonErr_e xECU_CANInit(IVEC_EcuCANHandle_s *xCanHandle)
{ {
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
assert(xCANhandle->pMCAN == CANFD0); if((xCanHandle->pMCAN != CANFD0) && (xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_500))
assert(xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_500);
if (xCANhandle->__xCanHandle.__u8Init == 1)
{ {
l_xFuncStatus = commonECU_ALREADY_INIT; return commonECU_INVALID_PARAM;
return l_xFuncStatus; }
if (xCanHandle->__xCanHandle.__u8Init == 1)
{
l_eFuncStatus = commonECU_ALREADY_INIT;
return l_eFuncStatus;
} }
xCANhandle->__xCanHandle.pMCAN = xCANhandle->pMCAN; xCanHandle->__xCanHandle.pMCAN = xCanHandle->pMCAN;
xCANhandle->__xCanHandle.u16Speed = xCANhandle->u16Speed; xCanHandle->__xCanHandle.u16Speed = xCanHandle->u16Speed;
IVEC_McalStatus_e eMcalStatus; xCanHandle->__xCanHandle.i32FilterCount = xCanHandle->i32FilterCount;
xCanHandle->__xCanHandle.i32MaskCount = xCanHandle->i32MaskCount;
for (int i = 0; i < ecuMAX_FILTERS_u8; i++) {
xCanHandle->__xCanHandle.u32FilterValues[i] = xCanHandle->u32FilterValues[i];
xCanHandle->__xCanHandle.u32MaskValues[i] = xCanHandle->u32MaskValues[i];
}
IVEC_McalCommonErr_e l_eMcalStatus;
/* Call MCAL initialization function */ /* Call MCAL initialization function */
eMcalStatus = xMCAL_MCANInit(&xCANhandle->__xCanHandle); l_eMcalStatus = xMCAL_MCANInit(&xCanHandle->__xCanHandle);
/* Check if initialization was successful */ /* Check if initialization was successful */
if (eMcalStatus != IVEC_MCAL_STATUS_SUCCESS) if (l_eMcalStatus != commonMCAL_SUCCESS)
{ {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
@ -224,34 +228,37 @@ IVEC_EcuCommonErr_e xECU_CANInit(IVEC_EcuCANHandle_s *xCANhandle)
* It ensures that the CAN module is properly deinitialized by calling the * It ensures that the CAN module is properly deinitialized by calling the
* MCAL deinitialization function and checks for errors during the process. * MCAL deinitialization function and checks for errors during the process.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonECU_ALREADY_DEINIT`, * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonECU_ALREADY_DEINIT`,
* or `commonECU_INIT_FAIL`). * or `commonECU_INIT_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_CANDeInit(IVEC_EcuCANHandle_s *xCANhandle) IVEC_EcuCommonErr_e xECU_CANDeInit(IVEC_EcuCANHandle_s *xCanHandle)
{ {
/* Assert that the MCAN module pointer is valid */ /* Assert that the MCAN module pointer is valid */
assert(xCANhandle->pMCAN == CANFD0); if(xCanHandle->pMCAN != CANFD0)
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
if (xCANhandle->__xCanHandle.__u8Init == 0)
{ {
l_xFuncStatus = commonECU_ALREADY_DEINIT; return commonECU_INVALID_PARAM;
return l_xFuncStatus; }
IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
if (xCanHandle->__xCanHandle.__u8Init == 0)
{
l_eFuncStatus = commonECU_ALREADY_DEINIT;
return l_eFuncStatus;
} }
IVEC_McalStatus_e eMcalStatus; IVEC_McalCommonErr_e l_eMcalStatus;
/* Call MCAL deinitialization function */ /* Call MCAL deinitialization function */
eMcalStatus = xMCAL_MCANDeInit(&xCANhandle->__xCanHandle); l_eMcalStatus = xMCAL_MCANDeInit(&xCanHandle->__xCanHandle);
/* Check if deinitialization was successful */ /* Check if deinitialization was successful */
if (eMcalStatus != IVEC_MCAL_STATUS_SUCCESS) if (l_eMcalStatus != commonMCAL_SUCCESS)
{ {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
@ -261,28 +268,34 @@ IVEC_EcuCommonErr_e xECU_CANDeInit(IVEC_EcuCANHandle_s *xCANhandle)
* initialized, it retrieves the error status. If an error is detected, it attempts * initialized, it retrieves the error status. If an error is detected, it attempts
* to reinitialize the CAN module. * to reinitialize the CAN module.
* *
* @param[in] xCANhandle Pointer to the CAN handle structure. * @param[in] xCanHandle Pointer to the CAN handle structure.
* @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonMCAL_FAIL`). * @return IVEC_EcuCommonErr_e Status of the operation (`commonECU_SUCCESS`, `commonMCAL_FAIL`).
*/ */
IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCANhandle) IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCanHandle)
{ {
/* Ensure that the MCAN instance is CANFD0 */ /* Ensure that the MCAN instance is CANFD0 */
assert(xCANhandle->pMCAN == CANFD0); if(xCanHandle->pMCAN != CANFD0)
assert(xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCANhandle->u16Speed == IVEC_ECU_CAN_SPEED_500);
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
if (xCANhandle->__xCanHandle.__u8Init == 0)
{ {
l_xFuncStatus = commonMCAL_FAIL; return commonECU_INVALID_PARAM;
return l_xFuncStatus;
} }
char cErrorString[32] = {0}; if((xCanHandle->pMCAN != CANFD0) && (xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_250 || xCanHandle->u16Speed == IVEC_ECU_CAN_SPEED_500))
{
return commonECU_INVALID_PARAM;
}
IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
if (xCanHandle->__xCanHandle.__u8Init == 0)
{
l_eFuncStatus = commonMCAL_FAIL;
return l_eFuncStatus;
}
int8_t l_i8ErrorString[32] = {0};
/* Retrieve the MCAN error status */ /* Retrieve the MCAN error status */
if (xMCAL_MCANGetErrorStatus(&xCANhandle->__xCanHandle, cErrorString) == IVEC_MCAL_STATUS_ERROR) if (xMCAL_MCANGetErrorStatus(&xCanHandle->__xCanHandle, l_i8ErrorString) == commonMCAL_FAIL)
{ {
/* Reinitialize CAN if an error is detected */ /* Reinitialize CAN if an error is detected */
l_xFuncStatus = xECU_CANReInit(xCANhandle); l_eFuncStatus = xECU_CANReInit(xCanHandle);
} }
return l_xFuncStatus; return l_eFuncStatus;
} }

View File

@ -10,44 +10,44 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define IVEC_ECU_UART_MAX_PACKET_LENGTH 32/*!<Maximum length of packet that can be received*/ #define ecuUART_MAX_PACKET_LENGTH_u8 32/*!<Maximum length of packet that can be received*/
#define IVEC_ECU_UART_PKT_HEADER 7/*!<Protocol headers*/ #define ecuUART_PKT_HEADER_u8 7/*!<Protocol headers*/
#define IVEC_ECU_UART_PKT_HEADER_FOOTER 9/*!<Protocol headers+footers*/ #define ecuUART_PKT_HEADER_FOOTER_u8 9/*!<Protocol headers+footers*/
#endif #endif
#define IVEC_ECU_UART_GET_PACKET_SIZE(x) (x + IVEC_ECU_UART_PKT_HEADER_FOOTER)/*!<Complete packet size*/ #define ecuUART_GET_PACKET_SIZE(x) (x + ecuUART_PKT_HEADER_FOOTER_u8)/*!<Complete packet size*/
#define IVEC_ECU_UART_PACKET_SUCCESS 0/*!<Success*/ #define ecuUART_PACKET_SUCCESS_u8 0/*!<Success*/
#define IVEC_ECU_UART_PACKET_FAIL -1/*!<Error*/ #define ecuUART_PACKET_FAIL_i8 -1/*!<Error*/
/*Private Variables*/ /*Private Variables*/
typedef int IVEC_ECU_UartPacketRetCode_e;/*SERVICE_SUCESS or SERVICE_FAIL*/ typedef int IVEC_ECU_UartPacketRetCode_e;/*SERVICE_SUCESS or SERVICE_FAIL*/
typedef enum
{ typedef enum {
eEcuUartBaudAuto = 0, IVEC_ECU_UART_BAUD_AUTO = 0,
eEcuUartBaud2400 = 2400, IVEC_ECU_UART_BAUD_2400 = 2400,
eEcuUartBaud4800 = 4800, IVEC_ECU_UART_BAUD_4800 = 4800,
eEcuUartBaud9600 = 9600, IVEC_ECU_UART_BAUD_9600 = 9600,
eEcuUartBaud14400 = 14400, IVEC_ECU_UART_BAUD_14400 = 14400,
eEcuUartBaud19200 = 19200, IVEC_ECU_UART_BAUD_19200 = 19200,
eEcuUartBaud28800 = 28800, IVEC_ECU_UART_BAUD_28800 = 28800,
eEcuUartBaud33600 = 33600, IVEC_ECU_UART_BAUD_33600 = 33600,
eEcuUartBaud38400 = 38400, IVEC_ECU_UART_BAUD_38400 = 38400,
eEcuUartBaud57600 = 57600, IVEC_ECU_UART_BAUD_57600 = 57600,
eEcuUartBaud115200 = 115200, IVEC_ECU_UART_BAUD_115200 = 115200,
eEcuUartBaud230400 = 230400, IVEC_ECU_UART_BAUD_230400 = 230400,
eEcuUartBaud460800 = 460800, IVEC_ECU_UART_BAUD_460800 = 460800,
eEcuUartBaud921600 = 921600, IVEC_ECU_UART_BAUD_921600 = 921600,
eEcuUartBaud1000000 = 1000000, IVEC_ECU_UART_BAUD_1000000 = 1000000,
eEcuUartBaud1843200 = 1843200, IVEC_ECU_UART_BAUD_1843200 = 1843200,
eEcuUartBaud2000000 = 2000000, IVEC_ECU_UART_BAUD_2000000 = 2000000,
eEcuUartBaud2100000 = 2100000, IVEC_ECU_UART_BAUD_2100000 = 2100000,
eEcuUartBaud3686400 = 3686400, IVEC_ECU_UART_BAUD_3686400 = 3686400,
eEcuUartBaud4000000 = 4000000, IVEC_ECU_UART_BAUD_4000000 = 4000000,
eEcuUartBaud4468750 = 4468750 IVEC_ECU_UART_BAUD_4468750 = 4468750
} eEcuUartBaudRate; } IVEC_EcuUartBaudRate_e;
typedef enum typedef enum
@ -67,26 +67,26 @@ typedef enum
typedef struct typedef struct
{ {
xMcalUartHandle __xUartHandle; IVEC_McalUartHandle_s __xUartHandle;
IVEC_ECU_UartPortNumber_e eUartPortNumber; IVEC_ECU_UartPortNumber_e eUartPortNumber;
volatile uint8_t* u8Qbuffer; volatile uint8_t* u8Qbuffer;
uint16_t u16QbufSize; uint16_t u16QbufSize;
uint16_t u16len; uint16_t u16len;
eEcuUartBaudRate u32BaudRate; IVEC_EcuUartBaudRate_e u32BaudRate;
void (*pvUartRecvCallback)(IVEC_ECU_UartPortNumber_e, IVEC_ECU_UartEvent_e , char *, uint32_t); void (*pvUartRecvCallback)(IVEC_ECU_UartPortNumber_e, IVEC_ECU_UartEvent_e , char *, uint32_t);
} IVEC_ECU_UartHandle_s; } IVEC_EcuUartHandle_s;
/*=========================================================================== /*===========================================================================
* Functions declaration * Functions declaration
===========================================================================*/ ===========================================================================*/
IVEC_EcuCommonErr_e xECU_UartInit(IVEC_ECU_UartHandle_s* uartHandle); IVEC_EcuCommonErr_e xECU_UartInit(IVEC_EcuUartHandle_s* pxUartHandle);
IVEC_EcuCommonErr_e xECU_UartDeinit(IVEC_ECU_UartHandle_s *uartHandle); IVEC_EcuCommonErr_e xECU_UartDeinit(IVEC_EcuUartHandle_s *pxUartHandle);
IVEC_EcuCommonErr_e xECU_UartReinit(IVEC_ECU_UartHandle_s *uartHandle); IVEC_EcuCommonErr_e xECU_UartReinit(IVEC_EcuUartHandle_s *pxUartHandle);
IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint16_t len); IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len);
IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint16_t len, uint16_t timeout); IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len, uint16_t u16Timeout);
IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* data, uint8_t dlc, uint32_t id); IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint8_t u8Dlc, uint32_t u32Id);
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint32_t *id); IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id);
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_ECU_UartHandle_s* uartHandle, uint8_t* buffer, uint32_t *id); IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id);
int32_t iECU_UartInitiateTransmit(IVEC_ECU_UartHandle_s* uartHandle, uint32_t id, uint8_t *data, uint8_t len); int32_t iECU_UartInitiateTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint32_t u32Id, uint8_t* pu8Data, uint8_t u8Len);

View File

@ -6,7 +6,7 @@
//#define NFC_UART_BUFFER_MAX_SIZE 256 //#define NFC_UART_BUFFER_MAX_SIZE 256
#define DATA_PACKET_TIMEOUT_MS 300 #define DATA_PACKET_TIMEOUT_MS 300
volatile static CmplxFifoQueueHandle_s __gprv_EcuUartResponseQueue[IVEC_MCAL_UART_MAX_PORT] = { 0 }; volatile static CmplxFifoQueueHandle_s __gprv_xUartResponseQueue[IVEC_ECU_UART_PORT_MAX] = { 0 };
//static uint8_t __gprv_u8NFCUartDataBuffer[NFC_UART_BUFFER_MAX_SIZE]; //static uint8_t __gprv_u8NFCUartDataBuffer[NFC_UART_BUFFER_MAX_SIZE];
/** /**
@ -17,22 +17,22 @@ volatile static CmplxFifoQueueHandle_s __gprv_EcuUartResponseQueue[IVEC_MCAL_UAR
* *
* @param[in] uartPort The UART port number where the data was received. * @param[in] uartPort The UART port number where the data was received.
* @param[in] eventType The event type indicating the status of the UART reception. * @param[in] eventType The event type indicating the status of the UART reception.
* @param[in] pucBuffer Pointer to the received data buffer. * @param[in] pu8Buffer Pointer to the received data buffer.
* @param[in] u32Size Size of the received data buffer. * @param[in] u32Size Size of the received data buffer.
*/ */
static void __prvEcu_CANOverUartMsgCallback(eMcalUartPortNumber uartPort, IVEC_ECU_UartEvent_e eventType, char* pucBuffer, uint32_t u32Size) static void __prv_EcuCanOverUartMsgCallback(IVEC_McalUartPort_e eUartPort, IVEC_ECU_UartEvent_e eEventType,int8_t* pu8Buffer, uint32_t u32Size)
{ {
switch (uartPort) switch (eUartPort)
{ {
case eMcalUartPort2: case IVEC_MCAL_UART_PORT_2:
if (eventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) { if (eEventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) {
u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[IVEC_ECU_UART_PORT2], pucBuffer, u32Size); u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[IVEC_ECU_UART_PORT2], pu8Buffer, u32Size);
} }
break; break;
case eMcalUartPort3: case IVEC_MCAL_UART_PORT_3:
if (eventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) { if (eEventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) {
u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[IVEC_ECU_UART_PORT3], pucBuffer, u32Size); u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[IVEC_ECU_UART_PORT3], pu8Buffer, u32Size);
} }
break; break;
default: default:
@ -52,17 +52,17 @@ static void __prvEcu_CANOverUartMsgCallback(eMcalUartPortNumber uartPort, IVEC_E
* The checksum consists of two bytes. * The checksum consists of two bytes.
*/ */
static void _prvECU_CalculateChecksum(uint8_t* pkt, int len, uint8_t* checksum) { static void _prv_EcuCalculateChecksum(uint8_t* pkt, int i32Len, uint8_t* u8CheckSum) {
uint8_t checksum_a = 0, checksum_b = 0; uint8_t l_u8CheckSumFirst = 0, l_u8CheckSumSecond = 0;
/* Incremented to ignore Sync data */ /* Incremented to ignore Sync data */
for (int i = 2; i < len - 2; i++) { for (int u32Index = 2; u32Index < i32Len - 2; u32Index++) {
checksum_a += pkt[i]; l_u8CheckSumFirst += pkt[u32Index];
checksum_b += checksum_a; l_u8CheckSumSecond += l_u8CheckSumFirst;
} }
checksum_a &= 0xFF; l_u8CheckSumFirst &= 0xFF;
checksum_b &= 0xFF; l_u8CheckSumSecond &= 0xFF;
checksum[0] = checksum_a; u8CheckSum[0] = l_u8CheckSumFirst;
checksum[1] = checksum_b; u8CheckSum[1] = l_u8CheckSumSecond;
} }
/** /**
@ -73,7 +73,7 @@ static void _prvECU_CalculateChecksum(uint8_t* pkt, int len, uint8_t* checksum)
* specified UART port. It also sets the UART parameters such as baud rate, * specified UART port. It also sets the UART parameters such as baud rate,
* flow control, data bits, stop bits, and parity bits. * flow control, data bits, stop bits, and parity bits.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure containing * @param[in] pxUartHandle Pointer to the UART handle structure containing
* UART port configuration and queue settings. * UART port configuration and queue settings.
* *
* @return IVEC_EcuCommonErr_e Status of the initialization process: * @return IVEC_EcuCommonErr_e Status of the initialization process:
@ -85,72 +85,72 @@ static void _prvECU_CalculateChecksum(uint8_t* pkt, int len, uint8_t* checksum)
* FIFO queue for receiving data. * FIFO queue for receiving data.
* - Initializes the UART configuration with provided parameters (baud rate, flow control, * - Initializes the UART configuration with provided parameters (baud rate, flow control,
* data bits, stop bits, and parity). * data bits, stop bits, and parity).
* - Sets the UART receive callback to `__prvEcu_CANOverUartMsgCallback`. * - Sets the UART receive callback to `__prv_EcuCanOverUartMsgCallback`.
* - If the initialization of the FIFO queue or UART fails, the function returns * - If the initialization of the FIFO queue or UART fails, the function returns
* `commonECU_INIT_FAIL`. * `commonECU_INIT_FAIL`.
*/ */
IVEC_EcuCommonErr_e xECU_UartInit(IVEC_ECU_UartHandle_s* prvUartHandle) IVEC_EcuCommonErr_e xECU_UartInit(IVEC_EcuUartHandle_s* pxUartHandle)
{ {
if (prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return commonMCAL_INIT_FAIL; return commonMCAL_INIT_FAIL;
} }
IVEC_ECU_FUNC_ENTRY(LOG_STRING); IVEC_ECU_FUNC_ENTRY(LOG_STRING);
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
uint8_t l_i32Ret = 0; uint8_t l_i32Ret = 0;
IVEC_ECU_LOG(LOG_STRING, "UART Initializing Queue"); IVEC_ECU_LOG(LOG_STRING, "UART Initializing Queue");
if (prvUartHandle->eUartPortNumber < IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle->eUartPortNumber < IVEC_ECU_UART_PORT_MAX)
{ {
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].i32ElementSize = sizeof(uint8_t); __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32ElementSize = sizeof(uint8_t);
switch (prvUartHandle->eUartPortNumber) switch (pxUartHandle->eUartPortNumber)
{ {
case IVEC_ECU_UART_PORT2: case IVEC_ECU_UART_PORT2:
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].i32TotalElements = prvUartHandle->u16QbufSize; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32TotalElements = pxUartHandle->u16QbufSize;
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = prvUartHandle->u8Qbuffer; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = pxUartHandle->u8Qbuffer;
break; break;
case IVEC_ECU_UART_PORT3: case IVEC_ECU_UART_PORT3:
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].i32TotalElements = prvUartHandle->u16QbufSize; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32TotalElements = pxUartHandle->u16QbufSize;
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = prvUartHandle->u8Qbuffer; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = pxUartHandle->u8Qbuffer;
break; break;
default: default:
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = NULL; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = NULL;
break; break;
} }
__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber].i32QueueType = FIXED_ELEMENT_SIZE_QUEUE; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32QueueType = FIXED_ELEMENT_SIZE_QUEUE;
l_i32Ret = u8CMPLX_FifoQueueInit((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber]); l_i32Ret = u8CMPLX_FifoQueueInit((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber]);
} }
if (l_i32Ret == 0) if (l_i32Ret == 0)
{ {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
goto exit; goto exit;
} }
IVEC_ECU_LOG(LOG_STRING, "Initializing UART"); IVEC_ECU_LOG(LOG_STRING, "Initializing UART");
prvUartHandle->__xUartHandle.pvUartRecvCallback = __prvEcu_CANOverUartMsgCallback; pxUartHandle->__xUartHandle.pvUartRecvCallback = __prv_EcuCanOverUartMsgCallback;
prvUartHandle->__xUartHandle.xUartConfig.eUartBaudrate = prvUartHandle->u32BaudRate; pxUartHandle->__xUartHandle.xUartConfig.eUartBaudrate = pxUartHandle->u32BaudRate;
prvUartHandle->__xUartHandle.eUartPortNumber = prvUartHandle->eUartPortNumber; pxUartHandle->__xUartHandle.eUartPortNumber = pxUartHandle->eUartPortNumber;
prvUartHandle->__xUartHandle.xUartConfig.eUartFlowCtrl = eMcalUartFcNone; pxUartHandle->__xUartHandle.xUartConfig.eUartFlowCtrl = IVEC_MCAL_UART_FC_NONE;
prvUartHandle->__xUartHandle.xUartConfig.eUartDataBit = eMcalUartDataBit8; pxUartHandle->__xUartHandle.xUartConfig.eUartDataBit = IVEC_MCAL_UART_DATA_BIT_8;
prvUartHandle->__xUartHandle.xUartConfig.eUartStopBit = eMcalUartStopBit1; pxUartHandle->__xUartHandle.xUartConfig.eUartStopBit = IVEC_MCAL_UART_STOP_BIT_1;
prvUartHandle->__xUartHandle.xUartConfig.eUartParityBit = eMcalUartParityNone; pxUartHandle->__xUartHandle.xUartConfig.eUartParityBit = IVEC_MCAL_UART_PARITY_NONE;
l_i32Ret = xMCAL_UartInit(&prvUartHandle->__xUartHandle); l_i32Ret = xMCAL_UartInit(&pxUartHandle->__xUartHandle);
if (l_i32Ret != 0) if (l_i32Ret != 0)
{ {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
goto exit; goto exit;
} }
exit: exit:
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0); IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
* @brief Deinitializes the UART interface. * @brief Deinitializes the UART interface.
@ -159,7 +159,7 @@ exit:
* queue and calling the `xMCAL_UartDeInit` function. If the UART port number is invalid * queue and calling the `xMCAL_UartDeInit` function. If the UART port number is invalid
* or the UART handle is NULL, it returns an initialization failure status. * or the UART handle is NULL, it returns an initialization failure status.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure to be deinitialized. * @param[in] pxUartHandle Pointer to the UART handle structure to be deinitialized.
* *
* @return IVEC_EcuCommonErr_e Status of the deinitialization: * @return IVEC_EcuCommonErr_e Status of the deinitialization:
* - `commonECU_SUCCESS`: Deinitialization was successful. * - `commonECU_SUCCESS`: Deinitialization was successful.
@ -174,38 +174,38 @@ exit:
* - If successful, it flushes the UART response queue. * - If successful, it flushes the UART response queue.
*/ */
IVEC_EcuCommonErr_e xECU_UartDeinit(IVEC_ECU_UartHandle_s* prvUartHandle) IVEC_EcuCommonErr_e xECU_UartDeinit(IVEC_EcuUartHandle_s* pxUartHandle)
{ {
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return commonECU_INIT_FAIL; return commonECU_INIT_FAIL;
} }
IVEC_ECU_FUNC_ENTRY(LOG_STRING); IVEC_ECU_FUNC_ENTRY(LOG_STRING);
uint8_t l_i32Ret; uint8_t l_i32Ret;
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
if (prvUartHandle == NULL) if (pxUartHandle == NULL)
{ {
l_xFuncStatus = commonECU_ALREADY_DEINIT; l_eFuncStatus = commonECU_ALREADY_DEINIT;
goto exit; goto exit;
} }
IVEC_ECU_LOG(LOG_STRING, "Deinitializing UART"); IVEC_ECU_LOG(LOG_STRING, "Deinitializing UART");
l_i32Ret = xMCAL_UartDeInit(&prvUartHandle->__xUartHandle); l_i32Ret = xMCAL_UartDeInit(&pxUartHandle->__xUartHandle);
if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS) if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
{ {
l_xFuncStatus = commonECU_DEINIT_FAIL; l_eFuncStatus = commonECU_DEINIT_FAIL;
goto exit; goto exit;
} }
if (prvUartHandle->eUartPortNumber < IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle->eUartPortNumber < IVEC_ECU_UART_PORT_MAX)
{ {
vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber]); vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber]);
} }
exit: exit:
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0); IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
* @brief Reinitializes the UART interface. * @brief Reinitializes the UART interface.
@ -213,7 +213,7 @@ exit:
* This function first deinitializes the UART interface using `xECU_UartDeinit`, * This function first deinitializes the UART interface using `xECU_UartDeinit`,
* and then reinitializes it with the new configuration using `xECU_UartInit`. * and then reinitializes it with the new configuration using `xECU_UartInit`.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure to be reinitialized. * @param[in] pxUartHandle Pointer to the UART handle structure to be reinitialized.
* *
* @return IVEC_EcuCommonErr_e Status of the reinitialization: * @return IVEC_EcuCommonErr_e Status of the reinitialization:
* - `commonECU_SUCCESS`: Reinitialization was successful. * - `commonECU_SUCCESS`: Reinitialization was successful.
@ -226,32 +226,32 @@ exit:
* - If any step fails, the function returns an appropriate error status. * - If any step fails, the function returns an appropriate error status.
*/ */
IVEC_EcuCommonErr_e xECU_UartReinit(IVEC_ECU_UartHandle_s* prvUartHandle) IVEC_EcuCommonErr_e xECU_UartReinit(IVEC_EcuUartHandle_s* pxUartHandle)
{ {
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return commonECU_INIT_FAIL; return commonECU_INIT_FAIL;
} }
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
uint8_t l_i32Ret; uint8_t l_i32Ret;
// Deinitialize UART // Deinitialize UART
l_i32Ret = xECU_UartDeinit(prvUartHandle); l_i32Ret = xECU_UartDeinit(pxUartHandle);
if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS) if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
{ {
l_xFuncStatus = commonECU_DEINIT_FAIL; l_eFuncStatus = commonECU_DEINIT_FAIL;
goto exit; goto exit;
} }
// Reinitialize UART with the new speed // Reinitialize UART with the new speed
l_i32Ret = xECU_UartInit(prvUartHandle); l_i32Ret = xECU_UartInit(pxUartHandle);
if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS) if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
{ {
l_xFuncStatus = commonECU_INIT_FAIL; l_eFuncStatus = commonECU_INIT_FAIL;
} }
exit: exit:
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
* @brief Transmits data over UART. * @brief Transmits data over UART.
@ -259,15 +259,15 @@ exit:
* This function is a placeholder and currently does not transmit data. * This function is a placeholder and currently does not transmit data.
* It returns a failure status as the implementation is not provided. * It returns a failure status as the implementation is not provided.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure. * @param[in] pxUartHandle Pointer to the UART handle structure.
* @param[in] pucBuffer Pointer to the data buffer to be transmitted. * @param[in] pu8Buffer Pointer to the data buffer to be transmitted.
* @param[in] len Length of the data to be transmitted. * @param[in] len Length of the data to be transmitted.
* *
* @return IVEC_EcuCommonErr_e Status of the transmission: * @return IVEC_EcuCommonErr_e Status of the transmission:
* - `commonECU_FAIL`: Transmission is not implemented. * - `commonECU_FAIL`: Transmission is not implemented.
*/ */
IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len) IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len)
{ {
return commonECU_FAIL; return commonECU_FAIL;
} }
@ -276,7 +276,7 @@ IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_ECU_UartHandle_s* prvUartHandle, uint
* *
* This function clears the response queue associated with the specified UART port. * This function clears the response queue associated with the specified UART port.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure. * @param[in] pxUartHandle Pointer to the UART handle structure.
* *
* @return IVEC_EcuCommonErr_e Status of the flush operation: * @return IVEC_EcuCommonErr_e Status of the flush operation:
* - `commonECU_SUCCESS`: Queue was flushed successfully. * - `commonECU_SUCCESS`: Queue was flushed successfully.
@ -288,13 +288,13 @@ IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_ECU_UartHandle_s* prvUartHandle, uint
*/ */
IVEC_EcuCommonErr_e xECU_UartFlush(IVEC_ECU_UartHandle_s* prvUartHandle) IVEC_EcuCommonErr_e xECU_UartFlush(IVEC_EcuUartHandle_s* pxUartHandle)
{ {
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return commonECU_FAIL; return commonECU_FAIL;
} }
vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber]); vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber]);
return commonECU_SUCCESS; return commonECU_SUCCESS;
} }
/** /**
@ -304,8 +304,8 @@ IVEC_EcuCommonErr_e xECU_UartFlush(IVEC_ECU_UartHandle_s* prvUartHandle)
* If the data is available, it copies the data into the provided buffer. If data is not available * If the data is available, it copies the data into the provided buffer. If data is not available
* within the timeout, it returns an error. * within the timeout, it returns an error.
* *
* @param[in] prvUartHandle Pointer to the UART handle structure. * @param[in] pxUartHandle Pointer to the UART handle structure.
* @param[out] pucBuffer Pointer to the buffer where the received data will be stored. * @param[out] pu8Buffer Pointer to the buffer where the received data will be stored.
* @param[in] len Length of the data to be received. * @param[in] len Length of the data to be received.
* @param[in] timeout Timeout period in milliseconds. * @param[in] timeout Timeout period in milliseconds.
* *
@ -321,39 +321,39 @@ IVEC_EcuCommonErr_e xECU_UartFlush(IVEC_ECU_UartHandle_s* prvUartHandle)
* - Interrupts are disabled during the dequeue operation to ensure data integrity. * - Interrupts are disabled during the dequeue operation to ensure data integrity.
*/ */
IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout) IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len, uint16_t u16Timeout)
{ {
IVEC_ECU_FUNC_ENTRY(LOG_STRING); IVEC_ECU_FUNC_ENTRY(LOG_STRING);
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS;
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
l_xFuncStatus = commonECU_INVALID_PARAM; l_eFuncStatus = commonECU_INVALID_PARAM;
goto exit; goto exit;
} }
uint16_t l_u16Len = 0; uint16_t l_u16Len = 0;
uint32_t u32CommTimestamp = i32MCAL_GetTicks(); uint32_t u32CommTimestamp = i32MCAL_getTicks();
while(((i32MCAL_GetTicks() - u32CommTimestamp) <= timeout+1) && (l_u16Len < len)) while(((i32MCAL_getTicks() - u32CommTimestamp) <= u16Timeout+1) && (l_u16Len < u16Len))
{ {
l_u16Len = i32CMPLX_FifoCounts((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber]); l_u16Len = i32CMPLX_FifoCounts((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber]);
} }
if (l_u16Len < len) if (l_u16Len < u16Len)
{ {
l_xFuncStatus = commonECU_READ_FAIL; l_eFuncStatus = commonECU_READ_FAIL;
goto exit; goto exit;
} }
else else
{ {
int i32Len = 0; int i32Len = 0;
__disable_irq();//disabling interrupt to avoid enqueing while dequeing __disable_irq();//disabling interrupt to avoid enqueing while dequeing
for(int i=0;i<len;i++) for(int u32Index=0;u32Index<u16Len;u32Index++)
{ {
u8CMPLX_FifoDequeue((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber], &pucBuffer[i], &i32Len, 0); u8CMPLX_FifoDequeue((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber], &pu8Buffer[u32Index], &i32Len, 0);
} }
__enable_irq(); __enable_irq();
@ -361,48 +361,9 @@ IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_ECU_UartHandle_s* prvUartHandle, uint8
exit: exit:
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0); IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
return l_xFuncStatus; return l_eFuncStatus;
} }
//IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout)
//{
// IVEC_ECU_FUNC_ENTRY(LOG_STRING);
//
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
//
// // Validate parameters
// if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT)
// {
// l_xFuncStatus = commonECU_INVALID_PARAM;
// goto exit;
// }
//
// uint8_t ijk = 0;
// int l_u32Len = 0;
// uint32_t u32CommTimestamp = i32MCAL_GetTicks();
//
// // Loop until timeout or buffer is filled
// while (((i32MCAL_GetTicks() - u32CommTimestamp) <= timeout + 1) && (ijk < len))
// {
// if (!u8CMPLX_FifoQueueEmpty((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber]))
// {
// if (u8CMPLX_FifoDequeue((CmplxFifoQueueHandle_s*)&__gprv_EcuUartResponseQueue[prvUartHandle->eUartPortNumber], &pucBuffer[ijk], &l_u32Len, 0) == 1)
// ijk++;
// }
// }
//
// // Check if all requested data was received
// if (ijk != len)
// {
// l_xFuncStatus = commonECU_READ_FAIL;
// goto exit;
// }
//
//exit:
// IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
// return l_xFuncStatus;
//}
/** /**
* @brief Reads and validates CAN data length over UART. * @brief Reads and validates CAN data length over UART.
@ -411,25 +372,25 @@ IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_ECU_UartHandle_s* prvUartHandle, uint8
* the packet length, and verifies the checksum. It handles various conditions and * the packet length, and verifies the checksum. It handles various conditions and
* returns the packet length or failure code. * returns the packet length or failure code.
* *
* @param[in] prvUartHandle Pointer to the UART handle for communication. * @param[in] pxUartHandle Pointer to the UART handle for communication.
* @param[out] pucBuf Buffer to store the received data. * @param[out] pu8Buf Buffer to store the received data.
* @param[out] ulId Pointer to store the extracted CAN ID. * @param[out] u32Id Pointer to store the extracted CAN ID.
* *
* @return The packet length on success, or a failure code: * @return The packet length on success, or a failure code:
* - `commonECU_READ_FAIL` if the read operation or checksum validation fails. * - `commonECU_READ_FAIL` if the read operation or checksum validation fails.
* - `IVEC_ECU_UART_PACKET_FAIL` if the packet synchronization is lost. * - `ecuUART_PACKET_FAIL_i8` if the packet synchronization is lost.
*/ */
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t* ulId) IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id)
{ {
int PktLen = commonECU_READ_FAIL; int PktLen = commonECU_READ_FAIL;
if ((xECU_UartGetData(prvUartHandle, (uint8_t*)&pucBuf[0], 1, 0) == commonECU_SUCCESS)) if ((xECU_UartGetData(pxUartHandle, (uint8_t*)&pu8Buf[0], 1, 0) == commonECU_SUCCESS))
{ {
if (pucBuf[0] == 0xB5) if (pu8Buf[0] == 0xB5)
{ {
if (xECU_UartGetData(prvUartHandle, (uint8_t*)&pucBuf[1], 1, 5) == commonECU_SUCCESS) { if (xECU_UartGetData(pxUartHandle, (uint8_t*)&pu8Buf[1], 1, 5) == commonECU_SUCCESS) {
if (pucBuf[1] != 0x62) { if (pu8Buf[1] != 0x62) {
PktLen = commonECU_READ_FAIL; PktLen = commonECU_READ_FAIL;
goto EXIT; // 0x62 not found, OUT OF SYNC goto EXIT; // 0x62 not found, OUT OF SYNC
} }
@ -439,25 +400,25 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_ECU_UartHandle
PktLen = commonECU_READ_FAIL; PktLen = commonECU_READ_FAIL;
goto EXIT; goto EXIT;
} }
if (xECU_UartGetData(prvUartHandle, (uint8_t*)&pucBuf[2], 5, DATA_PACKET_TIMEOUT_MS) != commonECU_SUCCESS) { if (xECU_UartGetData(pxUartHandle, (uint8_t*)&pu8Buf[2], 5, DATA_PACKET_TIMEOUT_MS) != commonECU_SUCCESS) {
PktLen = commonECU_READ_FAIL; PktLen = commonECU_READ_FAIL;
goto EXIT; goto EXIT;
} }
*(ulId) = (uint32_t)((pucBuf[6] << 24) | (pucBuf[5] << 16) | (pucBuf[4] << 8) | (pucBuf[3])); *(u32Id) = (uint32_t)((pu8Buf[6] << 24) | (pu8Buf[5] << 16) | (pu8Buf[4] << 8) | (pu8Buf[3]));
uint8_t l_ucTempLen = pucBuf[2]; uint8_t l_u8TempLen = pu8Buf[2];
PktLen = IVEC_ECU_UART_PKT_HEADER_FOOTER + l_ucTempLen; PktLen = ecuUART_PKT_HEADER_FOOTER_u8 + l_u8TempLen;
if (xECU_UartGetData(prvUartHandle, (uint8_t*)&pucBuf[IVEC_ECU_UART_PKT_HEADER], (uint32_t)(PktLen - IVEC_ECU_UART_PKT_HEADER), DATA_PACKET_TIMEOUT_MS) != commonECU_SUCCESS) if (xECU_UartGetData(pxUartHandle, (uint8_t*)&pu8Buf[ecuUART_PKT_HEADER_u8], (uint32_t)(PktLen - ecuUART_PKT_HEADER_u8), DATA_PACKET_TIMEOUT_MS) != commonECU_SUCCESS)
{ {
PktLen = commonECU_READ_FAIL; PktLen = commonECU_READ_FAIL;
goto EXIT; goto EXIT;
} }
uint8_t checksum[2]; uint8_t l_u8CheckSum[2];
_prvECU_CalculateChecksum(pucBuf, PktLen, checksum); _prv_EcuCalculateChecksum(pu8Buf, PktLen, l_u8CheckSum);
/* TODO: (Python Script) Sometimes fails due to bad checksum */ /* TODO: (Python Script) Sometimes fails due to bad checksum */
if ((checksum[0] == pucBuf[PktLen - 2]) && (checksum[1] == pucBuf[PktLen - 1])) { if ((l_u8CheckSum[0] == pu8Buf[PktLen - 2]) && (l_u8CheckSum[1] == pu8Buf[PktLen - 1])) {
PktLen -= IVEC_ECU_UART_PKT_HEADER_FOOTER; PktLen -= ecuUART_PKT_HEADER_FOOTER_u8;
} }
else else
{ {
@ -468,7 +429,7 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_ECU_UartHandle
else else
{ {
// COM_FlushBuffer(); // COM_FlushBuffer();
PktLen = IVEC_ECU_UART_PACKET_FAIL; PktLen = ecuUART_PACKET_FAIL_i8;
} }
} }
EXIT: EXIT:
@ -481,23 +442,23 @@ EXIT:
* length over UART by calling `xECU_UartReadCANDataLenOverUART`. * length over UART by calling `xECU_UartReadCANDataLenOverUART`.
* It returns the result based on the outcome of that function. * It returns the result based on the outcome of that function.
* *
* @param[in] prvUartHandle Pointer to the UART handle for communication. * @param[in] pxUartHandle Pointer to the UART handle for communication.
* @param[out] pucBuf Buffer to store the received data. * @param[out] pu8Buf Buffer to store the received data.
* @param[out] ulId Pointer to store the extracted CAN ID. * @param[out] u32Id Pointer to store the extracted CAN ID.
* *
* @return The result of reading the CAN data over UART. * @return The result of reading the CAN data over UART.
* - `IVEC_ECU_UART_PACKET_FAIL` if the UART handle is invalid or the * - `ecuUART_PACKET_FAIL_i8` if the UART handle is invalid or the
* packet read fails. * packet read fails.
*/ */
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t* ulId) IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id)
{ {
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return IVEC_ECU_UART_PACKET_FAIL; return ecuUART_PACKET_FAIL_i8;
} }
IVEC_ECU_UartPacketRetCode_e retCode = IVEC_ECU_UART_PACKET_FAIL; IVEC_ECU_UartPacketRetCode_e l_eRetCode = ecuUART_PACKET_FAIL_i8;
retCode = xECU_UartReadCANDataLenOverUART(prvUartHandle, pucBuf, ulId); l_eRetCode = xECU_UartReadCANDataLenOverUART(pxUartHandle, pu8Buf, u32Id);
return retCode; return l_eRetCode;
} }
/** /**
* @brief Writes data to UART. * @brief Writes data to UART.
@ -505,8 +466,8 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_ECU_UartHandle_s*
* This function writes a buffer of data to the UART, returning a success * This function writes a buffer of data to the UART, returning a success
* or failure status based on the outcome of the write operation. * or failure status based on the outcome of the write operation.
* *
* @param[in] prvUartHandle Pointer to the UART handle for communication. * @param[in] pxUartHandle Pointer to the UART handle for communication.
* @param[in] pucBuffer Pointer to the buffer containing the data to send. * @param[in] pu8Buffer Pointer to the buffer containing the data to send.
* @param[in] len Length of the data to send. * @param[in] len Length of the data to send.
* *
* @return Status of the write operation: * @return Status of the write operation:
@ -514,23 +475,23 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_ECU_UartHandle_s*
* - `commonECU_INVALID_PARAM` if the UART handle is invalid. * - `commonECU_INVALID_PARAM` if the UART handle is invalid.
* - `commonECU_WRITE_FAIL` if the write operation fails. * - `commonECU_WRITE_FAIL` if the write operation fails.
*/ */
IVEC_EcuCommonErr_e IVEC_ECU_Uart_Write(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len) IVEC_EcuCommonErr_e IVEC_ECUUartWrite(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t len)
{ {
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_WRITE_FAIL; IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_WRITE_FAIL;
uint8_t l_i32Ret; uint8_t l_i32Ret;
if (prvUartHandle == NULL) if (pxUartHandle == NULL)
{ {
l_xFuncStatus = commonECU_INVALID_PARAM; l_eFuncStatus = commonECU_INVALID_PARAM;
} }
l_i32Ret = xMCAL_UartWrite(&prvUartHandle->__xUartHandle, pucBuffer, len); l_i32Ret = xMCAL_UartWrite(&pxUartHandle->__xUartHandle, pu8Buffer, len);
if (l_i32Ret == IVEC_CORE_STATUS_SUCCESS) if (l_i32Ret == IVEC_CORE_STATUS_SUCCESS)
{ {
l_xFuncStatus = commonECU_SUCCESS; l_eFuncStatus = commonECU_SUCCESS;
} }
return l_xFuncStatus; return l_eFuncStatus;
} }
/** /**
* @brief Formats and prepares a UART packet for transmission. * @brief Formats and prepares a UART packet for transmission.
@ -538,29 +499,29 @@ IVEC_EcuCommonErr_e IVEC_ECU_Uart_Write(IVEC_ECU_UartHandle_s* prvUartHandle, ui
* This function formats a packet with a sync character, data length, CAN ID, * This function formats a packet with a sync character, data length, CAN ID,
* and checksum, and then sends it via UART using `IVEC_ECU_Uart_Write`. * and checksum, and then sends it via UART using `IVEC_ECU_Uart_Write`.
* *
* @param[in] prvUartHandle Pointer to the UART handle for communication. * @param[in] pxUartHandle Pointer to the UART handle for communication.
* @param[in] pucData Pointer to the data buffer to format. * @param[in] pucData Pointer to the data buffer to format.
* @param[in] ucDlc Data length code (DLC) for the packet. * @param[in] ucDlc Data length code (DLC) for the packet.
* @param[in] ulId CAN ID to be included in the packet. * @param[in] u32Id CAN ID to be included in the packet.
* *
* @return Status of the packet formatting: * @return Status of the packet formatting:
* - `IVEC_ECU_UART_PACKET_SUCCESS` if successful. * - `IVEC_ECU_UART_PACKET_SUCCESS` if successful.
* - `IVEC_ECU_UART_PACKET_FAIL` if the packet formatting or write fails. * - `ecuUART_PACKET_FAIL_i8` if the packet formatting or write fails.
*/ */
IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_ECU_UartHandle_s* prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId) IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint8_t u8Dlc, uint32_t u32Id)
{ {
pucData[0] = 0xb5; // SYNC_CHAR[0] pu8Data[0] = 0xb5; // SYNC_CHAR[0]
pucData[1] = 0x62; // SYNC_CHAR[1] pu8Data[1] = 0x62; // SYNC_CHAR[1]
pucData[2] = ucDlc; pu8Data[2] = u8Dlc;
memcpy(&pucData[3], &ulId, sizeof(uint32_t)); memcpy(&pu8Data[3], &u32Id, sizeof(uint32_t));
unsigned char checksum[2] = { 0 }; unsigned char l_u8CheckSum[2] = { 0 };
_prvECU_CalculateChecksum(pucData, (ucDlc + IVEC_ECU_UART_PKT_HEADER_FOOTER), checksum); _prv_EcuCalculateChecksum(pu8Data, (u8Dlc + ecuUART_PKT_HEADER_FOOTER_u8), l_u8CheckSum);
pucData[(ucDlc + IVEC_ECU_UART_PKT_HEADER_FOOTER) - 2] = checksum[0]; pu8Data[(u8Dlc + ecuUART_PKT_HEADER_FOOTER_u8) - 2] = l_u8CheckSum[0];
pucData[(ucDlc + IVEC_ECU_UART_PKT_HEADER_FOOTER) - 1] = checksum[1]; pu8Data[(u8Dlc + ecuUART_PKT_HEADER_FOOTER_u8) - 1] = l_u8CheckSum[1];
if (IVEC_ECU_Uart_Write(prvUartHandle, pucData, (ucDlc + IVEC_ECU_UART_PKT_HEADER_FOOTER)) != commonECU_SUCCESS) { if (IVEC_ECUUartWrite(pxUartHandle, pu8Data, (u8Dlc + ecuUART_PKT_HEADER_FOOTER_u8)) != commonECU_SUCCESS) {
return IVEC_ECU_UART_PACKET_FAIL; return ecuUART_PACKET_FAIL_i8;
} }
return IVEC_ECU_UART_PACKET_SUCCESS; return ecuUART_PACKET_SUCCESS_u8;
} }
/** /**
* @brief Initiates UART data transmission. * @brief Initiates UART data transmission.
@ -568,7 +529,7 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_ECU_UartHandle_s* prvUar
* This function prepares a data packet with the given CAN ID and data, * This function prepares a data packet with the given CAN ID and data,
* formats the packet, and sends it via UART. * formats the packet, and sends it via UART.
* *
* @param[in] prvUartHandle Pointer to the UART handle for communication. * @param[in] pxUartHandle Pointer to the UART handle for communication.
* @param[in] id CAN ID for the packet. * @param[in] id CAN ID for the packet.
* @param[in] pucData Pointer to the data to send. * @param[in] pucData Pointer to the data to send.
* @param[in] ucLen Length of the data to send. * @param[in] ucLen Length of the data to send.
@ -577,13 +538,13 @@ IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_ECU_UartHandle_s* prvUar
* - `0` on success. * - `0` on success.
* - `-1` on failure. * - `-1` on failure.
*/ */
int32_t iECU_UartInitiateTransmit(IVEC_ECU_UartHandle_s* prvUartHandle, uint32_t id, uint8_t* pucData, uint8_t ucLen) int32_t iECU_UartInitiateTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint32_t u32Id, uint8_t* pu8Data, uint8_t u8Len)
{ {
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber >= IVEC_MCAL_UART_MAX_PORT) if (pxUartHandle == NULL || pxUartHandle->eUartPortNumber >= IVEC_ECU_UART_PORT_MAX)
{ {
return commonECU_INIT_FAIL; return commonECU_INIT_FAIL;
} }
uint8_t pucBuf[IVEC_ECU_UART_MAX_PACKET_LENGTH] = { 0 }; uint8_t l_u8Buf[ecuUART_MAX_PACKET_LENGTH_u8] = {0};
memcpy(&pucBuf[IVEC_ECU_UART_PKT_HEADER], pucData, ucLen); memcpy(&l_u8Buf[ecuUART_PKT_HEADER_u8], pu8Data, u8Len);
return (xECU_UartFormatPacket(prvUartHandle, pucBuf, ucLen, id) == IVEC_ECU_UART_PACKET_SUCCESS) ? 0 : -1; return (xECU_UartFormatPacket(pxUartHandle, l_u8Buf, u8Len, u32Id) == ecuUART_PACKET_SUCCESS_u8) ? 0 : -1;
} }

View File

@ -17,28 +17,26 @@
#include "ivec_rte.h" #include "ivec_rte.h"
// UART Handles // UART Handles
IVEC_ECU_UartHandle_s g_xEcuUartHandle; IVEC_EcuUartHandle_s g_xUartHandle;
IVEC_ECU_UartHandle_s g_xEcuUart2Handle; IVEC_EcuUartHandle_s g_xUart2Handle;
IVEC_EcuCANHandle_s g_xEcuCanHandle; IVEC_EcuCANHandle_s g_xCanHandle;
// Configuration Macros // Configuration Macros
#define ivECU_CONFIG_BASIL_BATTERY_SMART 1 #define rteCONFIG_BASIL_BATTERY_SMART_u8 1
#define ivECU_CONFIG_BASIL 2 #define rteCONFIG_BASIL_u8 2
// UART Configuration // UART Configuration
#define ivECU_UART_PIN_SELECTION ivECU_CONFIG_BASIL_BATTERY_SMART #define rteUART_PIN_SELECTION_u8 rteCONFIG_BASIL_BATTERY_SMART_u8
// Global Variables uint8_t g_pu8UartBuffer[ecuUART_MAX_PACKET_LENGTH_u8] = {0};
xMCAL_CanBaud_e g_eCanSpeed = 0;
uint8_t g_pu8UartBuffer[IVEC_ECU_UART_MAX_PACKET_LENGTH] = {0};
volatile uint32_t g_u32CanId = 0x1FFFFFFF; volatile uint32_t g_u32CanId = 0x1FFFFFFF;
// CAN UART Buffer // CAN UART Buffer
#define ivECU_CAN_UART_BUFFER_MAX_SIZE 4096 #define eteCAN_UART_BUFFER_MAX_SIZE_u32 4096
volatile uint8_t g_prvU8CanUartDataBuffer[ivECU_CAN_UART_BUFFER_MAX_SIZE]; volatile uint8_t g_prvU8CanUartDataBuffer[eteCAN_UART_BUFFER_MAX_SIZE_u32];
// CAN Filters // CAN Filters
bool g_bIsExtendedId[ivECU_MAX_FILTERS]; bool g_bl_bIsExtendedId[ecuMAX_FILTERS_u8];
// Filter Information // Filter Information
@ -46,15 +44,11 @@ uint16_t g_u16ExtendedFilter = 0;
uint16_t g_u16StandardFilter = 0; uint16_t g_u16StandardFilter = 0;
// Private Static Variables // Private Static Variables
static uint8_t _prvU8Index = 0; static uint8_t __gprv_U8Index = 0;
// External Variables // External Variables
extern ExtU_socTouchDisplay_T socTouchDisplay_U; extern ExtU_socTouchDisplay_T socTouchDisplay_U;
extern ExtY_socTouchDisplay_T socTouchDisplay_Y; extern ExtY_socTouchDisplay_T socTouchDisplay_Y;
extern volatile bool g_bMcalMcanInitFlag; /*!< CAN initialization flag */
// CAN Filter Size
#define ivECU_MCAN_FILTER_SIZE 0U
/** /**
* @brief Sets the state of the MCU temperature data pin (SDA) for TM1650. * @brief Sets the state of the MCU temperature data pin (SDA) for TM1650.
@ -106,11 +100,11 @@ void vRTE_McuSetTempClkPin(uint8_t u8State)
* @note The pin direction is temporarily set to input to read the pin state. * @note The pin direction is temporarily set to input to read the pin state.
*/ */
static uint8_t _prvRTE_ReadMcuTempPin(void) { static uint8_t _prv_RteReadMcuTempPin(void) {
uint8_t l_u8ReadBuffer = 0; uint8_t l_u8ReadBuffer = 0;
vMCAL_set_gpioDirection(TM1650_SDA_PIN_IOMUX,false); vMCAL_setGpioDirection(TM1650_SDA_PIN_IOMUX,false);
l_u8ReadBuffer = u32MCAL_gpioRead(TM1650_PORT, TM1650_SDA_PIN_PIN); l_u8ReadBuffer = u32MCAL_gpioRead(TM1650_PORT, TM1650_SDA_PIN_PIN);
vMCAL_set_gpioDirection(TM1650_SDA_PIN_IOMUX,true); vMCAL_setGpioDirection(TM1650_SDA_PIN_IOMUX,true);
return l_u8ReadBuffer; return l_u8ReadBuffer;
} }
@ -126,15 +120,15 @@ static uint8_t _prvRTE_ReadMcuTempPin(void) {
* *
* @returns None * @returns None
* *
* @note The function uses `vMCAL_DelayTicks` for a delay after turning off the display. * @note The function uses `vMCAL_delayTicks` for a delay after turning off the display.
*/ */
void vRTE_MatlabInit(void) void vRTE_MatlabInit(void)
{ {
u8MCAL_gpioInit(); u8MCAL_gpioInit();
tm1650_Init(TM_1650_BRIGHT_8, TM_1650_Segment_8, TM_1650_Normal_Mode, TM_1650_Screen_ON, TM_1650_DIG_3, (void*)&vRTE_SetMcuTempDataPin , (void*)&vRTE_McuSetTempClkPin , &_prvRTE_ReadMcuTempPin); tm1650_Init(TM_1650_BRIGHT_8, TM_1650_Segment_8, TM_1650_Normal_Mode, TM_1650_Screen_ON, TM_1650_DIG_3, (void*)&vRTE_SetMcuTempDataPin , (void*)&vRTE_McuSetTempClkPin , &_prv_RteReadMcuTempPin);
tm1650_displaySwitch(TM_1650_Screen_OFF); tm1650_displaySwitch(TM_1650_Screen_OFF);
vMCAL_DelayTicks(500); vMCAL_delayTicks(500);
tm1650_showDot(TM_1650_DIG_1,false); tm1650_showDot(TM_1650_DIG_1,false);
tm1650_showDot(TM_1650_DIG_2,false); tm1650_showDot(TM_1650_DIG_2,false);
tm1650_showDot(TM_1650_DIG_3,false); tm1650_showDot(TM_1650_DIG_3,false);
@ -165,7 +159,7 @@ void vRTE_MatlabRun(void)
socTouchDisplay_step(); socTouchDisplay_step();
memset(&socTouchDisplay_U.Input[0], 0, sizeof(CAN_MESSAGE_BUS)*MAX_CAN_MESSAGE_INSTANCE); memset(&socTouchDisplay_U.Input[0], 0, sizeof(CAN_MESSAGE_BUS)*MAX_CAN_MESSAGE_INSTANCE);
_prvU8Index = 0; __gprv_U8Index = 0;
if( socTouchDisplay_Y.op_bDisplayStatus ) if( socTouchDisplay_Y.op_bDisplayStatus )
{ {
@ -222,7 +216,7 @@ void vRTE_MatlabRun(void)
void vRTE_AppInit(void) void vRTE_AppInit(void)
{ {
#if ivECU_UART_PIN_SELECTION == 1 #if rteUART_PIN_SELECTION_u8 == 1
vRTE_MatlabInit(); vRTE_MatlabInit();
#endif #endif
@ -242,26 +236,30 @@ void vRTE_AppInit(void)
void vRTE_InitUartCanEcho(void) void vRTE_InitUartCanEcho(void)
{ {
g_eCanSpeed = IVEC_CAN_BAUD_500; g_xUartHandle.u8Qbuffer = g_prvU8CanUartDataBuffer;
g_xEcuUartHandle.u8Qbuffer = g_prvU8CanUartDataBuffer; g_xUartHandle.u16QbufSize = eteCAN_UART_BUFFER_MAX_SIZE_u32;
g_xEcuUartHandle.u16QbufSize = ivECU_CAN_UART_BUFFER_MAX_SIZE;
#if (ivECU_UART_PIN_SELECTION == 1) #if (rteUART_PIN_SELECTION_u8 == 1)
g_xEcuUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT3; g_xUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT3;
g_xEcuUartHandle.u32BaudRate = eEcuUartBaud115200; g_xUartHandle.u32BaudRate = IVEC_ECU_UART_BAUD_115200;
#elif (ivECU_UART_PIN_SELECTION == 2) #elif (rteUART_PIN_SELECTION_u8 == 2)
g_xEcuUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT2; g_xUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT2;
g_xEcuUartHandle.u32BaudRate = eEcuUartBaud115200; g_xUartHandle.u32BaudRate = IVEC_ECU_UART_BAUD_115200;
#endif #endif
xECU_UartInit(&g_xEcuUartHandle); xECU_UartInit(&g_xUartHandle);
g_xEcuCanHandle.u16Speed = IVEC_ECU_CAN_SPEED_500; g_xCanHandle.u16Speed = IVEC_ECU_CAN_SPEED_500;
g_xEcuCanHandle.pMCAN = CANFD0; g_xCanHandle.pMCAN = CANFD0;
g_xEcuCanHandle.i32MaskCount = -1; g_xCanHandle.i32MaskCount = -1;
g_xEcuCanHandle.i32FilterCount = -1; g_xCanHandle.i32FilterCount = -1;
xECU_CANInit(&g_xEcuCanHandle); for (int i = 0; i < ecuMAX_FILTERS_u8; ++i)
{
g_xCanHandle.u32MaskValues[i] = 0;
g_xCanHandle.u32FilterValues[i] = 0;
}
xECU_CANInit(&g_xCanHandle);
} }
/** /**
* @brief Initializes the application run processes. * @brief Initializes the application run processes.
@ -289,7 +287,7 @@ void vRTE_AppRunInit(void)
void vMCAL_TimerCallback(void) void vMCAL_TimerCallback(void)
{ {
#if ivECU_CONFIG_BASIL_BATTERY_SMART == 1 #if rteUART_PIN_SELECTION_u8 == 1
vRTE_MatlabRun(); vRTE_MatlabRun();
#endif #endif
@ -304,15 +302,15 @@ void vMCAL_TimerCallback(void)
* *
* @param[in] u8Idx The index where the mask value is saved. * @param[in] u8Idx The index where the mask value is saved.
* @param[in] u32Mask The mask value to be stored. * @param[in] u32Mask The mask value to be stored.
* @param[in] bIsExtended Flag indicating whether the mask applies to extended IDs. * @param[in] bl_bIsExtended Flag indicating whether the mask applies to extended IDs.
* *
* @returns None * @returns None
*/ */
void vRTE_CanFilterMaskSaveVal(uint8_t u8Idx, uint32_t u32Mask, bool bIsExtended) void vRTE_CanFilterMaskSaveVal(uint8_t u8Idx, uint32_t u32Mask, bool bl_bIsExtended)
{ {
g_xEcuCanHandle.i32MaskCount = u8Idx; g_xCanHandle.i32MaskCount = u8Idx;
g_xEcuCanHandle.u32MaskValues[g_xEcuCanHandle.i32MaskCount] = u32Mask; g_xCanHandle.u32MaskValues[g_xCanHandle.i32MaskCount] = u32Mask;
} }
/** /**
* @brief Saves the CAN filter value. * @brief Saves the CAN filter value.
@ -322,16 +320,16 @@ void vRTE_CanFilterMaskSaveVal(uint8_t u8Idx, uint32_t u32Mask, bool bIsExtended
* *
* @param[in] u8Idx The index where the filter value is stored. * @param[in] u8Idx The index where the filter value is stored.
* @param[in] u32Filter The filter value to be stored. * @param[in] u32Filter The filter value to be stored.
* @param[in] bIsExtended Flag indicating whether the filter applies to extended IDs. * @param[in] bl_bIsExtended Flag indicating whether the filter applies to extended IDs.
* *
* @returns None * @returns None
*/ */
void vRTE_CanFilterSaveVal(uint8_t u8Idx, uint32_t u32Filter, bool bIsExtended) void vRTE_CanFilterSaveVal(uint8_t u8Idx, uint32_t u32Filter, bool bl_bIsExtended)
{ {
g_xEcuCanHandle.i32FilterCount = u8Idx; g_xCanHandle.i32FilterCount = u8Idx;
// Store filter value // Store filter value
g_xEcuCanHandle.u32FilterValues[g_xEcuCanHandle.i32FilterCount] = u32Filter; g_xCanHandle.u32FilterValues[g_xCanHandle.i32FilterCount] = u32Filter;
} }
/** /**
* @brief Processes UART data to manage CAN and UART communication. * @brief Processes UART data to manage CAN and UART communication.
@ -346,58 +344,58 @@ void vRTE_CanFilterSaveVal(uint8_t u8Idx, uint32_t u32Filter, bool bIsExtended)
void vRTE_ProcessUartData(void) void vRTE_ProcessUartData(void)
{ {
IVEC_ECU_UartPacketRetCode_e eRetCode = IVEC_ECU_UART_PACKET_FAIL; IVEC_ECU_UartPacketRetCode_e l_eRetCode = ecuUART_PACKET_FAIL_i8;
uint32_t l_u32Id = 0x1fffffff; uint32_t l_u32Id = 0x1fffffff;
eRetCode= xECU_UartReadCANDataOverUART(&g_xEcuUartHandle,g_pu8UartBuffer,&l_u32Id); l_eRetCode= xECU_UartReadCANDataOverUART(&g_xUartHandle,g_pu8UartBuffer,&l_u32Id);
l_u32Id &= 0x1fffffff; l_u32Id &= 0x1fffffff;
if(eRetCode > -1) if(l_eRetCode > -1)
{ {
if(eRetCode > 0 && l_u32Id == 0x00) if(l_eRetCode > 0 && l_u32Id == 0x00)
{ {
uint32_t l_u32Baudrate = 0; uint32_t l_u32Baudrate = 0;
uint8_t l_u8Mode = g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER]; uint8_t l_u8Mode = g_pu8UartBuffer[ecuUART_PKT_HEADER_u8];
memcpy(&l_u32Baudrate, &g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1], (uint32_t)eRetCode); memcpy(&l_u32Baudrate, &g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1], (uint32_t)l_eRetCode);
iECU_UartInitiateTransmit(&g_xEcuUartHandle, 0x01, g_pu8UartBuffer, 0); iECU_UartInitiateTransmit(&g_xUartHandle, 0x01, g_pu8UartBuffer, 0);
if( l_u8Mode == 0 ) if( l_u8Mode == 0 )
{ {
g_xEcuUartHandle.u32BaudRate = l_u32Baudrate; g_xUartHandle.u32BaudRate = l_u32Baudrate;
xECU_UartReinit(&g_xEcuUartHandle); xECU_UartReinit(&g_xUartHandle);
} }
else if( l_u8Mode == 1 ) else if( l_u8Mode == 1 )
{ {
g_xEcuCanHandle.u16Speed = (uint16_t)l_u32Baudrate;; g_xCanHandle.u16Speed = (uint16_t)l_u32Baudrate;;
xECU_CANReInit(&g_xEcuCanHandle); xECU_CANReInit(&g_xCanHandle);
} }
else if( l_u8Mode == 2 ) else if( l_u8Mode == 2 )
{ {
if( g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1] != 0 ){//22(20+2) rx filter available send each id in a frame if( g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1] != 0 ){//22(20+2) rx filter available send each id in a frame
uint32_t filterId = 0; uint32_t l_U32FilterId = 0;
memcpy(&filterId, &g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+3], sizeof(uint32_t)); memcpy(&l_U32FilterId, &g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+3], sizeof(uint32_t));
bool isExtended = 0; bool l_bIsExtended = 0;
isExtended = (filterId > 0x7FF); // Standard IDs are <= 0x7FF l_bIsExtended = (l_U32FilterId > 0x7FF); // Standard IDs are <= 0x7FF
vRTE_CanFilterSaveVal((g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1] - 1), filterId, isExtended); vRTE_CanFilterSaveVal((g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1] - 1), l_U32FilterId, l_bIsExtended);
if( g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+2] )//All filter received. Trigger Filter Settings if( g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+2] )//All filter received. Trigger Filter Settings
{ {
xECU_CANReInit(&g_xEcuCanHandle); xECU_CANReInit(&g_xCanHandle);
} }
else else
return; return;
} }
else{ else{
xECU_CANReInit(&g_xEcuCanHandle); xECU_CANReInit(&g_xCanHandle);
} }
} }
else if ( l_u8Mode == 3 ) else if ( l_u8Mode == 3 )
{ {
if( (g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1] < 1) || (g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1] > 8) )//0-7 maximum received pkts if( (g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1] < 1) || (g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1] > 8) )//0-7 maximum received pkts
return; return;
uint32_t maskId = 0; uint32_t l_u32u32MaskId = 0;
memcpy(&maskId, &g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+3], sizeof(uint32_t)); memcpy(&l_u32u32MaskId, &g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+3], sizeof(uint32_t));
bool isExtended = 0; bool l_bIsExtended = 0;
isExtended = (maskId > 0x7FF); // Standard IDs are <= 0x7FF l_bIsExtended = (l_u32u32MaskId > 0x7FF); // Standard IDs are <= 0x7FF
vRTE_CanFilterMaskSaveVal((g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER+1] - 1), maskId, isExtended); vRTE_CanFilterMaskSaveVal((g_pu8UartBuffer[ecuUART_PKT_HEADER_u8+1] - 1), l_u32u32MaskId, l_bIsExtended);
} }
else if (l_u8Mode == 100) else if (l_u8Mode == 100)
{ {
@ -405,16 +403,16 @@ void vRTE_ProcessUartData(void)
return; return;
} }
vMCAL_DelayTicks(100); vMCAL_delayTicks(100);
iECU_UartInitiateTransmit(&g_xEcuUartHandle, 0x01, g_pu8UartBuffer, 0); iECU_UartInitiateTransmit(&g_xUartHandle, 0x01, g_pu8UartBuffer, 0);
} }
if ( eRetCode == 0 && l_u32Id == 0){ if ( l_eRetCode == 0 && l_u32Id == 0){
iECU_UartInitiateTransmit(&g_xEcuUartHandle, 0x0, g_pu8UartBuffer, 0); //interface okay response iECU_UartInitiateTransmit(&g_xUartHandle, 0x0, g_pu8UartBuffer, 0); //interface okay response
} }
if ( eRetCode >= 0 && (l_u32Id > 0x00 && l_u32Id < 0xffffffff) ) if ( l_eRetCode >= 0 && (l_u32Id > 0x00 && l_u32Id < 0xffffffff) )
{ {
//_prvU8Buffer = (_prvU8Buffer + 1) % 2; //_prvU8Buffer = (_prvU8Buffer + 1) % 2;
xECU_WriteDataOverCAN(&g_xEcuCanHandle, &g_pu8UartBuffer[IVEC_ECU_UART_PKT_HEADER], l_u32Id, eRetCode, 0); xECU_WriteDataOverCAN(&g_xCanHandle, &g_pu8UartBuffer[ecuUART_PKT_HEADER_u8], l_u32Id, l_eRetCode, 0);
} }
} }
@ -435,23 +433,23 @@ void vRTE_ProcessCanData(void)
{ {
IVEC_ECU_CANBuff_s l_xCanBuff = { 0x00 }; IVEC_ECU_CANBuff_s l_xCanBuff = { 0x00 };
volatile uint8_t l_u8TxBurstMessages = 0; volatile uint8_t l_u8TxBurstMessages = 0;
while( xECU_CANGetData(&g_xEcuCanHandle, &l_xCanBuff) == commonECU_SUCCESS ) while( xECU_CANGetData(&g_xCanHandle, &l_xCanBuff) == commonECU_SUCCESS )
{ {
if( (l_xCanBuff.ulId == 0x16) && (l_xCanBuff.ucData[0] = 'V') && \ if( (l_xCanBuff.u32UlId == 0x16) && (l_xCanBuff.u8Data[0] = 'V') && \
(l_xCanBuff.ucData[1] == 'E') && (l_xCanBuff.ucData[2] == 'C')) (l_xCanBuff.u8Data[1] == 'E') && (l_xCanBuff.u8Data[2] == 'C'))
{ {
vMCAL_SoftReset(); vMCAL_softReset();
} }
iECU_UartInitiateTransmit(&g_xEcuUartHandle, (uint32_t)l_xCanBuff.ulId, (uint8_t*)&l_xCanBuff.ucData[0], (uint8_t)l_xCanBuff.ucLength); iECU_UartInitiateTransmit(&g_xUartHandle, (uint32_t)l_xCanBuff.u32UlId, (uint8_t*)&l_xCanBuff.u8Data[0], (uint8_t)l_xCanBuff.u8Length);
socTouchDisplay_U.Input[_prvU8Index].ID = l_xCanBuff.ulId; socTouchDisplay_U.Input[__gprv_U8Index].ID = l_xCanBuff.u32UlId;
socTouchDisplay_U.Input[_prvU8Index].Length = l_xCanBuff.ucLength; socTouchDisplay_U.Input[__gprv_U8Index].Length = l_xCanBuff.u8Length;
memcpy(&socTouchDisplay_U.Input[_prvU8Index].Data[0], &l_xCanBuff.ucData[0], 8); memcpy(&socTouchDisplay_U.Input[__gprv_U8Index].Data[0], &l_xCanBuff.u8Data[0], 8);
_prvU8Index = (_prvU8Index + 1) % MAX_CAN_MESSAGE_INSTANCE; __gprv_U8Index = (__gprv_U8Index + 1) % MAX_CAN_MESSAGE_INSTANCE;
if(l_u8TxBurstMessages < 16) if(l_u8TxBurstMessages < 16)
l_u8TxBurstMessages++; l_u8TxBurstMessages++;
else else
break; break;
} }
xECU_CANGetStatus(&g_xEcuCanHandle); xECU_CANGetStatus(&g_xCanHandle);
} }

View File

@ -1,2 +0,0 @@
#include "ivec_mcal_common.h"
//#include "ql_api_osi.h"

6
main.c
View File

@ -32,9 +32,9 @@ int main(void)
{ {
__enable_irq(); __enable_irq();
volatile DL_SYSCTL_RESET_CAUSE l_xResetCause = DL_SYSCTL_getResetCause(); volatile DL_SYSCTL_RESET_CAUSE l_xResetCause = DL_SYSCTL_getResetCause();
vMCAL_McuInit(); vMCAL_mcuInit();
xMCAL_SysctlInit(IVEC_HFXT,IVEC_STANDBY0); xMCAL_sysctlInit(IVEC_HFXT,IVEC_STANDBY0);
xMCAL_SystickInit(IVEC_SYSTICK_PERIOD_1MS); xMCAL_systickInit(IVEC_SYSTICK_PERIOD_1MS);
vApp_TimerConfig(); vApp_TimerConfig();

View File

@ -33,6 +33,7 @@
*****************************************************************************/ *****************************************************************************/
#include <stdint.h> #include <stdint.h>
#include "ti_msp_dl_config.h"
/* Entry point for the application. */ /* Entry point for the application. */
extern void SystemInit(void); extern void SystemInit(void);
@ -215,6 +216,20 @@ void Reset_Handler(void)
/* for examination by a debugger. */ /* for examination by a debugger. */
void Default_Handler(void) void Default_Handler(void)
{ {
// uint32_t *stack;
// uint32_t stacked_pc;
// uint32_t stacked_lr;
//
// // Get the Main Stack Pointer (MSP) to access the saved registers
// stack = (uint32_t *)__get_MSP();
//
// // The Program Counter (PC) is saved at position 6 in the stack frame
// stacked_pc = stack[6]; // stack[6] gives the address of the instruction that caused the fault
// stacked_lr = stack[5]; // LR is at offset 5 in the stack frame
//
// // stacked_pc will give you the address where the fault occurred
// // You can use this to trace the fault location in your code
/* Enter an infinite loop. */ /* Enter an infinite loop. */
while(1) while(1)
{ {

View File

@ -33,7 +33,7 @@ static const DL_VREF_ClockConfig g_dlVrefClockConfig = {
* @return IVEC_CORE_STATUS_SUCCESS if initialization is successful. * @return IVEC_CORE_STATUS_SUCCESS if initialization is successful.
*/ */
IVEC_CoreStatus_e xMCAL_SystickInit(IVEC_SystickPeriod_e eTick) IVEC_CoreStatus_e xMCAL_systickInit(IVEC_SystickPeriod_e eTick)
{ {
SysTick_Config(eTick); SysTick_Config(eTick);
NVIC_SetPriority(SysTick_IRQn, 0); NVIC_SetPriority(SysTick_IRQn, 0);
@ -69,7 +69,7 @@ static const DL_SYSCTL_SYSPLLConfig g_dlSysPllConfig = {
* IVEC_CORE_STATUS_INIT_FAIL if invalid parameters are provided. * IVEC_CORE_STATUS_INIT_FAIL if invalid parameters are provided.
*/ */
IVEC_CoreStatus_e xMCAL_SysctlInit(uint8_t u8ClkSrc, uint8_t u8LowPowerMode) IVEC_CoreStatus_e xMCAL_sysctlInit(uint8_t u8ClkSrc, uint8_t u8LowPowerMode)
{ {
if ((u8LowPowerMode != IVEC_STANDBY0) && (u8LowPowerMode != IVEC_SLEEP0)) if ((u8LowPowerMode != IVEC_STANDBY0) && (u8LowPowerMode != IVEC_SLEEP0))
return IVEC_CORE_STATUS_INIT_FAIL; return IVEC_CORE_STATUS_INIT_FAIL;
@ -132,7 +132,7 @@ void SysTick_Handler(void)
* @return The current tick count stored in `g_i32TickCnt`. * @return The current tick count stored in `g_i32TickCnt`.
*/ */
int32_t i32MCAL_GetTicks() int32_t i32MCAL_getTicks()
{ {
return g_i32TickCnt; return g_i32TickCnt;
} }
@ -144,11 +144,11 @@ int32_t i32MCAL_GetTicks()
* @param[in] i32DelayMs The delay in milliseconds to wait. * @param[in] i32DelayMs The delay in milliseconds to wait.
*/ */
void vMCAL_DelayTicks(int32_t i32DelayMs) void vMCAL_delayTicks(int32_t i32DelayMs)
{ {
int32_t l_i32CurrTick = i32MCAL_GetTicks(); int32_t l_i32CurrTick = i32MCAL_getTicks();
while ((i32MCAL_GetTicks() - l_i32CurrTick) < i32DelayMs) while ((i32MCAL_getTicks() - l_i32CurrTick) < i32DelayMs)
{ {
/* Wait */ /* Wait */
} }
@ -159,7 +159,7 @@ void vMCAL_DelayTicks(int32_t i32DelayMs)
* Calls the necessary functions to initialize power and GPIO configurations for the MCU. * Calls the necessary functions to initialize power and GPIO configurations for the MCU.
*/ */
void vMCAL_McuInit(void) void vMCAL_mcuInit(void)
{ {
SYSCFG_DL_initPower(); SYSCFG_DL_initPower();
SYSCFG_DL_GPIO_init(); SYSCFG_DL_GPIO_init();
@ -172,7 +172,7 @@ void vMCAL_McuInit(void)
* @param[in] u32Us The delay duration in microseconds. * @param[in] u32Us The delay duration in microseconds.
*/ */
void vMCAL_DelayUs(uint32_t u32Us) void vMCAL_delayUs(uint32_t u32Us)
{ {
delay_cycles(32 * u32Us); delay_cycles(32 * u32Us);
} }
@ -186,7 +186,7 @@ void vMCAL_DelayUs(uint32_t u32Us)
* IVEC_MCAL_STATUS_INIT_FAIL if VREF is already initialized. * IVEC_MCAL_STATUS_INIT_FAIL if VREF is already initialized.
*/ */
IVEC_McalStatus_e xMCAL_VrefInit(void) IVEC_McalStatus_e xMCAL_vrefInit(void)
{ {
if (g_vrefInitFlag == 0) if (g_vrefInitFlag == 0)
{ {
@ -207,7 +207,7 @@ IVEC_McalStatus_e xMCAL_VrefInit(void)
* Resets the MCU's CPU by calling the appropriate system control function. * Resets the MCU's CPU by calling the appropriate system control function.
*/ */
void vMCAL_SoftReset(void) void vMCAL_softReset(void)
{ {
DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU); DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU);
} }

View File

@ -44,14 +44,6 @@ typedef enum
IVEC_CORE_STATUS_UNSUPPORTED = 4, /*!< Generic operation unsupported status */ IVEC_CORE_STATUS_UNSUPPORTED = 4, /*!< Generic operation unsupported status */
} IVEC_CoreStatus_e; } IVEC_CoreStatus_e;
/* UART Baud Rate Options */
typedef enum
{
IVEC_UART_BAUD_115200 = 0,
IVEC_UART_BAUD_9600 = 1,
} IVEC_UartBaud_e;
/* SPI Clock Speed Options */ /* SPI Clock Speed Options */
typedef enum typedef enum
@ -86,13 +78,13 @@ typedef enum
} IVEC_I2cControllerStatus_e; } IVEC_I2cControllerStatus_e;
/* Function Declarations */ /* Function Declarations */
void vMCAL_McuInit(void); void vMCAL_mcuInit(void);
IVEC_CoreStatus_e xMCAL_SysctlInit(uint8_t u8ClkSrc, uint8_t u8LpMode); IVEC_CoreStatus_e xMCAL_sysctlInit(uint8_t u8ClkSrc, uint8_t u8LpMode);
IVEC_CoreStatus_e xMCAL_SystickInit(IVEC_SystickPeriod_e xTick); IVEC_CoreStatus_e xMCAL_systickInit(IVEC_SystickPeriod_e xTick);
int32_t i32MCAL_GetTicks(void); int32_t i32MCAL_getTicks(void);
void vMCAL_DelayTicks(int32_t i32DelayMs); void vMCAL_delayTicks(int32_t i32DelayMs);
void vMCAL_SoftReset(void); void vMCAL_softReset(void);
void vMCAL_DelayUs(uint32_t u32Us); void vMCAL_delayUs(uint32_t u32Us);
IVEC_McalStatus_e xMCAL_VrefInit(void); IVEC_McalStatus_e xMCAL_vrefInit(void);
#endif /* UTILS_IVEC_UTILS_H_ */ #endif /* UTILS_IVEC_UTILS_H_ */