⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_protocol.h

📁 一个简单示波器的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
// ulParam      - Scale in mV per division.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_SET_SCALE 0x0F

//*****************************************************************************
//
// Packet types (tScopePacket.ucPacketType) for packets sent from the device
// to the host.
//
//*****************************************************************************

//
// Sent from the device in response to SCOPE_PKT_HOST_HELLO. The ucVersion
// field of tScopePacket must be set to the protocol version that will be
// used for all future communication. This will be the lower of the version
// supported by the device and the version requested by the host in the
// SCOPE_PKT_HOST_HELLO packet. Both host and device must ensure that they
// use this protocol in all future transactions.
//
// ucParam      - Unused
// ulParam      - Unused
// ulDataLength - sizeof(tScopeSettings)
//
// A tScopeSettings structure is sent following the tScopePacket header. This
// contains the current oscilloscope settings at the device site and allows
// the application to initialize any user interface controls that mirror
// those settings.
//
#define SCOPE_PKT_HELLO_RESPONSE 0x80

//
// Sent from the device whenever the timebase is update either via the device
// user interface or as a result of a SCOPE_PKT_SET_TIMEBASE packet from the
// host.
//
// ucParam      - Unused
// ulParam      - The new timebase expressed in microseconds per division.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_TIMEBASE_UPDATED 0x81

//
// Sent from the device whenever the trigger type is changed either via the
// device user interface or as a result of a SCOPE_PKT_SET_TRIGGER_TYPE
// packet from the host.
//
// ucParam      - SCOPE_CHANNEL_1 or SCOPE_CHANNEL_2 to indicate the channel
//                on which triggering is to take place.
// ulParam      - SCOPE_TRIGGER_TYPE_LEVEL, SCOPE_TRIGGER_TYPE_RISING,
//                SCOPE_TRIGGER_TYPE_FALLING or SCOPE_TRIGGER_TYPE_ALWAYS.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_TRIGGER_TYPE 0x82

//
// Sent from the device whenever the trigger level is changed either via the
// device user interface or as a result of a SCOPE_PKT_SET_TRIGGER_LEVEL
// packet from the host.
//
// ucParam      - Unused
// ulParam      - The new trigger level in millivolts.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_TRIGGER_LEVEL 0x83

//
// Sent from the device whenever the trigger position is changed either via
// the device user interface or as a result of a SCOPE_PKT_SET_TRIGGER_POS
// packet from the host.
//
// ucParam      - Unused
// ulParam      - The new trigger position in pixels from center (-60,60).
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_TRIGGER_POS 0x84

//
// Sent from the device whenever channel 2 is enabled or disabled either via
// the device user interface or as a result of a SCOPE_PKT_SET_CHANNEL2
// packet from the host.
//
// ucParam      - SCOPE_CHANNEL2_DISABLE or SCOPE_CHANNEL2_ENABLE
// ulParam      - Unused
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_CHANNEL2 0x85

//
// Sent from the device in preparation for transmission of a capture data
// set to the host.
//
// ucParam      - 0
// ulParam      - Total number of tScopeDataElement or tScopeDualDataElement
//                structures that will be transmitted to complete the data
//                set. The type of structure that the host should expect
//                depends upon the bDualChannel field of the tScopeStartData
//                structure passed in the payload of this packet.
// ulDataLength - sizeof(tScopeStartData)
//
// A fully populated tScopeStartData structure follows the tScopePacket
// structure in this packet.
//
#define SCOPE_PKT_DATA_START 0x86

//
// Sent from the device to pass a portion of a captured data set to the host.
//
// ucParam      - Incrementing packet counter. The first SCOPE_PKT_DATA
//                packet for a data set must have ucParam set to 1 with
//                subsequent packets increasing this value by 1 on each
//                packet.
// ulParam      - The number of tScopeDataElement or tScopeDualDataElement
//                structures contained in the payload of this packet.
// ulDataLength - The number of bytes of payload data following. This will
//                be either (ulParam * sizeof(tScopeDataElement)) or
//                (ulParam * sizeof(tScopeDualDataElement)) depending upon
//                whether single or dual channel data is being returned.
//
// A packed array of ulParam tScopeDataElement or tScopeDualDataElement
// structures follows the tScopePacket header in this packet.
//
#define SCOPE_PKT_DATA 0x87

