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

📄 bsp.c

📁 UCOS-II对freescale的MC9S12NE64的移植范例
💻 C
📖 第 1 页 / 共 2 页
字号:
    }
}


void  LED_On (INT8U led)
{
    switch (led) {
         case 0:
             PTG |= 0x01;
             break;

        case 1:
             PTG |= 0x02;
             break;
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     uC/OS-II TICK ISR INITIALIZATION
*
* Description : This function is used to initialize one of the eight output compares to generate an
*               interrupt at the desired tick rate.  You must decide which output compare you will be
*               using by setting the configuration variable OS_TICK_OC (see OS_CFG.H and also OS_CPU_A.S) 
*               to 0..7 depending on which output compare to use.
*                   OS_TICK_OC set to 4 chooses output compare #4 as the ticker source
*                   OS_TICK_OC set to 5 chooses output compare #5 as the ticker source
*                   OS_TICK_OC set to 6 chooses output compare #6 as the ticker source
*                   OS_TICK_OC set to 7 chooses output compare #7 as the ticker source
* Arguments   : none
* Notes       : 1) It is assumed that you have set the prescaler rate of the free running timer within
*                  the first 64 E clock cycles of the 68HC12.
*               2) CPU registers are define in IO.H (see COSMIC compiler) and in OS_CPU_A.S.
*********************************************************************************************************
*/

static void  OSTickISR_Init (void)
{
    INT32U cpu_frq;
    INT32U bus_frq;
    INT8U  ECT_Prescaler;    


    cpu_frq = BSP_CPU_ClkFreq();            /* Get the current CPU frequency                           */
    bus_frq = cpu_frq / 2;                  /* Derive the BUS frequency from the CPU frequency         */
      
    ECT_Prescaler = TSCR2 & 0x07;           /* Get the prescaler value in the control register         */
    
    ECT_Prescaler = (1 << ECT_Prescaler);   /* Calculate the correct prescaler value from the reg val  */
    
                                            /* Calculate the nbr of ticks for the interrupt period     */ 
    OSTickCnts    = (INT16U)((bus_frq / (ECT_Prescaler * OS_TICKS_PER_SEC)) - 1); 

#if OS_TICK_OC == 4
    TIOS  |= 0x10;                          /* Make channel an output compare                          */
    TC4    = TCNT + OSTickCnts;             /* Set TC4 to present time + OS_TICK_OC_CNTS               */
    TIE |= 0x10;                            /* Enable OC4 interrupt.                                   */
#endif

#if OS_TICK_OC == 5
    TIOS  |= 0x20;                          /* Make channel an output compare                          */
    TC5    = TCNT + OSTickCnts;             /* Set TC5 to present time + OS_TICK_OC_CNTS               */
    TIE |= 0x20;                            /* Enable OC5 interrupt.                                   */
#endif

#if OS_TICK_OC == 6
    TIOS  |= 0x40;                          /* Make channel an output compare                          */
    TC6    = TCNT + OSTickCnts;             /* Set TC6 to present time + OS_TICK_OC_CNTS               */
    TIE |= 0x40;                            /* Enable OC6 interrupt.                                   */
#endif

#if OS_TICK_OC == 7
    TIOS  |= 0x80;                          /* Make channel an output compare                          */
    TC7    = TCNT + OSTickCnts;             /* Set TC7 to present time + OS_TICK_OC_CNTS               */
    TIE |= 0x80;                            /* Enable OC7 interrupt.                                   */
#endif

    TSCR1 = 0xC0;                           /* Enable counter & disable counter in background mode     */
}


/*
*********************************************************************************************************
*                                      uC/OS-II TICK ISR HANDLER
*
* Description : This function is called by OSTickISR() when a tick interrupt occurs.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OSTickISR_Handler (void)
{
#if OS_TICK_OC == 4
    TFLG1 |= 0x10;                          /* Clear interrupt                                         */
    TC4   += OSTickCnts;                    /* Set TC4 to present time + OS_TICK_OC_CNTS               */
#endif

#if OS_TICK_OC == 5
    TFLG1 |= 0x20;                          /* Clear interrupt                                         */
    TC5   += OSTickCnts;                    /* Set TC5 to present time + OS_TICK_OC_CNTS               */
#endif

#if OS_TICK_OC == 6
    TFLG1 |= 0x40;                          /* Clear interrupt                                         */
    TC6   += OSTickCnts;                    /* Set TC6 to present time + OS_TICK_OC_CNTS               */
#endif

#if OS_TICK_OC == 7
    TFLG1 |= 0x80;                          /* Clear interrupt                                         */
    TC7   += OSTickCnts;                    /* Set TC7 to present time + OS_TICK_OC_CNTS               */
#endif

    OSTimeTick();                           /* Notify uC/OS-II that a tick has occurred                */
}

/*
*********************************************************************************************************
*                                 uIP OS TIME DELAY
*
* Description : This function delays a specified number of milliseconds using uC/OS-II thus
*               preventing polling for time.
*
* Notes       : This function replaces the user defined delay_ms() found in timer.c / timer.h
*               which is often implented using polling.
*********************************************************************************************************
*/

void  BSP_DlyMS (INT8U ms)
{
    OSTimeDlyHMSM (0, 0, 0, ms);    
}

/*
*********************************************************************************************************
*                                 Set the ECT Prescaler
*
* Description : This function configures the ECT prescaler during SYSTEM initialization.
*
* Callers     : BSP_Init()
*
* Notes       : This function should be called during system init, ideally fro BSP_Init().
*               Changing the Prescaler during run-time could impact several modules. Be
*               sure to use extreme caution when calling this function.
*********************************************************************************************************
*/

static  void  BSP_SetECT_Prescaler (INT8U prescaler)
{
    TSCR2 &= ~TSCR2_PR_MASK;               /* Clear all prescaler bits                                 */
    
    switch (prescaler) {
        case 1:
             TSCR2 &= ~TSCR2_PR_MASK;      /* Set a prescaler of 1                                     */
             break;

        case   2:
             TSCR2 |= 0x01;                /* Set a prescaler of 2                                     */        
             break;

        case   4:
             TSCR2 |= 0x02;                /* Set a prescaler of 4                                     */        
             break;

        case   8:
             TSCR2 |= 0x03;                /* Set a prescaler of 8                                     */        
             break;

        case  16:
             TSCR2 |= 0x04;                /* Set a prescaler of 16                                    */        
             break;

        case  32:
             TSCR2 |= 0x05;                /* Set a prescaler of 32                                    */        
             break;

        case  64:
             TSCR2 |= 0x06;                /* Set a prescaler of 64                                    */        
             break;

        case 128:
             TSCR2 |= 0x07;                /* Set a prescaler of 128                                   */        
             break;

        default:
             TSCR2 |= 0x02;                /* Set a prescaler of 4 if the passed value is invalid      */        
             break;             
             
    }
}

⌨️ 快捷键说明

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