#ident "@(#)fgrab.h	1.1 -- 07/15/92"

#define i_scsi	initialize_scsi

/****************************************************************************
*	Copyright (C) 1990 Analogic/CDA											*
*																			*
*	fgrab.h			Sun support package for Analogic/CDA Frame Grabber Demo	*
*																			*
*	27Feb90			(V. Michael Oratovsky)									*
*****************************************************************************
*
*	Framegrabber support package, be it on a Sun or PC or some other system
*	must provide the following macros, C-language typedefs, and functions in
*	addition to appropriate #include directives:
*
*********************** #defines for the following macros *******************

EOL					end-of-line character (typically the line feed)

EOF					end-of-file constant (if not already defined)

FOPEN_CREATE_APPEND	the "mode" argument passed to fopen() used to open a new
					file for writing, or overwrite an existing file.

TARGET_DASM			the name of the dasm device passed to initialize_scsi() -
					whatever is appropriate for your system - note that this
					constant has to be legal for the C typedef target_t which
					you also have to define.

************************** typedefs for the following ************************

target_t			This is the data type of the variable referring to the dasm
					scsi device.  It is passed to the initialize_scsi() func-
					tion, which you must also provide.

handle_t			This is the data type which initialize_scsi() returns for
					every target that it is asked to initialize.  From that
					point on the demo programs will refer to the selected
					dasm scsi device via this handle.  It will be passed to
					write_scsi() and read_scsi() functions which you must
					also provide.

************************** the following functions ***************************

int scsi_hard_reset()	This function is for resetting the host scsi controller,
						assuming that it is possible and desired.  It is to
						return 0 on success, -1 otherwise.

int scsi_soft_reset( target )	This function is meant for resetting a single
target_t target ;				scsi slave unit attached to the scsi bus on
								systems where this is possible and necessary.
								Essentially, this would reset the FrameGrabber.
								It is to return 0 on success, -1 otherwise.


handle_t initialize_scsi( target )	This function is meant for "opening" the
target_t target ;					dasm FrameGrabber scsi device.  Whether
									or not this function actually goes out and
									touches any hardware is up to the system
									and/or you.  This function is not required
									to touch the dasm, but it may choose to do
									so in order to send a command block with
									some default values.  This function has to
									return a handle which will be used for
									subsequent accesses thru scsi_read() and
									scsi_write().  Return -1 on failure.


int write_scsi(target_id, buffer, starting_block, number_of_blocks)

handle_t target_handle ;			Handle returned by initialize_scsi().
unsigned char *buffer;				Address of buffer to be written.
long int starting_block;			Starting block number to be written.
unsigned int number_of_blocks;		Total number of blocks to write.

									This function must provide RAW block
									access to the scsi device.  It is to
									return 0 on success, error code otherwise.



int write_scsi(target_id, buffer, starting_block, number_of_blocks)

handle_t target_handle ;			Handle returned by initialize_scsi().
unsigned char *buffer;				Address of buffer to be written.
long int starting_block;			Starting block number to be written.
unsigned int number_of_blocks;		Total number of blocks to write.

									This function must provide RAW block
									access to the scsi device.  It is to
									return 0 on success, error code otherwise.


unsigned char *grabmem(blocks)		This function typically maps directly onto
unsigned int blocks;				malloc().  It is responsible for allocating
									a chunk of memory big enough to hold the
									requested number of blocks.  It returns a
									pointer on success, NULL on failure.

**********	Once you provide the facilities described	*************
**********	above, you should be able to compile, link	*************
**********	and run the FrameGrabber demo utilities.	*************
**********	How you decide to implement these require-	*************
**********	ments is entirely up to you.  You could		*************
**********	implement some (or all) of the required		*************
**********	functions by inventing clever macros, or	*************
**********	you could simply go ahead and implement		*************
**********	them as honest-to-goodness C functions.		*************/

/*	+---------------------------------------------------+
	|	This is the support package for a Sun system	|
	|													|
	|	It relies on scsi device manipulation routines	|
	|	found in scsi_io.c - good only on a Sun.		|
	|	It contains the following functions:			|
	|	scsi_open(), scsi_close(), scsi_read_blocks(),	|
	|	and scsi_write_blocks().						|
	+---------------------------------------------------+	*/

#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#define EOL '\n'

#define FOPEN_CREATE_APPEND	"w+"	/* how to open a (new) file for writing */

#ifdef ix386
#define TARGET_DASM		"/dev/rdsk/1p0"   /* 386ix */ 
#else
#define TARGET_DASM		"/dev/dasm0" 
#endif

typedef int 			handle_t;	/* handles are integer file descriptors */
typedef char 			*target_t;	/* device names on a Sun are strings */

#define write_scsi(target_handle, buffer, starting_block, number_of_blocks) \
  scsi_write_blocks(target_handle, buffer, starting_block, number_of_blocks)

#define read_scsi(target_handle, buffer, starting_block, number_of_blocks) \
  scsi_read_blocks(target_handle, buffer, starting_block, number_of_blocks)

#define grabmem(blocks) (unsigned char *)malloc((blocks) * 512)

int scsi_hard_reset()				/* This is very unwise to do because */
{									/* the system disk is controlled by  */
	return(0);						/* the scsi controller, and I defi-  */
}									/* nitely don't want to reset that.  */

int scsi_soft_reset( target )		/* There is no need, nor an easy way */
target_t target ;					/* to do this on a Sun when the sys- */
{									/* tem disk lives on the same scsi bus. */
	return(0);
}

handle_t initialize_scsi( target )
target_t target ;
{
	return( scsi_open( target ) );
}
