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

📄 bsp.c

📁 ucos II 2.85源码 LPC2148keil版的
💻 C
📖 第 1 页 / 共 3 页
字号:
}
#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  tmr_reload;

                                                                /* VIC TIMER #0 Initialization                              */
    VICIntSelect &= ~(1 << VIC_TIMER0);                         /* Enable interrupts                                        */
    VICVectAddr2  = (CPU_INT32U)Tmr_TickISR_Handler;            /* Set the vector address                                   */
    VICVectCntl2  = 0x20 | VIC_TIMER0;                          /* Enable vectored interrupts                               */
    VICIntEnable  = (1 << VIC_TIMER0);                          /* Enable Interrupts                                        */

    pclk_freq     = BSP_CPU_PclkFreq();
    tmr_reload    = pclk_freq / OS_TICKS_PER_SEC;
    T0TCR         = 0;                                          /* Disable timer 0.                                         */
    T0PC          = 0;                                          /* Prescaler is set to no division.                         */

    T0MR0         = tmr_reload;
    T0MCR         = 3;                                          /* Interrupt on MR0 (reset 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
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        BSP_PLL_Init()
*
* Description : Set up and activate the PLL
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  BSP_PLL_Init (void)
{
#if OS_CRITICAL_METHOD == 3                                     /* Allocate storage for CPU status register                 */
    OS_CPU_SR   cpu_sr = 0;
#endif
    CPU_INT16U  loop_ctr;

                                                                /* Configure PLL0, which determines the CPU clock           */
    PLLCFG   = 0x00000023;                                      /* Use PLL values of M = 4 and P = 2                        */
    PLLCON  |= 0x00000001;                                      /* Set the PLL Enable bit                                   */

    OS_ENTER_CRITICAL();
    PLLFEED  = 0xAA;                                            /* Write to the PLL Feed register                           */
    PLLFEED  = 0x55;
    OS_EXIT_CRITICAL();

    loop_ctr = 10000;                                           /* Wait for the PLL to lock into the new frequency          */
    while (((PLLSTAT & DEF_BIT_10) == 0) && (loop_ctr > 0)) {
        loop_ctr--;
    }

    PLLCON  |= 0x00000002;                                      /* Connect the PLL                                          */

    OS_ENTER_CRITICAL();
    PLLFEED  = 0xAA;                                            /* Write to the PLL Feed register                           */
    PLLFEED  = 0x55;
    OS_EXIT_CRITICAL();

    VPBDIV   = 0x00000002;                                      /* Set the VPB frequency to one-half of the CPU clock       */
}


/*
*********************************************************************************************************
*                                          BSP_IO_Init()
*
* Description : Initilize the GPIO pins.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Note(s)     :  (1) The pins P1.36-26 are setup as a Debug port and the pins P1.25-16 are setup as a
*                   trace port (by the last statements in this function).  If pins for one of these
*                   are to be used as GPIO, comment out the appropriate statement.
*
*               (2) Additional hardware may be necessary for using the Trace or Debug capability.
*                   According to section 23.5 of the LPC2148 user manual (UM10139, rev. 02):
*
*                       "To have these pins [P1.25-16] come as a Trace port, connect a
*                        weak bias resistor (4.7 kOhm) between the P1.20/TRACESYNC pin and Vss."
*
*                   Similarly, according to section 22.5 of the LPC2148 user manual,
*
*                       "To have them [pins P1.36-26] come up as a Debug port, connect a weak
*                        bias resistor (4.7-10kOhm depending on the external JTAG circuitry)
*                        between Vss and the P1.26/RTCK pin"
*********************************************************************************************************
*/

static  void  BSP_IO_Init (void)
{
//    SCS      = 0x00000001;                                      /* Fast GPIO registers will be used                         */

    PINSEL0  = 0x00000000;

    IO0DIR  &= ~GPIO0_INT1;                                     /* Push button INT1                                         */
    IO1DIR  |=  GPIO1_LEDS;                                     /* LEDs                                                     */

#ifdef DISP_MODULE_PRESENT
    DispRW_High();
#endif

                                                                /* The following statements setup the Trace/Debug           */
                                                                /* capabilitiy. If the pins indicated are to be used as     */
                                                                /* GPIO, remove or comment out these statements.            */

    PINSEL2  |= 0x00000004;                                     /* The pins P1.36-26 will be used as a Debug port.          */
//  PINSEL2  |= 0x00000008;                                     /* The pins P1.25-16 will be used as a Trace port.          */
}


