Update repo
This commit is contained in:
1 parent
749dab5721
commit
ce65a0f59a
14950 files changed
+4408250
-1
No files matched your search
@@ -0,0 +1,25 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_config_c28x"
|
||||
device="TMS320F28388D"
|
||||
cgtVersion="22.6.1.LTS"
|
||||
products="C2000WARE"
|
||||
outputFormat="ELF"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
>
|
||||
<configuration name="CPU1_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -v28 -ml -mt --cla_support=cla2 --define RAM --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define=CANA --define=CANB --diag_warning=225 --diag_suppress=10063" linkerBuildOptions="--entry_point code_start --stack_size=0x3F8 --heap_size=0x200" />
|
||||
<configuration name="CPU1_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define=CANA --define=CANB --diag_warning=225 --diag_suppress=10063" linkerBuildOptions="--entry_point code_start --stack_size=0x3F8 --heap_size=0x200" />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib/" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/driverlib.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/device.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/device.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_RAM_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="CPU1_FLASH" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="device" />
|
||||
<file action="link" path="../../../../../../driverlib/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="" />
|
||||
<file action="copy" path="../../../../../../driverlib/f2838x/driverlib/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="copy" path="../../../c28x/cm_common_config_c28x/cm_common_config_c28x.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,25 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex1_polling"
|
||||
device="Cortex M.TMS320F28388D"
|
||||
cgtVersion="20.2.7.LTS"
|
||||
products="C2000WARE"
|
||||
endianness="little"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
>
|
||||
<configuration name="CM_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a --define RAM" />
|
||||
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none --define=_FLASH -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/driverlib_cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/cm.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_RAM_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_FLASH" />
|
||||
<file action="copy" path="../../../../../../driverlib/f2838x/driverlib_cm/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="link" path="../../../../../../driverlib/f2838x/driverlib_cm/ccs/Debug/driverlib_cm.lib" targetDirectory="" />
|
||||
<file action="copy" path="../can_ex1_polling.c" targetDirectory="" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex2_loopback_interrupts"
|
||||
device="Cortex M.TMS320F28388D"
|
||||
cgtVersion="20.2.7.LTS"
|
||||
products="C2000WARE"
|
||||
endianness="little"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
>
|
||||
<configuration name="CM_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a --define RAM" />
|
||||
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none --define=_FLASH -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/driverlib_cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/cm.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_RAM_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_FLASH" />
|
||||
<file action="copy" path="../../../../../../driverlib/f2838x/driverlib_cm/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="link" path="../../../../../../driverlib/f2838x/driverlib_cm/ccs/Debug/driverlib_cm.lib" targetDirectory="" />
|
||||
<file action="copy" path="../can_ex2_loopback_interrupts.c" targetDirectory="" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,25 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex3_external_transmit"
|
||||
device="Cortex M.TMS320F28388D"
|
||||
cgtVersion="20.2.7.LTS"
|
||||
products="C2000WARE"
|
||||
endianness="little"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
>
|
||||
<configuration name="CM_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a --define RAM" />
|
||||
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none --define=_FLASH -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/driverlib_cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/cm.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_RAM_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_FLASH" />
|
||||
<file action="copy" path="../../../../../../driverlib/f2838x/driverlib_cm/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="link" path="../../../../../../driverlib/f2838x/driverlib_cm/ccs/Debug/driverlib_cm.lib" targetDirectory="" />
|
||||
<file action="copy" path="../can_ex3_external_transmit.c" targetDirectory="" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,25 @@
|
||||
<projectSpec>
|
||||
<project
|
||||
name="can_ex4_transmit_receive"
|
||||
device="Cortex M.TMS320F28388D"
|
||||
cgtVersion="20.2.7.LTS"
|
||||
products="C2000WARE"
|
||||
endianness="little"
|
||||
launchWizard="False"
|
||||
linkerCommandFile=""
|
||||
>
|
||||
<configuration name="CM_RAM" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a --define RAM" />
|
||||
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=DEBUG --float_support=none --define=_FLASH -mv7M4 -me --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a " />
|
||||
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/driverlib_cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/include/cm.h" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/cm.c" targetDirectory="device" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="targetConfigs" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_RAM_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_RAM" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_FLASH" />
|
||||
<file action="copy" path="../../../../../../driverlib/f2838x/driverlib_cm/" targetDirectory="device" excludeFromBuild="True" />
|
||||
<file action="link" path="../../../../../../driverlib/f2838x/driverlib_cm/ccs/Debug/driverlib_cm.lib" targetDirectory="" />
|
||||
<file action="copy" path="../can_ex4_transmit_receive.c" targetDirectory="" />
|
||||
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
|
||||
</project>
|
||||
</projectSpec>
|
||||
@@ -0,0 +1,195 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex1_loopback.c
|
||||
//
|
||||
// TITLE: CAN Loopback Example
|
||||
//
|
||||
//! \addtogroup driver_example_cm_list
|
||||
//! <h1> CAN 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. 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.
|
||||
//!
|
||||
//! Before running this example, please run the can_config_c28x example
|
||||
//! from the c28x folder. It will initialize the clock, configure the GPIOs
|
||||
//! and allocate CAN A to CM.
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - None.
|
||||
//!
|
||||
//! \b Watch \b Variables \n
|
||||
//! - msgCount - A counter for the number of successful messages received.
|
||||
//! - rxMsgData - An array with the data that was received.
|
||||
//! - txMsgData - An array with the data being sent.
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "cm.h"
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#define MSG_DATA_LENGTH 2
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
volatile unsigned long msgCount = 0;
|
||||
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
volatile uint32_t delay;
|
||||
uint8_t txMsgData[2], rxMsgData[2];
|
||||
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
CM_init();
|
||||
|
||||
//
|
||||
// Initialize the CAN controller
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz
|
||||
// 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, CM_CLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// 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: 0x1234
|
||||
// Message Frame: Standard
|
||||
// Message Type: Transmit
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 2 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, 1, 0x1234, CAN_MSG_FRAME_STD,
|
||||
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:
|
||||
// Message Object ID Number: 2
|
||||
// Message Identifier: 0x1234
|
||||
// Message Frame: Standard
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 2 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, 2, 0x1234, CAN_MSG_FRAME_STD,
|
||||
CAN_MSG_OBJ_TYPE_RX, 0, CAN_MSG_OBJ_NO_FLAGS,
|
||||
MSG_DATA_LENGTH);
|
||||
|
||||
//
|
||||
// Start CAN module operations
|
||||
//
|
||||
CAN_startModule(CANA_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(CANA_BASE, 1, MSG_DATA_LENGTH, txMsgData);
|
||||
|
||||
//
|
||||
// Delay before receiving the data
|
||||
//
|
||||
for(delay = 0U; delay < 50000; delay++);
|
||||
|
||||
//
|
||||
// Read CAN message object 2 and check for new data
|
||||
//
|
||||
if (CAN_readMessage(CANA_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]))
|
||||
{
|
||||
//
|
||||
// Device will halt here if transmitted and received data are
|
||||
// not same.
|
||||
//
|
||||
__asm(" bkpt #0");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Increment message received counter
|
||||
//
|
||||
msgCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Device will halt here during debug if no new data was received.
|
||||
//
|
||||
__asm(" bkpt #0");
|
||||
}
|
||||
|
||||
//
|
||||
// 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,373 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex2_loopback_interrupts.c
|
||||
//
|
||||
// TITLE: CAN External Loopback with Interrupts Example
|
||||
//
|
||||
//! \addtogroup driver_example_cm_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. Please refer to details of the External Loopback
|
||||
//! Test Mode in the CAN Chapter in the Technical Reference Manual.
|
||||
//!
|
||||
//! Before running this example, please run the can_config_c28x example
|
||||
//! from the c28x folder. It will initialize the clock, configure the GPIOs
|
||||
//! and allocate CAN A to CM.
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - None.
|
||||
//!
|
||||
//! \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
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
//
|
||||
//
|
||||
// C2000Ware v5.04.00.00
|
||||
//
|
||||
// Copyright (C) 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 "cm.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;
|
||||
uint8_t txMsgData[4];
|
||||
uint8_t rxMsgData[4];
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
__interrupt void canISR(void);
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
volatile uint32_t delay;
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
CM_init();
|
||||
|
||||
//
|
||||
// Initialize the CAN controller
|
||||
//
|
||||
CAN_initModule(CANA_BASE);
|
||||
|
||||
//
|
||||
// Set up the CAN bus bit rate to 500kHz
|
||||
// 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, CM_CLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Enable interrupts on the CAN peripheral.
|
||||
//
|
||||
CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// 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_registerHandler(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
|
||||
//
|
||||
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)
|
||||
{
|
||||
//
|
||||
// Device will halt here if there has been an error.
|
||||
//
|
||||
__asm(" bkpt #0");
|
||||
}
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorFlag = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Delay before continuing
|
||||
//
|
||||
for(delay = 0U; delay < 50000; delay++);
|
||||
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,356 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex3_external_transmit.c
|
||||
//
|
||||
// TITLE: CAN External Transmit Example
|
||||
//
|
||||
//! \addtogroup driver_example_cm_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.
|
||||
//!
|
||||
//! Before running this example, please run the can_config_c28x example
|
||||
//! from the c28x folder. It will initialize the clock, configure the GPIOs
|
||||
//! and allocate CAN A and CAN B to CM.
|
||||
//!
|
||||
//! \note Both CAN modules on the device need to be connected to each other
|
||||
//! via CAN transceivers.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with two CAN transceivers
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - ControlCARD CANA is on GPIO37 (CANTXA) and GPIO36 (CANRXA)
|
||||
//! - ControlCARD CANB is on GPIO12 (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
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
//
|
||||
//
|
||||
//
|
||||
// C2000Ware v5.04.00.00
|
||||
//
|
||||
// Copyright (C) 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 "cm.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;
|
||||
uint8_t txMsgData[4];
|
||||
uint8_t rxMsgData[4];
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
__interrupt void canbISR(void);
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
volatile uint32_t delay;
|
||||
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
CM_init();
|
||||
|
||||
//
|
||||
// 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, CM_CLK_FREQ, 500000, 16);
|
||||
CAN_setBitRate(CANB_BASE, CM_CLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Enable interrupts on the CAN B peripheral.
|
||||
//
|
||||
CAN_enableInterrupt(CANB_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// 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_registerHandler(INT_CANB0, &canbISR);
|
||||
|
||||
//
|
||||
// Enable the CAN-B interrupt signal
|
||||
//
|
||||
Interrupt_enable(INT_CANB0);
|
||||
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: 0x15555555
|
||||
// Message Frame: Extended
|
||||
// Message Type: Transmit
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: None
|
||||
// Message Data Length: 4 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x15555555,
|
||||
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: 0x15555555
|
||||
// Message Frame: Extended
|
||||
// Message Type: Receive
|
||||
// Message ID Mask: 0x0
|
||||
// Message Object Flags: Receive Interrupt
|
||||
// Message Data Length: 4 Bytes
|
||||
//
|
||||
CAN_setupMessageObject(CANB_BASE, RX_MSG_OBJ_ID, 0x15555555,
|
||||
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)
|
||||
{
|
||||
//
|
||||
// Device will halt here if there has been an error.
|
||||
//
|
||||
__asm(" bkpt #0");
|
||||
}
|
||||
|
||||
//
|
||||
// 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 before continuing
|
||||
//
|
||||
for(delay=0U; delay<50000; delay++);
|
||||
|
||||
//
|
||||
// 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(" bkpt #0");
|
||||
}
|
||||
|
||||
//
|
||||
// CAN B ISR - The interrupt service routine called when a CAN interrupt is
|
||||
// triggered on CAN module B.
|
||||
//
|
||||
__interrupt void
|
||||
canbISR(void)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
//
|
||||
// Read the CAN-B interrupt status to find the cause of the interrupt
|
||||
//
|
||||
status = CAN_getInterruptCause(CANB_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(CANB_BASE);
|
||||
|
||||
//
|
||||
// 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
|
||||
//
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
@@ -0,0 +1,367 @@
|
||||
//#############################################################################
|
||||
//
|
||||
// FILE: can_ex4_transmit_receive.c
|
||||
//
|
||||
// TITLE: CAN Configuration for Transmit and Receive.
|
||||
//
|
||||
//! \addtogroup driver_example_cm_list
|
||||
//! <h1> CAN Transmit and Receive Configurations </h1>
|
||||
//!
|
||||
//! This example shows the basic setup of CAN in order to transmit or receive
|
||||
//! messages on the CAN bus with a specific Message ID. The CAN Controller is
|
||||
//! configured according to the selection of the define.
|
||||
//!
|
||||
//! When the TRANSMIT define is selected, the CAN Controller acts as a
|
||||
//! Transmitter and sends data to the second CAN Controller connected
|
||||
//! externally.If TRANMSIT is not defined the CAN Controller acts as a Receiver
|
||||
//! and waits for message to be transmitted by the External CAN Controller.
|
||||
//!
|
||||
//! Before running this example, please run the can_config_c28x example
|
||||
//! from the c28x folder. It will initialize the clock, configure the GPIOs
|
||||
//! and allocate CAN A to CM.
|
||||
//!
|
||||
//! \note CAN modules on the device need to be connected to via CAN
|
||||
//! transceivers.
|
||||
//!
|
||||
//! \b Hardware \b Required \n
|
||||
//! - A C2000 board with CAN transceiver.
|
||||
//!
|
||||
//! \b External \b Connections \n
|
||||
//! - ControlCARD CANA is on GPIO37 (CANTXA) and GPIO36 (CANRXA)
|
||||
//!
|
||||
//! \b Watch \b Variables \b Transmit \Configuration \n
|
||||
//! - MSGCOUNT - Adjust to set the number of messages
|
||||
//! - txMsgCount - A counter for the number of messages sent
|
||||
//! - txMsgData - An array with the data being sent
|
||||
//! - errorFlag - A flag that indicates an error has occurred
|
||||
//! - rxMsgCount - Has the initial value as No. of Messages to be received
|
||||
//! and decrements with each message.
|
||||
//!
|
||||
//
|
||||
//#############################################################################
|
||||
|
||||
//
|
||||
// Included Files
|
||||
//
|
||||
#include "driverlib_cm.h"
|
||||
#include "cm.h"
|
||||
|
||||
//
|
||||
// Comment to Make the CAN Controller work as a Receiver.
|
||||
//
|
||||
#define TRANSMIT
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
#ifdef TRANSMIT
|
||||
#define TX_MSG_OBJ_ID 1
|
||||
#else
|
||||
#define RX_MSG_OBJ_ID 1
|
||||
#endif
|
||||
#define MSG_DATA_LENGTH 4
|
||||
#define MSGCOUNT 10
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
#ifdef TRANSMIT
|
||||
volatile uint32_t txMsgCount = 0;
|
||||
uint32_t txMsgSuccessful = 1;
|
||||
uint8_t txMsgData[4];
|
||||
#else
|
||||
volatile uint32_t rxMsgCount = MSGCOUNT;
|
||||
uint8_t rxMsgData[4];
|
||||
#endif
|
||||
|
||||
volatile unsigned long i;
|
||||
volatile uint32_t errorFlag = 0;
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
__interrupt void canaISR(void);
|
||||
|
||||
//
|
||||
// Main
|
||||
//
|
||||
void main(void)
|
||||
{
|
||||
volatile uint32_t delay;
|
||||
|
||||
//
|
||||
// Initialize device clock and peripherals
|
||||
//
|
||||
CM_init();
|
||||
|
||||
//
|
||||
// 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, CM_CLK_FREQ, 500000, 16);
|
||||
|
||||
//
|
||||
// Enable interrupts on the CAN A peripheral.
|
||||
//
|
||||
CAN_enableInterrupt(CANA_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
|
||||
CAN_INT_STATUS);
|
||||
|
||||
//
|
||||
// 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_registerHandler(INT_CANA0, &canaISR);
|
||||
|
||||
//
|
||||
// Enable the CAN-A interrupt signal
|
||||
//
|
||||
Interrupt_enable(INT_CANA0);
|
||||
|
||||
CAN_enableGlobalInterrupt(CANA_BASE, CAN_GLOBAL_INT_CANINT0);
|
||||
|
||||
#ifdef TRANSMIT
|
||||
//
|
||||
// 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
|
||||
//
|
||||
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x95555555,
|
||||
CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_TX, 0,
|
||||
CAN_MSG_OBJ_TX_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;
|
||||
#else
|
||||
//
|
||||
// Initialize the receive message object used for receiving CAN messages.
|
||||
// Message Object Parameters:
|
||||
// CAN Module: A
|
||||
// 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
|
||||
//
|
||||
CAN_setupMessageObject(CANA_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);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Start CAN module A operations
|
||||
//
|
||||
CAN_startModule(CANA_BASE);
|
||||
|
||||
#ifdef TRANSMIT
|
||||
//
|
||||
// Transmit messages from CAN-A.
|
||||
//
|
||||
for(i = 0; i < MSGCOUNT; i++)
|
||||
{
|
||||
//
|
||||
// Check the error flag to see if errors occurred
|
||||
//
|
||||
if(errorFlag)
|
||||
{
|
||||
__asm(" bkpt #0");
|
||||
}
|
||||
|
||||
//
|
||||
// Transmit the message.
|
||||
//
|
||||
CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH,
|
||||
txMsgData);
|
||||
|
||||
//
|
||||
// Delay before continuing
|
||||
//
|
||||
for(delay = 0U; delay < 50000; delay++);
|
||||
|
||||
while(txMsgSuccessful);
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
//
|
||||
// Update the flag for next message.
|
||||
//
|
||||
txMsgSuccessful = 1;
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Loop to keep receiving data from another CAN Controller.
|
||||
//
|
||||
while(rxMsgCount)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Stop the application.
|
||||
//
|
||||
__asm(" bkpt #0");
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// CAN A ISR - The interrupt service routine called when a CAN interrupt is
|
||||
// triggered on CAN module A.
|
||||
//
|
||||
__interrupt void
|
||||
canaISR(void)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
//
|
||||
// Read the CAN-B 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.
|
||||
//
|
||||
#ifdef TRANSMIT
|
||||
if(((status & ~(CAN_STATUS_TXOK)) != CAN_STATUS_LEC_MSK) &&
|
||||
((status & ~(CAN_STATUS_TXOK)) != CAN_STATUS_LEC_NONE))
|
||||
#else
|
||||
if(((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_MSK) &&
|
||||
((status & ~(CAN_STATUS_RXOK)) != CAN_STATUS_LEC_NONE))
|
||||
#endif
|
||||
{
|
||||
//
|
||||
// Set a flag to indicate some errors may have occurred.
|
||||
//
|
||||
errorFlag = 1;
|
||||
}
|
||||
}
|
||||
#ifdef TRANSMIT
|
||||
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
|
||||
// transmitted. In a real application this could be used to set flags to
|
||||
// indicate when a message is transmitted.
|
||||
//
|
||||
txMsgCount++;
|
||||
|
||||
//
|
||||
// Since the message was transmitted, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
|
||||
//
|
||||
// Clear the message transmitted successful Flag.
|
||||
//
|
||||
txMsgSuccessful = 0;
|
||||
}
|
||||
#else
|
||||
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);
|
||||
|
||||
//
|
||||
// Decrement the counter after a message has been received.
|
||||
//
|
||||
rxMsgCount--;
|
||||
|
||||
//
|
||||
// Since the message was received, clear any error flags.
|
||||
//
|
||||
errorFlag = 0;
|
||||
}
|
||||
#endif
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// End of File
|
||||
//
|
||||
Reference in new issue
Block a user