/* Configure the MCI CLKDIV in the MCI_MR register. The max. for MCI clock is MCK/2 and corresponds to CLKDIV = 0  */
void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed)
/* Configure the MCI CLKDIV in the MCI_MR register. The max. for MCI clock is MCK/2 and corresponds to CLKDIV = 0  */
void MCI_SetSpeed(Mci *pMci, unsigned int mciSpeed)
{
    AT91S_MCI *pMciHw = pMci->pMciHw;
    unsigned int mciMr;
    unsigned short clkdiv;
    SANITY_CHECK(pMci);
    SANITY_CHECK(pMci->pMciHw);
    mciMr = READ_MCI(pMciHw, MCI_MR) & (~AT91C_MCI_CLKDIV);
    if (mciSpeed > 0) {
        clkdiv = (BOARD_MCK / (mciSpeed * 2));
        if (clkdiv > 0) {
            clkdiv -= 1;
        }
    }
    else {
        clkdiv = 0;
    }
    WRITE_MCI(pMciHw, MCI_MR, mciMr | clkdiv);
}