📄 test.c
字号:
--*/
{
PUCHAR wPortDCR;
UCHAR dcr, dsrMask, dsrValue;
BOOLEAN bXFlag;
BOOLEAN bUseXFlag = FALSE;
DD(NULL,DDT,"P4IeeeTerminate1284Mode - enter - Controller=%x, IeeeState=%x\n",Controller,IeeeState);
wPortDCR = Controller + OFFSET_DCR;
dcr = P5ReadPortUchar(wPortDCR);
if( PHASE_TERMINATE == IeeeState->CurrentPhase ) {
// We are already terminated. This will fail if we don't just bypass this mess.
goto Terminate_ExitLabel;
}
// Keep Negotiated XFLAG to use for termination.
// xFlag, // Technically we should have
// cached this value from state
// 6 of nego. This peripheral's XFlag
// at pre state 22 should be the
// same as state 6.
bXFlag = P5ReadPortUchar(Controller + OFFSET_DSR) & 0x10;
// REVISIT: Do we need to ensure the preceeding state is a valid
// state to terminate from. In other words, is there there
// a black bar on the 1284 line for that state?
// =============== Host State 22 Termination ===============8
// DIR = Don't Care (Possibly Low)
// IRQEN = Don't Care (Possibly Low)
// 1284/SelectIn = Low (Signals state 22)
// nReverseReq/**(ECP only) = Don't Care (High for ECP, otherwise unused)
// HostAck/HostBusy/nAutoFeed = High
// HostClk/nStrobe = High
//
IeeeState->CurrentEvent = 22;
dcr = P5ReadPortUchar(wPortDCR);
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// Clear data lines so we don't have any random spew.
P5WritePortUchar(Controller + OFFSET_DATA, 0);
// *************** Periph State 23/24 Termination ***************8
// PeriphAck/PtrBusy = High (Signals state 23 for ECP
// otherwise already high)
// PeriphClk/PtrClk = Low (Signals state 24 for ecp
// Signals state 23 for Nibble)
// nAckRev/AckDataReq/PE = Don't Care
// XFlag = Low (ECP and Byte) (State 24)
// = High (Nibble) (State 24)
// = Low (All DeviceID Requests including Nibble) (State 24)
// = Undefined (EPP)
// nPeriphReq/nDataAvail = High
// Don't check nPeriphReq/nDataAvail
// Since it was in a "Don't Care"
// state (ie. Double bar in the spec)
// until state 23 for ECP mode.
if (IeeeState->CurrentPhase == PHASE_REVERSE_IDLE ||
IeeeState->CurrentPhase == PHASE_REVERSE_XFER) {
// We must be in Nibble Reverse. Let's double check!!!
if( FAMILY_REVERSE_NIBBLE == IeeeState->ProtocolFamily ||
FAMILY_REVERSE_BYTE == IeeeState->ProtocolFamily ) {
bUseXFlag = TRUE; // We're in Nibble or Byte
if( XFlagOnEvent24 == IgnoreXFlagOnEvent24 ) {
// normally we would honor XFlag but we need to work around Brother MFC-8700 firmware
bUseXFlag = FALSE;
}
} else
bUseXFlag = FALSE; // Don't know what mode we are in?
} else {
if( FAMILY_BECP == IeeeState->ProtocolFamily ||
FAMILY_ECP == IeeeState->ProtocolFamily )
bUseXFlag = TRUE; // We're in an ECP Flavor
else
bUseXFlag = FALSE; // Don't know what mode we are in?
}
if( bUseXFlag ) {
dsrMask = DSR_TEST_MASK( DONT_CARE, INACTIVE, DONT_CARE, bXFlag ? INACTIVE : ACTIVE, DONT_CARE );
dsrValue = DSR_TEST_VALUE( DONT_CARE, INACTIVE, DONT_CARE, bXFlag ? INACTIVE : ACTIVE, DONT_CARE );
}
else {
dsrMask = DSR_TEST_MASK( DONT_CARE, INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE );
dsrValue = DSR_TEST_VALUE( DONT_CARE, INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE );
}
IeeeState->CurrentEvent = 23;
if( !CheckPort( Controller + OFFSET_DSR, dsrMask, dsrValue, IEEE_MAXTIME_TL ) ) {
// We couldn't negotiate back to compatibility mode - just terminate.
DD(NULL,DDT,"IeeeTerminate1284Mode:State 23/24 Failed: Controller %x dsr %x dcr %x\n",
Controller, P5ReadPortUchar(Controller + OFFSET_DSR), dcr);
goto Terminate_ExitLabel;
}
// =============== Host State 25 Termination ===============8
// DIR = Don't Care (Possibly Low)
// IRQEN = Don't Care (Possibly Low)
// 1284/SelectIn = Low
// nReverseReq/**(ECP only) = Don't Care (Possibly High)
// HostAck/HostBusy/nAutoFeed = Low (Signals State 25)
// HostClk/nStrobe = High
//
IeeeState->CurrentEvent = 25;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, INACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// =============== State 26 Termination ===============8
// Do nothing for state 26
// =============== Periph State 27 Termination ===============8
// PeriphAck/PtrBusy = High
// PeriphClk/PtrClk = High (Signals State 27)
// nAckRev/AckDataReq/PE = Don't Care (Invalid from State 23)
// XFlag = Don't Care (All Modes) (Invlaid at State 27)
// nPeriphReq/nDataAvial = Don't Care (Invalid from State 26)
// dvrh 6/16/97
IeeeState->CurrentEvent = 27;
if( !CHECK_DSR(Controller, ACTIVE, ACTIVE, DONT_CARE, DONT_CARE, DONT_CARE, IEEE_MAXTIME_TL) ) {
DD(NULL,DDE,"P4IeeeTerminate1284Mode - State 27 Failed - Controller %x dsr %x dcr %x\n",
Controller, P5ReadPortUchar(Controller + OFFSET_DSR), dcr);
}
Terminate_ExitLabel:
// =============== Host State 28 Termination ===============8
// DIR = Don't Care (Possibly Low)
// IRQEN = Don't Care (Possibly Low)
// 1284/SelectIn = Low
// nReverseReq/**(ECP only) = Don't Care (Possibly High)
// HostAck/HostBusy/nAutoFeed = High (Signals State 28)
// HostClk/nStrobe = High
//
IeeeState->CurrentEvent = 28;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// We are now back in compatibility mode.
IeeeState->CurrentPhase = PHASE_TERMINATE;
IeeeState->Connected = FALSE;
IeeeState->IsIeeeTerminateOk = FALSE;
return;
}
NTSTATUS
P4IeeeEnter1284Mode(
IN PUCHAR Controller,
IN UCHAR Extensibility,
IN OUT PIEEE_STATE IeeeState
)
/*++
Routine Description:
This routine performs 1284 negotiation with the peripheral to the
nibble mode protocol.
Arguments:
Controller - supplies the port base address
Extensibility - supplies the IEEE 1284 mode desired
IeeeState - tracks the state of the negotiation with the peripheral
Return Value:
STATUS_SUCCESS - Successful negotiation.
otherwise - Unsuccessful negotiation.
--*/
{
PUCHAR wPortDCR;
UCHAR dcr;
const USHORT sPeriphResponseTime = 35;
wPortDCR = Controller + OFFSET_DCR;
/* =============== Host Prep for Pre State 0 ===============8
Set the following just in case someone didn't
put the port in compatibility mode before we got it.
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = Low
nReverseReq/ (ECP only)= High for ECP / Don't Care for Nibble
I will do ahead and set it to high
since Nibble doesn't care.
HostAck/HostBusy = High
HostClk/nStrobe = Don't Care
============================================================ */
dcr = P5ReadPortUchar(wPortDCR); // Get content of DCR.
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, ACTIVE, ACTIVE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
KeStallExecutionProcessor(2);
/* =============== Host Pre State 0 Negotiation ===============8
DIR = Low ( Don't Care by spec )
IRQEN = Low ( Don't Care by spec )
1284/SelectIn = Low
nReverseReq/ (ECP only)= High ( Don't Care by spec )
HostAck/HostBusy = High
HostClk/nStrobe = High
============================================================ */
dcr = UPDATE_DCR(dcr, INACTIVE, INACTIVE, INACTIVE, ACTIVE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
KeStallExecutionProcessor(2);
/* =============== Host State 0 Negotiation ===============8
Place the extensibility request value on the data bus - state 0.
============================================================ */
IeeeState->CurrentEvent = 0;
P5WritePortUchar(Controller + DATA_OFFSET, Extensibility);
KeStallExecutionProcessor(2);
/* =========== Host State 1 Negotiation Phase ===========8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High (Signals State 1)
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = Low (Signals state 1)
HostClk/nStrobe = High
============================================================ */
IeeeState->CurrentEvent = 1;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, INACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
/* =============== Periph State 2 Negotiation ===============8
PeriphAck/PtrBusy = Don't Care
PeriphClk/PtrClk = low Signals State 2
nAckReverse/AckDataReq = high Signals State 2
XFlag = high Signals State 2
**Note: It is high at state 2
for both ecp and nibble
nPeriphReq/nDataAvail = high Signals State 2
============================================================ */
IeeeState->CurrentEvent = 2;
if (!CHECK_DSR(Controller, DONT_CARE, INACTIVE, ACTIVE, ACTIVE, ACTIVE,
sPeriphResponseTime)) {
KeStallExecutionProcessor(2);
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, ACTIVE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
DD(NULL,DDT,"IeeeEnter1284Mode: %x - Extensibility=%x, FAIL - TIMEOUT on Event 2\n", Controller, Extensibility);
P5BSetPhase( IeeeState, PHASE_UNKNOWN );
IeeeState->Connected = FALSE;
IeeeState->IsIeeeTerminateOk = FALSE;
return STATUS_INVALID_DEVICE_REQUEST;
}
/* =============== Host State 3 Negotiation ===============8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = Low
HostClk/nStrobe = Low (signals State 3)
NOTE: Strobe the Extensibility byte
============================================================ */
IeeeState->CurrentEvent = 3;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, INACTIVE, INACTIVE);
P5WritePortUchar(wPortDCR, dcr);
// HostClk must be help low for at least .5 microseconds.
//
KeStallExecutionProcessor(2);
/* =============== Host State 4 Negotiation ===============8
DIR = Don't Care
IRQEN = Don't Care
1284/SelectIn = High
nReverseReq/ (ECP only)= Don't Care
HostAck/HostBusy = High (signals State 4)
HostClk/nStrobe = High (signals State 4)
NOTE: nReverseReq should be high in ECP, but this line is only
valid for ECP. Since it isn't used for signaling
anything in negotiation, let's just ignore it for now.
============================================================ */
IeeeState->CurrentEvent = 4;
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, ACTIVE, DONT_CARE, ACTIVE, ACTIVE);
P5WritePortUchar(wPortDCR, dcr);
/* ============== Periph State 5/6 Negotiation ===============
PeriphAck/PtrBusy = Don't Care. low (ECP) / Don't Care (Nibble)
Since this line differs based on Protocol
Let's not check the line.
PeriphClk/PtrClk = high (Signals State 6)
nAckReverse/AckDataReq = Don't Care. low (ECP) / high (Nibble)
Since this line differs based on Protocol
Let's not check the line.
XFlag = Don't Care. high (ECP) / low (Nibble)
Since this line differs based on Protocol
Let's not check the line.
nPeriphReq/nDataAvail = Don't Care. high (ECP) / low (Nibble)
Since this line differs based on Protocol
Let's not check the line.
============== Periph State 5/6 Negotiation ==============8
NOTES:
- It's ok to lump states 5 and 6 together. In state 5 Nibble,
the periph will set XFlag low and nPeriphReq/nDataAvail low.
The periph will then hold for .5ms then set PeriphClk/PtrClk
high. In ECP, state 5 is nAckReverse/AckDataReq going low and
PeriphAck/PtrBusy going low. Followed by a .5ms pause.
Followed by PeriphClk/PtrClk going high.
============================================================ */
IeeeState->CurrentEvent = 5;
if (!CHECK_DSR(Controller, DONT_CARE, ACTIVE, DONT_CARE, DONT_CARE, DONT_CARE,
sPeriphResponseTime)) {
dcr = UPDATE_DCR(dcr, DONT_CARE, DONT_CARE, INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE);
P5WritePortUchar(wPortDCR, dcr);
DD(NULL,DDE,"P4IeeeEnter1284Mode - controller=%x - Extensibility=%x, FAIL - TIMEOUT on Events 5/6\n"
, Controller, Extensibility);
P5BSetPhase( IeeeState, PHASE_UNKNOWN );
IeeeState->Connected = FALSE;
IeeeState->IsIeeeTerminateOk = FALSE;
return STATUS_INVALID_DEVICE_REQUEST;
}
KeStallExecutionProcessor(2);
P5BSetPhase( IeeeState, PHASE_NEGOTIATION );
IeeeState->Connected = TRUE;
return STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -