Example #1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_OscInit
 * Description   : Initialize OSC.
 *
 * This function initializes OSC according to configuration.
 *
 *END**************************************************************************/
clock_manager_error_code_t CLOCK_SYS_OscInit(uint32_t instance,
        osc_user_config_t *config)
{
    assert(instance < OSC_INSTANCE_COUNT);
    uint32_t capacitorMask = 0U;

    if (kOscSrcOsc == config->erefs) /* oscillator is used. */
    {
        capacitorMask = (config->enableCapacitor2p   ? kOscCapacitor2p   : 0U) |
                        (config->enableCapacitor4p   ? kOscCapacitor4p   : 0U) |
                        (config->enableCapacitor8p   ? kOscCapacitor8p   : 0U) |
                        (config->enableCapacitor16p  ? kOscCapacitor16p  : 0U);
        OSC_HAL_SetCapacitor(g_oscBase[instance], capacitorMask);
    }

    CLOCK_SYS_SetOscerConfigration(instance, &(config->oscerConfig));

#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
    if (0U == instance)
    {
#endif
        CLOCK_HAL_SetOsc0Mode(MCG, config->range, config->hgo, config->erefs);

        /* oscillator is used. */
        if ((kOscSrcOsc == config->erefs) &&
                (true == config->oscerConfig.enable))
        {
            while(!CLOCK_HAL_IsOsc0Stable(MCG)) {}
        }
        g_xtal0ClkFreq = config->freq;
#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
    }
    else
    {
        CLOCK_HAL_SetOsc1Mode(MCG, config->range, config->hgo, config->erefs);

        /* oscillator is used. */
        if ((kOscSrcOsc == config->erefs) &&
                (true == config->oscerConfig.enable))
        {
            while(!CLOCK_HAL_IsOsc1Stable(MCG)) {}
        }
        g_xtal1ClkFreq = config->freq;
    }
#endif

    return kClockManagerSuccess;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_SetConfiguration
 * Description   : This funtion sets the system to target configuration, it
 * only sets the clock modules registers for clock mode change, but not send
 * notifications to drivers.
 *
 *END**************************************************************************/
clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
{
    assert(NULL != config);

    /* Set outdiv for safe output clock frequency. */
    CLOCK_HAL_SetOutDiv(SIM_BASE, 0U, 1U, 1U, 4U);

    /* Set MCG mode. */
    CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);

    /* Set SIM setting. */
    CLOCK_SYS_SetSimConfigration(&config->simConfig);

    /* Set OSCERCLK setting. */
    CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);

    return kClockManagerSuccess;
}
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetFreq
 * Description   : Internal function to get the frequency by clock name
 * This function will get/calculate the clock frequency based on clock name
 * and current configuration of clock generator.
 *
 *END**************************************************************************/
clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
{
    assert(NULL != config);

    /* Set outdiv for safe output clock frequency. */

    CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);

    /* Set MCG mode. */
    CLOCK_SYS_SetMcgMode(&config->mcgConfig);

    /* Set SIM setting. */
    CLOCK_SYS_SetSimConfigration(&config->simConfig);

    /* Set OSCERCLK setting. */
    CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
    SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();

    return kClockManagerSuccess;
}
Example #4
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_OscInit
 * Description   : Initialize OSC.
 *
 * This function initializes OSC according to configuration.
 *
 *END**************************************************************************/
clock_manager_error_code_t CLOCK_SYS_OscInit(uint32_t instance,
        osc_user_config_t *config)
{
    assert(instance < OSC_INSTANCE_COUNT);
    uint32_t capacitorMask = 0U;

    if (kOscSrcOsc == config->erefs) /* oscillator is used. */
    {
        capacitorMask = (config->enableCapacitor2p   ? kOscCapacitor2p   : 0U) |
                        (config->enableCapacitor4p   ? kOscCapacitor4p   : 0U) |
                        (config->enableCapacitor8p   ? kOscCapacitor8p   : 0U) |
                        (config->enableCapacitor16p  ? kOscCapacitor16p  : 0U);
        OSC_HAL_SetCapacitor(g_oscBase[instance], capacitorMask);
    }

#if FSL_FEATURE_MCGLITE_HAS_RANGE0
    CLOCK_HAL_SetRange0Mode(MCG, config->range);
#endif
#if FSL_FEATURE_MCGLITE_HAS_HGO0
    CLOCK_HAL_SetHighGainOsc0Mode(MCG, config->hgo);
#endif
    CLOCK_HAL_SetExtRefSelMode0(MCG, config->erefs);

    CLOCK_SYS_SetOscerConfigration(instance, &(config->oscerConfig));

    /* oscillator is used. */
    if ((kOscSrcOsc == config->erefs) &&
            (true == config->oscerConfig.enable))
    {
        while(!CLOCK_HAL_IsOscStable(MCG)) {}
    }

    g_xtal0ClkFreq = config->freq;

    return kClockManagerSuccess;
}