SPRUI30H November 2015 – May 2024 DRA745 , DRA746 , DRA750 , DRA756
Reading the full 64-bit count takes two sequential MVC instructions. A read from TSCL causes the upper 32 bits of the current count (the value of the counter when the corresponding MVC instruction is at Fetch/DEC stage) to be copied into TSCH. In normal operation, only this snapshot of the upper half of the 64-bit count is available to the programmer. The value read will always be the value copied at the cycle of the last MVC TSCL,reg instruction. If it is read with no TSCL reads having taken place since reset, then the reset value of 0 is read.
When reading the full 64-bit value, it must be ensured that no interrupts are serviced between the two MVC instructions if an ISR is allowed to make use of the time stamp counter. There is no way for an ISR to restore the previous value of TSCH (snapshot) if it reads TSCL, since a new snapshot is performed.
The following example shows the correct and recommended way of obtaining the full 64-bit value of the time stamp counter:
// Disable interrupts
MVC CSR, R7 ; Get CSR into R7
CLR 0, 0, R7, R7 ; Clear R7[0]
MVC R7, CSR ; Copy R7 back to CSR (clears GIE)
// Read Counter
MVC TSCL, R0 ; read lower 32b into R0
MVC TSCH, R1 ; read upper 32b into R1
// Enable interrupts
MVC CSR, R7 ; Get CSR into R7
SET 0, 0, R7, R7 ; Set R7[0]
MVC R7, CSR ; Copy R7 back to CSR (sets GIE)