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

📄 bsp.c

📁 官方的UCOSii的移植文件
💻 C
📖 第 1 页 / 共 4 页
字号:
    DispDly_uS(100);
    DispE_Low();
}
#endif
#endif                                                                  /* End #ifdef DISP_MODULE_PRESENT                           */

/*
*********************************************************************************************************
*                                               DispDly_uS()
*
* Description : Delay for the specified number of microseconds.
*
* Argument(s) : us      Number of microseconds
*
* Return(s)   : none.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDly_uS (CPU_INT32U us)
{
    CPU_INT32U  us_per_tick;
    CPU_INT32U  ticks;


    us_per_tick = 1000000L / OS_TICKS_PER_SEC;
    ticks       = us / us_per_tick + 1;
    OSTimeDly(ticks);
}
#endif

/*
*********************************************************************************************************
*                                            DispSel()
*
* Description : Change the Register Select control line to the LCD controller to select either
*               command or data register.
*
* Argument(s) : sel         Indicates whether command or data register should be selected:
*
*                           DISP_SEL_CMD_REG    select command register
*                           DISP_SEL_DATA_REG   select data    register
*
* Return(s)   : none.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispSel (CPU_INT08U sel)
{
    if (sel == DISP_SEL_CMD_REG) {
        IO1CLR = GPIO1_LCD_RS;                     	            /* Select the command register (RS low)                     */
    } else {
        IO1SET = GPIO1_LCD_RS;                           	    /* Select the data    register (RS high)                    */
    }
}
#endif

/*
*********************************************************************************************************
*                                      DISPLAY CONTROL LINE FUNCTIONS
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  DispE_High (void)
{
    IO1SET = GPIO1_LCD_E;                           	        /* Raise the LCD Enable pin high                            */
}


static  void  DispE_Low (void)
{
    IO1CLR = GPIO1_LCD_E;                                	    /* Lower the LCD Enable pin                                 */
}


static  void  DispRW_High (void)
{
    IO1SET = GPIO1_LCD_RW;                                  	/* Raise the LCD R/W pin                                    */
}


static  void  DispRW_Low (void)
{
    IO1CLR = GPIO1_LCD_RW;                               	    /* Lower the LCD R/W pin                                    */
}
#endif



/*
*********************************************************************************************************
*********************************************************************************************************
**                                          uC/OS-View FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                              OSView_TmrInit()
*
* Description : Select & initialize a timer for use with uC/OS-View.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

#if (OS_VIEW_MODULE > 0)
void  OSView_TmrInit (void)
{
    T1PR  = 0;
    T1TCR = 0x00000001;                                         /* Enable the timer                                         */

}
#endif


/*
*********************************************************************************************************
*                                         OSView_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
* Return(s)   : The 32 bit counts of the timer.
*********************************************************************************************************
*/

