Tool/software: Code Composer Studio
Hi,
I'm observing that my MCU is taking more execution cycles per assembly instruction than it is supposed to take. My core clock frequency is set 200MHz. It is taking about 24 cycles to execute a single instruction. Function which I'm analysing is in RAM as well. It did improve a bit when I copied it from FLASH to RAM but I still think these are a lot of clock cycles for a single MOV instruction. MCU was taking about 13 cycles per instruction when core frequency was 80MHz. It appears to have become worse as I increase the clock frequency. Help would be appreciated.
Regards,
Nouman
Following is my main.c code:
/* USER CODE BEGIN (0) */
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "sys_main.h"
#define CRC_GENERATOR (unsigned short) 0x1021
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
static void flash_delay (void)
{
//const uint32_t start_time = TimerValueGet (TIMER0_BASE, TIMER_A);
_delay_cycles (12000000);
//return TimerValueGet (TIMER0_BASE, TIMER_A) - start_time;
}
__attribute__((ramfunc))
static void sram_delay (void)
{
// const uint32_t start_time = TimerValueGet (TIMER0_BASE, TIMER_A);
_delay_cycles (12000000);
// return TimerValueGet (TIMER0_BASE, TIMER_A) - start_time;
}
__attribute__((ramfunc))
uint16_t CRC_Calculator(uint16_t *DataWord)
{
uint8_t i, j;
uint16_t CRC = 0;
for (j=0; j<3; j++)
{
if(j==0) CRC ^= ~DataWord[j];
else CRC ^= DataWord[j];
for (i=0; i<16; i++)
{
if(CRC & 0x8000) CRC = (CRC<<1)^CRC_GENERATOR;
else CRC <<= 1;
}
}
return CRC;
}
uint16_t DataArray[3] = {0xAAAA, 0xBBBB, 0xCCCC};
uint16_t CRC_result;
uint32_t shutdown = 0, cleartrip = 0;
uint32_t T1, T2;
uint8 rx_data[9] = {0};
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
__delay_cycles(5000000); // Every 500 ms (aprox)
// Initializations
mibspiInit();
gioInit();
rtiInit();
canInit();
hetInit();
// Trips_Init();
// Transmit NODE ID
TRANSMIT_NODEID();
rtiStartCounter(rtiCOUNTER_BLOCK0);
while(1){
sram_delay(); // Every 500 ms (aprox)
TRANSMIT_NODEID();
T1 = rtiREG1->CNT[0].FRCx;
CRC_result = CRC_Calculator(DataArray);
T2 = rtiREG1->CNT[0].FRCx - T1;
}
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
/* USER CODE END */