\hypertarget{cbio_8c}{
\section{cbio.c File Reference}
\label{cbio_8c}\index{cbio.c@{cbio.c}}
}
{\tt \#include $<$vxWorks.h$>$}\par
{\tt \#include $<$iosLib.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$errnoLib.h$>$}\par
{\tt \#include \char`\"{}CBIO/cbio.h\char`\"{}}\par
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__cbio__Device}{\_\-cbio\_\-Device}
\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
typedef struct \hyperlink{struct__cbio__Device}{\_\-cbio\_\-Device} \hyperlink{cbio_8c_13723547c94c7ec396688376d1847ef9}{cbio\_\-Device}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static STATUS \hyperlink{cbio_8c_02281a725ca7263c6d8d32d3930fcd8b}{cbio\_\-Open} (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$cbioDev, char $\ast$remainder, int mode)
\begin{CompactList}\small\item\em vxWorks device driver open function. \item\end{CompactList}\item 
static STATUS \hyperlink{cbio_8c_26c30dd0fae609d6e3ab0e5ed3c0ead1}{cbio\_\-Write} (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$cbioDev, char $\ast$buffer, int nBytes)
\begin{CompactList}\small\item\em vxWorks device driver write function. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_afca3f54e770008dc408b267b301f50e}{CBIO\_\-Drv} ()
\begin{CompactList}\small\item\em Initialize CBIO vxWorks device driver. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_e146bce9995a9aaf3a3b84cbeb74eab1}{CBIO\_\-DrvRemove} ()
\begin{CompactList}\small\item\em Remove CBIO driver from device table. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_8db9253eecca619b1c257ea660fb1a68}{CBIO\_\-CreateDev} (char $\ast$name, \hyperlink{cbio_8h_0fc1cea9c88b77767de902687bb90004}{CBIO\_\-WriteCallback} $\ast$cbFunction, void $\ast$userData)
\begin{CompactList}\small\item\em Create CBIO device and attach user callback. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_dc978acd34550fd0bac48035a084e9bd}{CBIO\_\-DeleteDev} (char $\ast$name)
\begin{CompactList}\small\item\em Delete CBIO device and clean up allocation. \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
LOCAL int \hyperlink{cbio_8c_0e83b39e75302a50a265621e4784042d}{cbio\_\-driverNum} = -1
\end{CompactItemize}


\subsection{Detailed Description}
\begin{Desc}
\item[Author:]: Ray Caperoon\end{Desc}
\begin{Desc}
\item[Date:]: Thu Apr 3 10:00:33 2003\end{Desc}
Implementation of CBIO module for GLAST. Provides a method for application code to attach a callback to capture/log/telemeter any data printed to stdout or stderr. This is implemented as vxworks driver.

The calling application need to take the following steps to use the CBIO:

1) Install driver with \hyperlink{cbio_8h_afca3f54e770008dc408b267b301f50e}{CBIO\_\-Drv()}. This should be done at boot time or application init.

2) Create one or more CBIO devices with \hyperlink{cbio_8h_0dbe265e4955ba0ede1c26dc3566da28}{CBIO\_\-CreateDev()}. By convention, the devices should be named /cbio/0, /cbio/1, etc. When these devices are created, the application supplies a callback function and user data. The callbacks functions are calld when data is written to a CBIO device type. The callback function takes 3 arguments, the data written to the CBIO device, the number of bytes and a userData pointer. This userData pointer is set in the call to \hyperlink{cbio_8h_0dbe265e4955ba0ede1c26dc3566da28}{CBIO\_\-CreateDev()} and is unique to each open CBIO device.

3) Open a CBIO driver with open() to obtain a file descriptor.

4) Use the file descriptor directly or attach to other vxWorks system resources with logFdAdd(), ioTaskStdSet(), etc.

for cleanup:

5) Use close() to close file descriptor.

6) Use \hyperlink{cbio_8h_2863fcebbae82b124cefe737638111f8}{CBIO\_\-DeleteDev()} to delete the device

7) \hyperlink{cbio_8h_e146bce9995a9aaf3a3b84cbeb74eab1}{CBIO\_\-DrvRemove()} will remove the driver from the kernel.

The application can create a CBIO device and use vxWorks functions such as logFdAdd(), ioTaskStdSet() or ioGlobalStdSet() to provide a point to capture messages printed to the \char`\"{}screen\char`\"{} or unsolicited output from the vxWorks kernel.

This driver is only intended for vxWorks systems. No ports will be supported for other operating systems.

\begin{Desc}
\item[Date]2003/04/10 21:05:00 \end{Desc}
\begin{Desc}
\item[Source]/nfs/slac/g/glast/flight/archive/CBIO/src/cbio.c,v \end{Desc}
\begin{Desc}
\item[Author]ray \end{Desc}
\begin{Desc}
\item[Revision]1.1.1.1 \end{Desc}
\begin{Desc}
\item[Log]\hyperlink{cbio_8c}{cbio.c},v \end{Desc}
Revision 1.1.1.1 2003/04/10 21:05:00 ray Create package CBIO 

