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

📄 bsp.c

📁 ucos str912 dsfkdslalldllasdfs
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                          IAR STR912-SK Board
*                                         Board Support Package
*
*
*                                (c) Copyright 2006, Micrium, Weston, FL
*                                          All Rights Reserved
*
*
* File : BSP.C
*********************************************************************************************************
*/

#define  BSP_GLOBALS

#include  <includes.h>

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

#define  BSP_SRAM_SIZE_MASK                                       0xFFFFFFE7
#define  BSP_WSR_AHB_MASK                                         0xFFFFFFFB
#define  BSP_WSR_DTCM_MASK                                        0xFFFFFFFD
#define  BSP_SRAM_LK_EN_MASK                                      0xFFFFFFDF
#define  BSP_SRAM_SIZE                                                  0x02
#define  BSP_WSR_AHB_VAL                                                   0
#define  BSP_WSR_DTCM_VAL                                                  0
#define  BSP_SRAM_LK_EN_VAL                                                1
#define  BSP_TMR0_PRESCALER                                           0x0030
#define  BSP_VIC_CHANNELS                                                 16
#define  BSP_NBR_INT                                                      32

                                                     /* PLL dividers and multipliers                   */
#define  BSP_PLL_M                                                        25
#define  BSP_PLL_N                                                       192
#define  BSP_PLL_P                                                         2

                                                     /* Tick interrupt priority                        */
#define  BSP_TMR0_INT_PRIO                                                15
                                                     /* uC/OS-View UART interrupt priority             */
#define  BSP_UART1_INT_PRIO                                               15

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

typedef  void (*BSP_PFNCT)(void);

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

INT16U      BSP_Tmr0_Cmp_Value;

static      GPIO_InitTypeDef  BSP_GPIOInit;
static      UART_InitTypeDef  BSP_UARTInit;

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

static  void  BSP_IO_Init(void);

static  void  Tmr_TickInit(void);

static  void  VIC_Init(void);

#ifdef DISP_MODULE_PRESENT
static  void  DispE_High(void);
static  void  DispE_Low(void);
static  void  DispRW_Low (void);
#endif

/*
*********************************************************************************************************
*                                         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)
{
    CPU_INT32U  scr0_val;


    SCU_MCLKSourceConfig(SCU_MCLK_OSC);
                                                     /* Set the PLL's multipliers and dividers         */
    SCU_PLLFactorsConfig(BSP_PLL_N, BSP_PLL_M, BSP_PLL_P);
    SCU_PLLCmd(ENABLE);                              /* Enable the PLL                                 */
    SCU_RCLKDivisorConfig(SCU_RCLK_Div1);            /* Set RCLK, the CPU clock's main divider         */
    SCU_PCLKDivisorConfig(SCU_PCLK_Div1);            /* Set APBDIV, the PCLK divider                   */
    SCU_FMICLKDivisorConfig(SCU_FMICLK_Div2);

    SCU_MCLKSourceConfig(SCU_MCLK_PLL);              /* Select the PLL output as CPU clock             */

    scr0_val  = SCU->SCR0;                           /* Set the size of the SRAM                       */
    scr0_val &= (BSP_SRAM_SIZE_MASK & BSP_WSR_AHB_MASK & BSP_WSR_DTCM_MASK & BSP_SRAM_LK_EN_MASK);
    scr0_val |= ((BSP_SRAM_LK_EN_VAL << 5) | (BSP_SRAM_SIZE << 3) | (BSP_WSR_AHB_VAL << 2) | (BSP_WSR_DTCM_VAL << 1));
    SCU->SCR0 = scr0_val;
    SCU_PFQBCCmd(ENABLE);                            /* Enable the PFQBC                               */

    BSP_IO_Init();                                   /* Initialize the board's I/Os                    */

    VIC_Init();                                      /* Initialize the Vectored Interrupt Controller   */

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

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

/*
*********************************************************************************************************
*                                    INITIALIZE INTERRUPT CONTROLLER
*
* Description : This function initializes the Vectored Interrupt Controller (VIC).
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  VIC_Init (void)
{
    CPU_INT08U  i;
    CPU_INT32U  int_src;


    int_src = 0;

    SCU_AHBPeriphClockConfig(__VIC,   ENABLE);       /* Enable the VIC's clock signal                  */
    SCU_AHBPeriphReset(__VIC,   DISABLE);            /* Remove the VIC from reset state                */

    for (i = 0; i < BSP_VIC_CHANNELS; i++) {
        VIC_ITCmd(int_src, DISABLE);
        int_src++;
    }

    for (i = 0; i < BSP_VIC_CHANNELS; i++) {
        VIC_ITCmd(int_src, DISABLE);
        int_src++;
    }
}

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

void  BSP_IntDisAll (void)
{
    CPU_INT08U  i;


    for (i = 0; i < BSP_NBR_INT; i++) {
        VIC_ITCmd(i, DISABLE);
    }
}

/*
*********************************************************************************************************
*                                           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)
{
    BSP_PFNCT  pfnct;

#if  Simulator_Debug_EN>0
    OSTimeTick();
#endif    

    while (((VIC0->ISR) != 0) || ((VIC1->ISR) != 0)) {
                                                     /* Read the interrupt vector                      */
        pfnct = (BSP_PFNCT)(VIC_GetCurrentISRAdd(VIC0));
        if (pfnct != (BSP_PFNCT)0) {                 /* Make sure we don't have a NULL pointer         */
            (*pfnct)();                              /* Execute the ISR for the interrupting device    */
        } else {
            VIC0->VAR  = 0x00000000;                 /* Signal the end of the interrupt                */
            VIC1->VAR  = 0x00000000;
        }
    }
}

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

void  OS_CPU_FIQ_ISR_Handler (void)
{
}

