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

📄 lh7a400_uart_driver.c

📁 sharp触摸屏测试代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
 * $Workfile:   LH7A400_uart_driver.c  $
 * $Revision:   1.5  $
 * $Author:   BarnettH  $
 * $Date:   Aug 26 2002 16:32:22  $
 *
 * Project: LH7A400
 *
 * Description:
 *   LH7A400 UART Driver routines
 *
 * Applicable Documents:
 *
 * Notes:
 *    (1) ...
 *    (2) ...
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/CHIPS/archives/LH7A400/Startup/LH7A400_uart_driver.c-arc  $
 * 
 *    Rev 1.5   Aug 26 2002 16:32:22   BarnettH
 * Ensured FIFO's were flushed on initialization
 * Added LH7A400_uart_fifo_flush ()
 * 
 *    Rev 1.4   Aug 16 2002 09:31:34   FergisJ
 * Updated Note (6) in uart_init() function banner.
 *
 *    Rev 1.3   Aug 05 2002 16:25:48   FergisJ
 * Removed automatic disabling of SIR/IrDA in uart_init().
 *
 *    Rev 1.2   Jul 15 2002 15:38:24   MaysR
 * Moved initialization of timeout values from global area to UART
 * init function.
 *
 *    Rev 1.1   Jul 10 2002 13:45:48   BarnettH
 * Rearranged file.  No substantive changes.
 *
 *    Rev 1.0   Jun 25 2002 17:44:10   BarnettH
 * Initial revision.
 *
 ***********************************************************************
 *
 *  Copyright (c) 2002 Sharp Microelectronics of the Americas
 *
 *  All rights reserved
 *
 *  SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 *  OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 *  AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
 *  SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 *  SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
 *  FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
 *  SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT.  USE OF THIS SOURCE
 *  FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 **********************************************************************/
/***********************************************************************
 * Library header files (#include)
 **********************************************************************/

/***********************************************************************
 * Public user header files (#include)
 **********************************************************************/
#include "LH7A400_uart_driver.h"

/***********************************************************************
 * Private user header files (#include)
 **********************************************************************/

/***********************************************************************
 * Constant definitions (#define)
 **********************************************************************/

/***********************************************************************
 * Macro definitions (#define)
 **********************************************************************/

/***********************************************************************
 * Data declarations of global data imported.
 **********************************************************************/

/***********************************************************************
 * Function prototypes of global functions imported.
 **********************************************************************/

/***********************************************************************
 * Data definitions of global data exported.
 **********************************************************************/
INT_32 default_rx_string_timeout;
INT_32 default_txb_timeout;

/***********************************************************************
 * Function prototypes of functions requiring global scope
 * not included elsewhere.
 **********************************************************************/

/***********************************************************************
 * Static variable definition (file scope).
 **********************************************************************/

/***********************************************************************
 * Static function prototypes. (Forward declarations)
 **********************************************************************/

/***********************************************************************
 *
 * Function: UNS_32 LH7A400_uart_init (UARTREGS * uart,
 *                                     const UARTINIT * uinit)
 *
 * Purpose:
 *   To provide a streamlined method to initialize a LH7A400 UART device
 *   This is a "quick and dirty" method to set up any of the UART's as
 *   standard serial IO with the Baud Rate, Word length, and Parity, set
 *   by user. Stop bits are forced to 1 stop bit. FIFO is forced "ON".
 *
 * Processing:
 *   Disable UART-specific interrupts at the UART.
 *   Enable the UART function.
 *           (UART must be enabled to configure it.)
 *   Set the baud rate.
 *   Set the line control register.
 *   Set the control register.
 *   Return
 *
 * Parameters:
 *   UARTREGS * uart  - pointer to UART
 *                       {UART1 | UART2 | UART3 | SIR | IRDA}
 *
 *   UARTREGS * uinit - pointer to structure initialized by user with
 *                      desired UART configuration before calling this
 *                      function.  Registers may be initialized with
 *                      raw bit patterns, or using manifest constants
 *                      provided in LH7A400_uart.h
 *
 * Outputs: Sets memory-mapped UART registers.
 *
 * Returns: None.
 *
 * Notes:
 *    (1) In its current form, this function is not "bullet-proof".
 *        Care should be used in initializing the structure which is
 *        used to initialize the UART. No error or range checking is
 *        provided.
 *    (2) Sets up for UART Serial or SIR/IrDA IO
 *    (3) Forces FIFO enable. User specification of FIFO state has no
 *        effect.
 *    (4) Manner of specifying the baud rate is flexible.  User may
 *        use raw baud rate number, or use manifest constants provided
 *        by UART header file.
 *    (5) Typical UART uinit definition for UART operation:
 *          static const UARTREGS uinit =
 *          {
 *              0,
 *              UART_LCR_STP1 | UART_LCR_PNONE | UART_LCR_FEN |
 *                  UART_LCR_WLEN8,
 *              UART_BCR_9600,
 *              UART_CONTROL_UART_ENABLE | UART_CONTROL_SIR_DISABLE;
 *              0,
 *              0,
 *              0,
 *              0
 *          };
 *    (6) Typical UART uinit definition for SIR/IrDA operation:
 *          static const UARTREGS irda_init =
 *          {
 *              0,
 *              UART_LCR_STP1 | UART_LCR_PNONE | UART_LCR_FEN |
 *                  UART_LCR_WLEN8,
 *              UART_BCR_9600,
 *              UART_CONTROL_SIRBD  |     // disable SIR blanking
 *              UART_CONTROL_SIRLP  |     // set low-power mode
 *              UART_CONTROL_UART_ENABLE  // enable Uart ...
 *              ,                         //  IrDA/SIR is enabled
 *              0,                        //    by not disabling it
 *              0,
 *              0,
 *              0
 *          };
 *
 **********************************************************************/
void LH7A400_uart_init (UARTREGS * uart, const UARTREGS * uinit)
{
    UNS_32 buffer = UART_CONTROL_UART_ENABLE;

    default_rx_string_timeout = SIO_RXS_TIMEOUT_COUNT;
    default_txb_timeout       = SIO_TXB_TIMEOUT_COUNT;

    // disable all interrupts locally
    uart->inte = 0;

    // Clear the FIFO's by disabling the UART before enabling it.
    uart->control = 0x0;
    // Enable the UART
    uart->control = buffer;

    /*******************************************************************
     * Setup baud rate
     ******************************************************************/
    if (uinit->bcr < 256)  // use manifest constant directly
        uart->bcr = uinit->bcr;
    else                        // calculate baudrate divisor
        uart->bcr = UART_BCR(uinit->bcr);
    // END Setup baud rate

    /*******************************************************************
     * Setup control register
     ******************************************************************/
    // This operation will retain UART_ENABLE/SIR_DISABLE already set.
    // and will add such other bits as user specifies in the
    // initializing structure.
    // Will NOT clear any bits if already set elsewhere.
    uart->control |= uinit->control & _BITMASK(8);

    /*******************************************************************
     * Setup Line Control Register
     ******************************************************************/
    buffer = uinit->lcr;
    // Force FIFO enable;
    buffer |= UART_LCR_FEN;

    // Set Line Control Register
    uart->lcr = buffer & _BITMASK(8);
    // END Setup Line Control Register

    return;
}

/***********************************************************************
 *
 * Function: void LH7A400_uart_sendbreak (UARTREGS * uart,
 *                                        BREAKSTATE state)
 *
 * Purpose:
 *      To force a BREAK
 *
 * Processing:
 *      if turn break on
 *          enable break;
 *      else
 *          disable break;
 *
 * Parameters:
 *   UARTREGS * uart  - pointer to UART {UART1 | UART2 | UART3}
 *
 *   BREAKSTATE state - {BREAK_OFF | BREAK_ON}
 *
 * Outputs: Break asserted or deasserted on selected UART TX signal
 *          line.
 *
 * Returns: None.
 *
 **********************************************************************/
void LH7A400_uart_sendbreak (UARTREGS * uart, BREAKSTATE state)
{
    switch (state)
    {
        case BREAK_ON:
            uart->lcr |= UART_LCR_SENDBRK;
            break;

        case BREAK_OFF:
        default:
            uart->lcr &= ~UART_LCR_SENDBRK;
            break;
    }
}

/***********************************************************************
 *
 * Function: SIO_ERROR LH7A400_uart_rxs (UARTREGS * uart,
 *                                       UNS_8 * rxs,
 *                                       INT_32 term)
 *
 * Purpose:
 *      To receive a string of octets inbound from a selected UART in
 *      polling mode
 *
 * Processing:
 *
 *  if term == NUL
 *     receive octets and load buffer one octet at a time until
 *     NUL octet is received
 *
 *  if term == linefeed || term == carriage-return-linefeed
 *     receive octets and load buffer one octet at a time until
 *     LF octet is received, then add NUL character to buffer
 *
 *  if term == carriage return
 *     receive octets and load buffer one octet at a time until
 *     CR octet is received, then add NUL character to buffer
 *
 *  if term == positive integer
 *     receive octets and load buffer one octet at a time until
 *     <positive integer> octets have been received, then add NUL
 *     character to buffer
 *
 *  return SIO_ERROR
 *
 * Parameters:
 *   UARTREGS * uart  - pointer to UART {UART1 | UART2 | UART3}
 *
 *   UNS_8 * rxs      - pointer to buffer to hold received octets
 *
 *   INT_32 term      - string terminator code (flexible parameter)
 *      term arguments:
 *         { STRING_TERM_NUL | STRING_TERM_LF| STRING_TERM_CR |
 *             <positive number> }
 *          STRING_TERM_NUL   - a NUL ('\0', 0x0, ASC_NUL) character
 *          STRING_TERM_LF    - a LF (\n, 0x0A, ASC_LF) character
 *          STRING_TERM_CR    - a CR (\r, 0x0D, ASC_CR) character
 *          STRING_TERM_CRLF  - CR-LF (\r\n, 0x0D0A) characters
 *          <positive number> - number of octets in string
 *
 * Outputs: Asynchronous protocol bitstream on TX signal of selected
 *          UART.
 *
 * Returns: SIO_ERROR
 *  See LH7A400_uart_driver.h for SIO_ERROR values
 *
 * Notes:
 *    (1) User is responsible for providing a buffer of sufficient
 *        length to hold the expected data.
 *    (2) STRING_TERM_LF and STRING_TERM_CRLF are handled the same.
 *    (3) Function does not return until string is received.
 *
 **********************************************************************/
SIO_ERROR LH7A400_uart_rxs (UARTREGS * uart, UNS_8 * rxs, INT_32 term)
{
    SIO_ERROR err = SIOERR_NO_ERROR;
    INT_32 rxs_timeout;
    UNS_8 buf = 0xFF;

    rxs_timeout = default_rx_string_timeout;

    switch (term)
    {
        case STRING_TERM_NUL: // NUL terminated string
            do {

⌨️ 快捷键说明

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