\hypertarget{cbio_8c}{
\section{cbio.c File Reference}
\label{cbio_8c}\index{cbio.c@{cbio.c}}
}
{\tt \#include $<$vx\-Works.h$>$}\par
{\tt \#include $<$ios\-Lib.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$errno\-Lib.h$>$}\par
{\tt \#include \char`\"{}CBIO/cbio.h\char`\"{}}\par
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__cbio__Device}{\_\-cbio\_\-Device}
\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
typedef \hyperlink{struct__cbio__Device}{\_\-cbio\_\-Device} \hyperlink{cbio_8c_a0}{cbio\_\-Device}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
STATUS \hyperlink{cbio_8c_a2}{cbio\_\-Open} (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$cbio\-Dev, char $\ast$remainder, int mode)
\begin{CompactList}\small\item\em vx\-Works device driver open function. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_a3}{cbio\_\-Write} (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$cbio\-Dev, char $\ast$buffer, int n\-Bytes)
\begin{CompactList}\small\item\em vx\-Works device driver write function. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_a4}{CBIO\_\-Drv} ()
\begin{CompactList}\small\item\em Initialize CBIO vx\-Works device driver. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_a5}{CBIO\_\-Drv\-Remove} ()
\begin{CompactList}\small\item\em Remove CBIO driver from device table. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_a6}{CBIO\_\-Create\-Dev} (char $\ast$name, \hyperlink{cbio_8h_a0}{CBIO\_\-Write\-Callback} $\ast$cb\-Function, void $\ast$user\-Data)
\begin{CompactList}\small\item\em Create CBIO device and attach user callback. \item\end{CompactList}\item 
STATUS \hyperlink{cbio_8c_a7}{CBIO\_\-Delete\-Dev} (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_a1}{cbio\_\-driver\-Num} = -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_8c_a4}{CBIO\_\-Drv()}. This should be done at boot time or application init.

2) Create one or more CBIO devices with \hyperlink{cbio_8c_a6}{CBIO\_\-Create\-Dev()}. 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 user\-Data pointer. This user\-Data pointer is set in the call to \hyperlink{cbio_8c_a6}{CBIO\_\-Create\-Dev()} 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 vx\-Works system resources with log\-Fd\-Add(), io\-Task\-Std\-Set(), etc.

for cleanup:

5) Use close() to close file descriptor.

6) Use \hyperlink{cbio_8c_a7}{CBIO\_\-Delete\-Dev()} to delete the device

7) \hyperlink{cbio_8c_a5}{CBIO\_\-Drv\-Remove()} will remove the driver from the kernel.

The application can create a CBIO device and use vx\-Works functions such as log\-Fd\-Add(), io\-Task\-Std\-Set() or io\-Global\-Std\-Set() to provide a point to capture messages printed to the \char`\"{}screen\char`\"{} or unsolicited output from the vx\-Works kernel.

This driver is only intended for vx\-Works 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_a0}{
\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}\hyperlink{struct__cbio__Device}{cbio\_\-Device}}}
\label{cbio_8c_a0}


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

\subsection{Function Documentation}
\hypertarget{cbio_8c_a6}{
\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\_\-Create\-Dev (char $\ast$ {\em name}, \hyperlink{cbio_8h_a0}{CBIO\_\-Write\-Callback} $\ast$ {\em cb\-Function}, void $\ast$ {\em user\-Data})}}
\label{cbio_8c_a6}


Create CBIO device and attach user callback. 

\hyperlink{cbio_8c_a6}{CBIO\_\-Create\-Dev()} 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 cb\-Function}]Application callback function.\item[{\em user\-Data}]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 io\-Dev\-Add() failed. \end{description}
\end{Desc}
\hypertarget{cbio_8c_a7}{
\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\_\-Delete\-Dev (char $\ast$ {\em name})}}
\label{cbio_8c_a7}


Delete CBIO device and clean up allocation. 

\hyperlink{cbio_8c_a7}{CBIO\_\-Delete\-Dev()} 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_8c_a6}{CBIO\_\-Create\-Dev()} 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}]io\-Dev\-Add failed. \end{description}
\end{Desc}
\hypertarget{cbio_8c_a4}{
\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_a4}


Initialize CBIO vx\-Works device driver. 

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

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

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ERROR}]driver already installed or failure of ios\-Drv\-Install()\item[{\em OK}]success \end{description}
\end{Desc}
\hypertarget{cbio_8c_a5}{
\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\_\-Drv\-Remove ()}}
\label{cbio_8c_a5}


Remove CBIO driver from device table. 

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

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

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ERROR}]failure of ios\-Drv\-Install() \item[{\em OK}]success \end{description}
\end{Desc}
\hypertarget{cbio_8c_a2}{
\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 (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$ {\em cbio\-Dev}, char $\ast$ {\em remainder}, int {\em mode})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{cbio_8c_a2}


vx\-Works 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 cbio\-Dev}]cbio descriptor used by vx\-Works kernel.\item[{\em remainder}]not used. needed to comform to vx\-Works device structure.\item[{\em mode}]not used. needed to comform to vx\-Works device structure.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em return}]value is bogus\end{description}
\end{Desc}
\hypertarget{cbio_8c_a3}{
\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 (\hyperlink{struct__cbio__Device}{cbio\_\-Device} $\ast$ {\em cbio\-Dev}, char $\ast$ {\em buffer}, int {\em n\-Bytes})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{cbio_8c_a3}


vx\-Works 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 cbio\-Dev}]cbio descriptor used by vx\-Works kernel.\item[{\em buffer}]read buffer passed by caller.\item[{\em n\-Bytes}]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}


\subsection{Variable Documentation}
\hypertarget{cbio_8c_a1}{
\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}\hyperlink{cbio_8c_a1}{cbio\_\-driver\-Num} = -1}}
\label{cbio_8c_a1}


CBIO driver number. Returned by Vx\-Works 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\_\-Drv\-Remove set it to -1).