/**
 * \brief Set maxinum frequency clock for giving pripheral ID.
 *
 * \param id  Peripheral ID (ID_xxx).
 * \param mck  Master clock.
 * \return Peripheral clock.
 */
extern uint32_t PMC_SetPeriMaxClock( uint32_t dwId, uint32_t mck)
{
    uint32_t maxClock;
    uint8_t i;
    /* Disable peripher clock */
    PMC->PMC_PCR = PMC_PCR_PID(dwId) | PMC_PCR_CMD;
    maxClock = PMC_GetPeriMaxFreq(dwId);
    for ( i = 0; i < 4; i++) {
        if ( mck / (1 << i ) <= maxClock) break;
    }
    PMC->PMC_PCR = PMC_PCR_PID(dwId) | PMC_PCR_CMD | (i << PMC_PCR_DIV_Pos) | PMC_PCR_EN;
    return maxClock;
}
/*****************************************************************************************************
*   Function: ADC_EnablePeripheral_GLCK
*
*   Description: Enables the PCM for the AFEC with specific sourse clock.
*
*   Caveats: Non Reentrant
*****************************************************************************************************/
void ADC_EnablePeripheral_GLCK (void)
{

    PMC->PMC_PCR = PMC_PCR_PID(ID_AFEC0) | PMC_PCR_GCLKCSS(0) | PMC_PCR_CMD | PMC_PCR_GCLKEN ;
}