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

📄 bsp.c

📁 uCOS-II example for MC9S12DPxxx
💻 C
📖 第 1 页 / 共 2 页
字号:
*               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 0 chooses output compare #0 as the ticker source
*                   OS_TICK_OC set to 1 chooses output compare #1 as the ticker source
*                   OS_TICK_OC set to 2 chooses output compare #2 as the ticker source
*                   OS_TICK_OC set to 3 chooses output compare #3 as the ticker source
*                   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
*********************************************************************************************************
*/

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 == 0
    TIOS  |= 0x01;                                                      /* Make channel an output compare                           */
    TC0    = TCNT + OSTickCnts;                                         /* Set TC0 to present time + OS_TICK_OC_CNTS                */
    TIE |= 0x01;                                                        /* Enable OC4 interrupt.                                    */
#endif

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

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

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

#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() (located in the OS_CPU_C.C)
*               when a tick interrupt occurs.
*
* Arguments   : none
*********************************************************************************************************
*/

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

#if OS_TICK_OC == 1 
    TFLG1 |= 0x02;                                                      /* Clear interrupt                                          */
    TC1   += OSTickCnts;                                                /* Set TC1 to present time + OS_TICK_OC_CNTS                */
#endif

#if OS_TICK_OC == 2
    TFLG1 |= 0x04;                                                      /* Clear interrupt                                          */
    TC2   += OSTickCnts;                                                /* Set TC2 to present time + OS_TICK_OC_CNTS                */
#endif

#if OS_TICK_OC == 3
    TFLG1 |= 0x08;                                                      /* Clear interrupt                                          */
    TC3   += OSTickCnts;                                                /* Set TC3 to present time + OS_TICK_OC_CNTS                */
#endif

#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();                                                       /* Inform the OS about the Time Tick                        */
}


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


/*
*********************************************************************************************************
*                                 uC/LCD Display Hardware Initialization
*
* Description : DispInitPort() is responsible for initializing the hardware used to interface with the 
*               LCD module. DispInitPort() is called by DispInit().
*
* Arguments   : None
*
* Callers     : DispInit() from lcd.c
*
* Notes       : 1) RW is permanently pulled LOW in hardware. Under normal circumstances, it too would 
*                  have to be configured as an output pin.
*********************************************************************************************************
*/
#if (uC_LCD_MODULE > 0)
void DispInitPort (void)
{                                                                       
    DDRK |= LCD_BIT_RS    | LCD_BIT_E     | LCD_BIT_DATA0 |             /* Setup RS, E and Data bit 0 lines as outputs              */
            LCD_BIT_DATA1 | LCD_BIT_DATA2 | LCD_BIT_DATA3;				/* Setup the Data Lines 1, 2, 3 as outputs                  */
}
#endif


/*
*********************************************************************************************************
*                                 uC/LCD Display Register Select
*
* Description : DispSel() determines whether data written to the HD44780 goes to the control or data 
*               register.
*
* Arguments   : sel determines whether data written using DispDataWr() goes to the command register 
*               (when sel == DISP_SEL_CMD_REG) or the data register (when sel == DISP_SEL_DATA_REG).
*
* Callers     : Various from lcd.c
*********************************************************************************************************
*/
#if (uC_LCD_MODULE > 0)
void DispSel (INT8U sel)
{
    if (sel == DISP_SEL_CMD_REG) {
        PORTK &= ~LCD_BIT_RS;                                           /* Set the RS control line LOW                              */
    } else {
        PORTK |=  LCD_BIT_RS;                                           /* Set the RS control line HIGH                             */
    } 
}
#endif


/*
*********************************************************************************************************
*                                 uC/LCD Display Data Write
*
* Description : DispDataWr() is used to write a single byte to the LCD module. Depending on the state 
*               of the RS line, the byte will be either sent to the data (RS is 1) or control register 
*               (RS is 0) of the LCD controller.
*
* Arguments   : data is the byte value to write to the LCD controller module. The destination 慽nside

⌨️ 快捷键说明

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