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

📄 pcgen.bas

📁 usb pci detection to usb port device
💻 BAS
📖 第 1 页 / 共 3 页
字号:
Public Baud_153p6kEXT, Baud_38p4k, Baud_76p8k, baud_153p6kstd
#End If


'## PCGEN Status Register masks
Public Const COMM_OK_LED                  As Byte = &H10   ' bit b4, 0001_0000
Public Const GENI_OK_LED                  As Byte = &H8    ' bit b3, 0000_1000
Public Const WatchDogStatus               As Byte = &H2    ' bit b1, 0000_0010
Public Const ResetDetect                  As Byte = &H1    ' bit b0, 0000_0001
Public Const FILE_DEVICE_UNKNOWN          As Integer = 34  'Public Const FILE_DEVICE_UNKNOWN = &H22
Public Const METHOD_BUFFERED              As Long = 0

'PCI Genius card commands
'Declare IOCTL variables to Mimic C++ Macros with CTL_CODE Function
Public IOCTL_GEGENIUS_READ_PORT           As Long
Public IOCTL_GEGENIUS_WRITE_PORT          As Long
Public IOCTL_GEGENIUS_MAP_MEMORY          As Long
Public IOCTL_GEGENIUS_UNMAP_MEMORY        As Long
'Use these statements for API DeviceIOControl functions
'IOCTL_GEGENIUS_READ_PORT = CTL_CODE(FILE_DEVICE_UNKNOWN, &H910, METHOD_BUFFERED, FILE_READ_ACCESS)
'IOCTL_GEGENIUS_WRITE_PORT = CTL_CODE(FILE_DEVICE_UNKNOWN, &H911, METHOD_BUFFERED, FILE_WRITE_ACCESS)
'IOCTL_GEGENIUS_MAP_MEMORY = CTL_CODE(FILE_DEVICE_UNKNOWN, &H912, METHOD_BUFFERED, FILE_ANY_ACCESS)
'IOCTL_GEGENIUS_UNMAP_MEMORY = CTL_CODE(FILE_DEVICE_UNKNOWN, &H913, METHOD_BUFFERED, FILE_ANY_ACCESS)

Public Const MAX_PATH                        As Long = 260
Public Const INVALID_HANDLE_VALUE         As Long = -1
Public Const ERROR_FILE_NOT_FOUND            As Long = 2

'###############################################################################
'## The GENPORT_WRITE_INPUT structure defines the interface for reading/writing
'## one of the 3 PCGEN hardware registers:  configuration, status And control.
'##
'## See GFK-2342, "PCI Genius Card Quick Install Guide" for details.
'##
'Contents of GENPORT_WRITE_INPUT_WriteData
        'LongData As Long - Maximum Size
        'ShortData As Integer
        'CharData As Byte
Public Type GENPORT_WRITE_INPUT
    PortNumber                              As Long     '## Port # to be accessed
    WriteData                               As Long     '## Data to be read from / written to port
End Type  'GENPORT_WRITE_INPUT

'## ----------------------------------------------------------------------------
'## PCGEN Register Offsets
Public Const CONFIG_REG                   As Integer = 0 '## configuration register
Public Const STATUS_REG                   As Integer = 1 '## status register
Public Const CONTROL_REG                  As Integer = 2 '## control register

'###############################################################################
'## Caution:  The following structure MUST be defined as byte-aligned, not word-
'##             aligned.  The structure order cannot be altered.
'##
'##
'## The READ_DATAGRAM command instructs the PCGEN card to move a reply datagram
'## from its receive queue to dual-port RAM where it may be accessed.
'## See GFK-0845, "Genius I/O Geni Board User's Manual" for details.
'##
Public Type READ_DATAGRAM
    Source_SBA      As Byte     'SBA of device sending the datagram
    MainFunction    As Byte     'Datagram function code
    Subfunction     As Byte     'Datagram sub-function code
    DB_Indicator    As Byte     'Directed (=1) or broadcast (=0) indicator
    Length          As Byte     'Length of message
End Type    'READ_DATAGRAM

