\subchapter{Output-only character driver}{Objective: implement the
  write part of a character driver}

After this lab, you will be able to:

\begin{itemize}
\item Write a simple character driver, allowing to write data to the
  serial port of your CALAO board.
\item Write simple \code{file_operations} functions for a device,
  including \code{ioctl} controls.
\item Copy data from user memory space to kernel memory space and
  eventually to the device.
\item You will practice kernel standard error codes a little bit too.
\end{itemize}

\section{Setup}

You must have completed the previous lab before.

Stay in the \code{/home/<user>/felabs/linux/character} directory.

\section{Major number registration}

Find an available character device major number on your virtual
system. Modify the \code{serial.c} file to register this major number
in your new driver. Compile your module, load it, and check that it
effectively registered the major number you chose.

\section{Simplistic character driver}

Add the code to register a character driver with your major number, and
the empty file operation functions which already exist in
\code{serial.c}. Also create the corresponding \code{/dev/serial} device file.

Now, add code to your write function, to copy user data to the serial
port, writing characters one by one.

Once done, compile and load your module. Test that your \code{write} function
works properly by using:

\begin{verbatim}
echo "test" > /dev/serial
\end{verbatim}

The \code{test} string should appear on the remote side (i.e in
the \code{picocom} process connected to \code{/dev/ttyUSB1}).

You'll quickly discover than newlines do not work properly. To fix
this, when the userspace application sends \verb+"\n"+, you must send
\verb+"\n\r"+ to the serial port.

\section{Driver sanity check}

Once again, make sure that you can load your module again after
removing it.

\section{Ioctl operation}

We would like to maintain a counter of the number of characters
written through the serial port. So we need to implement two
\code{unlocked_ioctl()} operations:
\begin{itemize}

 \item \code{SERIAL_RESET_COUNTER}, which as its name says, will
   reset the counter to zero

 \item \code{SERIAL_GET_COUNTER}, which will return in a variable
   passed by address the current value of the counter.

\end{itemize}

Two already-compiled test applications are already available in the
\code{nfsroot/root/} directory, with their source code. They assume that
\code{SERIAL_RESET_COUNTER} is ioctl operation 0 and that
\code{SERIAL_GET_COUNTER} is ioctl operation 1.
