OpenCBM
Macros | Functions | Variables
xum1541.c File Reference

libusb-based xum1541 access routines More...

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "opencbm.h"
#include "arch.h"
#include "dynlibusb.h"
#include "getpluginaddress.h"
#include "xum1541.h"

Go to the source code of this file.

Macros

#define TAPE_SUPPORT   1
 
#define LIBUSB_PATH_MAX   512
 
#define PREFIX_OFFSET   (sizeof("libusb/xum1541:") - 1)
 
#define RefuseToWorkInWrongMode
 

Functions

const char * xum1541_device_path (int PortNumber)
 Query unique identifier for the xum1541 device This function tries to find an unique identifier for the xum1541 device. More...
 
int xum1541_init (usb_dev_handle **HandleXum1541, int PortNumber)
 Initialize the xum1541 device This function tries to find and identify the xum1541 device. More...
 
void xum1541_close (usb_dev_handle *HandleXum1541)
 close the xum1541 device More...
 
int xum1541_control_msg (usb_dev_handle *HandleXum1541, unsigned int cmd)
 Handle synchronous USB control messages, e.g. for RESET. xum1541_ioctl() is used for bulk messages. More...
 
int xum1541_ioctl (usb_dev_handle *HandleXum1541, unsigned int cmd, unsigned int addr, unsigned int secaddr)
 Perform an ioctl on the xum1541, which is any command other than read/write or special device management commands such as INIT and RESET. More...
 
int xum1541_tap_break (usb_dev_handle *HandleXum1541)
 Send tape operations abort command to the xum1541 device. More...
 
int xum1541_write (usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size)
 Write data to the xum1541 device. More...
 
int xum1541_write_ext (usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size, int *Status, int *BytesWritten)
 Wrapper for xum1541_write() forcing xum1541_wait_status(), with additional parameters: More...
 
int xum1541_read_ext (usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size, int *Status, int *BytesRead)
 Wrapper for xum1541_read() forcing xum1541_wait_status(), with additional parameters: More...
 
int xum1541_read (usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size)
 Read data from the xum1541 device. More...
 

Variables

unsigned char DeviceDriveMode
 

Detailed Description

libusb-based xum1541 access routines



Author
Nate Lawson

Definition in file xum1541.c.

Macro Definition Documentation

#define RefuseToWorkInWrongMode
Value:
{ \
if (/*uh->*/DeviceDriveMode == DeviceDriveMode_Uninit) \
{ \
xum1541_dbg(1, "[RefuseToWorkInWrongMode] cmd blocked - No disk or tape mode set."); \
return XUM1541_Error_NoDiskTapeMode; \
} \
\
if (isTapeCmd) \
{ \
if (/*uh->*/DeviceDriveMode == DeviceDriveMode_NoTapeSupport) \
{ \
xum1541_dbg(1, "[RefuseToWorkInWrongMode] cmd blocked - Firmware has no tape support."); \
return XUM1541_Error_NoTapeSupport; \
} \
\
if (/*uh->*/DeviceDriveMode == DeviceDriveMode_Disk) \
{ \
xum1541_dbg(1, "[RefuseToWorkInWrongMode] cmd blocked - Tape cmd in disk mode."); \
return XUM1541_Error_TapeCmdInDiskMode; \
} \
} \
else /*isDiskCmd*/ \
{ \
if (/*uh->*/DeviceDriveMode == DeviceDriveMode_Tape) \
{ \
xum1541_dbg(1, "[RefuseToWorkInWrongMode] cmd blocked - Disk cmd in tape mode."); \
return XUM1541_Error_DiskCmdInTapeMode; \
} \
} \
}

Definition at line 563 of file xum1541.c.

Function Documentation

void xum1541_close ( usb_dev_handle *  HandleXum1541)

close the xum1541 device

Parameters
HandleXum1541Pointer to a XUM1541_HANDLE which will contain the file handle of the USB device.
Remarks
This function releases the interface and closes the xum1541 handle.

Definition at line 466 of file xum1541.c.

Referenced by opencbm_plugin_driver_close(), xum1541_device_path(), and xum1541_init().

int xum1541_control_msg ( usb_dev_handle *  HandleXum1541,
unsigned int  cmd 
)

Handle synchronous USB control messages, e.g. for RESET. xum1541_ioctl() is used for bulk messages.

Parameters
HandleXum1541A XUM1541_HANDLE which contains the file handle of the USB device.
cmdThe command to run.
Returns
Returns the value the USB device sent back.

Definition at line 499 of file xum1541.c.

Referenced by opencbm_plugin_reset(), xum1541_plugin_control_msg(), and xum1541_tap_break().

const char* xum1541_device_path ( int  PortNumber)

Query unique identifier for the xum1541 device This function tries to find an unique identifier for the xum1541 device.

Parameters
PortNumberThe device's serial number to search for also. It is not considered, if set to 0.
Returns
0 on success, -1 on error. On error, the handle is cleaned up if it was already active.
Remarks
On success, xum1541_handle contains a valid handle to the xum1541 device. In this case, the device configuration has been set and the interface been claimed. xum1541_close() should be called when the user is done with it.

Definition at line 287 of file xum1541.c.

References xum1541_close().

Referenced by opencbm_plugin_get_driver_name().

