OpenCores
URL https://opencores.org/ocsvn/gecko3/gecko3/trunk

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-fw/] [firmware/] [include/] [usb_tmc.h] - Blame information for rev 32

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 nussgipfel
/* GECKO3COM
2
 *
3
 * Copyright (C) 2008 by
4
 *   ___    ____  _   _
5
 *  (  _`\ (  __)( ) ( )
6
 *  | (_) )| (_  | |_| |   Berne University of Applied Sciences
7
 *  |  _ <'|  _) |  _  |   School of Engineering and
8
 *  | (_) )| |   | | | |   Information Technology
9
 *  (____/'(_)   (_) (_)
10
 *
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
 
25
/*********************************************************************/
26
/** \file     usb_tmc.h
27
 *********************************************************************
28
 * \brief     header file for the USB Test and Measurement Class (TMC)
29
 *            functions.
30
 *
31
 *            According to USBTMC Specification Revision 1.0 and
32
 *            USBTMC-USB488 Subclass Specification Revision 1.0.
33
 *
34
 * \author    Christoph Zimmermann bfh.ch, Eldo José dos Santos
35
 * \date      2009-02-04
36
 *
37
*/
38
 
39
#ifndef _USBTMC_H_
40
#define _USBTMC_H_
41
 
42
/** length of the buffer to hold the response messages to be sent to the host */
43
#define TMC_RESPONSE_QUEUE_LENGTH 256  
44
 
45
/*****************************************************************************/
46
/* definitions, data structures and related stuff
47
 * according to USBTMC standard */
48
 
49
#define USB_TMC_HEADER_SIZE 12  /**< length of a USBTMC header */
50
 
51
 
52
/* USBTMC MsgID. Values, Ref.: Table 2 */
53 32 nussgipfel
#define DEV_DEP_MSG_OUT             1   /**< device dependent command message */
54
#define REQUEST_DEV_DEP_MSG_IN      2   /**< command message that requests the 
55
                                           device to send a USBTMC response */
56
#define DEV_DEP_MSG_IN              2   /**< response message to the 
57
                                           REQUEST_DEV_DEP_MSG_IN */
58
#define VENDOR_SPECIFIC_OUT         126 /**< vendor specific command message */
59
#define REQUEST_VENDOR_SPECIFIC_IN  127 /**< command message that requests the
60
                                           device to send a vendor specific
61
                                           USBTMC response */
62
#define VENDOR_SPECIFIC_IN          127 /**< response message to the 
63
                                           REQUEST_VENDOR_SPECIFIC_IN */
64 9 nussgipfel
 
65
 
66
/* format of bmRequestType byte */
67
#define bmRT_TMC_OUT   0x21             
68
#define bmRT_TMC_IN    0xA1
69
 
70
 
71
/* USBTMC commands (bRequest values, Ref.: Table 15) */
72
#define INITIATE_ABORT_BULK_OUT      1
73
#define CHECK_ABORT_BULK_OUT_STATUS  2
74
#define INITIATE_ABORT_BULK_IN       3
75
#define CHECK_ABORT_BULK_IN_STATUS   4
76
#define INITIATE_CLEAR               5
77
#define CHECK_CLEAR_STATUS           6
78
#define GET_CAPABILITIES             7
79
#define INDICATOR_PULSE              64
80
 
81
/* USBTMC USB488 Subclass commands (bRequest values, Ref.: Table 9) */
82
#define READ_STATUS_BYTE             128
83
#define REN_CONTROL                  160
84
#define GO_TO_LOCAL                  161
85
#define LOCAL_LOCKOUT                162
86
 
87
/* bmTransfer attributes */
88
#define bmTA_EOM       0x01  /**< bmTransfer Attribute: End of Message */
89
#define bmTA_TERMCHAR  0x02  /**< bmTransfer Attribute: Terminate transfer with Terminate Character */
90
 
91
/** \brief status values according to USBTMC specificaton, Ref.: Table 16 */
92
typedef enum {
93
        TMC_STATUS_SUCCESS                   = 0x01,
94
        TMC_STATUS_PENDING                   = 0x02,
95
 
96
        /* USB488 defined USBTMC status values */
97
        TMC_STATUS_INTERRUPT_IN_BUSY         = 0x20,
98
 
99
        TMC_STATUS_FAILED                    = 0x80,
100
        TMC_STATUS_TRANSFER_NOT_IN_PROGRESS  = 0x81,
101
        TMC_STATUS_SPLIT_NOT_IN_PROGRESS     = 0x82,
102
        TMC_STATUS_SPLIT_IN_PROGRESS         = 0x83,
103
} TMC_Status;
104
 
105
/* defines for the device capablilities, Ref.: Table 37 and Table 8 USB488 */
106
#define HAS_INDICATOR_PULSE 0x04
107
#define TALK_ONLY       0x02
108
#define LISTEN_ONLY     0x01
109
#define TERMCHAR_BULKIN 0x01
110
#define IS_488_2        0x04
111
#define ACCEPTS_LOCAL_LOCKOUT 0x02
112
#define TRIGGER         0x01
113
#define SCPI_COMPILIANT 0x08
114
#define SR1_CAPABLE     0x04
115
#define RL1_CAPABLE     0x02
116
#define DT1_CAPABLE     0x01
117
 
118
/** \brief Structure to handle get_capabilities command.
119
 *
120
 *  contains all required parameters for a correct device specification */
121
typedef struct {
122
  uint8_t USBTMC_status;
123
  uint8_t reserved0;
124
  uint8_t bcdUSBTMC_lsb;
125
  uint8_t bcdUSBTMC_msb;
126
  uint8_t TMCInterface;
127
  uint8_t TMCDevice;
128
  uint8_t reserved1[6];
129
  /* place here USB488 subclass capabilities */
130
  uint8_t bcdUSB488_lsb;
131
  uint8_t bcdUSB488_msb;
132
  uint8_t USB488Interface;
133
  uint8_t USB488Device;
134
  uint8_t reserved2[8];
135
} USB_TMC_Capabilities;
136
 
137
/* Structure to handle Bulk-OUT Header for a DEV_DEP_MSG
138
 *
139
 * Ref.: Table 3 or Bulk-IN Header for a DEV_DEP_MSG, Ref.: Table 9 */
140
typedef struct
141
{
142
        uint32_t TransferSize;
143
        int8_t   bmTransferAttributes;
144
        int8_t   Reserved[3];
145 32 nussgipfel
} DEV_DEP_MSG_OUT_Header, /**< Bulk-OUT Header for a DEV_DEP_MSG,
146
                            Ref.: Table 3 */
147
  DEV_DEP_MSG_IN_Header;  /**< Bulk-IN Header for a DEV_DEP_MSG,
148
                             Ref.: Table 9 */
149 9 nussgipfel
 
150
/** \brief Structure to handle USBTMC device dependent message IN requests.
151
 *
152
 *  Ref.: Table 4 */
153
typedef struct
154
{
155
        uint32_t TransferSize;
156
        int8_t   bmTransferAttributes;
157
        int8_t   TermChar;
158
        int8_t   Reserved[2];
159
} REQUEST_DEV_DEP_MSG_IN_Header; /* Ref.: Table 4 */
160
 
161
/* \brief structure to handle vendor specific IN/OUT or REQUESTS according
162
 *  to USBTMC */
163
typedef struct
164
{
165
        uint32_t TransferSize;
166
        int8_t   Reserved[4];
167 32 nussgipfel
} VENDOR_SPECIFIC_OUT_Header, /**< structure to handle vendor specific
168 9 nussgipfel
                               *IN/OUT or REQUESTS according to Ref.: Table 5 */
169 32 nussgipfel
  REQUEST_VENDOR_SPECIFIC_IN_Header, /**< structure to handle vendor
170 9 nussgipfel
                                      * specific IN/OUT or REQUESTS according
171
                                      * Ref.: Table 6 */
172 32 nussgipfel
  VENDOR_SPECIFIC_IN_Header; /**< structure to handle vendor specific
173 9 nussgipfel
                              * IN/OUT or REQUESTS according Ref.: Table 10 */
174
 
175
/** \brief general Header structure for USBTMC bulk messages. The MsgID value
176
 *  determines the type of the msg_specific part of these structure */
177
typedef struct _tHeader
178
{
179
        int8_t MsgID; /**< The MsgID value determines the type of the
180
                       * msg_specific part of these structure */
181
        int8_t bTag;
182
        int8_t bTagInverse;
183
        int8_t Reserved;
184
        int8_t msg_specific[8];
185
 
186
} BulkOUT_Header, /**< \brief According to USBTMC Ref.: Table 1 */
187
  BulkIN_Header,  /**< \brief According to USBTMC Ref.: Table 8 */
188
  tHeader; /**< \brief general Header structure for USBTMC bulk messages. */
189
 
190
 
191
/*****************************************************************************/
192
/* IEEE488 related stuff */
193
 
194
#define bmPOWER_ON                0x80
195
#define bmUSER_REQUEST            0x40
196
#define bmCOMMAND_ERROR           0x20
197
#define bmEXECUTION_ERROR         0x10
198
#define bmDEVICEDEPENDENT_ERROR   0x08
199
#define bmQUERY_ERROR             0x04
200
#define bmREQUEST_CONTROL         0x02
201
#define bmOPERATION_COMPLETE      0x01
202
 
203
/** \brief struct that contains all registers needed for the IEEE488.2
204
 *  compiliant status reporting */
205
typedef struct {
206
        uint8_t EventStatusRegister;
207
        uint8_t EventStatusEnable;
208
        uint8_t StatusByteRegister;
209
        uint8_t ServiceRequestEnable;
210
        uint8_t OPC_Received;
211
} IEEE488_status_registers;
212
 
