| 1 |
\documentclass{article} |
| 2 |
\usepackage{avremu} |
| 3 |
\usepackage{listings} |
| 4 |
\usepackage{hyperref} |
| 5 |
\usepackage{filecontents} |
| 6 |
\usepackage{tcolorbox} |
| 7 |
\usepackage{ydoc} |
| 8 |
|
| 9 |
\def\fileversion{v0.1} |
| 10 |
\def\filedate{2014/10/09} |
| 11 |
|
| 12 |
\makeatletter |
| 13 |
\def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}} |
| 14 |
\def\cmd@to@cs#1#2{\char\number`#2\relax} |
| 15 |
\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}} |
| 16 |
\makeatother |
| 17 |
|
| 18 |
\begin{filecontents*}{hello-world.c} |
| 19 |
#include <avr/io.h> |
| 20 |
|
| 21 |
int |
| 22 |
main(void) |
| 23 |
{ |
| 24 |
char *str = "Hello World!"; |
| 25 |
char *p = str; |
| 26 |
while (*p) { |
| 27 |
UDR = *p++; |
| 28 |
} |
| 29 |
asm volatile ("break;"); |
| 30 |
} |
| 31 |
\end{filecontents*} |
| 32 |
|
| 33 |
\title{The \texttt{avremu} Package} |
| 34 |
\author{Christian Dietrich\\ |
| 35 |
\url{[email protected]}\\ |
| 36 |
\url{https://gitlab.brokenpipe.de/stettberger/avremu}} |
| 37 |
|
| 38 |
\begin{document} |
| 39 |
|
| 40 |
\maketitle |
| 41 |
|
| 42 |
\begin{tcolorbox} |
| 43 |
\lstinputlisting[language=C]{hello-world.c} |
| 44 |
\tcblower |
| 45 |
\begin{lstlisting}[language=TeX] |
| 46 |
\avrloadc{hello-world.c} |
| 47 |
\avrrun |
| 48 |
UDR='\avrUDR' in \avrinstrcount\ instructions |
| 49 |
\end{lstlisting} |
| 50 |
\end{tcolorbox} |
| 51 |
\begin{tcolorbox} |
| 52 |
\avrloadc{hello-world.c}\avrrun |
| 53 |
UDR='\avrUDR' in \avrinstrcount\ instructions |
| 54 |
\end{tcolorbox} |
| 55 |
|
| 56 |
|
| 57 |
\LaTeX\ is known as a typesetting system. But the underlying \TeX\ system is a powerful macro |
| 58 |
processor. In fact, TeX is a Turing-complete programming language. \TeX\ can compute anything that |
| 59 |
is computable. Computeability is a concept from theoretical computer science. After visiting a |
| 60 |
theoretical computer-science course, you will know that there are things that cannot be solved by a |
| 61 |
machine. Never. Look out for the halting problem. |
| 62 |
|
| 63 |
This package does contain an \emph{CPU emulator} for the 8-bit microcontroller platform Atmel AVR, more |
| 64 |
precisely it implements the instruction-set architecture of the \texttt{ATmega8}. |
| 65 |
|
| 66 |
\begin{tcolorbox} |
| 67 |
\begin{lstlisting}[language=TeX] |
| 68 |
\avrloadc{mandelbrot.c} |
| 69 |
\avrrun |
| 70 |
|
| 71 |
\avrdrawppm{mandelbrot.ppm} |
| 72 |
\immediate\write18{convert mandelbrot.ppm mandelbrot.png} |
| 73 |
|
| 74 |
\includegraphics[width=\linewidth]{mandelbrot.png} |
| 75 |
\end{lstlisting} |
| 76 |
\tcblower |
| 77 |
This picture (250x250) took 44 hours to render. The source code can be found in the test-suite |
| 78 |
directory under mandelbrot.c.\\ |
| 79 |
|
| 80 |
\includegraphics[width=\linewidth]{imgs/mandelbrot-250x250} |
| 81 |
\end{tcolorbox} |
| 82 |
|
| 83 |
\section{Provided Commands} |
| 84 |
|
| 85 |
\DescribeMacro{\avrloadihex}{\meta{filename}} |
| 86 |
Load an Intel HEX formatted image of the flash into the code memory of the AVR |
| 87 |
emulator. Additionally the state of the AVR emulator is set back to zero. |
| 88 |
|
| 89 |
\DescribeMacro{\avrloadc}[\meta{compiler options}]{\meta{filename}} |
| 90 |
Requires \verb|--shell-escape|. Compiles C source code file with \verb|avr-gcc| and the given |
| 91 |
compiler options. The default compiler option set is \verb|-mmcu=atmega8 -Os|. The resulting |
| 92 |
\texttt{.elf} file is transformed to an Intel HEX file and loaded into the code memory of the |
| 93 |
emulator. |
| 94 |
|
| 95 |
\DescribeMacro{\avrrun} |
| 96 |
Run the emulator until a \textbf{break} instruction occurs. |
| 97 |
|
| 98 |
\DescribeMacro{\avrstep}[\meta{steps}=1] |
| 99 |
Run the emulator for N instructions. The default is a single step. The stepping does automatically |
| 100 |
end, if a \textbf{break} instruction is executed. |
| 101 |
|
| 102 |
\DescribeMacro{\avrinstrcount} |
| 103 |
Expands to the number of executed instructions. |
| 104 |
|
| 105 |
\DescribeMacro{\avrsinglestep} |
| 106 |
Starts an interactive single-stepping mode, which was mainly used for implementing the emulator. |
| 107 |
|
| 108 |
\DescribeMacro{\usravremulibrary}{\meta{list of libraryies}} |
| 109 |
|
| 110 |
\subsection{Access to the Serial Console} |
| 111 |
If the program write to the \verb|UDR| IO register, the emulator catched those characters in an |
| 112 |
internal buffer. |
| 113 |
|
| 114 |
\DescribeMacro{\avrUDR} |
| 115 |
Expands to the internal UDR buffer. |
| 116 |
|
| 117 |
\DescribeMacro{\avrUDRclear} |
| 118 |
Clears the internal UDR buffer. |
| 119 |
|
| 120 |
\subsection{Draw Library} |
| 121 |
\DescribeMacro{\useavremulibrary}{avr.draw} |
| 122 |
|
| 123 |
See source/test-suite/mandelbrot.c for more details. |
| 124 |
|
| 125 |
\section{Implementation Details} |
| 126 |
Read the source. |
| 127 |
\end{document} |
| 128 |
|
| 129 |
%%% Local Variables: |
| 130 |
%%% mode: latex |
| 131 |
%%% TeX-master: t |
| 132 |
%%% End: |