#if (OS_VIEW_MODULE > 0)
CPU_INT32U  OSView_TmrRd (void)
{
    return ((CPU_INT32U)T1TC);
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
*                             uC/Probe PLUG-IN FOR uC/OS-II FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       OSProbe_TmrInit()
*
* Description : Select & initialize a timer for use with the uC/Probe Plug-In for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
void  OSProbe_TmrInit (void)
{
    T1PR  = 0;
    T1TCR = 0x00000001;                                         /* Enable the timer                                         */

}
#endif


/*
*********************************************************************************************************
*                                        OSProbe_TmrRd()
*
* Description : Read the current counts of a 32-bit free running timer.
*
* Argument(s) : none.
*
* Return(s)   : The 32bit counts of the timer.
*********************************************************************************************************
*/

#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U  OSProbe_TmrRd (void)
{
    return ((CPU_INT32U)T1TC);
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
**                                     uC/OS-II TIMER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            Tmr_TickInit()
*
* Description : Initialize uC/OS-II's tick source.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U  pclk_freq;
    CPU_INT32U  rld_cnts;

                                                                /* VIC timer #0 Initialization                              */
    VICIntSelect &= ~(1 << VIC_TIMER0);                         /* Configure the timer interrupt as an IRQ source           */
    VICVectAddr4  =  (CPU_INT32U)Tmr_TickISR_Handler;           /* Set the vector address                                   */
    VICIntEnable  =  (1 << VIC_TIMER0);                         /* Enable the timer interrupt source                        */

    pclk_freq     =   BSP_CPU_PclkFreq(PCLK_TIMER0);            /* Get the peripheral clock frequency                       */

    rld_cnts      =   pclk_freq / OS_TICKS_PER_SEC;             /* Calculate the # of counts necessary for the OS ticker    */

    T0TCR         =  (1 << 1);                                  /* Disable and reset counter 0 and the prescale counter 0   */
    T0TCR         =   0;                                        /* Clear the reset bit                                      */
    T0PC          =   0;                                        /* Prescaler is set to no division                          */

    T0MR0         =   rld_cnts;
    T0MCR         =   3;                                        /* Interrupt on MR0 (reset TC), stop TC                     */

    T0CCR         =   0;                                        /* Capture is disabled.                                     */
    T0EMR         =   0;                                        /* No external match output.                                */
    T0TCR         =   1;                                        /* Enable timer 0                                           */
}


/*
*********************************************************************************************************
*                                       Tmr_TickISR_Handler()
*
* Description : Handle the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    T0IR = 0xFF;                                                /* Clear timer #0 interrupt                                 */

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


/*
*********************************************************************************************************
*********************************************************************************************************
**                                          LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            PLL_Init()
*
* Description : Set up and activate the PLL.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Note(s)     : (1) The PLL output frequency is calculated by:
*
*                           Fcco = 2 * Fin * m / n
*
*                   where
*
*                           Fin is the PLL input clock (here, the main oscillator)
*                           M   is the PLL clock multiplier. The value (M - 1) is programmed in PLLCFG.
*                           N   is the PLL clock divider.    The value (N - 1) is programmed in PLLCFG.
*
*               (2) Fcco must be between 250 and 550 MHz. The ARM Core clock must never exceed 72 MHz.
*                   Set clk_div to divide Fcco accordingly.
*
*               (3) When using the USB device, you must choose Fcco as a multiple of 96 MHz, and then
*                   set clk_div_usb to divide Fcco to exactly 48 MHz.
*
*               (4) In this example
*
*                         Fin         = 12MHz,
*                         M           = 12,
*                         N           =  1,
*                         clk_div     =  6, and
*                         clk_div_usb =  6.
*
*                 Therefore, Fcco        = 2 * Fin * M / N      = (2 * 12 * 12 / 1) = 288MHz.
*                 The processor clock    = (Fcco / clk_div)     = (288MHz / 6)      =  48MHz.
*                 Finally, the USB clock = (Fcco / clk_div_usb) = (288MHz / 6)      =  48MHz.
*
*               (5) A PLL errata on early revisions of the part prevent Fcco from being greater than 288MHz.
*
*               (6) For later revisions, M = 20, clk_div = 8, and clk_div_usb = 10 will yield 60MHz for
*                   the processor clock and 48MHz for the USB clock.
*********************************************************************************************************
*/

static  void  PLL_Init (void)
{
#if CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL /* Allocate storage for CPU status register                 */
    CPU_SR  cpu_sr = 0;
#endif

    CPU_INT32U  m;
    CPU_INT32U  n;
    CPU_INT32U  clk_div;
    CPU_INT32U  clk_div_usb;


    m           = 11;                                           /* PLL Multiplier = 20, MSEL bits = 12 - 1 = 11             */
    n           =  0;                                           /* PLL Divider    =  1, NSEL bits =  1 - 1 =  0             */
    clk_div     =  5;                                           /* Configure the  ARM Core clock div to 6. CCLKSEL =  6 - 1 */
    clk_div_usb =  5;                                           /* Configure the USB clock divider to 6, USBSEL  = 6 - 1    */

    if ((PLLSTAT & DEF_BIT_25) > 0) {                           /* If the PLL is already running                            */
        CPU_CRITICAL_ENTER();
        PLLCON  &= ~DEF_BIT_01;                                 /* Disconnect the PLL                                       */
        PLLFEED  =  0xAA;                                       /* PLL register update sequence, 0xAA, 0x55                 */
        PLLFEED  =  0x55;
        CPU_CRITICAL_EXIT();
    }

    CPU_CRITICAL_ENTER();
    PLLCON   &= ~DEF_BIT_00;                                    /* Disable the PLL                                          */
    PLLFEED   =  0xAA;                                          /* PLL register update sequence, 0xAA, 0x55                 */
    PLLFEED   =  0x55;
    CPU_CRITICAL_EXIT();

    SCS      &= ~DEF_BIT_04;                                    /* OSCRANGE = 0, Main OSC is between 1 and 20 Mhz           */
    SCS      |=  DEF_BIT_05;                                    /* OSCEN = 1, Enable the main oscillator                    */

    while ((SCS &  DEF_BIT_06) == 0) {                          /* Wait until OSCSTAT is set (Main OSC ready to be used)    */
        ;
    }

    CLKSRCSEL = DEF_BIT_00;                                     /* Select main OSC, 12MHz, as the PLL clock source          */

    CPU_CRITICAL_ENTER();
    PLLCFG    = (m << 0) | (n << 16);                           /* Configure the PLL multiplier and divider                 */
    PLLFEED   = 0xAA;                                           /* PLL register update sequence, 0xAA, 0x55                 */
    PLLFEED   = 0x55;
    CPU_CRITICAL_EXIT();

    CPU_CRITICAL_ENTER();
    PLLCON   |= DEF_BIT_00;                                     /* Enable the PLL                                           */
    PLLFEED   = 0xAA;                                           /* PLL register update sequence, 0xAA, 0x55                 */
    PLLFEED   = 0x55;
    CPU_CRITICAL_EXIT();

    CCLKCFG   = clk_div;                                        /* Configure the ARM Core Processor clock divider           */
    USBCLKCFG = clk_div_usb;                                    /* Configure the USB clock divider                          */

    while ((PLLSTAT & DEF_BIT_26) == 0) {                       /* Wait for PLOCK to become set                             */
        ;
    }

    PCLKSEL0  = 0xAAAAAAAA;                                     /* Set peripheral clocks to be half of main clock           */
    PCLKSEL1  = 0x22AAA8AA;

    CPU_CRITICAL_ENTER();
    PLLCON   |= DEF_BIT_01;                                     /* Connect the PLL. The PLL is now the active clock source  */
    PLLFEED   = 0xAA;                                           /* PLL register update sequence, 0xAA, 0x55                 */
    PLLFEED   = 0x55;

⌨️ 快捷键说明

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