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

📄 bsp.c

📁 LPC2106开发板上面的uCOS移植代码最新版2.83
💻 C
📖 第 1 页 / 共 2 页
字号:
             IOCLR = 1 << (led - 1);
             break;
        default:
             break;
    }
}


/*
*********************************************************************************************************
*                                             LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want to toggle ALL the LEDs
*                      1    toggles LED1  on the board
*                      .
*                      .
*                     16    toggles LED16 on the board
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    CPU_INT32U  are_on;
    CPU_INT32U  are_off;
    CPU_INT32U  is_off;


    switch (led) {
        case 0:
             are_off =  IOPIN ^ 0x0000FFFF;
             are_on  = ~IOPIN ^ 0x0000FFFF;
             IOCLR   =  are_on;
             IOSET   =  are_off;
             break;

        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
        case 16:
             is_off  = IOPIN ^ (1 << (led - 1));
             if (is_off) {
                 IOSET = 1 << (led - 1);
             } else {
                 IOCLR = 1 << (led - 1);
             }
             break;
        default:
             break;
    }
}


/*
*********************************************************************************************************
*                                         GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments   : push_button    is the number of the push button to probe
*                              1    probe the push button B1 (INT0)
*                              2    probe the push button B2 (ISP/INT1)
*                              4    probe the push button B4 (INT2)
*********************************************************************************************************
*/

CPU_BOOLEAN  PB_GetStatus (CPU_INT08U pb)
{
    CPU_BOOLEAN  status;


    status = DEF_FALSE;
    switch (pb) {
        case 1:
             if ((IOPIN & (1 << 14)) == 0) {
                 return (DEF_TRUE);
             }
             break;

        case 2:
             if ((IOPIN & (1 << 15)) == 0) {
                 return (DEF_TRUE);
             }
             break;

        case 4:
             if ((IOPIN & (1 << 16)) == 0) {
                 return (DEF_TRUE);
             }
             break;

        default:
             break;
    }

    return (status);
}


/*
*********************************************************************************************************
*                              PB EXTERNAL INTERRUPT INITIALIZATION
*
* Description : The external interrupt is configured to respond to change in the push buttons.  An
*               interrupt will be generated on a rising edge.
*
* Arguments   : isr     is the ISR which will receive the interrupt.
*
* Returns     : none
*********************************************************************************************************
*/

void  PB_EINT1_Init (void (*isr)(void))
{
    VICIntSelect       &= ~(1 << VIC_EINT1);                    /* Enable interrupts                                        */
    VICVectAddr11       = (CPU_INT32U)isr;                      /* Set the vector address                                   */
    VICVectCntl11       = 0x20 | VIC_EINT1;                     /* Enable vectored interrupts                               */
    VICIntEnable        = (1 << VIC_EINT1);                     /* Enable Interrupts                                        */
}

void  PB_EINT2_Init (void (*isr)(void))
{
    VICIntSelect       &= ~(1 << VIC_EINT2);                    /* Enable interrupts                                        */
    VICVectAddr12       = (CPU_INT32U)isr;                      /* Set the vector address                                   */
    VICVectCntl12       = 0x20 | VIC_EINT2;                     /* Enable vectored interrupts                               */
    VICIntEnable        = (1 << VIC_EINT2);                     /* Enable Interrupts                                        */
}


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

void  OS_CPU_ExceptHndlr (CPU_INT32U  except_id)
{
    BSP_PFNCT   pfnct;


    if ((except_id == OS_CPU_ARM_EXCEPT_IRQ) ||
        (except_id == OS_CPU_ARM_EXCEPT_IRQ)) {

        pfnct = (BSP_PFNCT)VICVectAddr;                         /* Read the interrupt vector from the VIC                   */
        if (pfnct != (BSP_PFNCT)0) {                            /* Make sure we don't have a NULL pointer                   */
          (*pfnct)();                                           /* Execute the ISR for the interrupting device              */
        }
    }
}


/*
*********************************************************************************************************
*                                     INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
*               used to make time measurements.
*
* Arguments   : none
*
* Returns     ; none
*
* Note(s)     : This function is EMPTY because the timer is initialized elsewhere.
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
void  OSView_TmrInit (void)
{
                                                                /* TIMER #1 Initialization                                  */
    T1TCR               = 0;                                    /* Disable timer 1.                                         */
    T1PC                = 0;                                    /* Prescaler is set to no division.                         */
    T1TCR               = 1;                                    /* Enable timer 1                                           */
}
#endif