\subsection{Typedef Documentation}
\hypertarget{cbio_8c_13723547c94c7ec396688376d1847ef9}{
\index{cbio.c@{cbio.c}!cbio\_\-Device@{cbio\_\-Device}}
\index{cbio\_\-Device@{cbio\_\-Device}!cbio.c@{cbio.c}}
\subsubsection[{cbio\_\-Device}]{\setlength{\rightskip}{0pt plus 5cm}{\bf cbio\_\-Device}}}
\label{cbio_8c_13723547c94c7ec396688376d1847ef9}


The typedef for \hyperlink{struct__cbio__Device}{\_\-cbio\_\-Device}. 

\subsection{Function Documentation}
\hypertarget{cbio_8c_8db9253eecca619b1c257ea660fb1a68}{
\index{cbio.c@{cbio.c}!CBIO\_\-CreateDev@{CBIO\_\-CreateDev}}
\index{CBIO\_\-CreateDev@{CBIO\_\-CreateDev}!cbio.c@{cbio.c}}
\subsubsection[{CBIO\_\-CreateDev}]{\setlength{\rightskip}{0pt plus 5cm}STATUS CBIO\_\-CreateDev (char $\ast$ {\em name}, \/  {\bf CBIO\_\-WriteCallback} $\ast$ {\em cbFunction}, \/  void $\ast$ {\em userData})}}
\label{cbio_8c_8db9253eecca619b1c257ea660fb1a68}


Create CBIO device and attach user callback. 

\hyperlink{cbio_8h_0dbe265e4955ba0ede1c26dc3566da28}{CBIO\_\-CreateDev()} is used to create a CBIO device. This is also where the application attaches a callback and user data to the device. This function must be called to create a CBIO device.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]name of vxworks driver, in the form \char`\"{}/cbio/0\char`\"{}, \char`\"{}/cbio/1\char`\"{}, etc.\item[{\em cbFunction}]Application callback function.\item[{\em userData}]Application callback function.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em OK}]function succeeded\item[{\em FAILED}]CBIO not installed, malloc() or ioDevAdd() failed. \end{description}
\end{Desc}


References \_\-cbio\_\-Device::callback, cbio\_\-driverNum, \_\-cbio\_\-Device::devHdr, and \_\-cbio\_\-Device::userData.\hypertarget{cbio_8c_dc978acd34550fd0bac48035a084e9bd}{
\index{cbio.c@{cbio.c}!CBIO\_\-DeleteDev@{CBIO\_\-DeleteDev}}
\index{CBIO\_\-DeleteDev@{CBIO\_\-DeleteDev}!cbio.c@{cbio.c}}
\subsubsection[{CBIO\_\-DeleteDev}]{\setlength{\rightskip}{0pt plus 5cm}STATUS CBIO\_\-DeleteDev (char $\ast$ {\em name})}}
\label{cbio_8c_dc978acd34550fd0bac48035a084e9bd}


Delete CBIO device and clean up allocation. 

\hyperlink{cbio_8h_2863fcebbae82b124cefe737638111f8}{CBIO\_\-DeleteDev()} is used to delete a CBIO device. The device should be closed before the device is deleted. After removing a device, it cannot be opened until another call to \hyperlink{cbio_8h_0dbe265e4955ba0ede1c26dc3566da28}{CBIO\_\-CreateDev()} is made.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]name of vxworks driver, in the form \char`\"{}/cbio/0\char`\"{}, \char`\"{}/cbio/1\char`\"{}, etc.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em OK}]function succeeded\item[{\em FAILED}]ioDevAdd failed. \end{description}
\end{Desc}
\hypertarget{cbio_8c_afca3f54e770008dc408b267b301f50e}{
\index{cbio.c@{cbio.c}!CBIO\_\-Drv@{CBIO\_\-Drv}}
\index{CBIO\_\-Drv@{CBIO\_\-Drv}!cbio.c@{cbio.c}}
\subsubsection[{CBIO\_\-Drv}]{\setlength{\rightskip}{0pt plus 5cm}STATUS CBIO\_\-Drv ()}}
\label{cbio_8c_afca3f54e770008dc408b267b301f50e}


Initialize CBIO vxWorks device driver. 

This function is called to register the CBIO device driver with the vxWorks kernel. If the driver has already been installed (indicated by the module global cbio\_\-driverNum being set to -1) this funciton will return error. This function will also fail if iosDrvInstall() fails.

This function should be called soon after (or during) kernel startup. It should only be called once unless \hyperlink{cbio_8h_e146bce9995a9aaf3a3b84cbeb74eab1}{CBIO\_\-DrvRemove()} is called to unregister the driver.

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ERROR}]driver already installed or failure of iosDrvInstall()\item[{\em OK}]success \end{description}
\end{Desc}


