Use pkg-config to find libusb CFLAGS and LDFLAGS.
[fw/stlink] / src / stlink-sg.h
1 /* 
2  * File:   stlink-sg.h
3  * Author: karl
4  *
5  * Created on October 1, 2011, 11:29 PM
6  */
7
8 #ifndef STLINK_SG_H
9 #define STLINK_SG_H
10
11 #ifdef  __cplusplus
12 extern "C" {
13 #endif
14     
15 #include <libusb.h>
16 #include "stlink-common.h"
17     
18         // device access
19 #define RDWR            0
20 #define RO              1
21 #define SG_TIMEOUT_SEC  1 // actually 1 is about 2 sec
22 #define SG_TIMEOUT_MSEC 3 * 1000
23     // Each CDB can be a total of 6, 10, 12, or 16 bytes, later version
24     // of the SCSI standard also allow for variable-length CDBs (min. CDB is 6).
25     // the stlink needs max. 10 bytes.
26 #define CDB_6           6
27 #define CDB_10          10
28 #define CDB_12          12
29 #define CDB_16          16
30
31 #define CDB_SL          10
32
33     // Query data flow direction.
34 #define Q_DATA_OUT      0
35 #define Q_DATA_IN       1
36
37     // The SCSI Request Sense command is used to obtain sense data
38     // (error information) from a target device.
39     // http://en.wikipedia.org/wiki/SCSI_Request_Sense_Command
40 #define SENSE_BUF_LEN           32
41
42
43
44     struct stlink_libsg {
45         libusb_context* libusb_ctx;
46         libusb_device_handle *usb_handle;
47         unsigned ep_rep;
48         unsigned ep_req;
49         
50         int sg_fd;
51         int do_scsi_pt_err;
52
53         unsigned char cdb_cmd_blk[CDB_SL];
54
55         int q_data_dir; // Q_DATA_IN, Q_DATA_OUT
56         // the start of the query data in the device memory space
57         uint32_t q_addr;
58
59         // Sense (error information) data
60         // obsolete, this was fed to the scsi tools
61         unsigned char sense_buf[SENSE_BUF_LEN];
62
63         reg reg;
64     };
65
66     stlink_t* stlink_v1_open(const int verbose);
67
68 #ifdef  __cplusplus
69 }
70 #endif
71
72 #endif  /* STLINK_SG_H */
73