/*
*********************************************************************************************************
*                                     READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 32 bit free running timer.
*
*               Timer #0 of the LPC2000 is used.  This is an UP-timer.
*
* Arguments   : none
*
* Returns     ; The 32 bit counts of the timer assuming the timer (MUST be an UP counter).
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
CPU_INT32U  OSView_TmrRd (void)
{
    return ((CPU_INT32U)T1TC);
}
#endif


/*
*********************************************************************************************************
*                                       TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
*               interrupts every 1 to 100 mS).
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U  peripheral_clk_freq;


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

    peripheral_clk_freq = BSP_CPU_ClkFreqPeripheral();

    T0TCR               = 0;                                    /* Disable timer 0.                                         */
    T0PC                = 0;                                    /* Prescaler is set to no division.                         */

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

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


/*
*********************************************************************************************************
*                                         TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    T0IR        = 0xFF;                                         /* Clear timer #0 interrupt                                 */
                                                                /* Reload 'relative' to current interrupt time              */

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


/*
*********************************************************************************************************
*                           VECTORED INTERRUPT CONTROLLER INITIALIZATION
*
* Description : This function initializes the VIC vectors to dummy handlers.
*
* Arguments   : None.
*
* Returns     : None.
*********************************************************************************************************
*/

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

    VICVectAddr1  = (INT32U)VIC_DummyWDT;                       /* Set the vector address                                   */
    VICVectAddr2  = (INT32U)VIC_DummyTIMER0;
    VICVectAddr3  = (INT32U)VIC_DummyTIMER1;
    VICVectAddr4  = (INT32U)VIC_DummyUART0;
    VICVectAddr5  = (INT32U)VIC_DummyUART1;
    VICVectAddr6  = (INT32U)VIC_DummyPWM0;
    VICVectAddr7  = (INT32U)VIC_DummyI2C;
    VICVectAddr8  = (INT32U)VIC_DummySPI;
    VICVectAddr9  = (INT32U)VIC_DummyRTC;
    VICVectAddr10 = (INT32U)VIC_DummyEINT0;
    VICVectAddr11 = (INT32U)VIC_DummyEINT1;
    VICVectAddr12 = (INT32U)VIC_DummyEINT2;
}


/*
*********************************************************************************************************
*                         VECTORED INTERRUPT CONTROLLER DUMMY HANDLERS
*
* Description : These are the dummy handlers for the VIC vecotrs.
*
* Arguments   : None.
*
* Returns     : None.
*********************************************************************************************************
*/

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

static  void  VIC_DummyWDT (void)
{
    VIC_SpuriousInt = VIC_WDT;
    VIC_Dummy();
}

static  void  VIC_DummyTIMER0 (void)
{
    VIC_SpuriousInt = VIC_TIMER0;
    VIC_Dummy();
}

static  void  VIC_DummyTIMER1 (void)
{
    VIC_SpuriousInt = VIC_TIMER1;
    VIC_Dummy();
}

static  void  VIC_DummyUART0 (void)
{
    VIC_SpuriousInt = VIC_UART0;
    VIC_Dummy();
}

static  void  VIC_DummyUART1 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}

static  void  VIC_DummyPWM0 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}

static  void  VIC_DummyI2C (void)
{
    VIC_SpuriousInt = VIC_I2C;
    VIC_Dummy();
}

static  void  VIC_DummySPI (void)
{
    VIC_SpuriousInt = VIC_SPI;
    VIC_Dummy();
}

static  void  VIC_DummyRTC (void)
{
    VIC_SpuriousInt = VIC_RTC;
    VIC_Dummy();
}

static  void  VIC_DummyEINT0 (void)
{
    VIC_SpuriousInt = VIC_EINT0;
    VIC_Dummy();
}

static  void  VIC_DummyEINT1 (void)
{
    VIC_SpuriousInt = VIC_EINT1;
    VIC_Dummy();
}

static  void  VIC_DummyEINT2 (void)
{
    VIC_SpuriousInt = VIC_EINT2;
    VIC_Dummy();
}

⌨️ 快捷键说明

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