This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: The code run too long for memorycopy code.

Part Number: TMS320F28388D

Hi Expert,

My customer run the below code and find take up about 4us, which they think it is too long, 

Could you take a check if it make sense to take so long time? thanks. 

//*************************************************************************************************
//
// ESC_readBlockISR
//
//*************************************************************************************************
void ESC_readBlockISR(ESCMEM_ADDR *pData, uint16_t address, uint16_t len)
{
    uint16_t i;
    //
    // Create pointer to ESC Address
    //
    //const void * escSource = (void *)(ESC_BASE + (uint32_t)(address >> 1U));

    uint32_t Addr = ESC_BASE + (uint32_t)(address >> 1U);

    //
    // Copy ESC data to buffer. Convert lengths to words.
    //
    //memcpy(pData, escSource, (size_t)((len + 1U) >> 1U));

    for( i = 0; i< (len >> 1);i++)
    {
        pData[ i ] = *(ESCMEM_ADDR*)( Addr + i );
    }

    //
    // Determine if length (in bytes) is even or odd
    // (No action on even)
    //
    if((len & 0x1U) == 0x1U)
    {
        //
        // Odd Length
        //

        //
        // Clear extra byte in buffer
        //
        pData[((len - 1U) >> 1U)] = (pData[((len - 1U) >> 1U)] & ESC_M_LSB);
    }
}

They do a little modification of memory copy function as below and view the assembly code, still take about 4us. any thing wrong ?

        ESC_readBlockISR():
0ab766:   B2BD        MOVL         *SP++, XAR1
174         uint32_t Addr = ESC_BASE + (uint32_t)(address >> 1U);
0ab767:   8F450000    MOVL         XAR5, #0x050000
0ab769:   8BA5        MOVL         XAR1, @XAR5
0ab76a:   FFC0        LSR          AL, 1
0ab76b:   80A9        MOVZ         AR7, @AL
167     {
0ab76c:   5DA8        MOVZ         AR5, @AH
174         uint32_t Addr = ESC_BASE + (uint32_t)(address >> 1U);
0ab76d:   B2A9        MOVL         @ACC, XAR1
0ab76e:   0DA7        ADDU         ACC, @AR7
0ab76f:   8BA9        MOVL         XAR1, @ACC
181         for( i = 0; i< (len >> 1);i++)
0ab770:   CCA5FFFE    AND          AL, @AR5, #0xfffe
0ab772:   610C        SB           $C$L9, EQ
0ab773:   92A5        MOV          AL, @AR5
0ab774:   D000        MOVB         XAR0, #0x0
0ab775:   C5A4        MOVL         XAR7, @XAR4
0ab776:   FFC0        LSR          AL, 1
0ab777:   9CFF        ADDB         AL, #-1
0ab778:   88A9        MOVZ         AR6, @AL
183             pData[ i ] = *(ESCMEM_ADDR*)( Addr + i );
        $C$L8:
0ab779:   9291        MOV          AL, *+XAR1[AR0]
181         for( i = 0; i< (len >> 1);i++)
0ab77a:   D801        ADDB         XAR0, #1
183             pData[ i ] = *(ESCMEM_ADDR*)( Addr + i );
0ab77b:   9687        MOV          *XAR7++, AL
181         for( i = 0; i< (len >> 1);i++)
0ab77c:   000EFFFD    BANZ         -3,AR6--
190         if((len & 0x1U) == 0x1U)
        $C$L9:
0ab77e:   40A5        TBIT         @AR5, #0x0
0ab77f:   6C0A        SB           $C$L10, NTC
199             pData[((len - 1U) >> 1U)] = (pData[((len - 1U) >> 1U)] & ESC_M_LSB);
0ab780:   DD81        SUBB         XAR5, #1
0ab781:   92A5        MOV          AL, @AR5
0ab782:   FFC0        LSR          AL, 1
0ab783:   5DA9        MOVZ         AR5, @AL
0ab784:   A8A9        MOVL         @ACC, XAR4
0ab785:   0DA5        ADDU         ACC, @AR5
0ab786:   8AA9        MOVL         XAR4, @ACC
0ab787:   18C400FF    AND          *+XAR4[0], #0x00ff
        $C$L10:
0ab789:   8BBE        MOVL         XAR1, *--SP
0ab78a:   0006        LRETR        

  • Hi Strong,

    What length (len) value are they passing to this function? I would say the execution time will depend on the length of memory they're reading.

    Best,

    Kevin

  • Hi Kevin,

    length (len) is 26, and actually the function will not run when len is 26. 

      if((len & 0x1U) == 0x1U)

  • Hi Kevin,

    Any update about this issue?

    I run the simple code below and also require about 4.2us. could you help check why it take so long?

    //#############################################################################
    //
    // FILE:   led_ex1_blinky.c
    //
    // TITLE:  LED Blinky Example
    //
    //! \addtogroup bitfield_example_list
    //! <h1> LED Blinky Example </h1>
    //!
    //! This example demonstrates how to blink a LED.
    //!
    //! \b External \b Connections \n
    //!  - None.
    //!
    //! \b Watch \b Variables \n
    //!  - None.
    //!
    //
    //#############################################################################
    //
    //
    // $Copyright:
    // Copyright (C) 2022 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 "f28x_project.h"
    
    
    Uint16 MoveDes=0x010000;
    Uint16 Movesource=0x082000 ;
    
    
    // Defines
    //
    #define DEVICE_GPIO_PIN_LED1    31
     //extern uint32_t RamfuncsRunStart;
    //extern uint32_t RamfuncsLoadStart;
    
    int len=22;
    int address =0;
    
    int test1[26];
    int test2[26];
    
    //
    // Main
    //
    void main(void)
    {
        uint16_t i;
        //
        // Initialize device clock and peripherals
        //
        InitSysCtrl();
    
        //
        // Initialize GPIO and configure the GPIO pin as a push-pull output
        //
        InitGpio();
        GPIO_SetupPinMux(DEVICE_GPIO_PIN_LED1, GPIO_MUX_CPU1, 0);
        GPIO_SetupPinOptions(DEVICE_GPIO_PIN_LED1, GPIO_OUTPUT, GPIO_PUSHPULL);
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts. 
        //
        DINT;
        InitPieCtrl();
        IER = 0x0000;
        IFR = 0x0000;
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        InitPieVectTable();
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    for(i=0;i<26;i++)
    {
        test1[i]=i;
    }
        //
        // Loop Forever
        //
        for(;;)
        {
            //
            // Turn on LED
            //
            GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 0);
    
    //        uint32_t Addr = ESC_BASE + (uint32_t)(address >> 1U);
    //        for( i = 0; i< (len >> 1);i++)
    //        {
    //            pData[ i ] = *(ESCMEM_ADDR*)( Addr + i );
    //        }
    //
           // memcpy(&MoveDes, &Movesource, (size_t)&len);
            for(i=0;i<26;i++)
            {
                test2[i]=test1[i];
            }
            //
            // Delay for a bit.
            //
    //        DELAY_US(500000);
    
            //
            // Turn off LED
            //
            GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 1);
    
    //        //
    //        // Delay for a bit.
    //        //
    //        DELAY_US(500000);
        }
    }
    
    //
    // End of File
    //
    

  • Closing the thread here as it is being discussed offline.