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

📄 bsp.c.2006-04-14.12-44-15.4375

📁 uCOSII 在LPC3180上的移植代码
💻 4375
📖 第 1 页 / 共 4 页
字号:
*
* 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
*                      2    turns OFF LED2  on the board
*********************************************************************************************************
*/

void  LED_Off (INT8U led)
{
    switch (led) {
        case 0:
             PIO_OUTP_SET  = LED_1;                                         /* Turn off LED 1                                       */
             PIO_OUTP_SET  = LED_2;                                         /* Turn off LED 2                                       */
             break;

        case 1:
             PIO_OUTP_SET  = LED_1;                                         /* Turn off LED 1                                       */
             break;

        case 2:
             PIO_OUTP_SET  = LED_2;                                         /* Turn off LED 2                                       */
             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
*                      2    toggles LED2  on the board
*********************************************************************************************************
*/

void  LED_Toggle (INT8U led)
{
    INT32U  status;


    status                 =  PIO_OUTP_STATE & (LED_1 | LED_2);             /* Get the current LED status                           */

    switch (led) {
        case 0:
             status       ^=  (LED_1 | LED_2);                              /* Toggle the bits for LED_1 and LED_2                  */
             PIO_OUTP_SET  =   status;                                      /* If the LEDs are on, turn them off by setting bits    */
             PIO_OUTP_CLR  = (~status & (LED_1 | LED_2));                   /* If the LEDs are off, turn them on by clearing bits   */
             break;

        case 1:
             status       ^=  (LED_1);                                      /* Toggle the bit for LED_1                             */
             PIO_OUTP_SET  =   status;                                      /* If the LED is on, turn it off by setting the bit     */
             PIO_OUTP_CLR  = (~status & LED_1);                             /* If the LED is off, turn it on by clearing the bit    */
             break;

        case 2:
             status       ^=  (LED_2);                                      /* Toggle the bit for LED_2                             */
             PIO_OUTP_SET  =   status;                                      /* If the LED is on, turn it off by setting the bit     */
             PIO_OUTP_CLR  = (~status & LED_2);                             /* If the LED is off, turn it on by clearing the bit    */
             break;
    }
}

/*
*********************************************************************************************************
*                                     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)
{
}
#endif

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

#if OS_VIEW_MODULE > 0
INT32U  OSView_TmrRd (void)
{
    if (OSRunning == TRUE) {
        return ((INT32U)HSTIM_COUNTER);
    } 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 and is allowed to free-run from 0x00000000
*                  to 0xFFFFFFFF. This mode of operation is ideal for making accurate time measurements
*                  in the OS Statistics task and OS-View.
*
*               2) The High Speed Timer clock MUST be enabled before any HST register reads or writes
*
*               3) The High Speed Timer clock is the 'Peripheral Clock'
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    INT32U  peripheral_clk_frq;


    TIMCLK_CTRL           |=  (1 << 1);                                     /* Enable the High Speed Timer Clock                    */
    HSTIM_CTRL            &= ~(1 << 0);                                     /* Stop the Timer                                       */
    HSTIM_CTRL            |=  (1 << 1);                                     /* Set the Timer Reset bit (set counter to 0x00000000   */
    HSTIM_CTRL            &= ~(1 << 1);                                     /* Clear the Reset bit (software must release reset)    */


    BSP_IntEn(BSP_MAIN_INT_CTL, 5, BSP_INT_HIGH_LEVEL,                      /* Configure the Interrupt Handler for Timer Int's      */
              BSP_INT_LEVEL_SENSITIVE, Tmr_TickISR_Handler);                /* Interrupt is part of the Main Int. Controller (0)    */
                                                                            /* The interrupt source is bit 5                        */
                                                                            /* the interrupt handler is Tmr_TickISR_Handler()       */

    peripheral_clk_frq     =   BSP_ClkFrqPeripheral();                      /* Get the Peripheral operating frequency               */

    Tmr_ReloadCnts         =  (peripheral_clk_frq / OS_TICKS_PER_SEC) - 1;  /* Determine the number of timer ticks necessary in     */
                                                                            /* order to achieve a tick rate of OS_TICKS_PER_SEC     */
#if BSP_OS_TMR_SEL == 0
    HSTIM_MATCH0           =   Tmr_ReloadCnts;                              /* Set the match compare value if using match reg. 0    */
    HSTIM_INT             |=  (1 << 0);                                     /* Clear the match interrupt for match register 0       */
    HSTIM_MCTRL           |=  (1 << 0);                                     /* Enable Interrupt generation for Match Register  0    */
#endif

#if BSP_OS_TMR_SEL == 1
    HSTIM_MATCH1           =   Tmr_ReloadCnts;                              /* Set the match compare value if using match reg. 1    */
    HSTIM_INT             |=  (1 << 1);                                     /* Clear the match interrupt for match register 1       */
    HSTIM_MCTRL           |=  (1 << 3);                                     /* Enable Interrupt generation for Match Register  1    */
#endif

#if BSP_OS_TMR_SEL == 2
    HSTIM_MATCH2           =   Tmr_ReloadCnts;                              /* Set the match compare value if using match reg. 2    */
    HSTIM_INT             |=  (1 << 2);                                     /* Clear the match interrupt for match register 2       */
    HSTIM_MCTRL           |=  (1 << 6);                                     /* Enale Interrupt generation for Match Register  2     */
#endif

    HSTIM_PCOUNT           =   0;                                           /* Set the Timer Prescaler to 0                         */
    HSTIM_CTRL            |=  (1 << 2);                                     /* Timer stops when the CPU is in debug mode            */
    HSTIM_CTRL            |=  (1 << 0);                                     /* Start the Timer                                      */
}


/*
*********************************************************************************************************
*                                         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.
*
*               2) Updating the Match Compare Register MUST be done before clearing the interrupt.
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
#if BSP_OS_TMR_SEL == 0
    HSTIM_MATCH0          +=   Tmr_ReloadCnts;                              /* Update the match register w/ the next compare value  */
    HSTIM_INT             |=  (1 << 0);                                     /* Clear the match interrupt for match register 0       */
#endif

#if BSP_OS_TMR_SEL == 1
    HSTIM_MATCH1          +=   Tmr_ReloadCnts;                              /* Update the match register w/ the next compare value  */
    HSTIM_INT             |=  (1 << 1);                                     /* Clear the match interrupt for match register 1       */
#endif

#if BSP_OS_TMR_SEL == 2
    HSTIM_MATCH2          +=   Tmr_ReloadCnts;                              /* Update the match register w/ the next compare value  */
    HSTIM_INT             |=  (1 << 2);                                     /* Clear the match interrupt for match register 2       */
#endif

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


⌨️ 快捷键说明

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