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

📄 probe_rs232c.c

📁 uCOS-II V2.84 LM3S6965 TCPIP Demo
💻 C
字号:
/*
*********************************************************************************************************
*                                      uC/Probe Communication
*
*                           (c) Copyright 2007; 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/Probe
*
*                                      Communication: RS-232
*                                Port for the LuminarMicro LM3Sxxxx
*
* Filename      : probe_rs232c.c
* Version       : V1.20
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#include  <probe_rs232.h>
#include  <includes.h>

/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/
                                                                /* ---------------- UART0 Register Defines ---------------- */
#define  UART0DR            (*(CPU_INT32U *)(UART0_BASE  + 0x0000))
#define  UART0FR            (*(CPU_INT32U *)(UART0_BASE  + 0x0018))
#define  UART0IBRD          (*(CPU_INT32U *)(UART0_BASE  + 0x0024))
#define  UART0FBRD          (*(CPU_INT32U *)(UART0_BASE  + 0x0028))
#define  UART0LCRH          (*(CPU_INT32U *)(UART0_BASE  + 0x002C))
#define  UART0CTL           (*(CPU_INT32U *)(UART0_BASE  + 0x0030))
#define  UART0IFLS          (*(CPU_INT32U *)(UART0_BASE  + 0x0034))
#define  UART0IM            (*(CPU_INT32U *)(UART0_BASE  + 0x0038))
#define  UART0MIS           (*(CPU_INT32U *)(UART0_BASE  + 0x0040))
#define  UART0ICR           (*(CPU_INT32U *)(UART0_BASE  + 0x0044))

                                                                /* ---------------- UART1 Register Defines ---------------- */
#define  UART1DR            (*(CPU_INT32U *)(UART1_BASE  + 0x0000))
#define  UART1FR            (*(CPU_INT32U *)(UART1_BASE  + 0x0018))
#define  UART1IBRD          (*(CPU_INT32U *)(UART1_BASE  + 0x0024))
#define  UART1FBRD          (*(CPU_INT32U *)(UART1_BASE  + 0x0028))
#define  UART1LCRH          (*(CPU_INT32U *)(UART1_BASE  + 0x002C))
#define  UART1CTL           (*(CPU_INT32U *)(UART1_BASE  + 0x0030))
#define  UART1IFLS          (*(CPU_INT32U *)(UART1_BASE  + 0x0034))
#define  UART1IM            (*(CPU_INT32U *)(UART1_BASE  + 0x0038))
#define  UART1MIS           (*(CPU_INT32U *)(UART1_BASE  + 0x0040))
#define  UART1ICR           (*(CPU_INT32U *)(UART1_BASE  + 0x0044))

                                                                /* ------------- UARTCTL Register Bit Defines ------------- */
#define  UARTCTL_UARTEN             DEF_BIT_00
#define  UARTCTL_TXE                DEF_BIT_08
#define  UARTCTL_RXE                DEF_BIT_09

                                                                /* ------------- UARTIM  Register Bit Defines ------------- */
                                                                /* ------------- UARTRIS Register Bit Defines ------------- */
                                                                /* ------------- UARTMIS Register Bit Defines ------------- */
                                                                /* ------------- UARTICR Register Bit Defines ------------- */
#define  UARTINT_RX                 DEF_BIT_04
#define  UARTINT_TX                 DEF_BIT_05
#define  UARTINT_RT                 DEF_BIT_06
#define  UARTINT_FE                 DEF_BIT_07
#define  UARTINT_PE                 DEF_BIT_08
#define  UARTINT_BE                 DEF_BIT_09
#define  UARTINT_OE                 DEF_BIT_10

                                                                /* ------------- UARTFLS Register Bit Defines ------------- */
#define  UARTFLS_RX_1_8             0x00000000
#define  UARTFLS_TX_7_8             0x00000004

                                                                /* ------------ UARTLCRH Register Bit Defines ------------- */
#define  UARTLCRH_WLEN_8            0x00000060
#define  UARTLCRH_FEN               DEF_BIT_04

                                                                /* ------------- UARTFR Register Bit Defines -------------- */
#define  UARTFR_BUSY                DEF_BIT_03
#define  UARTFR_RXFE                DEF_BIT_04
#define  UARTFR_TXFF                DEF_BIT_05
#define  UARTFR_RXFF                DEF_BIT_06
#define  UARTFR_TXFE                DEF_BIT_07

/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*********************************************************************************************************
*                                         GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                       Initialize COM port for uC/Probe RS-232 Communication Module
*
* Description: Initialize the UART for uC/Probe communication.
*
* Argument(s): baud_rate    is intended baud rate of the RS-232.
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_InitTarget (CPU_INT32U baud_rate)
{
    CPU_INT32U  idiv;
    CPU_INT32U  fdiv;
    CPU_INT32U  clk_freq;


                                                                /* --------------- COMPUTE DIVISOR BAUD RATE -------------- */
    clk_freq = SysCtlClockGet();
    idiv     = clk_freq / (16 * baud_rate);
    fdiv     = clk_freq % (16 * baud_rate);
    fdiv     = ((((2 * fdiv * 4) / baud_rate) + 1) / 2);

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralReset(SYSCTL_PERIPH_UART0);

                                                                /* ------------------- ENABLE UART0 I/Os ------------------ */
                                                                /* PA[0] & PA[1]                                            */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

                                                                /* --------------------- SETUP UART0 ---------------------- */
    UART0IBRD = idiv;
    UART0FBRD = fdiv;
    UART0LCRH = UARTLCRH_WLEN_8;
    UART0FR   = 0x00000000;
    UART0CTL  = UARTCTL_RXE | UARTCTL_TXE | UARTCTL_UARTEN;
    UART0IFLS = 0x00000000;
    UART0ICR  = UARTINT_OE | UARTINT_BE | UARTINT_PE | UARTINT_FE | UARTINT_RT | UARTINT_TX | UARTINT_RX;

    IntEnable(INT_UART0);                                       /* ------------ INITIALIZE INTERRUPT FOR UART0 ------------ */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralReset(SYSCTL_PERIPH_UART1);
                                                                /* ------------------- ENABLE UART0 I/Os ------------------ */
                                                                /* PD[3] & PD[4]                                            */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    GPIOPinTypeUART(GPI1_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);

                                                                /* --------------------- SETUP UART1 ---------------------- */
    UART1IBRD = idiv;
    UART1FBRD = fdiv;
    UART1LCRH = UARTLCRH_WLEN_8;
    UART1FR   = 0x00000000;
    UART1CTL  = UARTCTL_RXE | UARTCTL_TXE | UARTCTL_UARTEN;
    UART1IFLS = 0x00000000;
    UART1ICR  = UARTINT_OE | UARTINT_BE | UARTINT_PE | UARTINT_FE | UARTINT_RT | UARTINT_TX | UARTINT_RX;

    IntEnable(INT_UART1);                                       /* ------------ INITIALIZE INTERRUPT FOR UART1 ------------ */
#endif
}


/*
*********************************************************************************************************
*                                 Rx and Tx Communication Handler
*
* Description: This function handles both Rx and Tx interrupts.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_RxTxISRHandler (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif
    CPU_INT32U  status;
    CPU_INT08U  rx_data;


    CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR                */
    OSIntNesting++;
    CPU_CRITICAL_EXIT();

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    status = UART0MIS;

    if ((status & UARTINT_TX) == UARTINT_TX) {
        while (((UART0IM & UARTINT_TX) == UARTINT_TX) && ((UART0FR & UARTFR_TXFF) == 0)) {
            ProbeRS232_TxHandler();                             /* Call the generic Tx handler                              */
        }
    }

    if ((status & UARTINT_RX) == UARTINT_RX) {
        while ((UART0FR & UARTFR_RXFE) == 0) {
            rx_data = (UART0DR & 0xFF);
            ProbeRS232_RxHandler(rx_data);                      /* Call the generic Rx handler                              */
        }
    }

    UART0ICR = status;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    status = UART1MIS;

    if ((status & UARTINT_TX) == UARTINT_TX) {
        while (((UART1IM & UARTINT_TX) == UARTINT_TX) && ((UART1FR & UARTFR_TXFF) == 0)) {
            ProbeRS232_TxHandler();                             /* Call the generic Tx handler                              */
        }
    }

    if ((status & UARTINT_RX) == UARTINT_RX) {
        while ((UART1FR & UARTFR_RXFE) == 0) {
            rx_data = (UART1DR & 0xFF);
            ProbeRS232_RxHandler(rx_data);                      /* Call the generic Rx handler                              */
        }
    }

    UART1ICR = status;
#endif

    OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR                */
}

/*
*********************************************************************************************************
*                                 Rx and Tx Communication Handler
*
* Description: These functions handle the Rx and Tx interrupts.
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : These functions are empty because Rx and Tx interrupts are both handled by ProbeRS232_RxTxISRHandler()
*********************************************************************************************************
*/

void  ProbeRS232_RxISRHandler (void)
{
}

void  ProbeRS232_TxISRHandler (void)
{
}

/*
*********************************************************************************************************
*                                      Transmit One Byte
*
* Description: This function transmits one byte.
*
* Argument(s): c    is the byte to transmit.
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_Tx1 (CPU_INT08U c)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    UART0DR = c;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    UART1DR = c;
#endif
}

/*
*********************************************************************************************************
*                                      Enable/disable Tx Interrupts
*
* Description: Enables or disables Tx interrupts.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_TxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    UART0IM &= ~UARTINT_TX;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    UART1IM &= ~UARTINT_TX;
#endif
}

void  ProbeRS232_TxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    UART0IM |=  UARTINT_TX;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    UART1IM |=  UARTINT_TX;
#endif
}

/*
*********************************************************************************************************
*                                      Enable/disable Rx Interrupts
*
* Description: Enables or disables Rx interrupts.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeRS232_RxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    UART0IM &= ~UARTINT_RX;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    UART1IM &= ~UARTINT_RX;
#endif
}

void  ProbeRS232_RxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    UART0IM |=  UARTINT_RX | UARTINT_RT;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    UART1IM |=  UARTINT_RX | UARTINT_RT;
#endif
}

⌨️ 快捷键说明

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