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

📄 bsp.c

📁 可以在ARM嵌入式单片机上运行的uCOS源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                              LED TOGGLE
*
* Description : This function is used to alternate the state of an LED
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want ALL the LEDs to toggle
*                      1    toggle User LED 0 on the board
*                      .
*                      .
*                      3    toggle User LED 2 on the board
*********************************************************************************************************
*/

void  LED_Toggle (INT8U led)
{
#if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    OS_CPU_SR  cpu_sr;
#endif    


    OS_ENTER_CRITICAL();
    switch (led) {
        case 0:
             LED_Image ^= 0xFF;
             LED_PORT   = LED_Image;
             break;

        case 1:
             LED_Image ^= 0x01;
             LED_PORT   = LED_Image;
             break;

        case 2:
             LED_Image ^= 0x02;
             LED_PORT   = LED_Image;
             break;

        case 3:
             GPIOB->dr ^= 0x02;
             break;
    }
    OS_EXIT_CRITICAL();
}


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


#if 1   
    pfnct = (PFNCT)VIC->vectoraddr;             /* Read the interrupt vector from the VIC               */
    if (pfnct != (PFNCT)0) {                    /* Make sure we don't have a NULL pointer               */
        (*pfnct)();                             /* Execute the ISR for the interrupting device          */
    }
#else    
    pfnct = (PFNCT)VIC->vectoraddr;             /* Read the interrupt vector from the VIC               */
    while (pfnct != (PFNCT)0) {                 /* Make sure we don't have a NULL pointer               */
      (*pfnct)();                               /* Execute the ISR for the interrupting device          */
        pfnct = (PFNCT)VIC->vectoraddr;         /* Read the interrupt vector from the VIC               */
    }
#endif    
}

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


#if 1   
    pfnct = (PFNCT)VIC->vectoraddr;             /* Read the interrupt vector from the VIC               */
    if (pfnct != (PFNCT)0) {                    /* Make sure we don't have a NULL pointer               */
        (*pfnct)();                             /* Execute the ISR for the interrupting device          */
    }
#else    
    pfnct = (PFNCT)VIC->vectoraddr;             /* Read the interrupt vector from the VIC               */
    while (pfnct != (PFNCT)0) {                 /* Make sure we don't have a NULL pointer               */
      (*pfnct)();                               /* Execute the ISR for the interrupting device          */
        pfnct = (PFNCT)VIC->vectoraddr;         /* Read the interrupt vector from the VIC               */
    }
#endif    
}

/*
*********************************************************************************************************
*                          READ TIMER USED TO MEASURE INTERRUPT DISABLE TIME
*
* Description : This function is called to read the current counts of the interrupt disable time 
*               measurement timer.  It is assumed that the timer used for this measurement is a free-running
*               16 bit timer.  
*
*               Timer #1 of the LH79520 is used.  This is a down-timer and the counts are inverted to make
*               the timer look as an up counter.
*               
* Arguments   : none
*
* Returns     ; The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/

#if OS_CPU_INT_DIS_MEAS_EN > 0
INT16U  OS_CPU_IntDisMeasTmrRd (void)
{
    INT16U  cnts;


    cnts = (INT16U)(~TIMER1->value & 0xFFFF);
    return (cnts);
}
#endif

/*
*********************************************************************************************************
*                                     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 16 bit free running timer.
*
*               Timer #1 of the LH79520 is used.  This is a down-timer and the counts are inverted to make
*               the timer look as an up counter.
*               
* Arguments   : none
*
* Returns     ; The 16 bit counts of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
INT32U  OSView_TmrRd (void)
{
    INT32U  cnts;


    cnts = (INT32U)(~TIMER1->value & 0xFFFF);
    return (cnts);
}
#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).
*
*               We decided to use Timer #0 as the tick interrupt source.
*
* Arguments   : none
*
* Notes       :
*********************************************************************************************************
*/

void  Tmr_Init (void)
{
    TIMER0->clear       = 0;                 /* Disable Timer #0                                       */
    TIMER0->load        = BSP_LH79520_CLK / 16;
    TIMER0->control     = TMRCTRL_DISABLE | TMRCTRL_MODE_PERIODIC | TMRCTRL_PRESCALE16;

    TIMER1->clear       = 0;                 /* Enable Timer #1 for interrupt disable time measurement */
    TIMER1->load        = 0xFFFF;
    TIMER1->control     = TMRCTRL_ENABLE  | TMRCTRL_MODE_FREERUN  | TMRCTRL_PRESCALE1;

    TIMER2->clear       = 0;                 /* DISABLE Timer #2                                       */
    TIMER2->load        = BSP_LH79520_CLK / 16 / 100;
    TIMER2->control     = TMRCTRL_DISABLE | TMRCTRL_MODE_PERIODIC | TMRCTRL_PRESCALE16;
                                             
    TIMER3->clear       = 0;                 /* DISABLE Timer #3                                       */
    TIMER3->load        = BSP_LH79520_CLK / 16 / 100;
    TIMER3->control     = TMRCTRL_DISABLE | TMRCTRL_MODE_PERIODIC | TMRCTRL_PRESCALE16;
}

/*
*********************************************************************************************************
*                                       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)
{
    TIMER0->clear       = 0;                          /* Enable Timer #0 for uC/OS-II Tick Interrupts  */
    TIMER0->load        = BSP_LH79520_CLK / 16 / OS_TICKS_PER_SEC;
    TIMER0->control     = TMRCTRL_ENABLE  | TMRCTRL_MODE_PERIODIC | TMRCTRL_PRESCALE16;

                                                      /* Setup the interrupt vector for the tick ISR   */
                                                      /*    Timer interrupt is a medium priority       */
    VIC->vectcntl[VIC_VECT_OS_TICK] = VIC_VECTCNTL_ENABLE | VIC_TIMER0;
    VIC->vectaddr[VIC_VECT_OS_TICK] = (INT32U)Tmr_TickISR_Handler;
    VIC->intenable                  = _BIT(VIC_TIMER0);
}

/*
*********************************************************************************************************
*                                          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)
{
    TIMER0->clear   = 0x00000000L;              /* Clear the tick interrupt source                     */
    VIC->vectoraddr = 0x00000000L;              /* Clear the vector address register                   */

    OSTimeTick();                               /* Call uC/OS-II's OSTimeTick() to signal a tick       */
}

⌨️ 快捷键说明

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