Exemplo n.º 1
0
//------------------------------------------------------------------------------
///    Performs the low-level initialization of the chip.
//------------------------------------------------------------------------------
void LowLevelInit(unsigned int clockConfigEnable)
{
    unsigned char i;
    if (clockConfigEnable)
    {
        // Initialize main oscillator
        AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
        // Wait the main oscillator stabilization
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
        // Initialize PLLA at 200MHz
        AT91C_BASE_PMC->PMC_PLLAR = BOARD_CKGR_PLLA
                                    | BOARD_PLLACOUNT
                                    | BOARD_MULA
                                    | BOARD_DIVA;
        // Wait the PLLA locking
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA));
        // Wait for the master clock if it was already initialized
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

        // Set Master Clock Division only (before select the clock)
        // Processor clock = PLLA (200 MHz)
        // Master clock    = PLLA / 2 (100 MHz)   
        AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

        // Select PLLA
        AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLLA_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
    }
    /* Initialize AIC
     ****************/
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
    AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) defaultFiqHandler;
    for (i = 1; i < 31; i++) {

        AT91C_BASE_AIC->AIC_SVR[i] = (unsigned int) defaultIrqHandler;
    }
    AT91C_BASE_AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler;

    // Unstack nested interrupts
    for (i = 0; i < 8 ; i++) {

        AT91C_BASE_AIC->AIC_EOICR = 0;
    }

    /* Watchdog initialization
     *************************/
    AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;

    /* Remap
     *******/
    BOARD_RemapRam();   
    
    configure_AT73C224();
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
///    Performs the low-level initialization of the chip.
//------------------------------------------------------------------------------
void LowLevelInit(unsigned int clockConfigEnable)
{
    unsigned char i;
    if (clockConfigEnable)
    {
        // Initialize main oscillator
        AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
        // Wait the main oscillator stabilization
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
        // Initialize PLLA at 200MHz
        AT91C_BASE_PMC->PMC_PLLAR = BOARD_CKGR_PLLA
                                    | BOARD_PLLACOUNT
                                    | BOARD_MULA
                                    | BOARD_DIVA;
        // Wait the PLLA locking
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCKA));
        // Wait for the master clock if it was already initialized
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

        // Set Master Clock Division only (before select the clock)
        // Processor clock = PLLA (200 MHz)
        // Master clock    = PLLA / 2 (100 MHz)   
        AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_SLOW_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

        // Select PLLA
        AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLLA_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;
        while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));
    }
    /* Initialize AIC
     ****************/
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
    AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) defaultFiqHandler;
    for (i = 1; i < 31; i++) {

        AT91C_BASE_AIC->AIC_SVR[i] = (unsigned int) defaultIrqHandler;
    }
    AT91C_BASE_AIC->AIC_SPU = (unsigned int) defaultSpuriousHandler;

    // Unstack nested interrupts
    for (i = 0; i < 8 ; i++) {

        AT91C_BASE_AIC->AIC_EOICR = 0;
    }

    /* Watchdog initialization
     *************************/
    AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;

    /* Remap
     *******/
    BOARD_RemapRam();   
    
    // Disable RTT and PIT interrupts (potential problem when program A
    // configures RTT, then program B wants to use PIT only, interrupts
    // from the RTT will still occur since they both use AT91C_ID_SYS)
    AT91C_BASE_RTTC->RTTC_RTMR &= ~(AT91C_RTTC_ALMIEN | AT91C_RTTC_RTTINCIEN);
    AT91C_BASE_PITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;        
    
    configure_AT73C224();
}