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

📄 probe_rs232c.c

📁 AT91SAM7SE,ucos移植范例
💻 C
📖 第 1 页 / 共 2 页
字号:
              | AT91C_US_PAR_NONE                               /* No parity bit selected                                   */
              | AT91C_US_NBSTOP_1_BIT;                          /* 1 stop bit selected                                      */

                                                                /* Set the USART baud rate                                  */
    DBGU_BRGR = (CPU_INT16U)((mclk_freq) / baud_rate / 16);

                                                                /* --------------- INITIALIZE AIC FOR DBGU ---------------- */
                                                                /* See Note (1)                                             */
    PMC_PCER  = (1 << AT91C_ID_SYS);                            /* Enable the DBGU peripheral clock                         */
#endif
}

/*
*********************************************************************************************************
*                                     ProbeRS232_RxTxISRHandler()
*
* Description: Handle Rx and Tx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*
* Note(s)    : (1) If DBGU is used, then this function is expected to be called by an external
*                  function which handles interrupts on the system (SYS) vector.  It is expected as well
*                  that that function will clear the SYS interrupt.
*
*              (2) The AIC End Of Interrupt Command Register (AIC_EOICR) will need to be written by the
*                  generic interrupt handler which vectored to this specific IRQ handler after this
*                  function returns.
*********************************************************************************************************
*/

void  ProbeRS232_RxTxISRHandler (void)
{
    CPU_INT08U  rx_data;


#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    AIC_IVR   = 0;                                              /* Debug variant of IVR (protect mode is used)              */

                                                                /* If we received a byte                                    */
    if ((US0_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
        rx_data = (CPU_INT08U)(US0_RHR & 0x00FF);               /* Remove the data from the holding register                */
        ProbeRS232_RxHandler(rx_data);                          /* Call the generic Rx handler                              */
    }

                                                                /* If we completed transmitting a byte                      */
    if ((US0_CSR & AT91C_US_TXRDY) == AT91C_US_TXRDY) {
        ProbeRS232_TxHandler();                                 /* Call the generic Tx handler                              */
    }

    if ((US0_CSR  & AT91C_US_OVRE) == AT91C_US_OVRE) {
        US0_CR = AT91C_US_RSTSTA;                               /* If an overrun occurs, reset the OR flag                  */
    }

    AIC_ICCR  = AT91C_ID_US0;                                   /* Clear  US0 interrupt                                     */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    AIC_IVR   = 0;                                              /* Debug variant of IVR (protect mode is used)              */
                                                                /* If we received a byte                                    */
    if ((US1_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
        rx_data = (CPU_INT08U)(US1_RHR & 0x00FF);               /* Remove the data from the holding register                */
        ProbeRS232_RxHandler(rx_data);                          /* Call the generic Rx handler                              */
    }

                                                                /* If we completed transmitting a byte                      */
    if ((US1_CSR & AT91C_US_TXRDY) == AT91C_US_TXRDY) {
        ProbeRS232_TxHandler();                                 /* Call the generic Tx handler                              */
    }

    if ((US0_CSR  & AT91C_US_OVRE) == AT91C_US_OVRE) {
        US1_CR = AT91C_US_RSTSTA;                               /* If an overrun occurs, reset the OR flag                  */
    }

    AIC_ICCR  = AT91C_ID_US1;                                   /* Clear  US0 interrupt                                     */
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
                                                                /* If we received a byte                                    */
    if ((DBGU_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
        rx_data = (CPU_INT08U)(DBGU_RHR & 0x00FF);              /* Remove the data from the holding register                */
        ProbeRS232_RxHandler(rx_data);                          /* Call the generic Rx handler                              */
    }

                                                                /* If we completed transmitting a byte                      */
    if ((DBGU_CSR & AT91C_US_TXRDY) == AT91C_US_TXRDY) {
        ProbeRS232_TxHandler();                                 /* Call the generic Tx handler                              */
    }

    if ((DBGU_CSR  & AT91C_US_OVRE) == AT91C_US_OVRE) {
        DBGU_CR = AT91C_US_RSTSTA;                              /* If an overrun occurs, reset the OR flag                  */
    }
#endif
}


/*
*********************************************************************************************************
*                                    ProbeRS232_RxISRHandler()
*
* Description: Handle Rx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*
* Note(s)    : This function is empty because Rx interrupts are handled by ProbeRS232_RxTxISRHandler()
*********************************************************************************************************
*/

void  ProbeRS232_RxISRHandler (void)
{
}


/*
*********************************************************************************************************
*                                      ProbeRS232_RxIntDis()
*
* Description: Disable Rx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*********************************************************************************************************
*/

void  ProbeRS232_RxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    US0_IDR  = AT91C_US_RXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    US1_IDR  = AT91C_US_RXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
    DBGU_IDR = AT91C_US_RXRDY;
#endif
}


/*
*********************************************************************************************************
*                                      ProbeRS232_RxIntEn()
*
* Description: Enable Rx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*********************************************************************************************************
*/

void  ProbeRS232_RxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    US0_IER  = AT91C_US_RXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    US1_IER  = AT91C_US_RXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
    DBGU_IER = AT91C_US_RXRDY;
#endif
}


/*
*********************************************************************************************************
*                                    ProbeRS232_TxISRHandler()
*
* Description: Handle Tx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*
* Note(s)    : This function is empty because Tx interrupts are handled by ProbeRS232_RxTxISRHandler()
*********************************************************************************************************
*/

void  ProbeRS232_TxISRHandler (void)
{
}


/*
*********************************************************************************************************
*                                      ProbeRS232_Tx1()
*
* Description: Transmit one byte.
*
* Argument(s): c            The byte to transmit.
*
* Return(s)  : none.
*********************************************************************************************************
*/

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

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    US1_THR  = c;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
    DBGU_THR = c;
#endif
}


/*
*********************************************************************************************************
*                                      ProbeRS232_TxIntDis()
*
* Description: Disable Tx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*********************************************************************************************************
*/

void  ProbeRS232_TxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    US0_IDR  = AT91C_US_TXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    US1_IDR  = AT91C_US_TXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
    DBGU_IDR = AT91C_US_TXRDY;
#endif
}


/*
*********************************************************************************************************
*                                      ProbeRS232_TxIntEn()
*
* Description: Enable Tx interrupts.
*
* Argument(s): none.
*
* Return(s)  : none.
*********************************************************************************************************
*/

void  ProbeRS232_TxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_0)
    US0_IER  = AT91C_US_TXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
    US1_IER  = AT91C_US_TXRDY;
#endif

#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_DBG)
    DBGU_IER = AT91C_US_TXRDY;
#endif
}

⌨️ 快捷键说明

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