* Project : RTD AUTOSAR 4.7
* Platform : CORTEXM
* Peripheral : LPSPI
* Dependencies :
*
* Autosar Version : 4.7.0
* Autosar Revision : ASR_REL_4_7_REV_0000
* Autosar Conf.Variant :
* SW Version : 3.0.0
* Build Version : S32K3_RTD_3_0_0_D2303_ASR_REL_4_7_REV_0000_20230331
I am using the Lpspi_Ip_SyncTransmitHalfDuplex function with the TIMEOUT parameter and TransferType = LPSPI_IP_HALF_DUPLEX_RECEIVE. However, I believe there is an issue in this function.
Inside the while loop, the line ElapsedTicks = 0u; is executed in each iteration until ExpectedFifoReads == State->RxIndex.
For the TIMEOUT condition, the following code is used:
ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, LPSPI_IP_TIMEOUT_METHOD);
if (ElapsedTicks >= TimeoutTicks)
{
Status = LPSPI_IP_TIMEOUT;
}
Here, the OsIf_GetElapsed function uses CurrentTicks, which is set before the loop as shown below:
CurrentTicks = OsIf_GetCounter(LPSPI_IP_TIMEOUT_METHOD);
If CurrentTicks were truly initialized before the loop and OsIf_GetElapsed measured the time elapsed since that point, everything would work as expected.
However, the OsIf_GetElapsed function internally calls OsIf_Timer_System_GetElapsed, which then calls OsIf_Timer_System_Internal_GetElapsed. In this last function, I believe something unintended happens:
uint32 OsIf_Timer_System_Internal_GetElapsed(uint32 * const CurrentRef)
{
...
*CurrentRef = CurrentVal;
...
}
Here, CurrentRef is updated. As a result, instead of measuring the time elapsed since the beginning of the loop, the function measures the time elapsed since the last OsIf_GetElapsed call. This causes the SPI transfer to fail to timeout as expected, and it ends up stuck.
When the line ElapsedTicks = 0u; inside the while loop is removed, the function behaves as expected.
Could you clarify if this is a known issue or if there’s an intended use case I might be missing?