\hypertarget{can_8c}{
\section{can.c File Reference}
\label{can_8c}\index{can.c@{can.c}}
}
{\tt \#include \char`\"{}t89c51cc02.h\char`\"{}}\par
{\tt \#include \char`\"{}datatypes.h\char`\"{}}\par
{\tt \#include \char`\"{}can.h\char`\"{}}\par
{\tt \#include \char`\"{}command.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{can_8c_aef9c3157dcd88a49284e75c8294439f}{CAN\_\-init} ()
\begin{CompactList}\small\item\em initialize CAN Bus to receive and send packages \item\end{CompactList}\item 
void \hyperlink{can_8c_8d1082d175069c8af510b16fe57b552a}{CAN\_\-interrupt} (void)
\begin{CompactList}\small\item\em ISR for handling incoming CAN Bus messages. \item\end{CompactList}\item 
void \hyperlink{can_8c_035be78326cb1048d7ae61a08c8ed5a7}{CAN\_\-Send\-ACK} (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} cmd)
\begin{CompactList}\small\item\em acknowledge last recieved command via CAN Bus \item\end{CompactList}\item 
void \hyperlink{can_8c_f973b273d28985510a803aa283679134}{CAN\_\-Send\-NAK} (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} cmd)
\begin{CompactList}\small\item\em reply when last command was accepted but could not be completed \item\end{CompactList}\item 
void \hyperlink{can_8c_fadf8cc7df6e0f1a12342e83edb32a78}{CAN\_\-Send\-Msg} (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} length)
\begin{CompactList}\small\item\em transmits a message over the CAN Bus \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
volatile \hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} idata \hyperlink{can_8c_f44be59e397f21bd3c2ea6ba1791158e}{can\_\-data} \mbox{[}8\mbox{]}
\begin{CompactList}\small\item\em data buffer to construct CAN messages to be send \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}


Definition in file \hyperlink{can_8c-source}{can.c}.

\subsection{Function Documentation}
\hypertarget{can_8c_aef9c3157dcd88a49284e75c8294439f}{
\index{can.c@{can.c}!CAN_init@{CAN\_\-init}}
\index{CAN_init@{CAN\_\-init}!can.c@{can.c}}
\subsubsection[CAN\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void CAN\_\-init (void)}}
\label{can_8c_aef9c3157dcd88a49284e75c8294439f}


initialize CAN Bus to receive and send packages 

CAN packets are recieved on CAN ID 0x400 (hardcoded into \hyperlink{can_8h}{can.h})\par
 CAN packets are transmitted on CAN ID 0x401 \par
 The bus is put into 250kbps mode. 

Definition at line 29 of file can.c.

References CAN\_\-setchannel, CH\_\-DISABLE, and MSK\_\-CANGCON\_\-GRES.

Referenced by main().\hypertarget{can_8c_8d1082d175069c8af510b16fe57b552a}{
\index{can.c@{can.c}!CAN_interrupt@{CAN\_\-interrupt}}
\index{CAN_interrupt@{CAN\_\-interrupt}!can.c@{can.c}}
\subsubsection[CAN\_\-interrupt]{\setlength{\rightskip}{0pt plus 5cm}void CAN\_\-interrupt (void)}}
\label{can_8c_8d1082d175069c8af510b16fe57b552a}


ISR for handling incoming CAN Bus messages. 

A small implicit state machine is used to decode valid CAN messages. 

Definition at line 119 of file can.c.

References can\_\-data, CAN\_\-Send\-ACK(), CAN\_\-Send\-Msg(), CAN\_\-Send\-NAK(), CAN\_\-setchannel, Command\_\-Check\-Time, Command\_\-Clear\-Monitor, Command\_\-Clear\-Read, Command\_\-Disable\-Monitor(), Command\_\-Disable\-Report, COMMAND\_\-EEPROM\_\-CLEAR, COMMAND\_\-EEPROM\_\-SAVEMONITOR, Command\_\-Enable\-Monitor(), Command\_\-Enable\-Report(), COMMAND\_\-MONITOR, COMMAND\_\-MONITORSTATUS, COMMAND\_\-READ, COMMAND\_\-RECALLMONITOR, COMMAND\_\-REPORT, COMMAND\_\-RESET, Command\_\-Set\-Read(), COMMAND\_\-STOPALLMONITORS, COMMAND\_\-STOPMONITOR, COMMAND\_\-STOPREPORT, COMMAND\_\-TIMECHECK\_\-DISABLE, COMMAND\_\-TIMECHECK\_\-ENABLE, Command\_\-Timecheck\-Disable, Command\_\-Timecheck\-Enable, COMMAND\_\-TIMECHECKSTATUS, monitor, read\_\-eeprom\_\-config, and write\_\-eeprom\_\-config.\hypertarget{can_8c_035be78326cb1048d7ae61a08c8ed5a7}{
\index{can.c@{can.c}!CAN_SendACK@{CAN\_\-SendACK}}
\index{CAN_SendACK@{CAN\_\-SendACK}!can.c@{can.c}}
\subsubsection[CAN\_\-SendACK]{\setlength{\rightskip}{0pt plus 5cm}void CAN\_\-Send\-ACK (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} {\em cmd})}}
\label{can_8c_035be78326cb1048d7ae61a08c8ed5a7}