//
// Sent from the device to indicate that transmission of a data set has been
// completed.
//
// ucParam      - Final packet count. This value must be 1 greater than the
//                packet count passed in the final SCOPE_PKT_DATA packet for
//                this data set.
// ulParam      - Unused
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_DATA_END 0x88

//
// Sent either from the host or device in response to an incoming packet of
// type SCOPE_PKT_PING.
//
// ucParam      - From matching PING packet.
// ulParam      - From matching PING packet.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_PING_RESPONSE 0x89

//
// Sent from the device when automatic capture is started.
//
// ucParam      - Unused.
// ulParam      - Unused.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_STARTED 0x8A

//
// Sent from the device when automatic capture is stopped.
//
// ucParam      - Unused.
// ulParam      - Unused.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_STOPPED 0x8B

//
// Sent from the device to inform the host of a change in the vertical position
// offset for a given channel.
//
// ucParam      - SCOPE_CHANNEL_1 or SCOPE_CHANNEL_2 to indicate the channel
//                whose display position has been changed.
// ulParam      - Position offset in mV (signed).
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_POSITION 0x8C

//
// Sent from the device to inform the host of a change in the vertical
// scale for a given channel.
//
// ucParam      - SCOPE_CHANNEL_1 or SCOPE_CHANNEL_2 to indicate the channel
//                whose vertical scale is to be set.
// ulParam      - Scale in mV per division.
// ulDataLength - 0 (no additional payload).
//
#define SCOPE_PKT_SCALE 0x8D

//*****************************************************************************
//
// Payload of a SCOPE_PKT_HELLO_RESPONSE packet. This structure provides
// information on the current state of various user-configurable settings
// allowing the host to appropriately configure its user interface controls.
//
//*****************************************************************************
typedef struct
{
    unsigned long ulTriggerLevelmV;
    unsigned long ulTimebaseuS;
    long lTriggerPos;
    short sChannel1OffsetmV;
    short sChannel2OffsetmV;
    unsigned short usChannel1ScalemVdiv;
    unsigned short usChannel2ScalemVdiv;
    unsigned char ucChannel2Enabled;
    unsigned char ucTriggerType;
    unsigned char ucStarted;
    unsigned char ucTriggerChannel;
}
PACKED tScopeSettings;

//*****************************************************************************
//
// Payload of a SCOPE_PKT_DATA_START packet. This structure provides timing
// information about the dataset that will follow in SCOPE_PKT_DATA packets.
//
//*****************************************************************************
typedef struct
{
    //
    // This field contains the time difference between consecutive samples
    // from the same channel expressed in microseconds.
    //
    unsigned long ulSampleOffsetuS;

    //
    // When dual channel data is being returned, this field contains
    // information on the number of microseconds between capture of the sample
    // returned in tScopeDualDataElement.usSample1mVolts and
    // tScopeDualDataElement.usSample2mVolts with usSample2mVolts having
    // been captured later than Sample1mVolts. This information may be used to
    // correctly position the channel 2 waveform on the display.
    //
    // When single channel data is being returned, this value can be ignored.
    //
    unsigned long ulSamplePerioduS;

    //
    // The index the sample at which the trigger event was detected. The index
    // indicates which tScopeDualDataElement or tScopeDataElement structure
    // to be returned in following SCOPE_PKT_DATA packets contains the trigger.
    // Triggers are always associated with the sample in the usSample1mVolts
    // field. The trigger channel can be inferred from the bCh2SampleFirst
    // field below.
    //
    unsigned long ulTriggerIndex;

    //
    // The total number of data elements which are to be transmitted in
    // follow-on SCOPE_PKT_DATA packets. Each element contains either one
    // or two samples depending upon the state of bDualChannel below.
    //
    unsigned long ulTotalElements;

    //
    //
    // If non-zero, this field indicates that the following SCOPE_PKT_DATA
    // packets contain dual channel data represented using
    // tScopeDualElementData structures. If zero, the following SCOPE_PKT_DATA
    // packets contain single channel data represented using tScopeDataElement
    // structures.
    //
    unsigned char bDualChannel;

    //
    // If bDualChannel is non-zero then this field indicates the order of the
    // samples to be returned in the following SCOPE_PKT_DATA packets. If
    // zero, usSample1mVolts contains a sample for channel 1 of the oscilloscope
    // and usSample2mVolts contains a channel 2 sample. If non-zero, the
    // channels are swapped with usSample1mVolts containing a channel 2 sample
    // and usSample2mVolts containing a channel 1 sample.
    //
    unsigned char bCh2SampleFirst;
}
PACKED tScopeDataStart;

//*****************************************************************************
//
// The payload of SCOPE_PKT_DATA_START packets consists of an integral number
// of tScopeDataElement or tScopeDualDataElement structures. tScopeDataElement
// is used to transfer data sets when only a single channel of data is in use.
// tScopeDualDataElement is used when dual channel capture is enabled.
//
//*****************************************************************************
typedef struct
{
    //
    // The time at which this sample was taken expressed as a microsecond
    // offset from the sample time for the first sample in the current
    // capture sequence.
    //
    unsigned long ulTimeuS;

    //
    // The sampled voltage at time ulTimeuS expressed in millivolts.
    //
    short sSamplemVolts;
}
PACKED tScopeDataElement;

typedef struct
{
    //
    // The time at which the usSample1mVolts sample was taken expressed as a
    // microsecond offset from the sample time for the first sample in the
    // current capture sequence.
    //
    unsigned long ulTimeuS;

    //
    // The sampled voltage at time ulTimeuS expressed in millivolts. The input
    // sampled to give this voltage is determined by the bCh2SampleFirst field
    // in tScopeDataStart previously sent in a SCOPE_PKT_DATA_START packet.
    //
    short sSample1mVolts;

    //
    // The sampled voltage at time (ulTimeuS + ulSampleOffsetuS) where value
    // ulSampleOffsetuS is the value previously sent in a SCOPE_PKT_DATA_START
    // packet. The input sampled to give this voltage is determined by the
    // bCh2SampleFirst field in tScopeDataStart previously sent in a
    // SCOPE_PKT_DATA_START packet.
    //
    short sSample2mVolts;
}
PACKED tScopeDualDataElement;

//*****************************************************************************
//
// tScopePacket.ucParam for SCOPE_PKT_SET_TRIGGER_TYPE and
// SCOPE_PKT_TRIGGER_TYPE.
//
//*****************************************************************************
#define SCOPE_CHANNEL_1         0x00
#define SCOPE_CHANNEL_2         0x01

//*****************************************************************************
//
// tScopePacket.ulParam for SCOPE_PKT_SET_TRIGGER_TYPE and
// SCOPE_PKT_TRIGGER_TYPE.
//
//*****************************************************************************
#define SCOPE_TRIGGER_TYPE_LEVEL     0x00000000
#define SCOPE_TRIGGER_TYPE_RISING    0x00000001
#define SCOPE_TRIGGER_TYPE_FALLING   0x00000002
#define SCOPE_TRIGGER_TYPE_ALWAYS    0x00000003

//*****************************************************************************
//
// tScopePacket.ucParam for SCOPE_PKT_SET_CHANNEL2 and SCOPE_PKT_CHANNEL2.
//
//*****************************************************************************
#define SCOPE_CHANNEL2_DISABLE  0x00
#define SCOPE_CHANNEL2_ENABLE   0x01

//*****************************************************************************
//
// Return to default packing when using the IAR Embedded Workbench compiler.
//
//*****************************************************************************
#ifdef ewarm
#pragma pack()
#endif

#endif // _USB_PROTOCOL_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -