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

📄 os_viewc.c

📁 基于ucos的arm7 lpc2138的lcd程序
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-View
*
*                                 (c) Copyright 2005, Micrium, Weston, FL
*                                           All Rights Reserved
*
*                                            NXP LPC2000 (ARM7)
*                                             IAR C Compiler
*
*
* Filename   : OS_VIEWc.C
* Version    : V1.20
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*/

#include <includes.h>

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

#define  BIT0      0x01
#define  BIT1      0x02
#define  BIT2      0x04
#define  BIT3      0x08
#define  BIT4      0x10
#define  BIT5      0x20
#define  BIT6      0x40
#define  BIT7      0x80

/*$PAGE*/
/*
*********************************************************************************************************
*                                           EXIT uC/OS-View
*
* Description: This function is called if your target needs to 'uninstall' uC/OS-View.
*
* Note(s)    :
*********************************************************************************************************
*/

void  OSView_Exit (void)
{
}

/*
*********************************************************************************************************
*                                           Obtain CPU name
*********************************************************************************************************
*/

void  OSView_GetCPUName (INT8U *s)
{
    INT8U  cpu_clk_freq;


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

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*********************************************************************************************************
*/

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

/*$PAGE*/
/*
*********************************************************************************************************
*                                    INITIALISE 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.
*
* 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     pinsel;
    INT32U     pclk_freq;
#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          */

                                                         /* Compute divisor for desired baud rate      */
    pclk_freq = BSP_CPU_PclkFreq();
    div       = (INT16U)(((2 * pclk_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                  */

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    OS_ENTER_CRITICAL();
	pinsel              = PINSEL0;					     /* Enable UART0 I/Os                          */
	pinsel             &= 0xFFFFFFF0;
	pinsel             |= 0x00000005;
    PINSEL0             = pinsel;
    U0LCR               = BIT7;                          /* 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               = 0x01;                          /* Enable FIFO, flush Rx & Tx                 */
    OS_EXIT_CRITICAL();
                                                         /* VIC UART #0 Initialization                 */
    VICIntSelect       &= ~(1 << VIC_UART0);             /* Enable interrupts                          */
    VICVectAddr15       = (INT32U)OSView_RxTxISRHandler; /* Set the vector address                     */
    VICVectCntl15       = 0x20 | VIC_UART0;              /* Enable vectored interrupts                 */
    VICIntEnable        =  (1 << VIC_UART0);             /* Enable Interrupts                          */
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    OS_ENTER_CRITICAL();
	pinsel              = PINSEL0;						 /* Enable UART1 I/Os                          */
	pinsel             &= 0xFFF0FFFF;
	pinsel             |= 0x00050000;
    PINSEL0             = pinsel;
    U1LCR               = BIT7;                          /* 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               = 0x01;                          /* Enable FIFO, flush Rx & Tx                 */
    OS_EXIT_CRITICAL();
                                                         /* VIC UART #1 Initialization                 */
    VICIntSelect       &= ~(1 << VIC_UART1);             /* Enable interrupts                          */
    VICVectAddr15       = (INT32U)OSView_RxTxISRHandler; /* Set the vector address                     */
    VICVectCntl15       = 0x20 | VIC_UART1;              /* Enable vectored interrupts                 */
    VICIntEnable        =  (1 << VIC_UART1);             /* Enable Interrupts                          */
#endif
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    U0IER = 0;
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    U1IER = 0;
#endif
}

/*
*********************************************************************************************************
*                                       Enable Rx Interrupts
*********************************************************************************************************
*/

void  OSView_RxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    U0IER = BIT0;
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    U1IER = BIT0;
#endif
}

/*
*********************************************************************************************************
*                                 Rx Communication handler for uC/OS-View
*
* Description: This function is called by OSView_RxISR (see OS_VIEWa.ASM) to process a received
*              character interrupt.
*
* Note(s)    : This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the UART
*              and thus this function is not needed.
*********************************************************************************************************
*/

void  OSView_RxISRHandler (void)
{
}

/*
*********************************************************************************************************
*                                Rx/Tx Communication handler for uC/OS-View
*
* Description: This function is NOT called because the M16C has a separate Rx and Tx ISR.
*********************************************************************************************************
*/

void  OSView_RxTxISRHandler (void)
{
    volatile  INT8U  rx_data;
    volatile  INT8U  lsr;
    volatile  INT8U  iir;



#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    iir = U0IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  0:                                   /* Modem interrupt?                             */
                 break;

            case  2:                                   /* Transmitted character?                       */
                 OSView_TxHandler();
                 break;

            case  4:                                   /* Received a character?                        */
                 lsr     = U0LSR;
                 rx_data = U0RBR;
                 OSView_RxHandler(rx_data);            /* Call the generic Rx handler                  */
                 break;

            case  6:                                   /* Receive Line Status interrupt?               */
                 break;

            case 12:                                   /* CTI interrupt?                               */
                 break;
        }
        iir = U0IIR & 0x0F;
    }
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    iir = U1IIR & 0x0F;
    while (iir != 1) {
        switch (iir) {
            case  0:                                   /* Modem interrupt?                             */
                 break;

            case  2:                                   /* Transmitted character?                       */
                 OSView_TxHandler();
                 break;

            case  4:                                   /* Received a character?                        */
                 lsr     = U1LSR;
                 rx_data = U1RBR;
                 OSView_RxHandler(rx_data);            /* Call the generic Rx handler                  */
                 break;

            case  6:                                   /* Receive Line Status interrupt?               */
                 break;

            case 12:                                   /* CTI interrupt?                               */
                 break;
        }
        iir = U1IIR & 0x0F;
    }
#endif

    VICVectAddr = 0x00000000L;                         /* Clear the vector address register            */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*********************************************************************************************************
*/

void  OSView_Tx1 (INT8U c)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    U0THR = c;
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    U1THR = c;
#endif
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntDis (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    U0IER = BIT0;                                /* Just enable the receive interrupts                 */
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    U1IER = BIT0;                                /* Just enable the receive interrupts                 */
#endif
}

/*
*********************************************************************************************************
*                                       Enable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntEn (void)
{
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
    U0IER = BIT1 | BIT0;
#endif

#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
    U1IER = BIT1 | BIT0;
#endif
}

/*
*********************************************************************************************************
*                                 Tx Communication handler for uC/OS-View
*                                            (PORT SPECIFIC)
*
* Description: Handle transmission of a character
*
* Note(s)    : 1) This function is called by OSView_RxISR (see OS_VIEWa.ASM)
*              2) This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the
*                 UART and thus this function is not needed.
*********************************************************************************************************
*/

void  OSView_TxISRHandler (void)
{
}


⌨️ 快捷键说明

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