Update repo
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex10_mask"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex10_mask.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex11_error_generation"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex11_error_generation.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,41 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex1_loopback"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="sysconfig;C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG -v28 -ml -mt --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x3F8 --heap_size=0x200 --define RAM" />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG -v28 -ml -mt --define=CPU1 --define=_FLASH --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x3F8 --heap_size=0x200 " />
|
||||
|
||||
<configuration name="CPU1_CLB" postBuildStep="mkdir "${BuildDirectory}/simulation"
|
||||
;${CLB_SIM_COMPILER}/g++ -c -DCLB_SIM -I${SYSTEMC_INSTALL}/src -I${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/include -I${PROJECT_ROOT} -I${CLB_SIM_COMPILER}/include -Og -g -gdwarf-3 -gstrict-dwarf -Wall -MMD -MP -MF${BuildDirectory}/simulation/clb_sim.d -MT${BuildDirectory}/simulation/clb_sim.o -I${BuildDirectory}/syscfg -fno-threadsafe-statics -o${BuildDirectory}/simulation/clb_sim.o ${BuildDirectory}/syscfg/clb_sim.cpp
|
||||
;${CLB_SIM_COMPILER}/g++ -DCLB_SIM -Og -g -gdwarf-3 -gstrict-dwarf -Wall -Wl,-Map,${BuildDirectory}/simulation/simulation_output.map -L${SYSTEMC_INSTALL}/build/src -o${BuildDirectory}/simulation/simulation_output.exe ${BuildDirectory}/simulation/clb_sim.o ${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/src/CLB_FSM_SC_model.o ${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/src/CLB_HLC_SC_model.o ${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/src/CLB_LUT4_SC_model.o ${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/src/CLB_OutputLUT_SC_model.o ${C2000WARE_ROOT}/utilities/clb_tool/clb_syscfg/systemc/src/CLB_counter_SC_model.o -Wl,--start-group -lsystemc -Wl,--end-group;./simulation/simulation_output.exe
|
||||
;${NODE_TOOL} "${CLB_SYSCFG_ROOT}/dot_file_libraries/clbDotUtility.js" "${CLB_SYSCFG_ROOT}" "${BuildDirectory}/syscfg" "${BuildDirectory}/syscfg/clb.dot"" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG -v28 -ml -mt --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x3F8 --heap_size=0x200 --define RAM" />
|
||||
|
||||
<pathVariable name="CLB_SYSCFG_ROOT" path="../../../../../../utilities/clb_tool/clb_syscfg/" scope="project" />
|
||||
<pathVariable name="SYSTEMC_INSTALL" path="../../../../../../utilities/clb_tool/clb_syscfg/systemc-2.3.3" scope="project" />
|
||||
<pathVariable name="CLB_SIM_COMPILER" path="C:/TDM-GCC-64/bin" scope="project" />
|
||||
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM,CPU1_CLB" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../driverlib/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
|
||||
<file action="copy" path="../can_ex1_loopback.c" targetDirectory="" />
|
||||
<file action="copy" path="../can_ex1_loopback.syscfg" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex2_loopback_interrupts"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex2_loopback_interrupts.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex3_external_transmit"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --define=_DEBUG --define=LARGE_MODEL --diag_warning=225 --diag_suppress=10063 " linkerBuildOptions="--entry_point code_start --stack_size=0x380 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --define=LARGE_MODEL --diag_warning=225 --diag_suppress=10063 " linkerBuildOptions="--entry_point code_start --stack_size=0x380 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex3_external_transmit.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex4_simple_transmit"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex4_simple_transmit.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex5_simple_receive"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex5_simple_receive.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex8_remote_tx"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex8_remote_tx.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,28 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex9_remote_answer"
|
||||
device="TMS320F28377D"
|
||||
cgtVersion="22.6.0.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
enableSysConfigTool="true"
|
||||
sysConfigBuildOptions="--product ${C2000WARE_ROOT}/.metadata/sdk.json --device F2837xD"
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --define=DEBUG --define=_FLASH --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --define=CPU1 --diag_warning=225 --diag_suppress=10063 --display_error_number" linkerBuildOptions="--entry_point code_start --stack_size=0x100 " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../driverlib/" scope="project" />
|
||||
<pathVariable name="C2000WARE_ROOT" path="../../../../../../" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/cmd/2837xD_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2837xd/common/source/F2837xD_CodeStartBranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../driverlib" targetDirectory="device" excludeFromBuild="True"/>
|
||||
<file action="copy" path="../can_ex9_remote_answer.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,186 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex10_mask.c
|
||||
//
|
||||
// TITLE: CAN Acceptance Mask Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN example that illustrates the usage of Mask registers </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A for Reception. When a frame with a
|
||||
//! matching filter criterion is received, the data will be copied in mailbox 1
|
||||
//! and GPIO65 will be toggled a few times and the code gets ready for the next
|
||||
//! frame. If a message of any other MSGID is received, an ACK will be provided
|
||||
//! Completion of reception is determined by polling CAN_NDAT_21 register.
|
||||
//! No interrupts are used.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - An external CAN node that transmits to CAN-A on the C2000 MCU
|
||||
//!
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - rxMsgCount - A counter for the number of messages received
|
||||
//! - rxMsgData - An array with the data that was received
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
// $Release Date: $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 0 // "Don't care" for a Receive mailbox
|
||||
#define RX_MSG_OBJ_ID 1 // Use mailbox 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
uint16_t rxMsgData[8]; // Buffer for received data
|
||||
uint16_t Toggle_ctr; // GPIO toggle counter
|
||||
volatile uint32_t rxMsgCount = 0;
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO
|
||||
//
|
||||
Device_initGPIO();
|
||||
|
||||
//
|
||||
// Configure GPIO pins for CANTX/CANRX
|
||||
//
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
|
||||
//
|
||||
// Configure GPIO pin which is toggled upon message reception
|
||||
//
|
||||
GPIO_setPadConfig(65U, GPIO_PIN_TYPE_STD);
|
||||
GPIO_setDirectionMode(65U, GPIO_DIR_MODE_OUT);
|
||||
|
||||
//
|
||||
// Initialize the receive buffer to a known value
|
||||
//
|
||||
rxMsgData[0] = 0xDEAD;
|
||||
rxMsgData[1] = 0xDEAD;
|
||||
rxMsgData[2] = 0xDEAD;
|
||||
rxMsgData[3] = 0xDEAD;
|
||||
rxMsgData[4] = 0xDEAD;
|
||||
rxMsgData[5] = 0xDEAD;
|
||||
rxMsgData[6] = 0xDEAD;
|
||||
rxMsgData[7] = 0xDEAD;
|
||||
|
||||
//
|
||||
// Initialize the CAN controller
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kbps for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Initialize the receive message object used for receiving CAN messages.
|
||||
// Possible flags: CAN_MSG_OBJ_NO_FLAGS, CAN_MSG_OBJ_USE_EXT_FILTER,
|
||||
// CAN_MSG_OBJ_USE_DIR_FILTER
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x1F9FFFFA
|
||||
// Message Frame: Extended
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x1F000000
|
||||
// Message Object Flags: UMask, MXtd, MDir
|
||||
// Message Object flag CAN_MSG_OBJ_USE_ID_FILTER enables usage
|
||||
// of msgIDMask parameter for Message Identifier based filtering
|
||||
// Message Data Length: "Don't care" for a Receive mailbox
|
||||
CAN_setupMessageObject(CANA_BASE, RX_MSG_OBJ_ID, 0x1F9FFFFA,
|
||||
CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_RX, 0x1F000000,
|
||||
(CAN_MSG_OBJ_USE_ID_FILTER | CAN_MSG_OBJ_NO_FLAGS),
|
||||
MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Start CAN module A operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Start reception - Just wait for data from another node
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
//
|
||||
// Poll bit0 in CAN_NDAT_21 register to check completion of Reception
|
||||
//
|
||||
if((HWREG_BP(CANA_BASE + CAN_O_NDAT_21)) == 0x00000001)
|
||||
{
|
||||
//
|
||||
// Get the received message
|
||||
//
|
||||
asm(" NOP");
|
||||
CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData); // Will this clear NewDat?
|
||||
|
||||
rxMsgCount++;
|
||||
for(Toggle_ctr=0; Toggle_ctr<100; Toggle_ctr++)
|
||||
{
|
||||
GPIO_togglePin(65U);
|
||||
DEVICE_DELAY_US(100000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,734 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex11_error_generation.c
|
||||
//
|
||||
// TITLE: CAN Error Generation over GPIO Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN Error Generation Example </h1>
|
||||
//!
|
||||
//!
|
||||
//! This example demonstrates the ways of handling CAN Error conditions
|
||||
//! It generates the CAN Packets and sends them over GPIO
|
||||
//! It is looped back externally to be received in CAN module
|
||||
//! The CAN Interrupt service routine reads the Error status and
|
||||
//! demonstrates how different Error conditions can be detected
|
||||
//!
|
||||
//! Change ERR_CFG define to the different Error Scenarios and run the
|
||||
//! example. The corresponding Error Flag will be set in status variable
|
||||
//! of canaISR() routine.
|
||||
//! Uses a CPU Timer(Timer 0) for periodic timer interrupt of CANBITRATE uSec
|
||||
//! On the Timer interrupt it sends the required CAN Frame type with
|
||||
//! the specified error conditions
|
||||
//! \note CAN modules on the device need to be connected to via CAN
|
||||
//! transceivers.
|
||||
//!
|
||||
//! Please refer to the application note titled "Configurable Error Generator
|
||||
//! for Controller Area Network" at www.ti.com/lit/pdf/spracq3 for further
|
||||
//! details on this example
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - ControlCARD GPIOTX_PIN(GPIO4) should be connected to GPIO5(CANRXA)
|
||||
//!
|
||||
//! \b Watch \b Variables \b Transmit \Configuration \n
|
||||
//! - status - variable in canaISR for checking error Status
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//!
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
volatile uint32_t rxMsgCount = 0;
|
||||
volatile uint32_t errorFlag = 0;
|
||||
uint16_t txMsgData[8], rxMsgData[8]= {0,0,0,0,0,0,0,0};
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
int16_t generateCANFrame(uint32_t errCfg, int16_t remote_frame, int16_t bitNErr,
|
||||
int16_t dataByteNum, int16_t gpio);
|
||||
void selectGPIO(int16_t gpio);
|
||||
void initCPUTimers(void);
|
||||
void configCPUTimer(uint32_t cpuTimer, float freq, float bitrate);
|
||||
|
||||
//
|
||||
//Interrupt Service Routines
|
||||
//
|
||||
__interrupt void canaISR(void);
|
||||
__interrupt void cpuTimer0ISR(void);
|
||||
|
||||
//
|
||||
//Global Variables
|
||||
//
|
||||
int16_t stream[200];
|
||||
uint32_t canstream[200];
|
||||
uint16_t crcRg;
|
||||
int16_t crcNext,nbits,samebits;
|
||||
int16_t nxtBit, prev_bit, canBit=0;
|
||||
uint32_t arbID;
|
||||
int16_t bitpos=0, errpos=0, stuffbits=0;
|
||||
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
#define RX_MSG_OBJ_ID 2
|
||||
|
||||
// Definitions - do not change values in this section
|
||||
#define CAN_FRAME 0
|
||||
#define REMOTE_REQUEST 1
|
||||
#define CAN_GPIO_MODE 0
|
||||
#define CAN_DATALBCK_MODE 1
|
||||
|
||||
//
|
||||
// CAN error definitions
|
||||
// Use any of these defines for ERR_CFG
|
||||
//
|
||||
//No Error is generated for this define
|
||||
//
|
||||
#define NO_ERR 0
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define FF_SRS_ERR 1
|
||||
//
|
||||
//Form Error is generated for this Error define
|
||||
//
|
||||
#define FF_IDE_ERR 2
|
||||
//
|
||||
//Form Error is generated for this Error define
|
||||
//
|
||||
#define FF_RTR_ERR 3
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define FF_R1_ERR 4
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define FF_R0_ERR 5
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define MSGID_ERR 6
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define DATA_ERR 8
|
||||
//
|
||||
//Bit 0/ CRC Error is generated for this Error define
|
||||
//
|
||||
#define CRC_ERR 9
|
||||
//
|
||||
//Form Error is generated for this Error define
|
||||
//
|
||||
#define STUFF_BITS_ERR 10
|
||||
|
||||
//
|
||||
//Default No Error
|
||||
//Change this NO_ERR to required Error Type as above
|
||||
//
|
||||
#define ERR_CFG FF_IDE_ERR
|
||||
|
||||
// Message data length
|
||||
#define MSG_DATA_LENGTH 4
|
||||
// CAN bit rate
|
||||
#define CANBITRATE 500000
|
||||
|
||||
// Define if GPIO CAN Frame Emulation (CAN_GPIO_MODE) or Internal CAN Data Loopback mode (CAN_DATALBCK_MODE)
|
||||
// CAN_GPIO_MODE: GPIOTX_PIN will output the emulated CAN frame which can be observed externally
|
||||
// CAN_DATALBCK_MODE: The GPIO mapped to CANRX_PAD will receive the emulated CAN frame internally. Using this
|
||||
// mode will not allow for external monitoring of emulated CAN frames. The CANRX_PAD defined should be
|
||||
// driven high when in this mode either externally or through the internal pull up.
|
||||
#define CAN_EMULATION_MODE CAN_GPIO_MODE
|
||||
|
||||
|
||||
// CAN channel setup
|
||||
// GPIO Pin to emulate CAN bit stream
|
||||
#define GPIOTX_PIN 4
|
||||
|
||||
// GPIO assignment for CANRX
|
||||
#define CANRX_PAD GPIO_5_CANRXA
|
||||
|
||||
// GPIOPORT and PIN calculation from channel assignments
|
||||
#define GPIOPORT (GPIOTX_PIN/32)
|
||||
#define GPIORX_PIN ((((CANRX_PAD >> 8) & 0xFFU) + ((CANRX_PAD >> 16) - 0x6U))>>1)
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
int16_t frame_length;
|
||||
|
||||
//
|
||||
// Initialize System Control and device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Configure GPIO pin that will be emulated as CANTX
|
||||
//
|
||||
GPIO_setPinConfig(GPIO_4_GPIO4);
|
||||
|
||||
//
|
||||
// Initialize CAN DATA
|
||||
//
|
||||
arbID = 0x1914A75B;
|
||||
|
||||
txMsgData[0] = 0x95;
|
||||
txMsgData[1] = 0x1A;
|
||||
txMsgData[2] = 0x23;
|
||||
txMsgData[3] = 0x45;
|
||||
txMsgData[4] = 0x67;
|
||||
txMsgData[5] = 0x89;
|
||||
txMsgData[6] = 0xAB;
|
||||
txMsgData[7] = 0xCD;
|
||||
|
||||
frame_length = generateCANFrame(ERR_CFG, CAN_FRAME, 0, 0, GPIOTX_PIN);
|
||||
|
||||
GPIO_setPinConfig(CANRX_PAD);
|
||||
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, CANBITRATE, 20);
|
||||
|
||||
CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// Initialize PIE, clear PIE registers, disable and clear all
|
||||
// CPU interrupts and flags
|
||||
//
|
||||
Interrupt_initModule();
|
||||
|
||||
//
|
||||
// Initialize the PIE vector table with pointers to the shell interrupt
|
||||
// Service Routines (ISR).
|
||||
//
|
||||
Interrupt_initVectorTable();
|
||||
|
||||
//
|
||||
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
|
||||
//
|
||||
EINT;
|
||||
ERTM;
|
||||
|
||||
//
|
||||
// Interrupts that are used in this example are re-mapped to
|
||||
// ISR functions found within this file.
|
||||
// This registers the interrupt handler in PIE vector table.
|
||||
//
|
||||
Interrupt_register(INT_CANA0, &canaISR);
|
||||
Interrupt_register(INT_TIMER0, &cpuTimer0ISR);
|
||||
|
||||
//
|
||||
// Initializes the Device Peripheral. For this example, only initialize the
|
||||
// Cpu Timers.
|
||||
//
|
||||
initCPUTimers();
|
||||
|
||||
//
|
||||
// Configure CPU-Timer 0 interrupt every second:
|
||||
// CANBITRATE Period (in uSeconds)
|
||||
//
|
||||
configCPUTimer(CPUTIMER0_BASE, DEVICE_SYSCLK_FREQ, CANBITRATE);
|
||||
|
||||
//
|
||||
// To ensure precise timing, use write-only instructions to write to the
|
||||
// entire register. Therefore, if any of the configuration bits are changed
|
||||
// in configCPUTimer and initCPUTimers, the below settings must also
|
||||
// be updated.
|
||||
//
|
||||
CPUTimer_enableInterrupt(CPUTIMER0_BASE);
|
||||
|
||||
//
|
||||
// Enables CPU int1 which is connected to CPU-Timer 0,
|
||||
// Enable TINT0 in the PIE: Group 1 interrupt 7
|
||||
//
|
||||
Interrupt_enable(INT_TIMER0);
|
||||
|
||||
//
|
||||
// Enable the CAN interrupt signal
|
||||
//
|
||||
Interrupt_enable(INT_CANA0);
|
||||
CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
//RX set up
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, RX_MSG_OBJ_ID, arbID, CAN_MSG_FRAME_EXT,
|
||||
CAN_MSG_OBJ_TYPE_RX, 0, CAN_MSG_OBJ_RX_INT_ENABLE,
|
||||
MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
canBit = 0;
|
||||
|
||||
//
|
||||
// Start CPU-Timer 0
|
||||
//
|
||||
CPUTimer_startTimer(CPUTIMER0_BASE);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if(canBit >= frame_length)
|
||||
canBit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int16_t generateCANFrame(uint32_t errCfg, int16_t remote_frame,
|
||||
int16_t bitNErr, int16_t dataByteNum, int16_t gpio)
|
||||
{
|
||||
uint32_t i, j, idLSB, idMSB;
|
||||
int16_t xtd, idndx, dlcndx, datndx, nstuffbits;
|
||||
|
||||
// initialize stream and canstream
|
||||
for(i = 0;i < 200;i++)
|
||||
{
|
||||
stream[i] = -1;
|
||||
canstream[i] = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// arbID
|
||||
if(arbID > 0x7FF)
|
||||
{
|
||||
idLSB = arbID & 0x3FFFF;
|
||||
idMSB = ((arbID & 0x1FFFFFFF) >> 18) & 0x7FF;
|
||||
|
||||
stream[0] = 0;
|
||||
for(i = 0;i < 11;i++)
|
||||
stream[1 + i] = ((idMSB >> (10 - i)) & 1)?1:0;
|
||||
// SRS bit position
|
||||
if(errCfg == FF_SRS_ERR)
|
||||
bitpos = i + 1;
|
||||
// SRS bit
|
||||
stream[1 + i] = 1;
|
||||
// IDE bit position
|
||||
if(errCfg == FF_IDE_ERR)
|
||||
bitpos = i + 2;
|
||||
// IDE bit
|
||||
stream[2 + i] = 1;
|
||||
for(i = 0;i < 18;i++)
|
||||
stream[14 + i]=((idLSB >> (17 - i)) & 1 )?1:0;
|
||||
|
||||
idndx = 32;
|
||||
xtd = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
idLSB = arbID & 0x7FF;
|
||||
stream[0] = 0;
|
||||
for(i = 0;i < 11;i++)
|
||||
stream[1 + i] = ((idLSB >> (10 -i )) & 1) ? 1:0;
|
||||
|
||||
idndx = 12;
|
||||
xtd = 0;
|
||||
}
|
||||
// If errCfg value is MSGID_ERR, or DATA_ERR or CRC_ERR, ensure that bitNErr is valid
|
||||
if(errCfg == MSGID_ERR)
|
||||
{
|
||||
if(arbID > 0x7FF)
|
||||
{
|
||||
if(bitNErr > 28)
|
||||
// bitNErr VALUE is not valid - change to valid value
|
||||
ESTOP0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bitNErr > 11)
|
||||
// bitNErr VALUE is not valid - change to valid value
|
||||
ESTOP0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//If errCfg value is DATA_ERR
|
||||
//check for valid bit position bitNErr and dataByteNum value
|
||||
//
|
||||
if(errCfg == DATA_ERR)
|
||||
{
|
||||
if(dataByteNum > (MSG_DATA_LENGTH - 1))
|
||||
// dataByteNum value is not valid - change to valid value
|
||||
ESTOP0;
|
||||
if(bitNErr > 7)
|
||||
// bitNErr value is not valid - change to valid value
|
||||
ESTOP0;
|
||||
}
|
||||
// if errCfg value is CRC_ERR, check for valid bit position bitNErr
|
||||
if(errCfg == DATA_ERR)
|
||||
{
|
||||
if(bitNErr > 14)
|
||||
// bitNErr value is not valid - change to valid value
|
||||
ESTOP0;
|
||||
}
|
||||
|
||||
//RTR, r1, r0 = 0 for now
|
||||
// RTR bit position
|
||||
if(errCfg == FF_RTR_ERR) bitpos = idndx;
|
||||
// RTR bit
|
||||
stream[idndx] = (!remote_frame)?0:1;
|
||||
// R1 bit position
|
||||
if(errCfg == FF_R1_ERR)
|
||||
bitpos = idndx + 1;
|
||||
// R1 bit
|
||||
stream[idndx + 1] = 0;
|
||||
// R0 bit position
|
||||
if(errCfg==FF_R0_ERR)
|
||||
bitpos = idndx + 2;
|
||||
// R0 bit
|
||||
stream[idndx + 2] = 0;
|
||||
|
||||
//DLC
|
||||
dlcndx = (xtd)?35:15;
|
||||
for(i = 0;i < 4;i++)
|
||||
stream[dlcndx + i]=((MSG_DATA_LENGTH >> (3 - i)) & 1)? 1: 0;
|
||||
//DATA (up to 8 bytes
|
||||
if(!remote_frame)
|
||||
{
|
||||
datndx = (xtd)?39:19;
|
||||
for(i = 0;i < MSG_DATA_LENGTH;i++)
|
||||
{
|
||||
for(j=0;j<8;j++)
|
||||
stream[datndx + (i * 8) + j] =
|
||||
((txMsgData[i] >> (7 - j)) & 1)?1:0;
|
||||
}
|
||||
}
|
||||
|
||||
//determine how long the bitstream is
|
||||
i = 0;
|
||||
nxtBit = stream[i];
|
||||
while(nxtBit == 0 || nxtBit == 1)
|
||||
nxtBit=stream[i++];
|
||||
nbits=--i;
|
||||
|
||||
crcRg = 0;
|
||||
for(i = 0;i < nbits;i++)
|
||||
{
|
||||
nxtBit = stream[i];
|
||||
crcNext = nxtBit ^ ((crcRg & 0x4000) >> 14);
|
||||
crcRg=(crcRg << 1) & 0x7FFE;
|
||||
if(crcNext)
|
||||
{
|
||||
crcRg = crcRg ^ 0x4599; // CAN-15 CRC polynomial
|
||||
}
|
||||
}
|
||||
|
||||
// Invert bitNErr position in MSGID
|
||||
if(errCfg == MSGID_ERR)
|
||||
{
|
||||
bitpos = idndx - 1 - bitNErr;
|
||||
stream[bitpos] = (stream[bitpos] == 1)?0:1;
|
||||
|
||||
}
|
||||
|
||||
// SRS ERROR
|
||||
if(errCfg == FF_SRS_ERR)
|
||||
stream[bitpos] = 0;
|
||||
// IDE ERROR
|
||||
if(errCfg == FF_IDE_ERR)
|
||||
stream[bitpos] = 0;
|
||||
// RTR ERROR
|
||||
if(errCfg == FF_RTR_ERR)
|
||||
stream[bitpos] = 1;
|
||||
// R1 ERROR
|
||||
if(errCfg == FF_R1_ERR)
|
||||
stream[bitpos] = 1;
|
||||
// R0 ERROR
|
||||
if(errCfg == FF_R0_ERR)
|
||||
stream[bitpos] = 1;
|
||||
|
||||
// Invert bitNErr position in the data byte pointed by dataByteNum
|
||||
if(errCfg == DATA_ERR)
|
||||
{
|
||||
bitpos = datndx + (7 - bitNErr) + (dataByteNum * 8);
|
||||
stream[bitpos] = (stream[bitpos] == 1)?0:1;
|
||||
}
|
||||
|
||||
//Append CRC bits (15) + delimiter
|
||||
for(i = 0;i < 15;i++)
|
||||
{
|
||||
stream[nbits + i]=((crcRg >> (14 - i)) & 1)?1:0;
|
||||
}
|
||||
|
||||
// add CRC delimiter
|
||||
stream[nbits + i] = 1;
|
||||
nbits += 1;
|
||||
|
||||
// Invert bitNErr position in the 15-bit CRC
|
||||
if(errCfg==CRC_ERR)
|
||||
{
|
||||
bitpos = nbits + 13 - bitNErr;
|
||||
stream[bitpos] = stream[bitpos] == 1?0:1;
|
||||
}
|
||||
|
||||
//
|
||||
//Stuff bits: check for 5 consecutive bit states
|
||||
//then insert opposite bit state if this occurs
|
||||
//
|
||||
prev_bit = stream[0];
|
||||
canstream[0] = stream[0];
|
||||
j = 1;
|
||||
samebits = 0;
|
||||
nstuffbits = 0;
|
||||
for(i = 1;i < (nbits + 15);i++)
|
||||
{
|
||||
canstream[j++] = stream[i];
|
||||
//determine position of flipped bit
|
||||
if(i == bitpos)
|
||||
errpos = j - 1;
|
||||
if(prev_bit == stream[i])
|
||||
{
|
||||
if(!samebits)
|
||||
samebits = 2;
|
||||
else
|
||||
samebits++;
|
||||
|
||||
if(samebits == 5)
|
||||
{
|
||||
if(errCfg != STUFF_BITS_ERR)
|
||||
canstream[j++] = (stream[i] == 1) ? 0:1;
|
||||
samebits = 0;
|
||||
nstuffbits++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
samebits = 0;
|
||||
}
|
||||
prev_bit = canstream[j - 1];
|
||||
}
|
||||
stuffbits = nstuffbits;
|
||||
i = 0;
|
||||
nxtBit = canstream[i];
|
||||
while(nxtBit == 0 || nxtBit == 1)
|
||||
nxtBit=canstream[i++];
|
||||
nbits=--i;
|
||||
|
||||
// Append 20 recessive bits at the end of the bitstream
|
||||
for(i = 0;i < 14;i++)
|
||||
if(i==0)
|
||||
canstream[nbits + i] = 0;
|
||||
else
|
||||
canstream[nbits + i] = 1;
|
||||
|
||||
// format stream as 32-bit location
|
||||
for(i = 0;i <(nbits + 14);i++)
|
||||
{
|
||||
if(CAN_EMULATION_MODE==CAN_GPIO_MODE)
|
||||
{
|
||||
if(gpio <= 15)
|
||||
{
|
||||
canstream[i] = (canstream[i]==1)?(uint32_t)(1 << gpio):0;
|
||||
}
|
||||
if(gpio > 15 && gpio <= 31)
|
||||
{
|
||||
canstream[i] =
|
||||
(canstream[i]==1) ?
|
||||
(uint32_t)(0x10000 << (gpio - 16)) : 0;
|
||||
|
||||
}
|
||||
if(gpio > 31 && gpio <= 44)
|
||||
{
|
||||
canstream[i] =
|
||||
(canstream[i] == 1) ?(uint32_t)( 1 << (gpio - 32)):0;
|
||||
}
|
||||
}
|
||||
else
|
||||
canstream[i] = (canstream[i]==0) ?
|
||||
GPIO_PIN_TYPE_INVERT : GPIO_PIN_TYPE_STD;
|
||||
|
||||
}
|
||||
|
||||
return (nbits + 14);
|
||||
}
|
||||
|
||||
//
|
||||
// initCPUTimers - This function initializes all three CPU timers
|
||||
// to a known state.
|
||||
//
|
||||
void
|
||||
initCPUTimers(void)
|
||||
{
|
||||
//
|
||||
// Initialize timer period to maximum
|
||||
//
|
||||
CPUTimer_setPeriod(CPUTIMER0_BASE, 0xFFFFFFFF);
|
||||
|
||||
//
|
||||
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT)
|
||||
//
|
||||
CPUTimer_setPreScaler(CPUTIMER0_BASE, 0);
|
||||
|
||||
//
|
||||
// Make sure timer is stopped
|
||||
//
|
||||
CPUTimer_stopTimer(CPUTIMER0_BASE);
|
||||
|
||||
//
|
||||
// Reload all counter register with period value
|
||||
//
|
||||
CPUTimer_reloadTimerCounter(CPUTIMER0_BASE);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// configCPUTimer - This function initializes the selected timer to the
|
||||
// period specified by the "freq" and "period" parameters. The "freq" is
|
||||
// entered as Hz and the period in uSeconds. The timer is held in the stopped
|
||||
// state after configuration.
|
||||
//
|
||||
void
|
||||
configCPUTimer(uint32_t cpuTimer, float freq, float bitrate)
|
||||
{
|
||||
uint32_t temp;
|
||||
|
||||
//
|
||||
// Initialize timer period:
|
||||
//
|
||||
temp = (uint32_t)(freq / bitrate);
|
||||
CPUTimer_setPeriod(cpuTimer, temp);
|
||||
|
||||
//
|
||||
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
|
||||
//
|
||||
CPUTimer_setPreScaler(cpuTimer, 0);
|
||||
|
||||
//
|
||||
// Initializes timer control register. The timer is stopped, reloaded,
|
||||
// free run disabled, and interrupt enabled.
|
||||
// Additionally, the free and soft bits are set
|
||||
//
|
||||
CPUTimer_stopTimer(cpuTimer);
|
||||
CPUTimer_reloadTimerCounter(cpuTimer);
|
||||
CPUTimer_setEmulationMode(cpuTimer,
|
||||
CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT);
|
||||
CPUTimer_enableInterrupt(cpuTimer);
|
||||
|
||||
}
|
||||
|
||||
__interrupt void
|
||||
canaISR(void)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
//
|
||||
// Read the CAN-A interrupt status to find the cause of the interrupt
|
||||
//
|
||||
status = CAN_getInterruptCause(CANA_BASE);
|
||||
|
||||
//
|
||||
// If the cause is a controller status interrupt, then get the status
|
||||
//
|
||||
if(status == CAN_INT_INT0ID_STATUS)
|
||||
{
|
||||
//
|
||||
// Read the controller status. This will return a field of status
|
||||
// error bits that can indicate various errors. Error processing
|
||||
// is not done in this example for simplicity. Refer to the
|
||||
// API documentation for details about the error status bits.
|
||||
// The act of reading this status will clear the interrupt.
|
||||
//
|
||||
status = CAN_getStatus(CANA_BASE);
|
||||
// uncomment below in order to inspect LEC in CAN_ES
|
||||
//ESTOP0;
|
||||
|
||||
|
||||
//
|
||||
// Check to see if an error occurred.
|
||||
//
|
||||
if(((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_MSK) &&
|
||||
((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_NONE))
|
||||
{
|
||||
//
|
||||
// Set a flag to indicate some errors may have occurred.
|
||||
//
|
||||
errorFlag = 1;
|
||||
// uncomment below in order to inspect LEC in CAN_ES if error occurs
|
||||
//ESTOP0;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Check if the cause is the CAN-B receive message object 1
|
||||
//
|
||||
else if(status == RX_MSG_OBJ_ID)
|
||||
{
|
||||
//
|
||||
// Get the received message
|
||||
//
|
||||
CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData);
|
||||
|
||||
//
|
||||
// Getting to this point means that the RX interrupt occurred on
|
||||
// message object 1, and the message RX is complete. Clear the
|
||||
// message object interrupt.
|
||||
//
|
||||
CAN_clearInterruptStatus(CANA_BASE, RX_MSG_OBJ_ID);
|
||||
|
||||
//
|
||||
// Increment a counter to keep track of how many messages have been
|
||||
// received. In a real application this could be used to set flags to
|
||||
// indicate when a message is received.
|
||||
//
|
||||
rxMsgCount++;
|
||||
|
||||
//
|
||||
// Since the message was received, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
}
|
||||
//
|
||||
// If something unexpected caused the interrupt, this would handle it.
|
||||
//
|
||||
else
|
||||
{
|
||||
//
|
||||
// Spurious interrupt handling can go here.
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Clear the global interrupt flag for the CAN interrupt line
|
||||
//
|
||||
CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
// Acknowledge this interrupt located in group 9
|
||||
//
|
||||
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
|
||||
//ESTOP0;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// cpuTimer0ISR - Counter for CpuTimer0
|
||||
//
|
||||
__interrupt void
|
||||
cpuTimer0ISR(void)
|
||||
{
|
||||
|
||||
//
|
||||
// Write canstream data to GPIO port selected
|
||||
//
|
||||
if (CAN_EMULATION_MODE == CAN_GPIO_MODE)
|
||||
GPIO_writePortData((GPIO_Port)GPIOPORT, canstream[canBit++]);
|
||||
else
|
||||
GPIO_setPadConfig(GPIORX_PIN, canstream[canBit++]);
|
||||
//
|
||||
// Acknowledge this interrupt to receive more interrupts from group 1
|
||||
//
|
||||
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,201 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex1_loopback.c
|
||||
//
|
||||
// TITLE: CAN External Loopback Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN External Loopback </h1>
|
||||
//!
|
||||
//! This example shows the basic setup of CAN in order to transmit and receive
|
||||
//! messages on the CAN bus. The CAN peripheral is configured to transmit
|
||||
//! messages with a specific CAN ID. A message is then transmitted once per
|
||||
//! second, using a simple delay loop for timing. The message that is sent is
|
||||
//! a 2 byte message that contains an incrementing pattern.
|
||||
//!
|
||||
//! This example sets up the CAN controller in External Loopback test mode.
|
||||
//! Data transmitted is visible on the CANTXA pin and is received internally
|
||||
//! back to the CAN Core. Please refer to details of the External Loopback
|
||||
//! Test Mode in the CAN Chapter in the Technical Reference Manual.
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - None.
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - msgCount - A counter for the number of successful messages received
|
||||
//! - txMsgData - An array with the data being sent
|
||||
//! - rxMsgData - An array with the data that was received
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
//
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
#include "board.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 2
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile unsigned long msgCount = 0;
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
uint16_t txMsgData[2], rxMsgData[2];
|
||||
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
//
|
||||
Device_initGPIO();
|
||||
|
||||
//
|
||||
// Board initialization
|
||||
//
|
||||
Board_init();
|
||||
|
||||
//
|
||||
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
|
||||
//
|
||||
Interrupt_initModule();
|
||||
|
||||
//
|
||||
// Initialize the PIE vector table with pointers to the shell Interrupt
|
||||
// Service Routines (ISR).
|
||||
//
|
||||
Interrupt_initVectorTable();
|
||||
|
||||
//
|
||||
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
|
||||
//
|
||||
EINT;
|
||||
ERTM;
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(myCAN0_BASE);
|
||||
|
||||
//
|
||||
// Setup send and receive buffers
|
||||
//
|
||||
txMsgData[0] = 0x01;
|
||||
txMsgData[1] = 0x02;
|
||||
*(uint16_t *)rxMsgData = 0;
|
||||
|
||||
//
|
||||
// Loop Forever - Send and Receive data continuously
|
||||
//
|
||||
for(;;)
|
||||
{
|
||||
//
|
||||
// Send CAN message data from message object 1
|
||||
//
|
||||
CAN_sendMessage(myCAN0_BASE, 1, MSG_DATA_LENGTH, txMsgData);
|
||||
|
||||
//
|
||||
// Delay before receiving the data
|
||||
//
|
||||
DEVICE_DELAY_US(500000);
|
||||
|
||||
//
|
||||
// Read CAN message object 2 and check for new data
|
||||
//
|
||||
if (CAN_readMessage(myCAN0_BASE, 2, rxMsgData))
|
||||
{
|
||||
//
|
||||
// Check that received data matches sent data.
|
||||
// Device will halt here during debug if data doesn't match.
|
||||
//
|
||||
if((txMsgData[0] != rxMsgData[0]) ||
|
||||
(txMsgData[1] != rxMsgData[1]))
|
||||
{
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Increment message received counter
|
||||
//
|
||||
msgCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Device will halt here during debug if no new data was received.
|
||||
//
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// Increment the value in the transmitted message data.
|
||||
//
|
||||
txMsgData[0] += 0x01;
|
||||
txMsgData[1] += 0x01;
|
||||
|
||||
//
|
||||
// Reset data if exceeds a byte
|
||||
//
|
||||
if(txMsgData[0] > 0xFF)
|
||||
{
|
||||
txMsgData[0] = 0;
|
||||
}
|
||||
if(txMsgData[1] > 0xFF)
|
||||
{
|
||||
txMsgData[1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Import the modules used in this configuration.
|
||||
*/
|
||||
const can = scripting.addModule("/driverlib/can.js", {}, false);
|
||||
const can1 = can.addInstance();
|
||||
|
||||
/**
|
||||
* Write custom configuration values to the imported modules.
|
||||
*/
|
||||
can1.$name = "myCAN0";
|
||||
can1.enableLoopback = true;
|
||||
can1.loopbackMode = "CAN_TEST_EXL";
|
||||
can1.msgObjs = 2;
|
||||
can1.msgObj1.$name = "msgObj0";
|
||||
can1.msgObj1.msgID = 660;
|
||||
can1.msgObj1.msgType = "CAN_MSG_OBJ_TYPE_TX";
|
||||
can1.msgObj1.msgLen = 2;
|
||||
can1.msgObj2.$name = "msgObj1";
|
||||
can1.msgObj2.msgID = 660;
|
||||
can1.msgObj2.msgType = "CAN_MSG_OBJ_TYPE_RX";
|
||||
can1.msgObj2.msgLen = 2;
|
||||
@@ -0,0 +1,406 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex2_loopback_interrupts.c
|
||||
//
|
||||
// TITLE: CAN External Loopback with Interrupts Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN External Loopback with Interrupts </h1>
|
||||
//!
|
||||
//! This example shows the basic setup of CAN in order to transmit and receive
|
||||
//! messages on the CAN bus. The CAN peripheral is configured to transmit
|
||||
//! messages with a specific CAN ID. A message is then transmitted once per
|
||||
//! second, using a simple delay loop for timing. The message that is sent is
|
||||
//! a 4 byte message that contains an incrementing pattern. A CAN interrupt
|
||||
//! handler is used to confirm message transmission and count the number of
|
||||
//! messages that have been sent.
|
||||
//!
|
||||
//! This example sets up the CAN controller in External Loopback test mode.
|
||||
//! Data transmitted is visible on the CANTXA pin and is received internally
|
||||
//! back to the CAN Core. CAN-B module is not involved.
|
||||
//!
|
||||
//! Note: "External" loopback does not mean the loopback is done externally.
|
||||
//! The loopback is done internally, but the transmitted data can be seen
|
||||
//! externally on the CANTX pin.
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - None. (Transmitting node generates its own ACK)
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - txMsgCount - A counter for the number of messages sent
|
||||
//! - rxMsgCount - A counter for the number of messages received
|
||||
//! - txMsgData - An array with the data being sent
|
||||
//! - rxMsgData - An array with the data that was received
|
||||
//! - errorFlag - A flag that indicates an error has occurred
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
//
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 4
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
#define RX_MSG_OBJ_ID 2
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
volatile uint32_t rxMsgCount = 0;
|
||||
volatile uint32_t errorFlag = 0;
|
||||
uint16_t txMsgData[4];
|
||||
uint16_t rxMsgData[4];
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
__interrupt void canISR(void);
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
//
|
||||
Device_initGPIO();
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
|
||||
//
|
||||
// Initialize the CAN controller
|
||||
//
|
||||
// Puts the module in Initialization mode, Disables the parity function
|
||||
// Initializes the MBX RAM, Initiates a S/W reset of the module
|
||||
// Seeks write-access to configuration registers.
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500 kbps
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 20);
|
||||
|
||||
//
|
||||
// Enable interrupts on the CAN peripheral.
|
||||
// Enables Interrupt line 0, Error & Status Change interrupts in CAN_CTL
|
||||
// register.
|
||||
//
|
||||
CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
|
||||
//
|
||||
Interrupt_initModule();
|
||||
|
||||
//
|
||||
// Initialize the PIE vector table with pointers to the shell Interrupt
|
||||
// Service Routines (ISR).
|
||||
//
|
||||
Interrupt_initVectorTable();
|
||||
|
||||
//
|
||||
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
|
||||
//
|
||||
EINT;
|
||||
ERTM;
|
||||
|
||||
//
|
||||
// Interrupts that are used in this example are re-mapped to
|
||||
// ISR functions found within this file.
|
||||
// This registers the interrupt handler in PIE vector table.
|
||||
//
|
||||
Interrupt_register(INT_CANA0, &canISR);
|
||||
|
||||
//
|
||||
// Enable the CAN interrupt signal
|
||||
//
|
||||
Interrupt_enable(INT_CANA0);
|
||||
CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
// Enable CAN test mode with external loopback
|
||||
//
|
||||
CAN_enableTestMode(CANA_BASE, CAN_TEST_EXL);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object used for sending CAN messages.
|
||||
// Message Object Parameters:
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x1
|
||||
// Message Frame: Standard
|
||||
// Message Type: Transmit
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: Transmit Interrupt
|
||||
// Message Data Length: 4 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x1, CAN_MSG_FRAME_STD,
|
||||
CAN_MSG_OBJ_TYPE_TX, 0, CAN_MSG_OBJ_TX_INT_ENABLE,
|
||||
MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the receive message object used for receiving CAN messages.
|
||||
// Message Object Parameters:
|
||||
// Message Object ID Number: 2
|
||||
// Message Identifier: 0x1
|
||||
// Message Frame: Standard
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: Receive Interrupt
|
||||
// Message Data Length: 4 Bytes (Note that DLC field is a "don't care"
|
||||
// for a Receive mailbox)
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, RX_MSG_OBJ_ID, 0x1, CAN_MSG_FRAME_STD,
|
||||
CAN_MSG_OBJ_TYPE_RX, 0, CAN_MSG_OBJ_RX_INT_ENABLE,
|
||||
MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object data buffer to be sent
|
||||
//
|
||||
txMsgData[0] = 0x12;
|
||||
txMsgData[1] = 0x34;
|
||||
txMsgData[2] = 0x56;
|
||||
txMsgData[3] = 0x78;
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Loop Forever - A new message will be sent once per second.
|
||||
//
|
||||
for(;;)
|
||||
{
|
||||
//
|
||||
// Check the error flag to see if errors occurred
|
||||
//
|
||||
if(errorFlag)
|
||||
{
|
||||
Example_Fail = 1;
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// Verify that the number of transmitted messages equal the number of
|
||||
// messages received before sending a new message
|
||||
//
|
||||
if(txMsgCount == rxMsgCount)
|
||||
{
|
||||
CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH,
|
||||
txMsgData);
|
||||
|
||||
Example_PassCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorFlag = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Delay 1 second before continuing
|
||||
//
|
||||
DEVICE_DELAY_US(1000000);
|
||||
|
||||
//
|
||||
// Increment the value in the transmitted message data.
|
||||
//
|
||||
txMsgData[0] += 0x01;
|
||||
txMsgData[1] += 0x01;
|
||||
txMsgData[2] += 0x01;
|
||||
txMsgData[3] += 0x01;
|
||||
|
||||
//
|
||||
// Reset data if exceeds a byte
|
||||
//
|
||||
if(txMsgData[0] > 0xFF)
|
||||
{
|
||||
txMsgData[0] = 0;
|
||||
}
|
||||
if(txMsgData[1] > 0xFF)
|
||||
{
|
||||
txMsgData[1] = 0;
|
||||
}
|
||||
if(txMsgData[2] > 0xFF)
|
||||
{
|
||||
txMsgData[2] = 0;
|
||||
}
|
||||
if(txMsgData[3] > 0xFF)
|
||||
{
|
||||
txMsgData[3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// CAN ISR - The interrupt service routine called when a CAN interrupt is
|
||||
// triggered. It checks for the cause of the interrupt, and
|
||||
// maintains a count of all messages that have been transmitted.
|
||||
//
|
||||
__interrupt void
|
||||
canISR(void)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
//
|
||||
// Read the CAN interrupt status to find the cause of the interrupt
|
||||
//
|
||||
status = CAN_getInterruptCause(CANA_BASE);
|
||||
|
||||
//
|
||||
// If the cause is a controller status interrupt, then get the status
|
||||
//
|
||||
if(status == CAN_INT_INT0ID_STATUS)
|
||||
{
|
||||
//
|
||||
// Read the controller status. This will return a field of status
|
||||
// error bits that can indicate various errors. Error processing
|
||||
// is not done in this example for simplicity. Refer to the
|
||||
// API documentation for details about the error status bits.
|
||||
// The act of reading this status will clear the interrupt.
|
||||
//
|
||||
status = CAN_getStatus(CANA_BASE);
|
||||
|
||||
//
|
||||
// Check to see if an error occurred.
|
||||
//
|
||||
if(((status & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 7) &&
|
||||
((status & ~(CAN_STATUS_TXOK | CAN_STATUS_RXOK)) != 0))
|
||||
{
|
||||
//
|
||||
// Set a flag to indicate some errors may have occurred.
|
||||
//
|
||||
errorFlag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check if the cause is the transmit message object 1
|
||||
//
|
||||
else if(status == TX_MSG_OBJ_ID)
|
||||
{
|
||||
//
|
||||
// Getting to this point means that the TX interrupt occurred on
|
||||
// message object 1, and the message TX is complete. Clear the
|
||||
// message object interrupt.
|
||||
//
|
||||
CAN_clearInterruptStatus(CANA_BASE, TX_MSG_OBJ_ID);
|
||||
|
||||
//
|
||||
// Increment a counter to keep track of how many messages have been
|
||||
// sent. In a real application this could be used to set flags to
|
||||
// indicate when a message is sent.
|
||||
//
|
||||
txMsgCount++;
|
||||
|
||||
//
|
||||
// Since the message was sent, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if the cause is the receive message object 2
|
||||
//
|
||||
else if(status == RX_MSG_OBJ_ID)
|
||||
{
|
||||
//
|
||||
// Get the received message
|
||||
//
|
||||
CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData);
|
||||
|
||||
//
|
||||
// Getting to this point means that the RX interrupt occurred on
|
||||
// message object 2, and the message RX is complete. Clear the
|
||||
// message object interrupt.
|
||||
//
|
||||
CAN_clearInterruptStatus(CANA_BASE, RX_MSG_OBJ_ID);
|
||||
|
||||
//
|
||||
// Increment a counter to keep track of how many messages have been
|
||||
// received. In a real application this could be used to set flags to
|
||||
// indicate when a message is received.
|
||||
//
|
||||
rxMsgCount++;
|
||||
|
||||
//
|
||||
// Since the message was received, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// If something unexpected caused the interrupt, this would handle it.
|
||||
//
|
||||
else
|
||||
{
|
||||
//
|
||||
// Spurious interrupt handling can go here.
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Clear the global interrupt flag for the CAN interrupt line
|
||||
//
|
||||
CAN_clearGlobalInterruptStatus(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
// Acknowledge this interrupt located in group 9
|
||||
//
|
||||
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,397 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex3_external_transmit.c
|
||||
//
|
||||
// TITLE: CAN External Transmit Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN-A to CAN-B External Transmit </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A and CAN module B for external
|
||||
//! communication. CAN-A module is setup to transmit incrementing data for "n"
|
||||
//! number of times to the CAN-B module, where "n" is the value of TXCOUNT.
|
||||
//! CAN-B module is setup to trigger an interrupt service routine (ISR) when
|
||||
//! data is received. An error flag will be set if the transmitted data doesn't
|
||||
//! match the received data.
|
||||
//!
|
||||
//! \note Both CAN modules on the device need to be
|
||||
//! connected to each other via CAN transceivers. GPIOs will be different
|
||||
//! on Launchpad.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with two CAN transceivers
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - ControlCARD CANA is on GPIO31 (CANTXA) and GPIO30 (CANRXA)
|
||||
//! - ControlCARD CANB is on GPIO8 (CANTXB) and GPIO10 (CANRXB)
|
||||
//!
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - TXCOUNT - Adjust to set the number of messages to be transmitted
|
||||
//! - txMsgCount - A counter for the number of messages sent
|
||||
//! - rxMsgCount - A counter for the number of messages received
|
||||
//! - txMsgData - An array with the data being sent
|
||||
//! - rxMsgData - An array with the data that was received
|
||||
//! - errorFlag - A flag that indicates an error has occurred
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
// $Release Date: $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define TXCOUNT 100
|
||||
#define MSG_DATA_LENGTH 4
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
#define RX_MSG_OBJ_ID 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile unsigned long i;
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
volatile uint32_t rxMsgCount = 0;
|
||||
volatile uint32_t errorFlag = 0;
|
||||
uint16_t txMsgData[4];
|
||||
uint16_t rxMsgData[4];
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
__interrupt void canbISR(void); // Receive interrupt for CAN-B.
|
||||
// No Transmit interrupt for CAN-A
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
// on module A and B. The device.h file may need to be modified to
|
||||
// reflect the chosen GPIO pins in your board.
|
||||
//
|
||||
Device_initGPIO();
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXB);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXB);
|
||||
|
||||
//
|
||||
// Initialize the CAN controllers
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
CAN_initModule(CANB_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 20);
|
||||
CAN_setBitRate(CANB_BASE, DEVICE_SYSCLK_FREQ, 500000, 20);
|
||||
|
||||
//
|
||||
// Enable interrupts on the CAN B peripheral.
|
||||
// Enables Int.line0, Error & Status Change interrupts
|
||||
//
|
||||
CAN_enableInterrupt(CANB_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
|
||||
//
|
||||
Interrupt_initModule();
|
||||
|
||||
//
|
||||
// Initialize the PIE vector table with pointers to the shell Interrupt
|
||||
// Service Routines (ISR).
|
||||
//
|
||||
Interrupt_initVectorTable();
|
||||
|
||||
//
|
||||
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
|
||||
//
|
||||
EINT;
|
||||
ERTM;
|
||||
|
||||
//
|
||||
// Interrupts that are used in this example are re-mapped to
|
||||
// ISR functions found within this file.
|
||||
// This registers the interrupt handler in PIE vector table.
|
||||
//
|
||||
Interrupt_register(INT_CANB0, &canbISR);
|
||||
|
||||
//
|
||||
// Enable the CAN-B interrupt signal
|
||||
//
|
||||
Interrupt_enable(INT_CANB0);
|
||||
|
||||
//
|
||||
// Set GLBINT0_EN bit in CAN_GLB_INT_EN register
|
||||
//
|
||||
CAN_enableGlobalInterrupt(CANB_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object used for sending CAN messages.
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x95555555
|
||||
// Message Frame: Extended
|
||||
// Message Type: Transmit
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 4 Bytes
|
||||
// No interrupts are enabled for the Transmit side
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x95555555,
|
||||
CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_TX, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the receive message object used for receiving CAN messages.
|
||||
// Message Object Parameters:
|
||||
// CAN Module: B
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x95555555
|
||||
// Message Frame: Extended
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: Receive Interrupt
|
||||
// Message Data Length: 4 Bytes (Note that DLC field is a "don't care"
|
||||
// for a Receive mailbox)
|
||||
//
|
||||
CAN_setupMessageObject(CANB_BASE, RX_MSG_OBJ_ID, 0x95555555,
|
||||
CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_RX, 0,
|
||||
CAN_MSG_OBJ_RX_INT_ENABLE, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object data buffer to be sent
|
||||
//
|
||||
txMsgData[0] = 0x12;
|
||||
txMsgData[1] = 0x34;
|
||||
txMsgData[2] = 0x56;
|
||||
txMsgData[3] = 0x78;
|
||||
|
||||
//
|
||||
// Start CAN module A and B operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
CAN_startModule(CANB_BASE);
|
||||
|
||||
//
|
||||
// Transmit messages from CAN-A to CAN-B
|
||||
//
|
||||
for(i = 0; i < TXCOUNT; i++)
|
||||
{
|
||||
//
|
||||
// Check the error flag to see if errors occurred
|
||||
//
|
||||
if(errorFlag)
|
||||
{
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// Verify that the number of transmitted messages equal the number of
|
||||
// messages received before sending a new message
|
||||
//
|
||||
if(txMsgCount == rxMsgCount)
|
||||
{
|
||||
CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH,
|
||||
txMsgData);
|
||||
txMsgCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorFlag = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Delay 0.25 second before continuing
|
||||
//
|
||||
DEVICE_DELAY_US(250000);
|
||||
|
||||
//
|
||||
// Increment the value in the transmitted message data.
|
||||
//
|
||||
txMsgData[0] += 0x01;
|
||||
txMsgData[1] += 0x01;
|
||||
txMsgData[2] += 0x01;
|
||||
txMsgData[3] += 0x01;
|
||||
|
||||
//
|
||||
// Reset data if exceeds a byte
|
||||
//
|
||||
if(txMsgData[0] > 0xFF)
|
||||
{
|
||||
txMsgData[0] = 0;
|
||||
}
|
||||
if(txMsgData[1] > 0xFF)
|
||||
{
|
||||
txMsgData[1] = 0;
|
||||
}
|
||||
if(txMsgData[2] > 0xFF)
|
||||
{
|
||||
txMsgData[2] = 0;
|
||||
}
|
||||
if(txMsgData[3] > 0xFF)
|
||||
{
|
||||
txMsgData[3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Stop application
|
||||
//
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// CAN B ISR - The interrupt service routine is called when an interrupt is
|
||||
// triggered on CAN module B. It will be executed twice for every
|
||||
// frame received.
|
||||
// First time for status-change; second time for Mailbox receive.
|
||||
//
|
||||
__interrupt void
|
||||
canbISR(void)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
//
|
||||
// Read the CAN-B interrupt status (in the CAN_INT register) to find the
|
||||
// cause of the interrupt
|
||||
//
|
||||
status = CAN_getInterruptCause(CANB_BASE);
|
||||
|
||||
//
|
||||
// If the cause is a controller status interrupt, then get the status.
|
||||
// During first iteration of every ISR execution, status = 0x8000,
|
||||
// which simply means CAN_ES != 0x07.
|
||||
//
|
||||
if(status == CAN_INT_INT0ID_STATUS)
|
||||
{
|
||||
//
|
||||
// Read the controller status. This will return a field of status
|
||||
// error bits that can indicate various errors. Error processing
|
||||
// is not done in this example for simplicity. Refer to the
|
||||
// API documentation for details about the error status bits.
|
||||
// The act of reading this status will clear the interrupt.
|
||||
//
|
||||
status = CAN_getStatus(CANB_BASE); // Return CAN_ES value.
|
||||
//
|
||||
// Now status = 0x00000010, indicating RxOK.
|
||||
//
|
||||
|
||||
//
|
||||
// Check to see if an error occurred.
|
||||
//
|
||||
if(((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_MSK) &&
|
||||
((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_NONE))
|
||||
{
|
||||
//
|
||||
// Set a flag to indicate some errors may have occurred.
|
||||
//
|
||||
errorFlag = 1;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Check if the cause is the CAN-B receive message object 1. Will be skipped
|
||||
// in the first iteration of every ISR execution
|
||||
//
|
||||
else if(status == RX_MSG_OBJ_ID)
|
||||
{
|
||||
//
|
||||
// Get the received message
|
||||
//
|
||||
CAN_readMessage(CANB_BASE, RX_MSG_OBJ_ID, rxMsgData);
|
||||
|
||||
//
|
||||
// Getting to this point means that the RX interrupt occurred on
|
||||
// message object 1, and the message RX is complete. Clear the
|
||||
// message object interrupt.
|
||||
//
|
||||
CAN_clearInterruptStatus(CANB_BASE, RX_MSG_OBJ_ID);
|
||||
|
||||
//
|
||||
// Increment a counter to keep track of how many messages have been
|
||||
// received. In a real application this could be used to set flags to
|
||||
// indicate when a message is received.
|
||||
//
|
||||
rxMsgCount++;
|
||||
|
||||
//
|
||||
// Since the message was received, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
}
|
||||
//
|
||||
// If something unexpected caused the interrupt, this would handle it.
|
||||
//
|
||||
else
|
||||
{
|
||||
//
|
||||
// Spurious interrupt handling can go here.
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Clear the global interrupt flag for the CAN interrupt line
|
||||
//
|
||||
CAN_clearGlobalInterruptStatus(CANB_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
//
|
||||
// Acknowledge this interrupt located in group 9
|
||||
//
|
||||
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,172 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex4_simple_transmit.c
|
||||
//
|
||||
// TITLE: CAN simple External Transmit Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN-A External Transmit </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A for external communication.
|
||||
//! CAN-A module is setup to transmit data for "n" number of times,
|
||||
//! where "n" is the value of TXCOUNT. Another CAN node configured for the
|
||||
//! same bit-rate is needed to provide the ACK. No interrupts are used.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with CAN transceiver and another CAN node configured
|
||||
//! for the same bit-rate to provide the ACK.
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - TXCOUNT - Adjust to set the number of messages to be transmitted
|
||||
//! - txMsgCount - A counter for the number of messages sent
|
||||
//! - txMsgData - An array with the data being sent
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
// $TI Release: $
|
||||
// $Release Date: $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define TXCOUNT 100000
|
||||
#define MSG_DATA_LENGTH 8
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile unsigned long i;
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
uint16_t txMsgData[8];
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
// on module A
|
||||
//
|
||||
Device_initGPIO();
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
|
||||
//
|
||||
// Initialize the CAN controllers
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object used for sending CAN messages.
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x01
|
||||
// Message Frame: Standard
|
||||
// Message Type: Transmit
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 4 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x1,
|
||||
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_TX, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the transmit message object data buffer to be sent
|
||||
//
|
||||
txMsgData[0] = 0x01;
|
||||
txMsgData[1] = 0x23;
|
||||
txMsgData[2] = 0x45;
|
||||
txMsgData[3] = 0x67;
|
||||
txMsgData[4] = 0x89;
|
||||
txMsgData[5] = 0xAB;
|
||||
txMsgData[6] = 0xCD;
|
||||
txMsgData[7] = 0xEF;
|
||||
|
||||
//
|
||||
// Start CAN module A operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Transmit messages from CAN-A
|
||||
//
|
||||
while(1)
|
||||
//
|
||||
// Comment for infinite transmissions
|
||||
//
|
||||
//for(i = 0; i < TXCOUNT; i++)
|
||||
//
|
||||
{
|
||||
CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH, txMsgData);
|
||||
|
||||
//
|
||||
// Poll TxOk bit in CAN_ES register to check completion of transmission
|
||||
//
|
||||
while(((HWREGH(CANA_BASE + CAN_O_ES) & CAN_ES_TXOK)) != CAN_ES_TXOK)
|
||||
{
|
||||
}
|
||||
}
|
||||
//
|
||||
// Stop application
|
||||
//
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,162 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex5_simple_receive.c
|
||||
//
|
||||
// TITLE: CAN Simple Receive Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN simple example that illustrates data reception </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A for Reception. When a frame with a
|
||||
//! STD-MSGID of 0x1 is received, the data will be copied in mailbox 1.
|
||||
//! If a message of any other MSGID is received, an ACK will be provided.
|
||||
//! GPIO65 will be toggled in both cases. Completion of reception
|
||||
//! is determined by polling. No interrupts are used.
|
||||
//! Note: RxOK bit is set even when the MSGID does not match.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - An external CAN node that transmits to CAN-A on the C2000 MCU
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - rxMsgCount - A counter for the number of messages received
|
||||
//! - rxMsgData - An array with the data that was received
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
// $Release Date: $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 0 // "Don't care" for a Receive mailbox
|
||||
#define RX_MSG_OBJ_ID 1 // Use mailbox 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
uint16_t rxMsgData[8];
|
||||
volatile uint32_t rxMsgCount = 0;
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO
|
||||
//
|
||||
Device_initGPIO();
|
||||
|
||||
//
|
||||
// Configure GPIO pins for CANTX/CANRX
|
||||
//
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
|
||||
//
|
||||
// Configure GPIO pin which is toggled upon message reception
|
||||
//
|
||||
GPIO_setPadConfig(65U, GPIO_PIN_TYPE_STD);
|
||||
GPIO_setDirectionMode(65U, GPIO_DIR_MODE_OUT);
|
||||
|
||||
//
|
||||
// Initialize the CAN controller
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Initialize the receive message object used for receiving CAN messages.
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x1
|
||||
// Message Frame: Standard
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: "Don't care" for a Receive mailbox
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, RX_MSG_OBJ_ID, 0x1,
|
||||
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Start CAN module A operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Start reception - Just wait for data from another node
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
//
|
||||
// Poll RxOk bit in CAN_ES register to check completion of Reception
|
||||
//
|
||||
if(((HWREGH(CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) == CAN_ES_RXOK)
|
||||
{
|
||||
//
|
||||
// Get the received message
|
||||
//
|
||||
CAN_readMessage(CANA_BASE, RX_MSG_OBJ_ID, rxMsgData);
|
||||
GPIO_togglePin(65U);
|
||||
rxMsgCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,239 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex8_remote_tx.c
|
||||
//
|
||||
// TITLE: CAN Remote-Frame Transmit Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN-A Remote-Frame Transmit </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A for external communication.
|
||||
//! It demonstrates the ability of the module to transmit a Remote-frame
|
||||
//! and receive a response in the same mailbox. CAN-B node is configured
|
||||
//! to respond to the Remote frame. No interrupts are used.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with CAN transceiver and another CAN node configured
|
||||
//! for the same bit-rate to provide the response to the Remote frame.
|
||||
//! In this example, CAN-B is the "other node".
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - TXCOUNT - Adjust to set the number of Remote frames to be transmitted
|
||||
//! - txMsgCount - A counter for the number of messages sent
|
||||
//! - rxMsgData - An array with the data being received
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
// $Release Date: $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define TXCOUNT 1
|
||||
#define MSG_DATA_LENGTH 8
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile unsigned long i;
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
|
||||
//
|
||||
// Buffer to store the message Received by node A
|
||||
//
|
||||
uint16_t rxMsgData[8];
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
// on modules A & B
|
||||
//
|
||||
Device_initGPIO();
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXB);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXB);
|
||||
|
||||
//
|
||||
// Initialize the CAN controllers
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
CAN_initModule(CANB_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
CAN_setBitRate(CANB_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Initialize the mailbox used for sending the remote frame
|
||||
// - and receiving the corresponding data frame
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x111
|
||||
// Message Frame: Standard
|
||||
// Message Type: Receive (but transmits a Remote frame first)
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 8 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x111,
|
||||
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RX, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the mailbox used for responding to the remote frame
|
||||
// Message Object Parameters:
|
||||
// CAN Module: B
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x111
|
||||
// Message Frame: Standard
|
||||
// Message Type: Transmit (Auto respond to a remote frame)
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 8 Bytes ("Don't care" for this MBX)
|
||||
//
|
||||
CAN_setupMessageObject(CANB_BASE, TX_MSG_OBJ_ID, 0x111,
|
||||
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RXTX_REMOTE, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Initialize the receive buffer to a known value
|
||||
//
|
||||
rxMsgData[0] = 0;
|
||||
rxMsgData[1] = 0;
|
||||
rxMsgData[2] = 0;
|
||||
rxMsgData[3] = 0;
|
||||
rxMsgData[4] = 0;
|
||||
rxMsgData[5] = 0;
|
||||
rxMsgData[6] = 0;
|
||||
rxMsgData[7] = 0;
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
CAN_startModule(CANB_BASE);
|
||||
|
||||
//
|
||||
// Copy data into the mailbox1 RAM of CAN-B. This is the data that will be
|
||||
// automatically transmitted in response to a remote frame.
|
||||
//
|
||||
// Wait for busy bit to clear
|
||||
//
|
||||
while((HWREGH(CANB_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) ==
|
||||
CAN_IF1CMD_BUSY)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Write to IF1DATA & IF1DATB registers
|
||||
//
|
||||
HWREG_BP(CANB_BASE + CAN_O_IF1DATA) = 0x67452301UL;
|
||||
HWREG_BP(CANB_BASE + CAN_O_IF1DATB) = 0xEFCDAB89UL;
|
||||
|
||||
//
|
||||
// Transfer to MBX RAM
|
||||
//
|
||||
HWREG_BP(CANB_BASE + CAN_O_IF1CMD) = 0x00830001UL;
|
||||
|
||||
//
|
||||
// Wait for busy bit to clear
|
||||
//
|
||||
while((HWREGH(CANB_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) ==
|
||||
CAN_IF1CMD_BUSY)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Transmit Remote frame(s) from CAN-A and await data frame(s) from node B
|
||||
//
|
||||
//while(1) // Uncomment for infinite transmissions
|
||||
for(i = 0; i < TXCOUNT; i++)
|
||||
{
|
||||
//
|
||||
// Initiate transmission of remote frame. "rxMsgData" is "dummy"
|
||||
// No data will go out on a Remote Frame
|
||||
//
|
||||
CAN_sendRemoteRequestMessage(CANA_BASE, TX_MSG_OBJ_ID);
|
||||
|
||||
//
|
||||
// Poll TxOk bit in CAN_ES register to check completion of transmission
|
||||
//
|
||||
while(((HWREG_BP(CANA_BASE + CAN_O_ES) & CAN_ES_TXOK)) !=
|
||||
CAN_ES_TXOK){}
|
||||
|
||||
txMsgCount++; // Increment TX counter
|
||||
|
||||
//
|
||||
// Poll RxOk bit in CAN_ES register to check completion of reception
|
||||
//
|
||||
while(((HWREG_BP(CANA_BASE + CAN_O_ES) & CAN_ES_RXOK)) !=
|
||||
CAN_ES_RXOK){}
|
||||
|
||||
CAN_readMessage(CANA_BASE, 1, rxMsgData);
|
||||
}
|
||||
|
||||
//
|
||||
// Stop application
|
||||
//
|
||||
asm(" ESTOP0");
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,176 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex9_remote_answer.c
|
||||
//
|
||||
// TITLE: CAN Remote-Frame Auto-answer Example
|
||||
//
|
||||
//! \addtogroup driver_example_list
|
||||
//! <h1> CAN-A Remote-Frame Auto-answer </h1>
|
||||
//!
|
||||
//! This example initializes CAN module A for external communication.
|
||||
//! It demonstrates the ability of the module to respond to a Remote-frame.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with CAN transceiver and another CAN node configured
|
||||
//! for the same bit-rate to transmit the Remote frame.
|
||||
//!
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//!
|
||||
//! - txMsgCount - A counter for the number of data frames sent
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
// $Release $
|
||||
// $Copyright:
|
||||
// Copyright (C) 2013-2024 Texas Instruments Incorporated - http://www.ti.com/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
//
|
||||
// Neither the name of Texas Instruments Incorporated nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// $
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 8
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
Device_init();
|
||||
|
||||
//
|
||||
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
|
||||
// on modules A & B
|
||||
//
|
||||
Device_initGPIO();
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
|
||||
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
|
||||
|
||||
//
|
||||
// Initialize the CAN controllers
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz for each module
|
||||
// Refer to the Driver Library User Guide for information on how to set
|
||||
// tighter timing control. Additionally, consult the device data sheet
|
||||
// for more information about the CAN module clocking.
|
||||
//
|
||||
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Initialize the mailbox used for sending the data frame
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// Message Object ID Number: 1
|
||||
// Message Identifier: 0x111
|
||||
// Message Frame: Standard
|
||||
// Message Type: Transmit (with auto-answer)
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 8 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x111,
|
||||
CAN_MSG_FRAME_STD, CAN_MSG_OBJ_TYPE_RXTX_REMOTE, 0,
|
||||
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Copy data into the mailbox1 RAM of CAN-A. This is the data that will be
|
||||
// automatically transmitted in response to a remote frame.
|
||||
|
||||
//
|
||||
// Wait for busy bit to clear
|
||||
//
|
||||
while((HWREGH(CANA_BASE +CAN_O_IF1CMD) & CAN_IF1CMD_BUSY)==CAN_IF1CMD_BUSY)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Write to IF1DATA & IF1DATB registers
|
||||
//
|
||||
HWREG_BP(CANA_BASE + CAN_O_IF1DATA) = 0x44332211UL;
|
||||
HWREG_BP(CANA_BASE + CAN_O_IF1DATB) = 0x88776655UL;
|
||||
|
||||
//
|
||||
// Transfer to MBX RAM
|
||||
//
|
||||
HWREG_BP(CANA_BASE + CAN_O_IF1CMD) = 0x00830001UL;
|
||||
|
||||
//
|
||||
// Wait for busy bit to clear
|
||||
//
|
||||
while((HWREGH(CANA_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY) ==
|
||||
CAN_IF1CMD_BUSY)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Wait and Transmit data frame(s)in response to Remote frame(s)
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
//
|
||||
// Poll TxOk bit in CAN_ES register to check completion of transmission
|
||||
//
|
||||
while(((HWREGH(CANA_BASE + CAN_O_ES) & CAN_ES_TXOK)) != CAN_ES_TXOK)
|
||||
{
|
||||
}
|
||||
|
||||
txMsgCount++; // Increment TX counter
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
Reference in New Issue
Block a user