usrat.c File Reference

USART interface. More...

#include <stdio.h>
#include <avr/io.h>
#include "usrat.h"
Include dependency graph for usrat.c:

Functions

void usart_init (uint16_t baudval)
 Initialize USART, perform fdevopen with uart_putchar.
void usart_stop ()
 Disable USART completely.
int uart_putchar (char data)
 putchar() for USART.
int uart_getchar ()
 getchar() for USART. Wait for data if not available.
uint8_t uart_available ()
 Check data availability in USART buffer.
uint8_t uart_getc ()
 Nonblocking, nonchecking getchar for USART. Use with care.
void SIG_UART_RECV (void)

Detailed Description

USART interface.


Function Documentation

void SIG_UART_RECV ( void   ) 

00083                            {
00084     rx_buffer[rx_buffer_in] = (uint8_t)UDR;
00085     rx_buffer_in = (rx_buffer_in + 1) % RX_BUFFER_SIZE;
00086 }

uint8_t uart_available ( void   ) 

Check data availability in USART buffer.

Returns:
1 if buffer is not empty.

00070                          {
00071     return rx_buffer_in != rx_buffer_out;
00072 }

uint8_t uart_getc (  ) 

Nonblocking, nonchecking getchar for USART. Use with care.

00075                     {
00076     uint8_t result = rx_buffer[rx_buffer_out];
00077     rx_buffer_out = (rx_buffer_out + 1) % RX_BUFFER_SIZE;
00078     
00079     return result;
00080 }

int uart_getchar (  ) 

getchar() for USART. Wait for data if not available.

Returns:
value read.
See also:
uart_available()

00062                    {
00063     while (!uart_available());
00064     
00065     return (int) uart_getc();
00066 }

Here is the call graph for this function:

int uart_putchar ( char  data  ) 

putchar() for USART.

Parameters:
data character to print.

00044                             {
00045     //while (!(UCSRA & (1<<UDRE))) {};
00046     if (data == '\n') {
00047         (void)uart_putchar('\r');
00048     }
00049 
00050     //PORTD |= 1<<5;
00051     while (!(UCSRA & (1<<UDRE))) {};
00052     //PORTD &= (uint8_t)(~(1<<5));
00053 
00054     UDR = (uint8_t)data;
00055 
00056     return 0;
00057 }

Here is the call graph for this function:

void usart_init ( uint16_t  baudval  ) 

Initialize USART, perform fdevopen with uart_putchar.

Parameters:
baudval (F_CPU/(16*baudrate))-1
See also:
uart_putchar()

00020                                   {
00021     // Set baud rate
00022     UBRRH = (uint8_t)(baudval>>8);
00023     UBRRL = (uint8_t)baudval;
00024 
00025     rx_buffer_in = rx_buffer_out = 0;
00026 
00027     // Set frame format: 8 data, 1 stop bit
00028     UCSRC = (uint8_t)((1<<URSEL) | (0<<USBS) | (3<<UCSZ0));
00029     
00030     // Enable receiver and transmitter, enable RX complete interrupt
00031     UCSRB = (uint8_t)((1<<RXEN) | (1<<TXEN) | (1<<RXCIE));
00032 
00033     (void)fdevopen(uart_putchar, NULL/*, 0*/);
00034 }

Here is the call graph for this function:

void usart_stop (  ) 

Disable USART completely.

00037                   {
00038     UCSRB = 0;
00039     (void)fdevopen(uart_non,NULL);
00040 }


Generated on Sat Dec 12 00:45:14 2009 for Patashnik by  doxygen 1.6.1