Beispiel #1
0
uint32_t NutClockGet(int idx)
{
    if (clock_cache[idx] == 0) {
        clock_cache[idx] = NutArchClockGet(idx) | NUT_CACHE_LVALID;
    }
    return clock_cache[idx] & ~NUT_CACHE_LVALID;
}
Beispiel #2
0
uint32_t NutGetCpuClock(void)
{
#ifdef NUT_CPU_FREQ
    /* Keep this code small! Can we use a preprocessor
    ** macro to define NutGetCpuClock() as NUT_CPU_FREQ? */
    return NUT_CPU_FREQ;
#else /* !NUT_CPU_FREQ */
    /* Keep this code fast for the normal case, where the
    ** cached value is valid. */
    if (clock_cache[NUT_HWCLK_CPU]) {
        return clock_cache[NUT_HWCLK_CPU] & ~NUT_CACHE_LVALID;
    }
#if NUT_HWCLK_MAX
    return NutClockGet(NUT_HWCLK_CPU);
#else /* !NUT_HWCLK_MAX */
    clock_cache[NUT_HWCLK_CPU] = NutArchClockGet(NUT_HWCLK_CPU) | NUT_CACHE_LVALID;
    return clock_cache[NUT_HWCLK_CPU] & ~NUT_CACHE_LVALID;
#endif /* !NUT_HWCLK_MAX */
#endif /* !NUT_CPU_FREQ */
}
/*!
 * \brief Get divider for a given MCI clock rate.
 *
 * \param clk Requested clock rate.
 */
static uint32_t At91MciClockDiv(uint32_t clk)
{
    uint32_t rc;

    /* MCI is driven by MCK/2. */
    rc = NutArchClockGet(NUT_HWCLK_PERIPHERAL) / 2;
    /* Compensate rounding error, but do not care about 10kHz. */
    rc += clk - 10000;
    /* Calculate the divider. */
    rc /= clk;
    /* Actual divider is 1 less, avoid underflow. */
    if (rc) {
        rc -= 1;
    }
    /* In reality, overflow will only happen when the caller requests
       a unrealistic low MCI clock. */
    if (rc > 255) {
        rc = 255;
    }
    return rc;
}