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.

CCS/HALCOGEN: I have found a bug in rtiGetCurrentTick()

Part Number: HALCOGEN

Tool/software: Code Composer Studio

I don't know if this has been reported yet, but I have found a bug causing overflows in rtiGetCurrentTick().
This is the function:

uint32 rtiGetCurrentTick(uint32 compare)
{
    uint32 tick;
    uint32 counter = ((rtiREG1->COMPCTRL & (uint32)((uint32)1U << (compare << 2U))) != 0U ) ? 1U : 0U;
    uint32 RTI_CNT_FRCx = rtiREG1->CNT[counter].FRCx;
    uint32 RTI_CMP_COMPx = rtiREG1->CMP[compare].COMPx;
    uint32 RTI_CMP_UDCPx = rtiREG1->CMP[compare].UDCPx;

/* USER CODE BEGIN (27) */
/* USER CODE END */

    tick = RTI_CNT_FRCx - (RTI_CMP_COMPx - RTI_CMP_UDCPx);

    /**   @note The function rtiInit has to be called before this function can be used.
    */

/* USER CODE BEGIN (28) */
/* USER CODE END */

    return tick;
}

The problem is with synchronization, and occurs between reading the FRC register into RTI_CNT_FRCx, and the COMP register into RTI_CMP_COMPx. If between these two events, the value of the register FRC increases and reaches COMP, the value of RTI_CMP_COMPx will hold the new, increased value. But RTI_CNT_FRCx will still hold the value of FRC before the increase. And this causes the overflow in the row with the calculation of the return value of the function.

Thank you for reading!

  • Hello Ferenc,

    Before rtiGetCurrentTick(...) is used, the rtiInit has to be called first. The current ticks is less than the initial value in RTICOMPx register. If you have proper configuration for RTICOMPx and RTIUDCPx, you won't get an overflow. But if RTICOMPx initial value and RTIUDCPx are too small, the overflow will occur.

    If the initial compare value (RTICOMPx) and update compare value (RTIUDCPx ) are same and constant value in your application, you can use another way to get ticks and won't get overflow:

    ticks = (RTI_CNT_FRCx % initial compare value)