'## ----------------------------------------------------------------------------
'###############################################################################
'## Caution:  The following structure MUST be defined as byte-aligned, not word-
'##             aligned.  The structure order cannot be altered.
'##
'##
'## The TRANSMIT_DATAGRAM command instructs the PCGEN card to transmit a datagram
'## previously placed in dual-port RAM.
'## See GFK-0845, "Genius I/O Geni Board User's Manual" for details.
'##
Public Type TRANSMIT_DATAGRAM
    Destination     As Byte     'SBA of device datagram sent to
    MainFunction    As Byte     'Datagram function code
    Subfunction     As Byte     'Datagram sub-function code
    Priority        As Byte     'Priority (1=high, 0=low)
    Length          As Byte     'Length of message
End Type    'TRANSMIT_DATAGRAM

'## ----------------------------------------------------------------------------
'###############################################################################
'## Caution:  The following structure MUST be defined as byte-aligned, not word-
'##             aligned.  The structure order cannot be altered.
'##
'##
'## The TRANSMIT_DATAGRAM_WITH_REPLY command instructs the PCGEN card to transmit
'## a datagram previously placed in dual-port RAM, and then wait for a reply.
'## See GFK-0845, "Genius I/O Geni Board User's Manual" for details.
'##
Public Type TRANSMIT_DATAGRAM_WITH_REPLY
    Destination         As Byte     'SBA of device datagram sent to
    MainFunction        As Byte     'Datagram function code
    Xmit_Subfunction    As Byte     'Datagram transmission sub-function code
    Recv_Subfunction    As Byte     'Datagram reply sub-function code
    Priority            As Byte     'Priority (1=high, 0=low)
    Xmit_Length         As Byte     'Length of transmission message
    Recv_Length         As Byte     'Length of reply message
End Type    'TRANSMIT_DATAGRAM_WITH_REPLY

'## ----------------------------------------------------------------------------
'###############################################################################
'## Caution:  The following structure MUST be defined as byte-aligned, not word-
'##             aligned.  The structure order cannot be altered.
'##
'##
'## The COMMAND portion of PCGEN dual-port RAM is used for the processing of
'## datagrams.  The current intent is to shield the user from the nuances of
'## datagrams, which can be rather complex.  Should this portion of dual-port RAM
'## need to be exposed to the user, then the structure definitions would need to
'## moved to PCGEN.h
'##
'## @@ Have not yet added support for the "Change Configuration" datagram...
'##
' Content of COMMAND_OPTIONS
'       read_datagram_options As READ_DATAGRAM
'       xmit_datagram_options As TRANSMIT_DATAGRAM
'       xmit_with_reply_datagram_options As TRANSMIT_DATAGRAM_WITH_REPLY
'       OPTIONS(14) - Maximum Size
Public Type COMMAND
    status          As Byte  'Initiation of command + command status
    COMMAND         As Byte  'Command type (read, xmit, xmit w/reply, cfg change)
    OPTIONS(14)     As Byte  'maximum size
End Type    'COMMAND

'## Bit masks used in processing datagrams
Public Const CMDMASK                       As Long = &H3F
Public Const FLGMASK                       As Long = &H80
Public Const FREEBLK                       As Long = &H0
Public Const INCOMECMD                     As Long = &H1
Public Const INPROGRESS                    As Long = &H2
Public Const CCOMPLETE                     As Long = &H4
Public Const SYNTAXERR                     As Long = &H8
Public Const PROCERR                       As Long = &H10
'## Command types
Public Const READ_DATAGRAM                 As Integer = 1
Public Const XMIT_DATAGRAM                 As Integer = 2
Public Const XMIT_DATAGRAM_WITH_REPLY      As Integer = 3
Public Const CHANGE_CONFIG                 As Integer = 4
'## Command function codes
Public Const GEF_DATAGRAM                  As Long = &H20
'## Command Sub-function codes
Public Const SF_READ_ID                    As Long = &H0
Public Const SF_READ_ID_REPLY              As Long = &H1
Public Const SF_READ_CONFIG                As Long = &H2
Public Const SF_READ_CONFIG_REPLY          As Long = &H3
Public Const SF_WRITE_CONFIG               As Long = &H4
Public Const SF_ASSIGN_MONITOR             As Long = &H5
Public Const SF_BEGIN_PACKET_SEQUENCE      As Long = &H6
Public Const SF_END_PACKET_SEQUENCE        As Long = &H7
Public Const SF_READ_DIAGS                 As Long = &H8
Public Const SF_READ_DIAGS_REPLY           As Long = &H9
Public Const SF_WRITE_POINT                As Long = &HB
Public Const SF_READ_BLOCK_IO              As Long = &HC
Public Const SF_READ_BLOCK_IO_REPLY        As Long = &HD
Public Const SF_REPORT_FAULT               As Long = &HF
Public Const SF_PULSE_TEST                 As Long = &H10
Public Const SF_PULSE_TEST_COMPLETE        As Long = &H11
Public Const SF_CLEAR_CIRCUIT_FAULT        As Long = &H12
Public Const SF_CLEAR_ALL_CIRCUIT_FAULTS   As Long = &H13
Public Const SF_SWITCH_BSM                 As Long = &H1C
Public Const SF_READ_DEVICE                As Long = &H1E
Public Const SF_READ_DEVICE_REPLY          As Long = &H1F
Public Const SF_WRITE_DEVICE               As Long = &H20
Public Const SF_CONFIG_CHANGE              As Long = &H22
Public Const SF_READ_DATA                  As Long = &H27
Public Const SF_READ_DATA_REPLY            As Long = &H28
Public Const SF_READ_MAP                   As Long = &H2A
Public Const SF_READ_MAP_REPLY             As Long = &H2B
Public Const SF_WRITE_MAP                  As Long = &H2C
Public Const SF_ASSIGN_SBA29_HOT_STANDBY   As Long = &H2D
'## Transmit datagram priorities
Public Const NORMAL_PRIORITY               As Integer = 0
Public Const HIGH_PRIORITY                 As Integer = 1

