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

📄 os_viewc.c

📁 lpc2478开发板基于IAR编译器移植ucos实验例程
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                            uC/OS-View PORT
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                            uC/OS-View PORT
*
*                                             NXP LPC2468
*
* Filename      : os_viewc.c
*********************************************************************************************************
*/

#include <includes.h>

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

/*
*********************************************************************************************************
*                                           EXIT uC/OS-View
*
* Description: This function is called if your target needs to 'uninstall' uC/OS-View.
*
* Arguments   : none
*
* Returns     ; none
*********************************************************************************************************
*/

void  OSView_Exit (void)
{
    ;
}

/*
*********************************************************************************************************
*                                           Obtain CPU name
*
* Description: This function is used to fetch the CPU name.
*
* Arguments   : s   is a pointer to a string in which the CPU name will be stored.
*
* Returns     ; none.
*********************************************************************************************************
*/

void  OSView_GetCPUName (INT8U *s)
{
    INT8U  cpu_clk_freq;


    cpu_clk_freq = (INT8U)(BSP_CPU_ClkFreq() / 1000000L);
    (void)OS_StrCopy(s, "NXP LPC2468 (xx MHz)");
    s[13] = cpu_clk_freq / 10 + '0';
    s[14] = cpu_clk_freq % 10 + '0';
}

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*
* Description: These functions return the base and size of the interrupt stack, if used.
*
* Arguments   : none
*
* Returns     ; Stack location.
*
* Notes       : Because no ISR stack is used, these functions return zero.
*********************************************************************************************************
*/

INT32U  OSView_GetIntStkBase (void)
{
    return (0);                                                         /* We are not using an ISR stack                            */
}


INT32U  OSView_GetIntStkSize (void)
{
    return (0);                                                         /* We are not using an ISR stack                            */
}

/*
*********************************************************************************************************
*                                    INITIALIZE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
*              but may have to be tailored a little (regarding the clock frequency). Of course the same
*              holds true if for some reason you choose to use another timer.
*
* Arguments   : baud_rate   is the intended baud rate for the port.
*
* Returns     ; none.
*
* Note(s)    : 1) This function assumes that a free running timer has been initialized.  The timer can
*                 either be a 16 bits or 32 bits timer.  Your application needs to provide a function
*                 called OSView_TmrRd() that reads the current counts of this timer.  The free running
*                 timer is initialized by the BSP function OSView_TmrInit().
*********************************************************************************************************
*/

void  OSView_InitTarget (INT32U baud_rate)
{
    INT16U     div;                                                     /* Baud rate divisor                                        */
    INT8U      divlo;
    INT8U      divhi;
    INT8U      lcr;										                /* Line Control Register                                    */
    INT32U     p_clk_freq;
    INT32U     pinsel;


#if OS_CRITICAL_METHOD == 3                                             /* Allocate storage for CPU status register                 */
    OS_CPU_SR  cpu_sr    = 0;
#endif


    OSView_TmrInit();                                                   /* Initialize the free running timer                        */

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
                                                                        /* Compute divisor for desired baud rate                    */
    p_clk_freq      =   BSP_CPU_PclkFreq(PCLK_UART0);                   /* Get the CPU clock frequency                              */

    div             =  (INT16U)(((2 * p_clk_freq / 16 / baud_rate) + 1) / 2);
    divlo           =   div & 0x00FF;                                   /* Split divisor into LOW and HIGH bytes                    */
    divhi           =  (div >> 8) & 0x00FF;
    lcr             =   0x03;                                           /* 8 Bits, 1 Stop, No Parity                                */

    OS_ENTER_CRITICAL();
                                                                        /* Configure P0.2 & P0.3 for UART0                          */
    pinsel          = PINSEL0;
    pinsel         &= 0xFFFFFF0F;
    pinsel         |= 0x00000050;
    PINSEL0         = pinsel;

    U0LCR           =   DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U0DLL           =   divlo;                                          /* Load divisor                                             */
    U0DLM           =   divhi;
    U0LCR           =   lcr;                                            /* Set line control register (Bit 8 is 0)                   */
    U0IER           =   0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U0FCR           =   0x07;                                           /* Enable FIFO, flush Rx & Tx                               */
    OS_EXIT_CRITICAL();
                                                                        /* VIC UART #1 Initialization                               */
    VICIntSelect   &= ~(1 << VIC_UART0);                                /* Enable interrupts                                        */
    VICVectAddr6    =  (INT32U)OSView_RxTxISRHandler;                   /* Set the vector address                                   */
    VICIntEnable    =  (1 << VIC_UART0);                                /* Enable Interrupts                                        */
#endif



#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
                                                                        /* Compute divisor for desired baud rate                    */
    p_clk_freq      =   BSP_CPU_PclkFreq(PCLK_UART1);                   /* Get the CPU clock frequency                              */

    div             =  (INT16U)(((2 * p_clk_freq / 16 / baud_rate) + 1) / 2);
    divlo           =   div & 0x00FF;                                   /* Split divisor into LOW and HIGH bytes                    */
    divhi           =  (div >> 8) & 0x00FF;
    lcr             =   0x03;                                           /* 8 Bits, 1 Stop, No Parity                                */

    OS_ENTER_CRITICAL();
                                                                        /* Configure P3.16 & P3.17 for UART1                        */
    pinsel          = PINSEL7;
    pinsel         &= 0xFFFFFFF0;
    pinsel         |= 0x0000000F;
    PINSEL7         = pinsel;

    U1LCR           =   DEF_BIT_07;                                     /* Set divisor access bit                                   */
    U1DLL           =   divlo;                                          /* Load divisor                                             */
    U1DLM           =   divhi;
    U1LCR           =   lcr;                                            /* Set line control register (Bit 8 is 0)                   */
    U1IER           =   0x00;                                           /* Disable both Rx and Tx interrupts                        */
    U1FCR           =   0x07;                                           /* Enable FIFO, flush Rx & Tx                               */
    OS_EXIT_CRITICAL();
                                                                        /* VIC UART #1 Initialization                               */
    VICIntSelect   &= ~(1 << VIC_UART1);                                /* Enable interrupts                                        */
    VICVectAddr7    =  (INT32U)OSView_RxTxISRHandler;                   /* Set the vector address                                   */

⌨️ 快捷键说明

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