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

📄 bsp.c

📁 ucosII的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                       STMicroelectronics STR710
*                                         Board Support Package
*                 
*
*                                (c) Copyright 2005, Micrium, Weston, FL
*                                          All Rights Reserved
*
*
* File : BSP.C
*********************************************************************************************************
*/

#define   BSP_GLOBALS
#include  <includes.h>

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

#define  BSP_UNDEF_INSTRUCTION_VECTOR_ADDR   (*(CPU_INT32U *)0x00000004L)
#define  BSP_SWI_VECTOR_ADDR                 (*(CPU_INT32U *)0x00000008L)
#define  BSP_PREFETCH_ABORT_VECTOR_ADDR      (*(CPU_INT32U *)0x0000000CL)
#define  BSP_DATA_ABORT_VECTOR_ADDR          (*(CPU_INT32U *)0x00000010L)
#define  BSP_IRQ_VECTOR_ADDR                 (*(CPU_INT32U *)0x00000018L)
#define  BSP_FIQ_VECTOR_ADDR                 (*(CPU_INT32U *)0x0000001CL)

#define  BSP_IRQ_ISR_ADDR                    (*(CPU_INT32U *)0x00000038L)
#define  BSP_FIQ_ISR_ADDR                    (*(CPU_INT32U *)0x0000003CL)

#define  BSP_OSC_FREQ                                          16000000
#define  BSP_CPU_FREQ                                          48000000

#define  BSP_TMR0_PRESCALER                                        0x0F

#define  BSP_TMR1_PRESCALER                                        0x0F

#define  BSP_TMR0_INT                                                 0
#define  BSP_UART0_INT                                                9

#define  BSP_NBR_INT                                                 32

#define  BSP_VECT_SET                                                 0
#define  BSP_VECT_ERR                                                 1

#define  BSP_LCD_CTRL_REG                                    0x64000000  
#define  BSP_LCD_DATA_REG                                    0x64000004

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

typedef  void (*BSP_PFNCT)(void);

/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/

static  BSP_PFNCT       BSP_ISR_Table[BSP_NBR_INT];

static  CPU_INT08U     *BSP_LCD_Reg;

static  CPU_INT32U      BSP_Peripheral_Clk1_Freq;
static  CPU_INT32U      BSP_Peripheral_Clk2_Freq;

static  CPU_INT16U      BSP_Tmr0_Rst_Value;

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

static  void            BSP_IO_Init(void);

static  void            Tmr_TickInit(void);

static  void            EIC_Init(void);

static  void            EMI_Init(void);

/*
*********************************************************************************************************
*                                      Get the CPU Clock Frequency
*
* Description: This function determines MCLK, the frequency at which the CPU is running.
*
* Arguments  : none
*********************************************************************************************************
*/

CPU_INT32U  BSP_CPU_ClkFreq (void)
{
    CPU_INT32U   cpu_clk_freq;
    CPU_INT08U   mult;
    CPU_INT08U   pll_div;  
    CPU_INT08U   main_div;
    

    if (((RCCU->CFR) & 0x00008000) != 0) {             /* Determine if the clock is being divided by 2 */
        cpu_clk_freq = BSP_OSC_FREQ / 2;
    } else {
        cpu_clk_freq = BSP_OSC_FREQ;
    }
                                                       /* Determine if the PLL is being used           */
    if ((((RCCU->CFR) & 0x00000003) == 0x00000003) && (((PCU->PWRCR) & 0x1000) == 0x1000)) {
                                                       /* Multiply the clock by the appropriate factor */
        mult = (CPU_INT08U)(((RCCU->PLL1CR) & 0x00000030) >> 4);
        
        switch (mult) {
            case 0:
                 cpu_clk_freq *= 20;
                 break;

            case 1:
                 cpu_clk_freq *= 12;
                 break;

            case 2:
                 cpu_clk_freq *= 24;
                 break;

            case 3:
                 cpu_clk_freq *= 16;
                 break;
        }                        
                                                      /* Divide the clock by the appropriate factor    */
        pll_div = (CPU_INT08U)((RCCU->PLL1CR) & 0x00000007);
        
        if (pll_div != 7) {
            cpu_clk_freq /= (pll_div + 1);
        }
    }   
                                                     /* Again, divide the clock appropriately          */
    main_div      = (CPU_INT08U)(PCU->MDIVR & 0x0003);
    cpu_clk_freq /= (1 << main_div);

    return (cpu_clk_freq);
}

/*
*********************************************************************************************************
*                                   Get the Peripheral Clock Frequency
*
* Description: This function determines the clock frequency for APB1 and APB2, and sets variables 
*              corresponding to these values.
*
* Arguments  : none
*********************************************************************************************************
*/

