avruart
|
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <avr/io.h>
#include <util/atomic.h>
#include <util/setbaud.h>
Go to the source code of this file.
Data Structures | |
struct | DirBuff |
Presenting a circular buffer. More... | |
struct | CBuffer |
This holds the circular buffers. More... | |
struct | UARTcfg |
A struct to configure the UART. More... | |
Macros | |
#define | F_CPU 16000000UL /* 16MHz µc */ |
#define | BAUD 9600L |
#define | UARTAVR_VERSION_MAJOR 0 |
Version major. | |
#define | UARTAVR_VERSION_MINOR 3 |
Version minor. | |
#define | UARTAVR_VERSION_PATCH 0 |
Version patch. | |
#define | CR "\n\r" |
Define the line ending you need. This one will work with minicom on linux. More... | |
#define | CR_PRINTF "\r" |
If set this sign well be send whenever puts_printf_UART() sees a newline character. | |
#define | BUFFSIZE 64 |
The buffer size for the RX and TX buffers. | |
Enumerations | |
enum | DIR_BUFFS { RX_BUFF, TX_BUFF } |
Identifier for direction buffer. More... | |
Functions | |
void | cb_init (void) |
Initializes the circular buffer structure. More... | |
void | get_direction_buffer (enum DIR_BUFFS dir, struct DirBuff **dbuff) |
Get a direction buffer struct from CBuffer. More... | |
uint8_t | cb_pop (char *c, enum DIR_BUFFS dir) |
Get one byte from the circular buffer. More... | |
uint8_t | cp_push (char c, enum DIR_BUFFS dir) |
Put one byte in the circular buffer. More... | |
void | init_uart_cfg (struct UARTcfg *cfg) |
Init a cfg struct with the default values. More... | |
void | init_UART (const struct UARTcfg *cfg) |
Initialize the UART on the microcontroller. More... | |
void | put_UART (const char c) |
Send a single character. More... | |
void | puts_UART (const char *s) |
Write a string to the UART buffer. More... | |
uint8_t | get_UART (char *s) |
Retrieve one char from the buffer. More... | |
uint8_t | gets_UART (char *s) |
Get all data from the circular buffer. More... | |
int | puts_printf_UART (char c, FILE *stream) |
The FILE stream method for uartavr_stdout. More... | |
Variables | |
struct CBuffer | cb |
uartavr is a simple interrupt driven UART implementation for Atmel AVRs. This library uses a circular buffer data structure to store data that should be send or was received. In general the user does not have to interact directly with this buffer as there are some convenience methods already available.
In order to use this implementation you have to use sei which enables interrupts by setting the global interrupt mask.
#define CR "\n\r" |
Define the line ending you need. This one will work with minicom on linux.
This will automatically appended to all strings that you want to send using puts_UART()
enum DIR_BUFFS |
void cb_init | ( | void | ) |
Initializes the circular buffer structure.
uint8_t cb_pop | ( | char * | c, |
enum DIR_BUFFS | dir | ||
) |
Get one byte from the circular buffer.
c | Pointer to char variable |
dir | Get the byte from the TX or RX buffer |
uint8_t cp_push | ( | char | c, |
enum DIR_BUFFS | dir | ||
) |
Put one byte in the circular buffer.
c | A char variable |
dir | Put the byte on the TX or RX buffer |
uint8_t get_UART | ( | char * | s | ) |
Retrieve one char from the buffer.
s | Pointer to a char variable |
uint8_t gets_UART | ( | char * | s | ) |
Get all data from the circular buffer.
s | Pointer an array which this function uses to store the data from cb |
\0
as termination character. You can get the numbers of items in the buffer with DirBuff::items void init_UART | ( | const struct UARTcfg * | cfg | ) |
Initialize the UART on the microcontroller.
cfg | Pointer to a UARTcfg struct with the configuration for the UART |
Some configuration options are currently fixed. The UART will always be setup in 8N1 mode. This may be changed in the future.
This method also initializes a circular buffer. So there is no need to call cb_init() yourself.
void init_uart_cfg | ( | struct UARTcfg * | cfg | ) |
Init a cfg struct with the default values.
cfg |
void put_UART | ( | const char | c | ) |
Send a single character.
c | The character to send |
int puts_printf_UART | ( | char | c, |
FILE * | stream | ||
) |
The FILE stream method for uartavr_stdout.
c | The character to write into the circular buffer |
stream |
init_UART() will bind uartavr_stdout FILE stream to stdout. This way everything that will be written to stdout (e.g. with printf) will effectively be written in the circular buffer of uartavr. You need to link your application against printf_ftl or printf_min to make this work.
void puts_UART | ( | const char * | s | ) |
Write a string to the UART buffer.
s | The string you want to send |
The macro CR will automatically appended to your string so you do not have to worry about this.
struct CBuffer cb |
Global instance of the circular buffer