int xum1541_init ( usb_dev_handle **  HandleXum1541,
int  PortNumber 
)

Initialize the xum1541 device This function tries to find and identify the xum1541 device.

Parameters
HandleXum1541Pointer to a XUM1541_HANDLE which will contain the file handle of the USB device.
PortNumberThe device's serial number to search for also. It is not considered, if set to 0.
Returns
0 on success, -1 on error. On error, the handle is cleaned up if it was already active.
Remarks
On success, xum1541_handle contains a valid handle to the xum1541 device. In this case, the device configuration has been set and the interface been claimed. xum1541_close() should be called when the user is done with it.

Definition at line 374 of file xum1541.c.

References xum1541_close().

Referenced by opencbm_plugin_driver_open().

int xum1541_ioctl ( usb_dev_handle *  HandleXum1541,
unsigned int  cmd,
unsigned int  addr,
unsigned int  secaddr 
)

Perform an ioctl on the xum1541, which is any command other than read/write or special device management commands such as INIT and RESET.

Parameters
HandleXum1541A XUM1541_HANDLE which contains the file handle of the USB device.
cmdThe command to run.
addrThe IEC device to use or 0 if not needed.
secaddrThe IEC secondary address to use or 0 if not needed.
Returns
Returns the device status byte, which is 0 if the command does not have a return value. For some commands, the status byte gives info from the device such as the active IEC lines.

Definition at line 616 of file xum1541.c.

Referenced by opencbm_plugin_clear_eoi(), opencbm_plugin_get_eoi(), opencbm_plugin_iec_poll(), opencbm_plugin_iec_release(), opencbm_plugin_iec_set(), opencbm_plugin_iec_setrelease(), opencbm_plugin_iec_wait(), opencbm_plugin_pp_read(), and opencbm_plugin_pp_write().

int xum1541_read ( usb_dev_handle *  HandleXum1541,
unsigned char  mode,
unsigned char *  data,
size_t  size 
)

Read data from the xum1541 device.

Parameters
HandleXum1541A XUM1541_HANDLE which contains the file handle of the USB device.
modeDrive protocol to use to read the data from the device (e.g, XUM1541_CBM is normal IEC wire protocol).
dataPointer to a buffer which will contain the data read from the xum1541
sizeThe number of bytes to read from the xum1541
Returns
The number of bytes actually read, 0 on device error. If there is a fatal error, returns -1.

Definition at line 833 of file xum1541.c.

Referenced by opencbm_plugin_nib_read_n(), opencbm_plugin_pp_cc_read_n(), opencbm_plugin_pp_dc_read_n(), opencbm_plugin_raw_read(), opencbm_plugin_s1_read_n(), opencbm_plugin_s2_read_n(), and xum1541_read_ext().

int xum1541_read_ext ( usb_dev_handle *  HandleXum1541,
unsigned char  mode,
unsigned char *  data,
size_t  size,
int *  Status,
int *  BytesRead 
)

Wrapper for xum1541_read() forcing xum1541_wait_status(), with additional parameters:

Parameters
StatusThe return status.
BytesReadThe number of bytes read.
Returns
1 : Finished successfully. <0 : Fatal error.

Definition at line 801 of file xum1541.c.

References xum1541_read().

int xum1541_tap_break ( usb_dev_handle *  HandleXum1541)

Send tape operations abort command to the xum1541 device.

Parameters
HandleXum1541A XUM1541_HANDLE which contains the file handle of the USB device.
Returns
Returns the value the USB device sent back.

Definition at line 656 of file xum1541.c.

References xum1541_control_msg().

int xum1541_write ( usb_dev_handle *  HandleXum1541,
unsigned char  modeFlags,
const unsigned char *  data,
size_t  size 
)

Write data to the xum1541 device.

Parameters
HandleXum1541A XUM1541_HANDLE which contains the file handle of the USB device.
modeDrive protocol to use to read the data from the device (e.g, XUM1541_CBM is normal IEC wire protocol).
dataPointer to buffer which contains the data to be written to the xum1541
sizeThe number of bytes to write to the xum1541
Returns
The number of bytes actually written, 0 on device error. If there is a fatal error, returns -1.

Definition at line 686 of file xum1541.c.

Referenced by opencbm_plugin_close(), opencbm_plugin_listen(), opencbm_plugin_nib_write_n(), opencbm_plugin_open(), opencbm_plugin_pp_cc_write_n(), opencbm_plugin_pp_dc_write_n(), opencbm_plugin_raw_write(), opencbm_plugin_s1_write_n(), opencbm_plugin_s2_write_n(), opencbm_plugin_talk(), opencbm_plugin_unlisten(), opencbm_plugin_untalk(), and xum1541_write_ext().

int xum1541_write_ext ( usb_dev_handle *  HandleXum1541,
unsigned char  modeFlags,
const unsigned char *  data,
size_t  size,
int *  Status,
int *  BytesWritten 
)

Wrapper for xum1541_write() forcing xum1541_wait_status(), with additional parameters:

Parameters
StatusThe return status.
BytesWrittenThe number of bytes written.
Returns
1 : Finished successfully. <0 : Fatal error.

Definition at line 775 of file xum1541.c.

References xum1541_write().