usart driver 8h source


@DOC_TITLE@ Xmega Application Note usart_driver.hGo to the documentation of this file.00001 /* This file has been prepared for Doxygen automatic documentation generation.*/ 00059 #ifndef USART_DRIVER_H 00060 #define USART_DRIVER_H 00061 00062 #include "avr_compiler.h" 00063 00064 /* USART buffer defines. */ 00065 00066 /* \brief Receive buffer size: 2,4,8,16,32,64,128 or 256 bytes. */ 00067 #define USART_RX_BUFFER_SIZE 4 00068 /* \brief Transmit buffer size: 2,4,8,16,32,64,128 or 256 bytes */ 00069 #define USART_TX_BUFFER_SIZE 4 00070 /* \brief Receive buffer mask. */ 00071 #define USART_RX_BUFFER_MASK ( USART_RX_BUFFER_SIZE - 1 ) 00072 /* \brief Transmit buffer mask. */ 00073 #define USART_TX_BUFFER_MASK ( USART_TX_BUFFER_SIZE - 1 ) 00074 00075 00076 #if ( USART_RX_BUFFER_SIZE & USART_RX_BUFFER_MASK ) 00077 #error RX buffer size is not a power of 2 00078 #endif 00079 #if ( USART_TX_BUFFER_SIZE & USART_TX_BUFFER_MASK ) 00080 #error TX buffer size is not a power of 2 00081 #endif 00082 00083 00084 /* \brief USART transmit and receive ring buffer. */ 00085 typedef struct USART_Buffer 00086 { 00087 /* \brief Receive buffer. */ 00088 volatile uint8_t RX[USART_RX_BUFFER_SIZE]; 00089 /* \brief Transmit buffer. */ 00090 volatile uint8_t TX[USART_TX_BUFFER_SIZE]; 00091 /* \brief Receive buffer head. */ 00092 volatile uint8_t RX_Head; 00093 /* \brief Receive buffer tail. */ 00094 volatile uint8_t RX_Tail; 00095 /* \brief Transmit buffer head. */ 00096 volatile uint8_t TX_Head; 00097 /* \brief Transmit buffer tail. */ 00098 volatile uint8_t TX_Tail; 00099 } USART_Buffer_t; 00100 00101 00107 typedef struct Usart_and_buffer 00108 { 00109 /* \brief Pointer to USART module to use. */ 00110 USART_t * usart; 00111 /* \brief Data register empty interrupt level. */ 00112 USART_DREINTLVL_t dreIntLevel; 00113 /* \brief Data buffer. */ 00114 USART_Buffer_t buffer; 00115 } USART_data_t; 00116 00117 00118 /* Macros. */ 00119 00129 #define USART_Format_Set(_usart, _charSize, _parityMode, _twoStopBits) \ 00130 (_usart)->CTRLC = (uint8_t) _charSize | _parityMode | \ 00131 (_twoStopBits ? USART_SBMODE_bm : 0) 00132 00133 00156 #define USART_Baudrate_Set(_usart, _bselValue, _bScaleFactor) \ 00157 (_usart)->BAUDCTRLA =(uint8_t)_bselValue; \ 00158 (_usart)->BAUDCTRLB =(_bScaleFactor << USART_BSCALE0_bp)|(_bselValue >> 8) 00159 00160 00165 #define USART_Rx_Enable(_usart) ((_usart)->CTRLB |= USART_RXEN_bm) 00166 00167 00172 #define USART_Rx_Disable(_usart) ((_usart)->CTRLB &= ~USART_RXEN_bm) 00173 00174 00179 #define USART_Tx_Enable(_usart) ((_usart)->CTRLB |= USART_TXEN_bm) 00180 00181 00186 #define USART_Tx_Disable(_usart) ((_usart)->CTRLB &= ~USART_TXEN_bm) 00187 00188 00197 #define USART_RxdInterruptLevel_Set(_usart, _rxdIntLevel) \ 00198 ((_usart)->CTRLA = ((_usart)->CTRLA & ~USART_RXCINTLVL_gm) | _rxdIntLevel) 00199 00200 00209 #define USART_TxdInterruptLevel_Set(_usart, _txdIntLevel) \ 00210 (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_TXCINTLVL_gm) | _txdIntLevel 00211 00212 00213 00222 #define USART_DreInterruptLevel_Set(_usart, _dreIntLevel) \ 00223 (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_DREINTLVL_gm) | _dreIntLevel 00224 00225 00239 #define USART_SetMode(_usart, _usartMode) \ 00240 ((_usart)->CTRLC = ((_usart)->CTRLC & (~USART_CMODE_gm)) | _usartMode) 00241 00242 00243 00248 #define USART_IsTXDataRegisterEmpty(_usart) (((_usart)->STATUS & USART_DREIF_bm) != 0) 00249 00250 00251 00260 #define USART_PutChar(_usart, _data) ((_usart)->DATA = _data) 00261 00262 00263 00270 #define USART_IsRXComplete(_usart) (((_usart)->STATUS & USART_RXCIF_bm) != 0) 00271 00272 00273 00274 00284 #define USART_GetChar(_usart) ((_usart)->DATA) 00285 00286 00287 /* Functions for interrupt driven driver. */ 00288 void USART_InterruptDriver_Initialize(USART_data_t * usart_data, 00289 USART_t * usart, 00290 USART_DREINTLVL_t dreIntLevel ); 00291 00292 void USART_InterruptDriver_DreInterruptLevel_Set(USART_data_t * usart_data, 00293 USART_DREINTLVL_t dreIntLevel); 00294 00295 bool USART_TXBuffer_FreeSpace(USART_data_t * usart_data); 00296 bool USART_TXBuffer_PutByte(USART_data_t * usart_data, uint8_t data); 00297 bool USART_RXBufferData_Available(USART_data_t * usart_data); 00298 uint8_t USART_RXBuffer_GetByte(USART_data_t * usart_data); 00299 bool USART_RXComplete(USART_data_t * usart_data); 00300 void USART_DataRegEmpty(USART_data_t * usart_data); 00301 00302 /* Functions for polled driver. */ 00303 void USART_NineBits_PutChar(USART_t * usart, uint16_t data); 00304 uint16_t USART_NineBits_GetChar(USART_t * usart); 00305 00306 #endif @DOC_TITLE@ Generated on Wed Nov 5 10:23:27 2008 for AVRxxxx Application note title by 1.5.5

Wyszukiwarka

Podobne podstrony:
usart driver 8h
usart driver? source
documentation 8h source
usart example polled? source
usart driver?
usart example interrupt? source
avr compiler 8h source
arm math 8h source
source30
Matrix3?pp source
Thread?pp source
arm biquad ?scade ?1 ?st q31? source
arm conv ?2? source
arm mat mult q15? source
Driver
Resource 8inl source
arm fir lattice init q31? source

więcej podobnych podstron