Minikombajn Pomiarowy  20
 All Files Functions Variables Macros
usart_driver.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
59 #ifndef USART_DRIVER_H
60 #define USART_DRIVER_H
61 
62 #include "avr_compiler.h"
63 
64 /* USART buffer defines. */
65 
66 /* \brief Receive buffer size: 2,4,8,16,32,64,128 or 256 bytes. */
67 #define USART_RX_BUFFER_SIZE 4
68 /* \brief Transmit buffer size: 2,4,8,16,32,64,128 or 256 bytes */
69 #define USART_TX_BUFFER_SIZE 4
70 /* \brief Receive buffer mask. */
71 #define USART_RX_BUFFER_MASK ( USART_RX_BUFFER_SIZE - 1 )
72 /* \brief Transmit buffer mask. */
73 #define USART_TX_BUFFER_MASK ( USART_TX_BUFFER_SIZE - 1 )
74 
75 
76 #if ( USART_RX_BUFFER_SIZE & USART_RX_BUFFER_MASK )
77 #error RX buffer size is not a power of 2
78 #endif
79 #if ( USART_TX_BUFFER_SIZE & USART_TX_BUFFER_MASK )
80 #error TX buffer size is not a power of 2
81 #endif
82 
83 /* Macros. */
84 
94 #define USART_Format_Set(_usart, _charSize, _parityMode, _twoStopBits) \
95  (_usart)->CTRLC = (uint8_t) _charSize | _parityMode | \
96  (_twoStopBits ? USART_SBMODE_bm : 0)
97 
98 
121 #define USART_Baudrate_Set(_usart, _bselValue, _bScaleFactor) \
122  (_usart)->BAUDCTRLA =(uint8_t)_bselValue; \
123  (_usart)->BAUDCTRLB =(_bScaleFactor << USART_BSCALE0_bp)|(_bselValue >> 8)
124 
125 
130 #define USART_Rx_Enable(_usart) ((_usart)->CTRLB |= USART_RXEN_bm)
131 
132 
137 #define USART_Rx_Disable(_usart) ((_usart)->CTRLB &= ~USART_RXEN_bm)
138 
139 
144 #define USART_Tx_Enable(_usart) ((_usart)->CTRLB |= USART_TXEN_bm)
145 
146 
151 #define USART_Tx_Disable(_usart) ((_usart)->CTRLB &= ~USART_TXEN_bm)
152 
153 
162 #define USART_RxdInterruptLevel_Set(_usart, _rxdIntLevel) \
163  ((_usart)->CTRLA = ((_usart)->CTRLA & ~USART_RXCINTLVL_gm) | _rxdIntLevel)
164 
165 
174 #define USART_TxdInterruptLevel_Set(_usart, _txdIntLevel) \
175  (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_TXCINTLVL_gm) | _txdIntLevel
176 
177 
178 
187 #define USART_DreInterruptLevel_Set(_usart, _dreIntLevel) \
188  (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_DREINTLVL_gm) | _dreIntLevel
189 
190 
204 #define USART_SetMode(_usart, _usartMode) \
205  ((_usart)->CTRLC = ((_usart)->CTRLC & (~USART_CMODE_gm)) | _usartMode)
206 
207 
208 
213 #define USART_IsTXDataRegisterEmpty(_usart) (((_usart)->STATUS & USART_DREIF_bm) != 0)
214 
215 
216 
225 #define USART_PutChar(_usart, _data) ((_usart)->DATA = _data)
226 
227 
228 
235 #define USART_IsRXComplete(_usart) (((_usart)->STATUS & USART_RXCIF_bm) != 0)
236 
237 
238 
239 
249 #define USART_GetChar(_usart) ((_usart)->DATA)
250 
251 
252 #endif