\hypertarget{uart_8c}{
\section{uart.c File Reference}
\label{uart_8c}\index{uart.c@{uart.c}}
}


Implementation of USART Stack.  


{\ttfamily \#include $<$avr/io.h$>$}\par
{\ttfamily \#include $<$avr/interrupt.h$>$}\par
{\ttfamily \#include \char`\"{}uart.h\char`\"{}}\par
Include dependency graph for uart.c:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=279pt]{uart_8c__incl}
\end{center}
\end{figure}
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\hypertarget{uart_8c_aa83798b7dffa125b6e7896802f38f20a}{
\#define {\bfseries \_\-UART\_\-C\_\-}~1}
\label{uart_8c_aa83798b7dffa125b6e7896802f38f20a}

\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{uart_8c_a0c0ca72359ddf28dcd15900dfba19343}{uart\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Initialise the USART Module. \item\end{DoxyCompactList}\item 
void \hyperlink{uart_8c_aa37263506354fb968fb7b6b211892e4d}{uart\_\-sendbyte} (uint8\_\-t data)
\begin{DoxyCompactList}\small\item\em Send one Byte. \item\end{DoxyCompactList}\item 
uint8\_\-t \hyperlink{uart_8c_a5f25ebb9990551d061cb7e1c8a7d1355}{uart\_\-senddata} (uint8\_\-t data)
\begin{DoxyCompactList}\small\item\em Send one data byte without buffering in the FIFO. \item\end{DoxyCompactList}\item 
uint8\_\-t \hyperlink{uart_8c_aea449f3c91e613a4518cfcd77f48762e}{uart\_\-sendid} (uint8\_\-t data)
\begin{DoxyCompactList}\small\item\em Send one id byte without buffering in the FIFO. \item\end{DoxyCompactList}\item 
uint8\_\-t \hyperlink{uart_8c_a625ab0ae20701f3b2b5f46d438e54f51}{uart\_\-getbyte} (uint8\_\-t $\ast$data)
\begin{DoxyCompactList}\small\item\em Pull one Byte from RX-\/Buffer. \item\end{DoxyCompactList}\item 
int \hyperlink{uart_8c_ac3c226432ab26e07e928dcee1dcc7630}{uart\_\-putchar} (char c, FILE $\ast$sream)
\begin{DoxyCompactList}\small\item\em Send one Byte (printf version) \item\end{DoxyCompactList}\item 
int \hyperlink{uart_8c_ae29d6eea5f2e7997551b4acb64082d8e}{uart\_\-getchar} (FILE $\ast$stream)
\begin{DoxyCompactList}\small\item\em Pull one Byte from RX-\/Buffer. \item\end{DoxyCompactList}\item 
\hyperlink{uart_8c_a286140fc854cee1e35a615090de02af3}{ISR} (RXC\_\-vect)
\begin{DoxyCompactList}\small\item\em Interrupt-\/Service-\/Routine for the RX-\/Complete Interrupt. \item\end{DoxyCompactList}\item 
\hyperlink{uart_8c_aa30d86cd776cbd761e3e714987b3323d}{ISR} (DRE\_\-vect)
\begin{DoxyCompactList}\small\item\em Interrupt-\/Service-\/Routine for the Data-\/Register-\/Empty Interrupt. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\hypertarget{uart_8c_ab84155a3d2305e59a6fb6f3d3791c5c7}{
uint8\_\-t \hyperlink{uart_8c_ab84155a3d2305e59a6fb6f3d3791c5c7}{rx\_\-buffer} \mbox{[}UART\_\-RX\_\-BUFFER\_\-SIZE\mbox{]}}
\label{uart_8c_ab84155a3d2305e59a6fb6f3d3791c5c7}

\begin{DoxyCompactList}\small\item\em Memory for the Receive FIFO. \item\end{DoxyCompactList}\item 
\hypertarget{uart_8c_ab89d038143f0aa00291e71359700143d}{
uint8\_\-t \hyperlink{uart_8c_ab89d038143f0aa00291e71359700143d}{tx\_\-buffer} \mbox{[}UART\_\-TX\_\-BUFFER\_\-SIZE\mbox{]}}
\label{uart_8c_ab89d038143f0aa00291e71359700143d}

\begin{DoxyCompactList}\small\item\em Memory for the Transmit FIFO. \item\end{DoxyCompactList}\item 
\hypertarget{uart_8c_aa05a46cea94d19035fa075f27d6f4571}{
volatile uint8\_\-t \hyperlink{uart_8c_aa05a46cea94d19035fa075f27d6f4571}{rx\_\-head} = 0}
\label{uart_8c_aa05a46cea94d19035fa075f27d6f4571}

\begin{DoxyCompactList}\small\item\em head index of the Receive FIFO \item\end{DoxyCompactList}\item 
\hypertarget{uart_8c_a619b585d82637125e07ddc7832ff999e}{
volatile uint8\_\-t \hyperlink{uart_8c_a619b585d82637125e07ddc7832ff999e}{rx\_\-tail} = 0}
\label{uart_8c_a619b585d82637125e07ddc7832ff999e}

\begin{DoxyCompactList}\small\item\em tail index of the Receive FIFO \item\end{DoxyCompactList}\item 
\hypertarget{uart_8c_abbf149233ac55c827371f7ed3c5aadb7}{
volatile uint8\_\-t \hyperlink{uart_8c_abbf149233ac55c827371f7ed3c5aadb7}{tx\_\-head} = 0}
\label{uart_8c_abbf149233ac55c827371f7ed3c5aadb7}

\begin{DoxyCompactList}\small\item\em head index of the Transmit FIFO \item\end{DoxyCompactList}\item 
\hypertarget{uart_8c_aacdeab28a6150e19a446172b41da6b90}{
volatile uint8\_\-t \hyperlink{uart_8c_aacdeab28a6150e19a446172b41da6b90}{tx\_\-tail} = 0}
\label{uart_8c_aacdeab28a6150e19a446172b41da6b90}

\begin{DoxyCompactList}\small\item\em tail index of the Transmit FIFO \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Implementation of USART Stack. \begin{DoxyAuthor}{Author}
Dominic Rathje (\href{mailto:dominic.rathje@uni-ulm.de}{\tt dominic.rathje@uni-\/ulm.de}) 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
1.0 
\end{DoxyVersion}
\begin{DoxyNote}{Note}

\begin{DoxyItemize}
\item Compiler : WinAVR 20100110
\item Supported devices : ATMega8 
\end{DoxyItemize}
\end{DoxyNote}


Definition in file \hyperlink{uart_8c_source}{uart.c}.



\subsection{Function Documentation}
\hypertarget{uart_8c_a286140fc854cee1e35a615090de02af3}{
\index{uart.c@{uart.c}!ISR@{ISR}}
\index{ISR@{ISR}!uart.c@{uart.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (
\begin{DoxyParamCaption}
\item[{RXC\_\-vect}]{}
\end{DoxyParamCaption}
)}}
\label{uart_8c_a286140fc854cee1e35a615090de02af3}


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

If a RX-\/Complete Interrupt occurs:
\begin{DoxyItemize}
\item checkt if there is any space left in the FIFO Buffer
\item copy the received byte into the buffer 
\end{DoxyItemize}

Definition at line 130 of file uart.c.

\hypertarget{uart_8c_aa30d86cd776cbd761e3e714987b3323d}{
\index{uart.c@{uart.c}!ISR@{ISR}}
\index{ISR@{ISR}!uart.c@{uart.c}}
\subsubsection[{ISR}]{\setlength{\rightskip}{0pt plus 5cm}ISR (
\begin{DoxyParamCaption}
\item[{DRE\_\-vect}]{}
\end{DoxyParamCaption}
)}}
\label{uart_8c_aa30d86cd776cbd761e3e714987b3323d}


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

If a Data-\/Register-\/Empty Interrupt occurs:
\begin{DoxyItemize}
\item check if there is pending data in the FIFO
\begin{DoxyItemize}
\item if yes: send the next byte
\item if no: disable URDE Interrupt 
\end{DoxyItemize}
\end{DoxyItemize}

Definition at line 145 of file uart.c.



Here is the call graph for this function:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=240pt]{uart_8c_aa30d86cd776cbd761e3e714987b3323d_cgraph}
\end{center}
\end{figure}


\hypertarget{uart_8c_a625ab0ae20701f3b2b5f46d438e54f51}{
\index{uart.c@{uart.c}!uart\_\-getbyte@{uart\_\-getbyte}}
\index{uart\_\-getbyte@{uart\_\-getbyte}!uart.c@{uart.c}}
\subsubsection[{uart\_\-getbyte}]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t uart\_\-getbyte (
\begin{DoxyParamCaption}
\item[{uint8\_\-t $\ast$}]{ data}
\end{DoxyParamCaption}
)}}
\label{uart_8c_a625ab0ae20701f3b2b5f46d438e54f51}


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.

\begin{DoxySeeAlso}{See also}
\hyperlink{uart_8h_ae29d6eea5f2e7997551b4acb64082d8e}{uart\_\-getchar} for the scanf compatible version 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em data} & pointer to a buffer where the received data is copied to \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if data has been copied. false if the RX buffer was empty 
\end{DoxyReturn}


Definition at line 72 of file uart.c.

\hypertarget{uart_8c_ae29d6eea5f2e7997551b4acb64082d8e}{
\index{uart.c@{uart.c}!uart\_\-getchar@{uart\_\-getchar}}
\index{uart\_\-getchar@{uart\_\-getchar}!uart.c@{uart.c}}
\subsubsection[{uart\_\-getchar}]{\setlength{\rightskip}{0pt plus 5cm}int uart\_\-getchar (
\begin{DoxyParamCaption}
\item[{FILE $\ast$}]{ stream}
\end{DoxyParamCaption}
)}}
\label{uart_8c_ae29d6eea5f2e7997551b4acb64082d8e}


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.

\begin{DoxySeeAlso}{See also}
\hyperlink{uart_8h_a625ab0ae20701f3b2b5f46d438e54f51}{uart\_\-getbyte} for the standard version 
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
received data or \_\-FDEV\_\-EOF 
\end{DoxyReturn}


Definition at line 110 of file uart.c.

\hypertarget{uart_8c_a0c0ca72359ddf28dcd15900dfba19343}{
\index{uart.c@{uart.c}!uart\_\-init@{uart\_\-init}}
\index{uart\_\-init@{uart\_\-init}!uart.c@{uart.c}}
\subsubsection[{uart\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void uart\_\-init (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{uart_8c_a0c0ca72359ddf28dcd15900dfba19343}


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:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=252pt]{uart_8c_a0c0ca72359ddf28dcd15900dfba19343_cgraph}
\end{center}
\end{figure}


\hypertarget{uart_8c_ac3c226432ab26e07e928dcee1dcc7630}{
\index{uart.c@{uart.c}!uart\_\-putchar@{uart\_\-putchar}}
\index{uart\_\-putchar@{uart\_\-putchar}!uart.c@{uart.c}}
\subsubsection[{uart\_\-putchar}]{\setlength{\rightskip}{0pt plus 5cm}int uart\_\-putchar (
\begin{DoxyParamCaption}
\item[{char}]{ c, }
\item[{FILE $\ast$}]{ sream}
\end{DoxyParamCaption}
)}}
\label{uart_8c_ac3c226432ab26e07e928dcee1dcc7630}


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

\begin{DoxySeeAlso}{See also}
\hyperlink{uart_8h_aa37263506354fb968fb7b6b211892e4d}{uart\_\-sendbyte} for the standars version 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em data} & Data-\/Byte to send \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
always 0 
\end{DoxyReturn}


Definition at line 101 of file uart.c.



Here is the call graph for this function:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=278pt]{uart_8c_ac3c226432ab26e07e928dcee1dcc7630_cgraph}
\end{center}
\end{figure}


\hypertarget{uart_8c_aa37263506354fb968fb7b6b211892e4d}{
\index{uart.c@{uart.c}!uart\_\-sendbyte@{uart\_\-sendbyte}}
\index{uart\_\-sendbyte@{uart\_\-sendbyte}!uart.c@{uart.c}}
\subsubsection[{uart\_\-sendbyte}]{\setlength{\rightskip}{0pt plus 5cm}void uart\_\-sendbyte (
\begin{DoxyParamCaption}
\item[{uint8\_\-t}]{ data}
\end{DoxyParamCaption}
)}}
\label{uart_8c_aa37263506354fb968fb7b6b211892e4d}


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.

\begin{DoxySeeAlso}{See also}
\hyperlink{uart_8h_ac3c226432ab26e07e928dcee1dcc7630}{uart\_\-putchar} for the printf compatible version 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em data} & Data-\/Byte to send \\
\hline
\end{DoxyParams}


Definition at line 48 of file uart.c.



Here is the call graph for this function:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=284pt]{uart_8c_aa37263506354fb968fb7b6b211892e4d_cgraph}
\end{center}
\end{figure}




Here is the caller graph for this function:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=278pt]{uart_8c_aa37263506354fb968fb7b6b211892e4d_icgraph}
\end{center}
\end{figure}


