⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 iar环境下移植ucos-ii到at91sam7s64
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                            Atmel AT91 SAM7
*                                         Board Support Package
*
*                              (c) Copyright 2004, Micrium, Inc., Weston, FL
*                                          All Rights Reserved
*
*
* File : BSP.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#include <includes.h>


/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

#define  BSP_XTAL_FREQ                   18432L                /* 18,432 KHZ CRYSTAL OSCILLATOR PRESENT */


/*
*********************************************************************************************************
*                                               DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                              PROTOTYPES
*********************************************************************************************************
*/

static  void  BSP_DummyISR_Handler(void);

static  void  BSP_IntCtrlInit(void);

static  void  Tmr_TickInit(void);
static  void  Tmr_TickISR_Handler(void);


/*
*********************************************************************************************************
*                                           DUMMY IRQ HANDLER
*
* Description : This function is called to handle invalid IRQs
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  BSP_DummyISR_Handler (void)
{
    AT91C_BASE_AIC->AIC_IVR = 0;                                /* Debug variant of vector read (protect mode is used)      */
}


/*
*********************************************************************************************************
*                                      BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
*               functions found in this module.
*
* Arguments   : none
*********************************************************************************************************
*/

void  BSP_Init (void)
{
    PMC_Init();
    BSP_InitExceptVect();
    BSP_IntCtrlInit();                                          /* Initialize the Interrupt Controller                      */
    Tmr_TickInit();                                             /* Initialize uC/OS-II's Tick Rate                          */
    LED_Init();                                                 /* Initialize the I/Os for the LEDs                         */
}


/*
*********************************************************************************************************
*                                           PMC_Init()
*
* Description : This function initializes the PLL on the AT91SAM7S64.  The Embedded Flash Controller is
*               initialized with the proper number of wait states.
*
* Arguments   : none
*********************************************************************************************************
*/

void  PMC_Init (void)
{
                                                                /* Specify wait states for Flash memory                     */
    AT91C_BASE_MC->MC_FMR      = (0x00300000 | AT91C_MC_FWS_1FWS);

                                                                /* Disable the Watchdog Timer                               */
    AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;

                                                                /* Enable the main oscillator                               */
    AT91C_BASE_PMC->PMC_MOR    = (0x00000600 | AT91C_CKGR_MOSCEN);
                                                                /* Wait for the main oscillator to stabilize                */
    while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS) == 0) {
        ;
    }
                                                                /* Initialize the PLL (bit fields specified below)          */
    AT91C_BASE_PMC->PMC_PLLR   = 0x10191C05;                    /* [07:00]  Divider     =  5                                */
                                                                /* [13:08]  PLLCount startup delay = 28 slow clks           */
                                                                /* [26:16]  Multiplier  = (25 + 1) = 26                     */
                                                                /* [29:28]  USB Divider =  0                                */

                                                                /* Wait for the PLL to lock                                 */
    while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0) {
        ;
    }
                                                                /* Wait for the master clock to become ready                */
    while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }
                                                                /* Main Clock will be equal to half of the PLL Clock        */
    AT91C_BASE_PMC->PMC_MCKR   =  AT91C_PMC_PRES_CLK_2 ;

    while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }
                                                                /* Specify the PLL Clock as the source of the Main Clock    */
    AT91C_BASE_PMC->PMC_MCKR  |= AT91C_PMC_CSS_PLL_CLK  ;

    while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) {
        ;
    }
}


/*
*********************************************************************************************************
*                                    DETERMINE AND RETURN CPU OPERATING FREQUENCY
*
* Description : This function is called by OSView_c.c : OSView_GetCPUName() and is responsible for
*               determining the Master Clock Frequency. This is equal to the PLL frequency divided
*               by the Master Clock Divider.
*
* Arguments   : none
* Returns     : CPU frequency in khz.
*********************************************************************************************************
*/

CPU_INT32U  BSP_CPU_ClkFreq (void)
{
    CPU_INT32U      pll_mult;
    CPU_INT32U      pll_div;
    CPU_INT08U      mclk_div;
    CPU_INT32U      cpu_freq;


    pll_mult    = (AT91C_BASE_CKGR->CKGR_PLLR & 0x07FF0000) >> 16;
    pll_div     = (AT91C_BASE_CKGR->CKGR_PLLR & 0x000000FF) >>  0;

    if (pll_div == 0) {
        return (BSP_XTAL_FREQ);                                 /* If the PLL mult is 0, then the PLL is disabled           */
    }
                                                                /* Read the Master Clock divider                            */
    mclk_div    = (AT91C_BASE_PMC->PMC_MCKR >> 2) & 0x07;

    mclk_div    = 1 << mclk_div;                                /* Convert 0-7 into 1, 2, 4, 8, 16, 32, or 64               */

    if (mclk_div >= 128) {                                      /* Divider pattern for 128 is reserved                      */
        return (BSP_XTAL_FREQ);
    }

    cpu_freq    =  ((BSP_XTAL_FREQ * (pll_mult + 1)) / pll_div) / mclk_div;

    return (cpu_freq);
}


/*
*********************************************************************************************************
*                                    INITIALIZE THE INTERRUPT CONTROLLER
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  BSP_IntCtrlInit (void)
{
    CPU_INT16U      i;


    AT91C_BASE_AIC->AIC_EOICR         =  0x00000000;            /* End-of-interrupt command                                 */

    for (i = 0; i < 32; i++) {                                  /* Disable all ISRs                                         */
        AT91C_BASE_AIC->AIC_SVR[i] = (CPU_INT32U)BSP_DummyISR_Handler;
        AT91C_BASE_AIC->AIC_SMR[i] = 0;
    }
}


/*
*********************************************************************************************************
*                                          DISABLE ALL INTERRUPTS
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments   : none
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;                      /* Disable all interrupts                                   */
}


/*
*********************************************************************************************************
*                                         BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
*               functions found in this module.
*
* Arguments   : none
*********************************************************************************************************
*/

void  LED_Init (void)
{
    AT91C_BASE_PIOA->PIO_PER  = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;  /* Enable register                              */
    AT91C_BASE_PIOA->PIO_OER  = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;  /* Output enable                                */
    AT91C_BASE_PIOA->PIO_IDR  = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
    LED_Off(BSP_LED_ALL);                                                   /* Turn OFF all the LEDs                        */
}


/*
*********************************************************************************************************
*                                             LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want ALL the LEDs to be ON
*                      1    turns ON LED1 on the board
*                      .
*                      .
*                      4    turns ON LED4 on the board
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             AT91C_BASE_PIOA->PIO_CODR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
             break;

        case 1:
             AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
             break;

        case 2:
             AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
             break;

        case 3:
             AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
             break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -