Initial commit of workable stm32l debug
[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 "stlink-common.h"
16     
17         // device access
18 #define RDWR            0
19 #define RO              1
20 #define SG_TIMEOUT_SEC  1 // actually 1 is about 2 sec
21     // Each CDB can be a total of 6, 10, 12, or 16 bytes, later version
22     // of the SCSI standard also allow for variable-length CDBs (min. CDB is 6).
23     // the stlink needs max. 10 bytes.
24 #define CDB_6           6
25 #define CDB_10          10
26 #define CDB_12          12
27 #define CDB_16          16
28
29 #define CDB_SL          10
30
31     // Query data flow direction.
32 #define Q_DATA_OUT      0
33 #define Q_DATA_IN       1
34
35     // The SCSI Request Sense command is used to obtain sense data
36     // (error information) from a target device.
37     // http://en.wikipedia.org/wiki/SCSI_Request_Sense_Command
38 #define SENSE_BUF_LEN           32
39
40
41
42 #if defined(CONFIG_USE_LIBUSB)
43     struct stlink_libsg {
44         int sg_fd;
45         int do_scsi_pt_err;
46
47         unsigned char cdb_cmd_blk[CDB_SL];
48
49         int q_data_dir; // Q_DATA_IN, Q_DATA_OUT
50         // the start of the query data in the device memory space
51         uint32_t q_addr;
52
53         // Sense (error information) data
54         unsigned char sense_buf[SENSE_BUF_LEN];
55
56         uint32_t st_vid;
57         uint32_t stlink_pid;
58         uint32_t stlink_v;
59         uint32_t jtag_v;
60         uint32_t swim_v;
61         uint32_t core_id;
62
63         reg reg;
64     };
65 #else
66     struct stlink_libsg {};
67 #endif
68
69
70 #ifdef  __cplusplus
71 }
72 #endif
73
74 #endif  /* STLINK_SG_H */
75