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

📄 bsp.c

📁 在IAR EWARM开发环境下的ucos_2操作系统在LPC2200上的应用
💻 C
📖 第 1 页 / 共 3 页
字号:
* Argument(s) : led     The ID of the LED to control:
*
*                       0    toggles all  LEDs  on the board
*                       1    toggles user LED1  on the board
*                       2    toggles user LED2  on the board
*                       . 
*                       . 
*                       16   toggles user LED16 on the board
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*********************************************************************************************************
*/

void  BSP_LED_Toggle (CPU_INT08U led)
{
    CPU_INT32U  reg_val;
    
    reg_val = IOPIN;
    
    if (led > 0) {
        IOSET   = (~reg_val) &  DEF_BIT(led - 1);
        IOCLR   = ( reg_val) &  DEF_BIT(led - 1);        
    } else {
        IOSET   = (~reg_val) &  BSP_GPI00_LED_GRP;
        IOCLR   = ( reg_val) &  BSP_GPI00_LED_GRP;
    }
}

/*
*********************************************************************************************************
*                                             BSP_LED_Toggle()
*
* Description : Initializes the PB's I/O.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*********************************************************************************************************
*/

static  void  BSP_PB_Init (void) 
{
    IODIR &= ~BSP_GPIO0_PB_GRP;
}


/*
*********************************************************************************************************
*                                         BSP_PB_GetStatus()
*
* Description : Get the status of a push button on the board.
*
* Argument(s) : pb      The ID of the push button to probe
*
*                       1    probe the push button B1
*                       2    probe the push button B2
*                       3    probe the push button B3
*
* Return(s)   : DEF_FALSE   if the push button is pressed
*               DEF_TRUE    if the push button is not pressed
*
* Caller(s)   : Application.
*********************************************************************************************************
*/

CPU_BOOLEAN  BSP_PB_GetStatus (CPU_INT08U pb)
{
    CPU_BOOLEAN  status;


    status = DEF_FALSE;

    switch (pb) {
        case 1:
             status = DEF_BIT_IS_CLR(IOPIN, BSP_GPIO0_PB1);
             break;

        case 2:
             status = DEF_BIT_IS_CLR(IOPIN, BSP_GPIO0_PB2);
             break;

        case 3:
             status = DEF_BIT_IS_CLR(IOPIN, BSP_GPIO0_PB3);
             break;
             
        default:
             break;
    }

    return (status);
}


/*
*********************************************************************************************************
*********************************************************************************************************
*                             uC/Probe PLUG-IN FOR uC/OS-II FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       OSProbe_TmrInit()
*
* Description : Select & initialize a timer for use with the uC/Probe Plug-In for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

#if (APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && (OS_PROBE_HOOKS_EN == 1)
void  OSProbe_TmrInit (void)
{
    T1PR  = 0;
    T1TCR = 0x00000001;                                         /* Enable the timer                                         */

}
#endif


/*
*********************************************************************************************************
*                                        OSProbe_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
* Return(s)   : The 32 bit counts of the timer.
*********************************************************************************************************
*/

#if (APP_CFG_PROBE_OS_PLUGIN_EN > 0) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U  OSProbe_TmrRd (void)
{
    return ((CPU_INT32U)T1TC);
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
**                                     uC/OS-II TIMER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            Tmr_TickInit()
*
* Description : Initialize uC/OS-II's tick source.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  BSP_Tmr_TickInit (void)
{
    CPU_INT32U  pclk_freq;
    CPU_INT32U  tmr_reload;

                                                                /* VIC TIMER #0 Initialization                              */
    VICIntSelect &= ~(1 << VIC_TIMER0);                         /* Enable interrupts                                        */
    VICVectAddr4  = (CPU_INT32U)BSP_Tmr_TickISR_Handler;        /* Set the vector address                                   */
    VICVectCntl4  = 0x20 | VIC_TIMER0;                          /* Enable vectored interrupts                               */
    VICIntEnable  = (1 << VIC_TIMER0);                          /* Enable Interrupts                                        */

    pclk_freq     = BSP_CPU_PclkFreq();
    tmr_reload    = pclk_freq / OS_TICKS_PER_SEC;
    T0TCR         = 0;                                          /* Disable timer 0.                                         */
    T0PC          = 0;                                          /* Prescaler is set to no division.                         */

    T0MR0         = tmr_reload;
    T0MCR         = 3;                                          /* Interrupt on MR0 (reset TC)                              */

    T0CCR         = 0;                                          /* Capture is disabled.                                     */
    T0EMR         = 0;                                          /* No external match output.                                */
    T0TCR         = 1;                                          /* Enable timer 0                                           */
}


/*
*********************************************************************************************************
*                                       Tmr_TickISR_Handler()
*
* Description : Handle the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  BSP_Tmr_TickISR_Handler (void)
{
    T0IR = 0xFF;                                                /* Clear timer #0 interrupt                                 */

    OSTimeTick();                                               /* Call uC/OS-II's OSTimeTick()                             */
}


