AVR library
Macros | Functions
serque.c File Reference

Buffered USART routines. More...

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <string.h>
#include "circbuf8.h"
#include "swdefs.h"

Macros

#define UBRR0H   UBRRH
 
#define UBRR0L   UBRRL
 
#define UCSR0A   UCSRA
 
#define UCSR0B   UCSRB
 
#define UCSR0C   UCSRC
 
#define RXCIE0   RXCIE
 
#define RXEN0   RXEN
 
#define TXEN0   TXEN
 
#define UCSZ01   UCSZ1
 
#define UCSZ00   UCSZ0
 
#define UDR0   UDR
 
#define UDRIE0   UDRIE
 
#define USART0_UDRE_vect   USART_UDRE_vect
 
#define USART0_RX_vect   USART_RXC_vect
 
#define _URSEL   0
 

Functions

void ser_init (const uint8_t n, const uint16_t br, uint8_t *txb, uint8_t txs, uint8_t *rxb, uint8_t rxs)
 Init USART. More...
 
void ser_shutdown (const uint8_t n)
 Deinit USART. More...
 
void ser_flush_rxbuf (const uint8_t n)
 Flush rx buffer. More...
 
uint8_t ser_putc (const uint8_t n, const char a)
 Enqueue a byte to the serial queue for transmission. More...
 
uint8_t ser_getc (const uint8_t n, uint8_t *const d)
 Get a byte from the serial queue. More...
 

Detailed Description

Buffered USART routines.

All USART data transmission is interrupt driven. Received data is put into a FIFO (provided by circbuf8.c). Data to be transmitted is likewise put into a FIFO. Memory for both FIFOs is provided by the caller on init.

Author
Matej Kogovsek (matej.nosp@m.@ham.nosp@m.radio.nosp@m..si)
Note
This file is part of mat-avr-lib

Function Documentation

void ser_flush_rxbuf ( const uint8_t  n)

Flush rx buffer.

Parameters
[in]nUSART peripheral number (1..2)
uint8_t ser_getc ( const uint8_t  n,
uint8_t *const  d 
)

Get a byte from the serial queue.

Parameters
[in]nUSART peripheral number (1..2)
[out]dPointer to uint8_t where received data is put
Returns
Same as cbuf8_get
void ser_init ( const uint8_t  n,
const uint16_t  br,
uint8_t *  txb,
uint8_t  txs,
uint8_t *  rxb,
uint8_t  rxs 
)

Init USART.

Parameters
[in]nUSART peripheral number (1..2)
[in]brBaudrate (i.e. BAUD_115200 for 115.2k)
[in]txbPointer to caller allocated TX buffer
[in]txssizeof(txb)
[in]rxbPointer to caller allocated RX buffer
[in]rxssizeof(rxs)
uint8_t ser_putc ( const uint8_t  n,
const char  a 
)

Enqueue a byte to the serial queue for transmission.

Parameters
[in]nUSART peripheral number (1..2)
[in]aByte to transmit
void ser_shutdown ( const uint8_t  n)

Deinit USART.

Parameters
[in]nUSART peripheral number (1..2)