/* Calculates the improved timing values by specific baudrates for classical CAN.  */
bool FLEXCAN_CalculateImprovedTimingValues(uint32_t baudRate, uint32_t sourceClock_Hz, flexcan_timing_config_t *pTimingConfig)
/* Calculates the improved timing values by specific baudrates for classical CAN.  */
bool FLEXCAN_CalculateImprovedTimingValues(uint32_t baudRate, uint32_t sourceClock_Hz, flexcan_timing_config_t *pTimingConfig)
{
    assert(baudRate <= MAX_CAN_BAUDRATE);
    uint32_t clk;
    uint32_t tqNum;
    bool fgRet = false;
    tqNum = CTRL1_MAX_TIME_QUANTA;
    do
    {
        clk = baudRate * tqNum;
        if (clk > sourceClock_Hz)
        {
            continue;
        }
        if ((sourceClock_Hz / clk * clk) != sourceClock_Hz)
        {
            continue;
        }
        pTimingConfig->preDivider = (uint16_t)(sourceClock_Hz / clk) - 1U;
        if (pTimingConfig->preDivider > MAX_PRESDIV)
        {
            break;
        }
        if (FLEXCAN_GetSegments(baudRate, tqNum, pTimingConfig))
        {
            fgRet = true;
            break;
        }
    } while (--tqNum >= CTRL1_MIN_TIME_QUANTA);
    return fgRet;
}