Update repo

This commit is contained in:
hangpersonal committed 2026-08-30 23:04:35 -07:00
1 parent 749dab5721
commit ce65a0f59a
14950 files changed
+4408250 -1

No files matched your search

@@ -0,0 +1,25 @@
<projectSpec>
<project
name="aes_ex1_ecb_encrypt"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../aes_ex1_ecb_encrypt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="aes_ex2_ecb_decrypt"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../aes_ex2_ecb_decrypt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="aes_ex3_gcm_encrypt"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../aes_ex3_gcm_encrypt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="aes_ex4_gcm_decrypt"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../aes_ex4_gcm_decrypt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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,591 @@
//#############################################################################
//
// FILE: aes_ex1_ecb_encrypt.c
//
// TITLE: AES ECB Encryption
//
//! \addtogroup driver_example_cm_list
//! <h1>AES ECB Encryption Example (CM)</h1>
//!
//! This example encrypts block cipher-text using AES128 in ECB mode. It does
//! the encryption first without uDMA and then with uDMA. The results are
//! checked after each operation.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
//
//
//
// 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 <string.h>
#include "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// The DMA control structure table.
//
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Output cipher-text array
//
uint32_t cipherTextArray[16];
//
// Global interrupt status
//
static volatile uint32_t intStatus = 0;
//
// The AES interrupt handler and interrupt flags.
//
static volatile bool contextInIntFlag;
static volatile bool dataInIntFlag;
static volatile bool contextOutIntFlag;
static volatile bool dataOutIntFlag;
static volatile bool contextInDMADoneIntFlag;
static volatile bool dataInDMADoneIntFlag;
static volatile bool contextOutDMADoneIntFlag;
static volatile bool dataOutDMADoneIntFlag;
//
// Structure for NIST AES ECB tests
//
typedef struct
{
AES_KeySize keySize;
uint32_t keyArray[8];
uint32_t dataLength;
uint32_t plainTextArray[16];
uint32_t cipherTextArray[16];
} testVectorECB;
//
// Test Cases from NIST ECB Revised Spec.
//
testVectorECB testVectorECBArray[] =
{
//
// Test Case #1 with 128 bit key
//
{
.keySize = AES_KEY_SIZE_128BIT,
.keyArray = { 0x16157e2b, 0xa6d2ae28, 0x8815f7ab, 0x3c4fcf09 },
.dataLength = 64U,
.plainTextArray = { 0xe2bec16b, 0x969f402e, 0x117e3de9, 0x2a179373,
0x578a2dae, 0x9cac031e, 0xac6fb79e, 0x518eaf45,
0x461cc830, 0x11e45ca3, 0x19c1fbe5, 0xef520a1a,
0x45249ff6, 0x179b4fdf, 0x7b412bad, 0x10376ce6 },
.cipherTextArray = { 0xb47bd73a, 0x60367a0d, 0xf3ca9ea8, 0x97ef6624,
0x85d5d3f5, 0x9d69b903, 0x5a8985e7, 0xafbafd96,
0x7fcdb143, 0x23ce8e59, 0xe3001b88, 0x880603ed,
0x5e780c7b, 0x3fade827, 0x71202382, 0xd45d7204 }
},
//
// Test Case #2 with 256 bit key
//
{
.keySize = AES_KEY_SIZE_256BIT,
.keyArray = { 0x10eb3d60, 0xbe71ca15, 0xf0ae732b, 0x81777d85,
0x072c351f, 0xd708613b, 0xa310982d, 0xf4df1409 },
.dataLength = 64U,
.plainTextArray = { 0xe2bec16b, 0x969f402e, 0x117e3de9, 0x2a179373,
0x578a2dae, 0x9cac031e, 0xac6fb79e, 0x518eaf45,
0x461cc830, 0x11e45ca3, 0x19c1fbe5, 0xef520a1a,
0x45249ff6, 0x179b4fdf, 0x7b412bad, 0x10376ce6 },
.cipherTextArray = { 0xbdd1eef3, 0x3ca0d2b5, 0x7e5a4b06, 0xf881b13d,
0x10cb1c59, 0x26ed10d4, 0x4aa75bdc, 0x70283631,
0xb921edb6, 0xf9f4a69c, 0xb1e753f1, 0x1dedafbe,
0x7a4b3023, 0xfff3f939, 0x8f8d7d06, 0xc7ec249e }
}
};
//
// Function Prototypes
//
void performECBEncryption(AES_KeySize keySize, uint32_t *srcArray,
uint32_t *dstArray, uint32_t *keyArray,
uint32_t dataLength, bool useDMA);
uint32_t roundUpDataLength(uint32_t dataLength);
//
// ISR for AESINT.
//
__interrupt void localAESIntISR(void);
//
// Main
//
void main(void)
{
uint32_t errCountLocal, cnt;
uint32_t *keyArray, dataLength;
uint32_t *expCipherTextArray, *plainTextArray;
uint32_t vectorCnt;
AES_KeySize keySize;
//
// Initialize device clock and peripherals
//
CM_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Enable AES interrupts.
//
Interrupt_enable(INT_AES);
AES_registerInterrupt(INT_AES, localAESIntISR);
Interrupt_enableInProcessor();
//
// Setup the control table.
//
UDMA_enable(UDMA_BASE);
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Perform AES Soft Reset
//
AES_performSoftReset(AES_BASE);
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorECBArray) /
sizeof(testVectorECBArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorECBArray[vectorCnt].keySize;
keyArray = testVectorECBArray[vectorCnt].keyArray;
dataLength = testVectorECBArray[vectorCnt].dataLength;
plainTextArray = testVectorECBArray[vectorCnt].plainTextArray;
expCipherTextArray = testVectorECBArray[vectorCnt].cipherTextArray;
//
// Clear the array containing the cipher text.
//
for(cnt = 0; cnt < 16; cnt++)
{
cipherTextArray[cnt] = 0;
}
//
// Perform Encryption without DMA.
//
performECBEncryption(keySize, plainTextArray, cipherTextArray, keyArray,
dataLength, false);
//
// Check the results
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(cipherTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
//
// Clear the array containing the cipher text.
//
for(cnt = 0; cnt < 16; cnt++)
{
cipherTextArray[cnt] = 0;
}
//
// Perform Encryption with DMA.
//
performECBEncryption(keySize, plainTextArray, cipherTextArray, keyArray,
dataLength, true);
//
// Check the results
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(cipherTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Clean up AES Data registers
//
AES_performSoftReset(AES_BASE);
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// Perform an AES-ECB encryption operation.
//
void performECBEncryption(AES_KeySize keySize, uint32_t *srcArray,
uint32_t *dstArray, uint32_t *keyArray,
uint32_t dataLength, bool useDMA)
{
//
// Perform a soft reset.
//
AES_performSoftReset(AES_BASE);
//
// Clear the interrupt flags.
//
contextInIntFlag = false;
dataInIntFlag = false;
contextOutIntFlag = false;
dataOutIntFlag = false;
contextInDMADoneIntFlag = false;
dataInDMADoneIntFlag = false;
contextOutDMADoneIntFlag = false;
dataOutDMADoneIntFlag = false;
//
// Configure the AES module.
//
AES_ConfigParams aesConfig;
memset(&aesConfig, 0, sizeof(AES_ConfigParams));
aesConfig.direction = AES_DIRECTION_ENCRYPT;
aesConfig.keySize = keySize;
aesConfig.opMode = AES_OPMODE_ECB;
AES_configureModule(AES_BASE, &aesConfig);
//
// Write the key.
//
AES_setKey1(AES_BASE, keyArray, keySize);
//
// Depending on the argument, perform the decryption
// with or without uDMA.
//
if(useDMA)
{
//
// Disable Non-DMA interrupts.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, (AES_INT_CONTEXT_IN |
AES_INT_CONTEXT_OUT | AES_INT_DATA_IN |
AES_INT_DATA_OUT));
//
// Enable DMA interrupts.
//
AES_enableInterrupt(AES_BASE, AESW_BASE, (AES_INT_DMA_CONTEXT_IN |
AES_INT_DMA_DATA_IN |
AES_INT_DMA_CONTEXT_OUT |
AES_INT_DMA_DATA_OUT));
//
// Setup the DMA module to copy data in.
//
UDMA_changeChannelMapping(UDMA_BASE, UDMA_CHANNEL_AES_DIN,
UDMA_CH_MAPPING_0);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_AES_DIN,
UDMA_CH_ATTR_ALL);
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_AES_DIN |
UDMA_PRI_SELECT), (UDMA_SIZE_32 |
UDMA_SRC_INC_32 |
UDMA_DST_INC_NONE |
UDMA_ARB_4 |
UDMA_DST_PROT_PRIV));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_AES_DIN |
UDMA_PRI_SELECT), (void*)srcArray,
(void*)(AES_BASE + AES_O_DATA_IN_OUT_0),
UDMA_MODE_BASIC, roundUpDataLength(dataLength) / 4U);
//
// Setup the DMA module to copy the data out.
//
UDMA_changeChannelMapping(UDMA_BASE, UDMA_CHANNEL_AES_DOUT,
UDMA_CH_MAPPING_0);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_AES_DOUT,
UDMA_CH_ATTR_ALL);
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_AES_DOUT |
UDMA_PRI_SELECT), (UDMA_SIZE_32 |
UDMA_SRC_INC_NONE |
UDMA_DST_INC_32 |
UDMA_ARB_4 |
UDMA_SRC_PROT_PRIV));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_AES_DOUT |
UDMA_PRI_SELECT),
(void*)(AES_BASE + AES_O_DATA_IN_OUT_0),
(void*)dstArray, UDMA_MODE_BASIC,
roundUpDataLength(dataLength) / 4U);
//
// Enable the DMA channels to start the transfers. This must be done after
// writing the length to prevent data from copying before the context is
// truly ready.
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_AES_DIN);
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_AES_DOUT);
//
// Enable DMA requests
//
AES_enableDMARequest(AES_BASE,(AES_DMA_EN_DATA_IN |
AES_DMA_EN_DATA_OUT));
//
// Wait for the data in DMA done interrupt.
//
while(!dataInDMADoneIntFlag)
{
}
//
// Wait for the data out DMA done interrupt.
//
while(!dataOutDMADoneIntFlag)
{
}
}
else
{
//
// Enable all interrupts.
//
AES_enableInterrupt(AES_BASE, AESW_BASE, (AES_INT_CONTEXT_IN |
AES_INT_CONTEXT_OUT | AES_INT_DATA_IN |
AES_INT_DATA_OUT));
//
// Perform the encryption.
//
AES_processData(AES_BASE, srcArray, dstArray, dataLength);
}
}
//
// Round up length to nearest 16 byte boundary. This is needed because all
// four data registers must be written at once. This is handled in the AES
// driver, but if using uDMA, the length must rounded up.
//
uint32_t roundUpDataLength(uint32_t dataLength)
{
uint32_t remainder;
remainder = dataLength % 16;
if(remainder == 0)
{
return(dataLength);
}
else
{
return(dataLength + (16 - remainder));
}
}
//
// localAESIntISR - local AES Interrupt ISR
//
void localAESIntISR(void)
{
//
// Read the AES masked interrupt status.
//
intStatus = AES_getInterruptStatus(AES_BASE, AESW_BASE, false);
//
// Print a different message depending on the interrupt source.
//
if(intStatus & AES_INT_CONTEXT_IN)
{
//
// Context input registers are ready.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_CONTEXT_IN);
contextInIntFlag = true;
}
if(intStatus & AES_INT_DATA_IN)
{
//
// Data FIFO is ready to receive data.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_DATA_IN);
dataInIntFlag = true;
}
if(intStatus & AES_INT_CONTEXT_OUT)
{
//
// Context output registers are ready.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_CONTEXT_OUT);
contextOutIntFlag = true;
}
if(intStatus & AES_INT_DATA_OUT)
{
//
// Data FIFO is ready to provide data.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_DATA_OUT);
dataOutIntFlag = true;
}
if(intStatus & AES_INT_DMA_CONTEXT_IN)
{
//
// DMA completed a context write to the internal registers.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_CONTEXT_IN);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_CONTEXT_IN);
contextInDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_DATA_IN)
{
//
// DMA has written the last word of input data to the internal FIFO of
// the engine.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_DATA_IN);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_DATA_IN);
dataInDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_CONTEXT_OUT)
{
//
// DMA completed the output context movement from the internal
// registers.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_CONTEXT_OUT);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_CONTEXT_OUT);
contextOutDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_DATA_OUT)
{
//
// DMA has written the last word of process result.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_DATA_OUT);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_DATA_OUT);
dataOutDMADoneIntFlag = true;
}
}
//
// End of File
//
@@ -0,0 +1,588 @@
//#############################################################################
//
// FILE: aes_ex2_ecb_decrypt.c
//
// TITLE: AES ECB Decryption
//
//! \addtogroup driver_example_cm_list
//! <h1>AES ECB De-cryption Example (CM)</h1>
//!
//! This example de-crypts block cipher-text using AES128 in ECB mode. It does
//! the de-cryption first without uDMA and then with uDMA. The results are
//! checked after each operation.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
//
//
//
// 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 <string.h>
#include "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// The DMA control structure table.
//
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Output plain-text array
//
uint32_t plainTextArray[16];
//
// Global interrupt status
//
static volatile uint32_t intStatus;
//
// The AES interrupt handler and interrupt flags.
//
static volatile bool contextInIntFlag;
static volatile bool dataInIntFlag;
static volatile bool contextOutIntFlag;
static volatile bool dataOutIntFlag;
static volatile bool contextInDMADoneIntFlag;
static volatile bool dataInDMADoneIntFlag;
static volatile bool contextOutDMADoneIntFlag;
static volatile bool dataOutDMADoneIntFlag;
//
// Structure for NIST AES ECB tests
//
typedef struct
{
AES_KeySize keySize;
uint32_t keyArray[8];
uint32_t dataLength;
uint32_t plainTextArray[16];
uint32_t cipherTextArray[16];
} testVectorECB;
//
// Test Cases from NIST ECB Revised Spec.
//
testVectorECB testVectorECBArray[] =
{
//
// Test Case #1 with 128 bit key
//
{
.keySize = AES_KEY_SIZE_128BIT,
.keyArray = { 0x16157e2b, 0xa6d2ae28, 0x8815f7ab, 0x3c4fcf09 },
.dataLength = 64U,
.plainTextArray = { 0xe2bec16b, 0x969f402e, 0x117e3de9, 0x2a179373,
0x578a2dae, 0x9cac031e, 0xac6fb79e, 0x518eaf45,
0x461cc830, 0x11e45ca3, 0x19c1fbe5, 0xef520a1a,
0x45249ff6, 0x179b4fdf, 0x7b412bad, 0x10376ce6 },
.cipherTextArray = { 0xb47bd73a, 0x60367a0d, 0xf3ca9ea8, 0x97ef6624,
0x85d5d3f5, 0x9d69b903, 0x5a8985e7, 0xafbafd96,
0x7fcdb143, 0x23ce8e59, 0xe3001b88, 0x880603ed,
0x5e780c7b, 0x3fade827, 0x71202382, 0xd45d7204 }
},
//
// Test Case #2 with 256 bit key
//
{
.keySize = AES_KEY_SIZE_256BIT,
.keyArray = { 0x10eb3d60, 0xbe71ca15, 0xf0ae732b, 0x81777d85,
0x072c351f, 0xd708613b, 0xa310982d, 0xf4df1409 },
.dataLength = 64U,
.plainTextArray = { 0xe2bec16b, 0x969f402e, 0x117e3de9, 0x2a179373,
0x578a2dae, 0x9cac031e, 0xac6fb79e, 0x518eaf45,
0x461cc830, 0x11e45ca3, 0x19c1fbe5, 0xef520a1a,
0x45249ff6, 0x179b4fdf, 0x7b412bad, 0x10376ce6 },
.cipherTextArray = { 0xbdd1eef3, 0x3ca0d2b5, 0x7e5a4b06, 0xf881b13d,
0x10cb1c59, 0x26ed10d4, 0x4aa75bdc, 0x70283631,
0xb921edb6, 0xf9f4a69c, 0xb1e753f1, 0x1dedafbe,
0x7a4b3023, 0xfff3f939, 0x8f8d7d06, 0xc7ec249e }
}
};
//
// Function Prototypes
//
void performECBDecryption(AES_KeySize keySize, uint32_t *srcArray,
uint32_t *dstArray, uint32_t *keyArray,
uint32_t dataLength, bool useDMA);
uint32_t roundUpDataLength(uint32_t dataLength);
//
// ISR for AESINT.
//
__interrupt void localAESIntISR(void);
//
// Main
//
void main(void)
{
uint32_t errCountLocal, cnt;
uint32_t *keyArray, dataLength;
uint32_t *expPlainTextArray, *cipherTextArray;
uint32_t vectorCnt;
AES_KeySize keySize;
//
// Initialize device clock and peripherals
//
CM_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Enable AES interrupts.
//
Interrupt_enable(INT_AES);
AES_registerInterrupt(INT_AES, localAESIntISR);
Interrupt_enableInProcessor();
//
// Setup the control table.
//
UDMA_enable(UDMA_BASE);
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Perform AES Soft Reset
//
AES_performSoftReset(AES_BASE);
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorECBArray) /
sizeof(testVectorECBArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorECBArray[vectorCnt].keySize;
keyArray = testVectorECBArray[vectorCnt].keyArray;
dataLength = testVectorECBArray[vectorCnt].dataLength;
expPlainTextArray = testVectorECBArray[vectorCnt].plainTextArray;
cipherTextArray = testVectorECBArray[vectorCnt].cipherTextArray;
//
// Clear the array containing the plain text.
//
for(cnt = 0; cnt < 16; cnt++)
{
plainTextArray[cnt] = 0;
}
//
// Perform decryption without DMA.
//
performECBDecryption(keySize, cipherTextArray, plainTextArray, keyArray,
dataLength, false);
//
// Check the results
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(plainTextArray[cnt] != expPlainTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
//
// Clear the array containing the plain text.
//
for(cnt = 0; cnt < 16; cnt++)
{
plainTextArray[cnt] = 0;
}
//
// Perform decryption with DMA.
//
performECBDecryption(keySize, cipherTextArray, plainTextArray, keyArray,
dataLength, true);
//
// Check the results.
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(plainTextArray[cnt] != expPlainTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Clean up AES Data registers
//
AES_performSoftReset(AES_BASE);
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// Perform an AES-ECB decryption operation.
//
void performECBDecryption(AES_KeySize keySize, uint32_t *srcArray,
uint32_t *dstArray, uint32_t *keyArray,
uint32_t dataLength, bool useDMA)
{
//
// Perform a soft reset.
//
AES_performSoftReset(AES_BASE);
//
// Clear the interrupt flags.
//
contextInIntFlag = false;
dataInIntFlag = false;
contextOutIntFlag = false;
dataOutIntFlag = false;
contextInDMADoneIntFlag = false;
dataInDMADoneIntFlag = false;
contextOutDMADoneIntFlag = false;
dataOutDMADoneIntFlag = false;
//
// Configure the AES module.
//
AES_ConfigParams aesConfig;
memset(&aesConfig, 0, sizeof(AES_ConfigParams));
aesConfig.direction = AES_DIRECTION_DECRYPT;
aesConfig.keySize = keySize;
aesConfig.opMode = AES_OPMODE_ECB;
AES_configureModule(AES_BASE, &aesConfig);
//
// Write the key.
//
AES_setKey1(AES_BASE, keyArray, keySize);
//
// Depending on the argument, perform the decryption
// with or without uDMA.
//
if(useDMA)
{
//
// Disable Non-DMA interrupts.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, (AES_INT_CONTEXT_IN |
AES_INT_CONTEXT_OUT | AES_INT_DATA_IN |
AES_INT_DATA_OUT));
//
// Enable DMA interrupts.
//
AES_enableInterrupt(AES_BASE, AESW_BASE, (AES_INT_DMA_CONTEXT_IN |
AES_INT_DMA_DATA_IN |
AES_INT_DMA_CONTEXT_OUT |
AES_INT_DMA_DATA_OUT));
//
// Setup the DMA module to copy data in.
//
UDMA_changeChannelMapping(UDMA_BASE, UDMA_CHANNEL_AES_DIN,
UDMA_CH_MAPPING_0);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_AES_DIN,
UDMA_CH_ATTR_ALL);
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_AES_DIN |
UDMA_PRI_SELECT), (UDMA_SIZE_32 |
UDMA_SRC_INC_32 |
UDMA_DST_INC_NONE |
UDMA_ARB_4 |
UDMA_DST_PROT_PRIV));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_AES_DIN |
UDMA_PRI_SELECT), (void*)srcArray,
(void*)(AES_BASE + AES_O_DATA_IN_OUT_0),
UDMA_MODE_BASIC, roundUpDataLength(dataLength) / 4U);
//
// Setup the DMA module to copy the data out.
//
UDMA_changeChannelMapping(UDMA_BASE, UDMA_CHANNEL_AES_DOUT,
UDMA_CH_MAPPING_0);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_AES_DOUT,
UDMA_CH_ATTR_ALL);
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_AES_DOUT |
UDMA_PRI_SELECT), (UDMA_SIZE_32 |
UDMA_SRC_INC_NONE |
UDMA_DST_INC_32 |
UDMA_ARB_4 |
UDMA_SRC_PROT_PRIV));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_AES_DOUT |
UDMA_PRI_SELECT),
(void*)(AES_BASE + AES_O_DATA_IN_OUT_0),
(void*)dstArray, UDMA_MODE_BASIC,
roundUpDataLength(dataLength) / 4U);
//
// Enable the DMA channels to start the transfers. This must be done after
// writing the length to prevent data from copying before the context is
// truly ready.
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_AES_DIN);
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_AES_DOUT);
//
// Enable DMA requests
//
AES_enableDMARequest(AES_BASE,(AES_DMA_EN_DATA_IN |
AES_DMA_EN_DATA_OUT));
//
// Wait for the data in DMA done interrupt.
//
while(!dataInDMADoneIntFlag)
{
}
//
// Wait for the data out DMA done interrupt.
//
while(!dataOutDMADoneIntFlag)
{
}
}
else
{
//
// Enable all interrupts.
//
AES_enableInterrupt(AES_BASE, AESW_BASE, (AES_INT_CONTEXT_IN |
AES_INT_CONTEXT_OUT | AES_INT_DATA_IN |
AES_INT_DATA_OUT));
//
// Perform the decryption.
//
AES_processData(AES_BASE, srcArray, dstArray, dataLength);
}
}
//
// Round up length to nearest 16 byte boundary. This is needed because all
// four data registers must be written at once. This is handled in the AES
// driver, but if using uDMA, the length must rounded up.
//
uint32_t roundUpDataLength(uint32_t dataLength)
{
uint32_t remainder;
remainder = dataLength % 16;
if(remainder == 0)
{
return(dataLength);
}
else
{
return(dataLength + (16 - remainder));
}
}
//
// localAESIntISR - local AES Interrupt ISR
//
void localAESIntISR(void)
{
//
// Read the AES masked interrupt status.
//
intStatus = AES_getInterruptStatus(AES_BASE, AESW_BASE, false);
//
// Print a different message depending on the interrupt source.
//
if(intStatus & AES_INT_CONTEXT_IN)
{
//
// Context input registers are ready.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_CONTEXT_IN);
contextInIntFlag = true;
}
if(intStatus & AES_INT_DATA_IN)
{
//
// Data FIFO is ready to receive data.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_DATA_IN);
dataInIntFlag = true;
}
if(intStatus & AES_INT_CONTEXT_OUT)
{
//
// Context output registers are ready.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_CONTEXT_OUT);
contextOutIntFlag = true;
}
if(intStatus & AES_INT_DATA_OUT)
{
//
// Data FIFO is ready to provide data.
//
AES_disableInterrupt(AES_BASE, AESW_BASE, AES_INT_DATA_OUT);
dataOutIntFlag = true;
}
if(intStatus & AES_INT_DMA_CONTEXT_IN)
{
//
// DMA completed a context write to the internal registers.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_CONTEXT_IN);
contextInDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_DATA_IN)
{
//
// DMA has written the last word of input data to the internal FIFO of
// the engine.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_DATA_IN);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_DATA_IN);
dataInDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_CONTEXT_OUT)
{
//
// DMA completed the output context movement from the internal
// registers.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_CONTEXT_OUT);
contextOutDMADoneIntFlag = true;
}
if(intStatus & AES_INT_DMA_DATA_OUT)
{
//
// DMA has written the last word of process result.
//
AES_clearInterruptStatus(AESW_BASE, AES_INT_DMA_DATA_OUT);
AES_disableDMARequest(AES_BASE, AES_DMA_EN_DATA_OUT);
dataOutDMADoneIntFlag = true;
}
}
//
// End of File
//
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -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>
@@ -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
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="dmpu_ex1_secure_mem_transfer"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../dmpu_ex1_secure_mem_transfer.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="dmpu_ex2_sub_region_config"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../dmpu_ex2_sub_region_config.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,373 @@
//#############################################################################
//
// FILE: dmpu_ex1_secure_mem_transfer.c
//
// TITLE: Demonstrate CM-MPU usage for uDMA transfers
//
//! \addtogroup driver_example_cm_list
//! <h1> Demonstrate DMPU usage. </h1>
//!
//! This example demonstrates how to configure CM-MPU for uDMA transfer.
//! uDMA is configured to transfer data between two memory regions and
//! DMPU is configured to demonstrate memory access protection in uDMA
//! associated memory regions
//!
//! The following memory map is set up:
//! -\b Region 0 - uDMA source buffer
//! -\b Region 1 - uDMA control table
//! -\b Region 2 - uDMA destination buffer
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b faultCount - Count for uDMA access faults. This should be non zero.
//! - \b errCountGlobal - Error Counter. This should be zero.
//! - \b memTransferCount - Count of memory uDMA transfer blocks
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define UDMA_SW_INT 41U //!< Interrupt Number for UDMASWINT
#define UDMA_ERR_INT 42U //!< Interrupt Number for UDMAERRINT
#define SYSTICK_INT 15U //!< Interrupt Number for SYSTICKINT
//
// The size of the memory transfer source and destination buffers (in words).
//
#define MEM_BUFFER_SIZE 256U
//
// Globals
//
//
// The source and destination buffers used for memory transfers.
//
static uint32_t srcBuffer[MEM_BUFFER_SIZE]; //!< Source Buffer
static uint32_t dstBuffer[MEM_BUFFER_SIZE]; //!< Destination Buffer
//
// The count of uDMA errors. This value is incremented by the uDMA error
// handler.
//
static uint32_t errCountDMA = 0U, faultCount = 0U;
static volatile uint32_t memFaultAdd, busFaultAdd, val;
static volatile uint32_t faultStatus;
static volatile uint32_t intFlagStatus, accVioAdd;
//
// The count of times the uDMA interrupt occurred but the uDMA transfer was not
// complete. This should remain 0.
//
static uint32_t badInterruptCount = 0;
//
// Error Counter. This should be zero for the successful transfers.
//
static uint32_t errCountGlobal = 0;
//
// The count of memory uDMA transfer blocks. This value is incremented by the
// uDMA interrupt handler whenever a memory block transfer is completed.
//
static uint32_t memTransferCount = 0;
//
// The control table used by the uDMA controller. This table must be aligned
// to a 1024 byte boundary.
//
#pragma DATA_ALIGN(ucControlTable, 64)
UDMA_ControlTable ucControlTable[64];
//
// Function prototypes
//
void uDMAErrorISR(void);
void uDMAIntISR(void);
void initSWTransfer(void);
//
// Main
//
void main(void)
{
uint32_t index;
//
// Initialize device clock and peripherals
//
CM_init();
//
// Fill the source memory buffer with a simple incrementing pattern.
//
for(index = 0; index < MEM_BUFFER_SIZE; index++)
{
srcBuffer[index] = index;
}
//
// Register interrupt handlers in the RAM vector table.
//
Interrupt_registerHandler(UDMA_SW_INT, uDMAIntISR);
Interrupt_registerHandler(UDMA_ERR_INT, uDMAErrorISR);
//
// Enable the uDMA controller error interrupt. This interrupt will occur
// if there is a bus error during a transfer.
//
Interrupt_enable(UDMA_ERR_INT);
//
// Enable the uDMA controller.
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Setting up MPU regions for source, destination buffers and controltable
// array.
//
//
// All regions are configured with required access. No violation should be
// observed while writing to srcBuffer in ISR as CM-MPU.
//
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_0, (uint32_t)&srcBuffer,
(CMMPU_RGN_SIZE_1K| CMMPU_RGN_PERM_READ_ONLY |
CMMPU_RGN_ENABLE));
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_1, (uint32_t)&ucControlTable[0],
(CMMPU_RGN_SIZE_1K| CMMPU_RGN_PERM_FULL_ACCESS |
CMMPU_RGN_ENABLE));
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_2, (uint32_t)&dstBuffer,
(CMMPU_RGN_SIZE_1K| CMMPU_RGN_PERM_FULL_ACCESS |
CMMPU_RGN_ENABLE));
CMMPU_enableAccessViolationInterrupt(DMPU_BASE);
CMMPU_enable(DMPU_BASE);
//
// Initialize the uDMA memory to memory transfers.
//
initSWTransfer();
//
// Loop forever with the CPU not sleeping, so the debugger can connect.
//
while(1)
{
}
}
//
// initSWTransfer - Initializes the uDMA software channel to perform a memory
// to memory uDMA transfer.
//
void initSWTransfer(void)
{
//
// Enable interrupts from the uDMA software channel.
//
Interrupt_enable(UDMA_SW_INT);
//
// Put the attributes in a known state for the uDMA software channel.
// These should already be disabled by default.
//
UDMA_disableChannelAttribute(UDMA_BASE, 30U, UDMA_CH_ATTR_ALL);
//
// Configure the control parameters for the SW channel. The SW channel
// will be used to transfer between two memory buffers, 32 bits at a time.
// Therefore the data size is 32 bits, and the address increment is 32 bits
// for both source and destination. The arbitration size will be set to 8,
// which causes the uDMA controller to re-arbitrate after 8 items are
// transferred. This keeps this channel from hogging the uDMA controller
// once the transfer is started, and allows other channels cycles if they
// are higher priority.
//
UDMA_setChannelControlParams(UDMA_BASE, (30U | UDMA_PRI_SELECT),
(UDMA_SIZE_32 | UDMA_SRC_INC_32 |
UDMA_DST_INC_32 | UDMA_ARB_8));
//
// Set up the transfer parameters for the software channel. This will
// configure the transfer buffers and the transfer size. Auto mode must be
// used for software transfers.
//
UDMA_setChannelTransferParams(UDMA_BASE, (30U | UDMA_PRI_SELECT),
srcBuffer, dstBuffer, UDMA_MODE_AUTO,
MEM_BUFFER_SIZE);
//
// Now the software channel is primed to start a transfer. The channel
// must be enabled. For software based transfers, a request must be
// issued. After this, the uDMA memory transfer begins.
//
UDMA_enableChannel(UDMA_BASE, 30U);
UDMA_requestSoftwareTransfer(UDMA_BASE, 30U);
}
//
// uDMAIntISR - The interrupt handler for uDMA interrupts from the memory
// channel. This interrupt will increment a counter, and then restart another
// memory transfer.
//
void uDMAIntISR(void)
{
static uint32_t ranNum = 1;
uint32_t chMode;
uint32_t i;
//
// Check for the primary control structure to indicate complete.
//
chMode = UDMA_getChannelTransferMode(UDMA_BASE, (30U|UDMA_PRI_SELECT));
if(chMode == UDMA_MODE_STOP)
{
//
// Increment the count of completed transfers.
//
memTransferCount++;
//
// Check the data integrity of transfer
//
for(i=0; i< MEM_BUFFER_SIZE; i++)
{
if(dstBuffer[i] != srcBuffer[i])
{
errCountGlobal++;
}
}
if(errCountGlobal == 0)
{
for(i = 0; i < MEM_BUFFER_SIZE; i++)
{
srcBuffer[i] = i + ranNum;
}
ranNum++;
ranNum = ranNum % 100;
//
// Configure it for another transfer.
//
UDMA_setChannelTransferParams(UDMA_BASE, (30U|UDMA_PRI_SELECT),
srcBuffer, dstBuffer, UDMA_MODE_AUTO,
MEM_BUFFER_SIZE);
//
// Initiate another transfer.
//
UDMA_enableChannel(UDMA_BASE, 30U);
UDMA_requestSoftwareTransfer(UDMA_BASE, 30U);
}
}
//
// If the channel is not stopped, then something is wrong.
//
else
{
badInterruptCount++;
}
}
//
// uDMAErrorISR - The interrupt handler for uDMA errors. This interrupt will
// occur if the uDMA encounters a bus error while trying to perform a transfer.
// This handler just increments a counter if an error occurs.
//
void uDMAErrorISR(void)
{
uint32_t errStatus;
//
// CM-MPU ACC-VIO register status.
//
intFlagStatus = CMMPU_getAccessViolationFlags(DMPU_BASE);
accVioAdd = CMMPU_getAccessViolationAddr(DMPU_BASE);
CMMPU_clearAccessViolationFlags(DMPU_BASE, (CMMPU_ACC_VIO_FLAGS_READ |
CMMPU_ACC_VIO_FLAGS_WRITE));
//
// Increment a counter to indicate fault occurred in MPU.
//
if(intFlagStatus != 0U)
{
faultCount++;
}
//
// Check for uDMA error bit.
//
errStatus = UDMA_getErrorStatus(UDMA_BASE);
//
// If there is a uDMA error, then clear the error and increment
// the error counter.
//
if(errStatus)
{
UDMA_clearErrorStatus(UDMA_BASE);
errCountDMA++;
}
}
//
// End of File
//
@@ -0,0 +1,396 @@
//#############################################################################
//
// FILE: dmpu_ex2_sub_region_config.c
//
// TITLE: Demonstrate CM-MPU usage with sub-region configurations.
//
//! \addtogroup driver_example_cm_list
//! <h1> Demonstrate CM-MPU sub-region configurations </h1>
//!
//! This example demonstrates how to configure sub-regions in CM-MPU for
//! uDMA transfer between memory regions of desired size. Sub-regions are
//! configured to get desired region size of 6k.
//!
//! The following memory map is set up:
//! -\b Region 0 - uDMA source buffer
//! -\b Region 1 - uDMA control table
//! -\b Region 2 - uDMA destination buffer
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b testStatusGlobal - Equivalent to \b TEST_PASS if test finished
//! correctly, else the value is set to \b TEST_FAIL
//! - \b faultCount - Count for uDMA access faults. This should be non zero.
//! - \b errCountGlobal - Error Counter for valid memory transfers.
//! This should be zero.
//! - \b memTransferCount - Count of memory uDMA transfer blocks
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
#define UDMA_SW_INT 41U //!< Interrupt Number for UDMASWINT
#define UDMA_ERR_INT 42U //!< Interrupt Number for UDMAERRINT
#define SYSTICK_INT 15U //!< Interrupt Number for SYSTICKINT
//
// Buffer Size(in words)
// If mem buffer size is 2k fault should be generated and if mem buffer size is
// 1536 no fault should be generated.
// 2048 words -> 2048 * 4 bytes -> 8K bytes
// 1536 words -> 1536 * 4 bytes -> 6K bytes
//
//#define MEM_BUFFER_SIZE 2048U
#define MEM_BUFFER_SIZE 1536U
#define SRC_DMA_ADD (S2RAM_BASE)
#define DST_DMA_ADD (S2RAM_BASE + 0x2000U)
static volatile uint32_t srcDMA = S2RAM_BASE;
static volatile uint32_t dstDMA = (S2RAM_BASE + 0x2000U);
static volatile int32_t fullTransferSize = MEM_BUFFER_SIZE;
static volatile int32_t transferSize = 0;
//
// The count of uDMA errors. This value is incremented by the uDMA error
// handler.
//
static uint32_t errCountDMA = 0;
static volatile uint32_t faultCount;
static volatile uint32_t memFaultAdd, busFaultAdd, val;
static volatile uint32_t faultStatus;
static volatile uint32_t intFlagStatus, accVioAdd;
static volatile uint32_t indexISR = 0;
//
// The count of times the uDMA interrupt occurred but the uDMA transfer was not
// complete. This should remain 0.
//
static uint32_t badInterruptCount = 0;
//
// Test status & error counter.
//
uint32_t testStatusGlobal = TEST_FAIL;
static uint32_t errCountGlobal = 0;
//
// The count of memory uDMA transfer blocks. This value is incremented by the
// uDMA interrupt handler whenever a memory block transfer is completed.
//
static uint32_t memTransferCount = 0;
//
// The control table used by the uDMA controller. This table must be aligned
// to a 1024 byte boundary.
//
#pragma DATA_ALIGN(ucControlTable, 64)
UDMA_ControlTable ucControlTable[64];
//
// Function prototypes
//
void uDMAErrorISR(void);
void uDMAIntISR(void);
void initSWTransfer(void);
//
// Main
//
void main(void)
{
uint32_t i, srcAddr;
//
// Initialize device clock and peripherals
//
CM_init();
//
// Register interrupt handlers in the RAM vector table.
//
Interrupt_registerHandler(UDMA_SW_INT, uDMAIntISR);
Interrupt_registerHandler(UDMA_ERR_INT, uDMAErrorISR);
//
// Enable the uDMA controller error interrupt. This interrupt will occur
// if there is a bus error during a transfer.
//
Interrupt_enable(UDMA_ERR_INT);
//
// Enable the uDMA controller.
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Fill source array before enabling MPU.
//
srcAddr = S2RAM_BASE;
for(i=0; i < MEM_BUFFER_SIZE; i++)
{
HWREG(srcAddr) = i*2;
srcAddr = srcAddr + 4;
}
//
// Setting up MPU regions for source, destination buffers and controltable
// array.
//
//
// Configure sub regions to get desired region size 0f 6k. If mem buffer
// size is 2k fault should be generated and if membuffer size is 1536 no
// fault should be generated.
//
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_0, srcDMA,
(CMMPU_RGN_SIZE_8K | CMMPU_RGN_PERM_READ_ONLY |
(CMMPU_SUB_RGN_DISABLE_6 | CMMPU_SUB_RGN_DISABLE_7) |
CMMPU_RGN_ENABLE));
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_2, (uint32_t)&ucControlTable[0],
(CMMPU_RGN_SIZE_1K| CMMPU_RGN_PERM_FULL_ACCESS |
CMMPU_RGN_ENABLE));
CMMPU_setRegionAttributes(DMPU_BASE, CMMPU_RGN_3, dstDMA,
(CMMPU_RGN_SIZE_8K| CMMPU_RGN_PERM_FULL_ACCESS |
(CMMPU_SUB_RGN_DISABLE_6 | CMMPU_SUB_RGN_DISABLE_7) |
CMMPU_RGN_ENABLE));
CMMPU_enableAccessViolationInterrupt(DMPU_BASE);
CMMPU_enable(DMPU_BASE);
//
// Initialize the uDMA memory to memory transfers.
//
initSWTransfer();
//
// Check for error counter & fault counts
//
while((faultCount == 0) && (errCountGlobal == 0))
{
}
testStatusGlobal = TEST_FAIL;
//
// Loop forever with the CPU not sleeping, so the debugger can connect.
//
while(1)
{
}
}
//
// initSWTransfer - Initializes the uDMA software channel to perform a memory
// to memory uDMA transfer.
//
void initSWTransfer(void)
{
//
// Enable interrupts from the uDMA software channel.
//
Interrupt_enable(UDMA_SW_INT);
//
// Put the attributes in a known state for the uDMA software channel.
// These should already be disabled by default.
//
UDMA_disableChannelAttribute(UDMA_BASE, 30U, UDMA_CH_ATTR_ALL);
//
// Configure the control parameters for the SW channel. The SW channel
// will be used to transfer between two memory buffers, 32 bits at a time.
// Therefore the data size is 32 bits, and the address increment is 32 bits
// for both source and destination. The arbitration size will be set to 8,
// which causes the uDMA controller to re-arbitrate after 8 items are
// transferred. This keeps this channel from hogging the uDMA controller
// once the transfer is started, and allows other channels cycles if they
// are higher priority.
//
UDMA_setChannelControlParams(UDMA_BASE, (30U | UDMA_PRI_SELECT),
(UDMA_SIZE_32 | UDMA_SRC_INC_32 |
UDMA_DST_INC_32 | UDMA_ARB_8));
//
// Set up the transfer parameters for the software channel. This will
// configure the transfer buffers and the transfer size. Auto mode must be
// used for software transfers.
//
transferSize = (fullTransferSize > 1024U) ? 1024U : transferSize;
UDMA_setChannelTransferParams(UDMA_BASE, (30U | UDMA_PRI_SELECT),
(void*)(srcDMA), (void*)(dstDMA),
UDMA_MODE_AUTO, transferSize);
//
// Now the software channel is primed to start a transfer. The channel
// must be enabled. For software based transfers, a request must be
// issued. After this, the uDMA memory transfer begins.
//
UDMA_enableChannel(UDMA_BASE, 30U);
UDMA_requestSoftwareTransfer(UDMA_BASE, 30U);
}
//
// uDMAIntISR - The interrupt handler for uDMA interrupts from the memory
// channel. This interrupt will increment a counter, and then restart another
// memory transfer.
//
void uDMAIntISR(void)
{
uint32_t chMode;
uint32_t i;
//
// Check for the primary control structure to indicate complete.
//
chMode = UDMA_getChannelTransferMode(UDMA_BASE, (30U|UDMA_PRI_SELECT));
if(chMode == UDMA_MODE_STOP)
{
//
// Increment the count of completed transfers.
//
memTransferCount++;
//
// Check the data integrity of transfer
//
for(i=0; i< MEM_BUFFER_SIZE; i=i+4)
{
if(HWREG(S2RAM_BASE + i) != HWREG(S2RAM_BASE + 0x2000U + i))
{
errCountGlobal++;
}
}
if(errCountGlobal == 0U)
{
testStatusGlobal = TEST_PASS;
fullTransferSize = fullTransferSize - 1024;
srcDMA = srcDMA + (1024 * 4);
dstDMA = dstDMA + (1024 * 4);
if(srcDMA < (SRC_DMA_ADD + (MEM_BUFFER_SIZE * 4)))
{
transferSize = (fullTransferSize > 1024U) ?
1024U : fullTransferSize;
//
// Configure it for another transfer.
//
UDMA_setChannelTransferParams(UDMA_BASE, (30U|UDMA_PRI_SELECT),
(void*)srcDMA , (void*)dstDMA,
UDMA_MODE_AUTO, transferSize);
//
// Initiate another transfer.
//
UDMA_enableChannel(UDMA_BASE, 30U);
UDMA_requestSoftwareTransfer(UDMA_BASE, 30U);
}
}
}
//
// If the channel is not stopped, then something is wrong.
//
else
{
badInterruptCount++;
}
}
//
// uDMAErrorISR - The interrupt handler for uDMA errors. This interrupt will
// occur if the uDMA encounters a bus error while trying to perform a transfer.
// This handler just increments a counter if an error occurs.
//
void uDMAErrorISR(void)
{
uint32_t errStatus;
//
// CM-MPU ACC-VIO register status.
//
intFlagStatus = CMMPU_getAccessViolationFlags(DMPU_BASE);
accVioAdd = CMMPU_getAccessViolationAddr(DMPU_BASE);
CMMPU_clearAccessViolationFlags(DMPU_BASE, (CMMPU_ACC_VIO_FLAGS_READ |
CMMPU_ACC_VIO_FLAGS_WRITE));
//
// Increment a counter to indicate fault occurred in MPU.
//
if(intFlagStatus != 0U)
{
faultCount++;
}
//
// Check for uDMA error bit.
//
errStatus = UDMA_getErrorStatus(UDMA_BASE);
//
// If there is a uDMA error, then clear the error and increment
// the error counter.
//
if(errStatus)
{
UDMA_clearErrorStatus(UDMA_BASE);
errCountDMA++;
}
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --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 --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="empty_driverlib_project_cm"
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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../empty_driverlib_main_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,66 @@
//#############################################################################
//
// FILE: empty_driverlib_main_cm.c
//
// TITLE: Empty Project
//! \addtogroup driver_example_list
//!
//! <h1> CM Empty Project Example </h1>
//!
//! This example is an empty project setup for Driverlib development for CM.
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Main
//
void main(void)
{
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_c28x_config"
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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define=ETHERNET --define RAM --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=ETHERNET --define=CPU1 --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="ethernet_ex10_lowlatency_interrupt"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex10_lowlatency_interrupt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex1_basic_tx_rx_loopback"
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=1024 --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=1024 --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="../ethernet_ex1_basic_tx_rx_loopback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex2_phy_loopback"
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=1024 --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=1024 --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="../ethernet_ex2_phy_loopback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex3_threshold_mode_phy_loopback"
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=1024 --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=1024 --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="../ethernet_ex3_threshold_mode_phy_loopback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex4_ptp_basic_master"
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=1024 --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=1024 --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="../ethernet_ex4_ptp_basic_master.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex4_ptp_basic_slave"
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=1024 --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=1024 --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="../ethernet_ex4_ptp_basic_slave.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex5_ptp_offload_master"
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=1024 --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=1024 --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="../ethernet_ex5_ptp_offload_master.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex5_ptp_offload_slave"
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=1024 --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=1024 --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="../ethernet_ex5_ptp_offload_slave.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex6_crc_checksum_offload"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex6_crc_checksum_offload.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex7_tranport_segmentation_offload"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex7_tranport_segmentation_offload.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex8_vlan_filtering"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex8_vlan_filtering.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex9_revmii_example_mii_remote"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex9_revmii_example_mii_remote.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ethernet_ex9_revmii_example_revmii_side"
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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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 --display_error_number" linkerBuildOptions="--stack_size=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ethernet_ex9_revmii_example_revmii_side.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,414 @@
//#############################################################################
//
// FILE: ethernet_ex10_lowlatency_interrupt.c
//
// TITLE: Ethernet Low Latency Interrupt Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet Low Latency Interrupt </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to handle
//! the Ethernet transmit,receive with minimum latency interrupts.
//! The example interrupt handlers provided in the Ethernet driver
//! help to achieve user friendly buffer management and the generic interrupt
//! handler handles different interrupt sources, these factors might be more
//! cycle consuming. This example demonstrates how to achieve lowest possible
//! latency with interrupts and buffer management with the Ethernet Driver.
//! Before running this Communication Manager code the C28x cpu1 code has to be
//! run to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in Internal Loop back mode
//! and hence needs no external connection on the MII Data lines.
//! But it needs the MII Tx and Rx clocks to be input on those pins
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - genericISRCount
//! - transmitISRCount
//! - receiveISRCount
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 508
#define NUM_PACKETS 4
//
// Globals
//
static Ethernet_Handle emac_handle;
uint8_t pData[PACKET_LENGTH];
uint8_t rxBuffer[NUM_PACKETS*PACKET_LENGTH];
//
// The Descriptor Ring can be organized as
// Descriptors for TX Channel 0
// Descriptors for TX Channel 1
// Descriptors for RX Channel 0
// Descriptors for RX Channel 1
// Use the Descriptor pool in driver
//
extern Ethernet_HW_descriptor Ethernet_descArray[ETHERNET_DESCRIPTORS_NUM];
uint8_t indexWriteTx=0;
uint8_t indexMaxTx = ETHERNET_DESCRIPTORS_NUM_TX_PER_CHANNEL;
uint8_t indexReadTx=0;
uint8_t indexMaxRx=
(ETHERNET_DESCRIPTORS_NUM_TX+ETHERNET_DESCRIPTORS_NUM_RX_PER_CHANNEL);
uint8_t indexWriteRx=0;
uint8_t indexReadRx=0;
uint8_t buffIndex=0;
uint32_t genericISRCount,transmitISRCount, receiveISRCount,getBufferCount;
//
//This is a temporary Packet Descriptor passed to the
//Low level driver it is not linked by the driver
//
Ethernet_Pkt_Desc tempDescriptor;
Ethernet_Pkt_Desc *getPacketBuffer(void);
//
//This is a light weight implementation for sending a packet over Ethernet
//It does not maintain any software queue for the packets
//
void SendPacket(uint8_t *pData,uint32_t length)
{
Ethernet_descArray[indexWriteTx].des0 = (uint32_t)pData;
Ethernet_descArray[indexWriteTx].des1 = 0;
Ethernet_descArray[indexWriteTx].des2 = (ETHERNET_TX_DESC_IOC|length);
Ethernet_descArray[indexWriteTx].des3 = (ETHERNET_DESC_OWNER |
ETHERNET_PKT_FLAG_SOP |
ETHERNET_PKT_FLAG_EOP);
Ethernet_writeTxDescTailPointer(EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0,
(Ethernet_HW_descriptor *)
(&Ethernet_descArray[indexWriteTx]));
//
//End check for last descriptor
//
if(++indexWriteTx == ETHERNET_DESCRIPTORS_NUM_TX_PER_CHANNEL)
{
indexWriteTx = 0;
}
}
//
//Transmit interrupt handler only increments the book keeping variable
//and clears the interrupt can be modified as per needs
//
interrupt void transmitISR(void)
{
transmitISRCount++;
Ethernet_clearDMAChannelInterrupt(
EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0,
ETHERNET_DMA_CH0_STATUS_TI
);
}
//
//Receive interrupt handler called when complete packet is received
//
interrupt void receiveISR(void)
{
Ethernet_Pkt_Desc *ptrNewPacket=NULL;
//
//Clear the interrupt
//
Ethernet_clearDMAChannelInterrupt(EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0,
ETHERNET_DMA_CH0_STATUS_RI);
//
// Callback - Invoke any application specific callback here
//Just incrementing the indexRead here we are not consuming the buffers here
//
if(++indexReadRx >= (ETHERNET_DESCRIPTORS_NUM_TX +
ETHERNET_DESCRIPTORS_NUM_RX_PER_CHANNEL))
{
indexReadRx = ETHERNET_DESCRIPTORS_NUM_TX;
}
//
//Refill the packet buffer
//
if(Ethernet_descArray[indexReadRx].des3 & ETHERNET_DESC_OWNER )
{
ptrNewPacket = getPacketBuffer();
Ethernet_descArray[indexWriteRx].des0 =
(uint32_t)ptrNewPacket->dataBuffer;
Ethernet_descArray[indexWriteRx].des1 =0;
Ethernet_descArray[indexWriteRx].des2 = 0;
Ethernet_descArray[indexWriteRx].des3 = (ETHERNET_DESC_OWNER |
ETHERNET_RX_DESC_IOC |
ETHERNET_RX_DESC_BUF1_VALID);
if(++indexWriteRx == ETHERNET_DESCRIPTORS_NUM_TX +
ETHERNET_DESCRIPTORS_NUM_RX_PER_CHANNEL)
{
indexWriteRx = ETHERNET_DESCRIPTORS_NUM_TX;
}
}
receiveISRCount++;
}
void IntermediateFragmentCallback(uint8_t segmentnumber)
{
//
//Add contents here to service the received chunk (of partial packet)
//
}
//
//This generic ISR handles only the Early Rx completion interrupt
//If Early Transmit interrupt needs to be handled it can be added here as well
//
interrupt void genericISR(void)
{
uint16_t fragNumber;
genericISRCount++;
//
//Get the count of how many chunks of packets have come in
//If the Progammable Buffer length 32 bytes
//In threshold mode for each 32 bytes of DMA an early Rx interrupt
//is asserted by hardware which is serviced in this Generic ISR
//
fragNumber = Ethernet_getRxERICount(
EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0);
//
//Callback for signalling the arrival of chunk
//
IntermediateFragmentCallback(fragNumber);
//
//Clear the interrupts at hardware
//
Ethernet_clearDMAChannelInterrupt(
EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0,
ETHERNET_DMA_CH0_STATUS_ETI |
ETHERNET_DMA_CH0_STATUS_AIS);
Ethernet_clearDMAChannelInterrupt(
EMAC_BASE,
ETHERNET_DMA_CHANNEL_NUM_0,
ETHERNET_DMA_CH0_STATUS_ERI | ETHERNET_DMA_CH0_STATUS_NIS);
}
//
//This is a simple implementation of Buffer management it returns
//a new buffer pointer from the given packet buffer pool
//
Ethernet_Pkt_Desc *getPacketBuffer(void)
{
tempDescriptor.dataBuffer = &rxBuffer[buffIndex++ * PACKET_LENGTH];
if(buffIndex == NUM_PACKETS)
{
buffIndex= 0;
}
getBufferCount++;
return &tempDescriptor;
}
main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
uint32_t i;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Initialize the indexes for Descriptor Ring access
//
indexMaxTx = ETHERNET_DESCRIPTORS_NUM_TX_PER_CHANNEL;
indexMaxRx = ETHERNET_DESCRIPTORS_NUM_TX +
ETHERNET_DESCRIPTORS_NUM_RX_PER_CHANNEL;
indexWriteTx= indexReadTx = 0;
indexWriteRx = indexReadRx = ETHERNET_DESCRIPTORS_NUM_TX;
//
//Book keeping Watch variables initialized to zero
//
genericISRCount = transmitISRCount = receiveISRCount= getBufferCount= 0;
//
//Form the Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable =
&Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable =
&Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
Ethernet_getInitConfig(pInitCfg);
pInitCfg->numChannels = 1;
for(i=0;i<pInitCfg->numChannels;i++)
{
//
//Configure the TX in Threshold mode
//
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].storeNForward = \
ETHERNET_MTL_TXQ_OPMODE_TSF_DISABLE;
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].dmaQueueSize =
ETHERNET_MTL_Q_OP_MODE_QSIZE_2048;
//
//Configure the IP in threshold mode
//For the RX Size
//
pInitCfg->chInfo[ETHERNET_CH_DIR_RX][i].storeNForward =
ETHERNET_MTL_RX_Q_OP_MODE_RSF_DISABLE;
}
//
//Enable the Loopback mode of MAC
//
pInitCfg->loopbackMode = ETHERNET_MAC_CONFIGURATION_LM_LOOPBACK_ENABLED;
pInitCfg->dmaMode.InterruptMode = ETHERNET_DMA_MODE_INTM_MODE1;
//
//We are implementing our own ISR and hence this callback is not needed
//
pInitCfg->pfcbRxPacket = NULL;
pInitCfg->pfcbGetPacket = &getPacketBuffer;
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Register the interrupt handlers and enable interrupts
//
Interrupt_registerHandler(INT_EMAC_TX0, transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, receiveISR);
Interrupt_registerHandler(INT_EMAC, genericISR);
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Interrupt_enable(INT_EMAC);
//
//Enable Early receive and Early Transmit interrupts
//Abnormal interrupt is to be enabled for Early recive handling
//
Ethernet_enableDmaInterrupt(EMAC_BASE,
0,
(ETHERNET_DMA_CH0_INTERRUPT_ENABLE_AIE |
ETHERNET_DMA_CH0_INTERRUPT_ENABLE_ETIE |
ETHERNET_DMA_CH0_INTERRUPT_ENABLE_ERIE));
Ethernet_setDMAChannelTransmitStart(EMAC_BASE,ETHERNET_DMA_CHANNEL_NUM_0);
SendPacket(pData,PACKET_LENGTH);
while(1);
}
@@ -0,0 +1,244 @@
//#############################################################################
//
// FILE: ethernet_ex1_basic_tx_rx_loopback.c
//
// TITLE: Ethernet Basic Transmit and Receive MAC Loopback Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet MAC Internal Loopback </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in MAC Loop back mode
//! Prepares a packet to be sent, Sends the packet and reads the statistics
//! to check if the packet is received by the module
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in Internal Loop back mode
//! and hence needs no external connection on the MII Data lines.
//! But it needs the MII Tx and Rx clocks to be input on those pins
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 132
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 1538U
//
// Globals
//
uint8_t pData[PACKET_LENGTH];
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Statistics stats;
Ethernet_Handle emac_handle;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Form the unicast Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
//
//First 6 bytes of the packet are the MAC Destination Address
//Bytes, the Destination and CRC shall be inserted by the hardware
//
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Configure the Loopback mode
//
pInitCfg->loopbackMode = ETHERNET_MAC_CONFIGURATION_LM_LOOPBACK_ENABLED;
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer packet
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pData;
pktDesc.nextPacketDesc = 0;
pktDesc.flags = ETHERNET_PKT_FLAG_SOP |ETHERNET_PKT_FLAG_EOP|ETHERNET_PKT_FLAG_SA_INS;
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire and receive it
//
SysCtl_delay(3000);
//
//Read the statistics of the Module
//
Ethernet_getStatistics(emac_handle, &stats);
//
//Check if a packet has been received
//
if(!stats.rxUnicastPacketsGood)
__asm(" bkpt #0");
}
@@ -0,0 +1,276 @@
//#############################################################################
//
// FILE: ethernet_ex2_phy_loopback.c
//
// TITLE: Ethernet Basic Transmit and Receive External (PHY) Loopback Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet Basic Transmit and Receive PHY Loopback </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in External Loop back mode
//! the packet is looped back at external PHY.
//! Prepares a packet to be sent, Sends the packet and reads the staticstics
//! to check if the packet is received by the module
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in External Loop back mode (at PHY)
//! and hence needs external connection to the PHY on the MII interface and
//! also the MDIO Pins connected to the PHY. This example assumes DP83822 PHY
//! for the PHY configurations if a different PHY is used the sequences might change
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - phyRegContent variable can be checked to know if PHY register
//! read,write is working correctly
//! - stats to know if the packet is received correctly after loopback
//! at PHY side
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 132
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 1538U
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
uint8_t pData[PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Statistics stats;
Ethernet_Handle emac_handle;
uint16_t phyRegContent=0;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Form the unicast Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
//
//First 6 bytes of the packet are the MAC Destination Address
//Bytes, the Destination and CRC shall be inserted by the hardware
//
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle) 1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Low Frequency
//value of 5 for selecting the slowest possible MDIO Clock
//Clause 22 mode
//
Ethernet_configureMDIO(EMAC_BASE,0,5,0);
//
//The DP83822 External PHY in Control Card
//takes a PHY address of 1 by default
//Configure the MDIO module to use PHY address of 0x1
//
Ethernet_configurePHYAddress(EMAC_BASE,1);
//
//Address 0 of PHY corresponds to Basic Mode Control Register(BMCR)
//Read the register to know the state
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);
//
//Bit 14 of BMCR configures the MII Loopback
//
phyRegContent |= 0x4000;
Ethernet_writePHYRegister(EMAC_BASE,0,phyRegContent);
//
//Read back the BMCR register to confirm that the MII Loopback
//is configured properly
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer single packet
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pData;
pktDesc.nextPacketDesc = 0;
pktDesc.flags = ETHERNET_PKT_FLAG_SOP |ETHERNET_PKT_FLAG_EOP|ETHERNET_PKT_FLAG_SA_INS;
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire and receive it
//
SysCtl_delay(3000);
//
//Read the statistics of the Module
//
Ethernet_getStatistics(emac_handle, &stats);
//
//Check if a packet has been received
//
if(!stats.rxUnicastPacketsGood)
__asm(" bkpt #0");
}
@@ -0,0 +1,394 @@
//#############################################################################
//
// FILE: ethernet_ex3_threshold_mode_phy_loopback.c
//
// TITLE: Ethernet Threshold Mode Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet Threshold mode with level PHY loopback </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module in Threshold mode
//! It Configures the module in MII External Loop back mode in which
//! the packet is looped back at external PHY.
//! Prepares a packet to be sent, Sends the packet and reads the staticstics
//! to check if the packet is received by the module
//! It configures the Transmit and Receive queues of Ethernet DMA
//! in Threshold mode.
//! The Transmit threshold mode generates early
//! transmit interrupts when each buffer is transmitted from the memory
//! into the transmit FIFO. The Buffer can be reclaimed by the application.
//! The Receive threshold mode generates early receive interrupts
//! where the module generates Early receive interrupts when programmed
//! threshold buffer size is transferred into receive buffer memory from
//! the receive FIFO.
//! This will be of use when dealing with Time critical receive paths
//! where the application can consume the packets at programmed burstLength
//! unlike the conventional Store and Forward mode(Default) where the module
//! generates the interrupts when the complete packet is transmitted on the Line
//! and when the complete packet is received and checksum validation is succesful
//! This example provides a starting point for configuring the threshold mode.
//! Refer to the Driver API guide for the different callbacks available in the driver.
//! It uses the example Interrupt Service Routines provided in the driver library.
//! Users can modify those ISRs or write another as per their need.
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in External Loop back mode (at PHY)
//! and hence needs external connection to the PHY on the MII interface and
//! also the MDIO Pins connected to the PHY. This example assumes DP83822 PHY
//! for the PHY configurations if a different PHY is used the sequences might change.
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - phyRegContent variable can be checked to know if PHY register
//! read,write is working correctly
//! - Ethernet_txInterruptCount - this variable available in driver library
//! provides a count of number of times Transmit completion interrupt
//! (on full packet transmission onto the line) occured
//! - Ethernet_rxInterruptCount - this variable provides a count of
//! number of times the complete Receive completion interrupt occured
//! - Ethernet_earlyRxInterruptCount - the number of times the early
//! receive interrupt occured. This depends on the burstLength configured
//! - Ethernet_earlyTxInterruptCount - the number of times the early
//! transmit interrupt occured. This depends on the number of fragments of the
//! packets transmitted
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 1508
#define NUM_PACKETS 1
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 1538U
//
// Globals
// We are dividing the packet into two fragments
// For demonstration we are using two different buffers
//
uint8_t pData[PACKET_LENGTH/2];
uint8_t pData2[PACKET_LENGTH/2];
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc[2];
uint32_t i;
Ethernet_Handle emac_handle;
uint16_t phyRegContent=0;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Form the unicast Packet in Memory
//First 6 bytes of the packet are the MAC Destination Address
//Bytes, the Destination and CRC shall be inserted by the hardware
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Second Fragment shall not contain MAC header but just data
//
for(i=0;i<PACKET_LENGTH/8;i++)
{
HWREG((uint32_t *)pData2 +i) = 0xFFFFFFFF;
}
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Configure a single channel for Tx and Rx
//
pInitCfg->numChannels = 1;
//
// The default mode chosen by getInitConfig shall be Store and Forward
//In that mode the interrupts are generated when the complete packet is sent out
//on the line and received on the line in Receive side
//
for(i=0;i<pInitCfg->numChannels;i++)
{
//
//Configure the TX Queue in Threshold mode
//Disabling Store and Forward mode will configure Threshold mode
//
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].storeNForward =
ETHERNET_MTL_TXQ_OPMODE_TSF_DISABLE;
//
//Configure the Rx Queue in threshold mode
//Disabling Store and Forward mode will configure Threshold mode
//
pInitCfg->chInfo[ETHERNET_CH_DIR_RX][i].storeNForward =
ETHERNET_MTL_RX_Q_OP_MODE_RSF_DISABLE;
//
//Burst Length is the number of beats(32 bits/one word)
//Configuring 32 burstLength will generate an interrupt for every
//128 bytes of data pushed into Receive Queue from the Rx line
//Please program this to a value based on the ISR latency for the
//Ethernet Combined Interrupt (SBD) handler.The value of 32 is
//chosen based on the interrrupt handler example provided in the
//driver library
//
pInitCfg->chInfo[ETHERNET_CH_DIR_RX][i].burstLength = 32;
}
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//Get the handle for the module configured with the
//chosen parameters as configured above in addition
//to default parameters
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
Interrupt_registerHandler(INT_EMAC, Ethernet_genericISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Interrupt_enable(INT_EMAC);
//
//For Channel 0
//Enable the Abnormal Interrupt
//The Early Transmit interrupt and Early Receive interrupt
//which are key for handling Threshold mode of the module
//By default these interrupts are not enabled in the driver
//Generic SBD interrupt shall be generated for these events
//For this example we are relying on the example ISR provided by
//the Low level driver
//
Ethernet_enableDmaInterrupt(EMAC_BASE,
0,
ETHERNET_DMA_CH0_INTERRUPT_ENABLE_AIE
|ETHERNET_DMA_CH0_INTERRUPT_ENABLE_ETIE
|ETHERNET_DMA_CH0_INTERRUPT_ENABLE_ERIE);
//
//Low Frequency
//value of 5 for selecting the slowest possible MDIO Clock
//Clause 22 mode
//
Ethernet_configureMDIO(EMAC_BASE,0,5,0);
//
//The DP83822 External PHY in Control Card
//takes a PHY address of 1 by default
//Configure the MDIO module to use PHY address of 0x1
//
Ethernet_configurePHYAddress(EMAC_BASE,1);
//
//Address 0 of PHY corresponds to Basic Mode Control Register(BMCR)
//Read the register to know the state
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);
//
//Bit 14 of BMCR configures the MII Loopback
//
phyRegContent |= 0x4000;
Ethernet_writePHYRegister(EMAC_BASE,0,phyRegContent);
//
//Read back the BMCR register to confirm that the MII Loopback
//is configured properly
//
phyRegContent= Ethernet_readPHYRegister(EMAC_BASE,0);
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer single packet
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//
//In Threshold mode Transmit side the MAC shall generate early interrupt
//as when the buffer is pushed into the FIFO by the internal DMA
//the buffer can be reclaimed by the application
//With the first interrupt the buffer 0 can be reclaimed
//For the second interrupt the buffer 1 can be reclaimed by the application
//
pktDesc[0].bufferLength = PACKET_LENGTH/2;
pktDesc[0].dataOffset = 0;
pktDesc[0].dataBuffer = pData;
//
//Point to the next descriptor for forming a chain
//
pktDesc[0].nextPacketDesc =&pktDesc[1];
//
//This fragment has only SOP EOP shall be in next fragment
//
pktDesc[0].flags = ETHERNET_PKT_FLAG_SOP ;
pktDesc[0].pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc[0].pktLength = PACKET_LENGTH;
pktDesc[0].validLength = PACKET_LENGTH/2;
//
//This packet is split into two fragments
//
pktDesc[0].numPktFrags = 2;
pktDesc[1].bufferLength = PACKET_LENGTH/2;
pktDesc[1].dataOffset = 0;
pktDesc[1].dataBuffer = pData2;
pktDesc[1].nextPacketDesc =0;
pktDesc[1].flags = ETHERNET_PKT_FLAG_EOP;
pktDesc[1].pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc[1].pktLength = PACKET_LENGTH;
pktDesc[1].validLength = PACKET_LENGTH/2;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc[0]);
//
//Transmit Path Interrupts:
//While the packet is being sent we should observe two early Transmit interrupts
//and one transmit completion interrupt when the packet is completely transferred
//on the wire
//On the Receive Side:
//As and when the burstLength*4 bytes are transferred from the line to the
//Memory by the Ethernet DMA there will be an early interrupt
//
while(1);
}
@@ -0,0 +1,907 @@
//#############################################################################
//
// FILE: ethernet_ex4_ptp_basic_master.c
//
// TITLE: Ethernet PTP Basic Master Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet PTP Basic Master </h1>
//!
//! This example configures the device in IEEE PTPv2 Master mode and then
//! periodically sends Sync packets to the slave. On receiving the DelayReq
//! packets from the slave, the master also sends out the DelayResp packets.
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in PTP Basic Master mode.
//! The example project \e Ethernet \e PTP \e Basic \e Slave is intended to
//! be used along with this project to see the whole PTP Protocol state in
//! action. The second device is configured as \e Slave and both devices in
//! conjunction exchange Sync, DelayReq and DelayResp packets.
//!
//! Refer to the C28x CPU1 code of ethernet_config_c28x project for configuring
//! the PTP clock that drives the system time counter on the Ethernet module.
//!
//! \b Watch \b Variables \n
//! - gPtpMasterState
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "driverlib_cm.h"
#include "string.h"
#include "cm.h"
//
// This frequency is actually set in the c28x side code. If it is changed
// there, then the following value also needs to be updated since the
// timestamping module is initialized with the following values.
// Default value is 100 MHz.
//
#define PTP_REF_CLOCK_FREQ 100000000
#define PTP_REF_CLOCK_PERIOD 1000000000/PTP_REF_CLOCK_FREQ
static Ethernet_Handle emac_handle;
#define PACKET_LENGTH 200
#define ETHERNET_NO_OF_RX_PACKETS 8U
#define ETHERNET_MAX_PACKET_LENGTH PACKET_LENGTH
#define NUM_PACKET_DESC_RX_APPLICATION 8U
#define PTP_HEADER_OFFSET 14U
uint32_t Ethernet_numRxCallbackCustom = 0;
uint32_t releaseTxCount = 0;
Ethernet_Pkt_Desc pktDescriptorRXCustom[NUM_PACKET_DESC_RX_APPLICATION];
extern uint32_t Ethernet_numGetPacketBufferCallback;
extern Ethernet_Device Ethernet_device_struct;
uint8_t gMsgBuf[PACKET_LENGTH] = {0};
Ethernet_Pkt_Desc gPktDesc;
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
// Network related definitions as follows
//
//
// Taking care of network byte order conversions using these macros.
//
#define PP_HTONS(x) ((uint16_t)((((x) & (uint16_t)0x00ffU) << 8) | \
(((x) & (uint16_t)0xff00U) >> 8)))
#define PP_NTOHS(x) PP_HTONS(x)
#define PP_HTONL(x) ((((x) & (uint32_t)0x000000ffUL) << 24) | \
(((x) & (uint32_t)0x0000ff00UL) << 8) | \
(((x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((x) & (uint32_t)0xff000000UL) >> 24))
#define PP_NTOHL(x) PP_HTONL(x)
#define flip16(x) PP_HTONS(x)
#define flip32(x) PP_HTONL(x)
//
// Following definitions and prototypes are specific to the PTP state machine
// and have been adapted from the IEEE 1588 standard spec.
//
#define PTP_TWO_STEP 0x02
#define PTP_UUID_LENGTH 6
#define CLOCK_IDENTITY_LENGTH 8
#define FLAG_FIELD_LENGTH 2
#define HEADER_LENGTH 34
#define ANNOUNCE_LENGTH 64
#define SYNC_LENGTH 44
#define FOLLOW_UP_LENGTH 44
#define PDELAY_REQ_LENGTH 54
#define DELAY_REQ_LENGTH 44
#define DELAY_RESP_LENGTH 54
#define PDELAY_RESP_LENGTH 54
#define PDELAY_RESP_FOLLOW_UP_LENGTH 54
#define MANAGEMENT_LENGTH 48
typedef enum {FALSE=0, TRUE} Boolean;
typedef char Octet;
typedef signed char Integer8;
typedef signed short Integer16;
typedef signed int Integer32;
typedef unsigned char UInteger8;
typedef unsigned short UInteger16;
typedef unsigned int UInteger32;
typedef unsigned short Enumeration16;
typedef unsigned char Enumeration8;
typedef unsigned char Enumeration4;
typedef unsigned char UInteger4;
typedef unsigned char Nibble;
//
// brief Implementation specific of Integer64 type
//
typedef struct {
unsigned int lsb;
int msb;
} Integer64;
typedef struct {
unsigned int lsb;
unsigned short msb;
} UInteger48;
typedef struct {
UInteger48 secondsField;
UInteger32 nanosecondsField;
} Timestamp;
//
// brief Time structure to handle Linux time information
//
typedef struct {
Integer32 seconds;
Integer32 nanoseconds;
} TimeInternal;
//
// brief The ClockIdentity type identifies a clock
//
typedef Octet ClockIdentity[CLOCK_IDENTITY_LENGTH];
//
// brief The PortIdentity identifies a PTP port.
//
typedef struct {
ClockIdentity clockIdentity;
UInteger16 portNumber;
} PortIdentity;
//
// brief The common header for all PTP messages (Table 18 of the spec)
//
//
// Message header
//
typedef struct {
Nibble transportSpecific;
Enumeration4 messageType;
UInteger4 versionPTP;
UInteger16 messageLength;
UInteger8 domainNumber;
Octet flagField[2];
Integer64 correctionfield;
PortIdentity sourcePortIdentity;
UInteger16 sequenceId;
UInteger8 controlField;
Integer8 logMessageInterval;
} MsgHeader;
typedef struct
{
PortIdentity portIdentity;
Octet port_uuid_field[PTP_UUID_LENGTH];
Timestamp syncTimestamp;
Timestamp delayReqRecvTimestamp;
uint16_t syncSeqId;
uint16_t portNumber;
Boolean syncTimestampAvailable;
Boolean sendingDelayResp;
MsgHeader delayReqHeader;
} PTPMasterState;
PTPMasterState gPtpMasterState = {0};
//
// brief PTP Messages
//
enum {
SYNC=0x0,
DELAY_REQ=0x1,
FOLLOW_UP = 0x8,
DELAY_RESP = 0x9,
};
//
// Function prototypes used in this example
//
void fromInternalTime(TimeInternal * internal, Timestamp * external);
void msgPackHeader(Octet * buf, PTPMasterState *ptpMasterState);
void msgPackSync(Octet * buf, PTPMasterState *ptpMasterState);
void msgPackFollowUp(Octet * buf, PTPMasterState *ptpMasterState);
void msgPackDelayResp(Octet * buf, PTPMasterState *ptpMasterState);
void msgUnpackHeader(Octet * buf, MsgHeader * header);
void InitConstants(PTPMasterState *ptpMasterState);
void sendMessage(Octet * msg,
uint32_t messageType,
PTPMasterState * ptpMasterState,
Ethernet_Pkt_Desc * pktDesc);
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void);
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket);
void Ethernet_releaseTxPacketBufferCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket);
main(void)
{
Ethernet_InitConfig *pInitCfg;
uint32_t i;
uint32_t varPtpConfig = 0;
Ethernet_InitInterfaceConfig initInterfaceConfig;
uint32_t timeSec;
uint32_t timeNanosec;
float subSecondInc;
//
// Initialize device clock and peripherals
//
CM_init();
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
Ethernet_getInitConfig(pInitCfg);
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBufferCustom;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallbackCustom;
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBufferCustom;
varPtpConfig = (0 << ETHERNET_MAC_TIMESTAMP_CONTROL_SNAPTYPSEL_S) |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSCTRLSSR |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSMSTRENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSEVNTENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSVER2ENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSIPENA;
//
// Subsecond increment is added to the systime counter every ptp clock tick
// hence for Digital rollover, it is simply the time period of the clock
// tick.
//
subSecondInc = PTP_REF_CLOCK_PERIOD;
Ethernet_setConfigTimestampPTP(EMAC_BASE, varPtpConfig, subSecondInc);
Ethernet_enableSysTimePTP(EMAC_BASE);
//
// Start the system with a random value.
//
Ethernet_setSysTimePTP(EMAC_BASE, 0x4132EDCA, 0x25a5a5a5);
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Ethernet_setMACAddr(EMAC_BASE,
0,
0x00000506U,
0x01030304U,
ETHERNET_CHANNEL_0);
//
// We need to program this standard multicast address so that this device
// identifies PTP over Ethernet packets correctly. "01:1B:19:00:00:00"
//
Ethernet_setMACAddr(EMAC_BASE,
1,
0x00000000,
0x00191B01,
ETHERNET_CHANNEL_0);
Ethernet_selectTargetInterruptOrPulsePPS(
EMAC_BASE,
ETHERNET_MAC_PPS_OUT_INSTANCE_0,
ETHERNET_MAC_PPS_CONTROL_TRGTMODSEL_INTERRUPT);
//
// We need to set a standard defined Multicast address : 01:1B:19:00:00:00
// as the Destination address in the ethernet frame and that is how the
// receiver will recognize it as a valid PTP over Ethernet packet.
//
i=0; *((uint32_t *)gMsgBuf + i) = 0x00191B01;
i++; *((uint32_t *)gMsgBuf + i) = 0xF7880000;
InitConstants(&gPtpMasterState);
while(1)
{
//
// Use the system time counter to send the sync + followup messages
// every one second.
//
Ethernet_getSysTimePTP(EMAC_BASE, &timeSec, &timeNanosec);
Ethernet_setTargetTimePPS(EMAC_BASE, ETHERNET_MAC_PPS_OUT_INSTANCE_0,
timeSec + 1, timeNanosec);
//
// Waiting till the target time that we set above is reached.
// We're using the PPSOUT instance 0 as the timer.
//
while(((HWREG(EMAC_BASE + ETHERNET_O_MAC_TIMESTAMP_STATUS)) &
(ETHERNET_MAC_TIMESTAMP_STATUS_TSTARGT0)) == 0);
//
// Save the state. We want to capture the timestamp of the next SYNC
// packet that is being sent.
//
gPtpMasterState.syncTimestampAvailable = FALSE;
//
// Send out the SYNC packet.
//
sendMessage((Octet *)gMsgBuf, SYNC, &gPtpMasterState, &gPktDesc);
//
// Wait till the latest sync timestamp is captured. As soon as the
// timestamp for the SYNC packet going out is captured, this flag
// will be set to TRUE by the application.
//
while(gPtpMasterState.syncTimestampAvailable == FALSE);
//
// Since the timestamp for the last SYNC packet has been captured,
// send out the associated FOLLOW-UP packet.
//
sendMessage((Octet *)gMsgBuf, FOLLOW_UP, &gPtpMasterState, &gPktDesc);
}
}
void
fromInternalTime(TimeInternal * internal, Timestamp * external)
{
external->secondsField.lsb = internal->seconds;
external->nanosecondsField = internal->nanoseconds;
external->secondsField.msb = 0;
}
//
// Pack header message into OUT buffer of ptpClock
//
void
msgPackHeader(Octet * buf, PTPMasterState *ptpMasterState)
{
Nibble transport = 0x80;
//
// (spec annex D)
//
*(UInteger8 *) (buf + 0) = transport;
//
// PTPv2
//
*(UInteger4 *) (buf + 1) = 0x2;
//
// Default domain number is 0.
//
*(UInteger8 *) (buf + 4) = 0;
if (PTP_TWO_STEP)
*(UInteger8 *) (buf + 6) = PTP_TWO_STEP;
//
// correctionField
//
memset((buf + 8), 0, 8);
//
// sourcePortIdentity first 8 octets
//
memcpy((buf + 20), ptpMasterState->portIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
//
// sourcePortIdentity last 2 octets
//
*(UInteger16 *) (buf + 28) =
flip16(ptpMasterState->portIdentity.portNumber);
//
// Default value(spec Table 24)
//
*(UInteger8 *) (buf + 33) = 0x7F;
}
//
// Pack SYNC message into OUT buffer of ptpClock
//
void
msgPackSync(Octet * buf, PTPMasterState *ptpMasterState)
{
msgPackHeader(buf, ptpMasterState);
//
// changes in header
//
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
//
// RAZ messageType
//
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x00; /* Table 19 */
//
// messageLength
//
*(UInteger16 *) (buf + 2) = flip16(SYNC_LENGTH);
//
// Sequence Id
//
*(UInteger16 *) (buf + 30) =
flip16(ptpMasterState->syncSeqId);
//
// controlField
//
*(UInteger8 *) (buf + 32) = 0x00; /* Table 23 */
//
// logMessageInterval
//
*(Integer8 *) (buf + 33) = 0; // We'll send sync every second
if(!PTP_TWO_STEP)
{
//
// Sync message
//
*(UInteger16 *) (buf + 34) =
flip16(ptpMasterState->syncTimestamp.secondsField.msb);
*(UInteger32 *) (buf + 36) =
flip32(ptpMasterState->syncTimestamp.secondsField.lsb);
*(UInteger32 *) (buf + 40) =
flip32(ptpMasterState->syncTimestamp.nanosecondsField);
}
}
//
// pack Follow_up message into OUT buffer of ptpClock
//
void
msgPackFollowUp(Octet * buf, PTPMasterState *ptpMasterState)
{
msgPackHeader(buf, ptpMasterState);
//
// changes in header
//
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
//
// RAZ messageType
//
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x08; /* Table 19 */
//
// messageLength
//
*(UInteger16 *) (buf + 2) = flip16(FOLLOW_UP_LENGTH);
//
// Sequence Id
//
*(UInteger16 *) (buf + 30) =
flip16(ptpMasterState->syncSeqId);
//
// controlField
//
*(UInteger8 *) (buf + 32) = 0x02; /* Table 23 */
//
// logMessageInterval
//
*(Integer8 *) (buf + 33) = 0; // we're sending sync every one second.
//
// Follow_up message
//
*(UInteger16 *) (buf + 34) =
flip16(ptpMasterState->syncTimestamp.secondsField.msb);
*(UInteger32 *) (buf + 36) =
flip32(ptpMasterState->syncTimestamp.secondsField.lsb);
*(UInteger32 *) (buf + 40) =
flip32(ptpMasterState->syncTimestamp.nanosecondsField);
}
//
// pack delayResp message into OUT buffer of ptpClock
//
void
msgPackDelayResp(Octet * buf, PTPMasterState *ptpMasterState)
{
msgPackHeader(buf, ptpMasterState);
//
// changes in header
// Transport | messageType
//
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
//
// RAZ messageType
//
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x09; /* Table 19 */
//
// messageLength
//
*(UInteger16 *) (buf + 2) = flip16(DELAY_RESP_LENGTH);
//
// domain Number
//
*(UInteger8 *) (buf + 4) = ptpMasterState->delayReqHeader.domainNumber;
//
// Sequence Id
//
*(UInteger16 *) (buf + 30) =
flip16(ptpMasterState->delayReqHeader.sequenceId);
//
// controlField
//
*(UInteger8 *) (buf + 32) = 0x03; /* Table 23 */
//
// logMessageInterval
//
*(Integer8 *) (buf + 33) = 0; /* Table 24 */
*(UInteger16 *) (buf + 34) =
flip16(ptpMasterState->delayReqRecvTimestamp.secondsField.msb);
*(UInteger32 *) (buf + 36) =
flip32(ptpMasterState->delayReqRecvTimestamp.secondsField.lsb);
*(UInteger32 *) (buf + 40) =
flip32(ptpMasterState->delayReqRecvTimestamp.nanosecondsField);
memcpy((buf + 44),
ptpMasterState->delayReqHeader.sourcePortIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
*(UInteger16 *) (buf + 52) =
flip16(ptpMasterState->delayReqHeader.sourcePortIdentity.portNumber);
}
//
// Unpack Header from IN buffer to msgTmpHeader field
//
void
msgUnpackHeader(Octet * buf, MsgHeader * header)
{
header->transportSpecific = (*(Nibble *) (buf + 0)) >> 4;
header->messageType = (*(Enumeration4 *) (buf + 0)) & 0x0F;
header->versionPTP = (*(UInteger4 *) (buf + 1)) & 0x0F;
//
// force reserved bit to zero if not
//
header->messageLength = flip16(*(UInteger16 *) (buf + 2));
header->domainNumber = (*(UInteger8 *) (buf + 4));
memcpy(header->flagField, (buf + 6), FLAG_FIELD_LENGTH);
memcpy(&header->correctionfield.msb, (buf + 8), 4);
memcpy(&header->correctionfield.lsb, (buf + 12), 4);
header->correctionfield.msb = flip32(header->correctionfield.msb);
header->correctionfield.lsb = flip32(header->correctionfield.lsb);
memcpy(header->sourcePortIdentity.clockIdentity, (buf + 20),
CLOCK_IDENTITY_LENGTH);
header->sourcePortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 28));
header->sequenceId = flip16(*(UInteger16 *) (buf + 30));
header->controlField = (*(UInteger8 *) (buf + 32));
header->logMessageInterval = (*(Integer8 *) (buf + 33));
}
void InitConstants(PTPMasterState *ptpMasterState)
{
uint32_t mac_low,mac_high, i, j;
uint8_t *pucTemp;
Ethernet_getMACAddr(EMAC_BASE, 0, &mac_high, &mac_low);
pucTemp = (uint8_t *)&mac_low;
ptpMasterState->port_uuid_field[0] = pucTemp[0];
ptpMasterState->port_uuid_field[1] = pucTemp[1];
ptpMasterState->port_uuid_field[2] = pucTemp[2];
ptpMasterState->port_uuid_field[3] = pucTemp[3];
pucTemp = (uint8_t *)&mac_high;
ptpMasterState->port_uuid_field[4] = pucTemp[0];
ptpMasterState->port_uuid_field[5] = pucTemp[1];
//
// Init global constants.
//
for (i = 0, j = 0; i < CLOCK_IDENTITY_LENGTH; i++)
{
if (i == 3) ptpMasterState->portIdentity.clockIdentity[i] = 0xFF;
else if (i == 4) ptpMasterState->portIdentity.clockIdentity[i] = 0xFE;
else
{
ptpMasterState->portIdentity.clockIdentity[i] =
ptpMasterState->port_uuid_field[j];
j++;
}
}
}
void sendMessage(Octet * msg,
uint32_t messageType,
PTPMasterState * ptpMasterState,
Ethernet_Pkt_Desc * pktDesc)
{
uint32_t pktLen;
//
// We can't trust if the supplied descriptor is clean. Hence reset it.
//
memset(pktDesc, 0, sizeof(Ethernet_Pkt_Desc));
pktDesc->bufferLength = PACKET_LENGTH;
pktDesc->dataOffset = 0;
pktDesc->dataBuffer = (uint8_t *)msg;
pktDesc->nextPacketDesc = 0;
pktDesc->flags = ETHERNET_PKT_FLAG_SOP |
ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS |
ETHERNET_PKT_FLAG_CRC_PAD_INS;
pktDesc->pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc->numPktFrags = 1;
//
// Reset the buffer
//
memset(msg + 8, 0, PACKET_LENGTH - 8);
switch(messageType)
{
case SYNC:
pktDesc->flags |= ETHERNET_PKT_FLAG_TTSE;
msgPackSync(msg + 8, ptpMasterState);
pktLen = SYNC_LENGTH;
break;
case FOLLOW_UP:
msgPackFollowUp(msg + 8, ptpMasterState);
pktLen = FOLLOW_UP_LENGTH;
gPtpMasterState.syncSeqId++;
break;
case DELAY_RESP:
msgPackDelayResp(msg + 8, ptpMasterState);
pktLen = DELAY_RESP_LENGTH;
break;
default:
//
// Error condition, the code should never reach here
//
break;
}
pktDesc->pktLength = pktLen + 6 + 2;
pktDesc->validLength = pktDesc->pktLength;
Ethernet_sendPacket(emac_handle, pktDesc);
}
//*****************************************************************************
//
// This function is a callback function called by the example to
// get a Packet Buffer. Has to return a ETHERNET_Pkt_Desc Structure.
// Rewrite this API for custom use case.
//
//*****************************************************************************
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void)
{
//
// Get the next packet descriptor from the descriptor pool
//
uint32_t shortIndex = (Ethernet_numGetPacketBufferCallback + 3)
% NUM_PACKET_DESC_RX_APPLICATION;
//
// Increment the book-keeping pointer which acts as a head pointer
// to the circular array of packet descriptor pool.
//
Ethernet_numGetPacketBufferCallback++;
//
// Update buffer length information to the newly procured packet
// descriptor.
//
pktDescriptorRXCustom[shortIndex].bufferLength =
ETHERNET_MAX_PACKET_LENGTH;
//
// Update the receive buffer address in the packer descriptor.
//
pktDescriptorRXCustom[shortIndex].dataBuffer =
&Ethernet_device_struct.rxBuffer [
(ETHERNET_MAX_PACKET_LENGTH*Ethernet_device_struct.rxBuffIndex)];
//
// Update the receive buffer pool index.
//
Ethernet_device_struct.rxBuffIndex += 1U;
Ethernet_device_struct.rxBuffIndex =
(Ethernet_device_struct.rxBuffIndex%ETHERNET_NO_OF_RX_PACKETS);
//
// Receive buffer is usable from Address 0
//
pktDescriptorRXCustom[shortIndex].dataOffset = 0U;
//
// Return this new descriptor to the driver.
//
return (&(pktDescriptorRXCustom[shortIndex]));
}
//*****************************************************************************
//
// This is a hook function and called by the driver when it receives a
// packet. Application is expected to replenish the buffer after consuming it.
// Has to return a ETHERNET_Pkt_Desc Structure.
// Rewrite this API for custom use case.
//
//*****************************************************************************
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
//
// Need to unpack the header to check which packet is received.
// We expect a Delay Request packet from the slave. Ignore others.
//
msgUnpackHeader((Octet*)(pPacket->dataBuffer + PTP_HEADER_OFFSET),
&gPtpMasterState.delayReqHeader);
switch(gPtpMasterState.delayReqHeader.messageType)
{
case DELAY_REQ:
//
// Simply get the timestamp and send the delay response packet asap.
//
gPtpMasterState.delayReqRecvTimestamp.nanosecondsField =
pPacket->timeStampLow;
gPtpMasterState.delayReqRecvTimestamp.secondsField.lsb =
pPacket->timeStampHigh;
gPtpMasterState.delayReqRecvTimestamp.secondsField.msb = 0;
//
// Save this state that we are sending Delay Resp packet so that it
// doesn't affect other packets which are being sent.
//
gPtpMasterState.sendingDelayResp = TRUE;
//
// Send the corresponding Delay Response packet.
//
sendMessage((Octet *)gMsgBuf, DELAY_RESP, &gPtpMasterState, &gPktDesc);
break;
default:
//
// Error condition, the code should never reach here
//
break;
}
//
// Book-keeping to maintain number of callbacks received.
//
#ifdef ETHERNET_DEBUG
Ethernet_numRxCallbackCustom++;
#endif
return Ethernet_getPacketBufferCustom();
}
void Ethernet_releaseTxPacketBufferCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
//
// We would like to capture the timestamp for the SYNC packet only.
//
if(gPtpMasterState.sendingDelayResp == TRUE)
{
gPtpMasterState.sendingDelayResp = FALSE;
}
else if(gPtpMasterState.syncTimestampAvailable == FALSE)
{
gPtpMasterState.syncTimestamp.nanosecondsField = pPacket->timeStampLow;
gPtpMasterState.syncTimestamp.secondsField.lsb = pPacket->timeStampHigh;
gPtpMasterState.syncTimestamp.secondsField.msb = 0;
gPtpMasterState.syncTimestampAvailable = TRUE;
}
//
// Increment the book-keeping counter.
//
#if ETHERNET_DEBUG
Ethernet_releaseTxCount++;
#endif
}
@@ -0,0 +1,892 @@
//#############################################################################
//
// FILE: ethernet_ex4_ptp_basic_slave.c
//
// TITLE: Ethernet PTP Basic Slave Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet PTP Basic Slave </h1>
//!
//! This example configures the device in IEEE PTPv2 Slave mode and then
//! waits for the Sync packets from the slave. On receiving configurable number
//! of Sync packets from the master, the slave also sends out the DelayReq
//! packets. In response to the DelayReq packets, the Master also sends out the
//! DelayResp packets which is then received by the Slave. The slave parallely
//! maintains the internal state of the PTP in terms of \e Master \e to
//! \e Slave \e Delay and \e Slave \e to \e Master \e Delay. Consequently, the
//! slave also calculates \e Offset \e From \e Master and \e Mean \e Path
//! \e Delay.
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in PTP Basic Slave mode.
//! The example project \e Ethernet \e PTP \e Basic \e Master is intended to
//! be used along with this project to see the whole PTP Protocol state in
//! action. The second device is configured as \e Master and both devices in
//! conjunction exchange Sync, DelayReq and DelayResp packets.
//!
//! Refer to the C28x CPU1 code of ethernet_config_c28x project for configuring
//! the PTP clock that drives the system time counter on the Ethernet module.
//!
//! \b Watch \b Variables \n
//! - gPtpSlaveState
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "driverlib_cm.h"
#include "limits.h"
#include "string.h"
//
// Definition of 1 Billion or 10^9
//
#define ONE_BILLION 1000000000
//
// This frequency is actually set in the c28x side code. If it is changed
// there, then the following value also needs to be updated since the
// timestamping module is initialized with the following values.
// Default value is 100 MHz.
//
#define PTP_REF_CLOCK_FREQ 100000000
#define PTP_REF_CLOCK_PERIOD ONE_BILLION/PTP_REF_CLOCK_FREQ
static Ethernet_Handle emac_handle;
#define PACKET_LENGTH 200
Ethernet_Pkt_Desc gPktDesc;
#define ETHERNET_NO_OF_RX_PACKETS 8U
#define ETHERNET_MAX_PACKET_LENGTH PACKET_LENGTH
#define NUM_PACKET_DESC_RX_APPLICATION 8U
#define PTP_HEADER_OFFSET 14U
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
// Update clock if the offset from master wanders off further than this cutoff.
//
#define PTP_OFM_NANOSECONDS_CUTOFF 10000U
uint32_t Ethernet_numRxCallbackCustom = 0;
uint32_t releaseTxCount = 0;
Ethernet_Pkt_Desc pktDescriptorRXCustom[NUM_PACKET_DESC_RX_APPLICATION];
extern uint32_t Ethernet_numGetPacketBufferCallback;
extern Ethernet_Device Ethernet_device_struct;
uint8_t delayReqMsg[PACKET_LENGTH] = {0};
#define abs(x) (x<0?-x:x)
//
// Taking care of network byte order conversions using these macros.
//
#define PP_HTONS(x) ((uint16_t)((((x) & (uint16_t)0x00ffU) << 8) | \
(((x) & (uint16_t)0xff00U) >> 8)))
#define PP_NTOHS(x) PP_HTONS(x)
#define PP_HTONL(x) ((((x) & (uint32_t)0x000000ffUL) << 24) | \
(((x) & (uint32_t)0x0000ff00UL) << 8) | \
(((x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((x) & (uint32_t)0xff000000UL) >> 24))
#define PP_NTOHL(x) PP_HTONL(x)
#define flip16(x) PP_HTONS(x)
#define flip32(x) PP_HTONL(x)
//
// Following definitions and prototypes are specific to the PTP state machine
// and have been adapted from the IEEE 1588 standard spec.
//
#define PTP_TWO_STEP 0x02
#define PTP_UUID_LENGTH 6
#define CLOCK_IDENTITY_LENGTH 8
#define FLAG_FIELD_LENGTH 2
#define HEADER_LENGTH 34
#define ANNOUNCE_LENGTH 64
#define SYNC_LENGTH 44
#define FOLLOW_UP_LENGTH 44
#define PDELAY_REQ_LENGTH 54
#define DELAY_REQ_LENGTH 44
#define DELAY_RESP_LENGTH 54
#define PDELAY_RESP_LENGTH 54
#define PDELAY_RESP_FOLLOW_UP_LENGTH 54
#define MANAGEMENT_LENGTH 48
typedef enum {FALSE=0, TRUE} Boolean;
typedef char Octet;
typedef signed char Integer8;
typedef signed short Integer16;
typedef signed int Integer32;
typedef unsigned char UInteger8;
typedef unsigned short UInteger16;
typedef unsigned int UInteger32;
typedef unsigned short Enumeration16;
typedef unsigned char Enumeration8;
typedef unsigned char Enumeration4;
typedef unsigned char UInteger4;
typedef unsigned char Nibble;
//
// brief Implementation specific of Integer64 type
//
typedef struct {
unsigned int lsb;
int msb;
} Integer64;
typedef struct {
unsigned int lsb;
unsigned short msb;
} UInteger48;
typedef struct {
UInteger48 secondsField;
UInteger32 nanosecondsField;
} Timestamp;
//
// brief Time structure to handle Linux time information
//
typedef struct {
Integer32 seconds;
Integer32 nanoseconds;
} TimeInternal;
//
// brief The ClockIdentity type identifies a clock
//
typedef Octet ClockIdentity[CLOCK_IDENTITY_LENGTH];
//
// brief The PortIdentity identifies a PTP port.
//
typedef struct {
ClockIdentity clockIdentity;
UInteger16 portNumber;
} PortIdentity;
//
// brief The common header for all PTP messages (Table 18 of the spec)
//
//
// Message header
//
typedef struct {
Nibble transportSpecific;
Enumeration4 messageType;
UInteger4 versionPTP;
UInteger16 messageLength;
UInteger8 domainNumber;
Octet flagField[2];
Integer64 correctionfield;
PortIdentity sourcePortIdentity;
UInteger16 sequenceId;
UInteger8 controlField;
Integer8 logMessageInterval;
} MsgHeader;
typedef struct
{
PortIdentity portIdentity;
Octet port_uuid_field[PTP_UUID_LENGTH];
Timestamp syncRecvTimestamp;
Timestamp syncOriginTimestamp;
Timestamp delayReqSentTimestamp;
Timestamp delayReqRecvTimestamp;
TimeInternal delayMS;
TimeInternal delaySM;
TimeInternal offsetFromMaster;
TimeInternal meanPathDelay;
uint16_t lastSyncSeqId;
uint16_t delayReqSeqId;
uint16_t portNumber;
uint32_t clockUpdateCount;
Boolean waitingForFollowup;
Boolean waitingForDelayResp;
} PTPSlaveState;
PTPSlaveState gPtpSlaveState = {0};
//
// brief PTP Messages
//
enum {
SYNC=0x0,
DELAY_REQ=0x1,
FOLLOW_UP = 0x8,
DELAY_RESP = 0x9,
};
//
// Function prototypes used in this example
//
void fromInternalTime(TimeInternal * internal, Timestamp * external);
void msgPackHeader(Octet * buf, PTPSlaveState *ptpSlaveState);
void msgUnpackHeader(Octet * buf, MsgHeader * header);
void msgPackDelayReq(Octet * buf, PTPSlaveState * ptpSlaveState);
void InitConstants(PTPSlaveState *ptpSlaveState);
void normalizeTime(TimeInternal * r);
void
subTime(TimeInternal * r, const TimeInternal * x, const TimeInternal * y);
void
addTime(TimeInternal * r, const TimeInternal * x, const TimeInternal * y);
void div2Time(TimeInternal *r);
void toInternalTime(TimeInternal * internal, Timestamp * external);
void getTime(TimeInternal *time);
void setTime(TimeInternal *time);
void updateClock(void);
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void);
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket);
void Ethernet_releaseTxPacketBufferCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket);
main(void)
{
Ethernet_InitConfig *pInitCfg;
uint32_t varPtpConfig = 0;
Ethernet_InitInterfaceConfig initInterfaceConfig;
float subSecondInc;
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
Ethernet_getInitConfig(pInitCfg);
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBufferCustom;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallbackCustom;
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBufferCustom;
varPtpConfig = 0x0 |
(0 << ETHERNET_MAC_TIMESTAMP_CONTROL_SNAPTYPSEL_S) |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSCTRLSSR |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSEVNTENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSVER2ENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSIPENA;
//
// Subsecond increment is added to the systime counter every ptp clock tick
// hence for Digital rollover, it is simply the time period of the clock
// tick.
//
subSecondInc = PTP_REF_CLOCK_PERIOD;
Ethernet_setConfigTimestampPTP(EMAC_BASE, varPtpConfig, subSecondInc);
Ethernet_enableSysTimePTP(EMAC_BASE);
//
// Start the system with a random value.
//
Ethernet_setSysTimePTP(EMAC_BASE, 0x4132EDCA, 0x25a5a5a5);
pInitCfg->rxBuffer = Ethernet_rxBuffer;
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
// We need to program this standard multicast address so that this device
// identifies PTP over Ethernet packets correctly. "01:1B:19:00:00:00"
//
Ethernet_setMACAddr(EMAC_BASE,
1,
0x00000000,
0x00191B01,
ETHERNET_CHANNEL_0);
InitConstants(&gPtpSlaveState);
while(1)
{
}
}
void
fromInternalTime(TimeInternal * internal, Timestamp * external)
{
external->secondsField.lsb = internal->seconds;
external->nanosecondsField = internal->nanoseconds;
external->secondsField.msb = 0;
}
//
// Pack header message into OUT buffer of ptpClock
//
void
msgPackHeader(Octet * buf, PTPSlaveState *ptpSlaveState)
{
Nibble transport = 0x80;
//
// (spec annex D)
//
*(UInteger8 *) (buf + 0) = transport;
//
// PTPv2
//
*(UInteger4 *) (buf + 1) = 0x2;
//
// Default domain number is 0.
//
*(UInteger8 *) (buf + 4) = 0;
if (PTP_TWO_STEP)
*(UInteger8 *) (buf + 6) = PTP_TWO_STEP;
//
// correctionField
//
memset((buf + 8), 0, 8);
//
// sourcePortIdentity first 8 octets
//
memcpy((buf + 20), ptpSlaveState->portIdentity.clockIdentity,
CLOCK_IDENTITY_LENGTH);
//
// sourcePortIdentity last 2 octets
//
*(UInteger16 *) (buf + 28) =
flip16(ptpSlaveState->portIdentity.portNumber);
//
// Default value(spec Table 24)
//
*(UInteger8 *) (buf + 33) = 0x7F;
}
//
// Unpack Header from IN buffer to msgTmpHeader field
//
void
msgUnpackHeader(Octet * buf, MsgHeader * header)
{
header->transportSpecific = (*(Nibble *) (buf + 0)) >> 4;
header->messageType = (*(Enumeration4 *) (buf + 0)) & 0x0F;
header->versionPTP = (*(UInteger4 *) (buf + 1)) & 0x0F;
//
// force reserved bit to zero if not
//
header->messageLength = flip16(*(UInteger16 *) (buf + 2));
header->domainNumber = (*(UInteger8 *) (buf + 4));
memcpy(header->flagField, (buf + 6), FLAG_FIELD_LENGTH);
memcpy(&header->correctionfield.msb, (buf + 8), 4);
memcpy(&header->correctionfield.lsb, (buf + 12), 4);
header->correctionfield.msb = flip32(header->correctionfield.msb);
header->correctionfield.lsb = flip32(header->correctionfield.lsb);
memcpy(header->sourcePortIdentity.clockIdentity, (buf + 20),
CLOCK_IDENTITY_LENGTH);
header->sourcePortIdentity.portNumber =
flip16(*(UInteger16 *) (buf + 28));
header->sequenceId = flip16(*(UInteger16 *) (buf + 30));
header->controlField = (*(UInteger8 *) (buf + 32));
header->logMessageInterval = (*(Integer8 *) (buf + 33));
}
//
// pack delayReq message into OUT buffer of ptpClock
//
void
msgPackDelayReq(Octet * buf, PTPSlaveState * ptpSlaveState)
{
msgPackHeader(buf, ptpSlaveState);
//
// changes in header
//
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
//
// RAZ messageType
//
*(char *)(buf + 0) = *(char *)(buf + 0) | 0x01; /* Table 19 */
//
// messageLength
//
*(UInteger16 *) (buf + 2) = flip16(DELAY_REQ_LENGTH);
//
// Sequence Id
//
*(UInteger16 *) (buf + 30) =
flip16(ptpSlaveState->delayReqSeqId);
//
// controlField
//
*(UInteger8 *) (buf + 32) = 0x01; /* Table 23 */
//
// logMessageInterval
//
*(Integer8 *) (buf + 33) = 0x7F; /* Table 24 */
}
void InitConstants(PTPSlaveState *ptpSlaveState)
{
uint32_t mac_low,mac_high, i, j;
uint8_t *pucTemp;
Ethernet_getMACAddr(EMAC_BASE, 0, &mac_high, &mac_low);
pucTemp = (uint8_t *)&mac_low;
ptpSlaveState->port_uuid_field[0] = pucTemp[0];
ptpSlaveState->port_uuid_field[1] = pucTemp[1];
ptpSlaveState->port_uuid_field[2] = pucTemp[2];
ptpSlaveState->port_uuid_field[3] = pucTemp[3];
pucTemp = (uint8_t *)&mac_high;
ptpSlaveState->port_uuid_field[4] = pucTemp[0];
ptpSlaveState->port_uuid_field[5] = pucTemp[1];
//
// Init global constants.
//
for (i = 0, j = 0; i < CLOCK_IDENTITY_LENGTH; i++)
{
if (i == 3) ptpSlaveState->portIdentity.clockIdentity[i]=0xFF;
else if (i==4) ptpSlaveState->portIdentity.clockIdentity[i]=0xFE;
else
{
ptpSlaveState->portIdentity.clockIdentity[i] =
ptpSlaveState->port_uuid_field[j];
j++;
}
}
}
void
normalizeTime(TimeInternal * r)
{
r->seconds += r->nanoseconds / ONE_BILLION;
r->nanoseconds -= r->nanoseconds / ONE_BILLION * ONE_BILLION;
if (r->seconds > 0 && r->nanoseconds < 0) {
r->seconds -= 1;
r->nanoseconds += ONE_BILLION;
} else if (r->seconds < 0 && r->nanoseconds > 0) {
r->seconds += 1;
r->nanoseconds -= ONE_BILLION;
}
}
void
addTime(TimeInternal * r, const TimeInternal * x, const TimeInternal * y)
{
r->seconds = x->seconds + y->seconds;
r->nanoseconds = x->nanoseconds + y->nanoseconds;
normalizeTime(r);
}
void
subTime(TimeInternal * r, const TimeInternal * x, const TimeInternal * y)
{
r->seconds = x->seconds - y->seconds;
r->nanoseconds = x->nanoseconds - y->nanoseconds;
normalizeTime(r);
}
void div2Time(TimeInternal *r)
{
r->nanoseconds += r->seconds % 2 * ONE_BILLION;
r->seconds /= 2;
r->nanoseconds /= 2;
normalizeTime(r);
}
void
toInternalTime(TimeInternal * internal, Timestamp * external)
{
//
// Program will not run after 2038...
//
if (external->secondsField.lsb < INT_MAX) {
internal->seconds = external->secondsField.lsb;
internal->nanoseconds = external->nanosecondsField;
}
else
{
//
// Error condition.
// Clock servo canno't be executed :
// seconds field is higher than signed integer (32bits))
//
return;
}
}
void
getTime(TimeInternal *time)
{
//
// Fetch the current system time.
//
Ethernet_getSysTimePTP(EMAC_BASE, (uint32_t *)&time->seconds,
(uint32_t *)&time->nanoseconds);
}
void
setTime(TimeInternal *time)
{
//
// Set the new system time.
//
Ethernet_setSysTimePTP(EMAC_BASE, (uint32_t)time->seconds,
(uint32_t)time->nanoseconds);
}
void updateClock(void)
{
TimeInternal timeTmp;
//
// Update the clock if either
//
if((gPtpSlaveState.offsetFromMaster.seconds > 0) ||
(abs(gPtpSlaveState.offsetFromMaster.nanoseconds) >
PTP_OFM_NANOSECONDS_CUTOFF))
{
getTime(&timeTmp);
subTime(&timeTmp, &timeTmp, &gPtpSlaveState.offsetFromMaster);
setTime(&timeTmp);
gPtpSlaveState.clockUpdateCount++;
}
}
//*****************************************************************************
//
// This function is a callback function called by the example to
// get a Packet Buffer. Has to return a ETHERNET_Pkt_Desc Structure.
// Rewrite this API for custom use case.
//
//*****************************************************************************
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void)
{
//
// Get the next packet descriptor from the descriptor pool
//
uint32_t shortIndex = (Ethernet_numGetPacketBufferCallback + 3)
% NUM_PACKET_DESC_RX_APPLICATION;
//
// Increment the book-keeping pointer which acts as a head pointer
// to the circular array of packet descriptor pool.
//
Ethernet_numGetPacketBufferCallback++;
//
// Update buffer length information to the newly procured packet
// descriptor.
//
pktDescriptorRXCustom[shortIndex].bufferLength =
ETHERNET_MAX_PACKET_LENGTH;
//
// Update the receive buffer address in the packer descriptor.
//
pktDescriptorRXCustom[shortIndex].dataBuffer =
&Ethernet_device_struct.rxBuffer [ \
(ETHERNET_MAX_PACKET_LENGTH*Ethernet_device_struct.rxBuffIndex)];
//
// Update the receive buffer pool index.
//
Ethernet_device_struct.rxBuffIndex += 1U;
Ethernet_device_struct.rxBuffIndex = \
(Ethernet_device_struct.rxBuffIndex%ETHERNET_NO_OF_RX_PACKETS);
//
// Receive buffer is usable from Address 0
//
pktDescriptorRXCustom[shortIndex].dataOffset = 0U;
//
// Return this new descriptor to the driver.
//
return (&(pktDescriptorRXCustom[shortIndex]));
}
//*****************************************************************************
//
// This is a hook function and called by the driver when it receives a
// packet. Application is expected to replenish the buffer after consuming it.
// Has to return a ETHERNET_Pkt_Desc Structure.
// Rewrite this API for custom use case.
//
//*****************************************************************************
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
MsgHeader header;
TimeInternal recvTime;
TimeInternal sendTime;
uint32_t i;
msgUnpackHeader((Octet*)(pPacket->dataBuffer + PTP_HEADER_OFFSET), &header);
switch(header.messageType)
{
case SYNC:
//
// 1. Save the Sync receive timestamp.
//
gPtpSlaveState.syncRecvTimestamp.nanosecondsField =
pPacket->timeStampLow;
gPtpSlaveState.syncRecvTimestamp.secondsField.lsb =
pPacket->timeStampHigh;
gPtpSlaveState.syncRecvTimestamp.secondsField.msb = 0;
gPtpSlaveState.lastSyncSeqId = header.sequenceId;
break;
case FOLLOW_UP:
//
// 1. Retrieve the Sync send timestamp.
// 2. Calculate the Master to Slave delay
// 3. Subtract this from Mean Path Delay to get "Offset from Master"
// 4. Update the clock based on this value. Course correction.
//
if(header.sequenceId == gPtpSlaveState.lastSyncSeqId)
{
gPtpSlaveState.syncOriginTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 34 ));
gPtpSlaveState.syncOriginTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 36));
gPtpSlaveState.syncOriginTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 40));
while(gPtpSlaveState.syncOriginTimestamp.secondsField.lsb == 0x2000CE44);
//
// converting the origin timestamp to internal time
//
toInternalTime(&sendTime, &gPtpSlaveState.syncOriginTimestamp);
//
// converting the sync receive timestamp to internal time
//
toInternalTime(&recvTime, &gPtpSlaveState.syncRecvTimestamp);
//
// Calculate Master to slave delay
//
subTime(&gPtpSlaveState.delayMS, &recvTime, &sendTime);
//
// Calculate offset from master
//
subTime(&gPtpSlaveState.offsetFromMaster,
&gPtpSlaveState.delayMS,
&gPtpSlaveState.meanPathDelay);
updateClock();
//
// If sufficient sync/followups have been received, then issue a
// delay request packet.
//
if(!((gPtpSlaveState.lastSyncSeqId + 1) % 10))
{
//
// We need to set a standard defined Multicast address : 01:1B:19:00:00:00
// as the Destination address in the ethernet frame and that is how the
// receiver will recognize it as a valid PTP over Ethernet packet.
//
i=0; *((uint32_t *)delayReqMsg + i) = 0x00191B01;
i++; *((uint32_t *)delayReqMsg + i) = 0xF7880000;
//
// Reset the buffer next sync packet.
//
memset(delayReqMsg+8, 0, PACKET_LENGTH-8);
msgPackDelayReq((Octet *)delayReqMsg + 8, &gPtpSlaveState);
gPktDesc.bufferLength = PACKET_LENGTH;
gPktDesc.dataOffset = 0;
gPktDesc.dataBuffer = delayReqMsg;
gPktDesc.nextPacketDesc = 0;
gPktDesc.flags = ETHERNET_PKT_FLAG_TTSE |
ETHERNET_PKT_FLAG_SOP |
ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS |
ETHERNET_PKT_FLAG_CRC_PAD_INS;
gPktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
gPktDesc.pktLength = DELAY_REQ_LENGTH + 6 + 2;
gPktDesc.validLength = gPktDesc.pktLength;
gPktDesc.numPktFrags = 1;
Ethernet_sendPacket(emac_handle,&gPktDesc);
gPtpSlaveState.delayReqSeqId++;
}
}
break;
case DELAY_RESP:
//
// 1. Get the "Delay Request receive timestamp.
// 2. Calculate the Slave to Master Delay.
// 3. Calculate the Mean Path Delay and save it.
//
if(gPtpSlaveState.waitingForDelayResp == TRUE)
{
gPtpSlaveState.waitingForDelayResp = FALSE;
gPtpSlaveState.delayReqRecvTimestamp.secondsField.msb =
flip16(*(UInteger16 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 34 ));
gPtpSlaveState.delayReqRecvTimestamp.secondsField.lsb =
flip32(*(UInteger32 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 36));
gPtpSlaveState.delayReqRecvTimestamp.nanosecondsField =
flip32(*(UInteger32 *) (pPacket->dataBuffer + PTP_HEADER_OFFSET + 40));
//
// Update delay and calculate Mean Path Delay.
//
toInternalTime(&sendTime, &gPtpSlaveState.delayReqSentTimestamp);
toInternalTime(&recvTime, &gPtpSlaveState.delayReqRecvTimestamp);
subTime(&gPtpSlaveState.delaySM, &recvTime, &sendTime);
addTime(&gPtpSlaveState.meanPathDelay,
&gPtpSlaveState.delaySM,
&gPtpSlaveState.delayMS);
div2Time(&gPtpSlaveState.meanPathDelay);
}
break;
}
//
// Book-keeping to maintain number of callbacks received.
//
#ifdef ETHERNET_DEBUG
Ethernet_numRxCallbackCustom++;
#endif
return Ethernet_getPacketBufferCustom();
}
void Ethernet_releaseTxPacketBufferCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
gPtpSlaveState.delayReqSentTimestamp.nanosecondsField =
pPacket->timeStampLow;
gPtpSlaveState.delayReqSentTimestamp.secondsField.lsb =
pPacket->timeStampHigh;
gPtpSlaveState.delayReqSentTimestamp.secondsField.msb = 0;
gPtpSlaveState.waitingForDelayResp = TRUE;
//
// Increment the book-keeping counter.
//
#ifdef ETHERNET_DEBUG
releaseTxCount++;
#endif
}
@@ -0,0 +1,335 @@
//#############################################################################
//
// FILE: ethernet_ex5_ptp_offload_master.c
//
// TITLE: Ethernet PTP Offload Master Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet PTP Offload Master </h1>
//!
//! This example configures the device in IEEE PTPv2 Master mode and sets the
//! options that are needed by the offload engine to operate such as the
//! \e domainNumber, \e LogSyncInterval among others. After that it enables
//! sending SYNC messages periodically according to the interval already set
//! previously.
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in PTP Offload Master mode.
//! The example project \e Ethernet \e PTP \e Offload \e Slave is intended to
//! be used along with this project to see the whole PTP Offload engine in
//! action. The second device is configured as \e Slave and both devices in
//! conjunction exchange Sync, DelayReq and DelayResp packets.
//!
//! Refer to the C28x CPU1 code of ethernet_config_c28x project for configuring
//! the PTP clock that drives the system time counter on the Ethernet module.
//!
//! \b Watch \b Variables \n
//! - Ethernet_ptpDelayReqPktCount
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "driverlib_cm.h"
#include "cm.h"
//
// This frequency is actually set in the c28x side code. If it is changed
// there, then the following value also needs to be updated since the
// timestamping module is initialized with the following values.
// Default value is 100 MHz.
//
#define PTP_REF_CLOCK_FREQ 100000000
#define PTP_REF_CLOCK_PERIOD 1000000000/PTP_REF_CLOCK_FREQ
#define NUM_PACKET_DESC_RX_APPLICATION 8U
#define ETHERNET_NO_OF_RX_PACKETS 8U
#define ETHERNET_MAX_PACKET_LENGTH 100U
static Ethernet_Handle emac_handle;
extern Ethernet_Device Ethernet_device_struct;
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
//
// This function is a callback function called by the LLD to
// Get a Packet Buffer. Has to return a ETHERNET_Pkt_Desc Structure filled
// User or upper level stack can rewrite this API for their own use case
//
uint32_t Ethernet_numGetPacketBufferCallbackCustom = 0;
uint32_t Ethernet_numRxCallbackCustom = 0;
uint32_t Ethernet_ptpDelayReqPktCount = 0;
Ethernet_Pkt_Desc pktDescriptorRXCustom[NUM_PACKET_DESC_RX_APPLICATION];
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void)
{
uint32_t shortIndex = (Ethernet_numGetPacketBufferCallbackCustom + 3) %
NUM_PACKET_DESC_RX_APPLICATION;
Ethernet_numGetPacketBufferCallbackCustom++;
pktDescriptorRXCustom[shortIndex].bufferLength =
ETHERNET_MAX_PACKET_LENGTH;
pktDescriptorRXCustom[shortIndex].dataBuffer =
&Ethernet_device_struct.rxBuffer [
(ETHERNET_MAX_PACKET_LENGTH * Ethernet_device_struct.rxBuffIndex)];
//
// Wrap around
//
Ethernet_device_struct.rxBuffIndex += 1U;
Ethernet_device_struct.rxBuffIndex =
(Ethernet_device_struct.rxBuffIndex%ETHERNET_NO_OF_RX_PACKETS);
//
// Usable from Address 0
//
pktDescriptorRXCustom[shortIndex].dataOffset = 0U;
return (&(pktDescriptorRXCustom[shortIndex]));
}
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
//
// 14th byte in the received packet is 'messageType' field of
// ptp frame format.
//
// messageType == 0x1 indicates "DelayReq" packet.
//
if ((pPacket->dataBuffer[14] & 0x0F) == 0x1)
Ethernet_ptpDelayReqPktCount++;
Ethernet_numRxCallbackCustom++;
//
// This is a placeholder for Application specific handling
// We are replenishing the buffer received with another buffer
//
return Ethernet_getPacketBufferCustom();
}
main(void)
{
Ethernet_InitConfig *pInitCfg;
Ethernet_InitInterfaceConfig initInterfaceConfig;
uint32_t varPtpConfig = 0;
float subSecondInc;
//
// Initialize device clock and peripherals
//
CM_init();
//
// Hardcoded MAC Address
//
uint32_t mac_lower = 0x00F363A8;
uint32_t mac_higher = 0x00800000;
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
Ethernet_getInitConfig(pInitCfg);
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallbackCustom;
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBufferCustom;
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
Interrupt_registerHandler(INT_EMAC,Ethernet_genericISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Interrupt_enable(INT_EMAC);
Ethernet_setMACAddr(EMAC_BASE,
0,
mac_higher,
mac_lower,
ETHERNET_CHANNEL_0);
//
// We need to program this standard multicast address so that this device
// identifies PTP over Ethernet packets correctly. "01:1B:19:00:00:00"
//
Ethernet_setMACAddr(EMAC_BASE,
1,
0x00000000,
0x00191B01,
ETHERNET_CHANNEL_0);
//
// Ethernet PTP module is configured with:
// - Master
// - Identify event messages (Sync, DelayReq)
// - Identify PTP over Ethernet packets
// - PTP version 2
// - Digital Rollover
//
varPtpConfig = 0x0 |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSEVNTENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSMSTRENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSIPENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSVER2ENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSCTRLSSR;
subSecondInc = PTP_REF_CLOCK_PERIOD;
Ethernet_setConfigTimestampPTP(EMAC_BASE, varPtpConfig, subSecondInc);
Ethernet_enableSysTimePTP(EMAC_BASE);
Ethernet_setSysTimePTP(EMAC_BASE, 0x4132EDCA, 0x25a5a5a5);
//
// PTP Offlad related configuration follows. This is used to automatically
// assemble the PTP Header for the packets which will be ultimately sent
// out by the PTP Offload engine.
//
Ethernet_PTPOffloadConfigParams ptoConfigParams = {0};
//
// "sourcePortIdentity" field in the PTP Header.
//
ptoConfigParams.srcPortId.id0 = 0xFFFFFFFF;
ptoConfigParams.srcPortId.id1 = 0xFFFFFFFF;
ptoConfigParams.srcPortId.id2 = 0xFFFF;
//
// "logMessageInterval" field in the PTP Header.
//
ptoConfigParams.logMsgIntervalConf.delayReqToSyncRatio = 2;
ptoConfigParams.logMsgIntervalConf.logMinPdelayReqInterval= 0;
ptoConfigParams.logMsgIntervalConf.logSyncInterval = 0;
//
// "domainNumber" field in the PTP Header.
//
ptoConfigParams.domainNumber = 0x00;
//
// Automatic Message reply switches follow
//
//
// Peer to Peer mechanism not required, so disable sending of PDelayReq
// packet.
//
ptoConfigParams.ptoAutoPDelayReqMode =
ETHERNET_PTO_AUTO_P_DELAY_REQ_MESSAGE_DISABLE;
//
// This is Master code, so enable sending of Sync packets.
//
ptoConfigParams.ptoAutoPtpSyncMode =
ETHERNET_PTO_AUTO_SYNC_MESSAGE_ENABLE;
//
// Since this is Master code, enabling this switch will result in sending
// of automatic DelayResp messages in response to the DelayReq messages
// sent by the slave.
//
ptoConfigParams.ptoDelayReqRespMode =
ETHERNET_PTO_DELAY_REQ_DELAY_RESP_ENABLE;
//
// Peer to Peer mechanism not required, so disable sending of PDelayResp
// packet.
//
ptoConfigParams.ptoPDelayRespMode =
ETHERNET_PTO_P_DELAY_RESP_MESSAGE_DISABLE;
//
// Pass the configuration to the Ethernet driver to program the hardware
// with this.
//
Ethernet_setConfigPTPOffload(EMAC_BASE, ptoConfigParams);
//
// Finally, enable the PTP offload engine for above configuration to take
// effect.
//
Ethernet_enableDisablePTPOffload(EMAC_BASE, ETHERNET_PTP_OFFLOAD_ENABLE);
while(1)
{
}
}
@@ -0,0 +1,396 @@
//#############################################################################
//
// FILE: ethernet_ex5_ptp_offload_slave.c
//
// TITLE: Ethernet PTP Offload Slave Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet PTP Offload Slave </h1>
//!
//! This example configures the device in IEEE PTPv2 Slave mode and sets the
//! options that are needed by the offload engine to operate such as the
//! \e domainNumber, \e LogSyncInterval among others. After that it enables
//! sending DelayReq messages periodically for every configurable number of
//! Sync packets.
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in PTP Offload Slave mode.
//! The example project \e Ethernet \e PTP \e Offload \e Master is intended to
//! be used along with this project to see the whole PTP Offload engine in
//! action. The second device is configured as \e Slave and both devices in
//! conjunction exchange Sync, DelayReq and DelayResp packets.
//!
//! Refer to the C28x CPU1 code of ethernet_config_c28x project for configuring
//! the PTP clock that drives the system time counter on the Ethernet module.
//!
//! \b Watch \b Variables \n
//! - Ethernet_ptpSyncPktCount
//! - Ethernet_ptpDelayRespPktCount
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "driverlib_cm.h"
#include "cm.h"
//
// This frequency is actually set in the c28x side code. If it is changed
// there, then the following value also needs to be updated since the
// timestamping module is initialized with the following values.
//
#define PTP_REF_CLOCK_FREQ 100000000
#define PTP_REF_CLOCK_PERIOD 1000000000/PTP_REF_CLOCK_FREQ
#define NUM_PACKET_DESC_RX_APPLICATION 8U
#define ETHERNET_NO_OF_RX_PACKETS 8U
#define ETHERNET_MAX_PACKET_LENGTH 100U
static Ethernet_Handle emac_handle;
extern Ethernet_Device Ethernet_device_struct;
extern void Ethernet_enableMACInterrupt(uint32_t base, uint32_t flags);
//
// Prototype definitions for this example
//
interrupt void Ethernet_customGenericISR(void);
// This function is a callback function called by the LLD to
// Get a Packet Buffer. Has to return a ETHERNET_Pkt_Desc Structure filled
// User or upper level stack can rewrite this API for their own use case
//
uint32_t Ethernet_numRxCallbackCustom = 0;
uint32_t Ethernet_ptpSyncPktCount = 0;
uint32_t Ethernet_ptpDelayRespPktCount = 0;
uint32_t Ethernet_customGenericInterruptCount = 0;
uint32_t Ethernet_numGetPacketBufferCallbackCustom;
Ethernet_Pkt_Desc pktDescriptorRXCustom[NUM_PACKET_DESC_RX_APPLICATION];
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
Ethernet_Pkt_Desc* Ethernet_getPacketBufferCustom(void)
{
uint32_t shortIndex = (Ethernet_numGetPacketBufferCallbackCustom + 3) %
NUM_PACKET_DESC_RX_APPLICATION;
Ethernet_numGetPacketBufferCallbackCustom++;
pktDescriptorRXCustom[shortIndex].bufferLength =
ETHERNET_MAX_PACKET_LENGTH;
pktDescriptorRXCustom[shortIndex].dataBuffer =
&Ethernet_device_struct.rxBuffer[
(ETHERNET_MAX_PACKET_LENGTH * Ethernet_device_struct.rxBuffIndex)];
//
// Wrap around
//
Ethernet_device_struct.rxBuffIndex += 1U;
Ethernet_device_struct.rxBuffIndex =
(Ethernet_device_struct.rxBuffIndex % ETHERNET_NO_OF_RX_PACKETS);
//
// Usable from Address 0
//
pktDescriptorRXCustom[shortIndex].dataOffset = 0U;
return (&(pktDescriptorRXCustom[shortIndex]));
}
Ethernet_Pkt_Desc* Ethernet_receivePacketCallbackCustom(
Ethernet_Handle handleApplication,
Ethernet_Pkt_Desc *pPacket)
{
//
// 14th byte in the received packet is 'messageType' field of
// ptp frame format.
//
// messageType == 0x0 indicates "Sync" packet.
// messageType == 0x9 indicates "DelayResp" packet.
//
if ((pPacket->dataBuffer[14] & 0x0F) == 0x0)
Ethernet_ptpSyncPktCount++;
else if ((pPacket->dataBuffer[14] & 0x0F) == 0x9)
Ethernet_ptpDelayRespPktCount++;
Ethernet_numRxCallbackCustom++;
//
// This is a placeholder for Application specific handling
// We are replenishing the buffer received with another buffer
//
return Ethernet_getPacketBufferCustom();
}
main(void)
{
Ethernet_InitConfig *pInitCfg;
Ethernet_InitInterfaceConfig initInterfaceConfig;
uint32_t varPtpConfig = 0;
float subSecondInc;
//
// Hardcoded MAC Address
//
uint32_t mac_lower = 0x00F263A8;
uint32_t mac_higher = 0x00800000;
//
// Initialize device clock and peripherals
//
CM_init();
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
Ethernet_getInitConfig(pInitCfg);
pInitCfg->pfcbRxPacket=&Ethernet_receivePacketCallbackCustom;
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBufferCustom;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg, &emac_handle);
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
Interrupt_registerHandler(INT_EMAC, Ethernet_customGenericISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Interrupt_enable(INT_EMAC);
Ethernet_setMACAddr(EMAC_BASE,
0,
mac_higher,
mac_lower,
ETHERNET_CHANNEL_0);
//
// We need to program this standard multicast address so that this device
// identifies PTP over Ethernet packets correctly. "01:1B:19:00:00:00"
//
Ethernet_setMACAddr(EMAC_BASE,
1,
0x00000000,
0x00191B01,
ETHERNET_CHANNEL_0);
//
// Ethernet PTP module is configured with:
// - Slave
// - Identify event messages (Sync, DelayReq)
// - Identify PTP over Ethernet packets
// - PTP version 2
// - Digital Rollover
//
varPtpConfig = ETHERNET_MAC_TIMESTAMP_CONTROL_TSEVNTENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSIPENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSVER2ENA |
ETHERNET_MAC_TIMESTAMP_CONTROL_TSCTRLSSR;
subSecondInc = PTP_REF_CLOCK_PERIOD;
Ethernet_setConfigTimestampPTP(EMAC_BASE, varPtpConfig, subSecondInc);
Ethernet_enableSysTimePTP(EMAC_BASE);
Ethernet_setSysTimePTP(EMAC_BASE, 0x4132EDCA, 0x25a5a5a5);
//
// Enable the timestamp interrupt to get an interrupt when timestamp is
// captured for the outgoing DelayReq packet.
//
Ethernet_enableMACInterrupt(EMAC_BASE, ETHERNET_MAC_INTERRUPT_ENABLE_TSIE);
//
// PTP Offlad related configuration follows. This is used to automatically
// assemble the PTP Header for the packets which will be ultimately sent
// out by the PTP Offload engine.
//
Ethernet_PTPOffloadConfigParams ptoConfigParams = {0};
//
// "sourcePortIdentity" field in the PTP Header.
//
ptoConfigParams.srcPortId.id0 = 0xFFFFFFFF;
ptoConfigParams.srcPortId.id1 = 0xFFFFFFFF;
ptoConfigParams.srcPortId.id2 = 0x0000;
//
// "logMessageInterval" field in the PTP Header.
//
ptoConfigParams.logMsgIntervalConf.delayReqToSyncRatio = 2;
ptoConfigParams.logMsgIntervalConf.logMinPdelayReqInterval= 0;
ptoConfigParams.logMsgIntervalConf.logSyncInterval = 0;
//
// "domainNumber" field in the PTP Header.
//
ptoConfigParams.domainNumber = 0x00;
//
// Automatic Message reply switches follow
//
//
// Peer to Peer mechanism not required, so disable sending of PDelayReq
// packet.
//
ptoConfigParams.ptoAutoPDelayReqMode =
ETHERNET_PTO_AUTO_P_DELAY_REQ_MESSAGE_DISABLE;
//
// This is slave code, so disable sending of Sync packets.
//
ptoConfigParams.ptoAutoPtpSyncMode =
ETHERNET_PTO_AUTO_SYNC_MESSAGE_DISABLE;
//
// Since this is slave code, enabling this switch will result in sending
// of automatic DelayReq messages in response to a configurable number of
// Sync packets.
//
ptoConfigParams.ptoDelayReqRespMode =
ETHERNET_PTO_DELAY_REQ_DELAY_RESP_ENABLE;
//
// Peer to Peer mechanism not required, so disable sending of PDelayResp
// packet.
//
ptoConfigParams.ptoPDelayRespMode =
ETHERNET_PTO_P_DELAY_RESP_MESSAGE_DISABLE;
//
// Pass the configuration to the Ethernet driver to program the hardware
// with this.
//
Ethernet_setConfigPTPOffload(EMAC_BASE, ptoConfigParams);
//
// Finally, enable the PTP offload engine for above configuration to take
// effect.
//
Ethernet_enableDisablePTPOffload(EMAC_BASE, ETHERNET_PTP_OFFLOAD_ENABLE);
//
// Wait forever. Sending of the messages is handled by the PTP Offload
// hardware.
//
while(1)
{
}
}
interrupt void Ethernet_customGenericISR(void)
{
//
// Increment the generic interrupt receive count
//
Ethernet_customGenericInterruptCount++;
if(true == Ethernet_isTimestampIntActive())
{
//
// Placeholder to call any Timestamp Interrupt Handler API.
//
// Following is a dummy implementation for a case
// when tx timestamp is captured for an outgoing packet
// in PTP Offload mode. Refer to
// individual APIs for more information.
// Note: For this particular case, when the interrupt
// is generated for transmit timestamp capture
// in PTP offload mode the Interrupt is cleared
// only when the actual timestamp
// is read from the Timestamp Status
// Seconds and Nanoseconds registers
//
uint32_t seconds, nanoSeconds;
//
// Check if the transmit timestamp status is set.
//
if(true == Ethernet_isTransmitTimestampStatusSet())
{
//
// Read the timestamp for the transmitted packet to
//clear this interrupt
//
Ethernet_getOneStepTransmitTimestampPTP(
Ethernet_device_struct.baseAddresses.enet_base,
&seconds,
&nanoSeconds);
}
}
}
@@ -0,0 +1,256 @@
//#############################################################################
//
// FILE: ethernet_ex6_basic_crc_checksum_offload.c
//
// TITLE: Ethernet CRC and Checksum Offloading Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet MAC CRC and Checksum Offload </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in MAC Loop back mode.
//! Demonstrates how to program the CRC offload
//! and Checksum Offload(IP Checksum)
//! Prepares a packet to be sent, Sends the packet and reads the statistics
//! to check if the packet is received by the module
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in Internal Loop back mode
//! and hence needs no external connection on the MII Data lines.
//! But it needs the MII Tx and Rx clocks to be input on those pins
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 128U
//
// Globals
//
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
//
//This is an example IP protocol packet
//
uint8_t icmp98[92] = {
//0xa8, 0x63, 0xf2, 0x00, 0x00, 0x80,
0x04, 0x03, 0x02, 0x01, 0x06, 0x05,
/* Since the sender MAC address is going to be embedded
* before sending the packet, we comment the following 6 bytes
*/
/*0x78, 0xa5, // .c....x. // 0x04, 0xc8, 0xa5, 0x0b,*/
0x08, 0x00, 0x45, 0x00, /* ......E. */
0x00, 0x54, 0xb1, 0xa2, 0x40, 0x00, 0x40, 0x01, /* .T..@.@. */
0x07, 0xae, 0xc0, 0xa8, 0x00, 0x03, 0xc0, 0xa8, /* ........ */
0x00, 0x04, 0x07, 0x00, 0x32, 0x4a, 0x57, 0xe8, /* ....2JW. */
0x00, 0x01, 0x73, 0x84, 0xfe, 0x58, 0x04, 0xec, /* ..s..X.. */
0x0c, 0x00, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, /* ........ */
0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, /* ........ */
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, /* ........ */
0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, /* .. !"#$% */
0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, /* &'()*+,- */
0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, /* ./012345 */
0x36, 0x38 /* 67 */
};
#define PACKET_LENGTH sizeof(icmp98)
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
Ethernet_Statistics stats;
Ethernet_Handle emac_handle;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Configure the Loopback mode
//
pInitCfg->loopbackMode = ETHERNET_MAC_CONFIGURATION_LM_LOOPBACK_ENABLED;
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer packet
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = icmp98;
pktDesc.nextPacketDesc = 0;
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//Please OR these values to achieve required CRC offloading
//ETHERNET_PKT_FLAG_CRC_PAD_INS value is zero which corresponds to CRC
//Insertion and Pad enabling
//Use ETHERNET_PKT_FLAG_CRC_INS_NO_PAD to insert CRC but no padding
//Use ETHERNET_PKT_FLAG_CRC_PAD_DIS to disable CRC and Disable padding
//Use ETHERNET_PKT_FLAG_CRC_REPL_NO_PAD to replace CRC and disable padding
//
//ETHERNET_PKT_FLAG_CIC flag enables the Checksum offload feature at driver
//which turns on the Hardware Checksum feature with this flag being set
//
pktDesc.flags = (ETHERNET_PKT_FLAG_SOP | ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS | ETHERNET_PKT_FLAG_CIC);
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire and receive it
//
SysCtl_delay(3000);
//
//Read the statistics of the Module
//
Ethernet_getStatistics(emac_handle, &stats);
//
//Check if a packet has been received
//
if(!stats.rxUnicastPacketsGood)
__asm(" bkpt #0");
}
@@ -0,0 +1,438 @@
//#############################################################################
//
// FILE: ethernet_ex7_transport_segmentation_offload.c
//
// TITLE: Ethernet Transport Segmentation Offload Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet Transmit Segmentation Offload </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in MAC Loop back mode.
//! Demonstrates how to program the Transport Segmentation Offload feature
//! in the Low level driver which in turn programs the feature in the hardware
//! The Hardware segments a single packet into configured segment size
//! Prepares a packet to be sent, Sends the packet and reads the statistics
//! to check if the packet is received by the module
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in Internal Loop back mode
//! and hence needs no external connection on the MII Data lines.
//! But it needs the MII Tx and Rx clocks to be input on those pins
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 1334
#define NO_OF_RX_PACKETS 4U
//
//Change this define for changing Packet buffer length
//
#define MAX_PACKET_LENGTH 450U
uint8_t Ethernet_rxBuffer[NO_OF_RX_PACKETS *
MAX_PACKET_LENGTH];
//
// Globals
//
Ethernet_Pkt_Desc pktDescriptorRX;
uint32_t rxBuffIndex=0;
//
//This is an example IP protocol packet
//
uint8_t pSegmentData[PACKET_LENGTH]= {
0x04, 0x03, 0x02, 0x01, 0x06, 0x05, 0x08, 0x00,
0x45, 0x00, 0x05, 0x28, 0x00, 0x00, 0x40, 0x00,
0x40, 0x06, 0xB3, 0x7F, 0xC0, 0xA8, 0x00, 0x01,
0xC0, 0xA8, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x50, 0x00, 0xFF, 0xFC, 0x67, 0x58, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
Ethernet_Pkt_Desc *getPacketBufferCustom(void);
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Statistics stats;
Ethernet_Handle emac_handle;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
for(i=0;i<pInitCfg->numChannels;i++)
{
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].dmaQueueSize = ETHERNET_MTL_Q_OP_MODE_QSIZE_2048;
//
//This enables the Transport Segmentation Engine
//
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].enableTSE = ETHERNET_TX_CHANNEL_TSE_ENABLE;
//
//This configures the Segment Size for each Transport Segment going
//out/Transmitted by the MAC
//
pInitCfg->chInfo[ETHERNET_CH_DIR_TX][i].maximumSegmentSize = 0x140;
}
//
//Configure the Loopback mode
//
pInitCfg->loopbackMode = ETHERNET_MAC_CONFIGURATION_LM_LOOPBACK_ENABLED;
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &getPacketBufferCustom;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer packet
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pSegmentData;
//
//Second dataBuffer points to location where the Transport Segment starts
//
pktDesc.dataBuffer2 = pSegmentData+48;
pktDesc.nextPacketDesc = 0;
//
//Enable Transport Segmentation on the packet
//This also enables CRC offload engine
//Source Address is to be auto inserted by the MAC
//
pktDesc.flags = ETHERNET_PKT_FLAG_SOP | ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS | ETHERNET_PKT_FLAG_TSE;
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
//
//
//
pktDesc.pktLength = 1280;
pktDesc.validLength = 48; //Header Buffer 1
pktDesc.buffer2Length = 1280;//Payload length
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire and receive it
//
SysCtl_delay(3000);
//
//Read the statistics of the Module
//
Ethernet_getStatistics(emac_handle, &stats);
//
//Check if a packet has been received
//There should be three packets received since
//There are three segments/frames sent by the MAC after segmentation
//
while(1);
}
Ethernet_Pkt_Desc *getPacketBufferCustom(void)
{
pktDescriptorRX.bufferLength = MAX_PACKET_LENGTH;
pktDescriptorRX.dataBuffer = &Ethernet_rxBuffer [
(MAX_PACKET_LENGTH * rxBuffIndex)];
//
//Wrap around
//
rxBuffIndex += 1U;
rxBuffIndex = rxBuffIndex% NO_OF_RX_PACKETS;
return(&pktDescriptorRX);
}
@@ -0,0 +1,297 @@
//#############################################################################
//
// FILE: ethernet_ex8_vlan_filtering.c
//
// TITLE: Ethernet VLAN and VLAN Filter Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet MAC Internal Loopback </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in MAC Loop back mode
//! The packet sent is inserted with a VLAN tag.
//! A VLAN filter is configured to route it to a different channel
//! Prepares a packet to be sent, Sends the packet and reads the statistics
//! to check if the packet is received by the module
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//!
//! \b External \b Connections \n
//! This example programs the Ethernet module in Internal Loop back mode
//! and hence needs no external connection on the MII Data lines.
//! But it needs the MII Tx and Rx clocks to be input on those pins
//! Refer to the C28x CPU1 code of ethernet_config_c28x project
//! for which GPIOs are used for connecting to the PHY
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 1538U
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
//
// Globals
//
#define PACKET_LENGTH 1508
uint8_t pData[PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Statistics stats;
Ethernet_VlanConfig vLANConfig;
Ethernet_VLAN_Perfect_FilterParams vlanPerfectFilterParams;
Ethernet_Handle emac_handle;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Configure the Loopback mode
//
pInitCfg->loopbackMode = ETHERNET_MAC_CONFIGURATION_LM_LOOPBACK_ENABLED;
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_TX1, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
Interrupt_registerHandler(INT_EMAC_RX1, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
Interrupt_enable(INT_EMAC_TX1);
Interrupt_enable(INT_EMAC_RX1);
//
//Setup VLAN Parameters
//
vLANConfig.vlan_tag =0x0B0B;
vLANConfig.vlanType = ETHERNET_VLAN_TYPE_C;
vLANConfig.vlanTagControl = ETHERNET_VLAN_TX_INSERT;
//
//This sets a VLAN Tag insertion for all the packets going out of the MAC
//
Ethernet_setConfig(emac_handle,ETHERNET_SET_CONFIG_VLAN_TX_OUTER,
&vLANConfig,sizeof(vLANConfig));
//
//Make the Queues to assign based on dynamic Queues
//Hence the DMA channels will be selected as programmed in the VLAN Filter
//This is needed for any Dynamic Queue handling based on incoming parameter
//
Ethernet_setDMARxQueueMode(EMAC_BASE, ETHERNET_RX_DMA_QUEUE_DYNAMIC, \
ETHERNET_QUEUE_0, ETHERNET_CHANNEL_1);
Ethernet_setDMARxQueueMode(EMAC_BASE, ETHERNET_RX_DMA_QUEUE_DYNAMIC, \
ETHERNET_QUEUE_1, ETHERNET_CHANNEL_1);
//
//Now Set up the VLAN Filter Parameters
//
vlanPerfectFilterParams.dmaChannelEnable = ETHERNET_DMA_CHANNELNUM_ENABLED;
//
//Let the packet come into dma Channel 1 for a matching VLAN tag
//
vlanPerfectFilterParams.dmaChannelNum = ETHERNET_CHANNEL_1;
vlanPerfectFilterParams.filterid = 1;
vlanPerfectFilterParams.vlanid =0x0B0B;
vlanPerfectFilterParams.vlanEnableDisable = (Ethernet_VlanRxPerfectFilterEnable)ETHERNET_VLAN_RX_FILTER_INNER_VLAN_ENABLED;
vlanPerfectFilterParams.vlanFilterMode = ETHERNET_VLAN_PERFECT_FILTER_COMPARE_12BITS;
vlanPerfectFilterParams.vlanPerfectTypeComparisonDisable = ETHERNET_VLAN_PERFECT_FILTER_TYPE_COMPARISON_ENABLED;
//Check for 0x8100
vlanPerfectFilterParams.vlanType = ETHERNET_VLAN_TYPE_C;
//Check only OuterVLAN
vlanPerfectFilterParams.innerVLANEnabled = ETHERNET_VLAN_RX_FILTER_INNER_VLAN_DISABLED;
Ethernet_setConfig(emac_handle,ETHERNET_SET_CONFIG_FILTER_VLAN_PERFECT,
&vlanPerfectFilterParams,sizeof(vlanPerfectFilterParams));
//
//Form the Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer packet
//
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pData;
pktDesc.nextPacketDesc = 0;
//
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//Please OR these values to achieve required CRC offloading
//ETHERNET_PKT_FLAG_CRC_PAD_INS value is zero which corresponds to CRC
//Insertion and Pad enabling
//Use ETHERNET_PKT_FLAG_CRC_INS_NO_PAD to insert CRC but no padding
//Use ETHERNET_PKT_FLAG_CRC_PAD_DIS to disable CRC and Disable padding
//Use ETHERNET_PKT_FLAG_CRC_REPL_NO_PAD to replace CRC and disable padding
//
pktDesc.flags = (ETHERNET_PKT_FLAG_SOP | ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS );
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire and receive it
//
SysCtl_delay(3000);
//
//Read the statistics of the Module
//
Ethernet_getStatistics(emac_handle, &stats);
//
//Check if a packet has been received
//The packet should have come through Receive DMA Channel 1
//
if(!stats.rxUnicastPacketsGood)
__asm(" bkpt #0");
}
@@ -0,0 +1,251 @@
//#############################################################################
//
// FILE: ethernet_ex9_revmii_example_mii_remote.c
//
// TITLE: Ethernet RevMII example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet RevMII Example MII side </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in MII mode.
//! The other device is running a RevMII mode
//! This demonstrates the sequence for MII - RevMII communication
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//! This Example has been validated on an TI internal board and will not run on
//! Control Card. This has been run with RevMII Example Remote MAC side.
//! Once the RevMII mode is configured this appears like a PHY to the external
//! MAC which is connected over MDIO. Even though there is no physical PHY
//! the RevMII mode lets the remote MAC see this side as a MAC.
//!
//! \b External \b Connections \n
//! TBD
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 132
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 128U
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
#define REVMII_REMOTE_PHY_ADDRESS 0U
#define REVMII_LOCAL_PHY_ADDRESS 0xAU
//
// Globals
//
uint8_t pData[PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Statistics stats;
Ethernet_Handle emac_handle;
uint16_t revmiiIntStatus;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_MII;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Form the Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Configure the PHY address for Remote PHY in the MDIO module
//
Ethernet_configurePHYAddress(EMAC_BASE,REVMII_REMOTE_PHY_ADDRESS);
//
//Rev MII PHY control register
//Loopback and 100mbps mode
//Ethernet_writePHYRegister(EMAC_BASE,0x0,0x6100);
//No Loopback and 100mbps mode
//
Ethernet_readPHYRegister(EMAC_BASE,
0x0);
Ethernet_writePHYRegister(EMAC_BASE,0x0,0x2100);
//Check for RevMII link status change interrupt
//Read RevMII Interrupt Status Mask Register
revmiiIntStatus = Ethernet_readPHYRegister(EMAC_BASE,
0x10);
if(revmiiIntStatus& 0x100)
{
//
//Clear the interrupt by writing to LSI field of RevMII Interrupt
//Status Mask Register
//
revmiiIntStatus &= 0x100;
Ethernet_writePHYRegister(EMAC_BASE,
0x10,
revmiiIntStatus);
}
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pData;
pktDesc.nextPacketDesc = 0;
pktDesc.flags = ETHERNET_PKT_FLAG_SOP |ETHERNET_PKT_FLAG_EOP|ETHERNET_PKT_FLAG_SA_INS;
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//We expect a packet to come from Remote side
//Query Statistics to check if a packet has come
//
Ethernet_getStatistics(emac_handle, &stats);
if(stats.rxUnicastPacketsGood)
__asm(" bkpt #0");
else
__asm(" bkpt #0");
}
@@ -0,0 +1,255 @@
//#############################################################################
//
// FILE: ethernet_ex9_revmii_example_revmii_side.c
//
// TITLE: Ethernet RevMII example
//
//! \addtogroup driver_example_cm_list
//! <h1> Ethernet RevMII Example RevMII side </h1>
//!
//! This example demonstrates the steps to be followed in using the
//! Ethernet of the Communication Manager Subsystem to initialize
//! the Ethernet module and Configure the module in RevMII mode.
//! Before running this Communication Manager code the C28x cpu1 code has to be run
//! to configure the clocks to Communication manager
//! and required IO pads for Ethernet module
//! This Example has been validated on an TI internal board and will not run on
//! Control Card. This has been run with RevMII Example Remote MAC side.
//! Once the RevMII mode is configured this appears like a PHY to the external
//! MAC which is connected over MDIO. Even though there is no physical PHY
//! the RevMII mode lets the remote MAC see this side as a PHY.
//!
//! \b External \b Connections \n
//! TBD
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define PACKET_LENGTH 132
#define ETHERNET_NO_OF_RX_PACKETS 1U
//
//Change this define for changing Packet buffer length
//
#define ETHERNET_MAX_PACKET_LENGTH 128U
uint8_t Ethernet_rxBuffer[ETHERNET_NO_OF_RX_PACKETS *
ETHERNET_MAX_PACKET_LENGTH];
#define REVMII_REMOTE_PHY_ADDRESS 0U
#define REVMII_LOCAL_PHY_ADDRESS 0xAU
//
// Globals
//
uint8_t pData[PACKET_LENGTH];
//
// Main
//
void main(void)
{
Ethernet_InitInterfaceConfig initInterfaceConfig;
Ethernet_InitConfig *pInitCfg;
Ethernet_Pkt_Desc pktDesc;
uint32_t i;
Ethernet_Handle emac_handle;
//
// Initialize device clock and peripherals
//
CM_init();
//
//Select the MII interface of the module
//
initInterfaceConfig.ssbase = EMAC_SS_BASE;
initInterfaceConfig.enet_base = EMAC_BASE;
initInterfaceConfig.phyMode = ETHERNET_SS_PHY_INTF_SEL_REVMII;
//
//This configures external 25MHZ clock as the source for RevMII
//
initInterfaceConfig.clockSel = ETHERNET_SS_CLK_SRC_INTERNAL;
//
//This is the MDIO address used to access the internal RevMII registers
//Local PHY
//
initInterfaceConfig.localPhyAddress = REVMII_LOCAL_PHY_ADDRESS;
//
//This is the PHY address for the Remote PHY
//
initInterfaceConfig.remotePhyAddress = REVMII_REMOTE_PHY_ADDRESS;
//
//Assign SoC specific functions for Enabling,Disabling interrupts
//and for enabling the Peripheral at system level
//
initInterfaceConfig.ptrPlatformInterruptDisable = &Platform_disableInterrupt;
initInterfaceConfig.ptrPlatformInterruptEnable = &Platform_enableInterrupt;
initInterfaceConfig.ptrPlatformPeripheralEnable = &Platform_enablePeripheral;
initInterfaceConfig.ptrPlatformPeripheralReset = &Platform_resetPeripheral;
//
//Assign the peripheral number at the SoC
//
initInterfaceConfig.peripheralNum = SYSCTL_PERIPH_CLK_ENET;
//
//Assign the default SoC specific interrupt numbers of Ethernet interrupts
//
initInterfaceConfig.interruptNum[0] = INT_EMAC;
initInterfaceConfig.interruptNum[1] = INT_EMAC_TX0;
initInterfaceConfig.interruptNum[2] = INT_EMAC_TX1;
initInterfaceConfig.interruptNum[3] = INT_EMAC_RX0;
initInterfaceConfig.interruptNum[4] = INT_EMAC_RX1;
pInitCfg = Ethernet_initInterface(initInterfaceConfig);
//
// Get an initial configuration of known good parameters
//
Ethernet_getInitConfig(pInitCfg);
//
//Assign the callbacks for Getting packet buffer when needed
//Releasing the TxPacketBuffer on Transmit interrupt callbacks
//Receive packet callback on Receive packet completion interrupt
//
pInitCfg->pfcbGetPacket = &Ethernet_getPacketBuffer;
pInitCfg->pfcbFreePacket = &Ethernet_releaseTxPacketBuffer;
pInitCfg->pfcbRxPacket = &Ethernet_receivePacketCallback;
//
//Assign the Buffer to be used by the Low level driver for receiving
//Packets. This should be accessible by the Ethernet DMA
//
pInitCfg->rxBuffer = Ethernet_rxBuffer;
//
//The Application handle is not used by this application
//Hence using a dummy value of 1
//
Ethernet_getHandle((Ethernet_Handle)1,pInitCfg , &emac_handle);
//
//Do global Interrupt Enable
//
(void)Interrupt_enableInProcessor();
//
//Assign default ISRs
//
Interrupt_registerHandler(INT_EMAC_TX0, Ethernet_transmitISR);
Interrupt_registerHandler(INT_EMAC_RX0, Ethernet_receiveISR);
//
//Enable the default interrupt handlers
//
Interrupt_enable(INT_EMAC_TX0);
Interrupt_enable(INT_EMAC_RX0);
//
//Configure the PHY address for Local PHY in the MDIO module
//
Ethernet_configurePHYAddress(EMAC_BASE,REVMII_LOCAL_PHY_ADDRESS);
//
//Read RevMII Interrupt Status Mask Register
//
Ethernet_readPHYRegister(EMAC_BASE,0x0);
//
//Rev MII PHY control register
//Loopback and 100mbps mode
//No Loopback and 100mbps mode
//
Ethernet_writePHYRegister(EMAC_BASE,0x0,0x2100);
//
//Form the Packet in Memory
//
for(i=0;i<PACKET_LENGTH/4;i++)
{
if(i == 0)
*((uint32_t *)pData + i) = 0x01020304;
else if(i == 1)
*((uint32_t *)pData + i) = 0xFFFF0506;
else
HWREG((uint32_t *)pData +i) = 0xFFFFFFFF;
}
//
//Prepare a Packet Descriptor structure to send a packet
//This contains a single buffer packet
//
pktDesc.bufferLength = PACKET_LENGTH;
pktDesc.dataOffset = 0;
pktDesc.dataBuffer = pData;
pktDesc.nextPacketDesc = 0;
//The Source address shall be inserted by the MAC
//Packet CRC is auto computed by the module and appended in the packet
//Please OR these values to achieve required CRC offloading
//ETHERNET_PKT_FLAG_CRC_PAD_INS value is zero which corresponds to CRC
//Insertion and Pad enabling
//Use ETHERNET_PKT_FLAG_CRC_INS_NO_PAD to insert CRC but no padding
//Use ETHERNET_PKT_FLAG_CRC_PAD_DIS to disable CRC and Disable padding
//Use ETHERNET_PKT_FLAG_CRC_REPL_NO_PAD to replace CRC and disable padding
//
pktDesc.flags = (ETHERNET_PKT_FLAG_SOP | ETHERNET_PKT_FLAG_EOP |
ETHERNET_PKT_FLAG_SA_INS);
pktDesc.pktChannel = ETHERNET_DMA_CHANNEL_NUM_0;
pktDesc.pktLength = PACKET_LENGTH;
pktDesc.validLength = PACKET_LENGTH;
pktDesc.numPktFrags = 1;
//
//Send the packet prepared
//
Ethernet_sendPacket(emac_handle,&pktDesc);
//
//Delay for the MAC to send the packet on the wire
//
SysCtl_delay(3000);
__asm(" bkpt #0");
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --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 --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,26 @@
<projectSpec>
<project
name="flash_ex2_ecc_test_mode"
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} -I${FlashAPI_INCLUDE_ROOT} --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225 " linkerBuildOptions="-I${FlashAPI_LIB_ROOT} --stack_size=512 --heap_size=1024 --library=libc.a --define RAM" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
<pathVariable name="FlashAPI_INCLUDE_ROOT" path="../../../../../../libraries/flash_api/f2838x/cm/include/FlashAPI/" scope="project" />
<pathVariable name="FlashAPI_LIB_ROOT" path="../../../../../../libraries/flash_api/f2838x/cm/lib/" scope="project" />
<file action="copy" path="../../../../../../libraries/flash_api/f2838x/cm/lib/F2838x_CM_FlashAPI.lib" targetDirectory="" />
<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="" />
<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="../flash_ex2_ecc_test_mode.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,27 @@
<projectSpec>
<project
name="flashapi_cm_ex1_programming"
device="Cortex M.TMS320F28388D"
cgtVersion="20.2.7.LTS"
products="C2000WARE"
endianness="little"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} -I${FlashAPI_INCLUDE_ROOT} --define=DEBUG --define=_FLASH -mv7M4 -me --float_support=none --diag_warning=225" linkerBuildOptions="-I${FlashAPI_LIB_ROOT} --stack_size=512 --heap_size=1024 --library=libc.a " />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/f2838x/driverlib_cm/" scope="project" />
<pathVariable name="FlashAPI_INCLUDE_ROOT" path="../../../../../../libraries/flash_api/f2838x/cm/include/FlashAPI/" scope="project" />
<pathVariable name="FlashAPI_LIB_ROOT" path="../../../../../../libraries/flash_api/f2838x/cm/lib/" scope="project" />
<file action="copy" path="../../../../../../libraries/flash_api/f2838x/cm/lib/F2838x_CM_FlashAPI.lib" targetDirectory="" />
<file action="copy" path="../flash_programming_f2838x_cm.h" targetDirectory="" />
<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_flash_api_lnk_cm.cmd" targetDirectory="" />
<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="../flashapi_cm_ex1_programming.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,348 @@
//#############################################################################
//
// FILE: flash_ex2_ecc_test_mode.c
//
// TITLE: Flash ECC Test Mode Example
//
//! \addtogroup driver_example_cm_list
//! <h1> Flash ECC Test Mode </h1>
//!
//! This example demonstrates ECC Test mode.
//| ECC Test mode is provided to check the correctness of SECDED logic.
//! Four types of errors are inserted to demonstrate the usage of ECC Test Mode
//! 1. Single bit error detection
//! 2. Double bit error detection
//! 3. Single bit ECC error detection
//! 4. Double bit ECC error detection
//!
//! Before running this example, please run the cm_common_config_c28x Example
//! from the c28x folder. It will initialize the clock, configure CPU1 Flash
//! wait-states, fall back power mode, performance features and ECC.
//!
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - None
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Include Flash API include file
//
#include "F021_F2838x_CM.h"
uint32 flash_address = 0x210000;
uint64 flash_data = 0xAAAABBBBCCCCDDDD;
uint8 flash_ecc = 0;
uint8 error = 0;
#define DATA_BIT_ERROR_POSITION 7
#define ECC_BIT_ERROR_POSITION 5
//
// Inserts a single bit error in the data before providing the data to ECC Test
// Block
//
void singleBitDataErrorExample();
//
// Inserts a double bit error in the data before providing the data to ECC Test
// Block
//
void doubleBitDataErrorExample();
//
// Inserts a single bit error in the ECC of the data before providing the ecc to
// ECC Test Block
//
void singleBitECCErrorExample();
//
// Inserts a double bit error in the ECC of the data before providing the ecc to
// ECC Test Block
//
void doubleBitECCErrorExample();
//
// Sets ECC Test Block parameters
// Enables the ECC Test mode, uses Lower ECC Test block and performs ECC
// calculation
//
void setupECCTestBlock(uint64 data, uint32 address, uint16 ecc);
#define SINGLE_BIT_DATA_ERROR_EXAMPLE 0
#define DOUBLE_BIT_DATA_ERROR_EXAMPLE 1
#define SINGLE_BIT_ECC_ERROR_EXAMPLE 2
#define DOUBLE_BIT_ECC_ERROR_EXAMPLE 3
//
// Modify the below value to run a different example
//
uint8 current_example = SINGLE_BIT_DATA_ERROR_EXAMPLE;
//
// Main
//
void main(void)
{
//
// Initializes device clock and peripherals
//
CM_init();
//
// Call Flash Initialization to setup flash wait states
//
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, 2);
//
// Initialize the Flash API by providing the Flash register base address
// and operating frequency.
//
Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 125);
//
// Get the corresponding ECC of the data
//
flash_ecc = Fapi_calculateEcc(flash_address, flash_data);
switch(current_example) {
case SINGLE_BIT_DATA_ERROR_EXAMPLE:
{
//#####################################################################
// Single bit data error insertion
//#####################################################################
singleBitDataErrorExample();
//
// Get the error type
//
if(FLASH_SINGLE_ERROR != Flash_getECCTestStatus(FLASH0ECC_BASE))
error++;
//
// Check if the detected error is data error
//
if(FLASH_DATA_BITS != Flash_getECCTestSingleBitErrorType(
FLASH0ECC_BASE))
error++;
//
// Check if the detected error position matches with the error position
// set
//
if(DATA_BIT_ERROR_POSITION != Flash_getECCTestErrorPosition(
FLASH0ECC_BASE))
error++;
//
// Check if the SECDED logic corrected single bit error
//
if((uint32)flash_data != Flash_getTestDataOutLow(FLASH0ECC_BASE))
error++;
}
break;
case DOUBLE_BIT_DATA_ERROR_EXAMPLE:
{
//#####################################################################
// Double bit data error insertion
//#####################################################################
doubleBitDataErrorExample();
//
// Get the error type
//
if(FLASH_UNC_ERROR != Flash_getECCTestStatus(FLASH0ECC_BASE))
error++;
}
break;
case SINGLE_BIT_ECC_ERROR_EXAMPLE:
{
//#####################################################################
// Single bit ECC error insertion
//#####################################################################
singleBitECCErrorExample();
//
// Get the error type
//
if(FLASH_SINGLE_ERROR != Flash_getECCTestStatus(FLASH0ECC_BASE))
error++;
//
// Check if the detected error is ecc error
//
if(FLASH_CHECK_BITS != Flash_getECCTestSingleBitErrorType(
FLASH0ECC_BASE))
error++;
//
// Check if the detected error position matches with the error position
// set
//
if(ECC_BIT_ERROR_POSITION != Flash_getECCTestErrorPosition(
FLASH0ECC_BASE))
error++;
}
break;
case DOUBLE_BIT_ECC_ERROR_EXAMPLE:
{
//#####################################################################
// Double bit ECC error insertion
//#####################################################################
doubleBitECCErrorExample();
//
// Get the error type
//
if(FLASH_UNC_ERROR != Flash_getECCTestStatus(FLASH0ECC_BASE))
error++;
}
break;
default:
{
error++;
}
}
//
// Revert back the ECC Test mode setting
//
Flash_disableECCTestMode(FLASH0ECC_BASE);
}
void singleBitDataErrorExample()
{
//
// Insert single bit error in data
//
setupECCTestBlock(flash_data ^ (1 << DATA_BIT_ERROR_POSITION),
flash_address, flash_ecc);
}
void doubleBitDataErrorExample()
{
//
// Insert double bit error in data
//
setupECCTestBlock(flash_data ^ 0x3, flash_address, flash_ecc);
}
void singleBitECCErrorExample()
{
//
// Insert single bit error in ECC
//
setupECCTestBlock(flash_data, flash_address,
flash_ecc ^ (1 << ECC_BIT_ERROR_POSITION));
}
void doubleBitECCErrorExample()
{
//
// Insert double bit error in ECC
//
setupECCTestBlock(flash_data, flash_address, flash_ecc ^ 0x3);
}
void setupECCTestBlock(uint64 data, uint32 address, uint16 ecc)
{
//
// Write 128-bit flash address in FADDR_TEST
//
Flash_setECCTestAddress(FLASH0ECC_BASE, address);
//
// Write lower 32 bits of data in FDATAL_TEST
//
Flash_setDataLowECCTest(FLASH0ECC_BASE, (uint32)data);
//
// Write upper 32 bits of data in FDATAH_TEST
//
Flash_setDataHighECCTest(FLASH0ECC_BASE, (uint32)(data >> 32));
//
// Write corresponding ECC in the FECC_TEST
// Insert double bit error in flash ecc
//
Flash_setECCTestECCBits(FLASH0ECC_BASE, ecc);
//
// Select lower ECC block
// Only one of the SECDED modules (out of the two SECDED modules that work
// on lower 64 bits and upper 64 bits of a read 128-bit data) at a time
// can be tested.
//
Flash_selectLowECCBlock(FLASH0ECC_BASE);
//
// Enable the ECC Test Mode
//
Flash_enableECCTestMode(FLASH0ECC_BASE);
//
// Perform ECC calculation
//
Flash_performECCCalculation(FLASH0ECC_BASE);
}
//
// End of File
//
@@ -0,0 +1,74 @@
//###########################################################################
//
// FILE: flash_programming_f2838x_cm.h
//
// TITLE: A set of Constant Values for the F2838x CM Family.
//
//###########################################################################
//
//
//
// 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.
// $
//###########################################################################
#ifndef FLASH_PROGRAMMING_F2838X_CM_H
#define FLASH_PROGRAMMING_F2838X_CM_H
//
// Bank0 Sector start addresses
//
#define FlashStartAddress 0x200000
#define Bzero_Sector0_start 0x200000
#define Bzero_Sector1_start 0x204000
#define Bzero_Sector2_start 0x208000
#define Bzero_Sector3_start 0x20C000
#define Bzero_Sector4_start 0x210000
#define Bzero_Sector5_start 0x220000
#define Bzero_Sector6_start 0x230000
#define Bzero_Sector7_start 0x240000
#define Bzero_Sector8_start 0x250000
#define Bzero_Sector9_start 0x260000
#define Bzero_Sector10_start 0x270000
#define Bzero_Sector11_start 0x274000
#define Bzero_Sector12_start 0x278000
#define Bzero_Sector13_start 0x27C000
#define FlashEndAddress 0x27FFFF
//
// Sector length in number of 32bits
//
#define Sector16KB_u32length 0x1000
#define Sector64KB_u32length 0x4000
#endif /* FLASH_PROGRAMMING_F2838X_CM_H */
@@ -0,0 +1,808 @@
//#############################################################################
//
// FILE: flashapi_cm_ex1_programming.c
//
// TITLE: Flash programming example
//
//! \addtogroup driver_example_list
//! <h1> Flash Programming with AutoECC, DataAndECC, DataOnly and EccOnly </h1>
//!
//! This example demonstrates how to program Flash using API's following options
//! 1. AutoEcc generation
//! 2. DataOnly and EccOnly
//! 3. DataAndECC
//!
//! Before running this example, please run the cm_common_config_c28x Example
//! from the c28x folder. It will initialize the clock, configure CPU1 Flash
//! wait-states, fall back power mode, performance features and ECC.
//!
//! \b External \b Connections \n
//! - None.
//!
//! \b Watch \b Variables \n
//! - None.
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Include Flash API include file
//
#include "F021_F2838x_CM.h"
//
// Include Flash API example header file
//
#include "flash_programming_f2838x_cm.h"
//
// Defines
//
//
// Length of data buffer used for program
//
#define WORDS_IN_FLASH_BUFFER 0x100
//
// Globals
//
//
// Data Buffers used for program operation using the flash API program function
//
#pragma DATA_SECTION(Buffer,"DataBufferSection");
uint8 Buffer[WORDS_IN_FLASH_BUFFER];
uint32 *Buffer32 = (uint32 *)Buffer;
//
// Prototype of the functions used in this example
//
void Example_Error(Fapi_StatusType status);
void Example_Done(void);
void Example_CallFlashAPI(void);
void FMSTAT_Fail(void);
void ECC_Fail(void);
void Example_EraseSector(void);
void Example_ProgramUsingAutoECC(void);
void Example_ProgramUsingDataOnlyECCOnly(void);
void Example_ProgramUsingDataAndECC(void);
//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
// Copy the Flash initialization code from Flash to RAM
// Copy the Flash API from Flash to RAM
// Configure Flash wait-states, fall back power mode, performance features
// and ECC
//
CM_init();
//
// At 125MHz, execution wait-states for external oscillator is 2. Modify the
// wait-states when the CM operating frequency is changed.
//
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, 2);
//
// Pump access must be gained by the core using pump semaphore
//
Flash_claimPumpSemaphore(FLASH_CM_WRAPPER);
//
// Flash API functions should not be executed from the same bank on which
// erase/program operations are in progress.
// Also, note that there should not be any access to the Flash bank on
// which erase/program operations are in progress. Hence below function
// is mapped to RAM for execution.
//
Example_CallFlashAPI();
//
// Release the pump access
//
Flash_releasePumpSemaphore();
//
// Example is done here
//
Example_Done();
}
//*****************************************************************************
// Example_CallFlashAPI
//
// This function will interface to the flash API.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_CallFlashAPI, ".TI.ramfunc");
#endif
void Example_CallFlashAPI(void)
{
uint16 i = 0;
Fapi_StatusType oReturnCheck;
//
// Initialize the Flash API by providing the Flash register base address
// and operating frequency(in MHz).
// This function is required to initialize the Flash API based on CM
// operating frequency before any other Flash API operation can be performed.
// This function must also be called whenever System frequency or RWAIT is
// changed.
//
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS,
CM_CLK_FREQ/1000000U);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Initialize the Flash banks and FMC for erase and program operations.
// Fapi_setActiveFlashBank() function sets the Flash banks and FMC for
// further Flash operations to be performed on the banks.
//
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Erase the sector before programming
//
Example_EraseSector();
//
// Fill a buffer with data to program into the flash.
//
for(i=0; i < WORDS_IN_FLASH_BUFFER; i++)
{
Buffer[i] = i;
}
//
// Program the sector using AutoECC option
//
Example_ProgramUsingAutoECC();
//
// Erase the sector before programming
//
Example_EraseSector();
//
// Program the sector using DataOnly and ECCOnly options
//
Example_ProgramUsingDataOnlyECCOnly();
//
// Erase the sector before programming
//
Example_EraseSector();
//
// Program the sector using DataAndECC option
//
Example_ProgramUsingDataAndECC();
//
// Erase the sector for cleaner exit from the example.
//
Example_EraseSector();
}
//*****************************************************************************
// Example_ProgramUsingAutoECC
//
// Example function to Program data in Flash using "AutoEccGeneration" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingAutoECC, ".TI.ramfunc");
#endif
void Example_ProgramUsingAutoECC(void)
{
uint32 u32Index = 0;
uint16 i = 0;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// A data buffer of max 16 bytes can be supplied to the program function.
// Each byte is programmed until the whole buffer is programmed or a
// problem is found. However to program a buffer that has more than 16
// bytes, program function can be called in a loop to program 16 bytes for
// each loop iteration until the whole buffer is programmed.
//
// Remember that the main array flash programming must be aligned to
// 64-bit address boundaries and each 64 bit word may only be programmed
// once per write/erase cycle. Meaning the length of the data buffer
// (3rd parameter for Fapi_issueProgrammingCommand() function) passed
// to the program function can only be either 8 or 16.
//
// Program data in Flash using "AutoEccGeneration" option.
// When AutoEccGeneration opton is used, Flash API calculates ECC for the
// given 64-bit data and programs it along with the 64-bit main array data.
// Note that any unprovided data with in a 64-bit data slice
// will be assumed as 1s for calculating ECC and will be programmed.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// Monitor ECC address for Sector6 while programming with AutoEcc mode.
//
// In this example, 0x100 bytes are programmed in Flash Sector6
// along with auto-generated ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 16, u32Index+= 16)
{
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, Buffer+i,
16, 0, 0, Fapi_AutoEccGeneration);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
//
// For illustration purpose both Fapi_doVerify and Fapi_doVerifyByByte
// are used in this example. Use either one of them based on the need.
//
//
// Verify the programmed values. Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 32-bit
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32 + (i/4),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Verify the programmed values against supplied data by byte.
// Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 8-bit
//
oReturnCheck = Fapi_doVerifyByByte((uint8 *)u32Index,
16, Buffer + i,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_ProgramUsingDataOnlyECCOnly
//
// Example function to Program data in Flash using "DataOnly" option and ECC
// using "EccOnly" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingDataOnlyECCOnly, ".TI.ramfunc");
#endif
void Example_ProgramUsingDataOnlyECCOnly(void)
{
uint32 u32Index = 0;
uint16 i = 0, ECC_B = 0, ECC_LB = 0, ECC_HB = 0;
uint64 *LData, *HData, dataLow, dataHigh;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Program data using "DataOnly" option and ECC using "EccOnly" option.
//
// When DataOnly option is used, Flash API will program only the data
// portion in Flash at the address specified.
//
// When EccOnly option is used, Flash API will program only the ECC portion
// in Flash ECC memory space (Flash main array address should be provided
// for this function and not the corresponding ECC address).
// Fapi_calculateEcc is used to calculate the corresponding ECC of the data.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// In this example, 0x100 bytes are programmed in Flash Sector6
// along with the specified ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 16, u32Index+= 16)
{
//
// Point LData to the lower 64 bit data
// and HData to the higher 64 bit data
//
LData = (uint64 *)(Buffer32 + i/4);
HData = (uint64 *)(Buffer32 + i/4 + 2);
//
// Calculate ECC for lower 64 bit and higher 64 bit data
//
ECC_LB = Fapi_calculateEcc(u32Index,*LData);
ECC_HB = Fapi_calculateEcc(u32Index+8,*HData);
ECC_B = ((ECC_HB<<8) | ECC_LB);
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
16, 0, 0, Fapi_DataOnly);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//Check FMSTAT and debug accordingly
FMSTAT_Fail();
}
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, 0, 0,
(uint8 *)&ECC_B, 2, Fapi_EccOnly);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
Flash_enableECC(FLASH0ECC_BASE);
//
// Read back the programmed data to check if there are any ECC failures
//
dataLow = *(uint64 *)(u32Index);
Flash_ErrorStatus errorStatusLow = Flash_getLowErrorStatus(FLASH0ECC_BASE);
if((errorStatusLow != FLASH_NO_ERR) || (dataLow != *LData))
{
ECC_Fail();
}
dataHigh = *(uint64 *)(u32Index + 8);
Flash_ErrorStatus errorStatusHigh = Flash_getHighErrorStatus(FLASH0ECC_BASE);
if((errorStatusHigh != FLASH_NO_ERR) || (dataHigh != *HData))
{
ECC_Fail();
}
//
// For illustration purpose both Fapi_doVerify and Fapi_doVerifyByByte
// are used in this example. Use either one of them based on the need.
//
//
// Verify the programmed values. Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 32-bit
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32 + (i/4),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Verify the programmed values against supplied data by byte.
// Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 8-bit
//
oReturnCheck = Fapi_doVerifyByByte((uint8 *)u32Index,
16, Buffer + i,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_ProgramUsingDataAndECC
//
// Example function to Program data in Flash using "DataAndEcc" option.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_ProgramUsingDataAndECC, ".TI.ramfunc");
#endif
void Example_ProgramUsingDataAndECC(void)
{
uint32 u32Index = 0;
uint16 i = 0, ECC_B = 0, ECC_LB = 0, ECC_HB = 0;
uint64 *LData, *HData, dataLow, dataHigh;
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Program data and ECC in Flash using "DataAndEcc" option.
// When DataAndECC option is used, Flash API will program both the supplied
// data and ECC in Flash at the address specified.
// Fapi_calculateEcc is used to calculate the corresponding ECC of the data.
//
// Note that data buffer (Buffer) is aligned on 64-bit boundary for verify
// reasons.
//
// In this example, 0x100 bytes are programmed in Flash Sector6
// along with the specified ECC.
//
for(i=0, u32Index = Bzero_Sector6_start;
(u32Index < (Bzero_Sector6_start + WORDS_IN_FLASH_BUFFER));
i+= 16, u32Index+= 16)
{
//
// Point LData to the lower 64 bit data
// and HData to the higher 64 bit data
//
LData = (uint64 *)(Buffer32 + i/4);
HData = (uint64 *)(Buffer32 + i/4 + 2);
//
// Calculate ECC for lower 64 bit and higher 64 bit data
//
ECC_LB = Fapi_calculateEcc(u32Index,*LData);
ECC_HB = Fapi_calculateEcc(u32Index+8,*HData);
ECC_B = ((ECC_HB<<8) | ECC_LB);
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
16, (uint8 *)&ECC_B, 2, Fapi_DataAndEcc);
//
// Wait until the Flash program operation is over
//
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// program command to see if there are any program operation related
// errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check FMSTAT and debug accordingly
//
FMSTAT_Fail();
}
Flash_enableECC(FLASH0ECC_BASE);
//
// Read back the programmed data to check if there are any ECC failures
//
dataLow = *(uint64 *)(u32Index);
Flash_ErrorStatus errorStatusLow = Flash_getLowErrorStatus(FLASH0ECC_BASE);
if((errorStatusLow != FLASH_NO_ERR) || (dataLow != *LData))
{
ECC_Fail();
}
dataHigh = *(uint64 *)(u32Index + 8);
Flash_ErrorStatus errorStatusHigh = Flash_getHighErrorStatus(FLASH0ECC_BASE);
if((errorStatusHigh != FLASH_NO_ERR) || (dataHigh != *HData))
{
ECC_Fail();
}
//
// For illustration purpose both Fapi_doVerify and Fapi_doVerifyByByte
// are used in this example. Use either one of them based on the need.
//
//
// Verify the programmed values. Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 32-bit
//
oReturnCheck = Fapi_doVerify((uint32 *)u32Index,
4, Buffer32 + (i/4),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Verify the programmed values against supplied data by byte.
// Check for any ECC errors.
// Use this API when the length of the buffer is a multiple of 8-bit
//
oReturnCheck = Fapi_doVerifyByByte((uint8 *)u32Index,
16, Buffer + i,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
}
}
//*****************************************************************************
// Example_EraseSector
//
// Example function to Erase data of a sector in Flash.
// Flash API functions used in this function are executed from RAM in this
// example.
//*****************************************************************************
#ifdef __cplusplus
#pragma CODE_SECTION(".TI.ramfunc");
#else
#pragma CODE_SECTION(Example_EraseSector, ".TI.ramfunc");
#endif
void Example_EraseSector(void)
{
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
//
// Erase the sector that is programmed in the above example
// Erase Sector6
//
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_Sector6_start);
//
// Wait until FSM is done with erase sector operation
//
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// erase command to see if there are any erase operation related errors
//
oFlashStatus = Fapi_getFsmStatus();
if(oFlashStatus != 0)
{
//
// Check Flash API documentation for FMSTAT and debug accordingly
// Fapi_getFsmStatus() function gives the FMSTAT register contents.
// Check to see if any of the EV bit, ESUSP bit, CSTAT bit or
// VOLTSTAT bit is set (Refer to API documentation for more details).
//
FMSTAT_Fail();
}
//
// Verify that Sector6 is erased
//
oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_Sector6_start,
Sector64KB_u32length,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for error info
//
Example_Error(oReturnCheck);
}
}
//******************************************************************************
// For this example, just stop here if an API error is found
//******************************************************************************
void Example_Error(Fapi_StatusType status)
{
//
// Error code will be in the status parameter
//
__asm(" bkpt #0");
}
//******************************************************************************
// For this example, once we are done just stop here
//******************************************************************************
void Example_Done(void)
{
__asm(" bkpt #0");
}
//******************************************************************************
// For this example, just stop here if FMSTAT fail occurs
//******************************************************************************
void FMSTAT_Fail(void)
{
__asm(" bkpt #0");
}
//******************************************************************************
// For this example, just stop here if ECC fail occurs
//******************************************************************************
void ECC_Fail(void)
{
__asm(" bkpt #0");
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="gcrc_ex1_basic"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../gcrc_ex1_basic.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,169 @@
//#############################################################################
//
// FILE: gcrc_ex1_basic.c
//
// TITLE: CRC computation using GCRC module
//
//! \addtogroup driver_example_cm_list
//! <h1>GCRC example</h1>
//!
//! This example showcases how to use GCRC to compute CRC for a 8-bit array.
//! This demonstrates 2 methods for computing the CRC
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b crcResult1 - CRC value computed using Method 1
//! - \b crcResult2 - CRC value computed using Method 2
//! - \b crcGolden - Golden CRC value
//!
//
//#############################################################################
//
// 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.
// $
//#############################################################################
#include "cm.h"
#pragma DATA_ALIGN(gData, 32)
uint8_t gData[] = {0x8a, 0xf6, 0x1e, 0x6d, 0x8d};
//
// Main
//
void main(void)
{
int i;
uint8_t data[] = {0x8a, 0xf6, 0x1e, 0x6d, 0x8d};
uint32_t crcResult1 = 0;
uint32_t crcResult2 = 0;
uint32_t crcGolden = 0x52d24341;
//
// disable WD, enable peripheral clocks.
//
CM_init();
//
// GCRC configurations
//
uint32_t poly = 0x4C11DB7;
uint32_t polysize = 32;
uint32_t seed = 0x654cfd7a;
uint32_t endianness = GCRC_ENDIANNESS_BIG;
uint32_t dataType = GCRC_DATATYPE_8BIT;
bool bitRev = false;
uint32_t dataMask = 0;
//
// Configure the GCRC module
//
GCRC_setPolynomial(GCRC_BASE, poly, polysize);
GCRC_setDataType(GCRC_BASE, dataType);
GCRC_setDataEndianness(GCRC_BASE, endianness);
GCRC_setDataMask(GCRC_BASE, dataMask);
GCRC_enableBitReverse(GCRC_BASE, bitRev);
/////////////////////////////////////////////////////////////////
// Method 1 - Providing data to the CRC engine as 8-bit writes //
/////////////////////////////////////////////////////////////////
//
// Set Seed value
//
GCRC_setSeedValue(GCRC_BASE, seed);
//
// Write data to the CRC engine
//
for(i = 0; i < 5; i++)
{
GCRC_writeData(GCRC_BASE, data[i], dataType);
}
//
// Read the CRC result
//
crcResult1 = GCRC_readResult(GCRC_BASE);
//////////////////////////////////////////////////////////////////////////////////////
// Method 2 (optimal) - Providing data to the CRC engine as 32-bit and 8-bit writes //
//////////////////////////////////////////////////////////////////////////////////////
//
// The 4 bytes aligned to a 32-bit address can be combined and provided
// to the engine as a single 32-bit data
//
//
// Set Seed value
//
GCRC_setSeedValue(GCRC_BASE, seed);
//
// Write data to the CRC engine.
// gData is aligned to a 32-bit address
//
GCRC_writeData(GCRC_BASE, *(uint32_t *)gData, GCRC_DATATYPE_32BIT);
GCRC_writeData(GCRC_BASE, gData[4], GCRC_DATATYPE_8BIT);
//
// Read the CRC result
//
crcResult2 = GCRC_readResult(GCRC_BASE);
//
// Check for computed crc values
//
if((crcResult1 != crcGolden) || (crcResult2 != crcGolden))
{
//
// Error. The computed crc does not match the golden value
//
__asm(" bkpt #0");
}
//
// Loop indefinitely (optional)
//
while(1);
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --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 --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="i2c_ex1_slave_receive_int"
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="../i2c_ex1_slave_receive_int.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,219 @@
//#############################################################################
//
// FILE: i2c_ex1_slave_receive_int.c
//
// TITLE: I2C Loopback with Slave Receive Interrupt
//
//! \addtogroup driver_example_cm_list
//! <h1>I2C Loopback with Slave Receive Interrupt</h1>
//!
//! This program shows how to configure a receive interrupt on the slave
//! module. This includes setting up the I2C0 module for loopback mode as well
//! as configuring the master and slave modules. Loopback mode internally
//! connects the master and slave data and clock lines together. The address
//! of the slave module is set to a value so it can receive data from the
//! master.
//!
//! This is a 7-bit slave module address sent in the following format:
//! [A6:A5:A4:A3:A2:A1:A0:RS]
//!
//! A zero in the R/S position of the first byte means that the master
//! transmits (sends) data to the selected slave, and a one in this position
//! means that the master receives data from the slave.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b ui32DataTx - Data to send
//! - \b ui32DataRx - Received data
//! - \b result - Status of the I2C communication
//!
//
//#############################################################################
//
//
//
// 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 <stdint.h>
#include <stdbool.h>
#include "cm.h"
//
// Defines
//
#define SLAVE_ADDRESS 0x3C
#define NUM_I2C_DATA 3
#define PASS 0
#define FAIL 1
//
// Globals
//
uint32_t result = FAIL;
uint32_t ui32DataTx;
static uint32_t ui32DataRx;
//
// Function Prototypes
//
void initI2C(void);
__interrupt void I2C0SlaveIntHandler(void);
//
// Main
//
void main(void)
{
uint16_t i;
//
// disable WD, enable peripheral clocks.
//
CM_init();
//
// Enable the I2C0 interrupt on the processor (NVIC).
//
I2C_registerInt(INT_I2C0,I2C0SlaveIntHandler);
//
// Set I2C use, initializing master and slave
//
initI2C();
//
// Initialize the data to send.
//
ui32DataTx = 'I';
//
// Place the data to be sent in the data register.
//
I2C_putMasterData(I2C0_BASE, ui32DataTx);
//
// Initiate send of single piece of data from the master. Since the
// loopback mode is enabled, the Master and Slave units are connected
// allowing us to receive the same data that we sent out.
//
I2C_setMasterConfig(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(1)
{
//
// Delay
//
for(i=1000; i>0; i--);
}
}
//
// Function to configure I2C0.
//
void initI2C()
{
//
// Enable the Master module.
//
I2C_enableMaster(I2C0_BASE);
//
// I2C configuration. Set up to transfer data at 100 Kbps.
//
I2C_initMaster(I2C0_BASE,I2C_CLK_FREQ,false);
//
// Enable the Slave module.
//
I2C_enableSlave(I2C0_BASE);
//
// Configure for internal loopback mode
//
I2C_setSlaveAddress(I2C0_BASE,SLAVE_ADDRESS,I2C_MASTER_WRITE);
I2C_setOwnSlaveAddress(I2C0_BASE,I2C_SLAVE_ADDR_PRIMARY,SLAVE_ADDRESS);
I2C_enableLoopback(I2C0_BASE);
//
// Configure and turn on the I2C0 slave interrupt. The I2C_enableSlaveInt()
// gives you the ability to only enable specific interrupts. For this case
// we are only interrupting when the slave device receives data.
//
I2C_enableSlaveInt(I2C0_BASE);
}
//
// I2C0 Receive ISR.
//
__interrupt void I2C0SlaveIntHandler(void)
{
uint32_t slvStatus;
//
// Get the slave interrupt status
//
slvStatus = I2C_getSlaveIntStatus(I2C0_BASE,I2C_MASTER_RAW_INT);
//
// Clear the I2C0 interrupt flag.
//
I2C_clearSlaveInt(I2C0_BASE);
//
// Read the data from the slave.
//
ui32DataRx = I2C_getSlaveData(I2C0_BASE);
if(ui32DataRx != ui32DataTx)
result = FAIL;
else
result = PASS;
//
// Clear the slave interrupt status
//
I2C_clearSlaveIntSource(I2C0_BASE,slvStatus);
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="mcan_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=MCAN --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=MCAN --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="mcan_ex1_loopback"
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=1024 --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=1024 --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="../mcan_ex1_loopback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="mcan_ex2_external_loopback"
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=1024 --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=1024 --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="../mcan_ex2_external_loopback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,482 @@
//#############################################################################
//
// FILE: mcan_ex1_loopback.c
//
// TITLE: MCAN Loopback with Interrupts Example
//
//! \addtogroup driver_example_cm_list
//! <h1> MCAN Internal Loopback with Interrupt </h1>
//!
//! This example demonstrates Loopback functionality of the MCAN (CAN FD) module.
//! The internal loopback mode is chosen. The transmitted message will be received
//! by the node. All action is internal to the device, hence transmission will not be
//! visible on the MCAN_TX pin. Uses the last address of memory for Rx buffer.
//!
//! Before running this example, please run the mcan_config_c28x example
//! It will initialize the clock, configure the GPIOs.
//!
//! \b External \b Connections \n
//! - None.
//!
//! \b Watch \b Variables \n
//! - error - Checks if there is an error that occurred when the data was
//! sent using internal loopback.
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
//
// Include Files
//
#include "cm.h"
#include "inc/stw_dataTypes.h"
#include "inc/stw_types.h"
//
// Defines
//
#define MCAN_STD_ID_FILT_START_ADDR (0x0U)
#define MCAN_STD_ID_FILTER_NUM (1U)
#define MCAN_EXT_ID_FILT_START_ADDR (0x14U)
#define MCAN_EXT_ID_FILTER_NUM (1U)
#define MCAN_TX_BUFF_START_ADDR (0x80U)
#define MCAN_TX_BUFF_SIZE (10U)
#define MCAN_FIFO_1_START_ADDR (0xc0U)
#define MCAN_FIFO_1_NUM (10U)
#define MCAN_TX_EVENT_START_ADDR (0x100U)
#define MCAN_TX_EVENT_SIZE (10U)
#define MCAN_EXT_ID_AND_MASK (0x1FFFFFFFU)
#define MCAN_RX_BUFF_START_ADDR (948U)
#define MCAN_FIFO_0_START_ADDR (548U)
#define MCAN_FIFO_0_NUM (5U)
#define MCAN_MSG_INT (0x81200)
//
// Global Variables.
//
volatile uint32_t isrIntr0Flag = 1U;
volatile uint32_t isrIntr1Flag = 1U;
volatile uint16_t monEn = 0x0;
volatile unsigned long msgCount = 0;
volatile unsigned long error = 0;
//
// Function Prototype.
//
static void MCANConfig(void);
static void MCANIntrConfig(void);
static void MCANIntr0ISR(void);
static void MCANIntr1ISR(void);
//
// Main
//
void main(void)
{
volatile uint32_t mode = 0U;
MCAN_TxBufElement txMsg;
MCAN_RxBufElement rxMsg;
MCAN_RxNewDataStatus newData;
//
// Switching on the peripheral.
//
CM_init();
//
// Reset the peripheral.
//
SysCtl_resetPeripheral(SYSCTL_PERIPH_RES_MCAN_A);
//
// CrossBar and ISR Configuration.
//
MCANIntrConfig();
//
// Initialize message to transmit.
//
txMsg.id = ((uint32_t)(0x4)) << 18U; // Identifier Value.
txMsg.rtr = 0U; // Transmit data frame.
txMsg.xtd = 0U; // 11-bit standard identifier.
txMsg.esi = 0U; // ESI bit in CAN FD format depends only on error
// passive flag.
txMsg.dlc = 4U; // CAN + CAN FD: transmit frame has 0-8 data bytes.
txMsg.brs = 1U; // CAN FD frames transmitted with bit rate
// switching.
txMsg.fdf = 1U; // Frame transmitted in CAN FD format.
txMsg.efc = 1U; // Store Tx events.
txMsg.mm = 0xAAU; // Message Marker.
//
// Data bytes.
//
txMsg.data[0] = 0x12;
txMsg.data[1] = 0x34;
txMsg.data[2] = 0x56;
txMsg.data[3] = 0x78;
//
// Configure MCAN.
//
MCANConfig();
//
// Enable Interrupts.
//
MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_MASK_ALL, 1U);
//
// Select Interrupt Line.
//
MCAN_selectIntrLine(MCAN0_BASE, MCAN_INTR_MASK_ALL, MCAN_INTR_LINE_NUM_1);
//
// Enable Interrupt Line.
//
MCAN_enableIntrLine(MCAN0_BASE, MCAN_INTR_LINE_NUM_1, 1U);
//
// Write Tx Message to the Message RAM.
//
MCAN_writeMsgRam(MCAN0_BASE, MCAN_MEM_TYPE_BUF, 1U, &txMsg);
//
// Enable Transmission interrupt.
//
MCAN_txBufTransIntrEnable(MCAN0_BASE, 1U,1U);
//
// Add request for transmission.
//
MCAN_txBufAddReq(MCAN0_BASE, 1U);
//
// Wait for the isrIntr1Flag to be reset.
//
while(isrIntr1Flag)
{
}
//
// Read Message RAM.
//
MCAN_readMsgRam(MCAN0_BASE, MCAN_MEM_TYPE_BUF, 0U, MCAN_RX_FIFO_NUM_1,
&rxMsg);
//
// Get the New Data Status.
//
MCAN_getNewDataStatus(MCAN0_BASE, &newData);
//
// Check that received data matches sent data.
// Device will halt here during debug if data doesn't match.
//
if((txMsg.data[0] != rxMsg.data[0]) ||
(txMsg.data[1] != rxMsg.data[1]) ||
(txMsg.data[2] != rxMsg.data[2]) ||
(txMsg.data[3] != rxMsg.data[3]))
{
//
// Device will halt here if transmitted and received data are
// not same.
//
__asm(" bkpt #0");
}
else
{
//
// Increment message count if message is received.
//
msgCount++;
}
//
// Stop Application.
//
__asm(" bkpt #0");
}
//
// This function will configure MCAN module.
//
static void MCANConfig(void)
{
MCAN_RevisionId revId;
MCAN_InitParams initParams;
MCAN_ConfigParams configParams;
MCAN_MsgRAMConfigParams msgRAMConfigParams;
MCAN_StdMsgIDFilterElement stdFiltelem;
MCAN_BitTimingParams bitTimes;
//
// Initialize MCAN Init parameters.
//
initParams.fdMode = 0x1U; // FD operation enabled.
initParams.brsEnable = 0x1U; // Bit rate switching for
// transmissions enabled.
initParams.txpEnable = 0x0U; // Transmit pause disabled.
initParams.efbi = 0x0U; // Edge filtering disabled.
initParams.pxhddisable = 0x0U; // Protocol exception handling enabled.
initParams.darEnable = 0x0U; // Enable automatic retransmission of messages
// that were not transmitted successfully.
initParams.wkupReqEnable = 0x1U; // Wakeup request is enabled.
initParams.autoWkupEnable = 0x1U; // Auto-Wakeup is enabled.
initParams.emulationEnable = 0x1U; // Emulation/Debug Suspend is enabled.
initParams.tdcEnable = 0x1U; // Transmitter Delay Compensation is
// enabled.
initParams.wdcPreload = 0xFFU; // Start value of the Message RAM
// Watchdog Counter preload.
//
// Transmitter Delay Compensation parameters.
//
initParams.tdcConfig.tdcf = 0xAU;
initParams.tdcConfig.tdco = 0x6U;
//
// Initialize MCAN Config parameters.
//
configParams.monEnable = monEn; // Bus Monitoring Mode is disabled.
configParams.asmEnable = 0x0U; // Normal CAN operation.
configParams.tsPrescalar = 0xFU; // Prescaler Value.
configParams.tsSelect = 0x0U; // Timestamp counter value.
configParams.timeoutSelect = MCAN_TIMEOUT_SELECT_CONT;
// Time-out counter source select.
configParams.timeoutPreload = 0xFFFFU; // Start value of the Timeout
// Counter.
configParams.timeoutCntEnable = 0x0U; // Time-out Counter is disabled.
configParams.filterConfig.rrfs = 0x1U; // Reject all remote frames with
// 29-bit extended IDs.
configParams.filterConfig.rrfe = 0x1U; // Reject all remote frames with
// 11-bit standard IDs.
configParams.filterConfig.anfe = 0x1U; // Accept in Rx FIFO 1.
configParams.filterConfig.anfs = 0x1U; // Accept in Rx FIFO 1.
//
// Initialize Message RAM Sections Configuration Parameters.
//
msgRAMConfigParams.flssa = MCAN_STD_ID_FILT_START_ADDR;
// Standard ID Filter List Start Address.
msgRAMConfigParams.lss = MCAN_STD_ID_FILTER_NUM;
// List Size: Standard ID.
msgRAMConfigParams.flesa = MCAN_EXT_ID_FILT_START_ADDR;
// Extended ID Filter List Start Address.
msgRAMConfigParams.lse = MCAN_EXT_ID_FILTER_NUM;
// List Size: Extended ID.
msgRAMConfigParams.txStartAddr = MCAN_TX_BUFF_START_ADDR;
// Tx Buffers Start Address.
msgRAMConfigParams.txBufNum = MCAN_TX_BUFF_SIZE;
// Number of Dedicated Transmit Buffers.
msgRAMConfigParams.txFIFOSize = 0U; // No Tx FIFO/Queue.
msgRAMConfigParams.txBufMode = 0U; //Tx FIFO operation
msgRAMConfigParams.txBufElemSize = MCAN_ELEM_SIZE_64BYTES;
// Tx Buffer Element Size.
msgRAMConfigParams.txEventFIFOStartAddr = MCAN_TX_EVENT_START_ADDR;
// Tx Event FIFO Start Address.
msgRAMConfigParams.txEventFIFOSize = MCAN_TX_BUFF_SIZE;
// Event FIFO Size.
msgRAMConfigParams.txEventFIFOWaterMark = 3U;
// Level for Tx Event FIFO watermark interrupt.
msgRAMConfigParams.rxFIFO0startAddr = MCAN_FIFO_0_START_ADDR;
// Rx FIFO0 Start Address.
msgRAMConfigParams.rxFIFO0size = MCAN_FIFO_0_NUM;
// Number of Rx FIFO elements.
msgRAMConfigParams.rxFIFO0waterMark = 3U; // Rx FIFO0 Watermark.
msgRAMConfigParams.rxFIFO0OpMode = 0U; // FIFO blocking mode.
msgRAMConfigParams.rxFIFO1startAddr = MCAN_FIFO_1_START_ADDR;
// Rx FIFO1 Start Address.
msgRAMConfigParams.rxFIFO1size = MCAN_FIFO_1_NUM;
// Number of Rx FIFO elements.
msgRAMConfigParams.rxFIFO1waterMark = 3U; // Level for Rx FIFO 1
// watermark interrupt.
msgRAMConfigParams.rxFIFO1OpMode = 0U; // FIFO blocking mode.
msgRAMConfigParams.rxBufStartAddr = MCAN_RX_BUFF_START_ADDR;
// Rx Buffer Start Address.
msgRAMConfigParams.rxBufElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx Buffer Element Size.
msgRAMConfigParams.rxFIFO0ElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx FIFO0 Element Size.
msgRAMConfigParams.rxFIFO1ElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx FIFO1 Element Size.
//
// Initialize Tx Buffer Configuration parameters.
//
stdFiltelem.sfid2 = 0x0U; // Standard Filter ID 2.
stdFiltelem.sfid1 = 0x4U; // Standard Filter ID 1.
stdFiltelem.sfec = 0x7U; // Store into Rx Buffer or as
// debug message, configuration of SFT[1:0] ignored.
stdFiltelem.sft = 0x0U; // Range filter from SFID1 to SFID2.
//
// Initialize bit timings.
//
bitTimes.nomRatePrescalar = 0x1FU; // Nominal Baud Rate Pre-scaler.
bitTimes.nomTimeSeg1 = 0x1U; // Nominal Time segment before sample point.
bitTimes.nomTimeSeg2 = 0x1U; // Nominal Time segment after sample point.
bitTimes.nomSynchJumpWidth = 0x0U; // Nominal (Re)Synchronization Jump Width Range.
bitTimes.dataRatePrescalar = 0x3U; // Data Baud Rate Pre-scaler.
bitTimes.dataTimeSeg1 = 0x1U; // Data Time segment before sample point.
bitTimes.dataTimeSeg2 = 0x1U; // Data Time segment after sample point.
bitTimes.dataSynchJumpWidth = 0x0U; // Data (Re)Synchronization Jump Width.
//
// Get MCANSS Revision ID.
//
MCAN_getRevisionId(MCAN0_BASE, &revId);
//
// Wait for Memory initialization to be completed.
//
while(FALSE == MCAN_isMemInitDone(MCAN0_BASE));
//
// Put MCAN in SW initialization mode.
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_SW_INIT);
//
// Wait till MCAN is not initialized.
//
while (MCAN_OPERATION_MODE_SW_INIT != MCAN_getOpMode(MCAN0_BASE));
//
// Initialize MCAN module.
//
MCAN_init(MCAN0_BASE, &initParams);
//
// Configure MCAN module.
//
MCAN_config(MCAN0_BASE, &configParams);
//
// Configure Bit timings.
//
MCAN_setBitTime(MCAN0_BASE, &bitTimes);
//
// Set Extended ID Mask.
//
MCAN_setExtIDAndMask(MCAN0_BASE, MCAN_EXT_ID_AND_MASK);
//
// Configure Message RAM Sections
//
MCAN_msgRAMConfig(MCAN0_BASE, &msgRAMConfigParams);
//
// Configure Standard ID filter element
//
MCAN_addStdMsgIDFilter(MCAN0_BASE, 0U, &stdFiltelem);
//
// Enable internal loopback mode
//
MCAN_lpbkModeEnable(MCAN0_BASE, MCAN_LPBK_MODE_EXTERNAL, TRUE);
//
// Take MCAN out of the SW initialization mode
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_NORMAL);
while (MCAN_OPERATION_MODE_NORMAL != MCAN_getOpMode(MCAN0_BASE));
}
//
// This function will configure X-BAR for MCAN interrupts.
//
static void MCANIntrConfig(void)
{
Interrupt_registerHandler(INT_MCANSS_0,&MCANIntr0ISR);
Interrupt_enable(INT_MCANSS_0);
Interrupt_registerHandler(INT_MCANSS_1,&MCANIntr1ISR);
Interrupt_enable(INT_MCANSS_1);
Interrupt_enableInProcessor();
}
//
// This is Interrupt Service Routine for MCAN interrupt 0.
//
static void MCANIntr0ISR(void)
{
uint32_t intrStatus;
intrStatus = MCAN_getIntrStatus(MCAN0_BASE);
if (MCAN_MSG_INT != intrStatus)
{
error++;
}
//
// Clear the interrupt Status.
//
MCAN_clearIntrStatus(MCAN0_BASE, intrStatus);
//
// Update the flag value.
//
isrIntr0Flag = 0U;
}
//
// This is Interrupt Service Routine for MCAN interrupt 1.
//
static void MCANIntr1ISR(void)
{
uint32_t intrStatus;
intrStatus = MCAN_getIntrStatus(MCAN0_BASE);
if (MCAN_MSG_INT != intrStatus)
{
error++;
}
//
// Clear the interrupt Status.
//
MCAN_clearIntrStatus(MCAN0_BASE, intrStatus);
//
// Update the flag value.
//
isrIntr1Flag = 0U;
}
@@ -0,0 +1,640 @@
//#############################################################################
//
// FILE: mcan_ex2_external_loopback.c
//
// TITLE: MCAN External Loopback with Interrupt
//
//! \addtogroup driver_example_cm_list
//! <h1> MCAN External Loopback with Interrupt </h1>
//!
//! This example shows the MCAN External Loopback functionality. The external
//! loopback is done between two MCAN Controllers. As there is only one MCAN
//! that exist this example can be changed to make MCAN Transmit or Receive
//! based on define selected. The GPIOs of MCAN should be connected to a CAN
//! Transceiver
//!
//! Before running this example, please run the mcan_config_c28x example
//! It will initialize the clock, configure the GPIOs.
//!
//! Selection of Mode : A define has to be selected to make the MCAN to
//! transmit or receive.
//! - TRANSMIT - MCAN to Transmit messages.
//! - RECEIVE - MCAN to Receive Messages.
//!
//! Run the example as with RECEIVE Define on one MCAN Controller before
//! running it as Transmit.
//!
//! \b Hardware \b Required \n
//! - A C2000 board with CAN transceiver
//!
//! \b External \b Connections \n
//! - MCAN is on GPIO30 (MCANRXA) and GPIO31 (MCANTXA)
//!
//! \b Watch \b Variables \n
//! - isrIntr0Flag - The flag has initial value as no. of messages to be
//! transmitted and its value decrements after a message is
//! transmitted.
//! - isrIntr1Flag - The flag has initial value as no. of messages that are
//! received and its value decrements after a message is
//! successfully received.
//! - error - Checks if there is an error that occurred when the data was
//! sent using internal loopback
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
//
// Include Files
//
#include "cm.h"
#include "inc/stw_types.h"
#include "inc/stw_dataTypes.h"
//
// Select one of the Modes.
//
#define TRANSMIT
//#define RECEIVE
//
// Defines.
//
#define NUM_OF_MSG (10U)
#define MCAN_STD_ID_FILT_START_ADDR (0U)
#define MCAN_STD_ID_FILTER_NUM (1U)
#define MCAN_EXT_ID_FILT_START_ADDR (48U)
#define MCAN_EXT_ID_FILTER_NUM (1U)
#define MCAN_TX_EVENT_START_ADDR (100U)
#define MCAN_TX_EVENT_SIZE (NUM_OF_MSG)
#define MCAN_TX_EVENT_WATERMARK (NUM_OF_MSG/2)
#define MCAN_TX_BUFF_START_ADDR (148U)
#define MCAN_TX_BUFF_SIZE (NUM_OF_MSG)
#define MCAN_TX_FIFO_SIZE (NUM_OF_MSG)
#define MCAN_FIFO_0_START_ADDR (548U)
#define MCAN_FIFO_0_NUM (NUM_OF_MSG)
#define MCAN_FIFO_0_WATERMARK (NUM_OF_MSG)
#define MCAN_FIFO_1_START_ADDR (748U)
#define MCAN_FIFO_1_NUM (NUM_OF_MSG)
#define MCAN_FIFO_1_WATERMARK (NUM_OF_MSG)
#define MCAN_RX_BUFF_START_ADDR (948U)
#define MCAN_EXT_ID_AND_MASK (0x1FFFFFFFU)
#define MCAN_TS_PRESCALAR (0xB0)
#define MCAN_TX_BUFF_ELEM_SIZE (MCAN_ELEM_SIZE_64Bytes)
#define MCAN_RX_BUFF_ELEM_SIZE (MCAN_ELEM_SIZE_64Bytes)
#define MCAN_RX_FIFO0_ELEM_SIZE (MCAN_ELEM_SIZE_64Bytes)
#define MCAN_RX_FIFO1_ELEM_SIZE (MCAN_ELEM_SIZE_64Bytes)
//
// Global Variables.
//
volatile uint32_t isrIntr0Flag = NUM_OF_MSG;
volatile uint32_t isrIntr1Flag = NUM_OF_MSG;
volatile uint32_t isrIntrTSFlag = 1U;
int32_t error = 0;
MCAN_TxBufElement txMsg[NUM_OF_MSG];
MCAN_RxBufElement rxMsg[NUM_OF_MSG], rxMsg1;
int32_t loopCnt = 0U;
//
// Function Prototype.
//
static void MCANConfig(void);
static void MCANIntrConfig(void);
static void MCANIntr0ISR(void);
static void MCANIntr1ISR(void);
void main()
{
#ifdef RECEIVE
int32_t dataCnt;
#endif
int i = 0;
uint32_t numOfMsg = NUM_OF_MSG;
volatile uint32_t mode = 0U;
uint32_t dataBytes = 8;
//
// Switching on the peripheral.
//
CM_init();
//
// Reset the peripheral.
//
SysCtl_resetPeripheral(SYSCTL_PERIPH_RES_MCAN_A);
//
// CrossBar and ISR Configuration.
//
MCANIntrConfig();
//
// Initialize message to transmit.
//
for(loopCnt = 0U ; loopCnt < numOfMsg ; loopCnt++)
{
txMsg[loopCnt].id = (0x0);
txMsg[loopCnt].id = (loopCnt) << 16U;
txMsg[loopCnt].id |= (0xFF);
txMsg[loopCnt].rtr = 0U;
txMsg[loopCnt].xtd = 1U;
txMsg[loopCnt].esi = 0U;
txMsg[loopCnt].dlc = 15U;
txMsg[loopCnt].brs = 0U;
txMsg[loopCnt].fdf = 1U;
txMsg[loopCnt].efc = 1U;
txMsg[loopCnt].mm = 0xAAU;
txMsg[loopCnt].data[i] = 0x1;
for(i = 1; i < dataBytes; i++)
{
txMsg[loopCnt].data[i] = txMsg[loopCnt].data[i-1] + 1;
}
i = 0;
}
for(loopCnt = 0U ; loopCnt < numOfMsg ; loopCnt++)
{
rxMsg[loopCnt].id = 0U;
rxMsg[loopCnt].rtr = 0U;
rxMsg[loopCnt].xtd = 0U;
rxMsg[loopCnt].esi = 0U;
rxMsg[loopCnt].rxts = 0U;
rxMsg[loopCnt].dlc = 0U;
rxMsg[loopCnt].brs = 0U;
rxMsg[loopCnt].fdf = 0U;
rxMsg[loopCnt].fidx = 0U;
rxMsg[loopCnt].anmf = 0U;
for(i = 0; i < dataBytes; i++)
{
rxMsg[loopCnt].data[i] = 0;
}
}
//
// Configure the MCAN Module.
//
MCANConfig();
#ifdef TRANSMIT
//
// This is transmitter side application.
//
//
// Enable Interrupts.
//
MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_MASK_ALL,1);
MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_SRC_RES_ADDR_ACCESS|
MCAN_INTR_SRC_TIMESTAMP_WRAPAROUND,0);
//
// Select Interrupt Line.
//
MCAN_selectIntrLine(MCAN0_BASE, MCAN_INTR_MASK_ALL,
MCAN_INTR_LINE_NUM_0);
//
// Enable Interrupt Line.
//
MCAN_enableIntrLine(MCAN0_BASE, MCAN_INTR_LINE_NUM_0, 1U);
//
// Enable Transmission interrupt.
//
for(loopCnt = 0U ; loopCnt < numOfMsg ; loopCnt++)
{
MCAN_txBufTransIntrEnable(MCAN0_BASE, loopCnt,1);
//
// Write message to Message RAM.
//
MCAN_writeMsgRam(MCAN0_BASE, MCAN_MEM_TYPE_BUF, loopCnt,
&txMsg[loopCnt]);
}
//
// Add request for all transmission.
//
HWREG(MCAN0_BASE + MCAN_TXBAR) = 0x000003FF;
//
// Wait till the flag becomes zero and all the messages are transmitted.
//
while(isrIntr0Flag)
{
}
#endif
#ifdef RECEIVE
//
// This is receiver side application.
//
//
// Enable Interrupts.
//
MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_MASK_ALL,1);
MCAN_enableIntr(MCAN0_BASE, MCAN_INTR_SRC_RES_ADDR_ACCESS|
MCAN_INTR_SRC_TIMESTAMP_WRAPAROUND,0);
//
// Select Interrupt Line.
//
MCAN_selectIntrLine(MCAN0_BASE, MCAN_INTR_MASK_ALL,
MCAN_INTR_LINE_NUM_1);
//
// Enable Interrupt Line.
//
MCAN_enableIntrLine(MCAN0_BASE, MCAN_INTR_LINE_NUM_1, 1U);
//
// Wait till the interrupt flag becomes zero.
//
while(isrIntr1Flag)
{
}
for(loopCnt = 0U ; loopCnt < numOfMsg;loopCnt++)
{
MCAN_readMsgRam(MCAN0_BASE, MCAN_MEM_TYPE_FIFO, 0U,
MCAN_RX_FIFO_NUM_1, &rxMsg1);
MCAN_writeRxFIFOAck(MCAN0_BASE, MCAN_RX_FIFO_NUM_1,
loopCnt);
rxMsg[loopCnt] = rxMsg1;
}
for(loopCnt = 0U ; loopCnt < numOfMsg ; loopCnt++)
{
if (rxMsg[loopCnt].id != txMsg[loopCnt].id)
{
error++;
}
if (rxMsg[loopCnt].rtr != txMsg[loopCnt].rtr)
{
error++;
}
if (rxMsg[loopCnt].xtd != txMsg[loopCnt].xtd)
{
error++;
}
if (rxMsg[loopCnt].esi != txMsg[loopCnt].esi)
{
error++;
}
if (rxMsg[loopCnt].dlc != txMsg[loopCnt].dlc)
{
error++;
}
if (rxMsg[loopCnt].brs != txMsg[loopCnt].brs)
{
error++;
}
if (rxMsg[loopCnt].fdf != txMsg[loopCnt].fdf)
{
error++;
}
if (loopCnt > 0)
{
if (rxMsg[loopCnt].rxts > rxMsg[loopCnt-1].rxts)
{
}
else
{
error++;
}
}
for (dataCnt = 0U ; dataCnt < dataBytes ; dataCnt++)
{
if (rxMsg[loopCnt].data[dataCnt]!=
txMsg[loopCnt].data[dataCnt])
{
error++;
}
}
}
#endif
if (error != 0)
{
//
// Stop if there is an error.
//
__asm(" bkpt #0");
}
//
// Stop Application.
//
__asm(" bkpt #0");
}
static void MCANIntrConfig(void)
{
Interrupt_registerHandler(INT_MCANSS_0,&MCANIntr0ISR);
Interrupt_enable(INT_MCANSS_0);
Interrupt_registerHandler(INT_MCANSS_1,&MCANIntr1ISR);
Interrupt_enable(INT_MCANSS_1);
Interrupt_enableInProcessor();
}
static void MCANConfig(void)
{
MCAN_RevisionId revId;
MCAN_InitParams initParams;
MCAN_ConfigParams configParams;
MCAN_MsgRAMConfigParams msgRAMConfigParams;
MCAN_StdMsgIDFilterElement stdFiltelem;
MCAN_ExtMsgIDFilterElement extFiltelem;
MCAN_BitTimingParams bitTimes;
//
// Initialize MCAN Init parameters.
//
initParams.fdMode = 0x1U; // FD operation disabled.
initParams.brsEnable = 0x1U; // Bit rate switching for
// transmissions enabled.
initParams.txpEnable = 0x1U; // Transmit pause enabled.
initParams.efbi = 0x0U; // Edge filtering disabled.
initParams.pxhddisable = 0x0U; // Protocol exception handling enabled.
initParams.darEnable = 0x1U; // Enable automatic retransmission of messages
// that were not transmitted successfully.
initParams.wkupReqEnable = 0x1U; // Wakeup request is enabled.
initParams.autoWkupEnable = 0x1U; // Auto-Wakeup is enabled.
initParams.emulationEnable = 0x1U; // Emulation/Debug Suspend is enabled.
initParams.tdcEnable = 0x1U; // Transmitter Delay Compensation is
// enabled.
initParams.wdcPreload = 0xFFU; // Start value of the Message RAM
// Watchdog Counter preload.
//
// Transmitter Delay Compensation parameters.
//
initParams.tdcConfig.tdcf = 0xAU;
initParams.tdcConfig.tdco = 0x6U;
//
// Initialize MCAN Config parameters.
//
configParams.monEnable = 0x0U; // Bus Monitoring Mode is disabled.
configParams.asmEnable = 0x0U; // Normal CAN operation.
configParams.tsPrescalar = 0x2U; // Prescaler Value.
configParams.tsSelect = 0x2U; // Timestamp counter value.
configParams.timeoutSelect = MCAN_TIMEOUT_SELECT_CONT;
// Time-out counter source select.
configParams.timeoutPreload = 0xFFFFU;// Start value of the Timeout
// Counter.
configParams.timeoutCntEnable = 0x0U; // Time-out Counter is disabled.
configParams.filterConfig.rrfs = 0x1U; // Reject all remote frames with
// 29-bit extended IDs.
configParams.filterConfig.rrfe = 0x1U; // Reject all remote frames with
// 11-bit standard IDs.
configParams.filterConfig.anfe = 0x1U; // Accept in Rx FIFO 1.
configParams.filterConfig.anfs = 0x1U; // Accept in Rx FIFO 1.
//
// Initialize Message RAM Sections Configuration Parameters
//
msgRAMConfigParams.flssa = MCAN_STD_ID_FILT_START_ADDR;
// Standard ID Filter List Start Address.
msgRAMConfigParams.lss = MCAN_STD_ID_FILTER_NUM;
// List Size: Standard ID.
msgRAMConfigParams.flesa = MCAN_EXT_ID_FILT_START_ADDR;
// Extended ID Filter List Start Address.
msgRAMConfigParams.lse = MCAN_EXT_ID_FILTER_NUM;
// List Size: Extended ID.
msgRAMConfigParams.txStartAddr = MCAN_TX_BUFF_START_ADDR;
// Tx Buffers Start Address.
msgRAMConfigParams.txBufNum = MCAN_TX_BUFF_SIZE;
// Number of Dedicated Transmit Buffers.
msgRAMConfigParams.txFIFOSize = MCAN_TX_FIFO_SIZE;
// Tx FIFO/Queue.
msgRAMConfigParams.txBufMode = 0U;
msgRAMConfigParams.txBufElemSize = MCAN_ELEM_SIZE_64BYTES;
// Tx Buffer Element Size.
msgRAMConfigParams.txEventFIFOStartAddr = MCAN_TX_EVENT_START_ADDR;
// Tx Event FIFO Start Address.
msgRAMConfigParams.txEventFIFOSize = MCAN_TX_BUFF_SIZE;
// Event FIFO Size.
msgRAMConfigParams.txEventFIFOWaterMark = MCAN_TX_EVENT_WATERMARK;
// Level for Tx Event FIFO watermark interrupt.
msgRAMConfigParams.rxFIFO0startAddr = MCAN_FIFO_0_START_ADDR;
// Rx FIFO0 Start Address.
msgRAMConfigParams.rxFIFO0size = MCAN_FIFO_0_NUM;
// Number of Rx FIFO elements.
msgRAMConfigParams.rxFIFO0waterMark = MCAN_FIFO_0_WATERMARK;
msgRAMConfigParams.rxFIFO0OpMode = 0U;
msgRAMConfigParams.rxFIFO1startAddr = MCAN_FIFO_1_START_ADDR;
// Rx FIFO1 Start Address.
msgRAMConfigParams.rxFIFO1size = MCAN_FIFO_1_NUM;
// Number of Rx FIFO elements.
msgRAMConfigParams.rxFIFO1waterMark = MCAN_FIFO_1_WATERMARK;
// Level for Rx FIFO 1 watermark interrupt.
msgRAMConfigParams.rxFIFO1OpMode = 0U; // FIFO blocking mode.
msgRAMConfigParams.rxBufStartAddr = MCAN_RX_BUFF_START_ADDR;
// Rx Buffer Start Address.
msgRAMConfigParams.rxBufElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx Buffer Element Size.
msgRAMConfigParams.rxFIFO0ElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx FIFO0 Element Size.
msgRAMConfigParams.rxFIFO1ElemSize = MCAN_ELEM_SIZE_64BYTES;
// Rx FIFO1 Element Size.
//
// Initialize Tx Buffer Configuration parameters.
//
stdFiltelem.sfid2 = 0x0U; // Standard Filter ID 2.
stdFiltelem.sfid1 = 0x4U; // Standard Filter ID 1.
stdFiltelem.sfec = 0x7U; // Store into Rx Buffer or as
// debug message, configuration of SFT[1:0] ignored.
stdFiltelem.sft = 0x0U; // Range filter from SFID1 to SFID2.
//
// Initialize Tx Buffer Configuration parameters.
//
extFiltelem.efid2 = (0x9U << 16U);
extFiltelem.efid2 |= 0xFFU;
extFiltelem.efid1 = (0x0U << 16U);
extFiltelem.efid1 |= 0xFFU;
extFiltelem.efec = 0x6U;
extFiltelem.eft = 0x0U;
//
// Initialize bit timings.
//
bitTimes.nomRatePrescalar = 0x1FU; // Nominal Baud Rate Pre-scaler.
bitTimes.nomTimeSeg1 = 0x1U; // Nominal Time segment before sample point.
bitTimes.nomTimeSeg2 = 0x1U; // Nominal Time segment after sample point.
bitTimes.nomSynchJumpWidth = 0x0U; // Nominal (Re)Synchronization Jump Width Range.
bitTimes.dataRatePrescalar = 0x3U; // Data Baud Rate Pre-scaler.
bitTimes.dataTimeSeg1 = 0x1U; // Data Time segment before sample point.
bitTimes.dataTimeSeg2 = 0x1U; // Data Time segment after sample point.
bitTimes.dataSynchJumpWidth = 0x0U; // Data (Re)Synchronization Jump Width.
//
// Get MCANSS Revision ID
//
MCAN_getRevisionId(MCAN0_BASE, &revId);
//
// Wait for memory initialization to happen.
//
while(FALSE == MCAN_isMemInitDone(MCAN0_BASE))
{
}
//
// Put MCAN in SW initialization mode.
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_SW_INIT);
//
// Wait till MCAN is not initialized.
//
while (MCAN_OPERATION_MODE_SW_INIT != MCAN_getOpMode(MCAN0_BASE))
{}
//
// Initialize MCAN module.
//
MCAN_init(MCAN0_BASE, &initParams);
//
// Configure MCAN module.
//
MCAN_config(MCAN0_BASE, &configParams);
//
// Disable external timeStamp overflow interrupt.
//
MCAN_extTSEnableIntr(MCAN0_BASE,1);
//
// Configure TimeStamp Counter.
//
MCAN_extTSCounterConfig(MCAN0_BASE, MCAN_TS_PRESCALAR);
//
// Configure Bit timings.
//
MCAN_setBitTime(MCAN0_BASE, &bitTimes);
//
// Set Extended ID Mask.
//
MCAN_setExtIDAndMask(MCAN0_BASE, MCAN_EXT_ID_AND_MASK);
//
// Configure Message RAM Sections
//
MCAN_msgRAMConfig(MCAN0_BASE, &msgRAMConfigParams);
//
// Configure Standard ID filter element
//
MCAN_addStdMsgIDFilter(MCAN0_BASE, 0U, &stdFiltelem);
//
// Configure Extended ID filter element
//
MCAN_addExtMsgIDFilter(MCAN0_BASE, 0U, &extFiltelem);
//
// Enable external counter.
//
MCAN_extTSCounterEnable(MCAN0_BASE, 1U);
//
// Take MCAN out of the SW initialization mode
//
MCAN_setOpMode(MCAN0_BASE, MCAN_OPERATION_MODE_NORMAL);
while (MCAN_OPERATION_MODE_NORMAL != MCAN_getOpMode(MCAN0_BASE))
{
}
}
static void MCANIntr0ISR(void)
{
uint32_t intrStatus;
intrStatus = MCAN_getIntrStatus(MCAN0_BASE);
MCAN_clearIntrStatus(MCAN0_BASE, intrStatus);
if (MCAN_INTR_SRC_TRANS_COMPLETE == (intrStatus &
MCAN_INTR_SRC_TRANS_COMPLETE))
{
//
// Decrement the flag after each message is transmitted.
//
isrIntr0Flag--;
}
else
{
//
// Stop the application if error occurs.
//
__asm(" bkpt #0");
}
}
static void MCANIntr1ISR(void)
{
uint32_t intrStatus;
intrStatus = MCAN_getIntrStatus(MCAN0_BASE);
MCAN_clearIntrStatus(MCAN0_BASE, intrStatus);
if(MCAN_INTR_SRC_RX_FIFO1_NEW_MSG ==
(intrStatus & MCAN_INTR_SRC_RX_FIFO1_NEW_MSG))
{
//
// Decrement the flag after each message is received.
//
isrIntr1Flag--;
}
else
{
//
// Stop the application if error occurs.
//
__asm(" bkpt #0");
}
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="memcfg_ex1_error_handling"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../memcfg_ex1_error_handling.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,510 @@
//#############################################################################
//
// FILE: memcfg_ex1_error_handling.c
//
// TITLE: Demonstrate memconfig diagnostics and error handling
//
//! \addtogroup driver_example_cm_list
//! <h1> Demonstrate memconfig diagnostics and error handling. </h1>
//!
//! This example demonstrates how to configure the diagnostic mode and induce
//! ECC errors. This example induces single and two bit ECC errors in E0RAM and
//! tries to read the corrupted location in diagnostic and functional mode.
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b testStatus - Equivalent to \b TEST_PASS if test finished
//! correctly, else the value is set to \b TEST_FAIL
//! - \b errorGlobalCount - Error counter
//! - \b retx - Individual test status
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include <stdint.h>
#include <stdbool.h>
#include "cpu.h"
#include "sysctl.h"
#include "interrupt.h"
#include "memcfg.h"
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
void Write_CAFECAFE(uint32_t startAddress, uint32_t endAddress)
{
uint32_t * addr;
for (addr = (uint32_t *)startAddress;addr <= (uint32_t *)endAddress ; addr++)
{
*addr = 0xCAFECAFE;
}
}
static volatile uint32_t memcfgErrorCount;
static volatile uint32_t nmiFaultCount, nmiFaultAddr;
uint32_t offset, eccRead1, eccRead2, readDataStart, cnt;
static volatile uint32_t testStatus = TEST_FAIL;
static volatile uint32_t errorGlobalCount = 0;
void
NMIFaultHandler(void)
{
//
// Check the NMI flag and clear it
//
if(!SysCtl_isNMIFlagSet(SYSCTL_NMI_MEMUNCERR))
{
errorGlobalCount++;
}
SysCtl_clearAllNMIFlags();
//
// get the address at which error occured and clear the flag
//
nmiFaultAddr = MemCfg_getUncorrErrorAddress(MEMCFG_UCERR_M4READ);
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
//
// Increment a counter to indicate the fault occurred.
//
nmiFaultCount++;
}
void
memcfgErrorISR(void)
{
//
// Check the flag and clear it
//
if(MemCfg_getCorrErrorInterruptStatus() != MEMCFG_CERR_M4READ)
{
errorGlobalCount++;
}
MemCfg_clearCorrErrorInterruptStatus(MEMCFG_CERR_M4READ);
//
// Increment a counter to indicate the error occurred.
//
memcfgErrorCount++;
}
bool Test_CorrErr_DiagMode();
bool Test_CorrErr_FuncMode();
bool Test_UncorrErr();
//
// Main
//
int
main(void)
{
//
// Enable Memcfg interrupt and NMI.
//
Interrupt_registerHandler(INT_CMRAM_TESTERROR_LOG, memcfgErrorISR);
Interrupt_enable(INT_CMRAM_TESTERROR_LOG);
Interrupt_registerHandler(FAULT_NMI, NMIFaultHandler);
SysCtl_enableGlobalNMI();
//
// Run the tests
//
bool ret1 = Test_CorrErr_DiagMode();
bool ret2 = Test_CorrErr_FuncMode();
bool ret3 = Test_UncorrErr();
if(ret1 && ret2 && ret3)
testStatus = TEST_PASS;
else
testStatus = TEST_FAIL;
while(1);
}
//
// Induce correctable error in memory in diagnostics mode
//
bool Test_CorrErr_DiagMode()
{
memcfgErrorCount = 0;
nmiFaultCount = 0;
bool status = true;
MemCfg_setTestMode(MEMCFG_SECT_E0, MEMCFG_TEST_FUNCTIONAL);
//
// Initial ROM read leads to error since ROM parity bits are not loaded
// properly
//
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
MemCfg_clearCorrErrorStatus(MEMCFG_CERR_M4READ);
MemCfg_enableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
SysCtl_clearAllNMIFlags();
//
// Write to E0 RAM
//
Write_CAFECAFE(E0RAM_BASE, E0RAM_BASE + 0x3FFF);
//
// Set correctable error threshold. Correctable interrupt will be generated
// once correctable error count reaches the threshold value.
//
MemCfg_setCorrErrorThreshold(5U);
//
// Generate 6 correctable errors
//
for(cnt = 1U; cnt<= 6U; cnt++)
{
offset = 0x08U + cnt*4U;
//
// ECC data read before corrupting
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
eccRead1 = HWREG(E0RAM_BASE + offset);
//
// Flip single bit and write back
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_DATA);
HWREG(E0RAM_BASE + offset) = HWREG(E0RAM_BASE + offset) ^ 0x02;
//
// ECC data read after corrupting
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
eccRead2 = HWREG(E0RAM_BASE + offset);
//
// Go to diagnostic mode.
// Try to read data and ceheck if diagnostic log register bits
// are getting updated.
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_FUNC_DIAG);
readDataStart = HWREG(E0RAM_BASE + offset);
uint32_t diagErrStatus = MemCfg_getDiagErrorStatus();
uint32_t diagErrAddr = MemCfg_getDiagErrorAddress();
if((diagErrStatus != MEMCFG_DIAGERR_CORR_READ) ||
(diagErrAddr != (E0RAM_BASE + offset)) ||
(eccRead1 != eccRead2))
{
return false;
}
//
// Clear the error flag
//
MemCfg_clearDiagErrorStatus(MEMCFG_DIAGERR_CORR_READ);
}
//
// Go back to functional mode
//
MemCfg_setTestMode(MEMCFG_SECT_E0, MEMCFG_TEST_FUNCTIONAL);
MemCfg_disableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
//
// Adding NOPs to introduce delay
//
asm(" nop");
asm(" nop");
asm(" nop");
asm(" nop");
//
// Check for fault flags if any
//
if(memcfgErrorCount != 0)
return false;
if(nmiFaultCount != 0)
return false;
return status;
}
//
// Induce correctable error & check if interrupt is
// getting generated once threshold is reached.
//
bool Test_CorrErr_FuncMode()
{
memcfgErrorCount = 0;
nmiFaultCount = 0;
errorGlobalCount = 0;
MemCfg_setTestMode(MEMCFG_SECT_E0, MEMCFG_TEST_FUNCTIONAL);
//
// Initial ROM read leads to error since ROM parity bits are not loaded
// properly
//
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
MemCfg_clearCorrErrorStatus(MEMCFG_CERR_M4READ);
MemCfg_enableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
SysCtl_clearAllNMIFlags();
HWREG(CMMEMORYERROR_BASE + MEMCFG_O_CERRCNT) = 0;
//
// Write to E0 RAM
//
Write_CAFECAFE(E0RAM_BASE, E0RAM_BASE+0x3FFF);
//
// Set correctable error threshold. Correctable interrupt will be generated
// once corr error count reaches the threshold value.
//
MemCfg_setCorrErrorThreshold(5U);
//
// Generate 6 correctable erros
//
for(cnt = 1U; cnt<= 6U; cnt++)
{
offset = 0x08U + cnt * 4U;
//
// ECC data read before corrupting
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
eccRead1 = HWREG(E0RAM_BASE + offset);
//
// Flip single bit and write back
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_DATA);
HWREG(E0RAM_BASE + offset) = HWREG(E0RAM_BASE + offset) ^ 0x02;
readDataStart = HWREG(E0RAM_BASE + offset);
//
// ECC data read after corrupting
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
eccRead2 = HWREG(E0RAM_BASE + offset);
//
// Bring back to functional mode.
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_FUNCTIONAL);
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
//
// Read data to induce error
//
readDataStart = HWREG(E0RAM_BASE + offset);
//
// Check for the correctable error count. An interrupt is genertaed one
// the count reaches 5 and the count is reset
//
uint32_t corrErrCnt = MemCfg_getCorrErrorCount();
if(corrErrCnt != (cnt % 5))
return false;
//
// Check if the ECC before and after corruption is the same
// Check for error flag and address
//
uint32_t corrErrStatus = MemCfg_getCorrErrorStatus();
uint32_t corrErrAddr = MemCfg_getCorrErrorAddress(MEMCFG_CERR_M4READ);
if((eccRead1 != eccRead2) ||
(corrErrStatus != MEMCFG_CERR_M4READ) ||
(corrErrAddr != (E0RAM_BASE + offset)))
{
return false;
}
//
// Clear the flags
//
MemCfg_clearCorrErrorStatus(MEMCFG_CERR_M4READ);
MemCfg_disableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
MemCfg_enableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
}
MemCfg_disableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
//
// Adding NOPs to introduce delay
//
asm(" nop");
asm(" nop");
asm(" nop");
asm(" nop");
//
// Check for the fault ISRs. Check if MemCfg error interrupt is invoked once
//
if(memcfgErrorCount != 1)
return false;
if(nmiFaultCount != 0)
return false;
if(errorGlobalCount != 0)
return false;
return true;
}
//
//Induce uncorrectable error in memory
//
bool Test_UncorrErr()
{
memcfgErrorCount = 0;
nmiFaultCount = 0;
errorGlobalCount = 0;
MemCfg_setTestMode(MEMCFG_SECT_E0, MEMCFG_TEST_FUNCTIONAL);
//
// Initial ROM read leads to error since ROM parity bits are not loaded
// properly
//
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
MemCfg_clearCorrErrorStatus(MEMCFG_CERR_M4READ);
MemCfg_enableCorrErrorInterrupt(MEMCFG_CERR_M4READ);
SysCtl_clearAllNMIFlags();
//
// Write to E0 RAM
//
Write_CAFECAFE(E0RAM_BASE, E0RAM_BASE+0x3FFF);
//
// Set correctable error threshold. Correctable interrupt will be generated
// once corr error count reaches the threshold value.
//
MemCfg_setCorrErrorThreshold(5U);
//
// Generate 6 correctable erros
//
for(cnt = 1U; cnt<= 6U; cnt++)
{
offset = 0x08U + cnt*4U;
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
//
// ECC data read before corrupting
//
eccRead1 = HWREG(E0RAM_BASE + offset);
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_DATA);
//
// Flip two bits and write back
//
HWREG(E0RAM_BASE + offset) = HWREG(E0RAM_BASE + offset) ^ 0x03;
//
// ECC data read after corrupting
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_WRITE_ECC);
eccRead2 = HWREG(E0RAM_BASE + offset);
//
// Bring back to functional mode.
//
MemCfg_setTestMode(MEMCFG_SECT_E0,MEMCFG_TEST_FUNCTIONAL);
//
// Initial ROM read leads to error since ROM parity bits are not loaded
// properly
//
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
//
// Read data to induce error. This causes an NMI
//
readDataStart = HWREG(E0RAM_BASE + offset);
//
// Adding NOPs to introduce delay
//
asm(" nop");
asm(" nop");
asm(" nop");
asm(" nop");
//
// Check if the ECC before and after corruption is the same
// Check for NMI flag and address
//
if((eccRead1 != eccRead2) || (nmiFaultCount != cnt) || nmiFaultAddr != (E0RAM_BASE + offset))
{
return false;
}
MemCfg_clearUncorrErrorStatus(MEMCFG_UCERR_M4READ);
}
//
// Adding NOPs to introduce delay
//
asm(" nop");
asm(" nop");
asm(" nop");
asm(" nop");
//
// Check for fault ISRs. Check if NMI fault is invoked 6 times
//
if(memcfgErrorCount != 0)
return false;
if(nmiFaultCount != 6)
return false;
if(errorGlobalCount != 0)
return false;
return true;
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="mpu_ex1_fault_handling"
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 RAM --define=DEBUG --float_support=none -mv7M4 -me --diag_warning=225" linkerBuildOptions="--stack_size=1024 --heap_size=1024 --library=libc.a" />
<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=1024 --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../mpu_ex1_fault_handling.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,435 @@
//#############################################################################
//
// FILE: mpu_ex1_fault_handling.c
//
// TITLE: Demonstrate CM4 MPU usage.
//
//! \addtogroup driver_example_cm_list
//! <h1> Demonstrate CM4 MPU usage. </h1>
//!
//! This example demonstrates how to configure MPU regions for different levels
//! of memory protection using core MPU. It demonstrates the use of the MPU to
//! protect a region of memory from access, and to handle a memory management
//! fault when there is an access violation.
//!
//! The following memory map is set up:
//! -\b Region 0 - executable, prv(r/w), user(r/w)
//! -\b Region 1 - executable, prv(read only), user(read only), code mem(RAM)
//! -\b Region 2 - executable, prv(read only), user(read only), code mem(RAM)
//! -\b Region 3 - non-exec, prv(r/w), user(r/w), for NVIC
//! -\b Region 4 - non-exec, prv(read only), user(none)
//! -\b Region 5 - non-exec, prv(none), user(none)
//! -\b Region 6 - non-exec, prv(read only), user(read only)
//! -\b Region 7 - non-exec, prv (r/w), user (none)
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b testStatusGlobal - Equivalent to \b TEST_PASS if test finished
//! correctly, else the value is set to \b TEST_FAIL
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global test status
//
uint32_t testStatusGlobal;
//
// Variables to hold the state of the fault status when the fault occurs and
// the faulting address.
//
static volatile uint32_t memFaultAdd, busFaultAdd;
static volatile uint32_t faultStatus;
//
// A counter to track the number of times the fault handler has been entered.
//
static volatile uint32_t faultCount;
//
// A location for storing data read from various addresses. Volatile forces
// the compiler to use it and not optimize the access away.
//
static volatile uint32_t readVal;
uint32_t successFlag = 0, tempVal;
//
// Function Prototypes
//
void MPUFaultHandler(void);
void BUSFaultHandler(void);
//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
CM_init();
//
// Configuring Region 0- executable, prv(r/w), user(r/w)
//
MPU_setRegionAttributes(MPU_RGN_0, S3RAM_BASE,
(MPU_RGN_SIZE_16K | MPU_RGN_PERM_EXEC |
MPU_RGN_PERM_PRV_RW_USR_RW | MPU_RGN_ENABLE));
//
// Configuring Region 1- executable, prv(read only), user(read only)
//
MPU_setRegionAttributes(MPU_RGN_1, S1RAM_BASE,
(MPU_RGN_SIZE_16K | MPU_RGN_PERM_EXEC |
MPU_RGN_PERM_PRV_RO_USR_RO | MPU_RGN_ENABLE));
//
// Configuring Region 2- executable, prv(read only), user(read only)
//
MPU_setRegionAttributes(MPU_RGN_2, S0RAM_BASE,
(MPU_RGN_SIZE_16K | MPU_RGN_PERM_EXEC |
MPU_RGN_PERM_PRV_RO_USR_RO | MPU_RGN_ENABLE));
//
// Configuring Region 3- non-executable, prv(r/w), user(r/w)
// This region is needed because NVIC registers are needed
// in order to control the MPU.
//
MPU_setRegionAttributes(MPU_RGN_3, NVIC_BASE,
(MPU_RGN_SIZE_4K | MPU_RGN_PERM_NOEXEC |
MPU_RGN_PERM_PRV_RW_USR_RW | MPU_RGN_ENABLE));
//
// Configuring Region 4- non-executable, prv(read only), user(none)
//
MPU_setRegionAttributes(MPU_RGN_4, (S2RAM_BASE + 0x1800U),
(MPU_RGN_SIZE_2K | MPU_RGN_PERM_NOEXEC |
MPU_RGN_PERM_PRV_RO_USR_NO | MPU_RGN_ENABLE));
//
// Configuring Region 5- non-executable, prv(none), user(none)
//
MPU_setRegionAttributes(MPU_RGN_5, (S2RAM_BASE + 0x1000U),
(MPU_RGN_SIZE_2K | MPU_RGN_PERM_NOEXEC |
MPU_RGN_PERM_PRV_NO_USR_NO | MPU_RGN_ENABLE));
//
// Configuring Region 6- non-executable, prv(read only), user(read only)
//
MPU_setRegionAttributes(MPU_RGN_6, (S2RAM_BASE + 0x800U),
(MPU_RGN_SIZE_2K | MPU_RGN_PERM_NOEXEC |
MPU_RGN_PERM_PRV_RO_USR_RO | MPU_RGN_ENABLE));
//
// Configuring Region 7- non-executable, prv(r/w), user(none)
//
MPU_setRegionAttributes(MPU_RGN_7, S2RAM_BASE,
(MPU_RGN_SIZE_2K | MPU_RGN_PERM_NOEXEC |
MPU_RGN_PERM_PRV_RW_USR_NO | MPU_RGN_ENABLE));
//
// Need to clear the NVIC fault status register to make sure there is no
// status hanging around from a previous program.
//
faultStatus = HWREG(NVIC_BASE + NVIC_O_MMSR);
HWREG(NVIC_BASE + NVIC_O_MMSR) = faultStatus;
//
// Enable the MPU & bus fault interrupts.
//
Interrupt_enable(FAULT_MPU);
Interrupt_registerHandler(FAULT_MPU, MPUFaultHandler);
Interrupt_enable(FAULT_BUS);
Interrupt_registerHandler(FAULT_BUS, BUSFaultHandler);
//
// Enable the MPU. This will begin to enforce the memory protection
// regions. The MPU is configured so that when in the hard fault or NMI
// exceptions, a default map will be used. Neither of these should occur
// in this example program.
//
MPU_enable(MPU_CONFIG_HARDFLT_NMI | MPU_CONFIG_PRIV_DEFAULT);
//
// Attempt to write to region 1(code memory). This should cause a
// protection fault due to the fact that this region is read-only.
// These memory locations are chosen only for demonstration purpose.
//
faultCount = 0;
HWREG(S0RAM_BASE + 0x1000U) = 0x12345678U;
//
// Adding NOPs to return execution to any of these NOPs and not the above
// statement which generated fault. This has been done to avoid repeated
// fault generation due to above memory write operation to protected memory.
//
NOP;
NOP;
NOP;
NOP;
//
// Verify that the fault occurred, at the expected address.
//
if((faultCount == 1U) && (faultStatus == 0x82U) &&
(memFaultAdd == (S0RAM_BASE + 0x1000U)))
{
//
// Correct fault has occurred
//
successFlag++;
}
//
// Writing to memory location region 7 which allows r/w in priv mode.
// These memory locations are chosen only for demonstration purpose.
//
faultCount = 0;
tempVal = HWREG(S2RAM_BASE + 0x100U);
HWREG(S2RAM_BASE + 0x100U) = 0x12345678U;
readVal = HWREG(S2RAM_BASE + 0x100U);
if((readVal == 0x12345678U) && (faultCount == 0U))
{
//
// Fault has not occurred
//
successFlag++;
}
//
// Write back the original value.
//
HWREG(S2RAM_BASE + 0x100U) = tempVal;
//
// Writing to memory location region 6 which is read only in priv mode.
// These memory locations are chosen only for demonstration purpose.
//
faultCount = 0;
readVal = HWREG(S2RAM_BASE + 0x900);
HWREG(S2RAM_BASE + 0x900) = 0x87654321;
//
// Adding NOPs to return execution to any of these NOPs and not the above
// statement which generated fault. This has been done to avoid repeated
// fault generation due to above memory write operation to protected memory.
//
NOP;
NOP;
NOP;
NOP;
//
// Verify that the fault occurred, at the expected address.
//
if((faultCount == 1U) && (faultStatus == 0x82U) &&
(memFaultAdd == (S2RAM_BASE + 0x900U)))
{
//
// Correct fault has occurred
//
successFlag++;
}
faultCount = 0U;
//
// Reading from a memory location in region 5. This should generate fault.
// Memory locations are chosen for demonstration purpose only.
//
readVal = HWREG(S2RAM_BASE + 0x1200U);
//
// Adding NOPs to return execution to any of these NOPs and not the above
// statement which generated fault. This has been done to avoid repeated
// fault generation due to above memory read operation to protected memory.
//
NOP;
NOP;
NOP;
NOP;
//
// Verify that the fault occurred, at the expected address.
//
if((faultCount == 1U) && (faultStatus == 0x82U) &&
(memFaultAdd == (S2RAM_BASE + 0x1200U)))
{
//
// Correct fault has occurred
//
successFlag++;
}
faultCount = 0U;
//
// Writing to a memory location in region 5. This should generate fault.
// Memory locations are chosen for demonstration purpose only.
//
HWREG(S2RAM_BASE + 0x1200U) = readVal;
//
// Adding NOPs to return execution to any of these NOPs and not the above
// statement which generated fault. This has been done to avoid repeated
// fault generation due to above memory write operation to protected memory.
//
NOP;
NOP;
NOP;
NOP;
//
// Verify that the fault occurred, at the expected address.
//
if((faultCount == 1U) && (faultStatus == 0x82U) &&
(memFaultAdd == (S2RAM_BASE + 0x1200U)))
{
//
// Correct fault has occurred
//
successFlag++;
}
//
// Disable the MPU, so there are no lingering side effects if another
// program is run.
//
MPU_disable();
if(successFlag == 5U)
{
testStatusGlobal = TEST_PASS;
}
//
// Loop forever.
//
while(1)
{
}
}
//
// MPUFaultHandler - The exception handler for memory management faults,
// which are caused by MPU access violations. This handler will verify the
// cause of the fault and clear the NVIC fault status register.
//
void MPUFaultHandler(void)
{
//
// Preserve the value of the MMAR (the address causing the fault).
// Preserve the fault status register value, then clear it.
//
memFaultAdd = HWREG(NVIC_BASE + NVIC_O_MMFAR);
faultStatus = HWREG(NVIC_BASE + NVIC_O_MMSR);
HWREG(NVIC_BASE + NVIC_O_MMSR) = faultStatus;
//
// Increment a counter to indicate the fault occurred.
//
faultCount++;
//
// Once ISR is executed the execution returns to the instruction that
// caused the fault and this again leads to another fault.
// Updating the return address in the stack so that the handler returns
// to any of the NOP instructions added in the example code.
// This is being done for demonstration purpose only. The application code
// should handle the fault as per requirement.
//
asm(" ldr r0, [sp, #0x18]");
asm(" add r0, r0, #4");
asm(" str r0, [sp, #0x18]");
}
//
// BUSFaultHandler - The exception handler for bus faults. This handler will
// verify the cause of the fault and clear the NVIC fault status register.
//
void BUSFaultHandler(void)
{
//
// Preserve the value of the MMAR (the address causing the fault).
// Preserve the fault status register value, then clear it.
//
busFaultAdd = HWREG(NVIC_BASE + NVIC_O_BFAR);
faultStatus = HWREG(NVIC_BASE + NVIC_O_BFSR);
HWREG(NVIC_BASE + NVIC_O_BFSR) = faultStatus;
//
// Increment a counter to indicate the fault occurred.
//
faultCount++;
//
// Bus fault ISR returns to the instruction that caused the fault and this
// this again leads to another fault. Updating the return address in the
// stack so that the handler returns to the next instruction. Adjust the
// required return address offset as per requirement.
// This is being done for demonstration purpose only. The application code
// should handle the fault as per requirement.
//
asm(" ldr r0, [sp, #0x18]");
asm(" add r0, r0, #4");
asm(" str r0, [sp, #0x18]");
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="ssi_ex1_loopback"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ssi_ex1_loopback.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="ssi_ex2_loopback_udma"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../ssi_ex2_loopback_udma.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,174 @@
//#############################################################################
//
// FILE: ssi_ex1_loopback.c
//
// TITLE: SSI loopback example
//
//! \addtogroup driver_example_cm_list
//! <h1>SSI Loopback example with interrupts</h1>
//!
//! This example showcases how to use SSI to transfer and receive data in
//! loopback mode
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b Configuration:
//! - Frame format : TI mode
//! - Baud rate : 625000
//! - Data width : 12 bits
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b txData - Data transmitted
//! - \b rxData - Data received
//! - \b errCount - Error count
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "cm.h"
uint32_t txData[4], rxData[4];
uint8_t errCount = 0xFF;
void ssiISR(void);
//
// Main
//
void main(void)
{
uint8_t i;
//
// Enable clocks
//
CM_init();
//
// Configure SSI in master mode, baud rate = 62500, dataWidth = 12
//
SSI_setConfig(SSI0_BASE, CM_CLK_FREQ, SSI_FRF_TI, SSI_MODE_MASTER, 625000, 12);
//
// Enable the SSI0 module.
//
SSI_enableModule(SSI0_BASE);
//
// Enable loopback mode
//
SSI_enableLoopback(SSI0_BASE);
//
// Read any residual data from the SSI port. This makes sure the receive
// FIFOs are empty, so we don't read any unwanted junk. This is done here
// because the TI SSI mode is full-duplex, which allows you to send and
// receive at the same time. The SSI_readDataNonBlocking function returns
// "true" when data was returned, and "false" when no data was returned.
// The "non-blocking" function checks if there is any data in the receive
// FIFO and does not "hang" if there isn't.
//
while(SSI_readDataNonBlocking(SSI0_BASE, rxData))
{
}
//
// Enable Rx interrupt
//
SSI_registerInterrupt(INT_SSI0, ssiISR);
SSI_enableInterrupt(SSI0_BASE, SSI_INT_RXFF);
//
// Initialize the data to send.
//
txData[0] = 0xAAA;
txData[1] = 0x555;
txData[2] = 0x333;
txData[3] = 0xCCC;
//
// Send data.
//
for(i = 0; i < 4; i++)
{
SSI_writeData(SSI0_BASE, txData[i]);
}
//
// Loop forever. Optional
//
while(1);
}
void ssiISR(void)
{
uint8_t i;
errCount = 0;
//
// Clear the SSI Rx interrupt flag
//
SSI_clearInterruptStatus(SSI0_BASE, SSI_INT_RXFF);
for(i = 0; i < 4; i++)
{
//
// Receive the data using the "blocking" function. This function
// will wait until there is data in the receive FIFO before returning.
//
SSI_readData(SSI0_BASE, &rxData[i]);
//
// Mask off the unwanted bits (Datawidth = 12)
//
rxData[i] = rxData[i] & 0xFFF;
//
// Check the received data
//
if(rxData[i] != txData[i])
{
errCount++;
}
}
}
@@ -0,0 +1,224 @@
//#############################################################################
//
// FILE: ssi_ex2_loopback_udma.c
//
// TITLE: SSI loopback example
//
//! \addtogroup driver_example_cm_list
//! <h1>SSI Loopback example with UDMA</h1>
//!
//! This example showcases how to use UDMA with SSI to transfer and receive data
//!
//! This configures the SSI in loopback mode and sends and receives data for
//! infinite time.
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b Configuration:
//! - Frame format : TI mode
//! - Baud rate : 625000
//! - Data width : 16 bits
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b TxData - Data transmitted
//! - \b RxData - Data received
//! - \b errCount - Error count
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include "cm.h"
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
//
// Initialize the data arrays
//
uint16_t TxData[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
uint16_t RxData[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
void ConfigureSSI(void)
{
uint32_t data;
//
// Configure SSI in master mode, baud rate = 62500, dataWidth = 16
//
SSI_setConfig(SSI0_BASE, CM_CLK_FREQ, SSI_FRF_TI, SSI_MODE_MASTER, 625000, 16);
//
// Enable the SSI0 module.
//
SSI_enableModule(SSI0_BASE);
//
// Enable loopback mode
//
SSI_enableLoopback(SSI0_BASE);
//
// Read any residual data from the SSI port. This makes sure the receive
// FIFOs are empty, so we don't read any unwanted junk. This is done here
// because the TI SSI mode is full-duplex, which allows you to send and
// receive at the same time. The SSI_readDataNonBlocking function returns
// "true" when data was returned, and "false" when no data was returned.
// The "non-blocking" function checks if there is any data in the receive
// FIFO and does not "hang" if there isn't.
//
while(SSI_readDataNonBlocking(SSI0_BASE, &data))
{
}
}
void ConfigureDMA(uint16_t* TxDma, uint16_t* RxDma, uint8_t size)
{
//
// Enable DMA for Tx snd Rx events
//
SSI_enableDMA(SSI0_BASE, SSI_DMA_TX | SSI_DMA_RX);
//
// Enable UDMA
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Put the attributes in a known state for the uDMA software channel.
// These should already be disabled by default.
//
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_SSI0_TX, UDMA_CH_ATTR_ALL);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_SSI0_RX, UDMA_CH_ATTR_ALL);
//
// Configure the control parameters for the SSI TX channels
// Tx channel will be used to transfer data from the buffer to the SSI Data
// register.
// Data size = 16
// Source address increment = 16 (data to be read from 16-bit buffer)
// Destination address increment = 0 (data to be copied to a single address location)
//
// The arbitration size will be set to 4, which causes the uDMA controller
// to rearbitrate after 8 items are transferred. This keeps this channel
// from hogging the uDMA controller once the transfer is started, and allows
// other channels cycles if they are higher priority.
//
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_SSI0_TX | UDMA_PRI_SELECT),
(UDMA_SIZE_16 | UDMA_SRC_INC_16 | UDMA_DST_INC_NONE
| UDMA_ARB_1));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_SSI0_TX | UDMA_PRI_SELECT),
TxDma, (void *)(SSI0_BASE + SSI_O_DR), UDMA_MODE_BASIC,
size);
//
// Configure the control parameters for the SSI RX channel.
// Rx channel will be used to transfer data from the SSI Data register to
// the buffer.
//
// Data size = 16
// Source address increment = 0 (data to be read from a single address location)
// Destination address increment = 0 (data to be copied to a 16-bit buffer)
//
// The arbitration size will be set to 4, which causes the uDMA controller
// to rearbitrate after 8 items are transferred. This keeps this channel
// from hogging the uDMA controller once the transfer is started, and allows
// other channels cycles if they are higher priority.
//
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_SSI0_RX | UDMA_PRI_SELECT),
(UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16
| UDMA_ARB_1));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_SSI0_RX | UDMA_PRI_SELECT),
(void *)(SSI0_BASE + SSI_O_DR), RxDma, UDMA_MODE_BASIC,
size);
}
//
// Main
//
void main(void)
{
uint8_t i;
uint8_t errCount = 0;
//
// Enable clocks
//
CM_init();
ConfigureSSI();
ConfigureDMA(TxData, RxData, 16);
//
// Enable the UDMA channels
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_SSI0_RX);
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_SSI0_TX);
//
// Wait until the complete transfer is done
//
while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_SSI0_TX));
while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_SSI0_RX));
//
// Check the receicved data
//
for(i = 0; i < 16; i++)
{
if(TxData[i] != RxData[i])
{
errCount++;
}
}
//
// Loop forever. Optional
//
while(1);
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="systick_ex1_interrupt"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../systick_ex1_interrupt.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,96 @@
//#############################################################################
//
// FILE: systick_ex1_interrupt.c
//
// TITLE: SysTick interrupt example
//
//! \addtogroup driver_example_cm_list
//! <h1>Systick interrupt example</h1>
//!
//! This example showcases how to use configure Systick interrupt. It increments
//! a counter every time the SysTick interrupt is asserted
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b isrCount - ISR counter
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "systick.h"
uint32_t isrCount = 0;
void sysTickHandler(void)
{
isrCount++;
}
//
// Main
//
void main(void)
{
//
// Register Systick interrupt
//
SYSTICK_registerInterruptHandler(sysTickHandler);
//
// Set timer period as 100 ticks
//
SYSTICK_setPeriod(100);
//
// Enable counter
//
SYSTICK_enableCounter();
//
// Loop forever
//
while(1);
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --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 --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="timer_ex1_cputimers"
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} -mv7M4 --define=DEBUG --float_support=none --define=ccs --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --define=ccs --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="../timer_ex1_cputimers.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,272 @@
//#############################################################################
//
// FILE: timer_ex1_cputimers.c
//
// TITLE: CPU Timers Example
//
//! \addtogroup driver_example_cm_list
//! <h1> CPU Timers </h1>
//!
//! This example configures CPU Timer0, 1, and 2 and increments
//! a counter each time the timer asserts an interrupt.
//!
//! Before running this example, please run the cm_common_config_c28x Example
//! from the c28x folder. It will initialize the clock and configure the GPIOs.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - cpuTimer0IntCount
//! - cpuTimer1IntCount
//! - cpuTimer2IntCount
//!
//
//#############################################################################
//
//
//
// 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 "driverlib_cm.h"
#include "cm.h"
//
// Globals
//
uint16_t cpuTimer0IntCount;
uint16_t cpuTimer1IntCount;
uint16_t cpuTimer2IntCount;
//
// Function Prototypes
//
__interrupt void cpuTimer0ISR(void);
__interrupt void cpuTimer1ISR(void);
__interrupt void cpuTimer2ISR(void);
void initCPUTimers(void);
void configCPUTimer(uint32_t, uint32_t);
//
// Main
//
void main(void)
{
//
// Initializes device clock and peripherals
//
CM_init();
//
// ISRs for each CPU Timer interrupt
//
Interrupt_registerHandler(INT_TIMER0, &cpuTimer0ISR);
Interrupt_registerHandler(INT_TIMER1, &cpuTimer1ISR);
Interrupt_registerHandler(INT_TIMER2, &cpuTimer2ISR);
//
// Initializes the Device Peripheral. For this example, only initialize the
// Cpu Timers.
//
initCPUTimers();
//
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 1 second Period (in uSeconds)
//
configCPUTimer(CPUTIMER0_BASE, 1000000);
configCPUTimer(CPUTIMER1_BASE, 1000000);
configCPUTimer(CPUTIMER2_BASE, 1000000);
//
// 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);
CPUTimer_enableInterrupt(CPUTIMER1_BASE);
CPUTimer_enableInterrupt(CPUTIMER2_BASE);
//
// Enables CPU int1, int13, and int14 which are connected to CPU-Timer 0,
// CPU-Timer 1, and CPU-Timer 2 respectively.
// Enable TINT0 in the PIE: Group 1 interrupt 7
//
Interrupt_enable(INT_TIMER0);
Interrupt_enable(INT_TIMER1);
Interrupt_enable(INT_TIMER2);
//
// Starts CPU-Timer 0, CPU-Timer 1, and CPU-Timer 2.
//
CPUTimer_startTimer(CPUTIMER0_BASE);
CPUTimer_startTimer(CPUTIMER1_BASE);
CPUTimer_startTimer(CPUTIMER2_BASE);
//
// IDLE loop. Just sit and loop forever (optional)
//
while(1)
{
}
}
//
// 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);
CPUTimer_setPeriod(CPUTIMER1_BASE, 0xFFFFFFFF);
CPUTimer_setPeriod(CPUTIMER2_BASE, 0xFFFFFFFF);
//
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT)
//
CPUTimer_setPreScaler(CPUTIMER0_BASE, 0);
CPUTimer_setPreScaler(CPUTIMER1_BASE, 0);
CPUTimer_setPreScaler(CPUTIMER2_BASE, 0);
//
// Make sure timer is stopped
//
CPUTimer_stopTimer(CPUTIMER0_BASE);
CPUTimer_stopTimer(CPUTIMER1_BASE);
CPUTimer_stopTimer(CPUTIMER2_BASE);
//
// Reload all counter register with period value
//
CPUTimer_reloadTimerCounter(CPUTIMER0_BASE);
CPUTimer_reloadTimerCounter(CPUTIMER1_BASE);
CPUTimer_reloadTimerCounter(CPUTIMER2_BASE);
//
// Reset interrupt counter
//
cpuTimer0IntCount = 0;
cpuTimer1IntCount = 0;
cpuTimer2IntCount = 0;
}
//
// configCPUTimer - This function initializes the selected timer to the
// period specified by the "freq" and "period" variables. The "freq" is
// CPU frequency in Hz and the period in uSeconds. The timer is held in
// the stopped state after configuration.
//
void
configCPUTimer(uint32_t cpuTimer, uint32_t period)
{
uint32_t temp, freq = CM_CLK_FREQ;
//
// Initialize timer period:
//
temp = ((freq / 1000000) * period);
CPUTimer_setPeriod(cpuTimer, temp - 1);
//
// 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);
//
// Resets interrupt counters for the three cpuTimers
//
if (cpuTimer == CPUTIMER0_BASE)
{
cpuTimer0IntCount = 0;
}
else if(cpuTimer == CPUTIMER1_BASE)
{
cpuTimer1IntCount = 0;
}
else if(cpuTimer == CPUTIMER2_BASE)
{
cpuTimer2IntCount = 0;
}
}
//
// cpuTimer0ISR - Counter for CpuTimer0
//
__interrupt void
cpuTimer0ISR(void)
{
cpuTimer0IntCount++;
}
//
// cpuTimer1ISR - Counter for CpuTimer1
//
__interrupt void
cpuTimer1ISR(void)
{
cpuTimer1IntCount++;
}
//
// cpuTimer2ISR - Counter for CpuTimer2
//
__interrupt void
cpuTimer2ISR(void)
{
cpuTimer2IntCount++;
}
//
// End of File
//
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="uart_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=UART --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=UART --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="uart_ex1_echoback"
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="../uart_ex1_echoback.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="uart_ex2_loopback_udma"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225 " linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../uart_ex2_loopback_udma.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,181 @@
//#############################################################################
//
// FILE: UART_ex1_echoback.c
//
// TITLE: UART echoback example.
//
//! \addtogroup driver_example_cm_list
//! <h1>UART Echoback</h1>
//!
//! This test receives and echo-backs data through the UART0 port.
//!
//! A terminal such as 'putty' can be used to view the data from
//! the CM-UART and to send information to the CM-UART. Characters
//! received by the CM-UART port are sent back to the host.
//!
//! \b Running \b the \b Application
//! Open a COM port with the following settings using a terminal:
//! - Find correct COM port
//! - Bits per second = 115200
//! - Data Bits = 8
//! - Parity = None
//! - Stop Bits = 1
//! - Hardware Control = None
//!
//! The program will print out a greeting and then ask you to
//! enter a character which it will echo back to the terminal.
//!
//! \b Watch \b Variables \n
//! - None
//!
//! \b External \b Connections \n
//! Connect the UART0 port to a PC via a transceiver and cable.
//! - GPIO85 is UART0RX/CMUARTRXA(Connect to Pin3, PC-TX, of serial DB9 cable)
//! - GPIO84 is UART0TX/CMUARTTXA(Connect to Pin2, PC-RX, of serial DB9 cable)
//!
//! \note The pin muxing for the UART0 port needs to be done by the master
//! CPU1. The common configuration example provided in the C28x folder can be
//! used for making GPIO85 as the UART Rx pin and GPIO84 as the UART Tx pin.
//
//#############################################################################
//
//
//
// 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 <stdint.h>
#include <stdbool.h>
#include "cm.h"
//
// Defines
//
#define NUM_UART_DATA 4
//
// Function Prototypes
//
__interrupt void UART_RX_IntHandler(void);
//
// Main
//
void main(void)
{
//
// disable WD, enable peripheral clocks.
//
CM_init();
//
// Configure UART0 for echoback.Set up to transfer data at 115200 baud.
//
UART_setConfig(UART0_BASE,UART_CLK_FREQ , 115200,(UART_CONFIG_WLEN_8 |
UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
//
// Put a character to show start of example. This will display on the
// terminal.
//
UART_writeChar(UART0_BASE, '!');
//
// Enable the UART0 interrupt on the processor (NVIC).
//
UART_registerInterrupt(INT_UART0,UART_RX_IntHandler);
//
// FIFO enable
//
UART_enableFIFO(UART0_BASE);
//
// FIFO interrupt levels are set to generate an interrupt
// when the TX FIFO is less than or equal to 7/8 empty and the
// RX FIFO is greater than or equal to 1/8 full.
//
UART_setFIFOLevel(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
//
// FIFO receive interrupt configuration
//
UART_clearInterruptStatus(UART0_BASE,UART_INT_RX | UART_INT_RT);
UART_enableInterrupt(UART0_BASE,UART_INT_RX);
//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}
__interrupt void UART_RX_IntHandler(void)
{
uint32_t ui32Status;
//
// Get the interrupt status.
//
ui32Status = UART_getInterruptStatus(UART0_BASE, UART_RAW_INT);
//
// Clear the asserted interrupts.
//
UART_clearInterruptStatus(UART0_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
while(UART_isDataAvailable(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
UART_writeCharNonBlocking(UART0_BASE,
UART_readCharNonBlocking(UART0_BASE));
}
}
//
// End of File
//
@@ -0,0 +1,223 @@
//#############################################################################
//
// FILE: uart_ex2_loopback_udma.c
//
// TITLE: UART loopback example
//
//! \addtogroup driver_example_cm_list
//! <h1>UART Loopback example with UDMA</h1>
//!
//! This example showcases how to use UDMA with UART to transfer and receive data
//!
//! This configures the UART in loopback mode and sends and receives data for
//! infinite time.
//! cm_common_config_c28x example needs to be run on C28x1 before running this
//! example on the CM core
//!
//! \b Configuration:
//! - Find correct COM port
//! - Bits per second = 115200
//! - Data Bits = 8
//! - Parity = None
//! - Stop Bits = 1
//! - Hardware Control = None
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b TxData - Data transmitted
//! - \b RxData - Data received
//! - \b errCount - Error count
//!
//
//#############################################################################
//
//
//
// 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.
// $
//#############################################################################
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "cm.h"
#include "driverlib_cm.h"
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
//
// Initialize the data arrays
//
uint8_t TxData[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
uint8_t RxData[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
void ConfigureUART(void)
{
//
// Configure UART with baud rate = 115200, dataWidth = 8
//
UART_setConfig(UART0_BASE,UART_CLK_FREQ , 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Enable the UART0 module.
//
UART_enableModule(UART0_BASE);
//
// Enable loopback mode
//
UART_enableLoopback(UART0_BASE);
}
void ConfigureDMA(uint8_t* TxDma, uint8_t* RxDma, uint8_t size)
{
//
// Enable DMA for Tx snd Rx events
//
UART_enableDMA(UART0_BASE,UART_DMA_TX |UART_DMA_RX);
//
// Enable UDMA
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Put the attributes in a known state for the uDMA software channel.
// These should already be disabled by default.
//
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_UART0_TX, UDMA_CH_ATTR_ALL);
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_UART0_RX, UDMA_CH_ATTR_ALL);
//
// Configure the control parameters for the UART TX channels
// Tx channel will be used to transfer data from the buffer to the UART Data
// register.
// Data size = 8
// Source address increment = 8 (data to be read from 8-bit buffer)
// Destination address increment = 0 (data to be copied to a single address location)
//
// The arbitration size will be set to 1, which causes the uDMA controller
// to re-arbitrate after 1 item is transferred.
//
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_UART0_TX | UDMA_PRI_SELECT),
(UDMA_SIZE_8 | UDMA_SRC_INC_8 | UDMA_DST_INC_NONE
| UDMA_ARB_1));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_UART0_TX | UDMA_PRI_SELECT),
TxDma, (void *)(UART0_BASE + UART_O_DR), UDMA_MODE_BASIC,
size);
//
// Configure the control parameters for the UART RX channel.
// Rx channel will be used to transfer data from the UART Data register to
// the buffer.
//
// Data size = 8
// Source address increment = 0 (data to be read from a single address location)
// Destination address increment = 8 (data to be copied to a 8-bit buffer)
//
// The arbitration size will be set to 1, which causes the uDMA controller
// to re arbitrate after 1 item is transferred.
//
UDMA_setChannelControlParams(UDMA_BASE, (UDMA_CHANNEL_UART0_RX | UDMA_PRI_SELECT),
(UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8
| UDMA_ARB_1));
UDMA_setChannelTransferParams(UDMA_BASE, (UDMA_CHANNEL_UART0_RX | UDMA_PRI_SELECT),
(void *)(UART0_BASE + UART_O_DR), RxDma, UDMA_MODE_BASIC,
size);
}
//
// Main
//
void main(void)
{
uint8_t i;
uint8_t errCount = 0;
//
// Disable WD, enable peripheral clocks.
//
CM_init();
//
// Configure the UART
//
ConfigureUART();
//
// Configure the UDMA to read/write to the TX/RX buffers
//
ConfigureDMA(TxData, RxData, 16);
//
// Enable the UDMA channels
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_UART0_RX);
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_UART0_TX);
//
// Wait until the complete transfer is done
//
while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_TX));
while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_UART0_RX));
//
// Check the received data
//
for(i = 0; i < 16; i++)
{
if(TxData[i] != RxData[i])
{
errCount++;
}
}
//
// Loop forever. Optional
//
while(1);
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="cm_common_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 --float_support=fpu64 --tmu_support=tmu0 --define=DEBUG --define=CPU1 --define RAM --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 --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="udma_ex1_software_trigger"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../udma_ex1_software_trigger.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="udma_ex2_scatter_gather_mode"
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} -mv7M4 --define=DEBUG --float_support=none --diag_warning=225" linkerBuildOptions="--stack_size=512 --heap_size=1024 --library=libc.a" />
<configuration name="CM_FLASH" compilerBuildOptions="--opt_level=off -I${PROJECT_ROOT}/device -I${C2000WARE_DLIB_ROOT} --define=_FLASH -mv7M4 --define=DEBUG --float_support=none --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="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
<file action="copy" path="../udma_ex2_scatter_gather_mode.c" targetDirectory="" />
</project>
</projectSpec>
@@ -0,0 +1,131 @@
//#############################################################################
//
// FILE: udma_ex1_software_trigger.c
//
// TITLE: uDMA RAM to RAM transfer using software trigger
//
//! \addtogroup driver_example_cm_list
//! <h1>uDMA RAM to RAM transfer</h1>
//!
//! This example showcases how to use uDMA to transfer data from one RAM
//! location to another using software trigger.
//!
//! This configures the UDMA in AUTO mode and transfers 32-bit words from
//! one location to another using Channel 30. Software trigger is being used
//! here. Once the transfer is completed, a check of the validity of the data
//! will be performed in the uDMA ISR.
//!
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b srcData - Source
//! - \b destData - Destination
//! - \b errCount - Error count
//!
//
//#############################################################################
#include "cm.h"
#define TRANSFER_SIZE 20
void udmaISR(void);
uint32_t srcData[TRANSFER_SIZE], destData[TRANSFER_SIZE];
uint8_t errCount = 0xFF;
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
//
// Main
//
void main(void)
{
int i;
//
// Enable peripheral clocks
//
CM_init();
//
// Initialize the source and destination arrays
//
for(i = 0; i < TRANSFER_SIZE; i++)
{
srcData[i] = i;
destData[i] = 0;
}
//
// Enable the uDMA controller.
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Enable interrupts from the uDMA software channel.
//
UDMA_registerInterrupt(UDMA_SW_INT, udmaISR);
//
// Put the attributes in a known state for the uDMA software channel.
// These should already be disabled by default.
//
UDMA_disableChannelAttribute(UDMA_BASE, UDMA_CHANNEL_SW_CH30, UDMA_CH_ATTR_ALL);
//
// Configure the control parameters for the SW channel. The SW channel
// will be used to transfer between two memory buffers, 32 bits at a time.
// Therefore the data size is 32 bits, and the address increment is 32 bits
// for both source and destination. The arbitration size will be set to 4,
// which causes the uDMA controller to rearbitrate after 8 items are
// transferred. This keeps this channel from hogging the uDMA controller
// once the transfer is started, and allows other channels cycles if they
// are higher priority.
//
UDMA_setChannelControlParams(UDMA_BASE, UDMA_CHANNEL_SW_CH30,
UDMA_SIZE_32 | UDMA_SRC_INC_32 | UDMA_DST_INC_32
| UDMA_ARB_4);
//
// Set up the transfer parameters for the software channel. This will
// configure the transfer buffers and the transfer size. Auto mode must be
// used for software transfers.
//
UDMA_setChannelTransferParams(UDMA_BASE, UDMA_CHANNEL_SW_CH30,
srcData, destData, UDMA_MODE_AUTO, TRANSFER_SIZE);
//
// Now the software channel is primed to start a transfer. The channel
// must be enabled. For software based transfers, a request must be
// issued. After this, the uDMA memory transfer begins.
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_SW_CH30);
UDMA_requestSoftwareTransfer(UDMA_BASE, UDMA_CHANNEL_SW_CH30);
while(1);
}
__interrupt void udmaISR(void)
{
int i;
errCount = 0;
for(i = 0; i < TRANSFER_SIZE; i++)
{
if(srcData[i] != destData[i])
{
errCount++;
}
}
}
@@ -0,0 +1,159 @@
//#############################################################################
//
// FILE: udma_ex2_scatter_gather_mode.c
//
// TITLE: uDMA RAM to RAM transfer using scatter gather mode
//
//! \addtogroup driver_example_cm_list
//! <h1>uDMA RAM to RAM transfer</h1>
//!
//! This example showcases how to configure uDMA in memory scatter-gather mode
//! and transfer data from varied locations in memory rather than a set of
//! contiguous locations in a memory buffer.
//!
//! This example creates an array of structs of length 20. The struct includes
//! a header element and a data element, each of length 10. The UDMA is
//! configured to tranfer only the data element from all the 20 data packets.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b packets - 'data' element contains the actual data to be transferred
//! - \b consolidatedData - Destination buffer where the data is transferred to
//! - \b errCount - Error count
//!
//
//#############################################################################
#include "cm.h"
#include "stdlib.h"
#pragma DATA_ALIGN(ucControlTable, 1024)
UDMA_ControlTable ucControlTable[64];
#define DATA_LENGTH 10
#define HEADER_LENGTH 10
#define TOTAL_NO_OF_PACKETS 20
//
// Define a data packet struct that includes a header and data.
//
typedef struct
{
uint32_t header[HEADER_LENGTH];
uint32_t data[DATA_LENGTH];
}DataPacket_t;
//
// Create an array of data packet struct of length 5
//
DataPacket_t packets[TOTAL_NO_OF_PACKETS];
//
// Memory buffer where the uDMA copies the data
//
uint32_t consolidatedData[TOTAL_NO_OF_PACKETS * DATA_LENGTH];
//
// uDMA task list used for scatter gather mode
//
UDMA_ControlTable tasklist[TOTAL_NO_OF_PACKETS];
uint32_t errCount;
//
// Main
//
void main(void)
{
uint32_t i,j;
//
// Enable peripheral clocks
//
CM_init();
//
// Initialize the data package with dummy data
//
for(i = 0; i < TOTAL_NO_OF_PACKETS; i++)
{
//
// Header is filled with random integers and the data is filled
// with integers in sequence to check at the end.
//
for(j = 0; j < HEADER_LENGTH; j++)
{
packets[i].header[j] = rand();
}
for(j = 0; j < DATA_LENGTH; j++)
{
packets[i].data[j] = (i * DATA_LENGTH) + j;
}
}
//
// Enable the uDMA controller.
//
UDMA_enable(UDMA_BASE);
//
// Point at the control table to use for channel control structures.
//
UDMA_setControlBase(UDMA_BASE, ucControlTable);
//
// Configure the task list
// Each task is configured for transferring the data element of a single
// data packet.
// Item size, source address increment, destination address increment is
// set as 32 and the data is collected in the memory buffer consolidatedData
// in a continuous manner
//
for(i = 0; i < TOTAL_NO_OF_PACKETS; i++)
{
UDMA_ControlTable task =
UDMA_TASK_STRUCT_ENTRY(DATA_LENGTH, // Transfer count
UDMA_SIZE_32, // Item size
UDMA_SRC_INC_32, // Src Increment
packets[i].data, // Src Address
UDMA_DST_INC_32, // Dst Increment
&consolidatedData[i * DATA_LENGTH], // Dst Address
UDMA_ARB_8, // Arbitration
UDMA_MODE_MEM_SCATTER_GATHER); // Transfer Mode
memcpy(&tasklist[i], &task, sizeof(task));
}
//
// Configure channel 0 for memory scatter gather mode.
//
UDMA_setChannelScatterGatherMode(UDMA_BASE, UDMA_CHANNEL_30,
TOTAL_NO_OF_PACKETS, tasklist, false);
//
// Now the software channel is primed to start a transfer. The channel
// must be enabled. For software based transfers, a request must be
// issued. After this, the uDMA memory transfer begins.
//
UDMA_enableChannel(UDMA_BASE, UDMA_CHANNEL_30);
UDMA_requestSoftwareTransfer(UDMA_BASE, UDMA_CHANNEL_30);
//
// Wait until the transfer is complete
//
while(UDMA_isChannelEnabled(UDMA_BASE, UDMA_CHANNEL_30));
//
// Check the transferred data
//
for(i = 0; i < TOTAL_NO_OF_PACKETS * DATA_LENGTH; i++)
{
if(consolidatedData[i] != i)
{
errCount++;
}
}
while(1);
}
@@ -0,0 +1,25 @@
<projectSpec>
<project
name="usb_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=USB --define=UART --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=USB --define=UART --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,33 @@
<projectSpec>
<project
name="usb_ex1_device_serial_cm"
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} -I${USB_LIB_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} -I${USB_LIB_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" />
<pathVariable name="USB_LIB_ROOT" path="../../../../../../libraries/communications/usb/f2838x/include/" 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_combined_lnk_cm.cmd" targetDirectory="" applicableConfigurations="CM_RAM" />
<file action="copy" path="../../../../../../device_support/f2838x/common/cmd/2838x_FLASH_lnk_shared_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="link" path="../../../../../../libraries/communications/usb/f2838x/lib/usblib_cm.lib" targetDirectory="" />
<file action="copy" path="../usb_ex1_device_serial_cm.c" targetDirectory="" />
<file action="copy" path="../usb_ex1_device_structs.c" targetDirectory="" />
<file action="copy" path="../usb_ex1_device_structs.h" targetDirectory="" />
<file action="copy" path="../usb_hal.h" targetDirectory="" />
<file action="copy" path="../usb_hal.c" targetDirectory="" />
<file action="copy" path="../../../../../../utilities/tools/usb/utils/ustdlib.h" targetDirectory="" />
<file action="copy" path="../../../../../../utilities/tools/usb/utils/ustdlib.c" targetDirectory="" />
<file action="copy" path="../../../../../../device_support/f2838x/common/source/startup_cm.c" targetDirectory="" />
</project>
</projectSpec>
Loaded 100 of 14950 files, more files were not shown because too many files have changed in this diff. Show more