📄 par12843.c
字号:
WRITE_PORT_UCHAR( CurrentPort, (UCHAR) (0x80 | ulDaisyIndex )) ;
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentPort, (UCHAR) (0x88 | ulDaisyIndex )) ;
KeStallExecutionProcessor( Delay ); // wait a bit
ucReadValue = READ_PORT_UCHAR( CurrentStatus ) ;
ucReadPattern = ( ucReadValue << 1 ) & 0x70 ;
ucReadPattern |= ( ucReadValue & 0x80 ) ;
if ( ucReadPattern != ucExpectedPattern ) {
// not Shuttle 1284_3 behaviour
bReturnValue = FALSE ;
break ;
}
ucExpectedPattern -= 0x10 ;
}
// last byte
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[6] );
} // Third status
} // Second status
} // First status
WRITE_PORT_UCHAR( CurrentControl, value ); // restore everything
return bReturnValue ;
} // end PptCheckIfStl1284_3()
BOOLEAN
PptCheckIfStlProductId(
IN PDEVICE_EXTENSION DeviceExtension,
IN ULONG ulDaisyIndex
)
/*++
Routine Description:
This function checks to see whether the device indicated
is a Shuttle non-1284_3 type of device.
Arguments:
Extension - Device extension structure.
ulDaisyIndex - The daisy chain id of the device that
this function will check on.
Return Value:
TRUE - Yes. Device is Shuttle non-1284_3 type of device.
FALSE - No. This may mean that this device is
non-shuttle.
--*/
{
BOOLEAN bReturnValue = FALSE ;
UCHAR i, value, newvalue, status;
ULONG Delay = 3;
UCHAR ucProdIdHiByteHiNibble, ucProdIdHiByteLoNibble ;
UCHAR ucProdIdLoByteHiNibble, ucProdIdLoByteLoNibble ;
UCHAR ucProdIdHiByte, ucProdIdLoByte ;
USHORT usProdId ;
PUCHAR CurrentPort, CurrentStatus, CurrentControl;
CurrentPort = DeviceExtension->PortInfo.Controller;
CurrentStatus = CurrentPort + 1;
CurrentControl = CurrentPort + 2;
// get current ctl reg
value = READ_PORT_UCHAR( CurrentControl );
// make sure 1284.3 devices do not get reseted
newvalue = (UCHAR)((value & ~DCR_SELECT_IN) | DCR_NOT_INIT);
// make sure we can write
newvalue = (UCHAR)(newvalue & ~DCR_DIRECTION);
WRITE_PORT_UCHAR( CurrentControl, newvalue ); // make sure we can write
// bring nStrobe high
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
// send first four bytes of the 1284.3 mode qualifier sequence out
for ( i = 0; i < MODE_LEN_1284_3 - 3; i++ ) {
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[i] );
KeStallExecutionProcessor( Delay );
}
// check for correct status
status = READ_PORT_UCHAR( CurrentStatus );
if ( (status & (UCHAR)0xb8 )
== ( DSR_NOT_BUSY | DSR_PERROR | DSR_SELECT | DSR_NOT_FAULT )) {
// continue with fifth byte of mode qualifier
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[4] );
KeStallExecutionProcessor( Delay );
// check for correct status
status = READ_PORT_UCHAR( CurrentStatus );
// note busy is high too but is opposite so we see it as a low
if (( status & (UCHAR) 0xb8 ) == (DSR_SELECT | DSR_NOT_FAULT)) {
// continue with sixth byte
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[5] );
KeStallExecutionProcessor( Delay );
// check for correct status
status = READ_PORT_UCHAR( CurrentStatus );
// if status is valid there is a device out there responding
if ((status & (UCHAR) 0x30 ) == ( DSR_PERROR | DSR_SELECT )) {
WRITE_PORT_UCHAR ( CurrentPort, (UCHAR) (CPP_QUERY_PRODID | ulDaisyIndex )) ;
KeStallExecutionProcessor( Delay );
// Device is out there
KeStallExecutionProcessor( Delay );
ucProdIdLoByteHiNibble = READ_PORT_UCHAR( CurrentStatus ) ;
ucProdIdLoByteHiNibble &= 0xF0 ;
KeStallExecutionProcessor( Delay );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue | DCR_STROBE) ); // bring nStrobe low
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
KeStallExecutionProcessor( Delay ); // wait a bit
ucProdIdLoByteLoNibble = READ_PORT_UCHAR( CurrentStatus ) ;
ucProdIdLoByteLoNibble >>= 4 ;
ucProdIdLoByte = ucProdIdLoByteHiNibble | ucProdIdLoByteLoNibble ;
KeStallExecutionProcessor( Delay );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue | DCR_STROBE) ); // bring nStrobe low
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
KeStallExecutionProcessor( Delay ); // wait a bit
ucProdIdHiByteHiNibble = READ_PORT_UCHAR( CurrentStatus ) ;
ucProdIdHiByteHiNibble &= 0xF0 ;
KeStallExecutionProcessor( Delay );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue | DCR_STROBE) ); // bring nStrobe low
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
KeStallExecutionProcessor( Delay ); // wait a bit
ucProdIdHiByteLoNibble = READ_PORT_UCHAR( CurrentStatus ) ;
ucProdIdHiByteLoNibble >>= 4 ;
ucProdIdHiByte = ucProdIdHiByteHiNibble | ucProdIdHiByteLoNibble ;
// issue the last strobe
KeStallExecutionProcessor( Delay );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue | DCR_STROBE) ); // bring nStrobe low
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
KeStallExecutionProcessor( Delay ); // wait a bit
usProdId = ( ucProdIdHiByte << 8 ) | ucProdIdLoByte ;
if ( ( SHTL_EPAT_PRODID == usProdId ) ||\
( SHTL_EPST_PRODID == usProdId ) ) {
// one of the devices that conform to the earlier
// draft is found
bReturnValue = TRUE ;
}
// last byte
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[6] );
} // Third status
} // Second status
} // First status
WRITE_PORT_UCHAR( CurrentControl, value ); // restore everything
return bReturnValue ;
} // end PptCheckIfStlProductId()
BOOLEAN
PptSend1284_3Command(
IN PDEVICE_EXTENSION DeviceExtension,
IN UCHAR Command
)
/*++
Routine Description:
This routine sends the 1284_3 Command given to it
down the parallel bus.
Arguments:
DriverObject - Supplies the driver object controlling all of the
devices.
Return Value:
None.
--*/
{
UCHAR i, value, newvalue, test;//, status;
ULONG ii;
PUCHAR CurrentPort, CurrentStatus, CurrentControl;
ULONG Delay = 3;
BOOLEAN success = FALSE;
CurrentPort = DeviceExtension->PortInfo.Controller;
CurrentStatus = CurrentPort + 1;
CurrentControl = CurrentPort + 2;
// Get Upper 4 bits to see what Command it is
test = (UCHAR)(Command & (UCHAR)CPP_COMMAND_FILTER);
PptDumpV( ("PptSend1284_3Command - test = %x\n", test) );
// get current ctl reg
value = READ_PORT_UCHAR( CurrentControl );
// make sure 1284.3 devices do not get reseted
newvalue = (UCHAR)((value & ~DCR_SELECT_IN) | DCR_NOT_INIT);
// make sure we can write
newvalue = (UCHAR)(newvalue & ~DCR_DIRECTION);
WRITE_PORT_UCHAR( CurrentControl, newvalue ); // make sure we can write
// bring nStrobe high
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) );
KeStallExecutionProcessor( Delay );
// send first four bytes of the 1284.3 mode qualifier sequence out
for ( i = 0; i < MODE_LEN_1284_3 - 3; i++ ) {
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[i] );
KeStallExecutionProcessor( Delay );
}
// check for correct status
// status = READ_PORT_UCHAR( CurrentStatus );
// wait up to 5 us : Spec says about 2 but we will be lienient
if (CHECK_DSR(CurrentPort,
INACTIVE, DONT_CARE, ACTIVE, ACTIVE, ACTIVE, 5 )) {
// if ( (status & (UCHAR)0xb8 )
// == ( DSR_NOT_BUSY | DSR_PERROR | DSR_SELECT | DSR_NOT_FAULT )) {
// continue with fifth byte of mode qualifier
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[4] );
KeStallExecutionProcessor( Delay );
// check for correct status
// status = READ_PORT_UCHAR( CurrentStatus );
// note busy is high too but is opposite so we see it as a low
// if (( status & (UCHAR) 0xb8 ) == (DSR_SELECT | DSR_NOT_FAULT)) {
// wait up to 5 us : Spec says about 2 but we will be lienient
if (CHECK_DSR(CurrentPort,
ACTIVE, DONT_CARE, INACTIVE, ACTIVE, ACTIVE, 5 )) {
// continue with sixth byte
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[5] );
KeStallExecutionProcessor( Delay );
// check for correct status
// status = READ_PORT_UCHAR( CurrentStatus );
// if status is valid there is a device out there responding
// if ((status & (UCHAR) 0x30 ) == ( DSR_PERROR | DSR_SELECT )) {
// wait up to 5 us : Spec says about 2 but we will be lienient
if (CHECK_DSR(CurrentPort,
DONT_CARE, DONT_CARE, ACTIVE, ACTIVE, DONT_CARE, 5 )) {
// Device is out there
KeStallExecutionProcessor( Delay );
// Command byte
WRITE_PORT_UCHAR( CurrentPort, Command );
KeStallExecutionProcessor( Delay ); // wait a bit
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue | DCR_STROBE) ); // bring nStrobe low
KeStallExecutionProcessor( Delay ); // wait a bit
// NOTE NOTE NOTE
// Assertion of strobe to be done ONLY after checking for the
// FAULT feedback, as per the 1284_3 specification. The following lines
// have been moved to after checking for the FAULT feedback
// WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
// KeStallExecutionProcessor( Delay ); // wait a bit
// Selection does not work correctly yet to be able to check for lines
switch ( test ) {
// Check to make sure we are selected
case CPP_SELECT:
PptDumpV( ("PptSend1284_3Command - Enter CPP_SELECT case\n") );
// wait for upto 250 micro Secs for for selection time out.
for ( ii = 25000; ii > 0; ii-- ) {
if ( ( READ_PORT_UCHAR( CurrentStatus ) & DSR_NOT_FAULT ) == DSR_NOT_FAULT ) {
// selection...
success = TRUE;
PptDumpV( ("PptSend1284_3Command - SUCCESS - Selected device\n") );
break;
}
}
if ( !success ) {
PptDumpV( ("PptSend1284_3Command - was not able to select device\n") );
}
break;
// Check to make sure we are deselected
case CPP_DESELECT:
// wait for upto 250 micro Secs for for deselection time out.
for ( ii = 25000; ii > 0; ii-- ) {
if ( (READ_PORT_UCHAR( CurrentStatus ) & DSR_NOT_FAULT) != DSR_NOT_FAULT ) {
// deselection...
success = TRUE;
PptDumpV( ("PptSend1284_3Command - SUCCESS - Deselected device\n") );
break;
}
}
if ( !success ) {
PptDumpV( ("PptSend1284_3Command - was not able to deselect device\n") );
}
break;
default :
PptDumpV( ("PptSend1284_3Command - Enter default case\n") );
// there is a device out there and Command completed sucessfully
KeStallExecutionProcessor( Delay ); // wait a bit
success = TRUE;
break;
} // End Switch
// NOTE NOTE NOTE
// the strobe is de-asserted now and the command is completed here
WRITE_PORT_UCHAR( CurrentControl, (UCHAR)(newvalue & ~DCR_STROBE) ); // bring nStrobe high
KeStallExecutionProcessor( Delay ); // wait a bit
// last byte
WRITE_PORT_UCHAR( CurrentPort, ModeQualifier[6] );
} // Third status
} // Second status
} // First status
WRITE_PORT_UCHAR( CurrentControl, value ); // restore everything
// returns TRUE if command succedded FALSE otherwise
return ( success );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -