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

📄 bsp.c

📁 lpc2378 iar开发环境 嵌入系统程序
💻 C
📖 第 1 页 / 共 3 页
字号:
}
#endif

/*
*********************************************************************************************************
*                                         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
*********************************************************************************************************
*/

CPU_BOOLEAN  PB_GetStatus (CPU_INT08U push_button_id)
{
    BOOLEAN  status;


    status = DEF_FALSE;

    switch (push_button_id) {
        case 1:
             if ((FIO2PIN & (1 << 10)) == 0) {
                 status =  (DEF_TRUE);
             }
             break;

        default:
             break;
    }

    return (status);
}

/*
*********************************************************************************************************
*                                         LED 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)
{
    LED_Off(0);                                                         /* 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
*                      .
*                      .
*                      8    turns ON LED8 on the board
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    if (led == 0) {
        FIO2SET    =    0xFF;                                           /* Turn on ALL LEDs                                        */
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        FIO2SET =  (1 << led);                                          /* Turn on the selected LED                                 */
    }
}

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

void  LED_Off (CPU_INT08U led)
{
    if (led == 0) {
        FIO2CLR    =    0xFF;                                           /* Turn off ALL LEDs                                        */
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        FIO2CLR =  (1 << led);                                          /* Turn off the selected LED                                */
    }
}

/*
*********************************************************************************************************
*                                             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
*                      .
*                      .
*                      8    toggles LED8 on the board
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    CPU_INT08U  status;


    if (led == 0) {
        status     =    FIO2PIN;
        FIO2SET    =   ~status;
        FIO2CLR    =    status;
    }

    if ((led >= 1) && (led <= 8)) {
        led--;                                                          /* Ex: If led is 1, then subtract 1 to indicate bit 0       */
        if ((FIO2PIN & (1 << led)) == 0) {                              /* If the LED is currently off                              */
            FIO2SET =  (1 << 0);                                        /* Turn on the selected LED                                 */
        } else {
            FIO2CLR =  (1 << led);                                      /* Turn off the selected LED                                */
        }
    }
}

/*
*********************************************************************************************************
*                                     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)     : 1) This function is EMPTY because the timer is initialized elsewhere.
*               2) BSP_DEBUG must be defined to 0 in order for the shared OS / OS-View
*                  timer to free-run.
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
void  OSView_TmrInit (void)
{
}
#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)
{
    if (OSRunning == TRUE) {
        return ((CPU_INT32U)T0TC);
    } else {
        return (0);
    }
}
#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
*
* Note(s)     : 1) The timer is setup for output compare mode BUT 'MUST' also 'freerun' so that the timer
*                  count goes from 0x00000000 to 0xFFFFFFFF to ALSO be able to read the free running count.
*                  The reason this is needed is because we use the free-running count in uC/OS-View.
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U  cClkFrq;
    CPU_INT32U  pClkFrq;

                                                                        /* VIC timer #0 Initialization                              */
    VICIntSelect       &= ~(1 << VIC_TIMER0);                           /* Configure the timer interrupt as an IRQ source           */
    VICVectAddr4        =  (CPU_INT32U)Tmr_TickISR_Handler;             /* Set the vector address                                   */
    VICIntEnable        =  (1 << VIC_TIMER0);                           /* Enable the timer interrupt source                        */

    cClkFrq             =   BSP_CPU_ClkFreq();                          /* Get the CPU clock frequency                              */
    PCLKSEL0           &= ~(3 << 2);                                    /* Clear the timer 0 PCLK selection bits so PCLKDIV = 4     */
    pClkFrq             =   cClkFrq / 4;                                /* Determine the peripheral clock frequency                 */

    Tmr_ReloadCnts      =   pClkFrq / OS_TICKS_PER_SEC;                 /* Calculate the # of counts necessary for the OS ticker    */

    T0TCR               =  (1 << 1);                                    /* Disable and reset counter 0 and the prescale counter 0   */
    T0TCR              &= ~(1 << 1);                                    /* Clear the reset bit                                      */
    T0PC                =   4;                                          /* Prescaler is set to divider by 4                         */

#if BSP_DEBUG == 0
    T0MR0               =   T0TC + Tmr_ReloadCnts;
    T0MCR               =   1;                                          /* Interrupt on MR0 (match register 0).                     */
#else
    T0MR0               =   Tmr_ReloadCnts;
    T0MCR               =   3;                                          /* Interrupt on MR0 (reset TC), stop TC                     */
#endif
    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
*
* Note(s)     : 1) The timer is 'reloaded' with the count at compare + the time for the next interrupt.
*                  Since we are using 'unsigned' integer math, overflows are irrelevant.
*********************************************************************************************************
*/

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

#if BSP_DEBUG == 0
    T0MR0      += Tmr_ReloadCnts;                                       /* Reload 'relative' to current interrupt time              */
#endif

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

⌨️ 快捷键说明

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