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.

Are there two IPC COUNTERH registers in the TMS320F28377D or is there a race condition

The F2837xD reference manual (SPRUHM8E) section 6.5 (Free Running Counter, p786) states that IPCCOUNTERH is latched on a read of IPCCOUNTERL to avoid a race condition between reading IPCCOUNTERL and IPCCOUNTERH in the event of an IPCCOUNTERL overflow. Figure 6-1 (p784) indicates there is a single set of IPCCOUNTERL and IPCCOUNTERH.

The scheme for reading the 64-bit timer is fine for a single CPU reading the IPC counter registers, but what happens in the event of both CPUs reading the IPC counter registers at the same time in the event of an IPCCOUNTERL overflow?

Here is an example (I am assuming the counter counts upwards):

1. CPU 1 reads IPCCOUNTERL as 0xFFFFFFFF. IPCCOUNTERH is latched as 0xFFFFFFFF

2. IPCCOUNTERL overflows to 0x00000000

3. CPU 2 reads IPCCOUNTERL as 0x00000000. IPCCOUNTERH is latched as 0x00000000

4. CPU 1 reads IPCCOUNTERH as 0x00000000

5. CPU 2 reads IPCCOUNTERH as 0x00000000

Therefore CPU1 has read the 64-bit timer as 0x00000000FFFFFFFF instead of 0xFFFFFFFFFFFFFFFF.

Is my logic correct, or is there a separate IPCCOUNTERH register for each CPU that is latched when that CPU reads IPCCOUNTERL, such that CPU1 reads 0xFFFFFFFFFFFFFFFF and CPU2 reads 0x0000000000000000 regardless of the interleaving of the reads by the two CPUs?

This question seems applicable to the F2837xD and F28M3x series

  • Hi Iain,

    Good question. IPCCOUNTERx are one set of register which are shared by CPU1 and CPU2.  So the issue you just described is valid one but like any other shared resource, if both CPU wants to read these register then some handshake mechanism should be implemented in SW using IPC method to avoid read from other CPU before both the registered are read.

    Regards,

    Vivek Singh

  • Vivek,

    Thanks for confirming my fears. The IPCCOUNTERx registers are rather special due to the side effects of reading IPCCOUNTERL.

    I was tempted to create a mutex using either the HW semaphores (PUMP_REQUEST or CLK_SEM) or the IPC flags, but I think the lowest overhead will be to read the counter repeatedly until the top 32 bits are constant.

    Regards,

    Iain

  • Hi Iain,

    but I think the lowest overhead will be to read the counter repeatedly until the top 32 bits are constant.

    That should work.

    Regards,

    Vivek Singh