\section{util/dll-src/loader.c File Reference}
\label{loader_8c}\index{util/dll-src/loader.c@{util/dll-src/loader.c}}
Brick\-OS task downloading. 

{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$unistd.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$fcntl.h$>$}\par
{\tt \#include $<$sys/time.h$>$}\par
{\tt \#include $<$sys/types.h$>$}\par
{\tt \#include $<$signal.h$>$}\par
{\tt \#include $<$errno.h$>$}\par
{\tt \#include $<$sys/lnp.h$>$}\par
{\tt \#include $<$sys/lnp-logical.h$>$}\par
{\tt \#include \char`\"{}rcxtty.h\char`\"{}}\par
{\tt \#include \char`\"{}keepalive.h\char`\"{}}\par
{\tt \#include $<$lx.h$>$}\par
{\tt \#include $<$getopt.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf MAX\_\-DATA\_\-CHUNK}\ 0xf8
\begin{CompactList}\small\item\em maximum data bytes/packet for boot protocol \item\end{CompactList}\item 
\#define {\bf XMIT\_\-RETRIES}\ 5
\begin{CompactList}\small\item\em number of packet transmit retries \item\end{CompactList}\item 
\#define {\bf REPLY\_\-TIMEOUT}\ 750000
\begin{CompactList}\small\item\em timeout for reply \item\end{CompactList}\item 
\#define {\bf BYTE\_\-TIME}\ (1000$\ast$LNP\_\-BYTE\_\-TIME)
\begin{CompactList}\small\item\em time to transmit a byte. \item\end{CompactList}\item 
\#define {\bf PROG\_\-MIN}\ 1
\item 
\#define {\bf PROG\_\-MAX}\ 8
\item 
\#define {\bf ADDR\_\-MIN}\ 0
\item 
\#define {\bf ADDR\_\-MAX}\ 15
\item 
\#define {\bf DEFAULT\_\-DEST}\ 0
\item 
\#define {\bf DEFAULT\_\-PROGRAM}\ PROG\_\-MIN
\item 
\#define {\bf DEFAULT\_\-SRCPORT}\ 0
\item 
\#define {\bf DEFAULT\_\-PRIORITY}\ 10
\item 
\#define {\bf HAVE\_\-GETOPT\_\-LONG}\ 1
\end{CompactItemize}
\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum {\bf packet\_\-cmd\_\-t} \{ \par
{\bf CMDacknowledge}, 
{\bf CMDdelete}, 
{\bf CMDcreate}, 
{\bf CMDoffsets}, 
\par
{\bf CMDdata}, 
{\bf CMDrun}, 
{\bf CMDirmode}, 
{\bf CMDsethost}, 
\par
{\bf CMDlast}
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf io\_\-handler} (void)
\item 
int {\bf lnp\_\-logical\_\-write} (const void $\ast$data, {\bf size\_\-t} length)
\item 
int {\bf lnp\_\-assured\_\-write} (const unsigned char $\ast$data, unsigned char length, unsigned char dest, unsigned char srcport)
\begin{CompactList}\small\item\em send a LNP layer 0 packet of given length \item\end{CompactList}\item 
void {\bf LNPinit} (const char $\ast$tty)
\item 
void {\bf ahandler} (const unsigned char $\ast$data, unsigned char len, unsigned char src)
\item 
void {\bf lnp\_\-download} (const {\bf lx\_\-t} $\ast$lx)
\item 
int {\bf main} (int argc, char $\ast$$\ast$argv)
\begin{CompactList}\small\item\em the user {\bf main()}{\rm (p.\,\pageref{fontdesign_8c_a1})} \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
const struct option {\bf long\_\-options} [$\,$]
\item 
volatile int {\bf received\-Ack} = 0
\item 
volatile unsigned short {\bf relocate\_\-to} = 0
\item 
unsigned int {\bf rcxaddr}
\item 
int {\bf run\_\-flag} = 0
\item 
int {\bf verbose\_\-flag} = 0
\begin{CompactList}\small\item\em display some diagnostics if non-zero \item\end{CompactList}\item 
int {\bf tty\_\-usb} = 0
\item 
int {\bf pdelete\_\-flag} = 0
\item 
int {\bf hostaddr\_\-flag} = 0
\end{CompactItemize}


\subsection{Detailed Description}
Brick\-OS task downloading. 

\begin{Desc}
\item[Author:]Markus L. Noga $<${\tt markus@noga.de}$>$\end{Desc}


Definition in file {\bf loader.c}.

\subsection{Define Documentation}
\index{loader.c@{loader.c}!ADDR_MAX@{ADDR\_\-MAX}}
\index{ADDR_MAX@{ADDR\_\-MAX}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ADDR\_\-MAX\ 15}\label{loader_8c_a7}




Definition at line 94 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!ADDR_MIN@{ADDR\_\-MIN}}
\index{ADDR_MIN@{ADDR\_\-MIN}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ADDR\_\-MIN\ 0}\label{loader_8c_a6}




Definition at line 93 of file loader.c.\index{loader.c@{loader.c}!BYTE_TIME@{BYTE\_\-TIME}}
\index{BYTE_TIME@{BYTE\_\-TIME}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define BYTE\_\-TIME\ (1000$\ast$LNP\_\-BYTE\_\-TIME)}\label{loader_8c_a3}


time to transmit a byte. 



Definition at line 88 of file loader.c.\index{loader.c@{loader.c}!DEFAULT_DEST@{DEFAULT\_\-DEST}}
\index{DEFAULT_DEST@{DEFAULT\_\-DEST}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define DEFAULT\_\-DEST\ 0}\label{loader_8c_a8}




Definition at line 96 of file loader.c.\index{loader.c@{loader.c}!DEFAULT_PRIORITY@{DEFAULT\_\-PRIORITY}}
\index{DEFAULT_PRIORITY@{DEFAULT\_\-PRIORITY}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define DEFAULT\_\-PRIORITY\ 10}\label{loader_8c_a11}




Definition at line 99 of file loader.c.\index{loader.c@{loader.c}!DEFAULT_PROGRAM@{DEFAULT\_\-PROGRAM}}
\index{DEFAULT_PROGRAM@{DEFAULT\_\-PROGRAM}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define DEFAULT\_\-PROGRAM\ PROG\_\-MIN}\label{loader_8c_a9}




Definition at line 97 of file loader.c.\index{loader.c@{loader.c}!DEFAULT_SRCPORT@{DEFAULT\_\-SRCPORT}}
\index{DEFAULT_SRCPORT@{DEFAULT\_\-SRCPORT}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define DEFAULT\_\-SRCPORT\ 0}\label{loader_8c_a10}




Definition at line 98 of file loader.c.\index{loader.c@{loader.c}!HAVE_GETOPT_LONG@{HAVE\_\-GETOPT\_\-LONG}}
\index{HAVE_GETOPT_LONG@{HAVE\_\-GETOPT\_\-LONG}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define HAVE\_\-GETOPT\_\-LONG\ 1}\label{loader_8c_a12}




Definition at line 116 of file loader.c.\index{loader.c@{loader.c}!MAX_DATA_CHUNK@{MAX\_\-DATA\_\-CHUNK}}
\index{MAX_DATA_CHUNK@{MAX\_\-DATA\_\-CHUNK}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define MAX\_\-DATA\_\-CHUNK\ 0xf8}\label{loader_8c_a0}


maximum data bytes/packet for boot protocol 



Definition at line 85 of file loader.c.\index{loader.c@{loader.c}!PROG_MAX@{PROG\_\-MAX}}
\index{PROG_MAX@{PROG\_\-MAX}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define PROG\_\-MAX\ 8}\label{loader_8c_a5}




Definition at line 91 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!PROG_MIN@{PROG\_\-MIN}}
\index{PROG_MIN@{PROG\_\-MIN}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define PROG\_\-MIN\ 1}\label{loader_8c_a4}




Definition at line 90 of file loader.c.\index{loader.c@{loader.c}!REPLY_TIMEOUT@{REPLY\_\-TIMEOUT}}
\index{REPLY_TIMEOUT@{REPLY\_\-TIMEOUT}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define REPLY\_\-TIMEOUT\ 750000}\label{loader_8c_a2}


timeout for reply 



Definition at line 87 of file loader.c.

Referenced by io\_\-handler(), and lnp\_\-assured\_\-write().\index{loader.c@{loader.c}!XMIT_RETRIES@{XMIT\_\-RETRIES}}
\index{XMIT_RETRIES@{XMIT\_\-RETRIES}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define XMIT\_\-RETRIES\ 5}\label{loader_8c_a1}


number of packet transmit retries 



Definition at line 86 of file loader.c.

\subsection{Enumeration Type Documentation}
\index{loader.c@{loader.c}!packet_cmd_t@{packet\_\-cmd\_\-t}}
\index{packet_cmd_t@{packet\_\-cmd\_\-t}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf packet\_\-cmd\_\-t}}\label{loader_8c_a38}


\begin{Desc}
\item[Enumeration values: ]\par
\begin{description}
\index{CMDacknowledge@{CMDacknowledge}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDacknowledge@{CMDacknowledge}}\item[{\em 
CMDacknowledge\label{loader_8c_a38a22}
}]1: \index{CMDdelete@{CMDdelete}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDdelete@{CMDdelete}}\item[{\em 
CMDdelete\label{loader_8c_a38a23}
}]1+ 1: b[nr] \index{CMDcreate@{CMDcreate}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDcreate@{CMDcreate}}\item[{\em 
CMDcreate\label{loader_8c_a38a24}
}]1+12: b[nr] s[textsize] s[datasize] s[bsssize] s[stacksize] s[start] b[prio] \index{CMDoffsets@{CMDoffsets}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDoffsets@{CMDoffsets}}\item[{\em 
CMDoffsets\label{loader_8c_a38a25}
}]1+ 7: b[nr] s[text] s[data] s[bss] \index{CMDdata@{CMDdata}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDdata@{CMDdata}}\item[{\em 
CMDdata\label{loader_8c_a38a26}
}]1+$>$3: b[nr] s[offset] array[data] \index{CMDrun@{CMDrun}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDrun@{CMDrun}}\item[{\em 
CMDrun\label{loader_8c_a38a27}
}]1+ 1: b[nr] \index{CMDirmode@{CMDirmode}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDirmode@{CMDirmode}}\item[{\em 
CMDirmode\label{loader_8c_a38a28}
}]1+ 1: b[0=near/1=far] \index{CMDsethost@{CMDsethost}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDsethost@{CMDsethost}}\item[{\em 
CMDsethost\label{loader_8c_a38a29}
}]1+ 1: b[hostaddr] \index{CMDlast@{CMDlast}!loader.c@{loader.c}}\index{loader.c@{loader.c}!CMDlast@{CMDlast}}\item[{\em 
CMDlast\label{loader_8c_a38a30}
}]? \end{description}
\end{Desc}



Definition at line 101 of file loader.c.

\subsection{Function Documentation}
\index{loader.c@{loader.c}!ahandler@{ahandler}}
\index{ahandler@{ahandler}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void ahandler (const unsigned char $\ast$ {\em data}, unsigned char {\em len}, unsigned char {\em src})}\label{loader_8c_a35}




Definition at line 342 of file loader.c.

References received\-Ack, and relocate\_\-to.

Referenced by main().\index{loader.c@{loader.c}!io_handler@{io\_\-handler}}
\index{io_handler@{io\_\-handler}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void io\_\-handler (void)}\label{loader_8c_a31}




Definition at line 238 of file loader.c.

References NULL, rcx\-FD(), REPLY\_\-TIMEOUT, and tty\_\-usb.

Referenced by lnp\_\-assured\_\-write().\index{loader.c@{loader.c}!lnp_assured_write@{lnp\_\-assured\_\-write}}
\index{lnp_assured_write@{lnp\_\-assured\_\-write}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int lnp\_\-assured\_\-write (const unsigned char $\ast$ {\em data}, unsigned char {\em length}, unsigned char {\em dest}, unsigned char {\em srcport})}\label{loader_8c_a33}


send a LNP layer 0 packet of given length 

\begin{Desc}
\item[Returns:]0 on success. \end{Desc}


Definition at line 189 of file loader.c.

References io\_\-handler(), NULL, rcx\-FD(), received\-Ack, and REPLY\_\-TIMEOUT.

Referenced by lnp\_\-download(), and main().\index{loader.c@{loader.c}!lnp_download@{lnp\_\-download}}
\index{lnp_download@{lnp\_\-download}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void lnp\_\-download (const {\bf lx\_\-t} $\ast$ {\em lx})}\label{loader_8c_a36}




Definition at line 353 of file loader.c.

References lx\_\-t::data\_\-size, exit(), lnp\_\-assured\_\-write(), memcpy(), rcxaddr, size\_\-t, lx\_\-t::text, and lx\_\-t::text\_\-size.

Referenced by main().\index{loader.c@{loader.c}!lnp_logical_write@{lnp\_\-logical\_\-write}}
\index{lnp_logical_write@{lnp\_\-logical\_\-write}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int lnp\_\-logical\_\-write (const void $\ast$ {\em data}, {\bf size\_\-t} {\em length})}\label{loader_8c_a32}


blocking I/R write. ! return number of bytes written, or negative for error. 

Definition at line 162 of file loader.c.

References keepalive\-Renew(), mywrite(), NULL, rcx\-FD(), and tty\_\-usb.\index{loader.c@{loader.c}!LNPinit@{LNPinit}}
\index{LNPinit@{LNPinit}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void LNPinit (const char $\ast$ {\em tty})}\label{loader_8c_a34}




Definition at line 291 of file loader.c.

References exit(), keepalive\-Init(), myperror(), rcx\-FD(), rcx\-Init(), and tty\_\-usb.

Referenced by main().\index{loader.c@{loader.c}!main@{main}}
\index{main@{main}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int main (int {\em argc}, char $\ast$$\ast$ {\em argv})}\label{loader_8c_a37}


the user {\bf main()}{\rm (p.\,\pageref{fontdesign_8c_a1})} 



Definition at line 379 of file loader.c.

References ADDR\_\-MAX, ahandler(), lx\_\-t::bss\_\-size, lx\_\-t::data\_\-size, hostaddr\_\-flag, lnp\_\-assured\_\-write(), lnp\_\-download(), LNPinit(), long\_\-options, lx\_\-read(), lx\_\-relocate(), lx\_\-t::offset, pdelete\_\-flag, PROG\_\-MAX, rcxaddr, relocate\_\-to, run\_\-flag, lx\_\-t::stack\_\-size, lx\_\-t::text\_\-size, tty\_\-usb, TTY\_\-VARIABLE, and verbose\_\-flag.

\subsection{Variable Documentation}
\index{loader.c@{loader.c}!hostaddr_flag@{hostaddr\_\-flag}}
\index{hostaddr_flag@{hostaddr\_\-flag}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int {\bf hostaddr\_\-flag} = 0}\label{loader_8c_a21}




Definition at line 155 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!long_options@{long\_\-options}}
\index{long_options@{long\_\-options}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}const struct option {\bf long\_\-options}[$\,$]\hspace{0.3cm}{\tt  [static]}}\label{loader_8c_a13}


{\bf Initial value:}

\footnotesize\begin{verbatim}{
  {"rcxaddr",required_argument,0,'r'},
  {"program",required_argument,0,'p'},
  {"delete", required_argument,0,'d'},
  {"srcport",required_argument,0,'s'},
  {"tty",    required_argument,0,'t'},
  {"irmode", required_argument,0,'i'},
  {"node"  , required_argument,0,'n'},
  {"execute",no_argument      ,0,'e'},
  {"verbose",no_argument      ,0,'v'},
  {0        ,0                ,0,0  }
}
\end{verbatim}\normalsize 


Definition at line 122 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!pdelete_flag@{pdelete\_\-flag}}
\index{pdelete_flag@{pdelete\_\-flag}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int {\bf pdelete\_\-flag} = 0}\label{loader_8c_a20}




Definition at line 154 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!rcxaddr@{rcxaddr}}
\index{rcxaddr@{rcxaddr}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned int {\bf rcxaddr}}\label{loader_8c_a16}


{\bf Initial value:}

\footnotesize\begin{verbatim} DEFAULT_DEST
              prog    = DEFAULT_PROGRAM
              srcport = DEFAULT_SRCPORT
              hostaddr = DEFAULT_DEST
                  irmode  = -1
\end{verbatim}\normalsize 


Definition at line 145 of file loader.c.

Referenced by lnp\_\-download(), and main().\index{loader.c@{loader.c}!receivedAck@{receivedAck}}
\index{receivedAck@{receivedAck}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}volatile int {\bf received\-Ack} = 0}\label{loader_8c_a14}




Definition at line 141 of file loader.c.

Referenced by ahandler(), and lnp\_\-assured\_\-write().\index{loader.c@{loader.c}!relocate_to@{relocate\_\-to}}
\index{relocate_to@{relocate\_\-to}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}volatile unsigned short {\bf relocate\_\-to} = 0}\label{loader_8c_a15}




Definition at line 143 of file loader.c.

Referenced by ahandler(), and main().\index{loader.c@{loader.c}!run_flag@{run\_\-flag}}
\index{run_flag@{run\_\-flag}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int {\bf run\_\-flag} = 0}\label{loader_8c_a17}




Definition at line 151 of file loader.c.

Referenced by main().\index{loader.c@{loader.c}!tty_usb@{tty\_\-usb}}
\index{tty_usb@{tty\_\-usb}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int {\bf tty\_\-usb} = 0}\label{loader_8c_a19}




Definition at line 153 of file loader.c.

Referenced by io\_\-handler(), lnp\_\-logical\_\-write(), LNPinit(), main(), nbread(), rcx\_\-init(), rcx\_\-send(), rcx\-Init(), and rx\_\-flush().\index{loader.c@{loader.c}!verbose_flag@{verbose\_\-flag}}
\index{verbose_flag@{verbose\_\-flag}!loader.c@{loader.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int {\bf verbose\_\-flag} = 0}\label{loader_8c_a18}


display some diagnostics if non-zero 



Definition at line 152 of file loader.c.