/* Configures the EBI for NandFlash access. Pins must be configured after or before calling this function.  */
void BOARD_ConfigureNandFlash(unsigned char busWidth)
/* Configures the EBI for NandFlash access. Pins must be configured after or before calling this function.  */
void BOARD_ConfigureNandFlash(unsigned char busWidth)
{
    AT91C_BASE_MATRIX->MATRIX_EBI |= AT91C_MATRIX_CS3A_SM;
    AT91C_BASE_SMC->SMC_SETUP3 = 0x00000000;
    AT91C_BASE_SMC->SMC_PULSE3 = 0x00030003;
    AT91C_BASE_SMC->SMC_CYCLE3 = 0x00050005;
    AT91C_BASE_SMC->SMC_CTRL3  = 0x00002003;
    if (busWidth == 8) {
        AT91C_BASE_SMC->SMC_CTRL3 |= AT91C_SMC_DBW_WIDTH_EIGTH_BITS;
    }
    else if (busWidth == 16) {
        AT91C_BASE_SMC->SMC_CTRL3 |= AT91C_SMC_DBW_WIDTH_SIXTEEN_BITS;
    }
}