ChibiOS/RT
2.6.0
uart.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012,2013 Giovanni Di Sirio.
00004 
00005     This file is part of ChibiOS/RT.
00006 
00007     ChibiOS/RT is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ChibiOS/RT is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020                                       ---
00021 
00022     A special exception to the GPL can be applied should you wish to distribute
00023     a combined work that includes ChibiOS/RT, without being obliged to provide
00024     the source code for any proprietary components. See the file exception.txt
00025     for full details of how and when the exception can be applied.
00026 */
00027 
00028 /**
00029  * @file    uart.h
00030  * @brief   UART Driver macros and structures.
00031  *
00032  * @addtogroup UART
00033  * @{
00034  */
00035 
00036 #ifndef _UART_H_
00037 #define _UART_H_
00038 
00039 #if HAL_USE_UART || defined(__DOXYGEN__)
00040 
00041 /*===========================================================================*/
00042 /* Driver constants.                                                         */
00043 /*===========================================================================*/
00044 
00045 /**
00046  * @name    UART status flags
00047  * @{
00048  */
00049 #define UART_NO_ERROR           0   /**< @brief No pending conditions.      */
00050 #define UART_PARITY_ERROR       4   /**< @brief Parity error happened.      */
00051 #define UART_FRAMING_ERROR      8   /**< @brief Framing error happened.     */
00052 #define UART_OVERRUN_ERROR      16  /**< @brief Overflow happened.          */
00053 #define UART_NOISE_ERROR        32  /**< @brief Noise on the line.          */
00054 #define UART_BREAK_DETECTED     64  /**< @brief Break detected.             */
00055 /** @} */
00056 
00057 /*===========================================================================*/
00058 /* Driver pre-compile time settings.                                         */
00059 /*===========================================================================*/
00060 
00061 /*===========================================================================*/
00062 /* Derived constants and error checks.                                       */
00063 /*===========================================================================*/
00064 
00065 /*===========================================================================*/
00066 /* Driver data structures and types.                                         */
00067 /*===========================================================================*/
00068 
00069 /**
00070  * @brief   Driver state machine possible states.
00071  */
00072 typedef enum {
00073   UART_UNINIT = 0,                  /**< Not initialized.                   */
00074   UART_STOP = 1,                    /**< Stopped.                           */
00075   UART_READY = 2                    /**< Ready.                             */
00076 } uartstate_t;
00077 
00078 /**
00079  * @brief   Transmitter state machine states.
00080  */
00081 typedef enum {
00082   UART_TX_IDLE = 0,                 /**< Not transmitting.                  */
00083   UART_TX_ACTIVE = 1,               /**< Transmitting.                      */
00084   UART_TX_COMPLETE = 2              /**< Buffer complete.                   */
00085 } uarttxstate_t;
00086 
00087 /**
00088  * @brief   Receiver state machine states.
00089  */
00090 typedef enum {
00091   UART_RX_IDLE = 0,                 /**< Not receiving.                     */
00092   UART_RX_ACTIVE = 1,               /**< Receiving.                         */
00093   UART_RX_COMPLETE = 2              /**< Buffer complete.                   */
00094 } uartrxstate_t;
00095 
00096 #include "uart_lld.h"
00097 
00098 /*===========================================================================*/
00099 /* Driver macros.                                                            */
00100 /*===========================================================================*/
00101 
00102 /*===========================================================================*/
00103 /* External declarations.                                                    */
00104 /*===========================================================================*/
00105 
00106 #ifdef __cplusplus
00107 extern "C" {
00108 #endif
00109   void uartInit(void);
00110   void uartObjectInit(UARTDriver *uartp);
00111   void uartStart(UARTDriver *uartp, const UARTConfig *config);
00112   void uartStop(UARTDriver *uartp);
00113   void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf);
00114   void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf);
00115   size_t uartStopSend(UARTDriver *uartp);
00116   size_t uartStopSendI(UARTDriver *uartp);
00117   void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf);
00118   void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf);
00119   size_t uartStopReceive(UARTDriver *uartp);
00120   size_t uartStopReceiveI(UARTDriver *uartp);
00121 #ifdef __cplusplus
00122 }
00123 #endif
00124 
00125 #endif /* HAL_USE_UART */
00126 
00127 #endif /* _UART_H_ */
00128 
00129 /** @} */