/*
*********************************************************************************************************
*                                          INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins used by the application.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  BSP_IO_Init (void)
{
#if OS_VIEW_MODULE > 0
    SCU_APBPeriphClockConfig(__GPIO3, ENABLE);       /* Enable appropriate GPIO ports' clock signal    */
#endif
    SCU_APBPeriphClockConfig(__GPIO6, ENABLE);
    SCU_APBPeriphClockConfig(__GPIO7, ENABLE);
#ifdef DISP_MODULE_PRESENT
    SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
    SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
#endif

#if OS_VIEW_MODULE > 0
    SCU_APBPeriphReset(__GPIO3, DISABLE);            /* Remove the ports from reset state              */
#endif
    SCU_APBPeriphReset(__GPIO6, DISABLE);
    SCU_APBPeriphReset(__GPIO7, DISABLE);
#ifdef DISP_MODULE_PRESENT
    SCU_APBPeriphReset(__GPIO8, DISABLE);
    SCU_APBPeriphReset(__GPIO9, DISABLE);
#endif


#if OS_VIEW_MODULE == 0
    BSP_GPIOInit.GPIO_Pin         = 0x0C;
    BSP_GPIOInit.GPIO_Direction   = GPIO_PinOutput;
    BSP_GPIOInit.GPIO_Type        = GPIO_Type_PushPull;
    BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable;
    BSP_GPIOInit.GPIO_Alternate   = GPIO_OutputAlt1;

    GPIO_Init(GPIO3, &BSP_GPIOInit);                 /* Initialize GPIO pins that manipulate LEDs      */
#endif

    BSP_GPIOInit.GPIO_Pin         = 0xF3;
    BSP_GPIOInit.GPIO_Direction   = GPIO_PinOutput;
    BSP_GPIOInit.GPIO_Type        = GPIO_Type_PushPull;
    BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable;
    BSP_GPIOInit.GPIO_Alternate   = GPIO_OutputAlt1;

    GPIO_Init(GPIO3, &BSP_GPIOInit);

    BSP_GPIOInit.GPIO_Pin         = 0xFF;

    GPIO_Init(GPIO6, &BSP_GPIOInit);

    BSP_GPIOInit.GPIO_Pin         = 0x60;
    BSP_GPIOInit.GPIO_Direction   = GPIO_PinInput;
    BSP_GPIOInit.GPIO_Type        = GPIO_Type_PushPull;
    BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable;
    BSP_GPIOInit.GPIO_Alternate   = GPIO_InputAlt1;

    GPIO_Init(GPIO7, &BSP_GPIOInit);                 /* Initialize GPIO pins corresponding to buttons  */

#ifdef DISP_MODULE_PRESENT
    GPIO8->DDR = 0xFF;
    GPIO9->DDR = 0xFF;                               /* Set the direction of the LCD pins              */
#endif

#if OS_VIEW_MODULE > 0                               /* Initialize GPIO pins used by uC/OS-View        */
    BSP_GPIOInit.GPIO_Pin         = 0x04;
    BSP_GPIOInit.GPIO_Direction   = GPIO_PinInput;
    BSP_GPIOInit.GPIO_Type        = GPIO_Type_PushPull;
    BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;
    BSP_GPIOInit.GPIO_Alternate   = GPIO_InputAlt1;

    GPIO_Init(GPIO3, &BSP_GPIOInit);

    BSP_GPIOInit.GPIO_Pin         = 0x08;
    BSP_GPIOInit.GPIO_Direction   = GPIO_PinOutput;
    BSP_GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable;
    BSP_GPIOInit.GPIO_Alternate   = GPIO_OutputAlt2;

    GPIO_Init(GPIO3, &BSP_GPIOInit);
#endif


}

/*
*********************************************************************************************************
*                                           LED INITIALIZATION
*
* Description : This function initializes the board's LEDs.
*
* Arguments   : none
*********************************************************************************************************
*/

void  LED_Init (void)
{
    LED_Off(0);
}

/*
*********************************************************************************************************
*                                                 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 to turn on all of the board's LEDs
*                      1    turn on LED1
*                      2    turn on LED2
*                      .
*                      16   turn on LED16
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U  led)
{
    switch (led) {
        case 0:
             GPIO_WriteBit(GPIO3, 0xFF, Bit_RESET);
             GPIO_WriteBit(GPIO6, 0xFF, Bit_RESET);
             break;

        case 1:
             GPIO_WriteBit(GPIO3, 0x01, Bit_RESET);
             break;

        case 2:
             GPIO_WriteBit(GPIO3, 0x02, Bit_RESET);
             break;

        case 3:
             GPIO_WriteBit(GPIO3, 0x04, Bit_RESET);
             break;

        case 4:
             GPIO_WriteBit(GPIO3, 0x08, Bit_RESET);
             break;

        case 5:
             GPIO_WriteBit(GPIO3, 0x10, Bit_RESET);
             break;

        case 6:
             GPIO_WriteBit(GPIO3, 0x20, Bit_RESET);
             break;

        case 7:
             GPIO_WriteBit(GPIO3, 0x40, Bit_RESET);
             break;

        case 8:
             GPIO_WriteBit(GPIO3, 0x80, Bit_RESET);
             break;

        case 9:
             GPIO_WriteBit(GPIO6, 0x01, Bit_RESET);
             break;

        case 10:
             GPIO_WriteBit(GPIO6, 0x02, Bit_RESET);
             break;

        case 11:
             GPIO_WriteBit(GPIO6, 0x04, Bit_RESET);
             break;

        case 12:
             GPIO_WriteBit(GPIO6, 0x08, Bit_RESET);
             break;

        case 13:
             GPIO_WriteBit(GPIO6, 0x10, Bit_RESET);

⌨️ 快捷键说明

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