/*
*********************************************************************************************************
*                                             BSP_MAM_Init()
*
* Description : Initialize the memory acceleration module.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  BSP_MAM_Init (void)
{
    MAMCR  = 0x00;                                              /* Disable the Memory Accelerator Module                    */
    MAMTIM = 0x03;                                              /* MAM fetch cycles are 3 CCLKs in duration                 */
    MAMCR  = 0x02;                                              /* Enable the Memory Accelerator Module                     */
}

/*
*********************************************************************************************************
*********************************************************************************************************
**                                            VIC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        Vectored Interrupt Controller
*********************************************************************************************************
*/

static  void  VIC_Init (void)
{
    VICIntEnClear = 0xFFFFFFFF;                                 /* Disable ALL interrupts                                   */
    VICProtection = 0;                                          /* Setup interrupt controller                               */

    VICVectAddr1  = (CPU_INT32U)VIC_DummyWDT;                   /* Set the vector address                                   */
    VICVectAddr2  = (CPU_INT32U)VIC_DummyTIMER0;
    VICVectAddr3  = (CPU_INT32U)VIC_DummyTIMER1;
    VICVectAddr4  = (CPU_INT32U)VIC_DummyUART0;
    VICVectAddr5  = (CPU_INT32U)VIC_DummyUART1;
    VICVectAddr6  = (CPU_INT32U)VIC_DummyPWM0;
    VICVectAddr7  = (CPU_INT32U)VIC_DummyI2C;
    VICVectAddr8  = (CPU_INT32U)VIC_DummySPI;
    VICVectAddr9  = (CPU_INT32U)VIC_DummyRTC;
    VICVectAddr10 = (CPU_INT32U)VIC_DummyEINT0;
    VICVectAddr11 = (CPU_INT32U)VIC_DummyEINT1;
    VICVectAddr12 = (CPU_INT32U)VIC_DummyEINT2;
}

static  void  VIC_Dummy (void)
{
    while (1) {
        (void)VIC_SpuriousInt;
    }
}

static  void  VIC_DummyWDT (void)
{
    VIC_SpuriousInt = VIC_WDT;
    VIC_Dummy();
}

static  void  VIC_DummyTIMER0 (void)
{
    VIC_SpuriousInt = VIC_TIMER0;
    VIC_Dummy();
}

static  void  VIC_DummyTIMER1 (void)
{
    VIC_SpuriousInt = VIC_TIMER1;
    VIC_Dummy();
}

static  void  VIC_DummyUART0 (void)
{
    VIC_SpuriousInt = VIC_UART0;
    VIC_Dummy();
}

static  void  VIC_DummyUART1 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}

static  void  VIC_DummyPWM0 (void)
{
    VIC_SpuriousInt = VIC_UART1;
    VIC_Dummy();
}

static  void  VIC_DummyI2C (void)
{
    VIC_SpuriousInt = VIC_I2C;
    VIC_Dummy();
}

static  void  VIC_DummySPI (void)
{
    VIC_SpuriousInt = VIC_SPI;
    VIC_Dummy();
}

static  void  VIC_DummyRTC (void)
{
    VIC_SpuriousInt = VIC_RTC;
    VIC_Dummy();
}

static  void  VIC_DummyEINT0 (void)
{
    VIC_SpuriousInt = VIC_EINT0;
    VIC_Dummy();
}

static  void  VIC_DummyEINT1 (void)
{
    VIC_SpuriousInt = VIC_EINT1;
    VIC_Dummy();
}

static  void  VIC_DummyEINT2 (void)
{
    VIC_SpuriousInt = VIC_EINT2;
    VIC_Dummy();
}

⌨️ 快捷键说明

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