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.

Unexpectedly long execution time for peripheral accesses on C6418

I need to pulse a GPIO very quickly. The operation is taking much much longer than I expected, so I put in reads to the timer as follows:

    timBeg = *((uint32_t*)TIMER_CNT_0);
    *((uint32_t*)GPIO_GPVAL) |= 0x00000020;
    *((uint32_t*)GPIO_GPVAL) &= ~0x00000020;
    timEnd = *((uint32_t*)TIMER_CNT_0);

I'm getting timer delta counts of about 23. Since the timer clock input on the C6418 is CPUCLK/8, this means these operations are taking 8*23 = 184 CPUCLK cycles!

This seems excessive. I've tried globally disabling interrupts prior to the code and the readings are similar. Any ideas on why this time is so long would be appreciated.

 

--Randy

 

PS: CPUCLK is 500 MHz in this system.

  • Config bus reads are slow. As I recall, they can be on the order of 20+ cycles each, and may be more. Writes take around the same time as reads, but several writes in a row can appear to be very fast because they will go into a write buffer. If the buffer (just my memory, but I think 7 words deep) gets filled, then later writes will stall until there is space in the buffer, or if a read occurs then all writes have to complete before the read will complete.

    What timer count difference do you get if you comment out the two GPIO lines?

    Your timer measurements are finding the time it takes to do 3 reads and 2 writes. But this means you are measuring an average of over 30 cycles, and that sounds high even for the slow Config bus.

    The fastest way to speed up the code is to maintain a shadow memory location that keeps the value at GPIO_GPVAL. You can modify that memory location and write it to GPIO_GPVAL. This way all you do is two writes to set a bit high then low. I think that writing old values to GPIO_GPVAL bits that are inputs will be immediately replaced by the value at the pin, so later reads will not be corrupted by doing this.

    Another choice would be to read GPIO_GPVAL to a temp location, set the bit in the temp loc, write it out, clear the bit in the temp loc and write it out. This would save one read from between the writes and would give you the same pulse width as the "fastest way" above.

  • Hi Randy,

    Thank you for your response and great suggestions. I tried the "comment out the two GPIO lines" and got timer deltas of about 5 or 6. So apparently your slow config bus read was the issue. Thanks!

     

    --Randy