OpenCBM
xum1541.h
1 /*
2  * Copyright (c) 2009-2010 Nate Lawson <nate@root.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 #ifndef XUM1541_H
10 #define XUM1541_H
11 
12 #include <usb.h>
13 
14 #include "opencbm.h"
15 #include "xum1541_types.h"
16 
17 /*
18  * Compile-time assert to make sure CBM_FILE is large enough.
19  * Perhaps this should be in the global opencbm.h
20  */
21 #ifndef CTASSERT
22 #define CTASSERT(x) _CTASSERT(x, __LINE__)
23 #define _CTASSERT(x, y) __CTASSERT(x, y)
24 #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
25 #endif
26 
27 CTASSERT(sizeof(CBM_FILE) >= sizeof(usb_dev_handle *));
28 
29 /*
30  * Make our control transfer timeout 10% later than the device itself
31  * times out. This is used for both the INIT and RESET messages since
32  * INIT can do its own reset if it finds the drive in the middle of
33  * a previous aborted transaction.
34  */
35 #define USB_TIMEOUT ((int)(XUM1541_TIMEOUT * 1100))
36 
37 // libusb value for "wait forever" (signed int)
38 #define LIBUSB_NO_TIMEOUT 0x7fffffff
39 
40 // the maximum value for all allowed xum1541 serial numbers
41 #define MAX_ALLOWED_XUM1541_SERIALNUM 255
42 
43 // Disk/tape mode
44 #define DeviceDriveMode_NoTapeSupport -1 // Firmware has no tape support
45 #define DeviceDriveMode_Uninit 0 // Uninitialized
46 #define DeviceDriveMode_Disk 1 // Disk drive mode (only communication to disk drives allowed)
47 #define DeviceDriveMode_Tape 2 // Tape drive mode (only communication to tape drive allowed)
48 
49 const char *xum1541_device_path(int PortNumber);
50 int xum1541_init(usb_dev_handle **HandleXum1541, int PortNumber);
51 void xum1541_close(usb_dev_handle *HandleXum1541);
52 int xum1541_control_msg(usb_dev_handle *HandleXum1541, unsigned int cmd);
53 int xum1541_ioctl(usb_dev_handle *HandleXum1541, unsigned int cmd,
54  unsigned int addr, unsigned int secaddr);
55 
56 // Read/write data in normal CBM and speeder protocol modes
57 int xum1541_write(usb_dev_handle *HandleXum1541, unsigned char mode,
58  const unsigned char *data, size_t size);
59 int xum1541_write_ext(usb_dev_handle *HandleXum1541, unsigned char mode,
60  const unsigned char *data, size_t size, int *Status, int *BytesWritten);
61 int xum1541_read(usb_dev_handle *HandleXum1541, unsigned char mode,
62  unsigned char *data, size_t size);
63 int xum1541_read_ext(usb_dev_handle *HandleXum1541, unsigned char mode,
64  unsigned char *data, size_t size, int *Status, int *BytesRead);
65 
66 int xum1541_tap_break(usb_dev_handle *HandleXum1541);
67 
68 #endif // XUM1541_H
const char * xum1541_device_path(int PortNumber)
Query unique identifier for the xum1541 device This function tries to find an unique identifier for t...
Definition: xum1541.c:287
void xum1541_close(usb_dev_handle *HandleXum1541)
close the xum1541 device
Definition: xum1541.c:466
int xum1541_tap_break(usb_dev_handle *HandleXum1541)
Send tape operations abort command to the xum1541 device.
Definition: xum1541.c:656
#define CBM_FILE
Definition: opencbm.h:87
int xum1541_write(usb_dev_handle *HandleXum1541, unsigned char modeFlags, const unsigned char *data, size_t size)
Write data to the xum1541 device.
Definition: xum1541.c:686
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: ...
Definition: xum1541.c:801
DLL interface for accessing the driver.
int xum1541_init(usb_dev_handle **HandleXum1541, int PortNumber)
Initialize the xum1541 device This function tries to find and identify the xum1541 device...
Definition: xum1541.c:374
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: ...
Definition: xum1541.c:775
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 managem...
Definition: xum1541.c:616
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...
Definition: xum1541.c:499
int xum1541_read(usb_dev_handle *HandleXum1541, unsigned char mode, unsigned char *data, size_t size)
Read data from the xum1541 device.
Definition: xum1541.c:833