'## ----------------------------------------------------------------------------
'###############################################################################
'## Caution:  The following structure MUST be defined as byte-aligned, not word-
'##             aligned.  The structure order cannot be altered.
'##
'##
'## This is the master structure definition of the PCGEN dual-port RAM.  The
'## current intent is to shield the user from dealing directly with dual-port RAM.
'## Should dual-port RAM need to be exposed to the user, then the structure
'## definitions would need to move to PCGEN.h
'##
Public MemStatus                                As String
Public hMap                                    As Long
Public SharedMem                               As Long
Public MemoryBaseAddress                        As Long
Public SRI                                     As Shared_RAM_Interface

Public Type Shared_RAM_Interface
    request_q(15)                               As REQUEST_Q_ENTRY  ' Incoming datagram queue
    queue_head_ptr                              As Byte             ' Entry currently being read
    queue_tail_ptr                              As Byte             ' Most recent entry in queue
    Setup                                       As GENI_SETUP       ' PCGEN card setup data
    status                                      As GENI_STATUS      ' PCGEN card status data
    interrupt_status(15)                        As Byte             ' Current interrupt status
    interrupt_disable(15)                       As Byte             ' Enable/disable host interrupts
    command_block                               As COMMAND          ' Outgoing datagram
    transmit_datagram_buffer(239)               As Byte             ' Temporary xmit datagram buffer
    read_datagram_buffer(133)                   As Byte             ' Read access to recd datagram
    iotable_lockout_request                     As Byte             ' Set/release I/O table lockout
    iotable_lockout_state                       As Byte             ' Actual lockout state
    host_clear                                  As Byte             ' Clear interrupts from host
    reserved_1(63)                              As Byte             ' Reserved area
    aux_request_q(47)                           As Byte             ' Used with datagram request queue
    heartbeat_enable                            As Integer          ' Enable host/PCGEN heartbeat monitoring
    heartbeat_timeout_multiplier                As Byte             ' Heartbeat time interval
    reserved_2(4929)                            As Byte             ' Reserved area
    devices(31)                                 As DEVICE_CONFIG    ' Device configuration table
    directed_control_input_table(127)           As Byte             ' PCGEN Directed Control input table
    broadcast_control_output_table(127)         As Byte             ' PCGEN Broadcast Control output table
    device_io_table(8191)                       As Byte             ' Device I/O table
End Type    'Shared_RAM_Interface

'## Shared RAM Interface Access Macro
'Public SRI As Shared_RAM_Interface
'#define SRI ((volatile Shared_RAM_Interface *)this.MemoryBaseAddress)

'## ----------------------------------------------------------------------------
' Control register declarations
Public Const BoardResetRelease                 As Byte = &H40
Public Const WDT_Disable                       As Byte = &H20
Public Const HHM_PresentTest                   As Byte = &H8

⌨️ 快捷键说明

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