static  void  BSP_Set_CPU_ClkFreqPeripheral (void)
{
    CPU_INT32U   cpu_peripheral_clk_freq;
    CPU_INT08U   mult;
    CPU_INT08U   pll_div;  
    CPU_INT08U   peripheral1_div;
    CPU_INT08U   peripheral2_div;
    

    if (((RCCU->CFR) & 0x00008000) != 0) {             /* Determine if the clock is being divided by 2 */
        cpu_peripheral_clk_freq = BSP_OSC_FREQ / 2;
    } else {
        cpu_peripheral_clk_freq = BSP_OSC_FREQ;
    }
                                                       /* Determine if the PLL is being used           */
    if ((((RCCU->CFR) & 0x00000003) == 0x00000003) && (((PCU->PWRCR) & 0x1000) == 0x1000)) {
                                                       /* Multiply the clock by the appropriate factor */
        mult = (CPU_INT08U)(((RCCU->PLL1CR) & 0x00000030) >> 4);
        
        switch (mult) {
            case 0:
                 cpu_peripheral_clk_freq *= 20;
                 break;

            case 1:
                 cpu_peripheral_clk_freq *= 12;
                 break;

            case 2:
                 cpu_peripheral_clk_freq *= 24;
                 break;

            case 3:
                 cpu_peripheral_clk_freq *= 16;
                 break;
        } 
                                                      /* Divide the clock by the appropriate factor    */
        pll_div = (CPU_INT08U)((RCCU->PLL1CR) & 0x00000007);
        
        if (pll_div != 7) {
            cpu_peripheral_clk_freq /= (pll_div + 1);
        }
    }   
                                                      /* Divide by the appropriate factor for APB1     */
    peripheral1_div          = (CPU_INT08U)(PCU->PDIVR & 0x0003);
    BSP_Peripheral_Clk1_Freq = cpu_peripheral_clk_freq / (1 << peripheral1_div);
                                                      /* Divide by the appropriate factor for APB2     */
    peripheral2_div          = (CPU_INT08U)((PCU->PDIVR >> 8) & 0x0003);
    BSP_Peripheral_Clk2_Freq = cpu_peripheral_clk_freq / (1 << peripheral2_div);
}

/*
*********************************************************************************************************
*                                         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)
{
    RCCU->PLL1CR                      = 0x00000051;             /* Set a CPU frequency of 48 MHz       */
    RCCU->CFR                        |= 0x00000003;


    BSP_IRQ_VECTOR_ADDR               = 0xE59FF018;             /* LDR PC,[PC,#0x18] instruction       */
    BSP_IRQ_ISR_ADDR                  = (CPU_INT32U)OS_CPU_IRQ_ISR; /* IRQ exception vector address        */

    BSP_FIQ_VECTOR_ADDR               = 0xE59FF018;             /* LDR PC,[PC,#0x18] instruction       */
    BSP_FIQ_ISR_ADDR                  = (CPU_INT32U)OS_CPU_FIQ_ISR; /* FIQ exception vector address        */


    BSP_UNDEF_INSTRUCTION_VECTOR_ADDR = 0xEAFFFFFE;             /* Jump to itself                      */
    BSP_SWI_VECTOR_ADDR               = 0xEAFFFFFE;
    BSP_PREFETCH_ABORT_VECTOR_ADDR    = 0xEAFFFFFE;
    BSP_DATA_ABORT_VECTOR_ADDR        = 0xEAFFFFFE;
    BSP_FIQ_VECTOR_ADDR               = 0xEAFFFFFE;


    BSP_Set_CPU_ClkFreqPeripheral();              /* Set variables reflecting the CPU's frequency      */
                                                  /* Wait until the new CPU frequency is in effect     */
    while (BSP_Peripheral_Clk1_Freq != BSP_CPU_FREQ) {
        BSP_Set_CPU_ClkFreqPeripheral();
    }

    BSP_IO_Init();                                /* Initialize the board's I/Os                       */
    
    EMI_Init();                                   /* Initialize the External Memory Interface          */

    EIC_Init();                                   /* Initialize the Enhanced Interrupt Controller      */

    LED_Init();                                   /* Initialize the I/Os for the LED controls          */

    Tmr_TickInit();                               /* Initialize the uC/OS-II tick interrupt            */
}

/*
*********************************************************************************************************
*                                       SET INTERRUPT VECTOR
*
* Description : This function sets the Interrut Vector Register for the device to the device's
*               interrupt channel number.  This number is then used as an index into a table of interrupt 
*               handlers.
*
* Arguments   : device    corresponds to the device's interrupt channel number
*               handler   the function to be used as the device's interrupt handler
*
* Returns     : 0 if the handler was added to the table, 1 otherwise
*********************************************************************************************************
*/

static  CPU_INT08U  BSP_VectSet (CPU_INT16U device, BSP_PFNCT handler)
{
    CPU_SR  cpu_sr = 0;


    if (device < BSP_NBR_INT) {              /* Make sure there is a space for the device in the table */
                                             /* Set the lower 16-bits of the device's IVR              */
        EIC->SIR[device]      = ((CPU_INT32U)device) << 16;   
        
        CPU_CRITICAL_ENTER();
        BSP_ISR_Table[device] = handler;     /* Add the device's handler to the table                  */
        CPU_CRITICAL_EXIT();
        
        return BSP_VECT_SET;
    } else {
        return BSP_VECT_ERR;
    }
}    

/*
*********************************************************************************************************
*                                    INITIALIZE INTERRUPT CONTROLLER
*
* Description : This function enables interrupts through the Enhanced Interrupt Controller (EIC). This
*               function also intializes the table that is used to determine the appropriate interrupt
*               handler for each interrupting device.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  EIC_Init (void)
{
    CPU_INT16U  i;
  
  
    EIC->ICR = 0x00000001;		                             /* Enable interrupts (IRQ)        */
    
    for (i = 0; i < BSP_NBR_INT; i++) {                              /* Insert null interrupt handlers */
        BSP_VectSet(i, (BSP_PFNCT)0);
    } 
}

/*
*********************************************************************************************************
*                                      DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*               
* Arguments   : none
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    EIC->ICR = 0x00000000;                                          /* Disable ALL interrupts          */
}

/*
*********************************************************************************************************
*                                           IRQ ISR HANDLER
*
* Description : This function is called by OS_CPU_IRQ_ISR() to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OS_CPU_IRQ_ISR_Handler (void)
{
    CPU_INT16U   idx;
    BSP_PFNCT    pfnct;
    
   
    idx   = (CPU_INT16U)((EIC->IVR) & 0x0000FFFF);  /* Get the index corresponding to the device's handler */

⌨️ 快捷键说明

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