References cbio\_\-driverNum, cbio\_\-Open(), and cbio\_\-Write().\hypertarget{cbio_8c_e146bce9995a9aaf3a3b84cbeb74eab1}{
\index{cbio.c@{cbio.c}!CBIO\_\-DrvRemove@{CBIO\_\-DrvRemove}}
\index{CBIO\_\-DrvRemove@{CBIO\_\-DrvRemove}!cbio.c@{cbio.c}}
\subsubsection[{CBIO\_\-DrvRemove}]{\setlength{\rightskip}{0pt plus 5cm}STATUS CBIO\_\-DrvRemove ()}}
\label{cbio_8c_e146bce9995a9aaf3a3b84cbeb74eab1}


Remove CBIO driver from device table. 

This function is called to unregister the CBIO device driver with the vxWorks kernel. If the driver has not been installed (indicated by the module global cbio\_\-driverNum being set to a value other than -1) this funciton will return error. This function will also fail if iosDrvRemove() fails.

This function should be called before or during kernel shutdown. It should only be called after \hyperlink{cbio_8h_afca3f54e770008dc408b267b301f50e}{CBIO\_\-Drv()} is called to register the CBIO driver.

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ERROR}]failure of iosDrvInstall() \item[{\em OK}]success \end{description}
\end{Desc}


References cbio\_\-driverNum.\hypertarget{cbio_8c_02281a725ca7263c6d8d32d3930fcd8b}{
\index{cbio.c@{cbio.c}!cbio\_\-Open@{cbio\_\-Open}}
\index{cbio\_\-Open@{cbio\_\-Open}!cbio.c@{cbio.c}}
\subsubsection[{cbio\_\-Open}]{\setlength{\rightskip}{0pt plus 5cm}STATUS cbio\_\-Open ({\bf cbio\_\-Device} $\ast$ {\em cbioDev}, \/  char $\ast$ {\em remainder}, \/  int {\em mode})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{cbio_8c_02281a725ca7263c6d8d32d3930fcd8b}


vxWorks device driver open function. 

This function is registered with the kernel I/O system as the OPEN function. When a CBIO device is open()'ed, this function will be called. The CBIO is a simple device so the open function does nothing but indicate success.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cbioDev}]cbio descriptor used by vxWorks kernel.\item[{\em remainder}]not used. needed to comform to vxWorks device structure.\item[{\em mode}]not used. needed to comform to vxWorks device structure.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em return}]value is bogus \end{description}
\end{Desc}


Referenced by CBIO\_\-Drv().\hypertarget{cbio_8c_26c30dd0fae609d6e3ab0e5ed3c0ead1}{
\index{cbio.c@{cbio.c}!cbio\_\-Write@{cbio\_\-Write}}
\index{cbio\_\-Write@{cbio\_\-Write}!cbio.c@{cbio.c}}
\subsubsection[{cbio\_\-Write}]{\setlength{\rightskip}{0pt plus 5cm}STATUS cbio\_\-Write ({\bf cbio\_\-Device} $\ast$ {\em cbioDev}, \/  char $\ast$ {\em buffer}, \/  int {\em nBytes})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{cbio_8c_26c30dd0fae609d6e3ab0e5ed3c0ead1}


vxWorks device driver write function. 

Called when data is written to cbio device. Passes data on to user callback. If no user callback has been registered, ERROR is returned. The error status should make it's way back to the original caller of write() or printf().

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cbioDev}]cbio descriptor used by vxWorks kernel.\item[{\em buffer}]read buffer passed by caller.\item[{\em nBytes}]number of bytes requested for write.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ERROR}]callback not registered or callback failure\item[{\em OK}]success \end{description}
\end{Desc}


References \_\-cbio\_\-Device::callback, and \_\-cbio\_\-Device::userData.

Referenced by CBIO\_\-Drv().

\subsection{Variable Documentation}
\hypertarget{cbio_8c_0e83b39e75302a50a265621e4784042d}{
\index{cbio.c@{cbio.c}!cbio\_\-driverNum@{cbio\_\-driverNum}}
\index{cbio\_\-driverNum@{cbio\_\-driverNum}!cbio.c@{cbio.c}}
\subsubsection[{cbio\_\-driverNum}]{\setlength{\rightskip}{0pt plus 5cm}{\bf cbio\_\-driverNum} = -1}}
\label{cbio_8c_0e83b39e75302a50a265621e4784042d}


CBIO driver number. Returned by VxWorks IOS facility. A global variable that tracks the index of the drivr in the kernel driver table. Set to -1 when driver is not installed (initialization and calls to CBIO\_\-DrvRemove set it to -1). 

Referenced by CBIO\_\-CreateDev(), CBIO\_\-Drv(), and CBIO\_\-DrvRemove().