/*
*********************************************************************************************************
*********************************************************************************************************
**                                          LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                           BSP_PLL_Init()
*
* Description : Set up and activate the PLL
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  BSP_PLL_Init (void)
{
#if OS_CRITICAL_METHOD == 3                                     /* Allocate storage for CPU status register                 */
    OS_CPU_SR   cpu_sr = 0;
#endif
    CPU_INT16U  loop_ctr;

                                                                /* Configure PLL0, which determines the CPU clock           */
    PLLCFG   = (BSP_PLLCFG_M << 0)
             | (BSP_PLLCFG_P << 5);      
    PLLCON  &= 0xFFFFFFFC;                                      /* Set the PLL Enable bit                                   */

    OS_ENTER_CRITICAL();
    PLLFEED  = 0xAA;                                            /* Write to the PLL Feed register                           */
    PLLFEED  = 0x55;
    OS_EXIT_CRITICAL();

    loop_ctr = 10000;                                           /* Wait for the PLL to lock into the new frequency          */
    while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) {
        loop_ctr--;
    }

    PLLCON  |= 0x00000003;                                      /* Connect the PLL                                          */

    OS_ENTER_CRITICAL();
    PLLFEED  = 0xAA;                                            /* Write to the PLL Feed register                           */
    PLLFEED  = 0x55;
    OS_EXIT_CRITICAL();

    APBDIV   = 0x00000002;                                      /* Set the VPB frequency to one-half of the CPU clock       */
}



/*
*********************************************************************************************************
*********************************************************************************************************
**                                            VIC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        Vectored Interrupt Controller
*********************************************************************************************************
*/

static  void  BSP_VIC_Init (void)
{
    VICIntEnClear = 0xFFFFFFFF;                                 /* Disable ALL interrupts                                   */
    VICProtection = 0;                                          /* Setup interrupt controller                               */

    VICVectAddr0  = (CPU_INT32U)BSP_VIC_DummyWDT;               /* Set the vector address                                   */
    VICVectAddr1  = (CPU_INT32U)BSP_VIC_DummyDBGRx;
    VICVectAddr2  = (CPU_INT32U)BSP_VIC_DummyDBGTx;
    VICVectAddr4  = (CPU_INT32U)BSP_VIC_DummyTIMER0;
    VICVectAddr5  = (CPU_INT32U)BSP_VIC_DummyTIMER1;
    VICVectAddr6  = (CPU_INT32U)BSP_VIC_DummyUART0;
    VICVectAddr7  = (CPU_INT32U)BSP_VIC_DummyUART1;
    VICVectAddr9  = (CPU_INT32U)BSP_VIC_DummyI2C0;
    VICVectAddr10 = (CPU_INT32U)BSP_VIC_DummySPI;
    VICVectAddr11 = (CPU_INT32U)BSP_VIC_DummySSP;
    VICVectAddr12 = (CPU_INT32U)BSP_VIC_DummyPLL;
    VICVectAddr13 = (CPU_INT32U)BSP_VIC_DummyRTC;
    VICVectAddr14 = (CPU_INT32U)BSP_VIC_DummyEINT0;
    VICVectAddr15 = (CPU_INT32U)BSP_VIC_DummyEINT1;
}

static  void  BSP_VIC_Dummy (void)
{
    while (1) {
        (void)VIC_SpuriousInt;
    }
}

static  void  BSP_VIC_DummyWDT (void)
{
    VIC_SpuriousInt = VIC_WDT;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyDBGRx (void)
{
    VIC_SpuriousInt = VIC_DEBUGRX;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyDBGTx (void)
{
    VIC_SpuriousInt = VIC_DEBUGTX;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyTIMER0 (void)
{
    VIC_SpuriousInt = VIC_TIMER0;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyTIMER1 (void)
{
    VIC_SpuriousInt = VIC_TIMER1;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyUART0 (void)
{
    VIC_SpuriousInt = VIC_UART0;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyUART1 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyI2C0 (void)
{
    VIC_SpuriousInt = VIC_I2C0;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummySPI (void)
{
    VIC_SpuriousInt = VIC_SSP;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummySSP (void)
{
    VIC_SpuriousInt = VIC_SSP;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyPLL (void)
{
    VIC_SpuriousInt = VIC_PLL;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyRTC (void)
{
    VIC_SpuriousInt = VIC_RTC;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyEINT0 (void)
{
    VIC_SpuriousInt = VIC_EINT0;
    BSP_VIC_Dummy();
}

static  void  BSP_VIC_DummyEINT1 (void)
{
    VIC_SpuriousInt = VIC_EINT1;
    BSP_VIC_Dummy();
}

⌨️ 快捷键说明

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