213
 
214
/*****************************************************************************/
215
/* internal definitions and typedef's needed for this implementation */
216
 
217
#define NEWTRANSFER 1
218
 
219
/** \brief Internal state of tmc system.
220
 *
221
 *  used by this implementation, no reference in standard */
222
typedef enum {
223
        TMC_STATE_IDLE = 0x01,
224
        TMC_STATE_OUT_TRANSFER = 0x02,
225
        TMC_STATE_IN_TRANSFER = 0x03,
226
        TMC_STATE_ABORTING_OUT = 0x04,
227
        TMC_STATE_ABORTING_IN = 0x05,
228
        TMC_STATE_HALT = 0x06,
229
} TMC_State;
230
 
231
/** \brief struct to hold all usb tmc transfer relevant information */
232
typedef struct {
233
  uint8_t bTag; /**< contains the bTag value of the currently active transfer */
234
  uint32_t transfer_size;
235 32 nussgipfel
  uint8_t new_transfer; /**< flag to signal the start of a new transfer,
236
                           else 0 */
237
  uint32_t nbytes_rxd; /**< contains the number of bytes received in active
238
                          tmc OUT transfer */
239
  uint32_t nbytes_txd; /**< contains the number of bytes transmitted in active
240
                          tmc IN transfer */
241 9 nussgipfel
 
242
} TMC_Transfer_Info;
243
 
244
 
245
/** \brief response queue to hold the data for requests */
246
typedef struct {
247
  unsigned char buf[TMC_RESPONSE_QUEUE_LENGTH]; /**< message buffer */
248
  uint16_t length;  /**< length of message. is 0 when no message is available */
249
} TMC_Response_Queue;
250
 
251
 
252
/* Global variables */
253 32 nussgipfel
extern volatile static TMC_Status usb_tmc_status;       /**< Global variable
254
contains the status of the last tmc operation. normally USB_TMC_SUCCESS */
255
extern volatile TMC_State usb_tmc_state;         /**< Global variable contains
256
the state of the tmc system. Example USB_TMC_IDLE or USB_TMC_IN_TRANSFER */
257
extern volatile idata TMC_Transfer_Info usb_tmc_transfer; /**< Global struct
258
to hold all usb tmc transfer relevant information */
259
extern volatile idata IEEE488_status_registers ieee488_status;   /**< Struct
260
that contains all status and enable registers for the IEEE488 status reporting
261
capabilities */
262 9 nussgipfel
 
263
 
264
/** Makro to check if this setup package is a USBTMC request */
265
#define usb_tmc_request() ((wIndexL == USB_TMC_INTERFACE && \
266
                            (bRequestType & bmRT_RECIP_INTERFACE) == bmRT_RECIP_INTERFACE) \
267
                           ||                                           \
268
                           (wIndexL == USB_TMC_EP_OUT && \
269
                            (bRequestType & bmRT_RECIP_ENDPOINT) == bmRT_RECIP_ENDPOINT) \
270
                           ||                                           \
271
                           (wIndexL == (bmRT_DIR_IN | USB_TMC_EP_IN) && \
272
                            (bRequestType & bmRT_RECIP_ENDPOINT) == bmRT_RECIP_ENDPOINT) \
273
                          )
274
 
275
/** \brief general function to handle the TMC requests.
276
 *
277
 *  Parses the TMC header to provide needed information to the
278
 *  following message parser.
279
 *  \return returns non-zero if it handled the command successfully.
280
 */
281
uint8_t usb_handle_tmc_packet (void);
282
 
283
 
284
/** \brief clears all global variables to known states. sets the POWER_ON bit */
285
void init_usb_tmc();
286
 
287 32 nussgipfel
/** set the mav bit (Message available or "Queue not empty") in the IEEE488
288
    status structure */
289 9 nussgipfel
#define IEEE488_set_mav() (ieee488_status.StatusByteRegister |= 0x10)
290
 
291 32 nussgipfel
/** clear the mav bit (Message available or "Queue not empty") in the IEEE488
292
    status structure */
293 9 nussgipfel
#define IEEE488_clear_mav() (ieee488_status.StatusByteRegister &= 0xEF)
294
 
295
/** \brief evalutates the status IEEE488 status byte. represents the current
296
 *         device state
297
 *
298
 * executes the process to evaluate the current state of the status byte
299
 * according to the IEEE488.2 standard status reporting capabilities.
300
 * Reference: IEC60488-2:2004 figure 4-1
301
 *
302
 * \param[in] *status pointer to a IEEE488_status_registers struct.
303
 *            Status byte in the struct is updated
304
 * \return return value is the current value of the status byte
305
 */
306
uint8_t IEEE488_status_query(idata IEEE488_status_registers *status);
307
 
308 32 nussgipfel
#endif /* _USBTMC_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.