acknowledge last recieved command via CAN Bus 

The ACK message consists of the command byte to be acknowledged and an ASCII ACK \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cmd}]numerical representation of last CAN command to be acknowledged \end{description}
\end{Desc}


Definition at line 296 of file can.c.

References CAN\_\-ACK, CAN\_\-enablechannel, CAN\_\-setchannel, CH\_\-DISABLE, and CH\_\-Tx\-ENA.

Referenced by CAN\_\-interrupt().\hypertarget{can_8c_fadf8cc7df6e0f1a12342e83edb32a78}{
\index{can.c@{can.c}!CAN_SendMsg@{CAN\_\-SendMsg}}
\index{CAN_SendMsg@{CAN\_\-SendMsg}!can.c@{can.c}}
\subsubsection[CAN\_\-SendMsg]{\setlength{\rightskip}{0pt plus 5cm}void CAN\_\-Send\-Msg (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} {\em length})}}
\label{can_8c_fadf8cc7df6e0f1a12342e83edb32a78}


transmits a message over the CAN Bus 

The message content has to be specified in \hyperlink{can_8h_f44be59e397f21bd3c2ea6ba1791158e}{can\_\-data} and the data length code has to be given.\par
 Transmission of the message is suspended as long as there is a message transmission in progress.\par
 During transfer of the buffer contents to the CAN controller the CAN interrupt is disabled. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em length}]length of data package \end{description}
\end{Desc}


Definition at line 344 of file can.c.

References can\_\-data, CAN\_\-enablechannel, CAN\_\-setchannel, CH\_\-DISABLE, and CH\_\-Tx\-ENA.

Referenced by CAN\_\-interrupt(), and main().\hypertarget{can_8c_f973b273d28985510a803aa283679134}{
\index{can.c@{can.c}!CAN_SendNAK@{CAN\_\-SendNAK}}
\index{CAN_SendNAK@{CAN\_\-SendNAK}!can.c@{can.c}}
\subsubsection[CAN\_\-SendNAK]{\setlength{\rightskip}{0pt plus 5cm}void CAN\_\-Send\-NAK (\hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} {\em cmd})}}
\label{can_8c_f973b273d28985510a803aa283679134}


reply when last command was accepted but could not be completed 

The function works similar to \hyperlink{can_8h_1646e9b44da3dbaaa1dda18db73519fe}{CAN\_\-Send\-ACK} but a NAK is send instead of the ACK to signal an imcomplete command or wrong data format. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cmd}]numerical representation of last CAN command for which the NAK answer is valid \end{description}
\end{Desc}


Definition at line 319 of file can.c.

References CAN\_\-enablechannel, CAN\_\-NAK, CAN\_\-setchannel, CH\_\-DISABLE, and CH\_\-Tx\-ENA.

Referenced by CAN\_\-interrupt().

\subsection{Variable Documentation}
\hypertarget{can_8c_f44be59e397f21bd3c2ea6ba1791158e}{
\index{can.c@{can.c}!can_data@{can\_\-data}}
\index{can_data@{can\_\-data}!can.c@{can.c}}
\subsubsection[can\_\-data]{\setlength{\rightskip}{0pt plus 5cm}volatile \hyperlink{datatypes_8h_92076741b75a8c2bdc5c24049c253d9a}{BYTE} idata \hyperlink{can_8h_f44be59e397f21bd3c2ea6ba1791158e}{can\_\-data}\mbox{[}8\mbox{]}}}
\label{can_8c_f44be59e397f21bd3c2ea6ba1791158e}


data buffer to construct CAN messages to be send 

The buffer resides in indirect addressable IRAM space of the T89C51CC02.\par
 The buffer is shared for both recieving and sending therefor disabling the CAN interrupt is advisable before sending. 

Definition at line 19 of file can.c.

Referenced by CAN\_\-interrupt(), CAN\_\-Send\-Msg(), and main().