\hypertarget{uart_8c_a5f25ebb9990551d061cb7e1c8a7d1355}{
\index{uart.c@{uart.c}!uart\_\-senddata@{uart\_\-senddata}}
\index{uart\_\-senddata@{uart\_\-senddata}!uart.c@{uart.c}}
\subsubsection[{uart\_\-senddata}]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t uart\_\-senddata (
\begin{DoxyParamCaption}
\item[{uint8\_\-t}]{ data}
\end{DoxyParamCaption}
)}}
\label{uart_8c_a5f25ebb9990551d061cb7e1c8a7d1355}


Send one data byte without buffering in the FIFO. 


\begin{DoxyParams}{Parameters}
{\em data} & Data-\/Byte to send \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if data has been send. else false 
\end{DoxyReturn}


Definition at line 56 of file uart.c.

\hypertarget{uart_8c_aea449f3c91e613a4518cfcd77f48762e}{
\index{uart.c@{uart.c}!uart\_\-sendid@{uart\_\-sendid}}
\index{uart\_\-sendid@{uart\_\-sendid}!uart.c@{uart.c}}
\subsubsection[{uart\_\-sendid}]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t uart\_\-sendid (
\begin{DoxyParamCaption}
\item[{uint8\_\-t}]{ data}
\end{DoxyParamCaption}
)}}
\label{uart_8c_aea449f3c91e613a4518cfcd77f48762e}


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.


\begin{DoxyParams}{Parameters}
{\em data} & Data-\/Byte to send \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if data has been send. else false 
\end{DoxyReturn}


Definition at line 64 of file uart.c.

