Defines | Functions | Variables

# uart.c File Reference

Implementation of USART Stack. More...

`#include <avr/io.h>`
`#include <avr/interrupt.h>`
`#include "uart.h"`
Include dependency graph for uart.c:

Go to the source code of this file.

## Defines
#define | _UART_C_ 1
## Functions
void | uart_init (void)
| Initialise the USART Module.
void | uart_sendbyte (uint8_t data)
| Send one Byte.
uint8_t | uart_senddata (uint8_t data)
| Send one data byte without buffering in the FIFO.
uint8_t | uart_sendid (uint8_t data)
| Send one id byte without buffering in the FIFO.
uint8_t | uart_getbyte (uint8_t *data)
| Pull one Byte from RX-Buffer.
int | uart_putchar (char c, FILE *sream)
| Send one Byte (printf version)
int | uart_getchar (FILE *stream)
| Pull one Byte from RX-Buffer.
| ISR (RXC_vect)
| Interrupt-Service-Routine for the RX-Complete Interrupt.
| ISR (DRE_vect)
| Interrupt-Service-Routine for the Data-Register-Empty Interrupt.
## Variables
uint8_t | rx_buffer [UART_RX_BUFFER_SIZE]
| Memory for the Receive FIFO.
uint8_t | tx_buffer [UART_TX_BUFFER_SIZE]
| Memory for the Transmit FIFO.
volatile uint8_t | rx_head = 0
| head index of the Receive FIFO
volatile uint8_t | rx_tail = 0
| tail index of the Receive FIFO
volatile uint8_t | tx_head = 0
| head index of the Transmit FIFO
volatile uint8_t | tx_tail = 0
| tail index of the Transmit FIFO

## Detailed Description

Implementation of USART Stack.

Author:
  Dominic Rathje (dominic.rathje@uni-ulm.de)

Version:
  1.0

Note:
  - Compiler : WinAVR 20100110
  - Supported devices : ATMega8

Definition in file uart.c.

## Function Documentation

ISR | ( | RXC_vect | ) |

Interrupt-Service-Routine for the RX-Complete Interrupt.

If a RX-Complete Interrupt occurs:

- checkt if there is any space left in the FIFO Buffer
- copy the received byte into the buffer

Definition at line 130 of file uart.c.

ISR | ( | DRE_vect | ) |

Interrupt-Service-Routine for the Data-Register-Empty Interrupt.

If a Data-Register-Empty Interrupt occurs:

- check if there is pending data in the FIFO
  - if yes: send the next byte
  - if no: disable URDE Interrupt

Definition at line 145 of file uart.c.

Here is the call graph for this function:

uint8_t uart_getbyte | ( | uint8_t * | data ) |

Pull one Byte from RX-Buffer.

If the RX-Fifo is enabled any data receives is automaticaly pusched into the Fifo ba the ISR. This function removes the oldest Byte from the Buffer and copies it into the Memory-Space which is handed over as a parameter.

See also:
  uart_getchar for the scanf compatible version

Parameters:

  data | pointer to a buffer where the received data is copied to

Returns:
  true if data has been copied. false if the RX buffer was empty

Definition at line 72 of file uart.c.

int uart_getchar | ( | FILE * | stream ) |

Pull one Byte from RX-Buffer.

If the RX-Fifo is enabled any data receives is automaticaly pusched into the Fifo ba the ISR. This function removes the oldest Byte from the Buffer and copies it into the Memory-Space which is handed over as a parameter.

See also:
  uart_getbyte for the standard version

Returns:
  received data or _FDEV_EOF

Definition at line 110 of file uart.c.

void uart_init | ( | void | ) |

Initialise the USART Module.

Configures the Port Registers and the USART Module. Call this function at the beginning of your main function.

Definition at line 27 of file uart.c.

Here is the call graph for this function:

int uart_putchar | ( | char | c,
|  | FILE * | sream
| ) |  |

Send one Byte (printf version)

This fuction sends one byte by copyint the data into the fifo-buffer and enabling the UDRE-Interrupt. The actual transmission is then initiated by the Interrupt-Service-Routine. If the buffer is full this function waits until the next byte has been transmitted, so it is always successful.

This is the printf compatible version ov uart_sendbyte

See also:
  uart_sendbyte for the standars version

Parameters:

  data | Data-Byte to send

Returns:
  always 0

Definition at line 101 of file uart.c.

Here is the call graph for this function:

void uart_sendbyte | ( | uint8_t | data ) |

Send one Byte.

This fuction sends one byte by copying the data into the fifo-buffer and enabling the UDRE-Interrupt. The actual transmission is then initiated by the Interrupt-Service-Routine. If the buffer is full this function waits until the next byte has been transmitted, so it is always successful.

See also:
  uart_putchar for the printf compatible version

Parameters:

  data | Data-Byte to send

Definition at line 48 of file uart.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t uart_senddata | ( | uint8_t | data ) |

Send one data byte without buffering in the FIFO.

Parameters:

  data | Data-Byte to send

Returns:
  true if data has been send. else false

Definition at line 56 of file uart.c.

uint8_t uart_sendid | ( | uint8_t | data ) |

Send one id byte without buffering in the FIFO.

This function is only for use in 9-Bit Character Size and MPCM Mode. The ninth bit es set to 1 to send an address/id frame.

Parameters:

  data | Data-Byte to send

Returns:
  true if data has been send. else false

Definition at line 64 of file uart.c.