Other Parts Discussed in Thread: SYSBIOS
Hi all,
I have a piece of code that I want to run periodically on my C6678EVM. It is very important for me to control the time it takes this code. The problem is that I have observed that, sometimes, it takes longer than usual. I have managed to reduce the code to the minimum to try to find the problem. Now, it looks like this:
#include <stdio.h>
#include <ti/sysbios/BIOS.h>
#include <ti/csl/csl_chip.h>
uint32_t guiProfileMin=0xFFFFFFFF;
uint32_t guiProfileMax=0;
uint64_t guiProfileTotal=0;
uint32_t guiProfileNumIter=0;
uint32_t guiProfileAvg=0;
#define NUM_MEASURES 100000000
void MyFunction()
{
uint64_t uiTimeOrigin = 0;
uint32_t uiTimeSpent = 0;
TSCH = 0;
TSCL = 0;
while (guiProfileNumIter < NUM_MEASURES)
{
uiTimeOrigin = _itoll(TSCH, TSCL); /* TIME 1 */
// Future additional code here
uiTimeSpent = (uint32_t)(_itoll(TSCH, TSCL) - uiTimeOrigin); /* TIME 2 */
// Update min, max and avg
if (uiTimeSpent < guiProfileMin)
guiProfileMin = uiTimeSpent;
if (uiTimeSpent > guiProfileMax)
guiProfileMax = uiTimeSpent;
guiProfileTotal += uiTimeSpent;
guiProfileNumIter ++;
guiProfileAvg = (uint32_t)(guiProfileTotal / guiProfileNumIter);
}
printf("guiProfileMin: %4d\n", guiProfileMin);
printf("guiProfileMax: %4d\n", guiProfileMax);
printf("guiProfileAvg: %4d\n", guiProfileAvg);
}
void core3_taskMain(void)
{
MyFunction();
}
int main()
{
BIOS_start ();
}
Basically, I measure the time between TIME1 and TIME2. In this code, it should be near 0 cycles (0 ns), since there is no code between those points. The problem is that, after running it in CCCS, I am getting the following output:
[C66xx_0] guiProfileMin: 8
[C66xx_0] guiProfileMax: 331
[C66xx_0] guiProfileAvg: 8
This means that, although in most of the iteration the time lapse is 8 ns (ok), sometimes it takes up to 331 ns between those points. Am I missing something? I think it should take always the same time...
The only idea that comes to my mind is that some kind of Task Scheduler is running periodically, affecting the times. If it was the reason, how could I disable it?
By the way, I am using bios_6_33_06_50
Best regards,
Alejandro