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

📄 bsp.c

📁 移植到freescale 9s12系列单片机的uCOSII
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                                (c) Copyright 2004, Micrium, Weston, FL
*                                          All Rights Reserved
*
*
*                                      BOARD SUPPORT PACKAGE (BSP)
*                                         Frescale MC9S12
*
* File : BSP.C
* By   : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>


/*
*********************************************************************************************************
*                                        CONSTANTS
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        PROTOTYPES
*********************************************************************************************************
*/

static  void     PLL_Init(void);            /* Initialize the CPU's PLL                                */
static  void     OSTickISR_Init(void);      /* Initialize the OS Ticker                                */
static  void     LED_Init(void);            /* Initialize the LED hardware                             */

/*
*********************************************************************************************************
*                                        DATATYPES
*
* Notes : 1) The CPU_ISR_FNCT_PTR data type is used to declare pointers to ISR functions in 
*            a more simplistic manner. It is used when setting the Vector Table in BSP_VectSet()
*********************************************************************************************************
*/

typedef  void  near  (*CPU_ISR_FNCT_PTR)(void *); 

/*
*********************************************************************************************************
*                                        GLOBALS
*********************************************************************************************************
*/

static  INT16U  OSTickCnts;

/*
*********************************************************************************************************
*                                        BSP_Init()
*
* Description: Initialize BSP, called from app.c instead of calling all of the internal bsp init functions
*********************************************************************************************************
*/

void BSP_Init (void)
{
    INT32U  sys_clk_frq;
    
    
#if PLL_EN > 0
    PLL_Init();                             /* Initialize the PLL.                                     */ 
    BSP_SetECT_Prescaler(4);                /* When using the PLL, an ECT prescaler > 4 MUST be set in */    
#endif                                      /* order to prevent OSTickCnts overflow during Tick Init   */ 
    
    OSTickISR_Init();
    LED_Init();   
    
    sys_clk_frq  =  BSP_CPU_ClkFreq();      /* Get the SYSCLK frequency in Hz                          */
    sys_clk_frq /=  1000;                   /* Convert the SYSCLK frequency into KHz                   */
    Flash_Init (sys_clk_frq);               /* Initialize on chip Flash for runtime program and erase  */
}


/*
*********************************************************************************************************
*                                        PLL_Init()
*
* Notes: Will HANG the application if PLL fails to initialize!
*********************************************************************************************************
*/

static void PLL_Init (void)
{  
    CLKSEL = 0x00;                          /* Meaning for CLKSEL:
                                                Bit 7: PLLSEL = 0 Keep using OSCCLK until we are ready to switch to PLLCLK
                                                Bit 6: PSTP   = 0 Do not need to go to Pseudo-Stop Mode
                                                Bit 5: SYSWAI = 0 In wait mode system clocks stop.
                                                Bit 4: ROAWAI = 0 Do not reduce oscillator amplitude in wait mode.
                                                Bit 3: PLLWAI = 0 Do not turn off PLL in wait mode
                                                Bit 2: CWAI	= 0 Do not stop the core during wait mode
                                                Bit 1: RTIWAI = 0 Do not stop the RTI in wait mode
                                                Bit 0: COPWAI = 0 Do not stop the COP in wait mode
                                             */  

 
    SYNR   = PLL_CLK_MUL;                   /* Set the desired clock multiplier                        */
    REFDV  = PLL_CLK_DIV;                   /* Set the desired clock divider                           */

 
    PLLCTL = 0xC0;                          /* Meaning for PLLCTL:
                                                Bit 7: CME   = 1; Clock monitor enable - reset if bad clock when set
                                                Bit 6: PLLON = 1; PLL On bit
                                                Bit 5: AUTO  = 0; No automatic control of bandwidth, manual through ACQ
                                                Bit 4: ACQ   = 1; 1 for high bandwidth filter (acquisition); 0 for low (tracking)
                                                Bit 3:            (Not Used by 9s12c32)
                                                Bit 2: PRE   = 0; RTI stops during Pseudo Stop Mode
                                                Bit 1: PCE   = 0; COP diabled during Pseudo STOP mode
                                                Bit 0: SCME  = 1; Crystal Clock Failure -> Use Self Clock mode.                                                  
                                            */
  
    while((CRGFLG & 0x08) == 0) { 	        /* Wait for PLLCLK to stabilize.                           */
        ;				                    /* If the PLL never stabilizes, this will hang forever     */
    }  
  
    CLKSEL_PLLSEL = 1;                      /* Switch to PLL clock                                     */
}


/*
*********************************************************************************************************
*                                        BSP_CPU_ClkFreq()
*
* Description : Returns the CPU operating frequency in Hz. (This is NOT the CPU BUS frequency)
*               However, the bus frequency is (clk_frq / 2)
*********************************************************************************************************
*/

INT32U  BSP_CPU_ClkFreq (void)
{
    INT32U clk_frq;
    
    
    if ((CLKSEL & CLKSEL_PLLSEL_MASK) == CLKSEL_PLLSEL_MASK) {
        clk_frq = ((OSCFREQ * 2) * (PLL_CLK_MUL + 1) / (PLL_CLK_DIV + 1));
    } else {
        clk_frq =  (OSCFREQ);
    }
        
    return  (clk_frq);
}


/*
*********************************************************************************************************
*                                        LED SUPPORT FUNCTIONS
*
* Description : These functions are included to encapsulate the control of LEDs.
*
* Arguments   : led    is the logical LED number of the desired LED to control
*********************************************************************************************************
*/

static void LED_Init (void) 
{  
    //DDRG = 0xFF;
    
    PTH_PTH7 = 1;
    
    DDRH_DDRH7 = 1;
}


void LED_Toggle (INT8U led)
{
/*    switch (led) {
        case 0:
             PTG ^= 0x01;
             break;

        case 1:
             PTG ^= 0x02;
             break;

    } */
    
    PTH_PTH7 ^= 1;
}


void  LED_Off (INT8U led)
{
/*    switch (led) {
         case 0:
             PTG &= ~0x01;
             break;

        case 1:

⌨️ 快捷键说明

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