![]() |
BLDC control on ATAVRMC303 with ATxMega128A1
|
XMEGA USART driver source file. More...
#include "usart_driver.h"
Go to the source code of this file.
Functions | |
| void | USART_DataRegEmpty (USART_data_t *usart_data) |
| Data Register Empty Interrupt Service Routine. More... | |
| void | USART_InterruptDriver_DreInterruptLevel_Set (USART_data_t *usart_data, USART_DREINTLVL_t dreIntLevel) |
| Set USART DRE interrupt level. More... | |
| void | USART_InterruptDriver_Initialize (USART_data_t *usart_data, USART_t *usart, USART_DREINTLVL_t dreIntLevel) |
| Initializes buffer and selects what USART module to use. More... | |
| uint16_t | USART_NineBits_GetChar (USART_t *usart) |
| Get received data (9 bit character). More... | |
| void | USART_NineBits_PutChar (USART_t *usart, uint16_t data) |
| Put data (9 bit character). More... | |
| uint8_t | USART_RXBuffer_GetByte (USART_data_t *usart_data) |
| Get received data (5-8 bit character). More... | |
| bool | USART_RXBufferData_Available (USART_data_t *usart_data) |
| Test if there is data in the receive software buffer. More... | |
| bool | USART_RXComplete (USART_data_t *usart_data) |
| RX Complete Interrupt Service Routine. More... | |
| bool | USART_TXBuffer_FreeSpace (USART_data_t *usart_data) |
| Test if there is data in the transmitter software buffer. More... | |
| bool | USART_TXBuffer_PutByte (USART_data_t *usart_data, uint8_t data) |
| Put data (5-8 bit character). More... | |
XMEGA USART driver source file.
This file contains the function implementations the XMEGA interrupt and polled USART driver.
The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA ADC module.
For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.
Some functions use the following construct: "some_register = ... | (some_parameter ? SOME_BIT_bm : 0) | ..." Although the use of the ternary operator ( if ? then : else ) is discouraged, in some occasions the operator makes it possible to write pretty clean and neat code. In this driver, the construct is used to set or not set a configuration bit based on a boolean input parameter, such as the "some_parameter" in the example above.
Copyright (c) 2008, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file usart_driver.c.
| void USART_DataRegEmpty | ( | USART_data_t * | usart_data | ) |
Data Register Empty Interrupt Service Routine.
Data Register Empty Interrupt Service Routine. Transmits one byte from TX software buffer. Disables DRE interrupt if buffer is empty. Argument is pointer to USART (USART_data_t).
| usart_data | The USART_data_t struct instance. |
Definition at line 260 of file usart_driver.c.
References Usart_and_buffer::buffer, USART_Buffer::TX, USART_Buffer::TX_Head, USART_Buffer::TX_Tail, Usart_and_buffer::usart, and USART_TX_BUFFER_MASK.
| void USART_InterruptDriver_DreInterruptLevel_Set | ( | USART_data_t * | usart_data, |
| USART_DREINTLVL_t | dreIntLevel | ||
| ) |
Set USART DRE interrupt level.
Set the interrupt level on Data Register interrupt.
| usart_data | The USART_data_t struct instance |
| dreIntLevel | Interrupt level of the DRE interrupt. |
Definition at line 106 of file usart_driver.c.
References Usart_and_buffer::dreIntLevel.
| void USART_InterruptDriver_Initialize | ( | USART_data_t * | usart_data, |
| USART_t * | usart, | ||
| USART_DREINTLVL_t | dreIntLevel | ||
| ) |
Initializes buffer and selects what USART module to use.
Initializes receive and transmit buffer and selects what USART module to use, and stores the data register empty interrupt level.
| usart_data | The USART_data_t struct instance. |
| usart | The USART module. |
| dreIntLevel | Data register empty interrupt level. |
Definition at line 81 of file usart_driver.c.
References Usart_and_buffer::buffer, Usart_and_buffer::dreIntLevel, USART_Buffer::RX_Head, USART_Buffer::RX_Tail, USART_Buffer::TX_Head, USART_Buffer::TX_Tail, and Usart_and_buffer::usart.
| uint16_t USART_NineBits_GetChar | ( | USART_t * | usart | ) |
Get received data (9 bit character).
This function reads out the received 9 bit character (uint16_t). Use the function USART_IsRXComplete to check if anything is received.
| usart | The USART module. |
| Received | data. |
Definition at line 313 of file usart_driver.c.
| void USART_NineBits_PutChar | ( | USART_t * | usart, |
| uint16_t | data | ||
| ) |
Put data (9 bit character).
Use the function USART_IsTXDataRegisterEmpty before using this function to put 9 bit character to the TX register.
| usart | The USART module. |
| data | The data to send. |
Definition at line 292 of file usart_driver.c.
| uint8_t USART_RXBuffer_GetByte | ( | USART_data_t * | usart_data | ) |
Get received data (5-8 bit character).
The function USART_RXBufferData_Available should be used before this function is used to ensure that data is available.
Returns data from RX software buffer.
| usart_data | The USART_data_t struct instance. |
Definition at line 204 of file usart_driver.c.
References Usart_and_buffer::buffer, USART_Buffer::RX, USART_Buffer::RX_Tail, and USART_RX_BUFFER_MASK.
| bool USART_RXBufferData_Available | ( | USART_data_t * | usart_data | ) |
Test if there is data in the receive software buffer.
This function can be used to test if there is data in the receive software buffer.
| usart_data | The USART_data_t struct instance |
| true | There is data in the receive buffer. |
| false | The receive buffer is empty. |
Definition at line 181 of file usart_driver.c.
References Usart_and_buffer::buffer, USART_Buffer::RX_Head, and USART_Buffer::RX_Tail.
| bool USART_RXComplete | ( | USART_data_t * | usart_data | ) |
RX Complete Interrupt Service Routine.
RX Complete Interrupt Service Routine. Stores received data in RX software buffer.
| usart_data | The USART_data_t struct instance. |
Definition at line 227 of file usart_driver.c.
References Usart_and_buffer::buffer, USART_Buffer::RX, USART_Buffer::RX_Head, USART_Buffer::RX_Tail, Usart_and_buffer::usart, and USART_RX_BUFFER_MASK.
| bool USART_TXBuffer_FreeSpace | ( | USART_data_t * | usart_data | ) |
Test if there is data in the transmitter software buffer.
This function can be used to test if there is free space in the transmitter software buffer.
| usart_data | The USART_data_t struct instance. |
| true | There is data in the receive buffer. |
| false | The receive buffer is empty. |
Definition at line 123 of file usart_driver.c.
References Usart_and_buffer::buffer, USART_Buffer::TX_Head, USART_Buffer::TX_Tail, and USART_TX_BUFFER_MASK.
Referenced by USART_TXBuffer_PutByte().
| bool USART_TXBuffer_PutByte | ( | USART_data_t * | usart_data, |
| uint8_t | data | ||
| ) |
Put data (5-8 bit character).
Stores data byte in TX software buffer and enables DRE interrupt if there is free space in the TX software buffer.
| usart_data | The USART_data_t struct instance. |
| data | The data to send. |
Definition at line 143 of file usart_driver.c.
References Usart_and_buffer::buffer, Usart_and_buffer::dreIntLevel, USART_Buffer::TX, USART_Buffer::TX_Head, Usart_and_buffer::usart, USART_TX_BUFFER_MASK, and USART_TXBuffer_FreeSpace().
